Index: /NEMO/branches/2019/dev_r12072_MERGE_OPTION2_2019/cfgs/SHARED/field_def_nemo-oce.xml
===================================================================
--- /NEMO/branches/2019/dev_r12072_MERGE_OPTION2_2019/cfgs/SHARED/field_def_nemo-oce.xml	(revision 12190)
+++ /NEMO/branches/2019/dev_r12072_MERGE_OPTION2_2019/cfgs/SHARED/field_def_nemo-oce.xml	(revision 12191)
@@ -127,4 +127,6 @@
         <field id="toce_vmean300"     field_ref="toce_e3t_vsum300"  unit="degree_C"     grid_ref="grid_T_vsum"  detect_missing_value="true" > toce_e3t_vsum300/e3t_vsum300 </field>
 
+        <!-- AGRIF sponge -->
+        <field id="agrif_spt"         long_name=" AGRIF t-sponge coefficient"   unit=" " />
 
         <!-- t-eddy viscosity coefficients (ldfdyn) -->
@@ -489,5 +491,6 @@
         <field id="uoces"        long_name="ocean transport along i-axis times salinity (CRS)"                                                  unit="1e-3*m/s"   grid_ref="grid_U_3D" />
         <field id="ssuww"        long_name="ocean surface wind work along i-axis"                   standard_name="surface_x_wind_work"         unit="N/m*s"                            > utau * ssu </field>
-
+        <!-- AGRIF sponge -->
+        <field id="agrif_spu"    long_name=" AGRIF u-sponge coefficient"   unit=" " />
         <!-- u-eddy diffusivity coefficients (available if ln_traldf_OFF=F) -->
         <field id="ahtu_2d"      long_name=" surface u-eddy diffusivity coefficient"   unit="m2/s or m4/s" />
@@ -547,5 +550,6 @@
         <field id="voces"        long_name="ocean transport along j-axis times salinity (CRS)"                                                  unit="1e-3*m/s"   grid_ref="grid_V_3D" />
         <field id="ssvww"        long_name="ocean surface wind work along j-axis"                   standard_name="surface_y_wind_work"         unit="N/m*s"                            > vtau * ssv </field>
-
+        <!-- AGRIF sponge -->
+        <field id="agrif_spv"    long_name=" AGRIF v-sponge coefficient"   unit=" " />
         <!-- v-eddy diffusivity coefficients (available if ln_traldf_OFF=F) -->
         <field id="ahtv_2d"      long_name=" surface v-eddy diffusivity coefficient"     unit="m2/s or (m4/s)^1/2" />
@@ -636,4 +640,6 @@
       
       <!-- F grid -->
+      <!-- AGRIF sponge -->
+      <field id="agrif_spf"    long_name=" AGRIF f-sponge coefficient"   unit=" " />
       <!-- f-eddy viscosity coefficients (ldfdyn) -->
       <field id="ahmf_2d"      long_name=" surface f-eddy viscosity coefficient"   unit="m2/s or m4/s" />
Index: /NEMO/branches/2019/dev_r12072_MERGE_OPTION2_2019/cfgs/SHARED/namelist_ref
===================================================================
--- /NEMO/branches/2019/dev_r12072_MERGE_OPTION2_2019/cfgs/SHARED/namelist_ref	(revision 12190)
+++ /NEMO/branches/2019/dev_r12072_MERGE_OPTION2_2019/cfgs/SHARED/namelist_ref	(revision 12191)
@@ -637,7 +637,10 @@
 &namagrif      !  AGRIF zoom                                            ("key_agrif")
 !-----------------------------------------------------------------------
+   ln_agrif_2way = .true.  !  activate two way nesting
    ln_spc_dyn    = .true.  !  use 0 as special value for dynamics
    rn_sponge_tra = 2880.   !  coefficient for tracer   sponge layer [m2/s]
    rn_sponge_dyn = 2880.   !  coefficient for dynamics sponge layer [m2/s]
+   rn_trelax_tra = 0.01    !  inverse of relaxation time (in steps) for tracers []
+   rn_trelax_dyn = 0.01    !  inverse of relaxation time (in steps) for dynamics []
    ln_chk_bathy  = .false. !  =T  check the parent bathymetry
 /
Index: /NEMO/branches/2019/dev_r12072_MERGE_OPTION2_2019/src/NST/agrif_all_update.F90
===================================================================
--- /NEMO/branches/2019/dev_r12072_MERGE_OPTION2_2019/src/NST/agrif_all_update.F90	(revision 12190)
+++ /NEMO/branches/2019/dev_r12072_MERGE_OPTION2_2019/src/NST/agrif_all_update.F90	(revision 12191)
@@ -1,5 +1,3 @@
-#define TWO_WAY
-
- MODULE agrif_all_update
+MODULE agrif_all_update
    !!======================================================================
    !!                   ***  MODULE  agrif_all_update  ***
@@ -41,6 +39,5 @@
       !!               Order of update matters here !
       !!----------------------------------------------------------------------
-# if defined TWO_WAY
-      IF (Agrif_Root()) RETURN
+      IF (( .NOT.ln_agrif_2way ).OR.(Agrif_Root())) RETURN
       !
       IF (lwp.AND.lk_agrif_debug) Write(*,*) ' --> START AGRIF UPDATE from grid Number',Agrif_Fixed()
@@ -67,5 +64,4 @@
       !
       Agrif_UseSpecialValueInUpdate = .FALSE.
-#endif
     END SUBROUTINE agrif_Update_All
 
Index: /NEMO/branches/2019/dev_r12072_MERGE_OPTION2_2019/src/NST/agrif_ice_update.F90
===================================================================
--- /NEMO/branches/2019/dev_r12072_MERGE_OPTION2_2019/src/NST/agrif_ice_update.F90	(revision 12190)
+++ /NEMO/branches/2019/dev_r12072_MERGE_OPTION2_2019/src/NST/agrif_ice_update.F90	(revision 12191)
@@ -1,4 +1,2 @@
-#define TWO_WAY
-!!#undef TWO_WAY
 #undef DECAL_FEEDBACK  /* SEPARATION of INTERFACES*/
 
@@ -63,5 +61,4 @@
       Agrif_UseSpecialValueInUpdate = .TRUE.
 
-# if defined TWO_WAY
 # if ! defined DECAL_FEEDBACK
       CALL Agrif_Update_Variable( tra_ice_id , procname = update_tra_ice  )
@@ -79,5 +76,4 @@
 !      CALL Agrif_Update_Variable( u_ice_id   , locupdate=(/0,1/), procname = update_u_ice    )
 !      CALL Agrif_Update_Variable( v_ice_id   , locupdate=(/0,1/), procname = update_v_ice    )
-# endif
       Agrif_SpecialValueFineGrid    = 0.
       Agrif_UseSpecialValueInUpdate = .FALSE.
Index: /NEMO/branches/2019/dev_r12072_MERGE_OPTION2_2019/src/NST/agrif_oce.F90
===================================================================
--- /NEMO/branches/2019/dev_r12072_MERGE_OPTION2_2019/src/NST/agrif_oce.F90	(revision 12190)
+++ /NEMO/branches/2019/dev_r12072_MERGE_OPTION2_2019/src/NST/agrif_oce.F90	(revision 12191)
@@ -17,18 +17,16 @@
 
    PUBLIC agrif_oce_alloc ! routine called by nemo_init in nemogcm.F90
-#if defined key_vertical
-   PUBLIC reconstructandremap ! remapping routine
-#endif   
+  
    !                                              !!* Namelist namagrif: AGRIF parameters
-   LOGICAL , PUBLIC ::   ln_spc_dyn    = .FALSE.   !:
-   INTEGER , PUBLIC, PARAMETER ::   nn_sponge_len = 2  !: Sponge width (in number of parent grid points)
+   LOGICAL , PUBLIC ::   ln_agrif_2way = .TRUE.    !: activate two way nesting 
+   LOGICAL , PUBLIC ::   ln_spc_dyn    = .FALSE.   !: use zeros (.false.) or not (.true.) in
+                                                   !: bdys dynamical fields interpolation
    REAL(wp), PUBLIC ::   rn_sponge_tra = 2800.     !: sponge coeff. for tracers
    REAL(wp), PUBLIC ::   rn_sponge_dyn = 2800.     !: sponge coeff. for dynamics
+   REAL(wp), PUBLIC ::   rn_trelax_tra = 0.01      !: time relaxation parameter for tracers
+   REAL(wp), PUBLIC ::   rn_trelax_dyn = 0.01      !: time relaxation parameter for momentum
    LOGICAL , PUBLIC ::   ln_chk_bathy  = .FALSE.   !: check of parent bathymetry 
-   LOGICAL , PUBLIC ::   lk_agrif_clp  = .FALSE.   !: Force clamped bcs
-   !                                              !!! OLD namelist names
-   REAL(wp), PUBLIC ::   visc_tra                  !: sponge coeff. for tracers
-   REAL(wp), PUBLIC ::   visc_dyn                  !: sponge coeff. for dynamics
-
+   !
+   INTEGER , PUBLIC, PARAMETER ::   nn_sponge_len = 2  !: Sponge width (in number of parent grid points)
    LOGICAL , PUBLIC :: spongedoneT = .FALSE.       !: tracer   sponge layer indicator
    LOGICAL , PUBLIC :: spongedoneU = .FALSE.       !: dynamics sponge layer indicator
@@ -42,13 +40,16 @@
    LOGICAL , PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) :: tabspongedone_u
    LOGICAL , PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) :: tabspongedone_v
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) :: fsaht_spu, fsaht_spv !: sponge diffusivities
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) :: fsahm_spt, fsahm_spf !: sponge viscosities
+   INTEGER , PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) :: utint_stage
+   INTEGER , PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) :: vtint_stage
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) :: fspu, fspv !: sponge arrays
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) :: fspt, fspf !:   "      "
 
    ! Barotropic arrays used to store open boundary data during time-splitting loop:
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::  ubdy_w, vbdy_w, hbdy_w
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::  ubdy_e, vbdy_e, hbdy_e
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::  ubdy_n, vbdy_n, hbdy_n
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::  ubdy_s, vbdy_s, hbdy_s
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::  ubdy, vbdy, hbdy
 
+# if defined key_vertical
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) :: ht0_parent, hu0_parent, hv0_parent
+   INTEGER,  PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) :: mbkt_parent, mbku_parent, mbkv_parent
+# endif
 
    INTEGER, PUBLIC :: tsn_id                                                  ! AGRIF profile for tracers interpolation and update
@@ -64,5 +65,5 @@
    INTEGER, PUBLIC :: scales_t_id
    INTEGER, PUBLIC :: avt_id, avm_id, en_id                ! TKE related identificators
-   INTEGER, PUBLIC :: umsk_id, vmsk_id
+   INTEGER, PUBLIC :: mbkt_id, ht0_id
    INTEGER, PUBLIC :: kindic_agr
    
@@ -82,17 +83,20 @@
       ierr(:) = 0
       !
-      ALLOCATE( fsaht_spu(jpi,jpj), fsaht_spv(jpi,jpj),   &
-         &      fsahm_spt(jpi,jpj), fsahm_spf(jpi,jpj),   &
-         &      tabspongedone_tsn(jpi,jpj),           &
+      ALLOCATE( fspu(jpi,jpj), fspv(jpi,jpj),    	    &
+         &      fspt(jpi,jpj), fspf(jpi,jpj),               &
+         &      tabspongedone_tsn(jpi,jpj),                 &
+         &      utint_stage(jpi,jpj), vtint_stage(jpi,jpj), &
 # if defined key_top         
          &      tabspongedone_trn(jpi,jpj),           &
-# endif         
+# endif   
+# if defined key_vertical
+         &      ht0_parent(jpi,jpj), mbkt_parent(jpi,jpj),  &
+         &      hu0_parent(jpi,jpj), mbku_parent(jpi,jpj),  &
+         &      hv0_parent(jpi,jpj), mbkv_parent(jpi,jpj),  &
+# endif      
          &      tabspongedone_u  (jpi,jpj),           &
          &      tabspongedone_v  (jpi,jpj), STAT = ierr(1) )
 
-      ALLOCATE( ubdy_w(nbghostcells,jpj), vbdy_w(nbghostcells,jpj), hbdy_w(nbghostcells,jpj),   &
-         &      ubdy_e(nbghostcells,jpj), vbdy_e(nbghostcells,jpj), hbdy_e(nbghostcells,jpj),   & 
-         &      ubdy_n(jpi,nbghostcells), vbdy_n(jpi,nbghostcells), hbdy_n(jpi,nbghostcells),   & 
-         &      ubdy_s(jpi,nbghostcells), vbdy_s(jpi,nbghostcells), hbdy_s(jpi,nbghostcells), STAT = ierr(2) )
+      ALLOCATE( ubdy(jpi,jpj), vbdy(jpi,jpj), hbdy(jpi,jpj), STAT = ierr(2) )
 
       agrif_oce_alloc = MAXVAL(ierr)
@@ -100,222 +104,4 @@
    END FUNCTION agrif_oce_alloc
 
-#if defined key_vertical
-   SUBROUTINE reconstructandremap(tabin,hin,tabout,hout,N,Nout)      
-      !!----------------------------------------------------------------------
-      !!                ***  FUNCTION reconstructandremap  ***
-      !!----------------------------------------------------------------------
-      IMPLICIT NONE
-      INTEGER N, Nout
-      REAL(wp) tabin(N), tabout(Nout)
-      REAL(wp) hin(N), hout(Nout)
-      REAL(wp) coeffremap(N,3),zwork(N,3)
-      REAL(wp) zwork2(N+1,3)
-      INTEGER jk
-      DOUBLE PRECISION, PARAMETER :: dsmll=1.0d-8  
-      REAL(wp) q,q01,q02,q001,q002,q0
-      REAL(wp) z_win(1:N+1), z_wout(1:Nout+1)
-      REAL(wp),PARAMETER :: dpthin = 1.D-3
-      INTEGER :: k1, kbox, ktop, ka, kbot
-      REAL(wp) :: tsum, qbot, rpsum, zbox, ztop, zthk, zbot, offset, qtop
-
-      z_win(1)=0.; z_wout(1)= 0.
-      DO jk=1,N
-         z_win(jk+1)=z_win(jk)+hin(jk)
-      ENDDO 
-      
-      DO jk=1,Nout
-         z_wout(jk+1)=z_wout(jk)+hout(jk)       
-      ENDDO       
-
-      DO jk=2,N
-         zwork(jk,1)=1./(hin(jk-1)+hin(jk))
-      ENDDO
-        
-      DO jk=2,N-1
-         q0 = 1./(hin(jk-1)+hin(jk)+hin(jk+1))
-         zwork(jk,2)=hin(jk-1)+2.*hin(jk)+hin(jk+1)
-         zwork(jk,3)=q0
-      ENDDO       
-     
-      DO jk= 2,N
-         zwork2(jk,1)=zwork(jk,1)*(tabin(jk)-tabin(jk-1))
-      ENDDO
-        
-      coeffremap(:,1) = tabin(:)
- 
-      DO jk=2,N-1
-         q001 = hin(jk)*zwork2(jk+1,1)
-         q002 = hin(jk)*zwork2(jk,1)        
-         IF (q001*q002 < 0) then
-            q001 = 0.
-            q002 = 0.
-         ENDIF
-         q=zwork(jk,2)
-         q01=q*zwork2(jk+1,1)
-         q02=q*zwork2(jk,1)
-         IF (abs(q001) > abs(q02)) q001 = q02
-         IF (abs(q002) > abs(q01)) q002 = q01
-        
-         q=(q001-q002)*zwork(jk,3)
-         q001=q001-q*hin(jk+1)
-         q002=q002+q*hin(jk-1)
-        
-         coeffremap(jk,3)=coeffremap(jk,1)+q001
-         coeffremap(jk,2)=coeffremap(jk,1)-q002
-        
-         zwork2(jk,1)=(2.*q001-q002)**2
-         zwork2(jk,2)=(2.*q002-q001)**2
-      ENDDO
-        
-      DO jk=1,N
-         IF(jk.EQ.1 .OR. jk.EQ.N .OR. hin(jk).LE.dpthin) THEN
-            coeffremap(jk,3) = coeffremap(jk,1)
-            coeffremap(jk,2) = coeffremap(jk,1)
-            zwork2(jk,1) = 0.
-            zwork2(jk,2) = 0.
-         ENDIF
-      ENDDO
-        
-      DO jk=2,N
-         q002=max(zwork2(jk-1,2),dsmll)
-         q001=max(zwork2(jk,1),dsmll)
-         zwork2(jk,3)=(q001*coeffremap(jk-1,3)+q002*coeffremap(jk,2))/(q001+q002)
-      ENDDO
-        
-      zwork2(1,3) = 2*coeffremap(1,1)-zwork2(2,3)
-      zwork2(N+1,3)=2*coeffremap(N,1)-zwork2(N,3)
- 
-      DO jk=1,N
-         q01=zwork2(jk+1,3)-coeffremap(jk,1)
-         q02=coeffremap(jk,1)-zwork2(jk,3)
-         q001=2.*q01
-         q002=2.*q02
-         IF (q01*q02<0) then
-            q01=0.
-            q02=0.
-         ELSEIF (abs(q01)>abs(q002)) then
-            q01=q002
-         ELSEIF (abs(q02)>abs(q001)) then
-            q02=q001
-         ENDIF
-         coeffremap(jk,2)=coeffremap(jk,1)-q02
-         coeffremap(jk,3)=coeffremap(jk,1)+q01
-      ENDDO
-
-      zbot=0.0
-      kbot=1
-      DO jk=1,Nout
-         ztop=zbot  !top is bottom of previous layer
-         ktop=kbot
-         IF     (ztop.GE.z_win(ktop+1)) then
-            ktop=ktop+1
-         ENDIF
-        
-         zbot=z_wout(jk+1)
-         zthk=zbot-ztop
-
-         IF(zthk.GT.dpthin .AND. ztop.LT.z_wout(Nout+1)) THEN
-
-            kbot=ktop
-            DO while (z_win(kbot+1).lt.zbot.and.kbot.lt.N)
-               kbot=kbot+1
-            ENDDO
-            zbox=zbot
-            DO k1= jk+1,Nout
-               IF     (z_wout(k1+1)-z_wout(k1).GT.dpthin) THEN
-                  exit !thick layer
-               ELSE
-                  zbox=z_wout(k1+1)  !include thin adjacent layers
-                  IF(zbox.EQ.z_wout(Nout+1)) THEN
-                     exit !at bottom
-                  ENDIF
-               ENDIF
-            ENDDO
-            zthk=zbox-ztop
-
-            kbox=ktop
-            DO while (z_win(kbox+1).lt.zbox.and.kbox.lt.N)
-               kbox=kbox+1
-            ENDDO
-          
-            IF(ktop.EQ.kbox) THEN
-               IF(z_wout(jk).NE.z_win(kbox).OR.z_wout(jk+1).NE.z_win(kbox+1)) THEN
-                  IF(hin(kbox).GT.dpthin) THEN
-                     q001 = (zbox-z_win(kbox))/hin(kbox)
-                     q002 = (ztop-z_win(kbox))/hin(kbox)
-                     q01=q001**2+q002**2+q001*q002+1.-2.*(q001+q002)
-                     q02=q01-1.+(q001+q002)
-                     q0=1.-q01-q02
-                  ELSE
-                     q0 = 1.0
-                     q01 = 0.
-                     q02 = 0.
-                  ENDIF
-                  tabout(jk)=q0*coeffremap(kbox,1)+q01*coeffremap(kbox,2)+q02*coeffremap(kbox,3)
-               ELSE
-                  tabout(jk) = tabin(kbox)
-               ENDIF 
-            ELSE
-               IF(ktop.LE.jk .AND. kbox.GE.jk) THEN
-                  ka = jk
-               ELSEIF (kbox-ktop.GE.3) THEN
-                  ka = (kbox+ktop)/2
-               ELSEIF (hin(ktop).GE.hin(kbox)) THEN
-                  ka = ktop
-               ELSE
-                  ka = kbox
-               ENDIF !choose ka
-    
-               offset=coeffremap(ka,1)
-    
-               qtop = z_win(ktop+1)-ztop !partial layer thickness
-               IF(hin(ktop).GT.dpthin) THEN
-                  q=(ztop-z_win(ktop))/hin(ktop)
-                  q01=q*(q-1.)
-                  q02=q01+q
-                  q0=1-q01-q02            
-               ELSE
-                  q0 = 1.
-                  q01 = 0.
-                  q02 = 0.
-               ENDIF
-               
-               tsum =((q0*coeffremap(ktop,1)+q01*coeffremap(ktop,2)+q02*coeffremap(ktop,3))-offset)*qtop
-    
-               DO k1= ktop+1,kbox-1
-                  tsum =tsum +(coeffremap(k1,1)-offset)*hin(k1)
-               ENDDO !k1
-               
-               qbot = zbox-z_win(kbox) !partial layer thickness
-               IF(hin(kbox).GT.dpthin) THEN
-                  q=qbot/hin(kbox)
-                  q01=(q-1.)**2
-                  q02=q01-1.+q
-                  q0=1-q01-q02                            
-               ELSE
-                  q0 = 1.0
-                  q01 = 0.
-                  q02 = 0.
-               ENDIF
-              
-               tsum = tsum +((q0*coeffremap(kbox,1)+q01*coeffremap(kbox,2)+q02*coeffremap(kbox,3))-offset)*qbot
-               
-               rpsum=1.0d0/zthk
-               tabout(jk)=offset+tsum*rpsum
-                 
-            ENDIF !single or multiple layers
-         ELSE
-            IF (jk==1) THEN
-               write(*,'(a7,i4,i4,3f12.5)')'problem = ',N,Nout,zthk,z_wout(jk+1),hout(1)
-            ENDIF
-            tabout(jk) = tabout(jk-1)
-             
-         ENDIF !normal:thin layer
-      ENDDO !jk
-            
-      return
-      end subroutine reconstructandremap
-#endif
-
 #endif
    !!======================================================================
Index: /NEMO/branches/2019/dev_r12072_MERGE_OPTION2_2019/src/NST/agrif_oce_interp.F90
===================================================================
--- /NEMO/branches/2019/dev_r12072_MERGE_OPTION2_2019/src/NST/agrif_oce_interp.F90	(revision 12190)
+++ /NEMO/branches/2019/dev_r12072_MERGE_OPTION2_2019/src/NST/agrif_oce_interp.F90	(revision 12191)
@@ -33,15 +33,18 @@
    USE agrif_oce_sponge
    USE lib_mpp
+   USE vremap
  
    IMPLICIT NONE
    PRIVATE
 
-   PUBLIC   Agrif_dyn, Agrif_ssh, Agrif_dyn_ts, Agrif_ssh_ts, Agrif_dta_ts
+   PUBLIC   Agrif_dyn, Agrif_ssh, Agrif_dyn_ts, Agrif_dyn_ts_flux, Agrif_ssh_ts, Agrif_dta_ts
    PUBLIC   Agrif_tra, Agrif_avm
    PUBLIC   interpun , interpvn
    PUBLIC   interptsn, interpsshn, interpavm
    PUBLIC   interpunb, interpvnb , interpub2b, interpvb2b
-   PUBLIC   interpe3t, interpumsk, interpvmsk
-
+   PUBLIC   interpe3t
+#if defined key_vertical
+   PUBLIC   interpht0, interpmbkt
+# endif
    INTEGER ::   bdy_tinterp = 0
 
@@ -78,5 +81,4 @@
       !
       INTEGER ::   ji, jj, jk       ! dummy loop indices
-      INTEGER ::   j1, j2, i1, i2
       INTEGER ::   ibdy1, jbdy1, ibdy2, jbdy2
       REAL(wp), DIMENSION(jpi,jpj) ::   zub, zvb
@@ -93,300 +95,246 @@
       Agrif_UseSpecialValue = .FALSE.
       !
-      ! prevent smoothing in ghost cells
-      i1 =  1   ;   i2 = nlci
-      j1 =  1   ;   j2 = nlcj
-      IF( nbondj == -1 .OR. nbondj == 2 )   j1 = 2 + nbghostcells
-      IF( nbondj == +1 .OR. nbondj == 2 )   j2 = nlcj - nbghostcells - 1
-      IF( nbondi == -1 .OR. nbondi == 2 )   i1 = 2 + nbghostcells 
-      IF( nbondi == +1 .OR. nbondi == 2 )   i2 = nlci - nbghostcells - 1
-
       ! --- West --- !
-      IF( nbondi == -1 .OR. nbondi == 2 ) THEN
-         ibdy1 = 2
-         ibdy2 = 1+nbghostcells 
-         !
-         IF( .NOT.ln_dynspg_ts ) THEN  ! Store transport
-            ua_b(ibdy1:ibdy2,:) = 0._wp
+      ibdy1 = 2
+      ibdy2 = 1+nbghostcells 
+      !
+      IF( .NOT.ln_dynspg_ts ) THEN  ! Store transport
+         DO ji = mi0(ibdy1), mi1(ibdy2)
+            ua_b(ji,:) = 0._wp
+
             DO jk = 1, jpkm1
                DO jj = 1, jpj
-                  ua_b(ibdy1:ibdy2,jj) = ua_b(ibdy1:ibdy2,jj) & 
-                      & + e3u_a(ibdy1:ibdy2,jj,jk) * ua(ibdy1:ibdy2,jj,jk) * umask(ibdy1:ibdy2,jj,jk)
-               END DO
-            END DO
+                  ua_b(ji,jj) = ua_b(ji,jj) + e3u_a(ji,jj,jk) * ua(ji,jj,jk) * umask(ji,jj,jk)
+               END DO
+            END DO
+
             DO jj = 1, jpj
-               ua_b(ibdy1:ibdy2,jj) = ua_b(ibdy1:ibdy2,jj) * r1_hu_a(ibdy1:ibdy2,jj)
-            END DO
-         ENDIF
-         !
-         IF( .NOT.lk_agrif_clp ) THEN
-            DO jk=1,jpkm1              ! Smooth
-               DO jj=j1,j2
-                  ua(ibdy2,jj,jk) = 0.25_wp*(ua(ibdy2-1,jj,jk)+2._wp*ua(ibdy2,jj,jk)+ua(ibdy2+1,jj,jk))
-               END DO
-            END DO
-         ENDIF
-         !
-         zub(ibdy1:ibdy2,:) = 0._wp    ! Correct transport
+               ua_b(ji,jj) = ua_b(ji,jj) * r1_hu_a(ji,jj)
+            END DO
+         END DO
+      ENDIF
+      !
+      DO ji = mi0(ibdy1), mi1(ibdy2)
+         zub(ji,:) = 0._wp    ! Correct transport
          DO jk = 1, jpkm1
             DO jj = 1, jpj
-               zub(ibdy1:ibdy2,jj) = zub(ibdy1:ibdy2,jj) & 
-                  & + e3u_a(ibdy1:ibdy2,jj,jk)  * ua(ibdy1:ibdy2,jj,jk)*umask(ibdy1:ibdy2,jj,jk)
+               zub(ji,jj) = zub(ji,jj) & 
+                  & + e3u_a(ji,jj,jk)  * ua(ji,jj,jk)*umask(ji,jj,jk)
             END DO
          END DO
          DO jj=1,jpj
-            zub(ibdy1:ibdy2,jj) = zub(ibdy1:ibdy2,jj) * r1_hu_a(ibdy1:ibdy2,jj)
+            zub(ji,jj) = zub(ji,jj) * r1_hu_a(ji,jj)
          END DO
             
          DO jk = 1, jpkm1
             DO jj = 1, jpj
-               ua(ibdy1:ibdy2,jj,jk) = ( ua(ibdy1:ibdy2,jj,jk) &
-                 & + ua_b(ibdy1:ibdy2,jj)-zub(ibdy1:ibdy2,jj)) * umask(ibdy1:ibdy2,jj,jk)
-            END DO
-         END DO
+               ua(ji,jj,jk) = ( ua(ji,jj,jk) + ua_b(ji,jj)-zub(ji,jj)) * umask(ji,jj,jk)
+            END DO
+         END DO
+      END DO
             
-         IF( ln_dynspg_ts ) THEN       ! Set tangential velocities to time splitting estimate
-            zvb(ibdy1:ibdy2,:) = 0._wp
+      IF( ln_dynspg_ts ) THEN       ! Set tangential velocities to time splitting estimate
+         DO ji = mi0(ibdy1), mi1(ibdy2)
+            zvb(ji,:) = 0._wp
             DO jk = 1, jpkm1
                DO jj = 1, jpj
-                  zvb(ibdy1:ibdy2,jj) = zvb(ibdy1:ibdy2,jj) & 
-                     & + e3v_a(ibdy1:ibdy2,jj,jk) * va(ibdy1:ibdy2,jj,jk) * vmask(ibdy1:ibdy2,jj,jk)
+                  zvb(ji,jj) = zvb(ji,jj) + e3v_a(ji,jj,jk) * va(ji,jj,jk) * vmask(ji,jj,jk)
                END DO
             END DO
             DO jj = 1, jpj
-               zvb(ibdy1:ibdy2,jj) = zvb(ibdy1:ibdy2,jj) * r1_hv_a(ibdy1:ibdy2,jj)
+               zvb(ji,jj) = zvb(ji,jj) * r1_hv_a(ji,jj)
             END DO
             DO jk = 1, jpkm1
                DO jj = 1, jpj
-                  va(ibdy1:ibdy2,jj,jk) = ( va(ibdy1:ibdy2,jj,jk) & 
-                    & + va_b(ibdy1:ibdy2,jj)-zvb(ibdy1:ibdy2,jj))*vmask(ibdy1:ibdy2,jj,jk)
-               END DO
-            END DO
-         ENDIF
-         !
-         DO jk = 1, jpkm1              ! Mask domain edges
-            DO jj = 1, jpj
-               ua(1,jj,jk) = 0._wp
-               va(1,jj,jk) = 0._wp
-            END DO
-         END DO 
+                  va(ji,jj,jk) = ( va(ji,jj,jk) + va_b(ji,jj)-zvb(ji,jj))*vmask(ji,jj,jk)
+               END DO
+            END DO
+         END DO
       ENDIF
 
       ! --- East --- !
-      IF( nbondi ==  1 .OR. nbondi == 2 ) THEN
-         ibdy1 = nlci-1-nbghostcells
-         ibdy2 = nlci-2 
-         !
-         IF( .NOT.ln_dynspg_ts ) THEN  ! Store transport
-            ua_b(ibdy1:ibdy2,:) = 0._wp
+      ibdy1 = jpiglo-1-nbghostcells
+      ibdy2 = jpiglo-2 
+      !
+      IF( .NOT.ln_dynspg_ts ) THEN  ! Store transport
+         DO ji = mi0(ibdy1), mi1(ibdy2)
+            ua_b(ji,:) = 0._wp
             DO jk = 1, jpkm1
                DO jj = 1, jpj
-                  ua_b(ibdy1:ibdy2,jj) = ua_b(ibdy1:ibdy2,jj) & 
-                      & + e3u_a(ibdy1:ibdy2,jj,jk) * ua(ibdy1:ibdy2,jj,jk) * umask(ibdy1:ibdy2,jj,jk)
+                  ua_b(ji,jj) = ua_b(ji,jj) & 
+                      & + e3u_a(ji,jj,jk) * ua(ji,jj,jk) * umask(ji,jj,jk)
                END DO
             END DO
             DO jj = 1, jpj
-               ua_b(ibdy1:ibdy2,jj) = ua_b(ibdy1:ibdy2,jj) * r1_hu_a(ibdy1:ibdy2,jj)
-            END DO
-         ENDIF
-         !
-         IF( .NOT.lk_agrif_clp ) THEN
-            DO jk=1,jpkm1              ! Smooth
-               DO jj=j1,j2
-                  ua(ibdy1,jj,jk) = 0.25_wp*(ua(ibdy1-1,jj,jk)+2._wp*ua(ibdy1,jj,jk)+ua(ibdy1+1,jj,jk))
-               END DO
-            END DO
-         ENDIF
-         !
-         zub(ibdy1:ibdy2,:) = 0._wp    ! Correct transport
+               ua_b(ji,jj) = ua_b(ji,jj) * r1_hu_a(ji,jj)
+            END DO
+         END DO
+      ENDIF
+      !
+      DO ji = mi0(ibdy1), mi1(ibdy2)
+         zub(ji,:) = 0._wp    ! Correct transport
          DO jk = 1, jpkm1
             DO jj = 1, jpj
-               zub(ibdy1:ibdy2,jj) = zub(ibdy1:ibdy2,jj) & 
-                  & + e3u_a(ibdy1:ibdy2,jj,jk)  * ua(ibdy1:ibdy2,jj,jk) * umask(ibdy1:ibdy2,jj,jk)
+               zub(ji,jj) = zub(ji,jj) & 
+                  & + e3u_a(ji,jj,jk)  * ua(ji,jj,jk) * umask(ji,jj,jk)
             END DO
          END DO
          DO jj=1,jpj
-            zub(ibdy1:ibdy2,jj) = zub(ibdy1:ibdy2,jj) * r1_hu_a(ibdy1:ibdy2,jj)
+            zub(ji,jj) = zub(ji,jj) * r1_hu_a(ji,jj)
          END DO
             
          DO jk = 1, jpkm1
             DO jj = 1, jpj
-               ua(ibdy1:ibdy2,jj,jk) = ( ua(ibdy1:ibdy2,jj,jk) & 
-                 & + ua_b(ibdy1:ibdy2,jj)-zub(ibdy1:ibdy2,jj))*umask(ibdy1:ibdy2,jj,jk)
-            END DO
-         END DO
+               ua(ji,jj,jk) = ( ua(ji,jj,jk) & 
+                 & + ua_b(ji,jj)-zub(ji,jj))*umask(ji,jj,jk)
+            END DO
+         END DO
+      END DO
             
-         IF( ln_dynspg_ts ) THEN       ! Set tangential velocities to time splitting estimate
-            ibdy1 = ibdy1 + 1
-            ibdy2 = ibdy2 + 1 
-            zvb(ibdy1:ibdy2,:) = 0._wp
+      IF( ln_dynspg_ts ) THEN       ! Set tangential velocities to time splitting estimate
+         ibdy1 = jpiglo-nbghostcells
+         ibdy2 = jpiglo-1 
+         DO ji = mi0(ibdy1), mi1(ibdy2)
+            zvb(ji,:) = 0._wp
             DO jk = 1, jpkm1
                DO jj = 1, jpj
-                  zvb(ibdy1:ibdy2,jj) = zvb(ibdy1:ibdy2,jj) &
-                     & + e3v_a(ibdy1:ibdy2,jj,jk) * va(ibdy1:ibdy2,jj,jk) * vmask(ibdy1:ibdy2,jj,jk)
+                  zvb(ji,jj) = zvb(ji,jj) &
+                     & + e3v_a(ji,jj,jk) * va(ji,jj,jk) * vmask(ji,jj,jk)
                END DO
             END DO
             DO jj = 1, jpj
-               zvb(ibdy1:ibdy2,jj) = zvb(ibdy1:ibdy2,jj) * r1_hv_a(ibdy1:ibdy2,jj)
+               zvb(ji,jj) = zvb(ji,jj) * r1_hv_a(ji,jj)
             END DO
             DO jk = 1, jpkm1
                DO jj = 1, jpj
-                  va(ibdy1:ibdy2,jj,jk) = ( va(ibdy1:ibdy2,jj,jk) & 
-                      & + va_b(ibdy1:ibdy2,jj)-zvb(ibdy1:ibdy2,jj)) * vmask(ibdy1:ibdy2,jj,jk)
-               END DO
-            END DO
-         ENDIF
-         !
-         DO jk = 1, jpkm1              ! Mask domain edges
-            DO jj = 1, jpj
-               ua(nlci-1,jj,jk) = 0._wp
-               va(nlci  ,jj,jk) = 0._wp
-            END DO
-         END DO 
+                  va(ji,jj,jk) = ( va(ji,jj,jk) & 
+                      & + va_b(ji,jj)-zvb(ji,jj)) * vmask(ji,jj,jk)
+               END DO
+            END DO
+         END DO
       ENDIF
 
       ! --- South --- !
-      IF( nbondj == -1 .OR. nbondj == 2 ) THEN
-         jbdy1 = 2
-         jbdy2 = 1+nbghostcells 
-         !
-         IF( .NOT.ln_dynspg_ts ) THEN  ! Store transport
-            va_b(:,jbdy1:jbdy2) = 0._wp
+      jbdy1 = 2
+      jbdy2 = 1+nbghostcells 
+      !
+      IF( .NOT.ln_dynspg_ts ) THEN  ! Store transport
+         DO jj = mj0(jbdy1), mj1(jbdy2)
+            va_b(:,jj) = 0._wp
             DO jk = 1, jpkm1
                DO ji = 1, jpi
-                  va_b(ji,jbdy1:jbdy2) = va_b(ji,jbdy1:jbdy2) & 
-                      & + e3v_a(ji,jbdy1:jbdy2,jk) * va(ji,jbdy1:jbdy2,jk) * vmask(ji,jbdy1:jbdy2,jk)
+                  va_b(ji,jj) = va_b(ji,jj) & 
+                      & + e3v_a(ji,jj,jk) * va(ji,jj,jk) * vmask(ji,jj,jk)
                END DO
             END DO
             DO ji=1,jpi
-               va_b(ji,jbdy1:jbdy2) = va_b(ji,jbdy1:jbdy2) * r1_hv_a(ji,jbdy1:jbdy2)
-            END DO
-         ENDIF
-         !
-         IF ( .NOT.lk_agrif_clp ) THEN
-            DO jk = 1, jpkm1           ! Smooth
-               DO ji = i1, i2
-                  va(ji,jbdy2,jk) = 0.25_wp*(va(ji,jbdy2-1,jk)+2._wp*va(ji,jbdy2,jk)+va(ji,jbdy2+1,jk))
-               END DO
-            END DO
-         ENDIF
-         !
-         zvb(:,jbdy1:jbdy2) = 0._wp    ! Correct transport
+               va_b(ji,jj) = va_b(ji,jj) * r1_hv_a(ji,jj)     
+            END DO
+         END DO
+      ENDIF
+      !
+      DO jj = mj0(jbdy1), mj1(jbdy2)
+         zvb(:,jj) = 0._wp    ! Correct transport
          DO jk=1,jpkm1
             DO ji=1,jpi
-               zvb(ji,jbdy1:jbdy2) = zvb(ji,jbdy1:jbdy2) & 
-                  & + e3v_a(ji,jbdy1:jbdy2,jk) * va(ji,jbdy1:jbdy2,jk) * vmask(ji,jbdy1:jbdy2,jk)
+               zvb(ji,jj) = zvb(ji,jj) & 
+                  & + e3v_a(ji,jj,jk) * va(ji,jj,jk) * vmask(ji,jj,jk)
             END DO
          END DO
          DO ji = 1, jpi
-            zvb(ji,jbdy1:jbdy2) = zvb(ji,jbdy1:jbdy2) * r1_hv_a(ji,jbdy1:jbdy2)
+            zvb(ji,jj) = zvb(ji,jj) * r1_hv_a(ji,jj)
          END DO
 
          DO jk = 1, jpkm1
             DO ji = 1, jpi
-               va(ji,jbdy1:jbdy2,jk) = ( va(ji,jbdy1:jbdy2,jk) & 
-                 & + va_b(ji,jbdy1:jbdy2) - zvb(ji,jbdy1:jbdy2) ) * vmask(ji,jbdy1:jbdy2,jk)
-            END DO
-         END DO
+               va(ji,jj,jk) = ( va(ji,jj,jk) & 
+                 & + va_b(ji,jj) - zvb(ji,jj) ) * vmask(ji,jj,jk)
+            END DO
+         END DO
+      END DO
             
-         IF( ln_dynspg_ts ) THEN       ! Set tangential velocities to time splitting estimate
-            zub(:,jbdy1:jbdy2) = 0._wp
+      IF( ln_dynspg_ts ) THEN       ! Set tangential velocities to time splitting estimate
+         DO jj = mj0(jbdy1), mj1(jbdy2)
+            zub(:,jj) = 0._wp
             DO jk = 1, jpkm1
                DO ji = 1, jpi
-                  zub(ji,jbdy1:jbdy2) = zub(ji,jbdy1:jbdy2) & 
-                     & + e3u_a(ji,jbdy1:jbdy2,jk) * ua(ji,jbdy1:jbdy2,jk) * umask(ji,jbdy1:jbdy2,jk)
+                  zub(ji,jj) = zub(ji,jj) & 
+                     & + e3u_a(ji,jj,jk) * ua(ji,jj,jk) * umask(ji,jj,jk)
                END DO
             END DO
             DO ji = 1, jpi
-               zub(ji,jbdy1:jbdy2) = zub(ji,jbdy1:jbdy2) * r1_hu_a(ji,jbdy1:jbdy2)
+               zub(ji,jj) = zub(ji,jj) * r1_hu_a(ji,jj)
             END DO
                
             DO jk = 1, jpkm1
                DO ji = 1, jpi
-                  ua(ji,jbdy1:jbdy2,jk) = ( ua(ji,jbdy1:jbdy2,jk) & 
-                    & + ua_b(ji,jbdy1:jbdy2) - zub(ji,jbdy1:jbdy2) ) * umask(ji,jbdy1:jbdy2,jk)
-               END DO
-            END DO
-         ENDIF
-         !
-         DO jk = 1, jpkm1              ! Mask domain edges
-            DO ji = 1, jpi
-               ua(ji,1,jk) = 0._wp
-               va(ji,1,jk) = 0._wp
-            END DO
-         END DO 
+                  ua(ji,jj,jk) = ( ua(ji,jj,jk) & 
+                    & + ua_b(ji,jj) - zub(ji,jj) ) * umask(ji,jj,jk)
+               END DO
+            END DO
+         END DO
       ENDIF
 
       ! --- North --- !
-      IF( nbondj ==  1 .OR. nbondj == 2 ) THEN
-         jbdy1 = nlcj-1-nbghostcells
-         jbdy2 = nlcj-2 
-         !
-         IF( .NOT.ln_dynspg_ts ) THEN  ! Store transport
-            va_b(:,jbdy1:jbdy2) = 0._wp
+      jbdy1 = jpjglo-1-nbghostcells
+      jbdy2 = jpjglo-2 
+      !
+      IF( .NOT.ln_dynspg_ts ) THEN  ! Store transport
+         DO jj = mj0(jbdy1), mj1(jbdy2)
+            va_b(:,jj) = 0._wp
             DO jk = 1, jpkm1
                DO ji = 1, jpi
-                  va_b(ji,jbdy1:jbdy2) = va_b(ji,jbdy1:jbdy2) & 
-                      & + e3v_a(ji,jbdy1:jbdy2,jk) * va(ji,jbdy1:jbdy2,jk) * vmask(ji,jbdy1:jbdy2,jk)
+                  va_b(ji,jj) = va_b(ji,jj) & 
+                      & + e3v_a(ji,jj,jk) * va(ji,jj,jk) * vmask(ji,jj,jk)
                END DO
             END DO
             DO ji=1,jpi
-               va_b(ji,jbdy1:jbdy2) = va_b(ji,jbdy1:jbdy2) * r1_hv_a(ji,jbdy1:jbdy2)
-            END DO
-         ENDIF
-         !
-         IF ( .NOT.lk_agrif_clp ) THEN
-            DO jk = 1, jpkm1           ! Smooth
-               DO ji = i1, i2
-                  va(ji,jbdy1,jk) = 0.25_wp*(va(ji,jbdy1-1,jk)+2._wp*va(ji,jbdy1,jk)+va(ji,jbdy1+1,jk))
-               END DO
-            END DO
-         ENDIF
-         !
-         zvb(:,jbdy1:jbdy2) = 0._wp    ! Correct transport
+               va_b(ji,jj) = va_b(ji,jj) * r1_hv_a(ji,jj)
+            END DO
+         END DO
+      ENDIF
+      !
+      DO jj = mj0(jbdy1), mj1(jbdy2)
+         zvb(:,jj) = 0._wp    ! Correct transport
          DO jk=1,jpkm1
             DO ji=1,jpi
-               zvb(ji,jbdy1:jbdy2) = zvb(ji,jbdy1:jbdy2) & 
-                  & + e3v_a(ji,jbdy1:jbdy2,jk) * va(ji,jbdy1:jbdy2,jk) * vmask(ji,jbdy1:jbdy2,jk)
+               zvb(ji,jj) = zvb(ji,jj) & 
+                  & + e3v_a(ji,jj,jk) * va(ji,jj,jk) * vmask(ji,jj,jk)
             END DO
          END DO
          DO ji = 1, jpi
-            zvb(ji,jbdy1:jbdy2) = zvb(ji,jbdy1:jbdy2) * r1_hv_a(ji,jbdy1:jbdy2)
+            zvb(ji,jj) = zvb(ji,jj) * r1_hv_a(ji,jj)
          END DO
 
          DO jk = 1, jpkm1
             DO ji = 1, jpi
-               va(ji,jbdy1:jbdy2,jk) = ( va(ji,jbdy1:jbdy2,jk) & 
-                 & + va_b(ji,jbdy1:jbdy2) - zvb(ji,jbdy1:jbdy2) ) * vmask(ji,jbdy1:jbdy2,jk)
-            END DO
-         END DO
+               va(ji,jj,jk) = ( va(ji,jj,jk) & 
+                 & + va_b(ji,jj) - zvb(ji,jj) ) * vmask(ji,jj,jk)
+            END DO
+         END DO
+      END DO
             
-         IF( ln_dynspg_ts ) THEN       ! Set tangential velocities to time splitting estimate
-            jbdy1 = jbdy1 + 1
-            jbdy2 = jbdy2 + 1 
-            zub(:,jbdy1:jbdy2) = 0._wp
+      IF( ln_dynspg_ts ) THEN       ! Set tangential velocities to time splitting estimate
+         jbdy1 = jpjglo-nbghostcells
+         jbdy2 = jpjglo-1
+         DO jj = mj0(jbdy1), mj1(jbdy2)
+            zub(:,jj) = 0._wp
             DO jk = 1, jpkm1
                DO ji = 1, jpi
-                  zub(ji,jbdy1:jbdy2) = zub(ji,jbdy1:jbdy2) & 
-                     & + e3u_a(ji,jbdy1:jbdy2,jk) * ua(ji,jbdy1:jbdy2,jk) * umask(ji,jbdy1:jbdy2,jk)
+                  zub(ji,jj) = zub(ji,jj) & 
+                     & + e3u_a(ji,jj,jk) * ua(ji,jj,jk) * umask(ji,jj,jk)
                END DO
             END DO
             DO ji = 1, jpi
-               zub(ji,jbdy1:jbdy2) = zub(ji,jbdy1:jbdy2) * r1_hu_a(ji,jbdy1:jbdy2)
+               zub(ji,jj) = zub(ji,jj) * r1_hu_a(ji,jj)
             END DO
                
             DO jk = 1, jpkm1
                DO ji = 1, jpi
-                  ua(ji,jbdy1:jbdy2,jk) = ( ua(ji,jbdy1:jbdy2,jk) & 
-                    & + ua_b(ji,jbdy1:jbdy2) - zub(ji,jbdy1:jbdy2) ) * umask(ji,jbdy1:jbdy2,jk)
-               END DO
-            END DO
-         ENDIF
-         !
-         DO jk = 1, jpkm1              ! Mask domain edges
-            DO ji = 1, jpi
-               ua(ji,nlcj  ,jk) = 0._wp
-               va(ji,nlcj-1,jk) = 0._wp
-            END DO
-         END DO 
+                  ua(ji,jj,jk) = ( ua(ji,jj,jk) & 
+                    & + ua_b(ji,jj) - zub(ji,jj) ) * umask(ji,jj,jk)
+               END DO
+            END DO
+         END DO
       ENDIF
       !
@@ -401,54 +349,129 @@
       !!
       INTEGER :: ji, jj
+      INTEGER :: istart, iend, jstart, jend
       !!----------------------------------------------------------------------  
       !
       IF( Agrif_Root() )   RETURN
       !
-      IF((nbondi == -1).OR.(nbondi == 2)) THEN
+      !--- West ---!
+      istart = 2
+      iend   = nbghostcells+1
+      DO ji = mi0(istart), mi1(iend)
          DO jj=1,jpj
-            va_e(2:nbghostcells+1,jj) = vbdy_w(1:nbghostcells,jj) * hvr_e(2:nbghostcells+1,jj)
-            ! Specified fluxes:
-            ua_e(2:nbghostcells+1,jj) = ubdy_w(1:nbghostcells,jj) * hur_e(2:nbghostcells+1,jj)
-            ! Characteristics method (only if ghostcells=1):
-            !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
-      !
-      IF((nbondi == 1).OR.(nbondi == 2)) THEN
+            va_e(ji,jj) = vbdy(ji,jj) * hvr_e(ji,jj)
+            ua_e(ji,jj) = ubdy(ji,jj) * hur_e(ji,jj)
+         END DO
+      END DO
+      !
+      !--- East ---!
+      istart = jpiglo-nbghostcells
+      iend   = jpiglo-1
+      DO ji = mi0(istart), mi1(iend)
          DO jj=1,jpj
-            va_e(nlci-nbghostcells:nlci-1,jj)   = vbdy_e(1:nbghostcells,jj) * hvr_e(nlci-nbghostcells:nlci-1,jj)
-            ! Specified fluxes:
-            ua_e(nlci-nbghostcells-1:nlci-2,jj) = ubdy_e(1:nbghostcells,jj) * hur_e(nlci-nbghostcells-1:nlci-2,jj)
-            ! Characteristics method (only if ghostcells=1):
-            !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
-      !
-      IF((nbondj == -1).OR.(nbondj == 2)) THEN
+            va_e(ji,jj) = vbdy(ji,jj) * hvr_e(ji,jj)
+         END DO
+      END DO
+      istart = jpiglo-nbghostcells-1
+      iend   = jpiglo-2
+      DO ji = mi0(istart), mi1(iend)
+         DO jj=1,jpj
+            ua_e(ji,jj) = ubdy(ji,jj) * hur_e(ji,jj)
+         END DO
+      END DO
+      !
+      !--- South ---!
+      jstart = 2
+      jend   = nbghostcells+1
+      DO jj = mj0(jstart), mj1(jend)
          DO ji=1,jpi
-            ua_e(ji,2:nbghostcells+1) = ubdy_s(ji,1:nbghostcells) * hur_e(ji,2:nbghostcells+1)
-            ! Specified fluxes:
-            va_e(ji,2:nbghostcells+1) = vbdy_s(ji,1:nbghostcells) * hvr_e(ji,2:nbghostcells+1)
-            ! Characteristics method (only if ghostcells=1):
-            !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
-      !
-      IF((nbondj == 1).OR.(nbondj == 2)) THEN
+            ua_e(ji,jj) = ubdy(ji,jj) * hur_e(ji,jj)
+            va_e(ji,jj) = vbdy(ji,jj) * hvr_e(ji,jj)
+         END DO
+      END DO
+      !
+      !--- North ---!
+      jstart = jpjglo-nbghostcells
+      jend   = jpjglo-1
+      DO jj = mj0(jstart), mj1(jend)
          DO ji=1,jpi
-            ua_e(ji,nlcj-nbghostcells:nlcj-1)   = ubdy_n(ji,1:nbghostcells) * hur_e(ji,nlcj-nbghostcells:nlcj-1)
-            ! Specified fluxes:
-            va_e(ji,nlcj-nbghostcells-1:nlcj-2) = vbdy_n(ji,1:nbghostcells) * hvr_e(ji,nlcj-nbghostcells-1:nlcj-2)
-            ! Characteristics method (only if ghostcells=1):
-            !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
+            ua_e(ji,jj) = ubdy(ji,jj) * hur_e(ji,jj)
+         END DO
+      END DO
+      jstart = jpjglo-nbghostcells-1
+      jend   = jpjglo-2
+      DO jj = mj0(jstart), mj1(jend)
+         DO ji=1,jpi
+            va_e(ji,jj) = vbdy(ji,jj) * hvr_e(ji,jj)
+         END DO
+      END DO
       !
    END SUBROUTINE Agrif_dyn_ts
 
+   SUBROUTINE Agrif_dyn_ts_flux( jn, zu, zv )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE Agrif_dyn_ts_flux  ***
+      !!----------------------------------------------------------------------  
+      INTEGER, INTENT(in) ::   jn
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) ::   zu, zv
+      !!
+      INTEGER :: ji, jj
+      INTEGER :: istart, iend, jstart, jend
+      !!----------------------------------------------------------------------  
+      !
+      IF( Agrif_Root() )   RETURN
+      !
+      !--- West ---!
+      istart = 2
+      iend   = nbghostcells+1
+      DO ji = mi0(istart), mi1(iend)
+         DO jj=1,jpj
+            zv(ji,jj) = vbdy(ji,jj) * e1v(ji,jj)
+            zu(ji,jj) = ubdy(ji,jj) * e2u(ji,jj)
+         END DO
+      END DO
+      !
+      !--- East ---!
+      istart = jpiglo-nbghostcells
+      iend   = jpiglo-1
+      DO ji = mi0(istart), mi1(iend)
+         DO jj=1,jpj
+            zv(ji,jj) = vbdy(ji,jj) * e1v(ji,jj)
+         END DO
+      END DO
+      istart = jpiglo-nbghostcells-1
+      iend   = jpiglo-2
+      DO ji = mi0(istart), mi1(iend)
+         DO jj=1,jpj
+            zu(ji,jj) = ubdy(ji,jj) * e2u(ji,jj)
+         END DO
+      END DO
+      !
+      !--- South ---!
+      jstart = 2
+      jend   = nbghostcells+1
+      DO jj = mj0(jstart), mj1(jend)
+         DO ji=1,jpi
+            zu(ji,jj) = ubdy(ji,jj) * e2u(ji,jj)
+            zv(ji,jj) = vbdy(ji,jj) * e1v(ji,jj)
+         END DO
+      END DO
+      !
+      !--- North ---!
+      jstart = jpjglo-nbghostcells
+      jend   = jpjglo-1
+      DO jj = mj0(jstart), mj1(jend)
+         DO ji=1,jpi
+            zu(ji,jj) = ubdy(ji,jj) * e2u(ji,jj)
+         END DO
+      END DO
+      jstart = jpjglo-nbghostcells-1
+      jend   = jpjglo-2
+      DO jj = mj0(jstart), mj1(jend)
+         DO ji=1,jpi
+            zv(ji,jj) = vbdy(ji,jj) * e1v(ji,jj)
+         END DO
+      END DO
+      !
+   END SUBROUTINE Agrif_dyn_ts_flux
 
    SUBROUTINE Agrif_dta_ts( kt )
@@ -470,23 +493,26 @@
       !
       ! Interpolate barotropic fluxes
-      Agrif_SpecialValue=0._wp
+      Agrif_SpecialValue = 0._wp
       Agrif_UseSpecialValue = ln_spc_dyn
+      !
+      ! Set bdy time interpolation stage to 0 (latter incremented locally do deal with corners)
+      utint_stage(:,:) = 0
+      vtint_stage(:,:) = 0
       !
       IF( ll_int_cons ) THEN  ! Conservative interpolation
          ! order matters here !!!!!!
          CALL Agrif_Bc_variable( ub2b_interp_id, calledweight=1._wp, procname=interpub2b ) ! Time integrated
-         CALL Agrif_Bc_variable( vb2b_interp_id, calledweight=1._wp, procname=interpvb2b )
+         CALL Agrif_Bc_variable( vb2b_interp_id, calledweight=1._wp, procname=interpvb2b ) 
+         !
          bdy_tinterp = 1
          CALL Agrif_Bc_variable( unb_id        , calledweight=1._wp, procname=interpunb  ) ! After
-         CALL Agrif_Bc_variable( vnb_id        , calledweight=1._wp, procname=interpvnb  )
+         CALL Agrif_Bc_variable( vnb_id        , calledweight=1._wp, procname=interpvnb  )  
+         !
          bdy_tinterp = 2
          CALL Agrif_Bc_variable( unb_id        , calledweight=0._wp, procname=interpunb  ) ! Before
-         CALL Agrif_Bc_variable( vnb_id        , calledweight=0._wp, procname=interpvnb  )         
+         CALL Agrif_Bc_variable( vnb_id        , calledweight=0._wp, procname=interpvnb  )   
       ELSE ! Linear interpolation
-         bdy_tinterp = 0
-         ubdy_w(:,:) = 0._wp   ;   vbdy_w(:,:) = 0._wp 
-         ubdy_e(:,:) = 0._wp   ;   vbdy_e(:,:) = 0._wp 
-         ubdy_n(:,:) = 0._wp   ;   vbdy_n(:,:) = 0._wp 
-         ubdy_s(:,:) = 0._wp   ;   vbdy_s(:,:) = 0._wp
+         !
+         ubdy(:,:) = 0._wp   ;   vbdy(:,:) = 0._wp 
          CALL Agrif_Bc_variable( unb_id, procname=interpunb )
          CALL Agrif_Bc_variable( vnb_id, procname=interpvnb )
@@ -503,5 +529,6 @@
       INTEGER, INTENT(in) ::   kt
       !
-      INTEGER  :: ji, jj, indx, indy
+      INTEGER  :: ji, jj
+      INTEGER  :: istart, iend, jstart, jend
       !!----------------------------------------------------------------------  
       !
@@ -516,42 +543,38 @@
       !
       ! --- West --- !
-      IF((nbondi == -1).OR.(nbondi == 2)) THEN
-         indx = 1+nbghostcells
+      istart = 2
+      iend   = 1 + nbghostcells
+      DO ji = mi0(istart), mi1(iend)
          DO jj = 1, jpj
-            DO ji = 2, indx
-               ssha(ji,jj) = hbdy_w(ji-1,jj)
-            ENDDO
+            ssha(ji,jj) = hbdy(ji,jj)
          ENDDO
-      ENDIF
+      ENDDO
       !
       ! --- East --- !
-      IF((nbondi == 1).OR.(nbondi == 2)) THEN
-         indx = nlci-nbghostcells
+      istart = jpiglo - nbghostcells
+      iend   = jpiglo - 1
+      DO ji = mi0(istart), mi1(iend)
          DO jj = 1, jpj
-            DO ji = indx, nlci-1
-               ssha(ji,jj) = hbdy_e(ji-indx+1,jj)
-            ENDDO
+            ssha(ji,jj) = hbdy(ji,jj)
          ENDDO
-      ENDIF
+      ENDDO
       !
       ! --- South --- !
-      IF((nbondj == -1).OR.(nbondj == 2)) THEN
-         indy = 1+nbghostcells
-         DO jj = 2, indy
-            DO ji = 1, jpi
-               ssha(ji,jj) = hbdy_s(ji,jj-1)
-            ENDDO
+      jstart = 2
+      jend   = 1 + nbghostcells
+      DO jj = mj0(jstart), mj1(jend)
+         DO ji = 1, jpi
+            ssha(ji,jj) = hbdy(ji,jj)
          ENDDO
-      ENDIF
+      ENDDO
       !
       ! --- North --- !
-      IF((nbondj == 1).OR.(nbondj == 2)) THEN
-         indy = nlcj-nbghostcells
-         DO jj = indy, nlcj-1
-            DO ji = 1, jpi
-               ssha(ji,jj) = hbdy_n(ji,jj-indy+1)
-            ENDDO
+      jstart = jpjglo - nbghostcells
+      jend   = jpjglo - 1
+      DO jj = mj0(jstart), mj1(jend)
+         DO ji = 1, jpi
+            ssha(ji,jj) = hbdy(ji,jj)
          ENDDO
-      ENDIF
+      ENDDO
       !
    END SUBROUTINE Agrif_ssh
@@ -564,49 +587,45 @@
       INTEGER, INTENT(in) ::   jn
       !!
-      INTEGER :: ji, jj, indx, indy
-      !!----------------------------------------------------------------------  
-      !! clem ghost (starting at i,j=1 is important I think otherwise you introduce a grad(ssh)/=0 at point 2)
+      INTEGER :: ji, jj
+      INTEGER  :: istart, iend, jstart, jend
+      !!----------------------------------------------------------------------  
       !
       IF( Agrif_Root() )   RETURN
       !
       ! --- West --- !
-      IF((nbondi == -1).OR.(nbondi == 2)) THEN
-         indx = 1+nbghostcells
+      istart = 2
+      iend   = 1+nbghostcells
+      DO ji = mi0(istart), mi1(iend)
          DO jj = 1, jpj
-            DO ji = 2, indx
-               ssha_e(ji,jj) = hbdy_w(ji-1,jj)
-            ENDDO
+            ssha_e(ji,jj) = hbdy(ji,jj)
          ENDDO
-      ENDIF
+      ENDDO
       !
       ! --- East --- !
-      IF((nbondi == 1).OR.(nbondi == 2)) THEN
-         indx = nlci-nbghostcells
+      istart = jpiglo - nbghostcells
+      iend   = jpiglo - 1
+      DO ji = mi0(istart), mi1(iend)
          DO jj = 1, jpj
-            DO ji = indx, nlci-1
-               ssha_e(ji,jj) = hbdy_e(ji-indx+1,jj)
-            ENDDO
+            ssha_e(ji,jj) = hbdy(ji,jj)
          ENDDO
-      ENDIF
+      ENDDO
       !
       ! --- South --- !
-      IF((nbondj == -1).OR.(nbondj == 2)) THEN
-         indy = 1+nbghostcells
-         DO jj = 2, indy
-            DO ji = 1, jpi
-               ssha_e(ji,jj) = hbdy_s(ji,jj-1)
-            ENDDO
+      jstart = 2
+      jend   = 1+nbghostcells
+      DO jj = mj0(jstart), mj1(jend)
+         DO ji = 1, jpi
+            ssha_e(ji,jj) = hbdy(ji,jj)
          ENDDO
-      ENDIF
+      ENDDO
       !
       ! --- North --- !
-      IF((nbondj == 1).OR.(nbondj == 2)) THEN
-         indy = nlcj-nbghostcells
-         DO jj = indy, nlcj-1
-            DO ji = 1, jpi
-               ssha_e(ji,jj) = hbdy_n(ji,jj-indy+1)
-            ENDDO
+      jstart = jpjglo - nbghostcells
+      jend   = jpjglo - 1
+      DO jj = mj0(jstart), mj1(jend)
+         DO ji = 1, jpi
+            ssha_e(ji,jj) = hbdy(ji,jj)
          ENDDO
-      ENDIF
+      ENDDO
       !
    END SUBROUTINE Agrif_ssh_ts
@@ -634,5 +653,5 @@
    
 
-   SUBROUTINE interptsn( ptab, i1, i2, j1, j2, k1, k2, n1, n2, before, nb, ndir )
+   SUBROUTINE interptsn( ptab, i1, i2, j1, j2, k1, k2, n1, n2, before )
       !!----------------------------------------------------------------------
       !!                  *** ROUTINE interptsn ***
@@ -641,16 +660,13 @@
       INTEGER                                     , INTENT(in   ) ::   i1, i2, j1, j2, k1, k2, n1, n2
       LOGICAL                                     , INTENT(in   ) ::   before
-      INTEGER                                     , INTENT(in   ) ::   nb , ndir
-      !
-      INTEGER  ::   ji, jj, jk, jn, iref, jref, ibdy, jbdy   ! dummy loop indices
-      INTEGER  ::   imin, imax, jmin, jmax, N_in, N_out
-      REAL(wp) ::   zrho, z1, z2, z3, z4, z5, z6, z7
-      LOGICAL :: western_side, eastern_side,northern_side,southern_side
+      !
+      INTEGER  ::   ji, jj, jk, jn  ! dummy loop indices
+      INTEGER  ::   N_in, N_out
       ! vertical interpolation:
-      REAL(wp), DIMENSION(i1:i2,j1:j2,1:jpk,n1:n2) :: ptab_child
-      REAL(wp), DIMENSION(k1:k2,n1:n2-1) :: tabin
+      REAL(wp) :: zhtot
+      REAL(wp), DIMENSION(k1:k2,1:jpts) :: tabin
       REAL(wp), DIMENSION(k1:k2) :: h_in
       REAL(wp), DIMENSION(1:jpk) :: h_out
-      REAL(wp) :: h_diff
+      !!----------------------------------------------------------------------
 
       IF( before ) THEN         
@@ -666,187 +682,74 @@
 
 # if defined key_vertical
+        ! Interpolate thicknesses
+        ! Warning: these are masked, hence extrapolated prior interpolation.
         DO jk=k1,k2
            DO jj=j1,j2
               DO ji=i1,i2
-                 ptab(ji,jj,jk,jpts+1) = tmask(ji,jj,jk) * e3t_n(ji,jj,jk) 
+                  ptab(ji,jj,jk,jpts+1) = tmask(ji,jj,jk) * e3t_n(ji,jj,jk)
               END DO
            END DO
         END DO
+
+        ! Extrapolate thicknesses in partial bottom cells:
+        ! Set them to Agrif_SpecialValue (0.). Correct bottom thicknesses are retrieved later on
+        IF (ln_zps) THEN
+           DO jj=j1,j2
+              DO ji=i1,i2
+                  jk = mbkt(ji,jj)
+                  ptab(ji,jj,jk,jpts+1) = 0._wp
+              END DO
+           END DO           
+        END IF
+     
+        ! Save ssh at last level:
+        IF (.NOT.ln_linssh) THEN
+           ptab(i1:i2,j1:j2,k2,jpts+1) = sshn(i1:i2,j1:j2)*tmask(i1:i2,j1:j2,1) 
+        ELSE
+           ptab(i1:i2,j1:j2,k2,jpts+1) = 0._wp
+        END IF      
 # endif
       ELSE 
 
-         western_side  = (nb == 1).AND.(ndir == 1)   ;   eastern_side  = (nb == 1).AND.(ndir == 2)
-         southern_side = (nb == 2).AND.(ndir == 1)   ;   northern_side = (nb == 2).AND.(ndir == 2)
-
-# if defined key_vertical              
+# if defined key_vertical 
+         IF (ln_linssh) ptab(i1:i2,j1:j2,k2,n2) = 0._wp 
+            
          DO jj=j1,j2
             DO ji=i1,i2
-               iref = ji
-               jref = jj
-               if(western_side) iref=MAX(2,ji)
-               if(eastern_side) iref=MIN(nlci-1,ji)
-               if(southern_side) jref=MAX(2,jj)
-               if(northern_side) jref=MIN(nlcj-1,jj)
-               N_in = 0
-               DO jk=k1,k2 !k2 = jpk of parent grid
-                  IF (ptab(ji,jj,jk,n2) == 0) EXIT
-                  N_in = N_in + 1
+               tsa(ji,jj,:,:) = 0._wp
+               N_in = mbkt_parent(ji,jj)
+               zhtot = 0._wp
+               DO jk=1,N_in !k2 = jpk of parent grid
+                  IF (jk==N_in) THEN
+                     h_in(jk) = ht0_parent(ji,jj) + ptab(ji,jj,k2,n2) - zhtot
+                  ELSE
+                     h_in(jk) = ptab(ji,jj,jk,n2)
+                  ENDIF
+                  zhtot = zhtot + h_in(jk)
                   tabin(jk,:) = ptab(ji,jj,jk,n1:n2-1)
-                  h_in(N_in) = ptab(ji,jj,jk,n2)
                END DO
                N_out = 0
                DO jk=1,jpk ! jpk of child grid
-                  IF (tmask(iref,jref,jk) == 0) EXIT 
+                  IF (tmask(ji,jj,jk) == 0._wp) EXIT 
                   N_out = N_out + 1
-                  h_out(jk) = e3t_n(iref,jref,jk)
+                  h_out(jk) = e3t_a(ji,jj,jk)
                ENDDO
-               IF (N_in > 0) THEN
-                  DO jn=1,jpts
-                     call reconstructandremap(tabin(1:N_in,jn),h_in,ptab_child(ji,jj,1:N_out,jn),h_out,N_in,N_out)
-                  ENDDO
+               IF (N_in*N_out > 0) THEN
+                  CALL reconstructandremap(tabin(1:N_in,1:jpts),h_in(1:N_in),tsa(ji,jj,1:N_out,1:jpts),h_out(1:N_out),N_in,N_out,jpts)
                ENDIF
             ENDDO
          ENDDO
 # else
-         ptab_child(i1:i2,j1:j2,1:jpk,1:jpts) = ptab(i1:i2,j1:j2,1:jpk,1:jpts)
-# endif
          !
          DO jn=1, jpts
-            tsa(i1:i2,j1:j2,1:jpk,jn)=ptab_child(i1:i2,j1:j2,1:jpk,jn)*tmask(i1:i2,j1:j2,1:jpk) 
-         END DO
-
-         IF ( .NOT.lk_agrif_clp ) THEN 
-            !
-            imin = i1 ; imax = i2
-            jmin = j1 ; jmax = j2
-            ! 
-            ! Remove CORNERS
-            IF((nbondj == -1).OR.(nbondj == 2)) jmin = 2 + nbghostcells
-            IF((nbondj == +1).OR.(nbondj == 2)) jmax = nlcj - nbghostcells - 1
-            IF((nbondi == -1).OR.(nbondi == 2)) imin = 2 + nbghostcells
-            IF((nbondi == +1).OR.(nbondi == 2)) imax = nlci - nbghostcells - 1      
-            !
-            IF( eastern_side ) THEN
-               zrho = Agrif_Rhox()
-               z1 = ( zrho - 1._wp ) * 0.5_wp                    
-               z3 = ( zrho - 1._wp ) / ( zrho + 1._wp )         
-               z6 = 2._wp * ( zrho - 1._wp ) / ( zrho + 1._wp )
-               z7 =       - ( zrho - 1._wp ) / ( zrho + 3._wp )
-               z2 = 1._wp - z1 ; z4 = 1._wp - z3 ; z5 = 1._wp - z6 - z7
-               !
-               ibdy = nlci-nbghostcells
-               DO jn = 1, jpts
-                  tsa(ibdy+1,jmin:jmax,1:jpkm1,jn) = z1 * ptab_child(ibdy+1,jmin:jmax,1:jpkm1,jn) + z2 * ptab_child(ibdy,jmin:jmax,1:jpkm1,jn)
-                  DO jk = 1, jpkm1
-                     DO jj = jmin,jmax
-                        IF( umask(ibdy-1,jj,jk) == 0._wp ) THEN
-                           tsa(ibdy,jj,jk,jn) = tsa(ibdy+1,jj,jk,jn) * tmask(ibdy,jj,jk)
-                        ELSE
-                           tsa(ibdy,jj,jk,jn)=(z4*tsa(ibdy+1,jj,jk,jn)+z3*tsa(ibdy-1,jj,jk,jn))*tmask(ibdy,jj,jk)
-                           IF( un(ibdy-1,jj,jk) > 0._wp ) THEN
-                              tsa(ibdy,jj,jk,jn)=( z6*tsa(ibdy-1,jj,jk,jn)+z5*tsa(ibdy+1,jj,jk,jn) & 
-                                                 + z7*tsa(ibdy-2,jj,jk,jn) ) * tmask(ibdy,jj,jk)
-                           ENDIF
-                        ENDIF
-                     END DO
-                  END DO
-                  ! Restore ghost points:
-                  tsa(ibdy+1,jmin:jmax,1:jpkm1,jn) = ptab_child(ibdy+1,jmin:jmax,1:jpkm1,jn) * tmask(ibdy+1,jmin:jmax,1:jpkm1)
-               END DO
-            ENDIF
-            ! 
-            IF( northern_side ) THEN
-               zrho = Agrif_Rhoy()
-               z1 = ( zrho - 1._wp ) * 0.5_wp                    
-               z3 = ( zrho - 1._wp ) / ( zrho + 1._wp )         
-               z6 = 2._wp * ( zrho - 1._wp ) / ( zrho + 1._wp )
-               z7 =       - ( zrho - 1._wp ) / ( zrho + 3._wp )
-               z2 = 1._wp - z1 ; z4 = 1._wp - z3 ; z5 = 1._wp - z6 - z7
-               !
-               jbdy = nlcj-nbghostcells         
-               DO jn = 1, jpts
-                  tsa(imin:imax,jbdy+1,1:jpkm1,jn) = z1 * ptab_child(imin:imax,jbdy+1,1:jpkm1,jn) + z2 * ptab_child(imin:imax,jbdy,1:jpkm1,jn)
-                  DO jk = 1, jpkm1
-                     DO ji = imin,imax
-                        IF( vmask(ji,jbdy-1,jk) == 0._wp ) THEN
-                           tsa(ji,jbdy,jk,jn) = tsa(ji,jbdy+1,jk,jn) * tmask(ji,jbdy,jk)
-                        ELSE
-                           tsa(ji,jbdy,jk,jn)=(z4*tsa(ji,jbdy+1,jk,jn)+z3*tsa(ji,jbdy-1,jk,jn))*tmask(ji,jbdy,jk)        
-                           IF (vn(ji,jbdy-1,jk) > 0._wp ) THEN
-                              tsa(ji,jbdy,jk,jn)=( z6*tsa(ji,jbdy-1,jk,jn)+z5*tsa(ji,jbdy+1,jk,jn)  &
-                                                 + z7*tsa(ji,jbdy-2,jk,jn) ) * tmask(ji,jbdy,jk)
-                           ENDIF
-                        ENDIF
-                     END DO
-                  END DO
-                  ! Restore ghost points:
-                  tsa(imin:imax,jbdy+1,1:jpkm1,jn) = ptab_child(imin:imax,jbdy+1,1:jpkm1,jn) * tmask(imin:imax,jbdy+1,1:jpkm1)
-               END DO
-            ENDIF
-            !
-            IF( western_side ) THEN
-               zrho = Agrif_Rhox()
-               z1 = ( zrho - 1._wp ) * 0.5_wp                    
-               z3 = ( zrho - 1._wp ) / ( zrho + 1._wp )         
-               z6 = 2._wp * ( zrho - 1._wp ) / ( zrho + 1._wp )
-               z7 =       - ( zrho - 1._wp ) / ( zrho + 3._wp )
-               z2 = 1._wp - z1 ; z4 = 1._wp - z3 ; z5 = 1._wp - z6 - z7
-               !    
-               ibdy = 1+nbghostcells       
-               DO jn = 1, jpts
-                  tsa(ibdy-1,jmin:jmax,1:jpkm1,jn) = z1 * ptab_child(ibdy-1,jmin:jmax,1:jpkm1,jn) + z2 * ptab_child(ibdy,jmin:jmax,1:jpkm1,jn)
-                  DO jk = 1, jpkm1
-                     DO jj = jmin,jmax
-                        IF( umask(ibdy,jj,jk) == 0._wp ) THEN
-                           tsa(ibdy,jj,jk,jn) = tsa(ibdy-1,jj,jk,jn) * tmask(ibdy,jj,jk)
-                        ELSE
-                           tsa(ibdy,jj,jk,jn)=(z4*tsa(ibdy-1,jj,jk,jn)+z3*tsa(ibdy+1,jj,jk,jn))*tmask(ibdy,jj,jk)        
-                           IF( un(ibdy,jj,jk) < 0._wp ) THEN
-                              tsa(ibdy,jj,jk,jn)=( z6*tsa(ibdy+1,jj,jk,jn)+z5*tsa(ibdy-1,jj,jk,jn) &
-                                                 + z7*tsa(ibdy+2,jj,jk,jn) ) * tmask(ibdy,jj,jk)
-                           ENDIF
-                        ENDIF
-                     END DO
-                  END DO
-                  ! Restore ghost points:
-                  tsa(ibdy-1,jmin:jmax,1:jpkm1,jn) = ptab_child(ibdy-1,jmin:jmax,1:jpkm1,jn) * tmask(ibdy-1,jmin:jmax,1:jpkm1)
-               END DO
-            ENDIF
-            !
-            IF( southern_side ) THEN
-               zrho = Agrif_Rhoy()
-               z1 = ( zrho - 1._wp ) * 0.5_wp                    
-               z3 = ( zrho - 1._wp ) / ( zrho + 1._wp )         
-               z6 = 2._wp * ( zrho - 1._wp ) / ( zrho + 1._wp )
-               z7 =       - ( zrho - 1._wp ) / ( zrho + 3._wp )
-               z2 = 1._wp - z1 ; z4 = 1._wp - z3 ; z5 = 1._wp - z6 - z7
-               !  
-               jbdy=1+nbghostcells        
-               DO jn = 1, jpts
-                  tsa(imin:imax,jbdy-1,1:jpkm1,jn) = z1 * ptab_child(imin:imax,jbdy-1,1:jpkm1,jn) + z2 * ptab_child(imin:imax,jbdy,1:jpkm1,jn)
-                  DO jk = 1, jpkm1      
-                     DO ji = imin,imax
-                        IF( vmask(ji,jbdy,jk) == 0._wp ) THEN
-                           tsa(ji,jbdy,jk,jn)=tsa(ji,jbdy-1,jk,jn) * tmask(ji,jbdy,jk)
-                        ELSE
-                           tsa(ji,jbdy,jk,jn)=(z4*tsa(ji,jbdy-1,jk,jn)+z3*tsa(ji,jbdy+1,jk,jn))*tmask(ji,jbdy,jk)
-                           IF( vn(ji,jbdy,jk) < 0._wp ) THEN
-                              tsa(ji,jbdy,jk,jn)=( z6*tsa(ji,jbdy+1,jk,jn)+z5*tsa(ji,jbdy-1,jk,jn) & 
-                                                 + z7*tsa(ji,jbdy+2,jk,jn) ) * tmask(ji,jbdy,jk)
-                           ENDIF
-                        ENDIF
-                     END DO
-                  END DO
-                  ! Restore ghost points:
-                  tsa(imin:imax,jbdy-1,1:jpkm1,jn) = ptab_child(imin:imax,jbdy-1,1:jpkm1,jn) * tmask(imin:imax,jbdy-1,1:jpkm1)
-               END DO
-            ENDIF
-            !
-         ENDIF
+            tsa(i1:i2,j1:j2,1:jpk,jn)=ptab(i1:i2,j1:j2,1:jpk,jn)*tmask(i1:i2,j1:j2,1:jpk) 
+         END DO
+# endif
+
       ENDIF
       !
    END SUBROUTINE interptsn
 
-   SUBROUTINE interpsshn( ptab, i1, i2, j1, j2, before, nb, ndir )
+   SUBROUTINE interpsshn( ptab, i1, i2, j1, j2, before )
       !!----------------------------------------------------------------------
       !!                  ***  ROUTINE interpsshn  ***
@@ -855,7 +758,5 @@
       REAL(wp), DIMENSION(i1:i2,j1:j2), INTENT(inout) ::   ptab
       LOGICAL                         , INTENT(in   ) ::   before
-      INTEGER                         , INTENT(in   ) ::   nb , ndir
-      !
-      LOGICAL :: western_side, eastern_side,northern_side,southern_side
+      !
       !!----------------------------------------------------------------------  
       !
@@ -863,18 +764,10 @@
          ptab(i1:i2,j1:j2) = sshn(i1:i2,j1:j2)
       ELSE
-         western_side  = (nb == 1).AND.(ndir == 1)
-         eastern_side  = (nb == 1).AND.(ndir == 2)
-         southern_side = (nb == 2).AND.(ndir == 1)
-         northern_side = (nb == 2).AND.(ndir == 2)
-         !! clem ghost
-         IF(western_side)  hbdy_w(1:nbghostcells,j1:j2) = ptab(i1:i2,j1:j2) * tmask(i1:i2,j1:j2,1)
-         IF(eastern_side)  hbdy_e(1:nbghostcells,j1:j2) = ptab(i1:i2,j1:j2) * tmask(i1:i2,j1:j2,1)
-         IF(southern_side) hbdy_s(i1:i2,1:nbghostcells) = ptab(i1:i2,j1:j2) * tmask(i1:i2,j1:j2,1) 
-         IF(northern_side) hbdy_n(i1:i2,1:nbghostcells) = ptab(i1:i2,j1:j2) * tmask(i1:i2,j1:j2,1)
+         hbdy(i1:i2,j1:j2) = ptab(i1:i2,j1:j2) * tmask(i1:i2,j1:j2,1)
       ENDIF
       !
    END SUBROUTINE interpsshn
 
-   SUBROUTINE interpun( ptab, i1, i2, j1, j2, k1, k2, m1, m2, before, nb, ndir )
+   SUBROUTINE interpun( ptab, i1, i2, j1, j2, k1, k2, m1, m2, before )
       !!----------------------------------------------------------------------
       !!                  *** ROUTINE interpun ***
@@ -884,14 +777,12 @@
       REAL(wp), DIMENSION(i1:i2,j1:j2,k1:k2,m1:m2), INTENT(inout) :: ptab
       LOGICAL, INTENT(in) :: before
-      INTEGER, INTENT(in) :: nb , ndir
       !!
       INTEGER :: ji,jj,jk
-      REAL(wp) :: zrhoy
+      REAL(wp) :: zrhoy, zhtot
       ! vertical interpolation:
       REAL(wp), DIMENSION(k1:k2) :: tabin, h_in
       REAL(wp), DIMENSION(1:jpk) :: h_out
-      INTEGER  :: N_in, N_out, iref
+      INTEGER  :: N_in, N_out
       REAL(wp) :: h_diff
-      LOGICAL  :: western_side, eastern_side
       !!---------------------------------------------    
       !
@@ -902,55 +793,63 @@
                   ptab(ji,jj,jk,1) = (e2u(ji,jj) * e3u_n(ji,jj,jk) * un(ji,jj,jk)*umask(ji,jj,jk)) 
 # if defined key_vertical
-                  ptab(ji,jj,jk,2) = (umask(ji,jj,jk) * e2u(ji,jj) * e3u_n(ji,jj,jk))
+                  ! Interpolate thicknesses (masked for subsequent extrapolation)
+                  ptab(ji,jj,jk,2) = umask(ji,jj,jk) * e2u(ji,jj) * e3u_n(ji,jj,jk)
 # endif
                END DO
             END DO
          END DO
+# if defined key_vertical
+         ! Extrapolate thicknesses in partial bottom cells:
+         ! Set them to Agrif_SpecialValue (0.). Correct bottom thicknesses are retrieved later on
+         IF (ln_zps) THEN
+            DO jj=j1,j2
+               DO ji=i1,i2
+                  jk = mbku(ji,jj)
+                  ptab(ji,jj,jk,2) = 0._wp
+               END DO
+            END DO           
+         END IF
+        ! Save ssh at last level:
+        ptab(i1:i2,j1:j2,k2,2) = 0._wp
+        IF (.NOT.ln_linssh) THEN
+           ! This vertical sum below should be replaced by the sea-level at U-points (optimization):
+           DO jk=1,jpk
+              ptab(i1:i2,j1:j2,k2,2) = ptab(i1:i2,j1:j2,k2,2) + e3u_n(i1:i2,j1:j2,jk) * umask(i1:i2,j1:j2,jk)
+           END DO
+           ptab(i1:i2,j1:j2,k2,2) = ptab(i1:i2,j1:j2,k2,2) - hu_0(i1:i2,j1:j2)
+        END IF 
+# endif
+         !
       ELSE
          zrhoy = Agrif_rhoy()
 # if defined key_vertical
 ! VERTICAL REFINEMENT BEGIN
-         western_side  = (nb == 1).AND.(ndir == 1)
-         eastern_side  = (nb == 1).AND.(ndir == 2)
+
+         IF (ln_linssh) ptab(i1:i2,j1:j2,k2,2) = 0._wp 
 
          DO ji=i1,i2
-            iref = ji
-            IF (western_side) iref = MAX(2,ji)
-            IF (eastern_side) iref = MIN(nlci-2,ji)
             DO jj=j1,j2
-               N_in = 0
-               DO jk=k1,k2
-                  IF (ptab(ji,jj,jk,2) == 0) EXIT
-                  N_in = N_in + 1
-                  tabin(jk) = ptab(ji,jj,jk,1)/ptab(ji,jj,jk,2)
-                  h_in(N_in) = ptab(ji,jj,jk,2)/(e2u(ji,jj)*zrhoy) 
+               ua(ji,jj,:) = 0._wp
+               N_in = mbku_parent(ji,jj)
+               zhtot = 0._wp
+               DO jk=1,N_in
+                  IF (jk==N_in) THEN
+                     h_in(jk) = hu0_parent(ji,jj) + ptab(ji,jj,k2,2) - zhtot
+                  ELSE
+                     h_in(jk) = ptab(ji,jj,jk,2)/(e2u(ji,jj)*zrhoy) 
+                  ENDIF
+                  zhtot = zhtot + h_in(jk)
+                  tabin(jk) = ptab(ji,jj,jk,1)/(e2u(ji,jj)*zrhoy*h_in(jk))
               ENDDO
-         
-              IF (N_in == 0) THEN
-                 ua(ji,jj,:) = 0._wp
-                 CYCLE
-              ENDIF
-         
+                  
               N_out = 0
               DO jk=1,jpk
-                 if (umask(iref,jj,jk) == 0) EXIT
+                 if (umask(ji,jj,jk) == 0) EXIT
                  N_out = N_out + 1
-                 h_out(N_out) = e3u_a(iref,jj,jk)
+                 h_out(N_out) = e3u_a(ji,jj,jk)
               ENDDO
-         
-              IF (N_out == 0) THEN
-                 ua(ji,jj,:) = 0._wp
-                 CYCLE
+              IF (N_in*N_out > 0) THEN
+                 CALL reconstructandremap(tabin(1:N_in),h_in(1:N_in),ua(ji,jj,1:N_out),h_out(1:N_out),N_in,N_out,1)
               ENDIF
-         
-              IF (N_in * N_out > 0) THEN
-                 h_diff = sum(h_out(1:N_out))-sum(h_in(1:N_in))
-! Should be able to remove the next IF/ELSEIF statement once scale factors are dealt with properly
-                 if (h_diff < -1.e4) then
-                    print *,'CHECK YOUR BATHY ...', h_diff, sum(h_out(1:N_out)), sum(h_in(1:N_in))
-!                    stop
-                 endif
-              ENDIF
-              call reconstructandremap(tabin(1:N_in),h_in(1:N_in),ua(ji,jj,1:N_out),h_out(1:N_out),N_in,N_out)
             ENDDO
          ENDDO
@@ -968,5 +867,5 @@
    END SUBROUTINE interpun
 
-   SUBROUTINE interpvn( ptab, i1, i2, j1, j2, k1, k2, m1, m2, before, nb, ndir )
+   SUBROUTINE interpvn( ptab, i1, i2, j1, j2, k1, k2, m1, m2, before )
       !!----------------------------------------------------------------------
       !!                  *** ROUTINE interpvn ***
@@ -976,5 +875,4 @@
       REAL(wp), DIMENSION(i1:i2,j1:j2,k1:k2,m1:m2), INTENT(inout) :: ptab
       LOGICAL, INTENT(in) :: before
-      INTEGER, INTENT(in) :: nb , ndir
       !
       INTEGER :: ji,jj,jk
@@ -983,7 +881,6 @@
       REAL(wp), DIMENSION(k1:k2) :: tabin, h_in
       REAL(wp), DIMENSION(1:jpk) :: h_out
-      INTEGER  :: N_in, N_out, jref
-      REAL(wp) :: h_diff
-      LOGICAL  :: northern_side,southern_side
+      INTEGER  :: N_in, N_out
+      REAL(wp) :: h_diff, zhtot
       !!---------------------------------------------    
       !      
@@ -994,4 +891,5 @@
                   ptab(ji,jj,jk,1) = (e1v(ji,jj) * e3v_n(ji,jj,jk) * vn(ji,jj,jk)*vmask(ji,jj,jk))
 # if defined key_vertical
+                  ! Interpolate thicknesses (masked for subsequent extrapolation)
                   ptab(ji,jj,jk,2) = vmask(ji,jj,jk) * e1v(ji,jj) * e3v_n(ji,jj,jk)
 # endif
@@ -999,39 +897,55 @@
             END DO
          END DO
+# if defined key_vertical
+         ! Extrapolate thicknesses in partial bottom cells:
+         ! Set them to Agrif_SpecialValue (0.). Correct bottom thicknesses are retrieved later on
+         IF (ln_zps) THEN
+            DO jj=j1,j2
+               DO ji=i1,i2
+                  jk = mbkv(ji,jj)
+                  ptab(ji,jj,jk,2) = 0._wp
+               END DO
+            END DO           
+         END IF
+        ! Save ssh at last level:
+        ptab(i1:i2,j1:j2,k2,2) = 0._wp
+        IF (.NOT.ln_linssh) THEN
+           ! This vertical sum below should be replaced by the sea-level at V-points (optimization):
+           DO jk=1,jpk
+              ptab(i1:i2,j1:j2,k2,2) = ptab(i1:i2,j1:j2,k2,2) + e3v_n(i1:i2,j1:j2,jk) * vmask(i1:i2,j1:j2,jk)
+           END DO
+           ptab(i1:i2,j1:j2,k2,2) = ptab(i1:i2,j1:j2,k2,2) - hv_0(i1:i2,j1:j2)
+        END IF 
+# endif
       ELSE       
          zrhox = Agrif_rhox()
 # if defined key_vertical
 
-         southern_side = (nb == 2).AND.(ndir == 1)
-         northern_side = (nb == 2).AND.(ndir == 2)
+         IF (ln_linssh) ptab(i1:i2,j1:j2,k2,2) = 0._wp 
 
          DO jj=j1,j2
-            jref = jj
-            IF (southern_side) jref = MAX(2,jj)
-            IF (northern_side) jref = MIN(nlcj-2,jj)
             DO ji=i1,i2
-               N_in = 0
-               DO jk=k1,k2
-                  if (ptab(ji,jj,jk,2) == 0) EXIT
-                  N_in = N_in + 1
-                  tabin(jk) = ptab(ji,jj,jk,1)/ptab(ji,jj,jk,2)
-                  h_in(N_in) = ptab(ji,jj,jk,2)/(e1v(ji,jj)*zrhox)
-               END DO
-               IF (N_in == 0) THEN
-                  va(ji,jj,:) = 0._wp
-                  CYCLE
-               ENDIF
+               va(ji,jj,:) = 0._wp
+               N_in = mbkv_parent(ji,jj)
+               zhtot = 0._wp
+               DO jk=1,N_in
+                  IF (jk==N_in) THEN
+                     h_in(jk) = hv0_parent(ji,jj) + ptab(ji,jj,k2,2) - zhtot
+                  ELSE
+                     h_in(jk) = ptab(ji,jj,jk,2)/(e1v(ji,jj)*zrhox) 
+                  ENDIF
+                  zhtot = zhtot + h_in(jk)
+                  tabin(jk) = ptab(ji,jj,jk,1)/(e1v(ji,jj)*zrhox*h_in(jk))
+              ENDDO
          
                N_out = 0
                DO jk=1,jpk
-                  if (vmask(ji,jref,jk) == 0) EXIT
+                  if (vmask(ji,jj,jk) == 0) EXIT
                   N_out = N_out + 1
-                  h_out(N_out) = e3v_a(ji,jref,jk)
-               END DO
-               IF (N_out == 0) THEN
-                 va(ji,jj,:) = 0._wp
-                 CYCLE
+                  h_out(N_out) = e3v_a(ji,jj,jk)
+               END DO
+               IF (N_in*N_out > 0) THEN
+                  call reconstructandremap(tabin(1:N_in),h_in(1:N_in),va(ji,jj,1:N_out),h_out(1:N_out),N_in,N_out,1)
                ENDIF
-               call reconstructandremap(tabin(1:N_in),h_in(1:N_in),va(ji,jj,1:N_out),h_out(1:N_out),N_in,N_out)
             END DO
          END DO
@@ -1045,5 +959,5 @@
    END SUBROUTINE interpvn
 
-   SUBROUTINE interpunb( ptab, i1, i2, j1, j2, before, nb, ndir )
+   SUBROUTINE interpunb( ptab, i1, i2, j1, j2, before)
       !!----------------------------------------------------------------------
       !!                  ***  ROUTINE interpunb  ***
@@ -1052,9 +966,7 @@
       REAL(wp), DIMENSION(i1:i2,j1:j2), INTENT(inout) ::   ptab
       LOGICAL                         , INTENT(in   ) ::   before
-      INTEGER                         , INTENT(in   ) ::   nb , ndir
       !
       INTEGER  ::   ji, jj
       REAL(wp) ::   zrhoy, zrhot, zt0, zt1, ztcoeff
-      LOGICAL  ::   western_side, eastern_side,northern_side,southern_side
       !!----------------------------------------------------------------------  
       !
@@ -1062,8 +974,4 @@
          ptab(i1:i2,j1:j2) = e2u(i1:i2,j1:j2) * hu_n(i1:i2,j1:j2) * un_b(i1:i2,j1:j2)
       ELSE
-         western_side  = (nb == 1).AND.(ndir == 1)
-         eastern_side  = (nb == 1).AND.(ndir == 2)
-         southern_side = (nb == 2).AND.(ndir == 1)
-         northern_side = (nb == 2).AND.(ndir == 2)
          zrhoy = Agrif_Rhoy()
          zrhot = Agrif_rhot()
@@ -1071,32 +979,36 @@
          zt0 = REAL(Agrif_NbStepint()  , wp) / zrhot
          zt1 = REAL(Agrif_NbStepint()+1, wp) / zrhot      
-         ! Polynomial interpolation coefficients:
-         IF( bdy_tinterp == 1 ) THEN
-            ztcoeff = zrhot * (  zt1**2._wp * (       zt1 - 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 )
-         ELSE
-            ztcoeff = 1
-         ENDIF
-         !   
-         IF(western_side)   ubdy_w(1:nbghostcells,j1:j2) = ubdy_w(1:nbghostcells,j1:j2) + ztcoeff * ptab(i1:i2,j1:j2)  
-         IF(eastern_side)   ubdy_e(1:nbghostcells,j1:j2) = ubdy_e(1:nbghostcells,j1:j2) + ztcoeff * ptab(i1:i2,j1:j2)  
-         IF(southern_side)  ubdy_s(i1:i2,1:nbghostcells) = ubdy_s(i1:i2,1:nbghostcells) + ztcoeff * ptab(i1:i2,j1:j2)
-         IF(northern_side)  ubdy_n(i1:i2,1:nbghostcells) = ubdy_n(i1:i2,1:nbghostcells) + ztcoeff * ptab(i1:i2,j1:j2) 
-         !            
-         IF( bdy_tinterp == 0 .OR. bdy_tinterp == 2) THEN
-            IF(western_side)   ubdy_w(1:nbghostcells,j1:j2) = ubdy_w(1:nbghostcells,j1:j2) / (zrhoy*e2u(i1:i2,j1:j2)) * umask(i1:i2,j1:j2,1)
-            IF(eastern_side)   ubdy_e(1:nbghostcells,j1:j2) = ubdy_e(1:nbghostcells,j1:j2) / (zrhoy*e2u(i1:i2,j1:j2)) * umask(i1:i2,j1:j2,1)
-            IF(southern_side)  ubdy_s(i1:i2,1:nbghostcells) = ubdy_s(i1:i2,1:nbghostcells) / (zrhoy*e2u(i1:i2,j1:j2)) * umask(i1:i2,j1:j2,1)
-            IF(northern_side)  ubdy_n(i1:i2,1:nbghostcells) = ubdy_n(i1:i2,1:nbghostcells) / (zrhoy*e2u(i1:i2,j1:j2)) * umask(i1:i2,j1:j2,1)
-         ENDIF
-      ENDIF
+         ! 
+         DO ji = i1, i2
+            DO jj = j1, j2
+               IF ( utint_stage(ji,jj) < (bdy_tinterp + 1) ) THEN
+                  IF    ( utint_stage(ji,jj) == 1  ) THEN
+                     ztcoeff = zrhot * (  zt1**2._wp * (       zt1 - 1._wp)        &
+                        &               - zt0**2._wp * (       zt0 - 1._wp)        )
+                  ELSEIF( utint_stage(ji,jj) == 2  ) THEN
+                     ztcoeff = zrhot * (  zt1        * (       zt1 - 1._wp)**2._wp &
+                        &               - zt0        * (       zt0 - 1._wp)**2._wp )
+                  ELSEIF( utint_stage(ji,jj) == 0  ) THEN                
+                     ztcoeff = 1._wp
+                  ELSE
+                     ztcoeff = 0._wp
+                  ENDIF
+                  !   
+                  ubdy(ji,jj) = ubdy(ji,jj) + ztcoeff * ptab(ji,jj)
+                  !            
+                  IF (( utint_stage(ji,jj) == 2 ).OR.( utint_stage(ji,jj) == 0 )) THEN
+                     ubdy(ji,jj) = ubdy(ji,jj) / (zrhoy*e2u(ji,jj)) * umask(ji,jj,1)
+                  ENDIF
+                  !
+                  utint_stage(ji,jj) = utint_stage(ji,jj) + 1
+               ENDIF
+            END DO
+         END DO
+      END IF
       ! 
    END SUBROUTINE interpunb
 
 
-   SUBROUTINE interpvnb( ptab, i1, i2, j1, j2, before, nb, ndir )
+   SUBROUTINE interpvnb( ptab, i1, i2, j1, j2, before )
       !!----------------------------------------------------------------------
       !!                  ***  ROUTINE interpvnb  ***
@@ -1105,9 +1017,7 @@
       REAL(wp), DIMENSION(i1:i2,j1:j2), INTENT(inout) ::   ptab
       LOGICAL                         , INTENT(in   ) ::   before
-      INTEGER                         , INTENT(in   ) ::   nb , ndir
-      !
-      INTEGER  ::   ji,jj
+      !
+      INTEGER  ::   ji, jj
       REAL(wp) ::   zrhox, zrhot, zt0, zt1, ztcoeff   
-      LOGICAL  ::   western_side, eastern_side,northern_side,southern_side
       !!----------------------------------------------------------------------  
       ! 
@@ -1115,34 +1025,35 @@
          ptab(i1:i2,j1:j2) = e1v(i1:i2,j1:j2) * hv_n(i1:i2,j1:j2) * vn_b(i1:i2,j1:j2)
       ELSE
-         western_side  = (nb == 1).AND.(ndir == 1)
-         eastern_side  = (nb == 1).AND.(ndir == 2)
-         southern_side = (nb == 2).AND.(ndir == 1)
-         northern_side = (nb == 2).AND.(ndir == 2)
          zrhox = Agrif_Rhox()
          zrhot = Agrif_rhot()
          ! Time indexes bounds for integration
          zt0 = REAL(Agrif_NbStepint()  , wp) / zrhot
-         zt1 = REAL(Agrif_NbStepint()+1, wp) / zrhot      
-         IF( bdy_tinterp == 1 ) THEN
-            ztcoeff = zrhot * (  zt1**2._wp * (       zt1 - 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 ) 
-         ELSE
-            ztcoeff = 1
-         ENDIF
-         !! clem ghost
-         IF(western_side)   vbdy_w(1:nbghostcells,j1:j2) = vbdy_w(1:nbghostcells,j1:j2) + ztcoeff * ptab(i1:i2,j1:j2)  
-         IF(eastern_side)   vbdy_e(1:nbghostcells,j1:j2) = vbdy_e(1:nbghostcells,j1:j2) + ztcoeff * ptab(i1:i2,j1:j2)   
-         IF(southern_side)  vbdy_s(i1:i2,1:nbghostcells) = vbdy_s(i1:i2,1:nbghostcells) + ztcoeff * ptab(i1:i2,j1:j2)
-         IF(northern_side)  vbdy_n(i1:i2,1:nbghostcells) = vbdy_n(i1:i2,1:nbghostcells) + ztcoeff * ptab(i1:i2,j1:j2) 
-         !            
-         IF( bdy_tinterp == 0 .OR. bdy_tinterp == 2) THEN
-            IF(western_side)   vbdy_w(1:nbghostcells,j1:j2) = vbdy_w(1:nbghostcells,j1:j2) / (zrhox*e1v(i1:i2,j1:j2)) * vmask(i1:i2,j1:j2,1)
-            IF(eastern_side)   vbdy_e(1:nbghostcells,j1:j2) = vbdy_e(1:nbghostcells,j1:j2) / (zrhox*e1v(i1:i2,j1:j2)) * vmask(i1:i2,j1:j2,1)
-            IF(southern_side)  vbdy_s(i1:i2,1:nbghostcells) = vbdy_s(i1:i2,1:nbghostcells) / (zrhox*e1v(i1:i2,j1:j2)) * vmask(i1:i2,j1:j2,1)
-            IF(northern_side)  vbdy_n(i1:i2,1:nbghostcells) = vbdy_n(i1:i2,1:nbghostcells) / (zrhox*e1v(i1:i2,j1:j2)) * vmask(i1:i2,j1:j2,1)
-         ENDIF
+         zt1 = REAL(Agrif_NbStepint()+1, wp) / zrhot 
+         !     
+         DO ji = i1, i2
+            DO jj = j1, j2
+               IF ( vtint_stage(ji,jj) < (bdy_tinterp + 1) ) THEN
+                  IF    ( vtint_stage(ji,jj) == 1  ) THEN
+                     ztcoeff = zrhot * (  zt1**2._wp * (       zt1 - 1._wp)        &
+                        &               - zt0**2._wp * (       zt0 - 1._wp)        )
+                  ELSEIF( vtint_stage(ji,jj) == 2  ) THEN
+                     ztcoeff = zrhot * (  zt1        * (       zt1 - 1._wp)**2._wp &
+                        &               - zt0        * (       zt0 - 1._wp)**2._wp )
+                  ELSEIF( vtint_stage(ji,jj) == 0  ) THEN                
+                     ztcoeff = 1._wp
+                  ELSE
+                     ztcoeff = 0._wp
+                  ENDIF
+                  !   
+                  vbdy(ji,jj) = vbdy(ji,jj) + ztcoeff * ptab(ji,jj)
+                  !            
+                  IF (( vtint_stage(ji,jj) == 2 ).OR.( vtint_stage(ji,jj) == 0 )) THEN
+                     vbdy(ji,jj) = vbdy(ji,jj) / (zrhox*e1v(ji,jj)) * vmask(ji,jj,1)
+                  ENDIF
+                  !
+                  vtint_stage(ji,jj) = vtint_stage(ji,jj) + 1
+               ENDIF
+            END DO
+         END DO          
       ENDIF
       !
@@ -1150,5 +1061,5 @@
 
 
-   SUBROUTINE interpub2b( ptab, i1, i2, j1, j2, before, nb, ndir )
+   SUBROUTINE interpub2b( ptab, i1, i2, j1, j2, before )
       !!----------------------------------------------------------------------
       !!                  ***  ROUTINE interpub2b  ***
@@ -1157,9 +1068,7 @@
       REAL(wp), DIMENSION(i1:i2,j1:j2), INTENT(inout) ::   ptab
       LOGICAL                         , INTENT(in   ) ::   before
-      INTEGER                         , INTENT(in   ) ::   nb , ndir
       !
       INTEGER  ::   ji,jj
-      REAL(wp) ::   zrhot, zt0, zt1,zat
-      LOGICAL  ::   western_side, eastern_side,northern_side,southern_side
+      REAL(wp) ::   zrhot, zt0, zt1, zat
       !!----------------------------------------------------------------------  
       IF( before ) THEN
@@ -1170,50 +1079,4 @@
          ENDIF
       ELSE
-         western_side  = (nb == 1).AND.(ndir == 1)
-         eastern_side  = (nb == 1).AND.(ndir == 2)
-         southern_side = (nb == 2).AND.(ndir == 1)
-         northern_side = (nb == 2).AND.(ndir == 2)
-         zrhot = Agrif_rhot()
-         ! Time indexes bounds for integration
-         zt0 = REAL(Agrif_NbStepint()  , wp) / zrhot
-         zt1 = REAL(Agrif_NbStepint()+1, wp) / zrhot
-         ! Polynomial interpolation coefficients:
-         zat = zrhot * (  zt1**2._wp * (-2._wp*zt1 + 3._wp)    &
-            &           - zt0**2._wp * (-2._wp*zt0 + 3._wp)    ) 
-         !! clem ghost
-         IF(western_side ) ubdy_w(1:nbghostcells,j1:j2) = zat * ptab(i1:i2,j1:j2)  
-         IF(eastern_side ) ubdy_e(1:nbghostcells,j1:j2) = zat * ptab(i1:i2,j1:j2)  
-         IF(southern_side) ubdy_s(i1:i2,1:nbghostcells) = zat * ptab(i1:i2,j1:j2)
-         IF(northern_side) ubdy_n(i1:i2,1:nbghostcells) = zat * ptab(i1:i2,j1:j2) 
-      ENDIF
-      ! 
-   END SUBROUTINE interpub2b
-   
-
-   SUBROUTINE interpvb2b( ptab, i1, i2, j1, j2, before, nb, ndir )
-      !!----------------------------------------------------------------------
-      !!                  ***  ROUTINE interpvb2b  ***
-      !!----------------------------------------------------------------------  
-      INTEGER                         , INTENT(in   ) ::   i1, i2, j1, j2
-      REAL(wp), DIMENSION(i1:i2,j1:j2), INTENT(inout) ::   ptab
-      LOGICAL                         , INTENT(in   ) ::   before
-      INTEGER                         , INTENT(in   ) ::   nb , ndir
-      !
-      INTEGER ::   ji,jj
-      REAL(wp) ::   zrhot, zt0, zt1,zat
-      LOGICAL ::   western_side, eastern_side,northern_side,southern_side
-      !!----------------------------------------------------------------------  
-      !
-      IF( before ) THEN
-         IF ( ln_bt_fw ) THEN
-            ptab(i1:i2,j1:j2) = e1v(i1:i2,j1:j2) * vb2_b(i1:i2,j1:j2)
-         ELSE
-            ptab(i1:i2,j1:j2) = e1v(i1:i2,j1:j2) * vn_adv(i1:i2,j1:j2)
-         ENDIF
-      ELSE      
-         western_side  = (nb == 1).AND.(ndir == 1)
-         eastern_side  = (nb == 1).AND.(ndir == 2)
-         southern_side = (nb == 2).AND.(ndir == 1)
-         northern_side = (nb == 2).AND.(ndir == 2)
          zrhot = Agrif_rhot()
          ! Time indexes bounds for integration
@@ -1224,8 +1087,44 @@
             &           - zt0**2._wp * (-2._wp*zt0 + 3._wp)    ) 
          !
-         IF(western_side )   vbdy_w(1:nbghostcells,j1:j2) = zat * ptab(i1:i2,j1:j2)  
-         IF(eastern_side )   vbdy_e(1:nbghostcells,j1:j2) = zat * ptab(i1:i2,j1:j2)  
-         IF(southern_side)   vbdy_s(i1:i2,1:nbghostcells) = zat * ptab(i1:i2,j1:j2)
-         IF(northern_side)   vbdy_n(i1:i2,1:nbghostcells) = zat * ptab(i1:i2,j1:j2) 
+         ubdy(i1:i2,j1:j2) = zat * ptab(i1:i2,j1:j2) 
+         !
+         ! Update interpolation stage:
+         utint_stage(i1:i2,j1:j2) = 1
+      ENDIF
+      ! 
+   END SUBROUTINE interpub2b
+   
+
+   SUBROUTINE interpvb2b( ptab, i1, i2, j1, j2, before )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE interpvb2b  ***
+      !!----------------------------------------------------------------------  
+      INTEGER                         , INTENT(in   ) ::   i1, i2, j1, j2
+      REAL(wp), DIMENSION(i1:i2,j1:j2), INTENT(inout) ::   ptab
+      LOGICAL                         , INTENT(in   ) ::   before
+      !
+      INTEGER ::   ji,jj
+      REAL(wp) ::   zrhot, zt0, zt1, zat
+      !!----------------------------------------------------------------------  
+      !
+      IF( before ) THEN
+         IF ( ln_bt_fw ) THEN
+            ptab(i1:i2,j1:j2) = e1v(i1:i2,j1:j2) * vb2_b(i1:i2,j1:j2)
+         ELSE
+            ptab(i1:i2,j1:j2) = e1v(i1:i2,j1:j2) * vn_adv(i1:i2,j1:j2)
+         ENDIF
+      ELSE      
+         zrhot = Agrif_rhot()
+         ! Time indexes bounds for integration
+         zt0 = REAL(Agrif_NbStepint()  , wp) / zrhot
+         zt1 = REAL(Agrif_NbStepint()+1, wp) / zrhot
+         ! Polynomial interpolation coefficients:
+         zat = zrhot * (  zt1**2._wp * (-2._wp*zt1 + 3._wp)    &
+            &           - zt0**2._wp * (-2._wp*zt0 + 3._wp)    ) 
+         !
+         vbdy(i1:i2,j1:j2) = zat * ptab(i1:i2,j1:j2)
+         !
+         ! update interpolation stage:
+         vtint_stage(i1:i2,j1:j2) = 1
       ENDIF
       !      
@@ -1233,5 +1132,5 @@
 
 
-   SUBROUTINE interpe3t( ptab, i1, i2, j1, j2, k1, k2, before, nb, ndir )
+   SUBROUTINE interpe3t( ptab, i1, i2, j1, j2, k1, k2, before )
       !!----------------------------------------------------------------------
       !!                  ***  ROUTINE interpe3t  ***
@@ -1240,8 +1139,6 @@
       REAL(wp),DIMENSION(i1:i2,j1:j2,k1:k2), INTENT(inout) :: ptab
       LOGICAL                              , INTENT(in   ) :: before
-      INTEGER                              , INTENT(in   ) :: nb , ndir
       !
       INTEGER :: ji, jj, jk
-      LOGICAL :: western_side, eastern_side, northern_side, southern_side
       !!----------------------------------------------------------------------  
       !    
@@ -1249,31 +1146,13 @@
          ptab(i1:i2,j1:j2,k1:k2) = tmask(i1:i2,j1:j2,k1:k2) * e3t_0(i1:i2,j1:j2,k1:k2)
       ELSE
-         western_side  = (nb == 1).AND.(ndir == 1)
-         eastern_side  = (nb == 1).AND.(ndir == 2)
-         southern_side = (nb == 2).AND.(ndir == 1)
-         northern_side = (nb == 2).AND.(ndir == 2)
          !
          DO jk = k1, k2
             DO jj = j1, j2
                DO ji = i1, i2
-                  !
                   IF( ABS( ptab(ji,jj,jk) - tmask(ji,jj,jk) * e3t_0(ji,jj,jk) ) > 1.D-2) THEN
-                     IF (western_side.AND.(ptab(i1+nbghostcells-1,jj,jk)>0._wp)) THEN
-                        WRITE(numout,*) 'ERROR bathymetry merge at the western border ji,jj,jk ', ji+nimpp-1,jj+njmpp-1,jk
-                        WRITE(numout,*)  ptab(ji,jj,jk), e3t_0(ji,jj,jk) 
-                        kindic_agr = kindic_agr + 1
-                     ELSEIF (eastern_side.AND.(ptab(i2-nbghostcells+1,jj,jk)>0._wp)) THEN
-                        WRITE(numout,*) 'ERROR bathymetry merge at the eastern border ji,jj,jk ', ji+nimpp-1,jj+njmpp-1,jk
-                        WRITE(numout,*)  ptab(ji,jj,jk), e3t_0(ji,jj,jk)
-                        kindic_agr = kindic_agr + 1
-                     ELSEIF (southern_side.AND.(ptab(ji,j1+nbghostcells-1,jk)>0._wp)) THEN
-                        WRITE(numout,*) 'ERROR bathymetry merge at the southern border ji,jj,jk', ji+nimpp-1,jj+njmpp-1,jk
-                        WRITE(numout,*)  ptab(ji,jj,jk), e3t_0(ji,jj,jk)
-                        kindic_agr = kindic_agr + 1
-                     ELSEIF (northern_side.AND.(ptab(ji,j2-nbghostcells+1,jk)>0._wp)) THEN
-                        WRITE(numout,*) 'ERROR bathymetry merge at the northen border ji,jj,jk', ji+nimpp-1,jj+njmpp-1,jk
-                        WRITE(numout,*)  ptab(ji,jj,jk), e3t_0(ji,jj,jk)
-                        kindic_agr = kindic_agr + 1
-                     ENDIF
+                     WRITE(numout,*) ' Agrif error for e3t_0: parent , child, i, j, k ',  & 
+                     &                 ptab(ji,jj,jk), tmask(ji,jj,jk) * e3t_0(ji,jj,jk), &
+                     &                 ji+nimpp-1, jj+njmpp-1, jk
+                     kindic_agr = kindic_agr + 1
                   ENDIF
                END DO
@@ -1284,88 +1163,4 @@
       ! 
    END SUBROUTINE interpe3t
-
-
-   SUBROUTINE interpumsk( ptab, i1, i2, j1, j2, k1, k2, before, nb, ndir )
-      !!----------------------------------------------------------------------
-      !!                  ***  ROUTINE interpumsk  ***
-      !!----------------------------------------------------------------------  
-      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
-      INTEGER                              , INTENT(in   ) ::   nb , ndir
-      !
-      INTEGER ::   ji, jj, jk
-      LOGICAL ::   western_side, eastern_side   
-      !!----------------------------------------------------------------------  
-      !    
-      IF( before ) THEN
-         ptab(i1:i2,j1:j2,k1:k2) = umask(i1:i2,j1:j2,k1:k2)
-      ELSE
-         western_side = (nb == 1).AND.(ndir == 1)
-         eastern_side = (nb == 1).AND.(ndir == 2)
-         DO jk = k1, k2
-            DO jj = j1, j2
-               DO ji = i1, i2
-                   ! Velocity mask at boundary edge points:
-                  IF (ABS(ptab(ji,jj,jk) - umask(ji,jj,jk)) > 1.D-2) THEN
-                     IF (western_side) THEN
-                        WRITE(numout,*) 'ERROR with umask at the western border ji,jj,jk ', ji+nimpp-1,jj+njmpp-1,jk
-                        WRITE(numout,*) '      masks: parent, child ', ptab(ji,jj,jk), umask(ji,jj,jk)
-                        kindic_agr = kindic_agr + 1
-                     ELSEIF (eastern_side) THEN
-                        WRITE(numout,*) 'ERROR with umask at the eastern border ji,jj,jk ', ji+nimpp-1,jj+njmpp-1,jk
-                        WRITE(numout,*) '      masks: parent, child ', ptab(ji,jj,jk), umask(ji,jj,jk)
-                        kindic_agr = kindic_agr + 1
-                     ENDIF
-                  ENDIF
-               END DO
-            END DO
-         END DO
-         !
-      ENDIF
-      ! 
-   END SUBROUTINE interpumsk
-
-
-   SUBROUTINE interpvmsk( ptab, i1, i2, j1, j2, k1, k2, before, nb, ndir )
-      !!----------------------------------------------------------------------
-      !!                  ***  ROUTINE interpvmsk  ***
-      !!----------------------------------------------------------------------  
-      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
-      INTEGER                              , INTENT(in   ) :: nb , ndir
-      !
-      INTEGER ::   ji, jj, jk
-      LOGICAL ::   northern_side, southern_side     
-      !!----------------------------------------------------------------------  
-      !    
-      IF( before ) THEN
-         ptab(i1:i2,j1:j2,k1:k2) = vmask(i1:i2,j1:j2,k1:k2)
-      ELSE
-         southern_side = (nb == 2).AND.(ndir == 1)
-         northern_side = (nb == 2).AND.(ndir == 2)
-         DO jk = k1, k2
-            DO jj = j1, j2
-               DO ji = i1, i2
-                   ! Velocity mask at boundary edge points:
-                  IF (ABS(ptab(ji,jj,jk) - vmask(ji,jj,jk)) > 1.D-2) THEN
-                     IF (southern_side) THEN
-                        WRITE(numout,*) 'ERROR with vmask at the southern border ji,jj,jk ', ji+nimpp-1,jj+njmpp-1,jk
-                        WRITE(numout,*) '      masks: parent, child ', ptab(ji,jj,jk), vmask(ji,jj,jk)
-                        kindic_agr = kindic_agr + 1
-                     ELSEIF (northern_side) THEN
-                        WRITE(numout,*) 'ERROR with vmask at the northern border ji,jj,jk ', ji+nimpp-1,jj+njmpp-1,jk
-                        WRITE(numout,*) '      masks: parent, child ', ptab(ji,jj,jk), vmask(ji,jj,jk)
-                        kindic_agr = kindic_agr + 1
-                     ENDIF
-                  ENDIF
-               END DO
-            END DO
-         END DO
-         !
-      ENDIF
-      ! 
-   END SUBROUTINE interpvmsk
 
 
@@ -1377,7 +1172,9 @@
       REAL(wp),DIMENSION(i1:i2,j1:j2,k1:k2,m1:m2), INTENT(inout) ::   ptab
       LOGICAL                                    , INTENT(in   ) ::   before
-      REAL(wp), DIMENSION(k1:k2) :: tabin, h_in
-      REAL(wp), DIMENSION(1:jpk) :: h_out
-      INTEGER  :: N_in, N_out, ji, jj, jk
+      !
+      INTEGER  :: ji, jj, jk
+      INTEGER  :: N_in, N_out
+      REAL(wp), DIMENSION(k1:k2) :: tabin, z_in
+      REAL(wp), DIMENSION(1:jpk) :: z_out
       !!----------------------------------------------------------------------  
       !      
@@ -1390,33 +1187,54 @@
            END DO
         END DO
-#ifdef key_vertical         
+
+# if defined key_vertical
+        ! Interpolate thicknesses
+        ! Warning: these are masked, hence extrapolated prior interpolation.
         DO jk=k1,k2
            DO jj=j1,j2
               DO ji=i1,i2
-                 ptab(ji,jj,jk,2) = wmask(ji,jj,jk) * e3w_n(ji,jj,jk) 
+                  ptab(ji,jj,jk,2) = tmask(ji,jj,jk) * e3t_n(ji,jj,jk)
               END DO
            END DO
         END DO
-#endif
+
+        ! Extrapolate thicknesses in partial bottom cells:
+        ! Set them to Agrif_SpecialValue (0.). Correct bottom thicknesses are retrieved later on
+        IF (ln_zps) THEN
+           DO jj=j1,j2
+              DO ji=i1,i2
+                  jk = mbkt(ji,jj)
+                  ptab(ji,jj,jk,2) = 0._wp
+              END DO
+           END DO           
+        END IF
+     
+        ! Save ssh at last level:
+        IF (.NOT.ln_linssh) THEN
+           ptab(i1:i2,j1:j2,k2,2) = sshn(i1:i2,j1:j2)*tmask(i1:i2,j1:j2,1) 
+        ELSE
+           ptab(i1:i2,j1:j2,k2,2) = 0._wp
+        END IF      
+# endif
       ELSE 
 #ifdef key_vertical         
-         avm_k(i1:i2,j1:j2,1:jpk) = 0.
-         DO jj=j1,j2
-            DO ji=i1,i2
-               N_in = 0
-               DO jk=k1,k2 !k2 = jpk of parent grid
-                  IF (ptab(ji,jj,jk,2) == 0) EXIT
-                  N_in = N_in + 1
-                  tabin(jk) = ptab(ji,jj,jk,1)
-                  h_in(N_in) = ptab(ji,jj,jk,2)
-               END DO
-               N_out = 0
-               DO jk=1,jpk ! jpk of child grid
-                  IF (wmask(ji,jj,jk) == 0) EXIT 
-                  N_out = N_out + 1
-                  h_out(jk) = e3t_n(ji,jj,jk)
+         IF (ln_linssh) ptab(i1:i2,j1:j2,k2,2) = 0._wp 
+         avm_k(i1:i2,j1:j2,k1:k2) = 0._wp
+            
+         DO jj = j1, j2
+            DO ji =i1, i2
+               N_in = mbkt_parent(ji,jj)
+               IF ( tmask(ji,jj,1) == 0._wp) N_in = 0
+               z_in(N_in+1) = ht0_parent(ji,jj) + ptab(ji,jj,k2,2)
+               DO jk = N_in, 1, -1  ! Parent vertical grid               
+                     z_in(jk) = z_in(jk+1) - ptab(ji,jj,jk,2)
+                    tabin(jk) = ptab(ji,jj,jk,1)
+               END DO
+               N_out = mbkt(ji,jj) 
+               DO jk = 1, N_out        ! Child vertical grid
+                  z_out(jk) = gdepw_n(ji,jj,jk)
                ENDDO
-               IF (N_in > 0) THEN
-                  CALL reconstructandremap(tabin(1:N_in),h_in,avm_k(ji,jj,1:N_out),h_out,N_in,N_out)
+               IF (N_in*N_out > 0) THEN
+                  CALL remap_linear(tabin(1:N_in),z_in(1:N_in),avm_k(ji,jj,1:N_out),z_out(1:N_out),N_in,N_out,1)
                ENDIF
             ENDDO
@@ -1428,4 +1246,42 @@
       !
    END SUBROUTINE interpavm
+
+# if defined key_vertical
+   SUBROUTINE interpmbkt( ptab, i1, i2, j1, j2, before )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE interpsshn  ***
+      !!----------------------------------------------------------------------  
+      INTEGER                         , INTENT(in   ) ::   i1, i2, j1, j2
+      REAL(wp), DIMENSION(i1:i2,j1:j2), INTENT(inout) ::   ptab
+      LOGICAL                         , INTENT(in   ) ::   before
+      !
+      !!----------------------------------------------------------------------  
+      !
+      IF( before) THEN
+         ptab(i1:i2,j1:j2) = REAL(mbkt(i1:i2,j1:j2),wp)
+      ELSE
+         mbkt_parent(i1:i2,j1:j2) = NINT(ptab(i1:i2,j1:j2))
+      ENDIF
+      !
+   END SUBROUTINE interpmbkt
+
+   SUBROUTINE interpht0( ptab, i1, i2, j1, j2, before )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE interpsshn  ***
+      !!----------------------------------------------------------------------  
+      INTEGER                         , INTENT(in   ) ::   i1, i2, j1, j2
+      REAL(wp), DIMENSION(i1:i2,j1:j2), INTENT(inout) ::   ptab
+      LOGICAL                         , INTENT(in   ) ::   before
+      !
+      !!----------------------------------------------------------------------  
+      !
+      IF( before) THEN
+         ptab(i1:i2,j1:j2) = ht_0(i1:i2,j1:j2)
+      ELSE
+         ht0_parent(i1:i2,j1:j2) = ptab(i1:i2,j1:j2)
+      ENDIF
+      !
+   END SUBROUTINE interpht0
+#endif
 
 #else
Index: /NEMO/branches/2019/dev_r12072_MERGE_OPTION2_2019/src/NST/agrif_oce_sponge.F90
===================================================================
--- /NEMO/branches/2019/dev_r12072_MERGE_OPTION2_2019/src/NST/agrif_oce_sponge.F90	(revision 12190)
+++ /NEMO/branches/2019/dev_r12072_MERGE_OPTION2_2019/src/NST/agrif_oce_sponge.F90	(revision 12191)
@@ -22,4 +22,6 @@
    USE agrif_oce
    USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
+   USE iom
+   USE vremap
 
    IMPLICIT NONE
@@ -58,4 +60,7 @@
 #endif
       !
+      CALL iom_put( 'agrif_spu', fspu(:,:))
+      CALL iom_put( 'agrif_spv', fspv(:,:))
+      !
    END SUBROUTINE Agrif_Sponge_Tra
 
@@ -85,4 +90,7 @@
 #endif
       !
+      CALL iom_put( 'agrif_spt', fspt(:,:))
+      CALL iom_put( 'agrif_spf', fspf(:,:))
+      !
    END SUBROUTINE Agrif_Sponge_dyn
 
@@ -93,62 +101,163 @@
       !!----------------------------------------------------------------------
       INTEGER  ::   ji, jj, ind1, ind2
-      INTEGER  ::   ispongearea
-      REAL(wp) ::   z1_spongearea
+      INTEGER  ::   ispongearea, jspongearea
+      REAL(wp) ::   z1_ispongearea, z1_jspongearea
       REAL(wp), DIMENSION(jpi,jpj) :: ztabramp
-      !!----------------------------------------------------------------------
-      !
+      REAL(wp), DIMENSION(jpjmax)  :: zmskwest,  zmskeast
+      REAL(wp), DIMENSION(jpimax)  :: zmsknorth, zmsksouth
+      !!----------------------------------------------------------------------
+      !
+      ! Sponge 1d example with:
+      !      iraf = 3 ; nbghost = 3 ; nn_sponge_len = 2
+      !                        
+      !coarse :     U     T     U     T     U     T     U
+      !|            |           |           |           |
+      !fine :     t u t u t u t u t u t u t u t u t u t u t
+      !sponge val:0   0   0   1  5/6 4/6 3/6 2/6 1/6  0   0
+      !           |   ghost     | <-- sponge area  -- > |
+      !           |   points    |                       |
+      !                         |--> dynamical interface
+
 #if defined SPONGE || defined SPONGE_TOP
       IF (( .NOT. spongedoneT ).OR.( .NOT. spongedoneU )) THEN
+         !
+         ! Retrieve masks at open boundaries:
+
+         ! --- West --- !
+         ztabramp(:,:) = 0._wp
+         ind1 = 1+nbghostcells
+         DO ji = mi0(ind1), mi1(ind1)                
+            ztabramp(ji,:) = ssumask(ji,:)
+         END DO
+         !
+         zmskwest(:) = 0._wp
+         zmskwest(1:jpj) = MAXVAL(ztabramp(:,:), dim=1)
+
+         ! --- East --- !
+         ztabramp(:,:) = 0._wp
+         ind1 = jpiglo - nbghostcells - 1
+         DO ji = mi0(ind1), mi1(ind1)                 
+            ztabramp(ji,:) = ssumask(ji,:)
+         END DO
+         !
+         zmskeast(:) = 0._wp
+         zmskeast(1:jpj) = MAXVAL(ztabramp(:,:), dim=1)
+
+         ! --- South --- !
+         ztabramp(:,:) = 0._wp
+         ind1 = 1+nbghostcells
+         DO jj = mj0(ind1), mj1(ind1)                 
+            ztabramp(:,jj) = ssvmask(:,jj)
+         END DO
+         !
+         zmsksouth(:) = 0._wp
+         zmsksouth(1:jpi) = MAXVAL(ztabramp(:,:), dim=2)
+
+         ! --- North --- !
+         ztabramp(:,:) = 0._wp
+         ind1 = jpjglo - nbghostcells - 1
+         DO jj = mj0(ind1), mj1(ind1)                 
+            ztabramp(:,jj) = ssvmask(:,jj)
+         END DO
+         !
+         zmsknorth(:) = 0._wp
+         zmsknorth(1:jpi) = MAXVAL(ztabramp(:,:), dim=2)
+         ! JC: SPONGE MASKING TO BE SORTED OUT:
+         zmskwest(:)  = 1._wp
+         zmskeast(:)  = 1._wp
+         zmsknorth(:) = 1._wp
+         zmsksouth(:) = 1._wp
+#if defined key_mpp_mpi
+!         CALL mpp_max( 'AGRIF_sponge', zmskwest(:) , jpjmax )
+!         CALL mpp_max( 'AGRIF_Sponge', zmskeast(:) , jpjmax )
+!         CALL mpp_max( 'AGRIF_Sponge', zmsksouth(:), jpimax )
+!         CALL mpp_max( 'AGRIF_Sponge', zmsknorth(:), jpimax )
+#endif
+
          ! Define ramp from boundaries towards domain interior at T-points
          ! Store it in ztabramp
 
-         ispongearea  = 1 + nn_sponge_len * Agrif_irhox()
-         z1_spongearea = 1._wp / REAL( ispongearea )
+         ispongearea  = nn_sponge_len * Agrif_irhox()
+         z1_ispongearea = 1._wp / REAL( ispongearea )
+         jspongearea  = nn_sponge_len * Agrif_irhoy()
+         z1_jspongearea = 1._wp / REAL( jspongearea )
          
          ztabramp(:,:) = 0._wp
 
+         ! Trick to remove sponge in 2DV domains:
+         IF ( nbcellsx <= 3 ) ispongearea = -1
+         IF ( nbcellsy <= 3 ) jspongearea = -1
+
          ! --- West --- !
-         IF( (nbondi == -1) .OR. (nbondi == 2) ) THEN
-            ind1 = 1+nbghostcells
-            ind2 = 1+nbghostcells + ispongearea 
+         ind1 = 1+nbghostcells
+         ind2 = 1+nbghostcells + ispongearea 
+         DO ji = mi0(ind1), mi1(ind2)   
+            DO jj = 1, jpj               
+               ztabramp(ji,jj) = REAL( ind2 - mig(ji) ) * z1_ispongearea * zmskwest(jj)
+            END DO
+         END DO
+
+         ! ghost cells:
+         ind1 = 1
+         ind2 = nbghostcells + 1
+         DO ji = mi0(ind1), mi1(ind2)   
+            DO jj = 1, jpj               
+               ztabramp(ji,jj) = zmskwest(jj)
+            END DO
+         END DO
+
+         ! --- East --- !
+         ind1 = jpiglo - nbghostcells - ispongearea
+         ind2 = jpiglo - nbghostcells
+         DO ji = mi0(ind1), mi1(ind2)
             DO jj = 1, jpj
-               DO ji = ind1, ind2                
-                  ztabramp(ji,jj) = REAL( ind2 - ji ) * z1_spongearea * umask(ind1,jj,1)
-               END DO
+               ztabramp(ji,jj) = MAX( ztabramp(ji,jj), REAL( mig(ji) - ind1 ) * z1_ispongearea) * zmskeast(jj)
             ENDDO
-         ENDIF
-
-         ! --- East --- !
-         IF( (nbondi == 1) .OR. (nbondi == 2) ) THEN
-            ind1 = nlci - nbghostcells - ispongearea
-            ind2 = nlci - nbghostcells
+         END DO
+
+         ! ghost cells:
+         ind1 = jpiglo - nbghostcells
+         ind2 = jpiglo
+         DO ji = mi0(ind1), mi1(ind2)
             DO jj = 1, jpj
-               DO ji = ind1, ind2
-                  ztabramp(ji,jj) = MAX( ztabramp(ji,jj), REAL( ji - ind1 ) * z1_spongearea * umask(ind2-1,jj,1) )
-               ENDDO
+               ztabramp(ji,jj) = zmskeast(jj)
             ENDDO
-         ENDIF
+         END DO
 
          ! --- South --- !
-         IF( (nbondj == -1) .OR. (nbondj == 2) ) THEN
-            ind1 = 1+nbghostcells
-            ind2 = 1+nbghostcells + ispongearea
-            DO jj = ind1, ind2 
-               DO ji = 1, jpi
-                  ztabramp(ji,jj) = MAX( ztabramp(ji,jj), REAL( ind2 - jj ) * z1_spongearea * vmask(ji,ind1,1) )
-               END DO
-            ENDDO
-         ENDIF
+         ind1 = 1+nbghostcells
+         ind2 = 1+nbghostcells + jspongearea
+         DO jj = mj0(ind1), mj1(ind2) 
+            DO ji = 1, jpi
+               ztabramp(ji,jj) = MAX( ztabramp(ji,jj), REAL( ind2 - mjg(jj) ) * z1_jspongearea) * zmsksouth(ji)
+            END DO
+         END DO
+
+         ! ghost cells:
+         ind1 = 1
+         ind2 = nbghostcells + 1
+         DO jj = mj0(ind1), mj1(ind2) 
+            DO ji = 1, jpi
+               ztabramp(ji,jj) = zmsksouth(ji)
+            END DO
+         END DO
 
          ! --- North --- !
-         IF( (nbondj == 1) .OR. (nbondj == 2) ) THEN
-            ind1 = nlcj - nbghostcells - ispongearea
-            ind2 = nlcj - nbghostcells
-            DO jj = ind1, ind2
-               DO ji = 1, jpi
-                  ztabramp(ji,jj) = MAX( ztabramp(ji,jj), REAL( jj - ind1 ) * z1_spongearea * vmask(ji,ind2-1,1) )
-               END DO
-            ENDDO
-         ENDIF
+         ind1 = jpjglo - nbghostcells - jspongearea
+         ind2 = jpjglo - nbghostcells
+         DO jj = mj0(ind1), mj1(ind2)
+            DO ji = 1, jpi
+               ztabramp(ji,jj) = MAX( ztabramp(ji,jj), REAL( mjg(jj) - ind1 ) * z1_jspongearea) * zmsknorth(ji)
+            END DO
+         END DO
+
+         ! ghost cells:
+         ind1 = jpjglo - nbghostcells
+         ind2 = jpjglo
+         DO jj = mj0(ind1), mj1(ind2)
+            DO ji = 1, jpi
+               ztabramp(ji,jj) = zmsknorth(ji)
+            END DO
+         END DO
 
       ENDIF
@@ -156,15 +265,15 @@
       ! Tracers
       IF( .NOT. spongedoneT ) THEN
-         fsaht_spu(:,:) = 0._wp
-         fsaht_spv(:,:) = 0._wp
+         fspu(:,:) = 0._wp
+         fspv(:,:) = 0._wp
          DO jj = 2, jpjm1
             DO ji = 2, jpim1   ! vector opt.
-               fsaht_spu(ji,jj) = 0.5_wp * visc_tra * ( ztabramp(ji,jj) + ztabramp(ji+1,jj  ) )
-               fsaht_spv(ji,jj) = 0.5_wp * visc_tra * ( ztabramp(ji,jj) + ztabramp(ji  ,jj+1) )
-            END DO
-         END DO
-         CALL lbc_lnk( 'agrif_oce_sponge', fsaht_spu, 'U', 1. )   ! Lateral boundary conditions
-         CALL lbc_lnk( 'agrif_oce_sponge', fsaht_spv, 'V', 1. )
-         
+               fspu(ji,jj) = 0.5_wp * ( ztabramp(ji,jj) + ztabramp(ji+1,jj  ) ) * ssumask(ji,jj)
+               fspv(ji,jj) = 0.5_wp * ( ztabramp(ji,jj) + ztabramp(ji  ,jj+1) ) * ssvmask(ji,jj)
+            END DO
+         END DO
+         CALL lbc_lnk( 'agrif_Sponge', fspu, 'U', 1. )   ! Lateral boundary conditions
+         CALL lbc_lnk( 'agrif_Sponge', fspv, 'V', 1. )
+
          spongedoneT = .TRUE.
       ENDIF
@@ -172,18 +281,46 @@
       ! Dynamics
       IF( .NOT. spongedoneU ) THEN
-         fsahm_spt(:,:) = 0._wp
-         fsahm_spf(:,:) = 0._wp
+         fspt(:,:) = 0._wp
+         fspf(:,:) = 0._wp
          DO jj = 2, jpjm1
             DO ji = 2, jpim1   ! vector opt.
-               fsahm_spt(ji,jj) = visc_dyn * ztabramp(ji,jj)
-               fsahm_spf(ji,jj) = 0.25_wp * visc_dyn * ( ztabramp(ji  ,jj  ) + ztabramp(ji  ,jj+1) &
-                                                     &  +ztabramp(ji+1,jj+1) + ztabramp(ji+1,jj  ) )
-            END DO
-         END DO
-         CALL lbc_lnk( 'agrif_oce_sponge', fsahm_spt, 'T', 1. )   ! Lateral boundary conditions
-         CALL lbc_lnk( 'agrif_oce_sponge', fsahm_spf, 'F', 1. )
+               fspt(ji,jj) = ztabramp(ji,jj) * ssmask(ji,jj)
+               fspf(ji,jj) = 0.25_wp * ( ztabramp(ji  ,jj  ) + ztabramp(ji  ,jj+1)   &
+                                     &  +ztabramp(ji+1,jj+1) + ztabramp(ji+1,jj  ) ) &
+                                     &  * ssvmask(ji,jj) * ssvmask(ji,jj+1)
+            END DO
+         END DO
+         CALL lbc_lnk( 'agrif_Sponge', fspt, 'T', 1. )   ! Lateral boundary conditions
+         CALL lbc_lnk( 'agrif_Sponge', fspf, 'F', 1. )
          
          spongedoneU = .TRUE.
       ENDIF
+
+#if defined key_vertical
+      ! Remove vertical interpolation where not needed:
+      DO jj = 2, jpjm1
+         DO ji = 2, jpim1
+            IF ((fspu(ji-1,jj)==0._wp).AND.(fspu(ji,jj)==0._wp).AND. &
+            &   (fspv(ji,jj-1)==0._wp).AND.(fspv(ji,jj)==0._wp)) mbkt_parent(ji,jj) = 0
+!
+            IF ((fspt(ji+1,jj)==0._wp).AND.(fspt(ji,jj)==0._wp).AND. &
+            &   (fspf(ji,jj-1)==0._wp).AND.(fspf(ji,jj)==0._wp)) mbku_parent(ji,jj) = 0
+!
+            IF ((fspt(ji,jj+1)==0._wp).AND.(fspt(ji,jj)==0._wp).AND. &
+            &   (fspf(ji-1,jj)==0._wp).AND.(fspf(ji,jj)==0._wp)) mbkv_parent(ji,jj) = 0
+!
+            IF ( ssmask(ji,jj) == 0._wp) mbkt_parent(ji,jj) = 0
+            IF (ssumask(ji,jj) == 0._wp) mbku_parent(ji,jj) = 0
+            IF (ssvmask(ji,jj) == 0._wp) mbkv_parent(ji,jj) = 0
+         END DO
+      END DO
+      !
+      ztabramp(:,:) = REAL( mbkt_parent(:,:), wp )   ;   CALL lbc_lnk( 'Agrif_Sponge', ztabramp, 'T', 1. )
+      mbkt_parent(:,:) = NINT( ztabramp(:,:) )
+      ztabramp(:,:) = REAL( mbku_parent(:,:), wp )   ;   CALL lbc_lnk( 'Agrif_Sponge', ztabramp, 'U', 1. )
+      mbku_parent(:,:) = NINT( ztabramp(:,:) )
+      ztabramp(:,:) = REAL( mbkv_parent(:,:), wp )   ;   CALL lbc_lnk( 'Agrif_Sponge', ztabramp, 'V', 1. )
+      mbkv_parent(:,:) = NINT( ztabramp(:,:) )
+#endif
       !
 #endif
@@ -201,5 +338,5 @@
       INTEGER  ::   ji, jj, jk, jn   ! dummy loop indices
       INTEGER  ::   iku, ikv
-      REAL(wp) :: ztsa, zabe1, zabe2, zbtr
+      REAL(wp) :: ztsa, zabe1, zabe2, zbtr, zhtot, ztrelax
       REAL(wp), DIMENSION(i1:i2,j1:j2,jpk) :: ztu, ztv
       REAL(wp), DIMENSION(i1:i2,j1:j2,jpk,n1:n2) ::tsbdiff
@@ -210,5 +347,4 @@
       REAL(wp), DIMENSION(1:jpk) :: h_out
       INTEGER :: N_in, N_out
-      REAL(wp) :: h_diff
       !!----------------------------------------------------------------------
       !
@@ -225,11 +361,31 @@
 
 # if defined key_vertical
-         DO jk=k1,k2
-            DO jj=j1,j2
-               DO ji=i1,i2
-                  tabres(ji,jj,jk,jpts+1) = tmask(ji,jj,jk) * e3t_n(ji,jj,jk) 
-               END DO
-            END DO
-         END DO
+        ! Interpolate thicknesses
+        ! Warning: these are masked, hence extrapolated prior interpolation.
+        DO jk=k1,k2
+           DO jj=j1,j2
+              DO ji=i1,i2
+                  tabres(ji,jj,jk,jpts+1) = tmask(ji,jj,jk) * e3t_b(ji,jj,jk)
+              END DO
+           END DO
+        END DO
+
+        ! Extrapolate thicknesses in partial bottom cells:
+        ! Set them to Agrif_SpecialValue (0.). Correct bottom thicknesses are retrieved later on
+        IF (ln_zps) THEN
+           DO jj=j1,j2
+              DO ji=i1,i2
+                  jk = mbkt(ji,jj)
+                  tabres(ji,jj,jk,jpts+1) = 0._wp
+              END DO
+           END DO           
+        END IF
+     
+        ! Save ssh at last level:
+        IF (.NOT.ln_linssh) THEN
+           tabres(i1:i2,j1:j2,k2,jpts+1) = sshb(i1:i2,j1:j2)*tmask(i1:i2,j1:j2,1) 
+        ELSE
+           tabres(i1:i2,j1:j2,k2,jpts+1) = 0._wp
+        END IF      
 # endif
 
@@ -237,13 +393,20 @@
          !
 # if defined key_vertical
-         tabres_child(:,:,:,:) = 0.
+
+         IF (ln_linssh) tabres(i1:i2,j1:j2,k2,n2) = 0._wp
+
          DO jj=j1,j2
             DO ji=i1,i2
-               N_in = 0
-               DO jk=k1,k2 !k2 = jpk of parent grid
-                  IF (tabres(ji,jj,jk,n2) == 0) EXIT
-                  N_in = N_in + 1
+               tabres_child(ji,jj,:,:) = 0._wp 
+               N_in = mbkt_parent(ji,jj)
+               zhtot = 0._wp
+               DO jk=1,N_in !k2 = jpk of parent grid
+                  IF (jk==N_in) THEN
+                     h_in(jk) = ht0_parent(ji,jj) + tabres(ji,jj,k2,n2) - zhtot
+                  ELSE
+                     h_in(jk) = tabres(ji,jj,jk,n2)
+                  ENDIF
+                  zhtot = zhtot + h_in(jk)
                   tabin(jk,:) = tabres(ji,jj,jk,n1:n2-1)
-                  h_in(N_in) = tabres(ji,jj,jk,n2)
                END DO
                N_out = 0
@@ -251,12 +414,15 @@
                   IF (tmask(ji,jj,jk) == 0) EXIT 
                   N_out = N_out + 1
-                  h_out(jk) = e3t_n(ji,jj,jk) !Child grid scale factors. Could multiply by e1e2t here instead of division above
+                  h_out(jk) = e3t_b(ji,jj,jk) !Child grid scale factors. Could multiply by e1e2t here instead of division above
                ENDDO
-               IF (N_in > 0) THEN
-                  h_diff = sum(h_out(1:N_out))-sum(h_in(1:N_in))
-                  tabres(ji,jj,k2,:) = tabres(ji,jj,k2-1,:) !what is this line for?????
-                  DO jn=1,jpts
-                     call reconstructandremap(tabin(1:N_in,jn),h_in,tabres_child(ji,jj,1:N_out,jn),h_out,N_in,N_out)
-                  ENDDO
+
+               ! Account for small differences in free-surface
+               IF ( sum(h_out(1:N_out)) > sum(h_in(1:N_in) )) THEN
+                  h_out(1) = h_out(1) - ( sum(h_out(1:N_out))-sum(h_in(1:N_in)) )
+               ELSE
+                  h_in(1)   = h_in(1)   - (sum(h_in(1:N_in))-sum(h_out(1:N_out)) )
+               ENDIF
+               IF (N_in*N_out > 0) THEN
+                  CALL reconstructandremap(tabin(1:N_in,1:jpts),h_in(1:N_in),tabres_child(ji,jj,1:N_out,1:jpts),h_out(1:N_out),N_in,N_out,jpts)
                ENDIF
             ENDDO
@@ -268,11 +434,16 @@
                DO jk=1,jpkm1
 # if defined key_vertical
-                  tsbdiff(ji,jj,jk,1:jpts) = tsb(ji,jj,jk,1:jpts) - tabres_child(ji,jj,jk,1:jpts)
+                  tsbdiff(ji,jj,jk,1:jpts) = (tsb(ji,jj,jk,1:jpts) - tabres_child(ji,jj,jk,1:jpts)) * tmask(ji,jj,jk)
 # else
-                  tsbdiff(ji,jj,jk,1:jpts) = tsb(ji,jj,jk,1:jpts) - tabres(ji,jj,jk,1:jpts)
+                  tsbdiff(ji,jj,jk,1:jpts) = (tsb(ji,jj,jk,1:jpts) - tabres(ji,jj,jk,1:jpts))*tmask(ji,jj,jk)
 # endif
                ENDDO
             ENDDO
          ENDDO
+
+         !* set relaxation time scale
+         IF( neuler == 0 .AND. lk_agrif_fstep ) THEN   ;   ztrelax =   rn_trelax_tra  / (        rdt )
+         ELSE                                          ;   ztrelax =   rn_trelax_tra  / (2._wp * rdt )
+         ENDIF
 
          DO jn = 1, jpts            
@@ -281,5 +452,5 @@
                DO jj = j1,j2
                   DO ji = i1,i2-1
-                     zabe1 = fsaht_spu(ji,jj) * umask(ji,jj,jk) * e2_e1u(ji,jj) * e3u_n(ji,jj,jk)
+                     zabe1 = rn_sponge_tra * fspu(ji,jj) * umask(ji,jj,jk) * e2_e1u(ji,jj) * e3u_n(ji,jj,jk)
                      ztu(ji,jj,jk) = zabe1 * ( tsbdiff(ji+1,jj  ,jk,jn) - tsbdiff(ji,jj,jk,jn) ) 
                   END DO
@@ -288,5 +459,5 @@
                DO ji = i1,i2
                   DO jj = j1,j2-1
-                     zabe2 = fsaht_spv(ji,jj) * vmask(ji,jj,jk) * e1_e2v(ji,jj) * e3v_n(ji,jj,jk)
+                     zabe2 = rn_sponge_tra * fspv(ji,jj) * vmask(ji,jj,jk) * e1_e2v(ji,jj) * e3v_n(ji,jj,jk)
                      ztv(ji,jj,jk) = zabe2 * ( tsbdiff(ji  ,jj+1,jk,jn) - tsbdiff(ji,jj,jk,jn) )
                   END DO
@@ -312,5 +483,6 @@
                         zbtr = r1_e1e2t(ji,jj) / e3t_n(ji,jj,jk)
                         ! horizontal diffusive trends
-                        ztsa = zbtr * (  ztu(ji,jj,jk) - ztu(ji-1,jj,jk) + ztv(ji,jj,jk) - ztv(ji,jj-1,jk)  )
+                        ztsa = zbtr * (  ztu(ji,jj,jk) - ztu(ji-1,jj,jk) + ztv(ji,jj,jk) - ztv(ji,jj-1,jk)  ) &
+                             &  - ztrelax * fspt(ji,jj) * tsbdiff(ji,jj,jk,jn) 
                         ! add it to the general tracer trends
                         tsa(ji,jj,jk,jn) = tsa(ji,jj,jk,jn) + ztsa
@@ -339,5 +511,5 @@
 
       ! sponge parameters 
-      REAL(wp) :: ze2u, ze1v, zua, zva, zbtr, h_diff
+      REAL(wp) :: ze2u, ze1v, zua, zva, zbtr, zhtot, ztrelax
       REAL(wp), DIMENSION(i1:i2,j1:j2,1:jpk) :: ubdiff
       REAL(wp), DIMENSION(i1:i2,j1:j2,1:jpk) :: rotdiff, hdivdiff
@@ -346,14 +518,14 @@
       REAL(wp), DIMENSION(k1:k2) :: tabin, h_in
       REAL(wp), DIMENSION(1:jpk) :: h_out
-      INTEGER ::N_in,N_out
+      INTEGER ::N_in, N_out
       !!---------------------------------------------    
       !
       IF( before ) THEN
-         DO jk=1,jpkm1
+         DO jk=k1,k2
             DO jj=j1,j2
                DO ji=i1,i2
                   tabres(ji,jj,jk,m1) = ub(ji,jj,jk)
 # if defined key_vertical
-                  tabres(ji,jj,jk,m2) = e3u_n(ji,jj,jk)*umask(ji,jj,jk)
+                  tabres(ji,jj,jk,m2) = e3u_b(ji,jj,jk)*umask(ji,jj,jk)
 # endif
                END DO
@@ -361,43 +533,63 @@
          END DO
 
+# if defined key_vertical
+         ! Extrapolate thicknesses in partial bottom cells:
+         ! Set them to Agrif_SpecialValue (0.). Correct bottom thicknesses are retrieved later on
+         IF (ln_zps) THEN
+            DO jj=j1,j2
+               DO ji=i1,i2
+                  jk = mbku(ji,jj)
+                  tabres(ji,jj,jk,m2) = 0._wp
+               END DO
+            END DO           
+         END IF
+        ! Save ssh at last level:
+        tabres(i1:i2,j1:j2,k2,m2) = 0._wp
+        IF (.NOT.ln_linssh) THEN
+           ! This vertical sum below should be replaced by the sea-level at U-points (optimization):
+           DO jk=1,jpk
+              tabres(i1:i2,j1:j2,k2,m2) = tabres(i1:i2,j1:j2,k2,m2) + e3u_b(i1:i2,j1:j2,jk) * umask(i1:i2,j1:j2,jk)
+           END DO
+           tabres(i1:i2,j1:j2,k2,m2) = tabres(i1:i2,j1:j2,k2,m2) - hu_0(i1:i2,j1:j2)
+        END IF 
+# endif
+
       ELSE
 
 # if defined key_vertical
-         tabres_child(:,:,:) = 0._wp
+         IF (ln_linssh) tabres(i1:i2,j1:j2,k2,m2) = 0._wp
+
          DO jj=j1,j2
             DO ji=i1,i2
-               N_in = 0
-               DO jk=k1,k2
-                  IF (tabres(ji,jj,jk,m2) == 0) EXIT
-                  N_in = N_in + 1
+               tabres_child(ji,jj,:) = 0._wp
+               N_in = mbku_parent(ji,jj)
+               zhtot = 0._wp
+               DO jk=1,N_in
+                  IF (jk==N_in) THEN
+                     h_in(jk) = hu0_parent(ji,jj) + tabres(ji,jj,k2,m2) - zhtot
+                  ELSE
+                     h_in(jk) = tabres(ji,jj,jk,m2)
+                  ENDIF
+                  zhtot = zhtot + h_in(jk)
                   tabin(jk) = tabres(ji,jj,jk,m1)
-                  h_in(N_in) = tabres(ji,jj,jk,m2)
-              ENDDO
-              !
-              IF (N_in == 0) THEN
-                 tabres_child(ji,jj,:) = 0.
-                 CYCLE
-              ENDIF
-         
-              N_out = 0
-              DO jk=1,jpk
-                 if (umask(ji,jj,jk) == 0) EXIT
-                 N_out = N_out + 1
-                 h_out(N_out) = e3u_n(ji,jj,jk)
-              ENDDO
-         
-              IF (N_out == 0) THEN
-                 tabres_child(ji,jj,:) = 0.
-                 CYCLE
-              ENDIF
-         
-              IF (N_in * N_out > 0) THEN
-                 h_diff = sum(h_out(1:N_out))-sum(h_in(1:N_in))
-                 if (h_diff < -1.e4) then
-                    print *,'CHECK YOUR BATHY ...', h_diff, sum(h_out(1:N_out)), sum(h_in(1:N_in))
-                 endif
-              ENDIF
-              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)
-         
+               ENDDO
+               !         
+               N_out = 0
+               DO jk=1,jpk
+                  IF (umask(ji,jj,jk) == 0) EXIT
+                  N_out = N_out + 1
+                  h_out(N_out) = e3u_b(ji,jj,jk)
+               ENDDO
+
+               ! Account for small differences in free-surface
+               IF ( sum(h_out(1:N_out)) > sum(h_in(1:N_in) )) THEN
+                  h_out(1) = h_out(1) - ( sum(h_out(1:N_out))-sum(h_in(1:N_in)) )
+               ELSE
+                  h_in(1)   = h_in(1)   - (sum(h_in(1:N_in))-sum(h_out(1:N_out)) )
+               ENDIF
+                  
+               IF (N_in * N_out > 0) THEN
+                  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)
+               ENDIF 
             ENDDO
          ENDDO
@@ -407,4 +599,8 @@
          ubdiff(i1:i2,j1:j2,:) = (ub(i1:i2,j1:j2,:) - tabres(i1:i2,j1:j2,:,1))*umask(i1:i2,j1:j2,:)
 #endif
+         !* set relaxation time scale
+         IF( neuler == 0 .AND. lk_agrif_fstep ) THEN   ;   ztrelax =   rn_trelax_dyn  / (        rdt )
+         ELSE                                          ;   ztrelax =   rn_trelax_dyn  / (2._wp * rdt )
+         ENDIF
          !
          DO jk = 1, jpkm1                                 ! Horizontal slab
@@ -416,7 +612,7 @@
             DO jj = j1,j2
                DO ji = i1+1,i2   ! vector opt.
-                  zbtr = r1_e1e2t(ji,jj) / e3t_n(ji,jj,jk) * fsahm_spt(ji,jj)
-                  hdivdiff(ji,jj,jk) = (  e2u(ji  ,jj)*e3u_n(ji  ,jj,jk) * ubdiff(ji  ,jj,jk) &
-                                     &   -e2u(ji-1,jj)*e3u_n(ji-1,jj,jk) * ubdiff(ji-1,jj,jk) ) * zbtr
+                  zbtr = r1_e1e2t(ji,jj) / e3t_b(ji,jj,jk) * rn_sponge_dyn * fspt(ji,jj)
+                  hdivdiff(ji,jj,jk) = (  e2u(ji  ,jj)*e3u_b(ji  ,jj,jk) * ubdiff(ji  ,jj,jk) &
+                                     &   -e2u(ji-1,jj)*e3u_b(ji-1,jj,jk) * ubdiff(ji-1,jj,jk) ) * zbtr
                END DO
             END DO
@@ -424,5 +620,5 @@
             DO jj = j1,j2-1
                DO ji = i1,i2   ! vector opt.
-                  zbtr = r1_e1e2f(ji,jj) * e3f_n(ji,jj,jk) * fsahm_spf(ji,jj)
+                  zbtr = r1_e1e2f(ji,jj) * e3f_n(ji,jj,jk) * rn_sponge_dyn * fspf(ji,jj)
                   rotdiff(ji,jj,jk) = ( -e1u(ji,jj+1) * ubdiff(ji,jj+1,jk)   &
                                     &   +e1u(ji,jj  ) * ubdiff(ji,jj  ,jk) ) * fmask(ji,jj,jk) * zbtr 
@@ -440,9 +636,9 @@
                      ! horizontal diffusive trends
                      zua = - ( ze2u - rotdiff (ji,jj-1,jk) ) / ( e2u(ji,jj) * e3u_n(ji,jj,jk) )   &
-                           + ( hdivdiff(ji+1,jj,jk) - ze1v ) * r1_e1u(ji,jj)
+                         & + ( hdivdiff(ji+1,jj,jk) - ze1v ) * r1_e1u(ji,jj) & 
+                         & - ztrelax  * fspu(ji,jj) * ubdiff(ji,jj,jk)
 
                      ! add it to the general momentum trends
-                     ua(ji,jj,jk) = ua(ji,jj,jk) + zua
-
+                     ua(ji,jj,jk) = ua(ji,jj,jk) + zua                                 
                   END DO
                ENDIF
@@ -492,5 +688,5 @@
       !
       INTEGER  ::   ji, jj, jk, imax
-      REAL(wp) ::   ze2u, ze1v, zua, zva, zbtr, h_diff
+      REAL(wp) ::   ze2u, ze1v, zua, zva, zbtr, zhtot, ztrelax
       REAL(wp), DIMENSION(i1:i2,j1:j2,1:jpk) :: vbdiff
       REAL(wp), DIMENSION(i1:i2,j1:j2,1:jpk) :: rotdiff, hdivdiff
@@ -503,47 +699,73 @@
       
       IF( before ) THEN 
-         DO jk=1,jpkm1
+         DO jk=k1,k2
             DO jj=j1,j2
                DO ji=i1,i2
                   tabres(ji,jj,jk,m1) = vb(ji,jj,jk)
 # if defined key_vertical
-                  tabres(ji,jj,jk,m2) = vmask(ji,jj,jk) * e3v_n(ji,jj,jk)
+                  tabres(ji,jj,jk,m2) = vmask(ji,jj,jk) * e3v_b(ji,jj,jk)
 # endif
                END DO
             END DO
          END DO
+
+# if defined key_vertical
+         ! Extrapolate thicknesses in partial bottom cells:
+         ! Set them to Agrif_SpecialValue (0.). Correct bottom thicknesses are retrieved later on
+         IF (ln_zps) THEN
+            DO jj=j1,j2
+               DO ji=i1,i2
+                  jk = mbkv(ji,jj)
+                  tabres(ji,jj,jk,m2) = 0._wp
+               END DO
+            END DO           
+         END IF
+        ! Save ssh at last level:
+        tabres(i1:i2,j1:j2,k2,m2) = 0._wp
+        IF (.NOT.ln_linssh) THEN
+           ! This vertical sum below should be replaced by the sea-level at V-points (optimization):
+           DO jk=1,jpk
+              tabres(i1:i2,j1:j2,k2,m2) = tabres(i1:i2,j1:j2,k2,m2) + e3v_b(i1:i2,j1:j2,jk) * vmask(i1:i2,j1:j2,jk)
+           END DO
+           tabres(i1:i2,j1:j2,k2,m2) = tabres(i1:i2,j1:j2,k2,m2) - hv_0(i1:i2,j1:j2)
+        END IF 
+# endif
+
       ELSE
 
 # if defined key_vertical
-         tabres_child(:,:,:) = 0._wp
+         IF (ln_linssh) tabres(i1:i2,j1:j2,k2,m2) = 0._wp
          DO jj=j1,j2
             DO ji=i1,i2
-               N_in = 0
-               DO jk=k1,k2
-                  IF (tabres(ji,jj,jk,m2) == 0) EXIT
-                  N_in = N_in + 1
+               tabres_child(ji,jj,:) = 0._wp
+               N_in = mbkv_parent(ji,jj)
+               zhtot = 0._wp
+               DO jk=1,N_in
+                  IF (jk==N_in) THEN
+                     h_in(jk) = hv0_parent(ji,jj) + tabres(ji,jj,k2,m2) - zhtot
+                  ELSE
+                     h_in(jk) = tabres(ji,jj,jk,m2)
+                  ENDIF
+                  zhtot = zhtot + h_in(jk)
                   tabin(jk) = tabres(ji,jj,jk,m1)
-                  h_in(N_in) = tabres(ji,jj,jk,m2)
-              ENDDO
+               ENDDO
+               !          
+               N_out = 0
+               DO jk=1,jpk
+                  IF (vmask(ji,jj,jk) == 0) EXIT
+                  N_out = N_out + 1
+                  h_out(N_out) = e3v_b(ji,jj,jk)
+               ENDDO
+
+               ! Account for small differences in free-surface
+               IF ( sum(h_out(1:N_out)) > sum(h_in(1:N_in) )) THEN
+                  h_out(1) = h_out(1) - ( sum(h_out(1:N_out))-sum(h_in(1:N_in)) )
+               ELSE
+                  h_in(1)   = h_in(1) - (  sum(h_in(1:N_in))-sum(h_out(1:N_out)) )
+               ENDIF
          
-              IF (N_in == 0) THEN
-                 tabres_child(ji,jj,:) = 0.
-                 CYCLE
-              ENDIF
-         
-              N_out = 0
-              DO jk=1,jpk
-                 if (vmask(ji,jj,jk) == 0) EXIT
-                 N_out = N_out + 1
-                 h_out(N_out) = e3v_n(ji,jj,jk)
-              ENDDO
-         
-              IF (N_in * N_out > 0) THEN
-                 h_diff = sum(h_out(1:N_out))-sum(h_in(1:N_in))
-                 if (h_diff < -1.e4) then
-                    print *,'CHECK YOUR BATHY ...', h_diff, sum(h_out(1:N_out)), sum(h_in(1:N_in))
-                 endif
-              ENDIF
-              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)
+               IF (N_in * N_out > 0) THEN
+                  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)
+               ENDIF
             ENDDO
          ENDDO
@@ -553,4 +775,8 @@
          vbdiff(i1:i2,j1:j2,:) = (vb(i1:i2,j1:j2,:) - tabres(i1:i2,j1:j2,:,1))*vmask(i1:i2,j1:j2,:)
 # endif
+         !* set relaxation time scale
+         IF( neuler == 0 .AND. lk_agrif_fstep ) THEN   ;   ztrelax =   rn_trelax_dyn  / (        rdt )
+         ELSE                                          ;   ztrelax =   rn_trelax_dyn  / (2._wp * rdt )
+         ENDIF
          !
          DO jk = 1, jpkm1                                 ! Horizontal slab
@@ -562,12 +788,12 @@
             DO jj = j1+1,j2
                DO ji = i1,i2   ! vector opt.
-                  zbtr = r1_e1e2t(ji,jj) / e3t_n(ji,jj,jk) * fsahm_spt(ji,jj)
-                  hdivdiff(ji,jj,jk) = ( e1v(ji,jj  ) * e3v_n(ji,jj  ,jk) * vbdiff(ji,jj  ,jk)  &
-                                     &  -e1v(ji,jj-1) * e3v_n(ji,jj-1,jk) * vbdiff(ji,jj-1,jk)  ) * zbtr
+                  zbtr = r1_e1e2t(ji,jj) / e3t_b(ji,jj,jk) * rn_sponge_dyn * fspt(ji,jj)
+                  hdivdiff(ji,jj,jk) = ( e1v(ji,jj  ) * e3v_b(ji,jj  ,jk) * vbdiff(ji,jj  ,jk)  &
+                                     &  -e1v(ji,jj-1) * e3v_b(ji,jj-1,jk) * vbdiff(ji,jj-1,jk)  ) * zbtr
                END DO
             END DO
             DO jj = j1,j2
                DO ji = i1,i2-1   ! vector opt.
-                  zbtr = r1_e1e2f(ji,jj) * e3f_n(ji,jj,jk) * fsahm_spf(ji,jj)
+                  zbtr = r1_e1e2f(ji,jj) * e3f_n(ji,jj,jk) * rn_sponge_dyn * fspf(ji,jj)
                   rotdiff(ji,jj,jk) = ( e2v(ji+1,jj) * vbdiff(ji+1,jj,jk) & 
                                     &  -e2v(ji  ,jj) * vbdiff(ji  ,jj,jk)  ) * fmask(ji,jj,jk) * zbtr
@@ -602,5 +828,6 @@
                      va(ji,jj,jk) = va(ji,jj,jk)                                                                  &
                         &  + ( rotdiff (ji,jj  ,jk) - rotdiff (ji-1,jj,jk) ) / ( e1v(ji,jj) * e3v_n(ji,jj,jk) )   &
-                        &  + ( hdivdiff(ji,jj+1,jk) - hdivdiff(ji  ,jj,jk) ) * r1_e2v(ji,jj)
+                        &  + ( hdivdiff(ji,jj+1,jk) - hdivdiff(ji  ,jj,jk) ) * r1_e2v(ji,jj)                      &
+                        &  - ztrelax * fspv(ji,jj) * vbdiff(ji,jj,jk)
                   END DO
                ENDIF
Index: /NEMO/branches/2019/dev_r12072_MERGE_OPTION2_2019/src/NST/agrif_oce_update.F90
===================================================================
--- /NEMO/branches/2019/dev_r12072_MERGE_OPTION2_2019/src/NST/agrif_oce_update.F90	(revision 12190)
+++ /NEMO/branches/2019/dev_r12072_MERGE_OPTION2_2019/src/NST/agrif_oce_update.F90	(revision 12191)
@@ -1,5 +1,5 @@
-#define TWO_WAY        /* TWO WAY NESTING */
-#undef DECAL_FEEDBACK  /* SEPARATION of INTERFACES*/
-#undef VOL_REFLUX      /* VOLUME REFLUXING*/
+#undef DECAL_FEEDBACK     /* SEPARATION of INTERFACES */
+#undef DECAL_FEEDBACK_2D  /* SEPARATION of INTERFACES (Barotropic mode) */
+#undef VOL_REFLUX         /* VOLUME REFLUXING*/
  
 MODULE agrif_oce_update
@@ -25,4 +25,5 @@
    USE lib_mpp        ! MPP library
    USE domvvl         ! Need interpolation routines 
+   USE vremap         ! Vertical remapping
 
    IMPLICIT NONE
@@ -46,8 +47,14 @@
       IF (Agrif_Root()) RETURN
       !
-#if defined TWO_WAY  
       IF (lwp.AND.lk_agrif_debug) Write(*,*) 'Update tracers  from grid Number',Agrif_Fixed()
 
+#if defined key_vertical
+! Effect of this has to be carrefully checked 
+! depending on what the nesting tools ensure for
+! volume conservation:
+      Agrif_UseSpecialValueInUpdate = .FALSE.
+#else
       Agrif_UseSpecialValueInUpdate = .TRUE.
+#endif
       Agrif_SpecialValueFineGrid    = 0._wp
       ! 
@@ -64,5 +71,4 @@
       Agrif_UseSpecialValueInUpdate = .FALSE.
       !
-#endif
       !
    END SUBROUTINE Agrif_Update_Tra
@@ -75,5 +81,4 @@
       IF (Agrif_Root()) RETURN
       !
-#if defined TWO_WAY
       IF (lwp.AND.lk_agrif_debug) Write(*,*) 'Update momentum from grid Number',Agrif_Fixed()
 
@@ -95,5 +100,5 @@
 # endif
 
-# if ! defined DECAL_FEEDBACK
+# if ! defined DECAL_FEEDBACK_2D
       CALL Agrif_Update_Variable(e1u_id,procname = updateU2d)
       CALL Agrif_Update_Variable(e2v_id,procname = updateV2d)  
@@ -103,5 +108,5 @@
 # endif
       !
-# if ! defined DECAL_FEEDBACK
+# if ! defined DECAL_FEEDBACK_2D
       ! Account for updated thicknesses at boundary edges
       IF (.NOT.ln_linssh) THEN
@@ -113,5 +118,5 @@
       IF ( ln_dynspg_ts .AND. ln_bt_fw ) THEN
          ! Update time integrated transports
-#  if ! defined DECAL_FEEDBACK
+#  if ! defined DECAL_FEEDBACK_2D
          CALL Agrif_Update_Variable(ub2b_update_id,procname = updateub2b)
          CALL Agrif_Update_Variable(vb2b_update_id,procname = updatevb2b)
@@ -121,5 +126,4 @@
 #  endif
       END IF
-#endif
       !
    END SUBROUTINE Agrif_Update_Dyn
@@ -131,10 +135,8 @@
       ! 
       IF (Agrif_Root()) RETURN
-      !
-#if defined TWO_WAY
       !
       Agrif_UseSpecialValueInUpdate = .TRUE.
       Agrif_SpecialValueFineGrid = 0.
-# if ! defined DECAL_FEEDBACK
+# if ! defined DECAL_FEEDBACK_2D
       CALL Agrif_Update_Variable(sshn_id,procname = updateSSH)
 # else
@@ -147,5 +149,5 @@
       IF ( ln_dynspg_ts.AND.ln_bt_fw ) THEN
          ! Refluxing on ssh:
-#  if defined DECAL_FEEDBACK
+#  if defined DECAL_FEEDBACK_2D
          CALL Agrif_Update_Variable(ub2b_update_id,locupdate1=(/0, 0/),locupdate2=(/1, 1/),procname = reflux_sshu)
          CALL Agrif_Update_Variable(vb2b_update_id,locupdate1=(/1, 1/),locupdate2=(/0, 0/),procname = reflux_sshv)
@@ -157,6 +159,4 @@
 #  endif
       !
-#endif
-      !
    END SUBROUTINE Agrif_Update_ssh
 
@@ -170,6 +170,4 @@
       IF (Agrif_Root()) RETURN
       !       
-#  if defined TWO_WAY
-
       Agrif_UseSpecialValueInUpdate = .TRUE.
       Agrif_SpecialValueFineGrid = 0.
@@ -180,6 +178,4 @@
 
       Agrif_UseSpecialValueInUpdate = .FALSE.
-
-#  endif
       
    END SUBROUTINE Agrif_Update_Tke
@@ -192,6 +188,4 @@
       !
       IF (Agrif_Root()) RETURN
-      !
-#if defined TWO_WAY  
       !
       IF (lwp.AND.lk_agrif_debug) Write(*,*) 'Update e3 from grid Number',Agrif_Fixed(), 'Step', Agrif_Nb_Step()
@@ -209,6 +203,4 @@
       CALL dom_vvl_update_UVF
       CALL Agrif_ParentGrid_To_ChildGrid()
-      !
-#endif
       !
    END SUBROUTINE Agrif_Update_vvl
@@ -300,21 +292,23 @@
       !!
       INTEGER :: ji,jj,jk,jn
-      REAL(wp), DIMENSION(i1:i2,j1:j2,1:jpk,n1:n2) :: tabres_child
+      INTEGER  :: N_in, N_out
+      REAL(wp) :: ztb, ztnu, ztno
       REAL(wp) :: h_in(k1:k2)
       REAL(wp) :: h_out(1:jpk)
-      INTEGER  :: N_in, N_out
-      REAL(wp) :: zrho_xy, h_diff
-      REAL(wp) :: tabin(k1:k2,n1:n2)
+      REAL(wp) :: tabin(k1:k2,1:jpts)
+      REAL(wp), DIMENSION(i1:i2,j1:j2,1:jpk,1:jpts) :: tabres_child
       !!---------------------------------------------
       !
       IF (before) THEN
-         AGRIF_SpecialValue = -999._wp
-         zrho_xy = Agrif_rhox() * Agrif_rhoy() 
+!jc_alt
+!         AGRIF_SpecialValue = -999._wp
          DO jn = n1,n2-1
             DO jk=k1,k2
                DO jj=j1,j2
                   DO ji=i1,i2
-                     tabres(ji,jj,jk,jn) = (tsn(ji,jj,jk,jn) * e3t_n(ji,jj,jk) ) &
-                                           * tmask(ji,jj,jk) + (tmask(ji,jj,jk)-1)*999._wp
+!jc_alt
+!                     tabres(ji,jj,jk,jn) = (tsn(ji,jj,jk,jn) * e3t_n(ji,jj,jk) ) &
+!                                         &  * tmask(ji,jj,jk) + (tmask(ji,jj,jk)-1._wp) * 999._wp
+                     tabres(ji,jj,jk,jn) = tsn(ji,jj,jk,jn) * e3t_n(ji,jj,jk)
                   END DO
                END DO
@@ -324,11 +318,13 @@
             DO jj=j1,j2
                DO ji=i1,i2
-                  tabres(ji,jj,jk,n2) = tmask(ji,jj,jk) * e3t_n(ji,jj,jk) &
-                                           + (tmask(ji,jj,jk)-1)*999._wp
+!jc_alt
+!                  tabres(ji,jj,jk,n2) =      tmask(ji,jj,jk) * e3t_n(ji,jj,jk) &
+!                                      &   + (tmask(ji,jj,jk) - 1._wp) * 999._wp
+                  tabres(ji,jj,jk,n2) = tmask(ji,jj,jk) * e3t_n(ji,jj,jk)
                END DO
             END DO
          END DO
       ELSE
-         tabres_child(:,:,:,:) = 0.
+         tabres_child(:,:,:,:) = 0._wp
          AGRIF_SpecialValue = 0._wp
          DO jj=j1,j2
@@ -336,5 +332,7 @@
                N_in = 0
                DO jk=k1,k2 !k2 = jpk of child grid
-                  IF (tabres(ji,jj,jk,n2) == 0  ) EXIT
+! jc_alt
+!                  IF (tabres(ji,jj,jk,n2) < -900._wp  ) EXIT
+                  IF (tabres(ji,jj,jk,n2) == 0._wp  ) EXIT
                   N_in = N_in + 1
                   tabin(jk,:) = tabres(ji,jj,jk,n1:n2-1)/tabres(ji,jj,jk,n2)
@@ -343,19 +341,10 @@
                N_out = 0
                DO jk=1,jpk ! jpk of parent grid
-                  IF (tmask(ji,jj,jk) < -900) EXIT ! TODO: Will not work with ISF
+                  IF (tmask(ji,jj,jk) == 0 ) EXIT ! TODO: Will not work with ISF
                   N_out = N_out + 1
                   h_out(N_out) = e3t_n(ji,jj,jk) 
                ENDDO
-               IF (N_in > 0) THEN !Remove this?
-                  h_diff = sum(h_out(1:N_out))-sum(h_in(1:N_in))
-                  IF (h_diff < -1.e-4) THEN
-                     print *,'CHECK YOUR bathy T points ...',ji,jj,h_diff,sum(h_in(1:N_in)),sum(h_out(1:N_out))
-                     print *,h_in(1:N_in)
-                     print *,h_out(1:N_out)
-                     STOP
-                  ENDIF
-                  DO jn=n1,n2-1
-                     CALL reconstructandremap(tabin(1:N_in,jn),h_in(1:N_in),tabres_child(ji,jj,1:N_out,jn),h_out(1:N_out),N_in,N_out)
-                  ENDDO
+               IF (N_in*N_out > 0) THEN !Remove this?
+                  CALL reconstructandremap(tabin(1:N_in,1:jpts),h_in(1:N_in),tabres_child(ji,jj,1:N_out,1:jpts),h_out(1:N_out),N_in,N_out,jpts)
                ENDIF
             ENDDO
@@ -364,24 +353,26 @@
          IF (.NOT.(lk_agrif_fstep.AND.(neuler==0))) THEN
             ! Add asselin part
-            DO jn = n1,n2-1
-               DO jk=1,jpk
-                  DO jj=j1,j2
-                     DO ji=i1,i2
-                        IF( tabres_child(ji,jj,jk,jn) .NE. 0. ) THEN
-                           tsb(ji,jj,jk,jn) = tsb(ji,jj,jk,jn) & 
-                                 & + atfp * ( tabres_child(ji,jj,jk,jn) &
-                                 &          - tsn(ji,jj,jk,jn) ) * tmask(ji,jj,jk)
+            DO jn = 1,jpts
+               DO jk = 1, jpkm1
+                  DO jj = j1, j2
+                     DO ji = i1, i2
+                        IF( tabres_child(ji,jj,jk,jn) /= 0._wp ) THEN
+                           ztb  = tsb(ji,jj,jk,jn) * e3t_b(ji,jj,jk) ! fse3t_b prior update should be used
+                           ztnu = tabres_child(ji,jj,jk,jn) * e3t_n(ji,jj,jk)
+                           ztno = tsn(ji,jj,jk,jn) * e3t_a(ji,jj,jk)
+                           tsb(ji,jj,jk,jn) = ( ztb + atfp * ( ztnu - ztno) )  & 
+                                     &        * tmask(ji,jj,jk) / e3t_b(ji,jj,jk)
                         ENDIF
-                     ENDDO
-                  ENDDO
-               ENDDO
-            ENDDO
-         ENDIF
-         DO jn = n1,n2-1
-            DO jk=1,jpk
-               DO jj=j1,j2
-                  DO ji=i1,i2
-                     IF( tabres_child(ji,jj,jk,jn) .NE. 0. ) THEN 
-                        tsn(ji,jj,jk,jn) = tabres_child(ji,jj,jk,jn) * tmask(ji,jj,jk)
+                     END DO
+                  END DO
+               END DO
+            END DO
+         ENDIF
+         DO jn = 1,jpts
+            DO jk = 1, jpkm1
+               DO jj = j1, j2
+                  DO ji = i1, i2
+                     IF( tabres_child(ji,jj,jk,jn) /= 0._wp ) THEN 
+                        tsn(ji,jj,jk,jn) = tabres_child(ji,jj,jk,jn)
                      END IF
                   END DO
@@ -389,4 +380,8 @@
             END DO
          END DO
+         !
+         IF  ((neuler==0).AND.(Agrif_Nb_Step()==0) ) THEN
+            tsb(i1:i2,j1:j2,1:jpkm1,1:jpts)  = tsn(i1:i2,j1:j2,1:jpkm1,1:jpts)
+         ENDIF
       ENDIF
       ! 
@@ -478,5 +473,5 @@
       !
       INTEGER ::   ji, jj, jk
-      REAL(wp)::   zrhoy
+      REAL(wp)::   zrhoy, zub, zunu, zuno
 ! VERTICAL REFINEMENT BEGIN
       REAL(wp), DIMENSION(i1:i2,j1:j2,1:jpk) :: tabres_child
@@ -491,12 +486,17 @@
       IF( before ) THEN
          zrhoy = Agrif_Rhoy()
-         AGRIF_SpecialValue = -999._wp
+!jc_alt
+!         AGRIF_SpecialValue = -999._wp
          DO jk=k1,k2
             DO jj=j1,j2
                DO ji=i1,i2
-                  tabres(ji,jj,jk,1) = zrhoy * e2u(ji,jj) * e3u_n(ji,jj,jk) * umask(ji,jj,jk) * un(ji,jj,jk)  &
-                                       + (umask(ji,jj,jk)-1)*999._wp
-                  tabres(ji,jj,jk,2) = zrhoy * umask(ji,jj,jk) * e2u(ji,jj) * e3u_n(ji,jj,jk)  &
-                                       + (umask(ji,jj,jk)-1)*999._wp
+!jc_alt
+!                  tabres(ji,jj,jk,1) = zrhoy * e2u(ji,jj) * e3u_n(ji,jj,jk) * umask(ji,jj,jk) * un(ji,jj,jk)  &
+!                                     &  + (umask(ji,jj,jk)-1._wp)*999._wp
+                  tabres(ji,jj,jk,1) = zrhoy * e2u(ji,jj) * e3u_n(ji,jj,jk) * umask(ji,jj,jk) * un(ji,jj,jk)  
+!jc_alt
+!                  tabres(ji,jj,jk,2) = zrhoy * umask(ji,jj,jk) * e2u(ji,jj) * e3u_n(ji,jj,jk)  &
+!                                     &  + (umask(ji,jj,jk)-1._wp)*999._wp
+                  tabres(ji,jj,jk,2) = zrhoy * umask(ji,jj,jk) * e2u(ji,jj) * e3u_n(ji,jj,jk)
                END DO
             END DO
@@ -511,5 +511,7 @@
                tabin(:) = 0._wp
                DO jk=k1,k2 !k2=jpk of child grid
-                  IF( tabres(ji,jj,jk,2) < -900) EXIT
+!jc_alt
+!                  IF( tabres(ji,jj,jk,2) < -900._wp) EXIT
+                  IF( tabres(ji,jj,jk,2) == 0.) EXIT
                   N_in = N_in + 1
                   tabin(jk) = tabres(ji,jj,jk,1)/tabres(ji,jj,jk,2)
@@ -524,8 +526,8 @@
                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 U 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.
-                     excess = 0._wp
                      DO jk=N_in,1,-1
                         thick = MIN(-1*h_diff, h_in(jk))
@@ -540,16 +542,19 @@
                      ENDDO
                   ENDIF
-                  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)
+                  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))
                ENDIF
             ENDDO
          ENDDO
-
+         !
          DO jk=1,jpk
             DO jj=j1,j2
                DO ji=i1,i2
                   IF (.NOT.(lk_agrif_fstep.AND.(neuler==0))) THEN ! Add asselin part
-                     ub(ji,jj,jk) = ub(ji,jj,jk) & 
-                           & + atfp * ( tabres_child(ji,jj,jk) - un(ji,jj,jk) ) * umask(ji,jj,jk)
+                     zub  = ub(ji,jj,jk) * e3u_b(ji,jj,jk)  ! fse3t_b prior update should be used
+                     zuno = un(ji,jj,jk) * e3u_a(ji,jj,jk)
+                     zunu = tabres_child(ji,jj,jk) * e3u_n(ji,jj,jk)
+                     ub(ji,jj,jk) = ( zub + atfp * ( zunu - zuno) ) &      
+                                    & * umask(ji,jj,jk) / e3u_b(ji,jj,jk)
                   ENDIF
                   !
@@ -558,4 +563,9 @@
             END DO
          END DO
+         !
+         IF  ((neuler==0).AND.(Agrif_Nb_Step()==0) ) THEN
+            ub(i1:i2,j1:j2,1:jpkm1)  = un(i1:i2,j1:j2,1:jpkm1)
+         ENDIF
+         !
       ENDIF
       ! 
@@ -665,5 +675,5 @@
       !
       INTEGER  ::   ji, jj, jk
-      REAL(wp) ::   zrhox
+      REAL(wp) ::   zrhox, zvb, zvnu, zvno
 ! VERTICAL REFINEMENT BEGIN
       REAL(wp), DIMENSION(i1:i2,j1:j2,1:jpk) :: tabres_child
@@ -678,12 +688,17 @@
       IF( before ) THEN
          zrhox = Agrif_Rhox()
-         AGRIF_SpecialValue = -999._wp
+!jc_alt
+!         AGRIF_SpecialValue = -999._wp
          DO jk=k1,k2
             DO jj=j1,j2
                DO ji=i1,i2
-                  tabres(ji,jj,jk,1) = zrhox * e1v(ji,jj) * e3v_n(ji,jj,jk) * vmask(ji,jj,jk) * vn(ji,jj,jk) &
-                                       + (vmask(ji,jj,jk)-1)*999._wp
-                  tabres(ji,jj,jk,2) = vmask(ji,jj,jk) * zrhox * e1v(ji,jj) * e3v_n(ji,jj,jk) &
-                                       + (vmask(ji,jj,jk)-1)*999._wp
+!jc_alt
+!                  tabres(ji,jj,jk,1) = zrhox * e1v(ji,jj) * e3v_n(ji,jj,jk) * vmask(ji,jj,jk) * vn(ji,jj,jk) &
+!                                     & + (vmask(ji,jj,jk)-1._wp) * 999._wp
+                  tabres(ji,jj,jk,1) = zrhox * e1v(ji,jj) * e3v_n(ji,jj,jk) * vmask(ji,jj,jk) * vn(ji,jj,jk) 
+!jc_alt
+!                  tabres(ji,jj,jk,2) = zrhox * e1v(ji,jj) * e3v_n(ji,jj,jk) * vmask(ji,jj,jk) &
+!                                     & + (vmask(ji,jj,jk)-1._wp) * 999._wp
+                  tabres(ji,jj,jk,2) = zrhox * e1v(ji,jj) * e3v_n(ji,jj,jk) * vmask(ji,jj,jk)
                END DO
             END DO
@@ -696,5 +711,7 @@
                N_in = 0
                DO jk=k1,k2
-                  IF (tabres(ji,jj,jk,2) < -900) EXIT
+!jc_alt
+!                  IF (tabres(ji,jj,jk,2) < -900._wp) EXIT
+                  IF (tabres(ji,jj,jk,2) == 0) EXIT
                   N_in = N_in + 1
                   tabin(jk) = tabres(ji,jj,jk,1)/tabres(ji,jj,jk,2)
@@ -709,8 +726,8 @@
                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 U points to be deeper in the child grid. 
+!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.
-                     excess = 0._wp
                      DO jk=N_in,1,-1
                         thick = MIN(-1*h_diff, h_in(jk))
@@ -725,17 +742,19 @@
                      ENDDO
                   ENDIF
-                  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)
+                  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))
                ENDIF
             ENDDO
          ENDDO
-
-         DO jk=1,jpk
+         !
+         DO jk=1,jpkm1
             DO jj=j1,j2
                DO ji=i1,i2
-                  !
-                  IF( .NOT.(lk_agrif_fstep.AND.(neuler==0)) ) THEN ! Add asselin part
-                     vb(ji,jj,jk) = vb(ji,jj,jk) & 
-                           & + atfp * ( tabres_child(ji,jj,jk) - vn(ji,jj,jk) ) * vmask(ji,jj,jk)
+                  IF (.NOT.(lk_agrif_fstep.AND.(neuler==0))) THEN ! Add asselin part
+                     zvb  = vb(ji,jj,jk) * e3v_b(ji,jj,jk) ! fse3t_b prior update should be used
+                     zvno = vn(ji,jj,jk) * e3v_a(ji,jj,jk)
+                     zvnu = tabres_child(ji,jj,jk) * e3v_n(ji,jj,jk)
+                     vb(ji,jj,jk) = ( zvb + atfp * ( zvnu - zvno) ) &      
+                                    & * vmask(ji,jj,jk) / e3v_b(ji,jj,jk)
                   ENDIF
                   !
@@ -744,4 +763,9 @@
             END DO
          END DO
+         !
+         IF  ((neuler==0).AND.(Agrif_Nb_Step()==0) ) THEN
+            vb(i1:i2,j1:j2,1:jpkm1)  = vn(i1:i2,j1:j2,1:jpkm1)
+         ENDIF
+         !
       ENDIF
       ! 
Index: /NEMO/branches/2019/dev_r12072_MERGE_OPTION2_2019/src/NST/agrif_top_interp.F90
===================================================================
--- /NEMO/branches/2019/dev_r12072_MERGE_OPTION2_2019/src/NST/agrif_top_interp.F90	(revision 12190)
+++ /NEMO/branches/2019/dev_r12072_MERGE_OPTION2_2019/src/NST/agrif_top_interp.F90	(revision 12191)
@@ -18,4 +18,5 @@
    USE par_trc
    USE trc
+   USE vremap
    !
    USE lib_mpp     ! MPP library
@@ -48,5 +49,5 @@
    END SUBROUTINE Agrif_trc
 
-   SUBROUTINE interptrn( ptab, i1, i2, j1, j2, k1, k2, n1, n2, before, nb, ndir )
+   SUBROUTINE interptrn( ptab, i1, i2, j1, j2, k1, k2, n1, n2, before )
       !!----------------------------------------------------------------------
       !!                  *** ROUTINE interptrn ***
@@ -55,16 +56,15 @@
       INTEGER                                     , INTENT(in   ) ::   i1, i2, j1, j2, k1, k2, n1, n2
       LOGICAL                                     , INTENT(in   ) ::   before
-      INTEGER                                     , INTENT(in   ) ::   nb , ndir
       !
-      INTEGER  ::   ji, jj, jk, jn, iref, jref, ibdy, jbdy   ! dummy loop indices
+      INTEGER  ::   ji, jj, jk, jn, ibdy, jbdy   ! dummy loop indices
       INTEGER  ::   imin, imax, jmin, jmax, N_in, N_out
       REAL(wp) ::   zrho, z1, z2, z3, z4, z5, z6, z7
-      LOGICAL :: western_side, eastern_side,northern_side,southern_side
+
       ! vertical interpolation:
-      REAL(wp), DIMENSION(i1:i2,j1:j2,1:jpk,n1:n2) :: ptab_child
-      REAL(wp), DIMENSION(k1:k2,n1:n2-1) :: tabin
+      REAL(wp), DIMENSION(i1:i2,j1:j2,1:jpk,1:jptra) :: ptab_child
+      REAL(wp), DIMENSION(k1:k2,1:jptra) :: tabin
       REAL(wp), DIMENSION(k1:k2) :: h_in
       REAL(wp), DIMENSION(1:jpk) :: h_out
-      REAL(wp) :: h_diff
+      !!----------------------------------------------------------------------
 
       IF( before ) THEN         
@@ -90,16 +90,8 @@
       ELSE 
 
-         western_side  = (nb == 1).AND.(ndir == 1)   ;   eastern_side  = (nb == 1).AND.(ndir == 2)
-         southern_side = (nb == 2).AND.(ndir == 1)   ;   northern_side = (nb == 2).AND.(ndir == 2)
-
-# if defined key_vertical              
+# if defined key_vertical
          DO jj=j1,j2
             DO ji=i1,i2
-               iref = ji
-               jref = jj
-               if(western_side) iref=MAX(2,ji)
-               if(eastern_side) iref=MIN(nlci-1,ji)
-               if(southern_side) jref=MAX(2,jj)
-               if(northern_side) jref=MIN(nlcj-1,jj)
+               ptab_child(ji,jj,:) = 0._wp
                N_in = 0
                DO jk=k1,k2 !k2 = jpk of parent grid
@@ -111,12 +103,10 @@
                N_out = 0
                DO jk=1,jpk ! jpk of child grid
-                  IF (tmask(iref,jref,jk) == 0) EXIT 
+                  IF (tmask(ji,jj,jk) == 0) EXIT 
                   N_out = N_out + 1
-                  h_out(jk) = e3t_n(iref,jref,jk)
+                  h_out(jk) = e3t_a(ji,jj,jk)
                ENDDO
                IF (N_in > 0) THEN
-                  DO jn=1,jptra
-                     call reconstructandremap(tabin(1:N_in,jn),h_in,ptab_child(ji,jj,1:N_out,jn),h_out,N_in,N_out)
-                  ENDDO
+                  CALL reconstructandremap(tabin(1:N_in,1:jptra),h_in,ptab_child(ji,jj,1:N_out,1:jptra),h_out,N_in,N_out,jptra)
                ENDIF
             ENDDO
@@ -129,133 +119,4 @@
             tra(i1:i2,j1:j2,1:jpk,jn)=ptab_child(i1:i2,j1:j2,1:jpk,jn)*tmask(i1:i2,j1:j2,1:jpk) 
          END DO
-
-         IF ( .NOT.lk_agrif_clp ) THEN 
-            !
-            imin = i1 ; imax = i2
-            jmin = j1 ; jmax = j2
-            ! 
-            ! Remove CORNERS
-            IF((nbondj == -1).OR.(nbondj == 2)) jmin = 2 + nbghostcells
-            IF((nbondj == +1).OR.(nbondj == 2)) jmax = nlcj - nbghostcells - 1
-            IF((nbondi == -1).OR.(nbondi == 2)) imin = 2 + nbghostcells
-            IF((nbondi == +1).OR.(nbondi == 2)) imax = nlci - nbghostcells - 1      
-            !
-            IF( eastern_side ) THEN
-               zrho = Agrif_Rhox()
-               z1 = ( zrho - 1._wp ) * 0.5_wp                    
-               z3 = ( zrho - 1._wp ) / ( zrho + 1._wp )         
-               z6 = 2._wp * ( zrho - 1._wp ) / ( zrho + 1._wp )
-               z7 =       - ( zrho - 1._wp ) / ( zrho + 3._wp )
-               z2 = 1._wp - z1 ; z4 = 1._wp - z3 ; z5 = 1._wp - z6 - z7
-               !
-               ibdy = nlci-nbghostcells
-               DO jn = 1, jptra
-                  tra(ibdy+1,jmin:jmax,1:jpkm1,jn) = z1 * ptab_child(ibdy+1,jmin:jmax,1:jpkm1,jn) + z2 * ptab_child(ibdy,jmin:jmax,1:jpkm1,jn)
-                  DO jk = 1, jpkm1
-                     DO jj = jmin,jmax
-                        IF( umask(ibdy-1,jj,jk) == 0._wp ) THEN
-                           tra(ibdy,jj,jk,jn) = tra(ibdy+1,jj,jk,jn) * tmask(ibdy,jj,jk)
-                        ELSE
-                           tra(ibdy,jj,jk,jn)=(z4*tra(ibdy+1,jj,jk,jn)+z3*tra(ibdy-1,jj,jk,jn))*tmask(ibdy,jj,jk)
-                           IF( un(ibdy-1,jj,jk) > 0._wp ) THEN
-                              tra(ibdy,jj,jk,jn)=( z6*tra(ibdy-1,jj,jk,jn)+z5*tra(ibdy+1,jj,jk,jn) & 
-                                                 + z7*tra(ibdy-2,jj,jk,jn) ) * tmask(ibdy,jj,jk)
-                           ENDIF
-                        ENDIF
-                     END DO
-                  END DO
-                  ! Restore ghost points:
-                  tra(ibdy+1,jmin:jmax,1:jpkm1,jn) = ptab_child(ibdy+1,jmin:jmax,1:jpkm1,jn) * tmask(ibdy+1,jmin:jmax,1:jpkm1)
-               END DO
-            ENDIF
-            ! 
-            IF( northern_side ) THEN
-               zrho = Agrif_Rhoy()
-               z1 = ( zrho - 1._wp ) * 0.5_wp                    
-               z3 = ( zrho - 1._wp ) / ( zrho + 1._wp )         
-               z6 = 2._wp * ( zrho - 1._wp ) / ( zrho + 1._wp )
-               z7 =       - ( zrho - 1._wp ) / ( zrho + 3._wp )
-               z2 = 1._wp - z1 ; z4 = 1._wp - z3 ; z5 = 1._wp - z6 - z7
-               !
-               jbdy = nlcj-nbghostcells         
-               DO jn = 1, jptra
-                  tra(imin:imax,jbdy+1,1:jpkm1,jn) = z1 * ptab_child(imin:imax,jbdy+1,1:jpkm1,jn) + z2 * ptab_child(imin:imax,jbdy,1:jpkm1,jn)
-                  DO jk = 1, jpkm1
-                     DO ji = imin,imax
-                        IF( vmask(ji,jbdy-1,jk) == 0._wp ) THEN
-                           tra(ji,jbdy,jk,jn) = tra(ji,jbdy+1,jk,jn) * tmask(ji,jbdy,jk)
-                        ELSE
-                           tra(ji,jbdy,jk,jn)=(z4*tra(ji,jbdy+1,jk,jn)+z3*tra(ji,jbdy-1,jk,jn))*tmask(ji,jbdy,jk)        
-                           IF (vn(ji,jbdy-1,jk) > 0._wp ) THEN
-                              tra(ji,jbdy,jk,jn)=( z6*tra(ji,jbdy-1,jk,jn)+z5*tra(ji,jbdy+1,jk,jn)  &
-                                                 + z7*tra(ji,jbdy-2,jk,jn) ) * tmask(ji,jbdy,jk)
-                           ENDIF
-                        ENDIF
-                     END DO
-                  END DO
-                  ! Restore ghost points:
-                  tra(imin:imax,jbdy+1,1:jpkm1,jn) = ptab_child(imin:imax,jbdy+1,1:jpkm1,jn) * tmask(imin:imax,jbdy+1,1:jpkm1)
-               END DO
-            ENDIF
-            !
-            IF( western_side ) THEN
-               zrho = Agrif_Rhox()
-               z1 = ( zrho - 1._wp ) * 0.5_wp                    
-               z3 = ( zrho - 1._wp ) / ( zrho + 1._wp )         
-               z6 = 2._wp * ( zrho - 1._wp ) / ( zrho + 1._wp )
-               z7 =       - ( zrho - 1._wp ) / ( zrho + 3._wp )
-               z2 = 1._wp - z1 ; z4 = 1._wp - z3 ; z5 = 1._wp - z6 - z7
-               !    
-               ibdy = 1+nbghostcells       
-               DO jn = 1, jptra
-                  tra(ibdy-1,jmin:jmax,1:jpkm1,jn) = z1 * ptab_child(ibdy-1,jmin:jmax,1:jpkm1,jn) + z2 * ptab_child(ibdy,jmin:jmax,1:jpkm1,jn)
-                  DO jk = 1, jpkm1
-                     DO jj = jmin,jmax
-                        IF( umask(ibdy,jj,jk) == 0._wp ) THEN
-                           tra(ibdy,jj,jk,jn) = tra(ibdy-1,jj,jk,jn) * tmask(ibdy,jj,jk)
-                        ELSE
-                           tra(ibdy,jj,jk,jn)=(z4*tra(ibdy-1,jj,jk,jn)+z3*tra(ibdy+1,jj,jk,jn))*tmask(ibdy,jj,jk)        
-                           IF( un(ibdy,jj,jk) < 0._wp ) THEN
-                              tra(ibdy,jj,jk,jn)=( z6*tra(ibdy+1,jj,jk,jn)+z5*tra(ibdy-1,jj,jk,jn) &
-                                                 + z7*tra(ibdy+2,jj,jk,jn) ) * tmask(ibdy,jj,jk)
-                           ENDIF
-                        ENDIF
-                     END DO
-                  END DO
-                  ! Restore ghost points:
-                  tra(ibdy-1,jmin:jmax,1:jpkm1,jn) = ptab_child(ibdy-1,jmin:jmax,1:jpkm1,jn) * tmask(ibdy-1,jmin:jmax,1:jpkm1)
-               END DO
-            ENDIF
-            !
-            IF( southern_side ) THEN
-               zrho = Agrif_Rhoy()
-               z1 = ( zrho - 1._wp ) * 0.5_wp                    
-               z3 = ( zrho - 1._wp ) / ( zrho + 1._wp )         
-               z6 = 2._wp * ( zrho - 1._wp ) / ( zrho + 1._wp )
-               z7 =       - ( zrho - 1._wp ) / ( zrho + 3._wp )
-               z2 = 1._wp - z1 ; z4 = 1._wp - z3 ; z5 = 1._wp - z6 - z7
-               !  
-               jbdy=1+nbghostcells        
-               DO jn = 1, jptra
-                  tra(imin:imax,jbdy-1,1:jpkm1,jn) = z1 * ptab_child(imin:imax,jbdy-1,1:jpkm1,jn) + z2 * ptab_child(imin:imax,jbdy,1:jpkm1,jn)
-                  DO jk = 1, jpkm1      
-                     DO ji = imin,imax
-                        IF( vmask(ji,jbdy,jk) == 0._wp ) THEN
-                           tra(ji,jbdy,jk,jn)=tra(ji,jbdy-1,jk,jn) * tmask(ji,jbdy,jk)
-                        ELSE
-                           tra(ji,jbdy,jk,jn)=(z4*tra(ji,jbdy-1,jk,jn)+z3*tra(ji,jbdy+1,jk,jn))*tmask(ji,jbdy,jk)
-                           IF( vn(ji,jbdy,jk) < 0._wp ) THEN
-                              tra(ji,jbdy,jk,jn)=( z6*tra(ji,jbdy+1,jk,jn)+z5*tra(ji,jbdy-1,jk,jn) & 
-                                                 + z7*tra(ji,jbdy+2,jk,jn) ) * tmask(ji,jbdy,jk)
-                           ENDIF
-                        ENDIF
-                     END DO
-                  END DO
-                  ! Restore ghost points:
-                  tra(imin:imax,jbdy-1,1:jpkm1,jn) = ptab_child(imin:imax,jbdy-1,1:jpkm1,jn) * tmask(imin:imax,jbdy-1,1:jpkm1)
-               END DO
-            ENDIF
-            !
-         ENDIF
 
       ENDIF
Index: /NEMO/branches/2019/dev_r12072_MERGE_OPTION2_2019/src/NST/agrif_top_sponge.F90
===================================================================
--- /NEMO/branches/2019/dev_r12072_MERGE_OPTION2_2019/src/NST/agrif_top_sponge.F90	(revision 12190)
+++ /NEMO/branches/2019/dev_r12072_MERGE_OPTION2_2019/src/NST/agrif_top_sponge.F90	(revision 12191)
@@ -20,4 +20,5 @@
    USE agrif_oce
    USE agrif_oce_sponge
+   USE vremap
    !
    USE in_out_manager
@@ -66,10 +67,10 @@
       !
       INTEGER  ::   ji, jj, jk, jn   ! dummy loop indices
-      REAL(wp) ::   zabe1, zabe2
-      REAL(wp), DIMENSION(i1:i2,j1:j2)             ::   ztu, ztv
-      REAL(wp), DIMENSION(i1:i2,j1:j2,k1:k2,n1:n2) ::   trbdiff
+      REAL(wp) ::   zabe1, zabe2, ztrelax
+      REAL(wp), DIMENSION(i1:i2,j1:j2)               ::   ztu, ztv
+      REAL(wp), DIMENSION(i1:i2,j1:j2,k1:k2,1:jptra) ::   trbdiff
       ! vertical interpolation:
-      REAL(wp), DIMENSION(i1:i2,j1:j2,jpk,n1:n2) ::tabres_child
-      REAL(wp), DIMENSION(k1:k2,n1:n2-1) :: tabin
+      REAL(wp), DIMENSION(i1:i2,j1:j2,jpk,1:jptra) ::tabres_child
+      REAL(wp), DIMENSION(k1:k2,1:jptra) :: tabin
       REAL(wp), DIMENSION(k1:k2) :: h_in
       REAL(wp), DIMENSION(1:jpk) :: h_out
@@ -93,5 +94,5 @@
             DO jj=j1,j2
                DO ji=i1,i2
-                  tabres(ji,jj,jk,jpts+1) = tmask(ji,jj,jk) * e3t_n(ji,jj,jk) 
+                  tabres(ji,jj,jk,jpts+1) = tmask(ji,jj,jk) * e3t_b(ji,jj,jk) 
                END DO
             END DO
@@ -114,12 +115,8 @@
                   IF (tmask(ji,jj,jk) == 0) EXIT 
                   N_out = N_out + 1
-                  h_out(jk) = e3t_n(ji,jj,jk) !Child grid scale factors. Could multiply by e1e2t here instead of division above
+                  h_out(jk) = e3t_b(ji,jj,jk) !Child grid scale factors. Could multiply by e1e2t here instead of division above
                ENDDO
                IF (N_in > 0) THEN
-                  h_diff = sum(h_out(1:N_out))-sum(h_in(1:N_in))
-                  tabres(ji,jj,k2,:) = tabres(ji,jj,k2-1,:) !what is this line for?????
-                  DO jn=1,jptra
-                     call reconstructandremap(tabin(1:N_in,jn),h_in,tabres_child(ji,jj,1:N_out,jn),h_out,N_in,N_out)
-                  ENDDO
+                  CALL reconstructandremap(tabin(1:N_in,1:jptra),h_in,tabres_child(ji,jj,1:N_out,1:jptra),h_out,N_in,N_out,jptra)
                ENDIF
             ENDDO
@@ -139,10 +136,15 @@
          ENDDO
 
+         !* set relaxation time scale
+         IF( neuler == 0 .AND. lk_agrif_fstep ) THEN   ;   ztrelax =   rn_trelax_tra  / (        rdt )
+         ELSE                                          ;   ztrelax =   rn_trelax_tra  / (2._wp * rdt )
+         ENDIF
+
          DO jn = 1, jptra
             DO jk = 1, jpkm1
                DO jj = j1,j2-1
                   DO ji = i1,i2-1
-                     zabe1 = fsaht_spu(ji,jj) * e2_e1u(ji,jj) * e3u_n(ji,jj,jk) * umask(ji,jj,jk)
-                     zabe2 = fsaht_spv(ji,jj) * e1_e2v(ji,jj) * e3v_n(ji,jj,jk) * vmask(ji,jj,jk)
+                     zabe1 = rn_sponge_tra * fspu(ji,jj) * e2_e1u(ji,jj) * e3u_n(ji,jj,jk) * umask(ji,jj,jk)
+                     zabe2 = rn_sponge_tra * fspv(ji,jj) * e1_e2v(ji,jj) * e3v_n(ji,jj,jk) * vmask(ji,jj,jk)
                      ztu(ji,jj) = zabe1 * ( trbdiff(ji+1,jj  ,jk,jn) - trbdiff(ji,jj,jk,jn) )
                      ztv(ji,jj) = zabe2 * ( trbdiff(ji  ,jj+1,jk,jn) - trbdiff(ji,jj,jk,jn) )
@@ -155,5 +157,6 @@
                         tra(ji,jj,jk,jn) = tra(ji,jj,jk,jn) + (  ztu(ji,jj) - ztu(ji-1,jj  )     &
                            &                                   + ztv(ji,jj) - ztv(ji  ,jj-1)  )  &
-                           &                                * r1_e1e2t(ji,jj) / e3t_n(ji,jj,jk)
+                           &                                * r1_e1e2t(ji,jj) / e3t_n(ji,jj,jk)  &
+                           &                                - ztrelax * fspt(ji,jj) * trbdiff(ji,jj,jk,jn)
                      ENDIF
                   END DO
Index: /NEMO/branches/2019/dev_r12072_MERGE_OPTION2_2019/src/NST/agrif_top_update.F90
===================================================================
--- /NEMO/branches/2019/dev_r12072_MERGE_OPTION2_2019/src/NST/agrif_top_update.F90	(revision 12190)
+++ /NEMO/branches/2019/dev_r12072_MERGE_OPTION2_2019/src/NST/agrif_top_update.F90	(revision 12191)
@@ -1,3 +1,2 @@
-#define TWO_WAY
 #undef DECAL_FEEDBACK
 
@@ -20,4 +19,5 @@
    USE par_trc
    USE trc
+   USE vremap
 
    IMPLICIT NONE
@@ -40,5 +40,4 @@
       IF (Agrif_Root()) RETURN 
       !
-#if defined TWO_WAY   
       Agrif_UseSpecialValueInUpdate = .TRUE.
       Agrif_SpecialValueFineGrid    = 0._wp
@@ -53,6 +52,4 @@
       !
       Agrif_UseSpecialValueInUpdate = .FALSE.
-      !
-#endif
       !
    END SUBROUTINE Agrif_Update_Trc
@@ -68,16 +65,15 @@
       !!
       INTEGER :: ji,jj,jk,jn
-      REAL(wp), DIMENSION(i1:i2,j1:j2,1:jpk,n1:n2) :: tabres_child
+      REAL(wp) :: ztb, ztnu, ztno
       REAL(wp) :: h_in(k1:k2)
       REAL(wp) :: h_out(1:jpk)
       INTEGER  :: N_in, N_out
       REAL(wp) :: h_diff
-      REAL(wp) :: zrho_xy
-      REAL(wp) :: tabin(k1:k2,n1:n2)
+      REAL(wp) :: tabin(k1:k2,1:jptra)
+      REAL(wp), DIMENSION(i1:i2,j1:j2,1:jpk,1:jptra) :: tabres_child
       !!---------------------------------------------
       !
       IF (before) THEN
          AGRIF_SpecialValue = -999._wp
-         zrho_xy = Agrif_rhox() * Agrif_rhoy() 
          DO jn = n1,n2-1
             DO jk=k1,k2
@@ -124,21 +120,21 @@
                      STOP
                   ENDIF
-                  DO jn=1,jptra
-                     CALL reconstructandremap(tabin(1:N_in,jn),h_in(1:N_in),tabres_child(ji,jj,1:N_out,jn),h_out(1:N_out),N_in,N_out)
-                  ENDDO
+                  CALL reconstructandremap(tabin(1:N_in,1:jptra),h_in(1:N_in),tabres_child(ji,jj,1:N_out,1:jptra),h_out(1:N_out),N_in,N_out,jptra)
                ENDIF
             ENDDO
          ENDDO
-
+         !
          IF (.NOT.(lk_agrif_fstep.AND.(neuler==0))) THEN
             ! Add asselin part
             DO jn = 1,jptra
-               DO jk=1,jpk
+               DO jk=1,jpkm1
                   DO jj=j1,j2
                      DO ji=i1,i2
                         IF( tabres_child(ji,jj,jk,jn) .NE. 0. ) THEN
-                           trb(ji,jj,jk,jn) = trb(ji,jj,jk,jn) & 
-                                 & + atfp * ( tabres_child(ji,jj,jk,jn) &
-                                 &          - trn(ji,jj,jk,jn) ) * tmask(ji,jj,jk)
+                           ztb  = trb(ji,jj,jk,jn) * e3t_b(ji,jj,jk) ! fse3t_b prior update should be used
+                           ztnu = tabres_child(ji,jj,jk,jn) * e3t_n(ji,jj,jk)
+                           ztno = trn(ji,jj,jk,jn) * e3t_a(ji,jj,jk)
+                           trb(ji,jj,jk,jn) = ( ztb + atfp * ( ztnu - ztno) )  & 
+                                     &        * tmask(ji,jj,jk) / e3t_b(ji,jj,jk)
                         ENDIF
                      ENDDO
@@ -148,9 +144,9 @@
          ENDIF
          DO jn = 1,jptra
-            DO jk=1,jpk
+            DO jk=1,jpkm1
                DO jj=j1,j2
                   DO ji=i1,i2
                      IF( tabres_child(ji,jj,jk,jn) .NE. 0. ) THEN 
-                        trn(ji,jj,jk,jn) = tabres_child(ji,jj,jk,jn) * tmask(ji,jj,jk)
+                        trn(ji,jj,jk,jn) = tabres_child(ji,jj,jk,jn)
                      END IF
                   END DO
@@ -158,4 +154,10 @@
             END DO
          END DO
+         !
+         IF  ((neuler==0).AND.(Agrif_Nb_Step()==0) ) THEN
+            trb(i1:i2,j1:j2,1:jpkm1,1:jptra)  = trn(i1:i2,j1:j2,1:jpkm1,1:jptra)
+         ENDIF
+         !
+
       ENDIF
       ! 
Index: /NEMO/branches/2019/dev_r12072_MERGE_OPTION2_2019/src/NST/agrif_user.F90
===================================================================
--- /NEMO/branches/2019/dev_r12072_MERGE_OPTION2_2019/src/NST/agrif_user.F90	(revision 12190)
+++ /NEMO/branches/2019/dev_r12072_MERGE_OPTION2_2019/src/NST/agrif_user.F90	(revision 12191)
@@ -6,446 +6,470 @@
    !! Software governed by the CeCILL license (see ./LICENSE)
    !!----------------------------------------------------------------------
-SUBROUTINE agrif_user
-END SUBROUTINE agrif_user
-
-SUBROUTINE agrif_before_regridding
-END SUBROUTINE agrif_before_regridding
-
-SUBROUTINE Agrif_InitWorkspace
-      !!----------------------------------------------------------------------
-      !!                 *** ROUTINE Agrif_InitWorkspace ***
-      !!----------------------------------------------------------------------
-   USE par_oce
-   USE dom_oce
-   USE nemogcm
-   USE mppini
-      !!
-   IMPLICIT NONE
-      !!----------------------------------------------------------------------
-   !
-   IF( .NOT. Agrif_Root() ) THEN
-      ! no more static variables
-!!$! JC: change to allow for different vertical levels
-!!$!     jpk is already set
-!!$!     keep it jpk possibly different from jpkglo which 
-!!$!     hold parent grid vertical levels number (set earlier)
-!!$!      jpk     = jpkglo 
-   ENDIF
-   !
-END SUBROUTINE Agrif_InitWorkspace
-
-
-SUBROUTINE Agrif_InitValues
+   SUBROUTINE agrif_user
+   END SUBROUTINE agrif_user
+
+   SUBROUTINE agrif_before_regridding
+   END SUBROUTINE agrif_before_regridding
+
+   SUBROUTINE Agrif_InitWorkspace
+   END SUBROUTINE Agrif_InitWorkspace
+
+   SUBROUTINE Agrif_InitValues
       !!----------------------------------------------------------------------
       !!                 *** ROUTINE Agrif_InitValues ***
-      !!
-      !! ** Purpose :: Declaration of variables to be interpolated
-      !!----------------------------------------------------------------------
-   USE Agrif_Util
-   USE oce 
-   USE dom_oce
-   USE nemogcm
-   USE tradmp
-   USE bdy_oce   , ONLY: ln_bdy
-   !!
-   IMPLICIT NONE
-      !!----------------------------------------------------------------------
-   !
-   CALL nemo_init       !* Initializations of each fine grid
-
-   !                    !* Agrif initialization
-   CALL agrif_nemo_init
-   CALL Agrif_InitValues_cont_dom
-   CALL Agrif_InitValues_cont
+      !!----------------------------------------------------------------------
+      USE nemogcm
+      !!----------------------------------------------------------------------
+      !
+      CALL nemo_init       !* Initializations of each fine grid
+      !
+      !                    !* Agrif initialization
+      CALL agrif_nemo_init
+      CALL Agrif_InitValues_cont_dom
+      CALL Agrif_InitValues_cont
 # if defined key_top
-   CALL Agrif_InitValues_cont_top
+      CALL Agrif_InitValues_cont_top
 # endif
 # if defined key_si3
-   CALL Agrif_InitValues_cont_ice
-# endif
-   !    
-END SUBROUTINE Agrif_initvalues
-
-
-SUBROUTINE Agrif_InitValues_cont_dom
-      !!----------------------------------------------------------------------
-      !!                 *** ROUTINE Agrif_InitValues_cont ***
-      !!
-      !! ** Purpose ::   Declaration of variables to be interpolated
-      !!----------------------------------------------------------------------
-   USE Agrif_Util
-   USE oce 
-   USE dom_oce
-   USE nemogcm
-   USE in_out_manager
-   USE agrif_oce_update
-   USE agrif_oce_interp
-   USE agrif_oce_sponge
-   !
-   IMPLICIT NONE
-      !!----------------------------------------------------------------------
-   !
-   ! Declaration of the type of variable which have to be interpolated
-   !
-   CALL agrif_declare_var_dom
-   !
-END SUBROUTINE Agrif_InitValues_cont_dom
-
-
-SUBROUTINE agrif_declare_var_dom
-      !!----------------------------------------------------------------------
-      !!                 *** ROUTINE agrif_declare_var ***
-      !!
-      !! ** Purpose :: Declaration of variables to be interpolated
-      !!----------------------------------------------------------------------
-   USE agrif_util
-   USE par_oce       
-   USE oce
-   !
-   IMPLICIT NONE
-   !
-   INTEGER :: ind1, ind2, ind3
+      CALL Agrif_InitValues_cont_ice
+# endif
+      !    
+   END SUBROUTINE Agrif_initvalues
+
+   SUBROUTINE Agrif_InitValues_cont_dom
+      !!----------------------------------------------------------------------
+      !!                 *** ROUTINE Agrif_InitValues_cont_dom ***
+      !!----------------------------------------------------------------------
+      !
+      CALL agrif_declare_var_dom
+      !
+   END SUBROUTINE Agrif_InitValues_cont_dom
+
+   SUBROUTINE agrif_declare_var_dom
+      !!----------------------------------------------------------------------
+      !!                 *** ROUTINE agrif_declare_var_dom ***
+      !!----------------------------------------------------------------------
+      USE par_oce, ONLY:  nbghostcells      
+      !
+      IMPLICIT NONE
+      !
+      INTEGER :: ind1, ind2, ind3
       !!----------------------------------------------------------------------
 
       ! 1. Declaration of the type of variable which have to be interpolated
       !---------------------------------------------------------------------
-   ind1 =     nbghostcells
-   ind2 = 1 + nbghostcells
-   ind3 = 2 + nbghostcells
-   CALL agrif_declare_variable((/1,2/),(/ind2,ind3/),(/'x','y'/),(/1,1/),(/nlci,nlcj/),e1u_id)
-   CALL agrif_declare_variable((/2,1/),(/ind3,ind2/),(/'x','y'/),(/1,1/),(/nlci,nlcj/),e2v_id)
+      ind1 =     nbghostcells
+      ind2 = 1 + nbghostcells
+      ind3 = 2 + nbghostcells
+      CALL agrif_declare_variable((/1,2/),(/ind2,ind3/),(/'x','y'/),(/1,1/),(/nlci,nlcj/),e1u_id)
+      CALL agrif_declare_variable((/2,1/),(/ind3,ind2/),(/'x','y'/),(/1,1/),(/nlci,nlcj/),e2v_id)
 
       ! 2. Type of interpolation
       !-------------------------
-   CALL Agrif_Set_bcinterp( e1u_id, interp1=Agrif_linear, interp2=AGRIF_ppm    )
-   CALL Agrif_Set_bcinterp( e2v_id, interp1=AGRIF_ppm   , interp2=Agrif_linear )
+      CALL Agrif_Set_bcinterp( e1u_id, interp1=Agrif_linear, interp2=AGRIF_ppm    )
+      CALL Agrif_Set_bcinterp( e2v_id, interp1=AGRIF_ppm   , interp2=Agrif_linear )
 
       ! 3. Location of interpolation
       !-----------------------------
-   CALL Agrif_Set_bc(e1u_id,(/0,ind1-1/))
-   CALL Agrif_Set_bc(e2v_id,(/0,ind1-1/))
+      CALL Agrif_Set_bc(e1u_id,(/0,ind1-1/))
+      CALL Agrif_Set_bc(e2v_id,(/0,ind1-1/))
 
       ! 4. Update type
       !--------------- 
 # if defined UPD_HIGH
-   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(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)
 #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)
+      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
 
-END SUBROUTINE agrif_declare_var_dom
-
-
-SUBROUTINE Agrif_InitValues_cont
+   END SUBROUTINE agrif_declare_var_dom
+
+   SUBROUTINE Agrif_InitValues_cont
       !!----------------------------------------------------------------------
       !!                 *** ROUTINE Agrif_InitValues_cont ***
-      !!
-      !! ** Purpose ::   Declaration of variables to be interpolated
-      !!----------------------------------------------------------------------
-   USE agrif_oce_update
-   USE agrif_oce_interp
-   USE agrif_oce_sponge
-   USE Agrif_Util
-   USE oce 
-   USE dom_oce
-   USE zdf_oce
-   USE nemogcm
-   !
-   USE lib_mpp
-   USE in_out_manager
-   !
-   IMPLICIT NONE
-   !
-   LOGICAL :: check_namelist
-   CHARACTER(len=15) :: cl_check1, cl_check2, cl_check3, cl_check4 
-      !!----------------------------------------------------------------------
-
-   ! 1. Declaration of the type of variable which have to be interpolated
-   !---------------------------------------------------------------------
-   CALL agrif_declare_var
-
-   ! 2. First interpolations of potentially non zero fields
-   !-------------------------------------------------------
-   Agrif_SpecialValue    = 0._wp
-   Agrif_UseSpecialValue = .TRUE.
-   CALL Agrif_Bc_variable(tsn_id,calledweight=1.,procname=interptsn)
-   CALL Agrif_Sponge
-   tabspongedone_tsn = .FALSE.
-   CALL Agrif_Bc_variable(tsn_sponge_id,calledweight=1.,procname=interptsn_sponge)
-   ! reset tsa to zero
-   tsa(:,:,:,:) = 0.
-
-   Agrif_UseSpecialValue = ln_spc_dyn
-   CALL Agrif_Bc_variable(un_interp_id,calledweight=1.,procname=interpun)
-   CALL Agrif_Bc_variable(vn_interp_id,calledweight=1.,procname=interpvn)
-   tabspongedone_u = .FALSE.
-   tabspongedone_v = .FALSE.
-   CALL Agrif_Bc_variable(un_sponge_id,calledweight=1.,procname=interpun_sponge)
-   tabspongedone_u = .FALSE.
-   tabspongedone_v = .FALSE.
-   CALL Agrif_Bc_variable(vn_sponge_id,calledweight=1.,procname=interpvn_sponge)
-
-   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 ( ln_dynspg_ts ) THEN
+      !!----------------------------------------------------------------------
+      USE agrif_oce
+      USE agrif_oce_interp
+      USE agrif_oce_sponge
+      USE dom_oce
+      USE oce
+      USE lib_mpp
+      USE lbclnk
+      !
+      IMPLICIT NONE
+      !
+      INTEGER :: ji, jj
+      LOGICAL :: check_namelist
+      CHARACTER(len=15) :: cl_check1, cl_check2, cl_check3, cl_check4 
+#if defined key_vertical
+      REAL(wp), DIMENSION(jpi,jpj) ::   zk   ! workspace
+#endif
+      !!----------------------------------------------------------------------
+
+      ! 1. Declaration of the type of variable which have to be interpolated
+      !---------------------------------------------------------------------
+      CALL agrif_declare_var
+
+      ! 2. First interpolations of potentially non zero fields
+      !-------------------------------------------------------
+
+#if defined key_vertical
+      ! Build consistent parent bathymetry and number of levels
+      ! on the child grid 
+      Agrif_UseSpecialValue = .FALSE.
+      ht0_parent(:,:) = 0._wp
+      mbkt_parent(:,:) = 0
+      !
+      CALL Agrif_Bc_variable(ht0_id ,calledweight=1.,procname=interpht0 )
+      CALL Agrif_Bc_variable(mbkt_id,calledweight=1.,procname=interpmbkt)
+      !
+      ! Assume step wise change of bathymetry near interface
+      ! TODO: Switch to linear interpolation of bathymetry in the s-coordinate case
+      !       and no refinement
+      DO jj = 1, jpjm1
+         DO ji = 1, jpim1
+            mbku_parent(ji,jj) = MIN(  mbkt_parent(ji+1,jj  ) , mbkt_parent(ji,jj)  )
+            mbkv_parent(ji,jj) = MIN(  mbkt_parent(ji  ,jj+1) , mbkt_parent(ji,jj)  )
+         END DO
+      END DO
+      IF ( ln_sco.AND.Agrif_Parent(ln_sco) ) THEN 
+         DO jj = 1, jpjm1
+            DO ji = 1, jpim1
+               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) )
+            END DO
+         END DO
+      ELSE
+         DO jj = 1, jpjm1
+            DO ji = 1, jpim1
+               hu0_parent(ji,jj) = MIN( ht0_parent(ji,jj), ht0_parent(ji+1,jj))
+               hv0_parent(ji,jj) = MIN( ht0_parent(ji,jj), ht0_parent(ji,jj+1))
+            END DO
+         END DO
+
+      ENDIF
+      !
+      CALL lbc_lnk( 'Agrif_InitValues_cont', hu0_parent, 'U', 1. )
+      CALL lbc_lnk( 'Agrif_InitValues_cont', hv0_parent, 'V', 1. )
+      zk(:,:) = REAL( mbku_parent(:,:), wp )   ;   CALL lbc_lnk( 'Agrif_InitValues_cont', zk, 'U', 1. )
+      mbku_parent(:,:) = MAX( NINT( zk(:,:) ), 1 )
+      zk(:,:) = REAL( mbkv_parent(:,:), wp )   ;   CALL lbc_lnk( 'Agrif_InitValues_cont', zk, 'V', 1. )
+      mbkv_parent(:,:) = MAX( NINT( zk(:,:) ), 1 )   
+#endif
+
+      Agrif_SpecialValue    = 0._wp
+      Agrif_UseSpecialValue = .TRUE.
+      CALL Agrif_Bc_variable(tsn_id,calledweight=1.,procname=interptsn)
+      CALL Agrif_Sponge
+      tabspongedone_tsn = .FALSE.
+      CALL Agrif_Bc_variable(tsn_sponge_id,calledweight=1.,procname=interptsn_sponge)
+      ! reset tsa to zero
+      tsa(:,:,:,:) = 0._wp
+
       Agrif_UseSpecialValue = ln_spc_dyn
-      CALL Agrif_Bc_variable(unb_id,calledweight=1.,procname=interpunb)
-      CALL Agrif_Bc_variable(vnb_id,calledweight=1.,procname=interpvnb)
-      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
-      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
-
-   Agrif_UseSpecialValue = .FALSE. 
-   ! reset velocities to zero
-   ua(:,:,:) = 0.
-   va(:,:,:) = 0.
-
-   ! 3. Some controls
-   !-----------------
-   check_namelist = .TRUE.
-
-   IF( check_namelist ) THEN 
-
-      ! Check time steps           
-      IF( NINT(Agrif_Rhot()) * NINT(rdt) .NE. Agrif_Parent(rdt) ) THEN
-         WRITE(cl_check1,*)  NINT(Agrif_Parent(rdt))
-         WRITE(cl_check2,*)  NINT(rdt)
-         WRITE(cl_check3,*)  NINT(Agrif_Parent(rdt)/Agrif_Rhot())
-         CALL ctl_stop( 'Incompatible time step between ocean grids',   &
-               &               'parent grid value : '//cl_check1    ,   & 
-               &               'child  grid value : '//cl_check2    ,   & 
-               &               'value on child grid should be changed to : '//cl_check3 )
-      ENDIF
-
-      ! Check run length
-      IF( Agrif_IRhot() * (Agrif_Parent(nitend)- &
-            Agrif_Parent(nit000)+1) .NE. (nitend-nit000+1) ) THEN
-         WRITE(cl_check1,*)  (Agrif_Parent(nit000)-1)*Agrif_IRhot() + 1
-         WRITE(cl_check2,*)   Agrif_Parent(nitend)   *Agrif_IRhot()
-         CALL ctl_warn( 'Incompatible run length between grids'                      ,   &
-               &               'nit000 on fine grid will be changed to : '//cl_check1,   &
-               &               'nitend on fine grid will be changed to : '//cl_check2    )
-         nit000 = (Agrif_Parent(nit000)-1)*Agrif_IRhot() + 1
-         nitend =  Agrif_Parent(nitend)   *Agrif_IRhot()
-      ENDIF
-
-      ! Check free surface scheme
-      IF ( ( Agrif_Parent(ln_dynspg_ts ).AND.ln_dynspg_exp ).OR.&
-         & ( Agrif_Parent(ln_dynspg_exp).AND.ln_dynspg_ts ) ) THEN
-         WRITE(cl_check1,*)  Agrif_Parent( ln_dynspg_ts )
-         WRITE(cl_check2,*)  ln_dynspg_ts
-         WRITE(cl_check3,*)  Agrif_Parent( ln_dynspg_exp )
-         WRITE(cl_check4,*)  ln_dynspg_exp
-         CALL ctl_stop( 'Incompatible free surface scheme between grids' ,  &
-               &               'parent grid ln_dynspg_ts  :'//cl_check1  ,  & 
-               &               'child  grid ln_dynspg_ts  :'//cl_check2  ,  &
-               &               'parent grid ln_dynspg_exp :'//cl_check3  ,  &
-               &               'child  grid ln_dynspg_exp :'//cl_check4  ,  &
-               &               'those logicals should be identical' )                 
-         STOP
-      ENDIF
-
-      ! Check if identical linear free surface option
-      IF ( ( Agrif_Parent(ln_linssh ).AND.(.NOT.ln_linssh )).OR.&
-         & ( (.NOT.Agrif_Parent(ln_linssh)).AND.ln_linssh ) ) THEN
-         WRITE(cl_check1,*)  Agrif_Parent(ln_linssh )
-         WRITE(cl_check2,*)  ln_linssh
-         CALL ctl_stop( 'Incompatible linearized fs option between grids',  &
-               &               'parent grid ln_linssh  :'//cl_check1     ,  &
-               &               'child  grid ln_linssh  :'//cl_check2     ,  &
-               &               'those logicals should be identical' )                  
-         STOP
+      CALL Agrif_Bc_variable(un_interp_id,calledweight=1.,procname=interpun)
+      CALL Agrif_Bc_variable(vn_interp_id,calledweight=1.,procname=interpvn)
+      tabspongedone_u = .FALSE.
+      tabspongedone_v = .FALSE.
+      CALL Agrif_Bc_variable(un_sponge_id,calledweight=1.,procname=interpun_sponge)
+      tabspongedone_u = .FALSE.
+      tabspongedone_v = .FALSE.
+      CALL Agrif_Bc_variable(vn_sponge_id,calledweight=1.,procname=interpvn_sponge)
+      ua(:,:,:) = 0._wp
+      va(:,:,:) = 0._wp
+
+      Agrif_UseSpecialValue = .TRUE.
+      CALL Agrif_Bc_variable(sshn_id,calledweight=1., procname=interpsshn )
+      hbdy(:,:) = 0._wp
+      ssha(:,:) = 0._wp
+
+      IF ( ln_dynspg_ts ) THEN
+         Agrif_UseSpecialValue = ln_spc_dyn
+         CALL Agrif_Bc_variable(unb_id,calledweight=1.,procname=interpunb)
+         CALL Agrif_Bc_variable(vnb_id,calledweight=1.,procname=interpvnb)
+         CALL Agrif_Bc_variable(ub2b_interp_id,calledweight=1.,procname=interpub2b)
+         CALL Agrif_Bc_variable(vb2b_interp_id,calledweight=1.,procname=interpvb2b)
+         ubdy(:,:) = 0._wp
+         vbdy(:,:) = 0._wp
+      ENDIF
+
+      Agrif_UseSpecialValue = .FALSE.
+
+      ! 3. Some controls
+      !-----------------
+      check_namelist = .TRUE.
+
+      IF( check_namelist ) THEN 
+
+         ! Check time steps           
+         IF( NINT(Agrif_Rhot()) * NINT(rdt) .NE. Agrif_Parent(rdt) ) THEN
+            WRITE(cl_check1,*)  NINT(Agrif_Parent(rdt))
+            WRITE(cl_check2,*)  NINT(rdt)
+            WRITE(cl_check3,*)  NINT(Agrif_Parent(rdt)/Agrif_Rhot())
+            CALL ctl_stop( 'Incompatible time step between ocean grids',   &
+                  &               'parent grid value : '//cl_check1    ,   & 
+                  &               'child  grid value : '//cl_check2    ,   & 
+                  &               'value on child grid should be changed to : '//cl_check3 )
+         ENDIF
+
+         ! Check run length
+         IF( Agrif_IRhot() * (Agrif_Parent(nitend)- &
+               Agrif_Parent(nit000)+1) .NE. (nitend-nit000+1) ) THEN
+            WRITE(cl_check1,*)  (Agrif_Parent(nit000)-1)*Agrif_IRhot() + 1
+            WRITE(cl_check2,*)   Agrif_Parent(nitend)   *Agrif_IRhot()
+            CALL ctl_warn( 'Incompatible run length between grids'                      ,   &
+                  &               'nit000 on fine grid will be changed to : '//cl_check1,   &
+                  &               'nitend on fine grid will be changed to : '//cl_check2    )
+            nit000 = (Agrif_Parent(nit000)-1)*Agrif_IRhot() + 1
+            nitend =  Agrif_Parent(nitend)   *Agrif_IRhot()
+         ENDIF
+
+         ! Check free surface scheme
+         IF ( ( Agrif_Parent(ln_dynspg_ts ).AND.ln_dynspg_exp ).OR.&
+            & ( Agrif_Parent(ln_dynspg_exp).AND.ln_dynspg_ts ) ) THEN
+            WRITE(cl_check1,*)  Agrif_Parent( ln_dynspg_ts )
+            WRITE(cl_check2,*)  ln_dynspg_ts
+            WRITE(cl_check3,*)  Agrif_Parent( ln_dynspg_exp )
+            WRITE(cl_check4,*)  ln_dynspg_exp
+            CALL ctl_stop( 'Incompatible free surface scheme between grids' ,  &
+                  &               'parent grid ln_dynspg_ts  :'//cl_check1  ,  & 
+                  &               'child  grid ln_dynspg_ts  :'//cl_check2  ,  &
+                  &               'parent grid ln_dynspg_exp :'//cl_check3  ,  &
+                  &               'child  grid ln_dynspg_exp :'//cl_check4  ,  &
+                  &               'those logicals should be identical' )                 
+            STOP
+         ENDIF
+
+         ! Check if identical linear free surface option
+         IF ( ( Agrif_Parent(ln_linssh ).AND.(.NOT.ln_linssh )).OR.&
+            & ( (.NOT.Agrif_Parent(ln_linssh)).AND.ln_linssh ) ) THEN
+            WRITE(cl_check1,*)  Agrif_Parent(ln_linssh )
+            WRITE(cl_check2,*)  ln_linssh
+            CALL ctl_stop( 'Incompatible linearized fs option between grids',  &
+                  &               'parent grid ln_linssh  :'//cl_check1     ,  &
+                  &               'child  grid ln_linssh  :'//cl_check2     ,  &
+                  &               'those logicals should be identical' )                  
+            STOP
+         ENDIF
+
       ENDIF
 
       ! check if masks and bathymetries match
       IF(ln_chk_bathy) THEN
+         Agrif_UseSpecialValue = .FALSE.
          !
+         IF(lwp) WRITE(numout,*) ' '
          IF(lwp) WRITE(numout,*) 'AGRIF: Check Bathymetry and masks near bdys. Level: ', Agrif_Level()
          !
          kindic_agr = 0
-         ! check if umask agree with parent along western and eastern boundaries:
-         CALL Agrif_Bc_variable(umsk_id,calledweight=1.,procname=interpumsk)
-         ! check if vmask agree with parent along northern and southern boundaries:
-         CALL Agrif_Bc_variable(vmsk_id,calledweight=1.,procname=interpvmsk)
-         ! check if tmask and vertical scale factors agree with parent over first two coarse grid points:
+# if ! defined key_vertical
+         !
+         ! check if tmask and vertical scale factors agree with parent in sponge area:
          CALL Agrif_Bc_variable(e3t_id,calledweight=1.,procname=interpe3t)
          !
+# else
+         !
+         ! In case of vertical interpolation, check only that total depths agree between child and parent:
+         DO ji = 1, jpi
+            DO jj = 1, jpj
+               IF ((mbkt_parent(ji,jj)/=0).AND.(ABS(ht0_parent(ji,jj)-ht_0(ji,jj))>1.e-3)) kindic_agr = kindic_agr + 1
+               IF ((mbku_parent(ji,jj)/=0).AND.(ABS(hu0_parent(ji,jj)-hu_0(ji,jj))>1.e-3)) kindic_agr = kindic_agr + 1
+               IF ((mbkv_parent(ji,jj)/=0).AND.(ABS(hv0_parent(ji,jj)-hv_0(ji,jj))>1.e-3)) kindic_agr = kindic_agr + 1
+            END DO
+         END DO
+# endif
          CALL mpp_sum( 'agrif_user', kindic_agr )
          IF( kindic_agr /= 0 ) THEN
-            CALL ctl_stop('Child Bathymetry is not correct near boundaries.')
+            CALL ctl_stop('==> Child Bathymetry is NOT correct near boundaries.')
          ELSE
-            IF(lwp) WRITE(numout,*) 'Child Bathymetry is ok near boundaries.'
-         END IF
-      ENDIF
-      !
-   ENDIF
-   ! 
-END SUBROUTINE Agrif_InitValues_cont
-
-SUBROUTINE agrif_declare_var
-      !!----------------------------------------------------------------------
-      !!                 *** ROUTINE agrif_declarE_var ***
-      !!
-      !! ** Purpose :: Declaration of variables to be interpolated
-      !!----------------------------------------------------------------------
-   USE agrif_util
-   USE agrif_oce
-   USE par_oce       ! ocean parameters
-   USE zdf_oce       ! vertical physics
-   USE oce
-   !
-   IMPLICIT NONE
-   !
-   INTEGER :: ind1, ind2, ind3
-      !!----------------------------------------------------------------------
-
-   ! 1. Declaration of the type of variable which have to be interpolated
-   !---------------------------------------------------------------------
-   ind1 =     nbghostcells
-   ind2 = 1 + nbghostcells
-   ind3 = 2 + nbghostcells
+            IF(lwp) WRITE(numout,*) '==> Child Bathymetry is ok near boundaries.'
+            IF(lwp) WRITE(numout,*) ' '
+         END IF  
+         !    
+      ENDIF
+
 # if defined key_vertical
-   CALL agrif_declare_variable((/2,2,0,0/),(/ind3,ind3,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,jpts+1/),tsn_id)
-   CALL agrif_declare_variable((/2,2,0,0/),(/ind3,ind3,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,jpts+1/),tsn_sponge_id)
-
-   CALL agrif_declare_variable((/1,2,0,0/),(/ind2,ind3,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,2/),un_interp_id)
-   CALL agrif_declare_variable((/2,1,0,0/),(/ind3,ind2,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,2/),vn_interp_id)
-   CALL agrif_declare_variable((/1,2,0,0/),(/ind2,ind3,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,2/),un_update_id)
-   CALL agrif_declare_variable((/2,1,0,0/),(/ind3,ind2,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,2/),vn_update_id)
-   CALL agrif_declare_variable((/1,2,0,0/),(/ind2,ind3,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,2/),un_sponge_id)
-   CALL agrif_declare_variable((/2,1,0,0/),(/ind3,ind2,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,2/),vn_sponge_id)
+      ! Additional constrain that should be removed someday:
+      IF ( Agrif_Parent(jpk).GT.jpk ) THEN
+	 CALL ctl_stop( ' With key_vertical, child grids must have jpk greater or equal to the parent value' )
+      ENDIF
+# endif
+      ! 
+   END SUBROUTINE Agrif_InitValues_cont
+
+   SUBROUTINE agrif_declare_var
+      !!----------------------------------------------------------------------
+      !!                 *** ROUTINE agrif_declare_var ***
+      !!----------------------------------------------------------------------
+      USE agrif_util
+      USE agrif_oce
+      USE par_oce
+      USE zdf_oce 
+      USE oce
+      !
+      IMPLICIT NONE
+      !
+      INTEGER :: ind1, ind2, ind3
+      !!----------------------------------------------------------------------
+
+      ! 1. Declaration of the type of variable which have to be interpolated
+      !---------------------------------------------------------------------
+      ind1 =     nbghostcells
+      ind2 = 1 + nbghostcells
+      ind3 = 2 + nbghostcells
+# if defined key_vertical
+      CALL agrif_declare_variable((/2,2,0,0/),(/ind3,ind3,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,jpts+1/),tsn_id)
+      CALL agrif_declare_variable((/2,2,0,0/),(/ind3,ind3,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,jpts+1/),tsn_sponge_id)
+
+      CALL agrif_declare_variable((/1,2,0,0/),(/ind2,ind3,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,2/),un_interp_id)
+      CALL agrif_declare_variable((/2,1,0,0/),(/ind3,ind2,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,2/),vn_interp_id)
+      CALL agrif_declare_variable((/1,2,0,0/),(/ind2,ind3,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,2/),un_update_id)
+      CALL agrif_declare_variable((/2,1,0,0/),(/ind3,ind2,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,2/),vn_update_id)
+      CALL agrif_declare_variable((/1,2,0,0/),(/ind2,ind3,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,2/),un_sponge_id)
+      CALL agrif_declare_variable((/2,1,0,0/),(/ind3,ind2,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,2/),vn_sponge_id)
 # else
-   CALL agrif_declare_variable((/2,2,0,0/),(/ind3,ind3,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,jpts/),tsn_id)
-   CALL agrif_declare_variable((/2,2,0,0/),(/ind3,ind3,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,jpts/),tsn_sponge_id)
-
-   CALL agrif_declare_variable((/1,2,0,0/),(/ind2,ind3,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,1/),un_interp_id)
-   CALL agrif_declare_variable((/2,1,0,0/),(/ind3,ind2,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,1/),vn_interp_id)
-   CALL agrif_declare_variable((/1,2,0,0/),(/ind2,ind3,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,1/),un_update_id)
-   CALL agrif_declare_variable((/2,1,0,0/),(/ind3,ind2,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,1/),vn_update_id)
-   CALL agrif_declare_variable((/1,2,0,0/),(/ind2,ind3,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,1/),un_sponge_id)
-   CALL agrif_declare_variable((/2,1,0,0/),(/ind3,ind2,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,1/),vn_sponge_id)
-# endif
-
-   CALL agrif_declare_variable((/2,2,0/),(/ind3,ind3,0/),(/'x','y','N'/),(/1,1,1/),(/nlci,nlcj,jpk/),e3t_id)
-   CALL agrif_declare_variable((/1,2,0/),(/ind2,ind3,0/),(/'x','y','N'/),(/1,1,1/),(/nlci,nlcj,jpk/),umsk_id)
-   CALL agrif_declare_variable((/2,1,0/),(/ind3,ind2,0/),(/'x','y','N'/),(/1,1,1/),(/nlci,nlcj,jpk/),vmsk_id)
-
-   CALL agrif_declare_variable((/2,2,0,0/),(/ind3,ind3,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,3/),scales_t_id)
-
-   CALL agrif_declare_variable((/1,2/),(/ind2,ind3/),(/'x','y'/),(/1,1/),(/nlci,nlcj/),unb_id)
-   CALL agrif_declare_variable((/2,1/),(/ind3,ind2/),(/'x','y'/),(/1,1/),(/nlci,nlcj/),vnb_id)
-   CALL agrif_declare_variable((/1,2/),(/ind2,ind3/),(/'x','y'/),(/1,1/),(/nlci,nlcj/),ub2b_interp_id)
-   CALL agrif_declare_variable((/2,1/),(/ind3,ind2/),(/'x','y'/),(/1,1/),(/nlci,nlcj/),vb2b_interp_id)
-   CALL agrif_declare_variable((/1,2/),(/ind2,ind3/),(/'x','y'/),(/1,1/),(/nlci,nlcj/),ub2b_update_id)
-   CALL agrif_declare_variable((/2,1/),(/ind3,ind2/),(/'x','y'/),(/1,1/),(/nlci,nlcj/),vb2b_update_id)
-
-   CALL agrif_declare_variable((/2,2/),(/ind3,ind3/),(/'x','y'/),(/1,1/),(/nlci,nlcj/),sshn_id)
-
-   IF( ln_zdftke.OR.ln_zdfgls ) THEN
-!      CALL agrif_declare_variable((/2,2,0/),(/ind3,ind3,0/),(/'x','y','N'/),(/1,1,1/),(/nlci,nlcj,jpk/), en_id)
-!      CALL agrif_declare_variable((/2,2,0/),(/ind3,ind3,0/),(/'x','y','N'/),(/1,1,1/),(/nlci,nlcj,jpk/),avt_id)
+      CALL agrif_declare_variable((/2,2,0,0/),(/ind3,ind3,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,jpts/),tsn_id)
+      CALL agrif_declare_variable((/2,2,0,0/),(/ind3,ind3,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,jpts/),tsn_sponge_id)
+
+      CALL agrif_declare_variable((/1,2,0,0/),(/ind2,ind3,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,1/),un_interp_id)
+      CALL agrif_declare_variable((/2,1,0,0/),(/ind3,ind2,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,1/),vn_interp_id)
+      CALL agrif_declare_variable((/1,2,0,0/),(/ind2,ind3,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,1/),un_update_id)
+      CALL agrif_declare_variable((/2,1,0,0/),(/ind3,ind2,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,1/),vn_update_id)
+      CALL agrif_declare_variable((/1,2,0,0/),(/ind2,ind3,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,1/),un_sponge_id)
+      CALL agrif_declare_variable((/2,1,0,0/),(/ind3,ind2,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,1/),vn_sponge_id)
+# endif
+
+      CALL agrif_declare_variable((/2,2,0/),(/ind3,ind3,0/),(/'x','y','N'/),(/1,1,1/),(/nlci,nlcj,jpk/),e3t_id)
+
 # if defined key_vertical
-      CALL agrif_declare_variable((/2,2,0,0/),(/ind3,ind3,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,2/),avm_id)
+      CALL agrif_declare_variable((/2,2/),(/ind3,ind3/),(/'x','y'/),(/1,1/),(/nlci,nlcj/),mbkt_id)
+      CALL agrif_declare_variable((/2,2/),(/ind3,ind3/),(/'x','y'/),(/1,1/),(/nlci,nlcj/),ht0_id)
+# endif
+
+      CALL agrif_declare_variable((/2,2,0,0/),(/ind3,ind3,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,3/),scales_t_id)
+
+      CALL agrif_declare_variable((/1,2/),(/ind2,ind3/),(/'x','y'/),(/1,1/),(/nlci,nlcj/),unb_id)
+      CALL agrif_declare_variable((/2,1/),(/ind3,ind2/),(/'x','y'/),(/1,1/),(/nlci,nlcj/),vnb_id)
+      CALL agrif_declare_variable((/1,2/),(/ind2,ind3/),(/'x','y'/),(/1,1/),(/nlci,nlcj/),ub2b_interp_id)
+      CALL agrif_declare_variable((/2,1/),(/ind3,ind2/),(/'x','y'/),(/1,1/),(/nlci,nlcj/),vb2b_interp_id)
+      CALL agrif_declare_variable((/1,2/),(/ind2,ind3/),(/'x','y'/),(/1,1/),(/nlci,nlcj/),ub2b_update_id)
+      CALL agrif_declare_variable((/2,1/),(/ind3,ind2/),(/'x','y'/),(/1,1/),(/nlci,nlcj/),vb2b_update_id)
+
+      CALL agrif_declare_variable((/2,2/),(/ind3,ind3/),(/'x','y'/),(/1,1/),(/nlci,nlcj/),sshn_id)
+
+      IF( ln_zdftke.OR.ln_zdfgls ) THEN
+!         CALL agrif_declare_variable((/2,2,0/),(/ind3,ind3,0/),(/'x','y','N'/),(/1,1,1/),(/nlci,nlcj,jpk/), en_id)
+!         CALL agrif_declare_variable((/2,2,0/),(/ind3,ind3,0/),(/'x','y','N'/),(/1,1,1/),(/nlci,nlcj,jpk/),avt_id)
+# if defined key_vertical
+         CALL agrif_declare_variable((/2,2,0,0/),(/ind3,ind3,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,2/),avm_id)
 # else
-      CALL agrif_declare_variable((/2,2,0,0/),(/ind3,ind3,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,1/),avm_id)
-# endif
-   ENDIF
-
-   ! 2. Type of interpolation
-   !-------------------------
-   CALL Agrif_Set_bcinterp(tsn_id,interp=AGRIF_linear)
-
-   CALL Agrif_Set_bcinterp(un_interp_id,interp1=Agrif_linear,interp2=AGRIF_ppm)
-   CALL Agrif_Set_bcinterp(vn_interp_id,interp1=AGRIF_ppm,interp2=Agrif_linear)
-
-   CALL Agrif_Set_bcinterp(tsn_sponge_id,interp=AGRIF_linear)
-
-   CALL Agrif_Set_bcinterp(sshn_id,interp=AGRIF_linear)
-   CALL Agrif_Set_bcinterp(unb_id,interp1=Agrif_linear,interp2=AGRIF_ppm)
-   CALL Agrif_Set_bcinterp(vnb_id,interp1=AGRIF_ppm,interp2=Agrif_linear)
-   CALL Agrif_Set_bcinterp(ub2b_interp_id,interp1=Agrif_linear,interp2=AGRIF_ppm)
-   CALL Agrif_Set_bcinterp(vb2b_interp_id,interp1=AGRIF_ppm,interp2=Agrif_linear)
-
-
-   CALL Agrif_Set_bcinterp(un_sponge_id,interp1=Agrif_linear,interp2=AGRIF_ppm)
-   CALL Agrif_Set_bcinterp(vn_sponge_id,interp1=AGRIF_ppm,interp2=Agrif_linear)
-
-   CALL Agrif_Set_bcinterp(e3t_id,interp=AGRIF_constant)
-   CALL Agrif_Set_bcinterp(umsk_id,interp=AGRIF_constant)
-   CALL Agrif_Set_bcinterp(vmsk_id,interp=AGRIF_constant)
-
-   IF( ln_zdftke.OR.ln_zdfgls )   CALL Agrif_Set_bcinterp( avm_id, interp=AGRIF_linear )
-
-   ! 3. Location of interpolation
-   !-----------------------------
-   CALL Agrif_Set_bc(       tsn_id, (/0,ind1/) )
-   CALL Agrif_Set_bc( un_interp_id, (/0,ind1/) )
-   CALL Agrif_Set_bc( vn_interp_id, (/0,ind1/) )
-
-   CALL Agrif_Set_bc( tsn_sponge_id, (/-nn_sponge_len*Agrif_irhox()-1,0/) )  ! if west and rhox=3 and sponge=2 and ghost=1: columns 2 to 9 
-   CALL Agrif_Set_bc(  un_sponge_id, (/-nn_sponge_len*Agrif_irhox()-1,0/) )
-   CALL Agrif_Set_bc(  vn_sponge_id, (/-nn_sponge_len*Agrif_irhox()-1,0/) )
-
-   CALL Agrif_Set_bc(        sshn_id, (/0,ind1-1/) )
-   CALL Agrif_Set_bc(         unb_id, (/0,ind1-1/) )
-   CALL Agrif_Set_bc(         vnb_id, (/0,ind1-1/) )
-   CALL Agrif_Set_bc( ub2b_interp_id, (/0,ind1-1/) )
-   CALL Agrif_Set_bc( vb2b_interp_id, (/0,ind1-1/) )
-
-   CALL Agrif_Set_bc(  e3t_id, (/-nn_sponge_len*Agrif_irhox(),ind1-1/) )   ! if west and rhox=3 and ghost=1: column 2 to 6 
-   CALL Agrif_Set_bc( umsk_id, (/0,0/) )
-   CALL Agrif_Set_bc( vmsk_id, (/0,0/) )
-
-
-   IF( ln_zdftke.OR.ln_zdfgls )   CALL Agrif_Set_bc( avm_id, (/0,ind1/) )
-
-   ! 4. Update type
-   !--------------- 
-   CALL Agrif_Set_Updatetype(scales_t_id, update = AGRIF_Update_Average)
+         CALL agrif_declare_variable((/2,2,0,0/),(/ind3,ind3,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,1/),avm_id)
+# endif
+      ENDIF
+
+      ! 2. Type of interpolation
+      !-------------------------
+      CALL Agrif_Set_bcinterp(tsn_id,interp=AGRIF_linear)
+
+      CALL Agrif_Set_bcinterp(un_interp_id,interp1=Agrif_linear,interp2=AGRIF_ppm)
+      CALL Agrif_Set_bcinterp(vn_interp_id,interp1=AGRIF_ppm,interp2=Agrif_linear)
+
+      CALL Agrif_Set_bcinterp(tsn_sponge_id,interp=AGRIF_linear)
+
+      CALL Agrif_Set_bcinterp(sshn_id,interp=AGRIF_linear)
+      CALL Agrif_Set_bcinterp(unb_id,interp1=Agrif_linear,interp2=AGRIF_ppm)
+      CALL Agrif_Set_bcinterp(vnb_id,interp1=AGRIF_ppm,interp2=Agrif_linear)
+      CALL Agrif_Set_bcinterp(ub2b_interp_id,interp1=Agrif_linear,interp2=AGRIF_ppm)
+      CALL Agrif_Set_bcinterp(vb2b_interp_id,interp1=AGRIF_ppm,interp2=Agrif_linear)
+!
+! > Divergence conserving alternative:
+!      CALL Agrif_Set_bcinterp(sshn_id,interp=AGRIF_constant)
+!      CALL Agrif_Set_bcinterp(unb_id,interp1=Agrif_linear,interp2=AGRIF_constant)
+!      CALL Agrif_Set_bcinterp(vnb_id,interp1=AGRIF_constant,interp2=Agrif_linear)
+!      CALL Agrif_Set_bcinterp(ub2b_interp_id,interp1=Agrif_linear,interp2=AGRIF_constant)
+!      CALL Agrif_Set_bcinterp(vb2b_interp_id,interp1=AGRIF_constant,interp2=Agrif_linear)
+!<
+
+      CALL Agrif_Set_bcinterp(un_sponge_id,interp1=Agrif_linear,interp2=AGRIF_ppm)
+      CALL Agrif_Set_bcinterp(vn_sponge_id,interp1=AGRIF_ppm,interp2=Agrif_linear)
+
+      CALL Agrif_Set_bcinterp(e3t_id,interp=AGRIF_constant)
+
+# if defined key_vertical
+      CALL Agrif_Set_bcinterp(mbkt_id,interp=AGRIF_constant)
+      CALL Agrif_Set_bcinterp(ht0_id ,interp=AGRIF_constant)
+# endif
+
+      IF( ln_zdftke.OR.ln_zdfgls )   CALL Agrif_Set_bcinterp( avm_id, interp=AGRIF_linear )
+
+      ! 3. Location of interpolation
+      !-----------------------------
+      CALL Agrif_Set_bc(       tsn_id, (/0,ind1-1/) ) ! if west,  rhox=3 and nbghost=3: columns 2 to 4
+      CALL Agrif_Set_bc( un_interp_id, (/0,ind1-1/) ) 
+      CALL Agrif_Set_bc( vn_interp_id, (/0,ind1-1/) )
+
+      CALL Agrif_Set_bc( tsn_sponge_id, (/-nn_sponge_len*Agrif_irhox()-1,0/) )  ! if west,  rhox=3, nn_sponge_len=2 
+      CALL Agrif_Set_bc(  un_sponge_id, (/-nn_sponge_len*Agrif_irhox()-1,0/) )  ! and nbghost=3: 
+      CALL Agrif_Set_bc(  vn_sponge_id, (/-nn_sponge_len*Agrif_irhox()-1,0/) )  ! columns 4 to 11
+
+      CALL Agrif_Set_bc(        sshn_id, (/0,ind1-1/) )
+      CALL Agrif_Set_bc(         unb_id, (/0,ind1-1/) )
+      CALL Agrif_Set_bc(         vnb_id, (/0,ind1-1/) )
+      CALL Agrif_Set_bc( ub2b_interp_id, (/0,ind1-1/) )
+      CALL Agrif_Set_bc( vb2b_interp_id, (/0,ind1-1/) )
+
+!      CALL Agrif_Set_bc(  e3t_id, (/-nn_sponge_len*Agrif_irhox(),ind1-1/) )  
+! JC: check near the boundary only until matching in sponge has been sorted out:
+      CALL Agrif_Set_bc(  e3t_id, (/0,ind1-1/) )  
+
+# if defined key_vertical 
+      ! extend the interpolation zone by 1 more point than necessary:
+      CALL Agrif_Set_bc(  mbkt_id, (/-nn_sponge_len*Agrif_irhox()-2,ind1/) )
+      CALL Agrif_Set_bc(  ht0_id,  (/-nn_sponge_len*Agrif_irhox()-2,ind1/) )
+# endif
+
+      IF( ln_zdftke.OR.ln_zdfgls )   CALL Agrif_Set_bc( avm_id, (/0,ind1/) )
+
+      ! 4. Update type
+      !--------------- 
+      CALL Agrif_Set_Updatetype(scales_t_id, update = AGRIF_Update_Average)
 
 # if defined UPD_HIGH
-   CALL Agrif_Set_Updatetype(tsn_id, update = Agrif_Update_Full_Weighting)
-   CALL Agrif_Set_Updatetype(un_update_id,update1 = Agrif_Update_Average, update2 = Agrif_Update_Full_Weighting)
-   CALL Agrif_Set_Updatetype(vn_update_id,update1 = Agrif_Update_Full_Weighting, update2 = Agrif_Update_Average)
-
-   CALL Agrif_Set_Updatetype(ub2b_update_id,update1 = Agrif_Update_Average, update2 = Agrif_Update_Full_Weighting)
-   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)
-
-   IF( ln_zdftke.OR.ln_zdfgls ) THEN
-!      CALL Agrif_Set_Updatetype( en_id, update = AGRIF_Update_Full_Weighting)
-!      CALL Agrif_Set_Updatetype(avt_id, update = AGRIF_Update_Full_Weighting)
-!      CALL Agrif_Set_Updatetype(avm_id, update = AGRIF_Update_Full_Weighting)
-   ENDIF
+      CALL Agrif_Set_Updatetype(tsn_id, update = Agrif_Update_Full_Weighting)
+      CALL Agrif_Set_Updatetype(un_update_id,update1 = Agrif_Update_Average, update2 = Agrif_Update_Full_Weighting)
+      CALL Agrif_Set_Updatetype(vn_update_id,update1 = Agrif_Update_Full_Weighting, update2 = Agrif_Update_Average)
+
+      CALL Agrif_Set_Updatetype(ub2b_update_id,update1 = Agrif_Update_Average, update2 = Agrif_Update_Full_Weighting)
+      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)
+
+      IF( ln_zdftke.OR.ln_zdfgls ) THEN
+!         CALL Agrif_Set_Updatetype( en_id, update = AGRIF_Update_Full_Weighting)
+!         CALL Agrif_Set_Updatetype(avt_id, update = AGRIF_Update_Full_Weighting)
+!         CALL Agrif_Set_Updatetype(avm_id, update = AGRIF_Update_Full_Weighting)
+      ENDIF
 
 #else
-   CALL Agrif_Set_Updatetype(tsn_id, update = AGRIF_Update_Average)
-   CALL Agrif_Set_Updatetype(un_update_id,update1 = Agrif_Update_Copy, update2 = Agrif_Update_Average)
-   CALL Agrif_Set_Updatetype(vn_update_id,update1 = Agrif_Update_Average, update2 = Agrif_Update_Copy)
-
-   CALL Agrif_Set_Updatetype(ub2b_update_id,update1 = Agrif_Update_Copy, update2 = Agrif_Update_Average)
-   CALL Agrif_Set_Updatetype(vb2b_update_id,update1 = Agrif_Update_Average, update2 = Agrif_Update_Copy)
-   CALL Agrif_Set_Updatetype(sshn_id, update = AGRIF_Update_Average)
-   CALL Agrif_Set_Updatetype(e3t_id, update = AGRIF_Update_Average)
-
-   IF( ln_zdftke.OR.ln_zdfgls ) THEN
-!      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)
-   ENDIF
+      CALL Agrif_Set_Updatetype(tsn_id, update = AGRIF_Update_Average)
+      CALL Agrif_Set_Updatetype(un_update_id,update1 = Agrif_Update_Copy, update2 = Agrif_Update_Average)
+      CALL Agrif_Set_Updatetype(vn_update_id,update1 = Agrif_Update_Average, update2 = Agrif_Update_Copy)
+
+      CALL Agrif_Set_Updatetype(ub2b_update_id,update1 = Agrif_Update_Copy, update2 = Agrif_Update_Average)
+      CALL Agrif_Set_Updatetype(vb2b_update_id,update1 = Agrif_Update_Average, update2 = Agrif_Update_Copy)
+      CALL Agrif_Set_Updatetype(sshn_id,update = AGRIF_Update_Average)
+      CALL Agrif_Set_Updatetype(e3t_id, update = AGRIF_Update_Average)
+
+      IF( ln_zdftke.OR.ln_zdfgls ) THEN
+!         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)
+      ENDIF
 
 #endif
-   !
-END SUBROUTINE agrif_declare_var
+      !
+   END SUBROUTINE agrif_declare_var
 
 #if defined key_si3
@@ -453,152 +477,143 @@
       !!----------------------------------------------------------------------
       !!                 *** ROUTINE Agrif_InitValues_cont_ice ***
+      !!----------------------------------------------------------------------
+      USE Agrif_Util
+      USE sbc_oce, ONLY : nn_fsbc  ! clem: necessary otherwise Agrif_Parent(nn_fsbc) = nn_fsbc
+      USE ice
+      USE agrif_ice
+      USE in_out_manager
+      USE agrif_ice_interp
+      USE lib_mpp
+      !
+      IMPLICIT NONE
+      !!----------------------------------------------------------------------
+      !
+      ! Declaration of the type of variable which have to be interpolated (parent=>child)
+      !----------------------------------------------------------------------------------
+      CALL agrif_declare_var_ice
+
+      ! Controls
+
+      ! clem: For some reason, nn_fsbc(child)/=1 does not work properly (signal can be largely degraded by the agrif zoom)
+      !          the run must satisfy CFL=Uice/(dx/dt) < 0.6/nn_fsbc(child)
+      !          therefore, if nn_fsbc(child)>1 one must reduce the time-step in proportion to nn_fsbc(child), which is not acceptable
+      !       If a solution is found, the following stop could be removed because the rest of the code take nn_fsbc(child) into account
+      IF( nn_fsbc > 1 )  CALL ctl_stop('nn_fsbc(child) must be set to 1 otherwise agrif and sea-ice may not work properly')
+
+      ! stop if rhot * nn_fsbc(parent) /= N * nn_fsbc(child) with N being integer
+      IF( MOD( Agrif_irhot() * Agrif_Parent(nn_fsbc), nn_fsbc ) /= 0 )  THEN
+         CALL ctl_stop('rhot * nn_fsbc(parent) /= N * nn_fsbc(child), therefore nn_fsbc(child) should be set to 1 or nn_fsbc(parent)')
+      ENDIF
+      ! First Interpolations (using "after" ice subtime step => nbstep_ice=1)
+      !----------------------------------------------------------------------
+      nbstep_ice = ( Agrif_irhot() * Agrif_Parent(nn_fsbc) / nn_fsbc ) ! clem: to have calledweight=1 in interp (otherwise the western border of the zoom is wrong)
+      CALL agrif_interp_ice('U') ! interpolation of ice velocities
+      CALL agrif_interp_ice('V') ! interpolation of ice velocities
+      CALL agrif_interp_ice('T') ! interpolation of ice tracers 
+      nbstep_ice = 0   
+      !
+   END SUBROUTINE Agrif_InitValues_cont_ice
+
+   SUBROUTINE agrif_declare_var_ice
+      !!----------------------------------------------------------------------
+      !!                 *** ROUTINE agrif_declare_var_ice ***
+      !!----------------------------------------------------------------------
+      USE Agrif_Util
+      USE ice
+      USE par_oce, ONLY : nbghostcells
+      !
+      IMPLICIT NONE
+      !
+      INTEGER :: ind1, ind2, ind3
+      !!----------------------------------------------------------------------
+      !
+      ! 1. Declaration of the type of variable which have to be interpolated (parent=>child)
+      !       agrif_declare_variable(position,1st point index,--,--,dimensions,name)
+      !           ex.:  position=> 1,1 = not-centered (in i and j)
+      !                            2,2 =     centered (    -     )
+      !                 index   => 1,1 = one ghost line
+      !                            2,2 = two ghost lines
+      !-------------------------------------------------------------------------------------
+      ind1 =     nbghostcells
+      ind2 = 1 + nbghostcells
+      ind3 = 2 + nbghostcells
+      CALL agrif_declare_variable((/2,2,0/),(/ind3,ind3,0/),(/'x','y','N'/),(/1,1,1/),(/nlci,nlcj,jpl*(8+nlay_s+nlay_i)/),tra_ice_id)
+      CALL agrif_declare_variable((/1,2/)  ,(/ind2,ind3/)  ,(/'x','y'/)    ,(/1,1/)  ,(/nlci,nlcj/)                      ,u_ice_id  )
+      CALL agrif_declare_variable((/2,1/)  ,(/ind3,ind2/)  ,(/'x','y'/)    ,(/1,1/)  ,(/nlci,nlcj/)                      ,v_ice_id  )
+
+      ! 2. Set interpolations (normal & tangent to the grid cell for velocities)
+      !-----------------------------------
+      CALL Agrif_Set_bcinterp(tra_ice_id, interp  = AGRIF_linear)
+      CALL Agrif_Set_bcinterp(u_ice_id  , interp1 = Agrif_linear,interp2 = AGRIF_ppm   )
+      CALL Agrif_Set_bcinterp(v_ice_id  , interp1 = AGRIF_ppm   ,interp2 = Agrif_linear)
+
+      ! 3. Set location of interpolations
+      !----------------------------------
+      CALL Agrif_Set_bc(tra_ice_id,(/0,ind1/))
+      CALL Agrif_Set_bc(u_ice_id  ,(/0,ind1/))
+      CALL Agrif_Set_bc(v_ice_id  ,(/0,ind1/))
+
+      ! 4. Set update type in case 2 ways (child=>parent) (normal & tangent to the grid cell for velocities)
+      !--------------------------------------------------
+# if defined UPD_HIGH
+      CALL Agrif_Set_Updatetype(tra_ice_id, update  = Agrif_Update_Full_Weighting)
+      CALL Agrif_Set_Updatetype(u_ice_id  , update1 = Agrif_Update_Average       , update2 = Agrif_Update_Full_Weighting)
+      CALL Agrif_Set_Updatetype(v_ice_id  , update1 = Agrif_Update_Full_Weighting, update2 = Agrif_Update_Average       )
+#else
+      CALL Agrif_Set_Updatetype(tra_ice_id, update  = AGRIF_Update_Average)
+      CALL Agrif_Set_Updatetype(u_ice_id  , update1 = Agrif_Update_Copy   , update2 = Agrif_Update_Average)
+      CALL Agrif_Set_Updatetype(v_ice_id  , update1 = Agrif_Update_Average, update2 = Agrif_Update_Copy   )
+#endif
+
+   END SUBROUTINE agrif_declare_var_ice
+#endif
+
+
+# if defined key_top
+   SUBROUTINE Agrif_InitValues_cont_top
+      !!----------------------------------------------------------------------
+      !!                 *** ROUTINE Agrif_InitValues_cont_top ***
+      !!----------------------------------------------------------------------
+      USE Agrif_Util
+      USE oce 
+      USE dom_oce
+      USE nemogcm
+      USE par_trc
+      USE lib_mpp
+      USE trc
+      USE in_out_manager
+      USE agrif_oce_sponge
+      USE agrif_top_update
+      USE agrif_top_interp
+      USE agrif_top_sponge
       !!
-      !! ** Purpose :: Initialisation of variables to be interpolated for ice
-      !!----------------------------------------------------------------------
-   USE Agrif_Util
-   USE sbc_oce, ONLY : nn_fsbc  ! clem: necessary otherwise Agrif_Parent(nn_fsbc) = nn_fsbc
-   USE ice
-   USE agrif_ice
-   USE in_out_manager
-   USE agrif_ice_interp
-   USE lib_mpp
-   !
-   IMPLICIT NONE
-      !!----------------------------------------------------------------------
-   !
-   ! Declaration of the type of variable which have to be interpolated (parent=>child)
-   !----------------------------------------------------------------------------------
-   CALL agrif_declare_var_ice
-
-   ! Controls
-
-   ! clem: For some reason, nn_fsbc(child)/=1 does not work properly (signal can be largely degraded by the agrif zoom)
-   !          the run must satisfy CFL=Uice/(dx/dt) < 0.6/nn_fsbc(child)
-   !          therefore, if nn_fsbc(child)>1 one must reduce the time-step in proportion to nn_fsbc(child), which is not acceptable
-   !       If a solution is found, the following stop could be removed because the rest of the code take nn_fsbc(child) into account
-   IF( nn_fsbc > 1 )  CALL ctl_stop('nn_fsbc(child) must be set to 1 otherwise agrif and sea-ice may not work properly')
-
-   ! stop if rhot * nn_fsbc(parent) /= N * nn_fsbc(child) with N being integer
-   IF( MOD( Agrif_irhot() * Agrif_Parent(nn_fsbc), nn_fsbc ) /= 0 )  THEN
-      CALL ctl_stop('rhot * nn_fsbc(parent) /= N * nn_fsbc(child), therefore nn_fsbc(child) should be set to 1 or nn_fsbc(parent)')
-   ENDIF
-   ! First Interpolations (using "after" ice subtime step => nbstep_ice=1)
-   !----------------------------------------------------------------------
-   nbstep_ice = ( Agrif_irhot() * Agrif_Parent(nn_fsbc) / nn_fsbc ) ! clem: to have calledweight=1 in interp (otherwise the western border of the zoom is wrong)
-   CALL agrif_interp_ice('U') ! interpolation of ice velocities
-   CALL agrif_interp_ice('V') ! interpolation of ice velocities
-   CALL agrif_interp_ice('T') ! interpolation of ice tracers 
-   nbstep_ice = 0
-   
-   !
-END SUBROUTINE Agrif_InitValues_cont_ice
-
-SUBROUTINE agrif_declare_var_ice
-      !!----------------------------------------------------------------------
-      !!                 *** ROUTINE agrif_declare_var_ice ***
-      !!
-      !! ** Purpose :: Declaration of variables to be interpolated for ice
-      !!----------------------------------------------------------------------
-   USE Agrif_Util
-   USE ice
-   USE par_oce, ONLY : nbghostcells
-   !
-   IMPLICIT NONE
-   !
-   INTEGER :: ind1, ind2, ind3
-      !!----------------------------------------------------------------------
-   !
-   ! 1. Declaration of the type of variable which have to be interpolated (parent=>child)
-   !       agrif_declare_variable(position,1st point index,--,--,dimensions,name)
-   !           ex.:  position=> 1,1 = not-centered (in i and j)
-   !                            2,2 =     centered (    -     )
-   !                 index   => 1,1 = one ghost line
-   !                            2,2 = two ghost lines
-   !-------------------------------------------------------------------------------------
-   ind1 =     nbghostcells
-   ind2 = 1 + nbghostcells
-   ind3 = 2 + nbghostcells
-   CALL agrif_declare_variable((/2,2,0/),(/ind3,ind3,0/),(/'x','y','N'/),(/1,1,1/),(/nlci,nlcj,jpl*(8+nlay_s+nlay_i)/),tra_ice_id)
-   CALL agrif_declare_variable((/1,2/)  ,(/ind2,ind3/)  ,(/'x','y'/)    ,(/1,1/)  ,(/nlci,nlcj/)                      ,u_ice_id  )
-   CALL agrif_declare_variable((/2,1/)  ,(/ind3,ind2/)  ,(/'x','y'/)    ,(/1,1/)  ,(/nlci,nlcj/)                      ,v_ice_id  )
-
-   ! 2. Set interpolations (normal & tangent to the grid cell for velocities)
-   !-----------------------------------
-   CALL Agrif_Set_bcinterp(tra_ice_id, interp  = AGRIF_linear)
-   CALL Agrif_Set_bcinterp(u_ice_id  , interp1 = Agrif_linear,interp2 = AGRIF_ppm   )
-   CALL Agrif_Set_bcinterp(v_ice_id  , interp1 = AGRIF_ppm   ,interp2 = Agrif_linear)
-
-   ! 3. Set location of interpolations
-   !----------------------------------
-   CALL Agrif_Set_bc(tra_ice_id,(/0,ind1/))
-   CALL Agrif_Set_bc(u_ice_id  ,(/0,ind1/))
-   CALL Agrif_Set_bc(v_ice_id  ,(/0,ind1/))
-
-   ! 4. Set update type in case 2 ways (child=>parent) (normal & tangent to the grid cell for velocities)
-   !--------------------------------------------------
-# if defined UPD_HIGH
-   CALL Agrif_Set_Updatetype(tra_ice_id, update  = Agrif_Update_Full_Weighting)
-   CALL Agrif_Set_Updatetype(u_ice_id  , update1 = Agrif_Update_Average       , update2 = Agrif_Update_Full_Weighting)
-   CALL Agrif_Set_Updatetype(v_ice_id  , update1 = Agrif_Update_Full_Weighting, update2 = Agrif_Update_Average       )
-#else
-   CALL Agrif_Set_Updatetype(tra_ice_id, update  = AGRIF_Update_Average)
-   CALL Agrif_Set_Updatetype(u_ice_id  , update1 = Agrif_Update_Copy   , update2 = Agrif_Update_Average)
-   CALL Agrif_Set_Updatetype(v_ice_id  , update1 = Agrif_Update_Average, update2 = Agrif_Update_Copy   )
-#endif
-
-END SUBROUTINE agrif_declare_var_ice
-#endif
-
-
-# if defined key_top
-SUBROUTINE Agrif_InitValues_cont_top
-      !!----------------------------------------------------------------------
-      !!                 *** ROUTINE Agrif_InitValues_cont_top ***
-      !!
-      !! ** Purpose :: Declaration of variables to be interpolated
-      !!----------------------------------------------------------------------
-   USE Agrif_Util
-   USE oce 
-   USE dom_oce
-   USE nemogcm
-   USE par_trc
-   USE lib_mpp
-   USE trc
-   USE in_out_manager
-   USE agrif_oce_sponge
-   USE agrif_top_update
-   USE agrif_top_interp
-   USE agrif_top_sponge
-   !!
-   IMPLICIT NONE
-   !
-   CHARACTER(len=10) :: cl_check1, cl_check2, cl_check3
-   LOGICAL :: check_namelist
-      !!----------------------------------------------------------------------
-
-
-   ! 1. Declaration of the type of variable which have to be interpolated
-   !---------------------------------------------------------------------
-   CALL agrif_declare_var_top
-
-   ! 2. First interpolations of potentially non zero fields
-   !-------------------------------------------------------
-   Agrif_SpecialValue=0.
-   Agrif_UseSpecialValue = .TRUE.
-   CALL Agrif_Bc_variable(trn_id,calledweight=1.,procname=interptrn)
-   Agrif_UseSpecialValue = .FALSE.
-   CALL Agrif_Sponge
-   tabspongedone_trn = .FALSE.
-   CALL Agrif_Bc_variable(trn_sponge_id,calledweight=1.,procname=interptrn_sponge)
-   ! reset tsa to zero
-   tra(:,:,:,:) = 0.
-
-
-   ! 3. Some controls
-   !-----------------
-   check_namelist = .TRUE.
-
-   IF( check_namelist ) THEN
-      ! Check time steps
+      IMPLICIT NONE
+      !
+      CHARACTER(len=10) :: cl_check1, cl_check2, cl_check3
+      LOGICAL :: check_namelist
+      !!----------------------------------------------------------------------
+
+      ! 1. Declaration of the type of variable which have to be interpolated
+      !---------------------------------------------------------------------
+      CALL agrif_declare_var_top
+
+      ! 2. First interpolations of potentially non zero fields
+      !-------------------------------------------------------
+      Agrif_SpecialValue=0._wp
+      Agrif_UseSpecialValue = .TRUE.
+      CALL Agrif_Bc_variable(trn_id,calledweight=1.,procname=interptrn)
+      Agrif_UseSpecialValue = .FALSE.
+      CALL Agrif_Sponge
+      tabspongedone_trn = .FALSE.
+      CALL Agrif_Bc_variable(trn_sponge_id,calledweight=1.,procname=interptrn_sponge)
+      ! reset tsa to zero
+      tra(:,:,:,:) = 0._wp
+
+      ! 3. Some controls
+      !-----------------
+      check_namelist = .TRUE.
+
+      IF( check_namelist ) THEN
+         ! Check time steps
       IF( NINT(Agrif_Rhot()) * NINT(rdt) .NE. Agrif_Parent(rdt) ) THEN
          WRITE(cl_check1,*)  Agrif_Parent(rdt)
@@ -630,187 +645,177 @@
    ENDIF
    !
-END SUBROUTINE Agrif_InitValues_cont_top
-
-
-SUBROUTINE agrif_declare_var_top
+   END SUBROUTINE Agrif_InitValues_cont_top
+
+
+   SUBROUTINE agrif_declare_var_top
       !!----------------------------------------------------------------------
       !!                 *** ROUTINE agrif_declare_var_top ***
+      !!----------------------------------------------------------------------
+      USE agrif_util
+      USE agrif_oce
+      USE dom_oce
+      USE trc
       !!
-      !! ** Purpose :: Declaration of TOP variables to be interpolated
-      !!----------------------------------------------------------------------
-   USE agrif_util
-   USE agrif_oce
-   USE dom_oce
-   USE trc
-   !!
-   IMPLICIT NONE
-   !
-   INTEGER :: ind1, ind2, ind3
-      !!----------------------------------------------------------------------
-
-   ! 1. Declaration of the type of variable which have to be interpolated
-   !---------------------------------------------------------------------
-   ind1 =     nbghostcells
-   ind2 = 1 + nbghostcells
-   ind3 = 2 + nbghostcells
+      IMPLICIT NONE
+      !
+      INTEGER :: ind1, ind2, ind3
+      !!----------------------------------------------------------------------
+
+      ! 1. Declaration of the type of variable which have to be interpolated
+      !---------------------------------------------------------------------
+      ind1 =     nbghostcells
+      ind2 = 1 + nbghostcells
+      ind3 = 2 + nbghostcells
 # if defined key_vertical
-   CALL agrif_declare_variable((/2,2,0,0/),(/ind3,ind3,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,jptra+1/),trn_id)
-   CALL agrif_declare_variable((/2,2,0,0/),(/ind3,ind3,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,jptra+1/),trn_sponge_id)
+      CALL agrif_declare_variable((/2,2,0,0/),(/ind3,ind3,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,jptra+1/),trn_id)
+      CALL agrif_declare_variable((/2,2,0,0/),(/ind3,ind3,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,jptra+1/),trn_sponge_id)
 # else
-   CALL agrif_declare_variable((/2,2,0,0/),(/3,3,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,jptra/),trn_id)
-   CALL agrif_declare_variable((/2,2,0,0/),(/3,3,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,jptra/),trn_sponge_id)
-# endif
-
-   ! 2. Type of interpolation
-   !-------------------------
-   CALL Agrif_Set_bcinterp(trn_id,interp=AGRIF_linear)
-   CALL Agrif_Set_bcinterp(trn_sponge_id,interp=AGRIF_linear)
-
-   ! 3. Location of interpolation
-   !-----------------------------
-   CALL Agrif_Set_bc(trn_id,(/0,ind1/))
-   CALL Agrif_Set_bc(trn_sponge_id,(/-nn_sponge_len*Agrif_irhox()-1,0/))
-
-   ! 4. Update type
-   !--------------- 
+      CALL agrif_declare_variable((/2,2,0,0/),(/ind3,ind3,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,jptra/),trn_id)
+      CALL agrif_declare_variable((/2,2,0,0/),(/ind3,ind3,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,jptra/),trn_sponge_id)
+# endif
+
+      ! 2. Type of interpolation
+      !-------------------------
+      CALL Agrif_Set_bcinterp(trn_id,interp=AGRIF_linear)
+      CALL Agrif_Set_bcinterp(trn_sponge_id,interp=AGRIF_linear)
+
+      ! 3. Location of interpolation
+      !-----------------------------
+      CALL Agrif_Set_bc(trn_id,(/0,ind1-1/))
+      CALL Agrif_Set_bc(trn_sponge_id,(/-nn_sponge_len*Agrif_irhox()-1,0/))
+
+      ! 4. Update type
+      !--------------- 
 # if defined UPD_HIGH
-   CALL Agrif_Set_Updatetype(trn_id, update = Agrif_Update_Full_Weighting)
+      CALL Agrif_Set_Updatetype(trn_id, update = Agrif_Update_Full_Weighting)
 #else
-   CALL Agrif_Set_Updatetype(trn_id, update = AGRIF_Update_Average)
+      CALL Agrif_Set_Updatetype(trn_id, update = AGRIF_Update_Average)
 #endif
    !
-END SUBROUTINE agrif_declare_var_top
-# endif
-
-SUBROUTINE Agrif_detect( kg, ksizex )
+   END SUBROUTINE agrif_declare_var_top
+# endif
+
+   SUBROUTINE Agrif_detect( kg, ksizex )
       !!----------------------------------------------------------------------
       !!                      *** ROUTINE Agrif_detect ***
       !!----------------------------------------------------------------------
-   INTEGER, DIMENSION(2) :: ksizex
-   INTEGER, DIMENSION(ksizex(1),ksizex(2)) :: kg 
-      !!----------------------------------------------------------------------
-   !
-   RETURN
-   !
-END SUBROUTINE Agrif_detect
-
-
-SUBROUTINE agrif_nemo_init
+      INTEGER, DIMENSION(2) :: ksizex
+      INTEGER, DIMENSION(ksizex(1),ksizex(2)) :: kg 
+      !!----------------------------------------------------------------------
+      !
+      RETURN
+      !
+   END SUBROUTINE Agrif_detect
+
+   SUBROUTINE agrif_nemo_init
       !!----------------------------------------------------------------------
       !!                     *** ROUTINE agrif_init ***
       !!----------------------------------------------------------------------
-   USE agrif_oce 
-   USE agrif_ice
-   USE in_out_manager
-   USE lib_mpp
-   !!
-   IMPLICIT NONE
-   !
-   INTEGER  ::   ios                 ! Local integer output status for namelist read
-   INTEGER  ::   iminspon
-   NAMELIST/namagrif/ rn_sponge_tra, rn_sponge_dyn, ln_spc_dyn, ln_chk_bathy
+      USE agrif_oce 
+      USE agrif_ice
+      USE in_out_manager
+      USE lib_mpp
+      !!
+      IMPLICIT NONE
+      !
+      INTEGER  ::   ios                 ! Local integer output status for namelist read
+      NAMELIST/namagrif/ ln_agrif_2way, rn_sponge_tra, rn_sponge_dyn, rn_trelax_tra, rn_trelax_dyn, &
+                       & ln_spc_dyn, ln_chk_bathy
       !!--------------------------------------------------------------------------------------
-   !
-   REWIND( numnam_ref )              ! Namelist namagrif in reference namelist : AGRIF zoom
-   READ  ( numnam_ref, namagrif, IOSTAT = ios, ERR = 901)
+      !
+      REWIND( numnam_ref )              ! Namelist namagrif in reference namelist : AGRIF zoom
+      READ  ( numnam_ref, namagrif, IOSTAT = ios, ERR = 901)
 901 IF( ios /= 0 )   CALL ctl_nam ( ios , 'namagrif in reference namelist' )
-   REWIND( numnam_cfg )              ! Namelist namagrif in configuration namelist : AGRIF zoom
-   READ  ( numnam_cfg, namagrif, IOSTAT = ios, ERR = 902 )
+      REWIND( numnam_cfg )              ! Namelist namagrif in configuration namelist : AGRIF zoom
+      READ  ( numnam_cfg, namagrif, IOSTAT = ios, ERR = 902 )
 902 IF( ios >  0 )   CALL ctl_nam ( ios , 'namagrif in configuration namelist' )
-   IF(lwm) WRITE ( numond, namagrif )
-   !
-   IF(lwp) THEN                    ! control print
-      WRITE(numout,*)
-      WRITE(numout,*) 'agrif_nemo_init : AGRIF parameters'
-      WRITE(numout,*) '~~~~~~~~~~~~~~~'
-      WRITE(numout,*) '   Namelist namagrif : set AGRIF parameters'
-      WRITE(numout,*) '      sponge coefficient for tracers    rn_sponge_tra = ', rn_sponge_tra, ' s'
-      WRITE(numout,*) '      sponge coefficient for dynamics   rn_sponge_tra = ', rn_sponge_dyn, ' s'
-      WRITE(numout,*) '      use special values for dynamics   ln_spc_dyn    = ', ln_spc_dyn
-      WRITE(numout,*) '      check bathymetry                  ln_chk_bathy  = ', ln_chk_bathy
-   ENDIF
-   !
-   ! convert DOCTOR namelist name into OLD names
-   visc_tra      = rn_sponge_tra
-   visc_dyn      = rn_sponge_dyn
-   !
-   ! Check sponge length:
-   iminspon = MIN(FLOOR(REAL(jpiglo-4)/REAL(2*Agrif_irhox())), FLOOR(REAL(jpjglo-4)/REAL(2*Agrif_irhox())) )
-   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( agrif_oce_alloc()  > 0 )   CALL ctl_warn('agrif agrif_oce_alloc: allocation of arrays failed')
-   !
-END SUBROUTINE agrif_nemo_init
+      IF(lwm) WRITE ( numond, namagrif )
+      !
+      IF(lwp) THEN                    ! control print
+         WRITE(numout,*)
+         WRITE(numout,*) 'agrif_nemo_init : AGRIF parameters'
+         WRITE(numout,*) '~~~~~~~~~~~~~~~'
+         WRITE(numout,*) '   Namelist namagrif : set AGRIF parameters'
+         WRITE(numout,*) '      Two way nesting activated ln_agrif_2way         = ', ln_agrif_2way
+         WRITE(numout,*) '      sponge coefficient for tracers    rn_sponge_tra = ', rn_sponge_tra, ' m^2/s'
+         WRITE(numout,*) '      sponge coefficient for dynamics   rn_sponge_tra = ', rn_sponge_dyn, ' m^2/s'
+         WRITE(numout,*) '      time relaxation for tracers       rn_trelax_tra = ', rn_trelax_tra, ' ad.'
+         WRITE(numout,*) '      time relaxation for dynamics      rn_trelax_dyn = ', rn_trelax_dyn, ' ad.'
+         WRITE(numout,*) '      use special values for dynamics   ln_spc_dyn    = ', ln_spc_dyn
+         WRITE(numout,*) '      check bathymetry                  ln_chk_bathy  = ', ln_chk_bathy
+      ENDIF
+      !
+      !
+      IF( agrif_oce_alloc()  > 0 )   CALL ctl_warn('agrif agrif_oce_alloc: allocation of arrays failed')
+      !
+   END SUBROUTINE agrif_nemo_init
 
 # if defined key_mpp_mpi
 
-SUBROUTINE Agrif_InvLoc( indloc, nprocloc, i, indglob )
+   SUBROUTINE Agrif_InvLoc( indloc, nprocloc, i, indglob )
       !!----------------------------------------------------------------------
       !!                     *** ROUTINE Agrif_InvLoc ***
       !!----------------------------------------------------------------------
-   USE dom_oce
-   !!
-   IMPLICIT NONE
-   !
-   INTEGER :: indglob, indloc, nprocloc, i
-      !!----------------------------------------------------------------------
-   !
-   SELECT CASE( i )
-   CASE(1)   ;   indglob = indloc + nimppt(nprocloc+1) - 1
-   CASE(2)   ;   indglob = indloc + njmppt(nprocloc+1) - 1
-   CASE DEFAULT
-      indglob = indloc
-   END SELECT
-   !
-END SUBROUTINE Agrif_InvLoc
-
-
-SUBROUTINE Agrif_get_proc_info( imin, imax, jmin, jmax )
+      USE dom_oce
+      !!
+      IMPLICIT NONE
+      !
+      INTEGER :: indglob, indloc, nprocloc, i
+      !!----------------------------------------------------------------------
+      !
+      SELECT CASE( i )
+      CASE(1)   ;   indglob = indloc + nimppt(nprocloc+1) - 1
+      CASE(2)   ;   indglob = indloc + njmppt(nprocloc+1) - 1
+      CASE DEFAULT
+         indglob = indloc
+      END SELECT
+      !
+   END SUBROUTINE Agrif_InvLoc
+
+   SUBROUTINE Agrif_get_proc_info( imin, imax, jmin, jmax )
       !!----------------------------------------------------------------------
       !!                 *** ROUTINE Agrif_get_proc_info ***
       !!----------------------------------------------------------------------
-   USE par_oce
-   !!
-   IMPLICIT NONE
-   !
-   INTEGER, INTENT(out) :: imin, imax
-   INTEGER, INTENT(out) :: jmin, jmax
-      !!----------------------------------------------------------------------
-   !
-   imin = nimppt(Agrif_Procrank+1)  ! ?????
-   jmin = njmppt(Agrif_Procrank+1)  ! ?????
-   imax = imin + jpi - 1
-   jmax = jmin + jpj - 1
-   ! 
-END SUBROUTINE Agrif_get_proc_info
-
-
-SUBROUTINE Agrif_estimate_parallel_cost(imin, imax,jmin, jmax, nbprocs, grid_cost)
+      USE par_oce
+      !!
+      IMPLICIT NONE
+      !
+      INTEGER, INTENT(out) :: imin, imax
+      INTEGER, INTENT(out) :: jmin, jmax
+      !!----------------------------------------------------------------------
+      !
+      imin = nimppt(Agrif_Procrank+1)  ! ?????
+      jmin = njmppt(Agrif_Procrank+1)  ! ?????
+      imax = imin + jpi - 1
+      jmax = jmin + jpj - 1
+      ! 
+   END SUBROUTINE Agrif_get_proc_info
+
+   SUBROUTINE Agrif_estimate_parallel_cost(imin, imax,jmin, jmax, nbprocs, grid_cost)
       !!----------------------------------------------------------------------
       !!                 *** ROUTINE Agrif_estimate_parallel_cost ***
       !!----------------------------------------------------------------------
-   USE par_oce
-   !!
-   IMPLICIT NONE
-   !
-   INTEGER,  INTENT(in)  :: imin, imax
-   INTEGER,  INTENT(in)  :: jmin, jmax
-   INTEGER,  INTENT(in)  :: nbprocs
-   REAL(wp), INTENT(out) :: grid_cost
-      !!----------------------------------------------------------------------
-   !
-   grid_cost = REAL(imax-imin+1,wp)*REAL(jmax-jmin+1,wp) / REAL(nbprocs,wp)
-   !
-END SUBROUTINE Agrif_estimate_parallel_cost
+      USE par_oce
+      !!
+      IMPLICIT NONE
+      !
+      INTEGER,  INTENT(in)  :: imin, imax
+      INTEGER,  INTENT(in)  :: jmin, jmax
+      INTEGER,  INTENT(in)  :: nbprocs
+      REAL(wp), INTENT(out) :: grid_cost
+      !!----------------------------------------------------------------------
+      !
+      grid_cost = REAL(imax-imin+1,wp)*REAL(jmax-jmin+1,wp) / REAL(nbprocs,wp)
+      !
+   END SUBROUTINE Agrif_estimate_parallel_cost
 
 # endif
 
 #else
-SUBROUTINE Subcalledbyagrif
+   SUBROUTINE Subcalledbyagrif
       !!----------------------------------------------------------------------
       !!                   *** ROUTINE Subcalledbyagrif ***
       !!----------------------------------------------------------------------
-   WRITE(*,*) 'Impossible to be here'
-END SUBROUTINE Subcalledbyagrif
+      WRITE(*,*) 'Impossible to be here'
+   END SUBROUTINE Subcalledbyagrif
 #endif
Index: /NEMO/branches/2019/dev_r12072_MERGE_OPTION2_2019/src/NST/vremap.F90
===================================================================
--- /NEMO/branches/2019/dev_r12072_MERGE_OPTION2_2019/src/NST/vremap.F90	(revision 12191)
+++ /NEMO/branches/2019/dev_r12072_MERGE_OPTION2_2019/src/NST/vremap.F90	(revision 12191)
@@ -0,0 +1,397 @@
+#undef PPR_LIB      /* USE PPR library */
+MODULE vremap
+!$AGRIF_DO_NOT_TREAT
+   !!======================================================================
+   !!                       ***  MODULE  vremap  ***
+   !! Ocean physics:  Vertical remapping routines
+   !!
+   !!======================================================================
+   !! History : 4.0  !  2019-09  (Jérôme Chanut)  Original code
+   !!----------------------------------------------------------------------
+   !!----------------------------------------------------------------------
+   !!
+   !!----------------------------------------------------------------------
+   USE par_oce
+#if defined PPR_LIB
+   USE ppr_1d   ! D. Engwirda piecewise polynomial reconstruction library
+#endif
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   reconstructandremap, remap_linear
+
+   !!----------------------------------------------------------------------
+   !! NEMO/OCE 4.0 , NEMO Consortium (2018)
+   !! $Id: vremap 11573 2019-09-19 09:18:03Z jchanut $ 
+   !! Software governed by the CeCILL license (see ./LICENSE)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+#if ! defined PPR_LIB
+   SUBROUTINE reconstructandremap(ptin, phin, ptout, phout, kjpk_in, kjpk_out, kn_var)      
+      !!----------------------------------------------------------------------
+      !!                    ***  ROUTINE  reconstructandremap ***
+      !!
+      !! ** Purpose :   Brief description of the routine
+      !!
+      !! ** Method  :   description of the methodoloy used to achieve the
+      !!                objectives of the routine. Be as clear as possible!
+      !!
+      !! ** Action  : - first action (share memory array/varible modified
+      !!                in this routine
+      !!              - second action .....
+      !!              - .....
+      !!
+      !! References :   Author et al., Short_name_review, Year
+      !!                Give references if exist otherwise suppress these lines
+      !!-----------------------------------------------------------------------
+      INTEGER , INTENT(in   )                      ::   kjpk_in    ! Number of input levels
+      INTEGER , INTENT(in   )                      ::   kjpk_out   ! Number of output levels
+      INTEGER , INTENT(in   )                      ::   kn_var     ! Number of variables
+      REAL(wp), INTENT(in   ), DIMENSION(kjpk_in)  ::   phin       ! Input thicknesses
+      REAL(wp), INTENT(in   ), DIMENSION(kjpk_out) ::   phout      ! Output thicknesses
+      REAL(wp), INTENT(in   ), DIMENSION(kjpk_in , kn_var) ::   ptin       ! Input data
+      REAL(wp), INTENT(inout), DIMENSION(kjpk_out, kn_var) ::   ptout      ! Remapped data
+      !
+      INTEGER             :: jk, jn, k1, kbox, ktop, ka, kbot
+      REAL(wp), PARAMETER :: dpthin = 1.D-3, dsmll = 1.0D-8
+      REAL(wp)            :: q, q01, q02, q001, q002, q0
+      REAL(wp)            :: tsum, qbot, rpsum, zbox, ztop, zthk, zbot, offset, qtop
+      REAL(wp)            :: coeffremap(kjpk_in,3), zwork(kjpk_in,3), zwork2(kjpk_in+1,3)
+      REAL(wp)            :: z_win(1:kjpk_in+1), z_wout(1:kjpk_out+1)
+      !!-----------------------------------------------------------------------
+
+      z_win(1)=0._wp ; z_wout(1)= 0._wp
+      DO jk = 1, kjpk_in
+         z_win(jk+1)=z_win(jk)+phin(jk)
+      END DO 
+      
+      DO jk = 1, kjpk_out
+         z_wout(jk+1)=z_wout(jk)+phout(jk)       
+      END DO       
+
+      DO jk = 2, kjpk_in
+         zwork(jk,1)=1._wp/(phin(jk-1)+phin(jk))
+      END DO
+        
+      DO jk = 2, kjpk_in-1
+         q0 = 1._wp / (phin(jk-1)+phin(jk)+phin(jk+1))
+         zwork(jk,2) = phin(jk-1) + 2._wp*phin(jk) + phin(jk+1)
+         zwork(jk,3) = q0
+      END DO       
+     
+      DO jn = 1, kn_var
+
+         DO jk = 2,kjpk_in
+            zwork2(jk,1) = zwork(jk,1)*(ptin(jk,jn)-ptin(jk-1,jn))
+         END DO
+        
+         coeffremap(:,1) = ptin(:,jn)
+ 
+         DO jk = 2, kjpk_in-1
+            q001 = phin(jk)*zwork2(jk+1,1)
+            q002 = phin(jk)*zwork2(jk,1)        
+            IF (q001*q002 < 0._wp) then
+               q001 = 0._wp
+               q002 = 0._wp
+            ENDIF
+            q=zwork(jk,2)
+            q01=q*zwork2(jk+1,1)
+            q02=q*zwork2(jk,1)
+            IF (abs(q001) > abs(q02)) q001 = q02
+            IF (abs(q002) > abs(q01)) q002 = q01
+        
+            q=(q001-q002)*zwork(jk,3)
+            q001=q001-q*phin(jk+1)
+            q002=q002+q*phin(jk-1)
+        
+            coeffremap(jk,3)=coeffremap(jk,1)+q001
+            coeffremap(jk,2)=coeffremap(jk,1)-q002
+        
+            zwork2(jk,1)=(2._wp*q001-q002)**2
+            zwork2(jk,2)=(2._wp*q002-q001)**2
+         ENDDO
+        
+         DO jk = 1, kjpk_in
+            IF(jk.EQ.1 .OR. jk.EQ.kjpk_in .OR. phin(jk).LE.dpthin) THEN
+               coeffremap(jk,3) = coeffremap(jk,1)
+               coeffremap(jk,2) = coeffremap(jk,1)
+               zwork2(jk,1) = 0._wp
+               zwork2(jk,2) = 0._wp
+            ENDIF
+         END DO
+        
+         DO jk = 2, kjpk_in
+            q002 = max(zwork2(jk-1,2),dsmll)
+            q001 = max(zwork2(jk,1)  ,dsmll)
+            zwork2(jk,3) = (q001*coeffremap(jk-1,3)+q002*coeffremap(jk,2))/(q001+q002)
+         END DO
+        
+         zwork2(1,3) = 2._wp*coeffremap(1,1)-zwork2(2,3)
+         zwork2(kjpk_in+1,3)=2._wp*coeffremap(kjpk_in,1)-zwork2(kjpk_in,3)
+ 
+         DO jk = 1, kjpk_in
+            q01=zwork2(jk+1,3)-coeffremap(jk,1)
+            q02=coeffremap(jk,1)-zwork2(jk,3)
+            q001=2._wp*q01
+            q002=2._wp*q02
+            IF (q01*q02<0._wp) then
+               q01=0._wp
+               q02=0._wp
+            ELSEIF (abs(q01)>abs(q002)) then
+               q01=q002
+            ELSEIF (abs(q02)>abs(q001)) then
+               q02=q001
+            ENDIF
+            coeffremap(jk,2)=coeffremap(jk,1)-q02
+            coeffremap(jk,3)=coeffremap(jk,1)+q01
+         ENDDO
+
+         zbot=0._wp
+         kbot=1
+         DO jk=1,kjpk_out
+            ztop=zbot  !top is bottom of previous layer
+            ktop=kbot
+            IF     (ztop.GE.z_win(ktop+1)) then
+               ktop=ktop+1
+            ENDIF
+        
+            zbot=z_wout(jk+1)
+            zthk=zbot-ztop
+
+            IF(zthk.GT.dpthin .AND. ztop.LT.z_wout(kjpk_out+1)) THEN
+ 
+               kbot=ktop
+               DO while (z_win(kbot+1).lt.zbot.and.kbot.lt.kjpk_in)
+                  kbot=kbot+1
+               ENDDO
+               zbox=zbot
+               DO k1= jk+1,kjpk_out
+                  IF     (z_wout(k1+1)-z_wout(k1).GT.dpthin) THEN
+                     exit !thick layer
+                  ELSE
+                     zbox=z_wout(k1+1)  !include thin adjacent layers
+                     IF(zbox.EQ.z_wout(kjpk_out+1)) THEN
+                        exit !at bottom
+                     ENDIF
+                  ENDIF
+               ENDDO
+               zthk=zbox-ztop
+
+               kbox=ktop
+               DO while (z_win(kbox+1).lt.zbox.and.kbox.lt.kjpk_in)
+                  kbox=kbox+1
+               ENDDO
+          
+               IF(ktop.EQ.kbox) THEN
+                  IF(z_wout(jk).NE.z_win(kbox).OR.z_wout(jk+1).NE.z_win(kbox+1)) THEN
+                     IF(phin(kbox).GT.dpthin) THEN
+                        q001 = (zbox-z_win(kbox))/phin(kbox)
+                        q002 = (ztop-z_win(kbox))/phin(kbox)
+                        q01=q001**2+q002**2+q001*q002+1._wp-2._wp*(q001+q002)
+                        q02=q01-1._wp+(q001+q002)
+                        q0=1._wp-q01-q02
+                     ELSE
+                        q0  = 1._wp
+                        q01 = 0._wp
+                        q02 = 0._wp
+                     ENDIF
+                     ptout(jk,jn)=q0*coeffremap(kbox,1)+q01*coeffremap(kbox,2)+q02*coeffremap(kbox,3)
+                  ELSE
+                     ptout(jk,jn) = ptin(kbox,jn)
+                  ENDIF 
+               ELSE
+                  IF(ktop.LE.jk .AND. kbox.GE.jk) THEN
+                     ka = jk
+                  ELSEIF (kbox-ktop.GE.3) THEN
+                     ka = (kbox+ktop)/2
+                  ELSEIF (phin(ktop).GE.phin(kbox)) THEN
+                     ka = ktop
+                  ELSE
+                     ka = kbox
+                  ENDIF !choose ka
+    
+                  offset=coeffremap(ka,1)
+    
+                  qtop = z_win(ktop+1)-ztop !partial layer thickness
+                  IF(phin(ktop).GT.dpthin) THEN
+                     q=(ztop-z_win(ktop))/phin(ktop)
+                     q01=q*(q-1._wp)
+                     q02=q01+q
+                     q0=1._wp-q01-q02            
+                  ELSE
+                     q0  = 1._wp
+                     q01 = 0._wp
+                     q02 = 0._wp
+                  ENDIF
+               
+                  tsum =((q0*coeffremap(ktop,1)+q01*coeffremap(ktop,2)+q02*coeffremap(ktop,3))-offset)*qtop
+    
+                  DO k1= ktop+1,kbox-1
+                     tsum =tsum +(coeffremap(k1,1)-offset)*phin(k1)
+                  ENDDO !k1
+               
+                  qbot = zbox-z_win(kbox) !partial layer thickness
+                  IF(phin(kbox).GT.dpthin) THEN
+                     q=qbot/phin(kbox)
+                     q01=(q-1._wp)**2
+                     q02=q01-1._wp+q
+                     q0=1_wp-q01-q02                            
+                  ELSE
+                     q0  = 1._wp
+                     q01 = 0._wp
+                     q02 = 0._wp
+                  ENDIF
+              
+                  tsum = tsum +((q0*coeffremap(kbox,1)+q01*coeffremap(kbox,2)+q02*coeffremap(kbox,3))-offset)*qbot
+               
+                  rpsum=1._wp / zthk
+                  ptout(jk,jn)=offset+tsum*rpsum
+                 
+               ENDIF !single or multiple layers
+            ELSE
+               IF (jk==1) THEN
+                  write(*,'(a7,i4,i4,3f12.5)')'problem = ',kjpk_in,kjpk_out,zthk,z_wout(jk+1),phout(1)
+               ENDIF
+               ptout(jk,jn) = ptout(jk-1,jn)
+             
+            ENDIF !normal:thin layer
+         ENDDO !jk
+
+      END DO ! loop over variables
+            
+   END SUBROUTINE reconstructandremap
+
+#else
+
+   SUBROUTINE reconstructandremap(ptin, phin, ptout, phout, kjpk_in, kjpk_out, kn_var)
+      !!----------------------------------------------------------------------
+      !!                    *** ROUTINE  reconstructandremap ***
+      !!
+      !! ** Purpose :   Conservative remapping of a vertical column 
+      !!                from one set of layers to an other one.
+      !!
+      !! ** Method  :   Uses D. Engwirda Piecewise Polynomial Reconstruction library.
+      !!                https://github.com/dengwirda/PPR
+      !!                
+      !!
+      !! References :   Engwirda, Darren & Kelley, Maxwell. (2015). A WENO-type 
+      !!                slope-limiter for a family of piecewise polynomial methods. 
+      !!                https://arxiv.org/abs/1606.08188
+      !!-----------------------------------------------------------------------
+      INTEGER , INTENT(in   )                      ::   kjpk_in    ! Number of input levels
+      INTEGER , INTENT(in   )                      ::   kjpk_out   ! Number of output levels
+      INTEGER , INTENT(in   )                      ::   kn_var     ! Number of variables
+      REAL(wp), INTENT(in   ), DIMENSION(kjpk_in)  ::   phin       ! Input thicknesses
+      REAL(wp), INTENT(in   ), DIMENSION(kjpk_out) ::   phout      ! Output thicknesses
+      REAL(wp), INTENT(in   ), DIMENSION(kjpk_in , kn_var) ::   ptin       ! Input data
+      REAL(wp), INTENT(inout), DIMENSION(kjpk_out, kn_var) ::   ptout      ! Remapped data
+      !
+      INTEGER, PARAMETER :: ndof = 1
+      INTEGER  :: jk, jn
+      REAL(wp) ::  zwin(kjpk_in+1) ,  ztin(ndof, kn_var, kjpk_in)
+      REAL(wp) :: zwout(kjpk_out+1), ztout(ndof, kn_var, kjpk_out)
+      TYPE(rmap_work) :: work
+      TYPE(rmap_opts) :: opts
+      TYPE(rcon_ends) :: bc_l(kn_var)
+      TYPE(rcon_ends) :: bc_r(kn_var)
+      !!--------------------------------------------------------------------
+     
+      ! Set interfaces and input data:
+      zwin(1) = 0._wp
+      DO jk = 2, kjpk_in + 1
+         zwin(jk) = zwin(jk-1) + phin(jk-1) 
+      END DO
+      
+      DO jn = 1, kn_var 
+         DO jk = 1, kjpk_in
+            ztin(ndof, jn, jk) =  ptin(jk, jn)
+         END DO
+      END DO
+
+      zwout(1) = 0._wp
+      DO jk = 2, kjpk_out + 1
+         zwout(jk) = zwout(jk-1) + phout(jk-1) 
+      END DO
+
+      ! specify methods
+!      opts%edge_meth = p1e_method     ! 1st-order edge interp.
+!      opts%cell_meth = plm_method     ! PLM method in cells
+      opts%edge_meth = p3e_method     ! 3rd-order edge interp.
+      opts%cell_meth = ppm_method     ! PPM method in cells    
+!      opts%edge_meth = p5e_method     ! 5th-order edge interp.
+!      opts%cell_meth = pqm_method     ! PQM method in cells
+
+      ! limiter
+!      opts%cell_lims = null_limit     ! no lim.
+      opts%cell_lims = mono_limit     ! monotone limiter   
+ 
+      ! set boundary conditions
+      bc_l%bcopt = bcon_loose         ! "loose" = extrapolate
+      bc_r%bcopt = bcon_loose
+!      bc_l%bcopt = bcon_slope        
+!      bc_r%bcopt = bcon_slope
+
+      ! init. method workspace
+      CALL work%init(kjpk_in+1, kn_var, opts)
+
+      ! remap
+      CALL rmap1d(kjpk_in+1, kjpk_out+1, kn_var, ndof, &
+      &           zwin, zwout, ztin, ztout,            &
+      &           bc_l, bc_r, work, opts)
+
+      ! clear method workspace
+      CALL work%free()
+
+      DO jn = 1, kn_var 
+         DO jk = 1, kjpk_out
+            ptout(jk, jn) = ztout(1, jn, jk)
+         END DO
+      END DO
+            
+   END SUBROUTINE reconstructandremap
+#endif
+
+   SUBROUTINE remap_linear(ptin, pzin, ptout, pzout, kjpk_in, kjpk_out, kn_var)
+      !!----------------------------------------------------------------------
+      !!                    *** ROUTINE  remap_linear ***
+      !!
+      !! ** Purpose :   Linear interpolation based on input/ouputs depths
+      !!
+      !!-----------------------------------------------------------------------
+      INTEGER , INTENT(in   )                      ::   kjpk_in    ! Number of input levels
+      INTEGER , INTENT(in   )                      ::   kjpk_out   ! Number of output levels
+      INTEGER , INTENT(in   )                      ::   kn_var     ! Number of variables
+      REAL(wp), INTENT(in   ), DIMENSION(kjpk_in)  ::   pzin       ! Input depths
+      REAL(wp), INTENT(in   ), DIMENSION(kjpk_out) ::   pzout      ! Output depths
+      REAL(wp), INTENT(in   ), DIMENSION(kjpk_in , kn_var) ::   ptin       ! Input data
+      REAL(wp), INTENT(inout), DIMENSION(kjpk_out, kn_var) ::   ptout      ! Interpolated data
+      !
+      INTEGER  :: jkin, jkout, jn
+      !!--------------------------------------------------------------------
+      !      
+      DO jkout = 1, kjpk_out !  Loop over destination grid
+         !
+         IF     ( pzout(jkout) <=  pzin(  1    ) ) THEN 	; ptout(jkout,1:kn_var) = ptin(    1    ,1:kn_var)         
+         ELSEIF ( pzout(jkout) >= pzin(kjpk_in) ) THEN 	; ptout(jkout,1:kn_var) = ptin( kjpk_in ,1:kn_var)
+         ELSEIF ( ( pzout(jkout) > pzin(1) ).AND.( pzout(jkout) < pzin(kjpk_in) )) THEN
+            DO jkin = 1, kjpk_in - 1 !  Loop over source grid
+               IF ( pzout(jkout) < pzin(jkin+1) ) THEN
+                  DO jn = 1, kn_var
+                     ptout(jkout,jn) =  ptin(jkin,jn) + &
+                                     & (pzout(jkout) - pzin(jkin)) / (pzin(jkin+1)    - pzin(jkin)) &
+                                     &                             * (ptin(jkin+1,jn) - ptin(jkin,jn))
+                  END DO  
+                  EXIT
+               ENDIF  
+            END DO
+         ENDIF
+         !
+      END DO
+
+   END SUBROUTINE remap_linear
+
+   !!======================================================================
+!$AGRIF_END_DO_NOT_TREAT
+END MODULE vremap
Index: /NEMO/branches/2019/dev_r12072_MERGE_OPTION2_2019/src/OCE/DYN/dynspg_ts.F90
===================================================================
--- /NEMO/branches/2019/dev_r12072_MERGE_OPTION2_2019/src/OCE/DYN/dynspg_ts.F90	(revision 12190)
+++ /NEMO/branches/2019/dev_r12072_MERGE_OPTION2_2019/src/OCE/DYN/dynspg_ts.F90	(revision 12191)
@@ -505,5 +505,5 @@
          !                             ! values of zhup2_e and zhvp2_e on the halo are not needed in bdy_vol2d
          IF( ln_bdy .AND. ln_vol ) CALL bdy_vol2d( kt, jn, ua_e, va_e, zhup2_e, zhvp2_e )
-         !
+         !      
          !                             ! resulting flux at mid-step (not over the full domain)
          zhU(1:jpim1,1:jpj  ) = e2u(1:jpim1,1:jpj  ) * ua_e(1:jpim1,1:jpj  ) * zhup2_e(1:jpim1,1:jpj  )   ! not jpi-column
@@ -512,30 +512,5 @@
 #if defined key_agrif
          ! Set fluxes during predictor step to ensure volume conservation
-         IF( .NOT.Agrif_Root() .AND. ln_bt_fw ) THEN
-            IF((nbondi == -1).OR.(nbondi == 2)) THEN
-               DO jj = 1, jpj
-                  zhU(2:nbghostcells+1,jj) = ubdy_w(1:nbghostcells,jj) * e2u(2:nbghostcells+1,jj)
-                  zhV(2:nbghostcells+1,jj) = vbdy_w(1:nbghostcells,jj) * e1v(2:nbghostcells+1,jj)
-               END DO
-            ENDIF
-            IF((nbondi ==  1).OR.(nbondi == 2)) THEN
-               DO jj=1,jpj
-                  zhU(nlci-nbghostcells-1:nlci-2,jj) = ubdy_e(1:nbghostcells,jj) * e2u(nlci-nbghostcells-1:nlci-2,jj)
-                  zhV(nlci-nbghostcells  :nlci-1,jj) = vbdy_e(1:nbghostcells,jj) * e1v(nlci-nbghostcells  :nlci-1,jj)
-               END DO
-            ENDIF
-            IF((nbondj == -1).OR.(nbondj == 2)) THEN
-               DO ji=1,jpi
-                  zhV(ji,2:nbghostcells+1) = vbdy_s(ji,1:nbghostcells) * e1v(ji,2:nbghostcells+1)
-                  zhU(ji,2:nbghostcells+1) = ubdy_s(ji,1:nbghostcells) * e2u(ji,2:nbghostcells+1)
-               END DO
-            ENDIF
-            IF((nbondj ==  1).OR.(nbondj == 2)) THEN
-               DO ji=1,jpi
-                  zhV(ji,nlcj-nbghostcells-1:nlcj-2) = vbdy_n(ji,1:nbghostcells) * e1v(ji,nlcj-nbghostcells-1:nlcj-2)
-                  zhU(ji,nlcj-nbghostcells  :nlcj-1) = ubdy_n(ji,1:nbghostcells) * e2u(ji,nlcj-nbghostcells  :nlcj-1)
-               END DO
-            ENDIF
-         ENDIF
+         IF( .NOT.Agrif_Root() .AND. ln_bt_fw ) CALL agrif_dyn_ts_flux( jn, zhU, zhV )
 #endif
          IF( ln_wd_il )   CALL wad_lmt_bt(zhU, zhV, sshn_e, zssh_frc, rdtbt)    !!gm wad_lmt_bt use of lbc_lnk on zhU, zhV
