Index: NEMO/branches/2019/dev_r11233_AGRIF-05_jchanut_vert_coord_interp/src/NST/agrif_oce_interp.F90
===================================================================
--- NEMO/branches/2019/dev_r11233_AGRIF-05_jchanut_vert_coord_interp/src/NST/agrif_oce_interp.F90	(revision 11799)
+++ NEMO/branches/2019/dev_r11233_AGRIF-05_jchanut_vert_coord_interp/src/NST/agrif_oce_interp.F90	(revision 11802)
@@ -719,4 +719,5 @@
                tsa(ji,jj,:,:) = 0._wp
                N_in = mbkt_parent(ji,jj)
+               IF ( tmask(ji,jj,1) == 0._wp) N_in = 0
                zhtot = 0._wp
                DO jk=1,N_in !k2 = jpk of parent grid
@@ -833,4 +834,5 @@
                N_in = mbku_parent(ji,jj)
                zhtot = 0._wp
+               IF ( umask(ji,jj,1) == 0._wp) N_in = 0
                DO jk=1,N_in
                   IF (jk==N_in) THEN
@@ -928,4 +930,5 @@
                va(ji,jj,:) = 0._wp
                N_in = mbkv_parent(ji,jj)
+               IF ( vmask(ji,jj,1) == 0._wp) N_in = 0
                zhtot = 0._wp
                DO jk=1,N_in
@@ -1276,7 +1279,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
       !!----------------------------------------------------------------------  
       !      
@@ -1289,33 +1294,57 @@
            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)
+         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 = 0
-               DO jk=1,jpk ! jpk of child grid
-                  IF (wmask(ji,jj,jk) == 0) EXIT 
+	       z_out(1) = 0._wp	
+               DO jk = 2, jpk       ! Child vertical grid
+                  IF (tmask(ji,jj,jk) == 0._wp) EXIT 
                   N_out = N_out + 1
-                  h_out(jk) = e3t_n(ji,jj,jk)
+                  z_out(jk) = z_out(jk-1) + e3t_n(ji,jj,jk-1)
                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,1)
+               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
Index: NEMO/branches/2019/dev_r11233_AGRIF-05_jchanut_vert_coord_interp/src/NST/agrif_oce_sponge.F90
===================================================================
--- NEMO/branches/2019/dev_r11233_AGRIF-05_jchanut_vert_coord_interp/src/NST/agrif_oce_sponge.F90	(revision 11799)
+++ NEMO/branches/2019/dev_r11233_AGRIF-05_jchanut_vert_coord_interp/src/NST/agrif_oce_sponge.F90	(revision 11802)
@@ -289,4 +289,31 @@
          spongedoneU = .TRUE.
       ENDIF
+
+#if defined key_vertical
+      ! Trick to vertical remove interpolation in sponge layer in case of 2DV domains:
+      DO jj = 2, jpjm1
+         DO ji = 2, jpim1
+            IF ((fspu(ji-1,jj)==0._wp).AND.(fspu(ji,jj)==0._wp)) mbkt_parent(ji,jj) = 0
+            IF ((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)) mbku_parent(ji,jj) = 0
+            IF ((fspt(ji,jj+1)==0._wp).AND.(fspt(ji,jj)==0._wp)) mbkv_parent(ji,jj) = 0
+!
+            IF ((fspf(ji,jj-1)==0._wp).AND.(fspf(ji,jj)==0._wp)) mbku_parent(ji,jj) = 0
+            IF ((fspf(ji-1,jj)==0._wp).AND.(fspf(ji,jj)==0._wp)) mbkv_parent(ji,jj) = 0
+!
+            IF (mbkt(ji,jj) == 0) mbkt_parent(ji,jj) = 0
+            IF (mbku(ji,jj) == 0) mbku_parent(ji,jj) = 0
+            IF (mbkv(ji,jj) == 0) mbkv_parent(ji,jj) = 0
+         END DO
+      END DO
+      !
+      ztabramp(:,:) = REAL( mbkt_parent(:,:), wp )   ;   CALL lbc_lnk( 'Agrif_Sponge', ztabramp, 'T', 1. )
+      mbkt_parent(:,:) = MAX( NINT( ztabramp(:,:) ), 1 )
+      ztabramp(:,:) = REAL( mbku_parent(:,:), wp )   ;   CALL lbc_lnk( 'Agrif_Sponge', ztabramp, 'U', 1. )
+      mbku_parent(:,:) = MAX( NINT( ztabramp(:,:) ), 1 )
+      ztabramp(:,:) = REAL( mbkv_parent(:,:), wp )   ;   CALL lbc_lnk( 'Agrif_Sponge', ztabramp, 'V', 1. )
+      mbkv_parent(:,:) = MAX( NINT( ztabramp(:,:) ), 1 )
+#endif
       !
 #endif
@@ -366,4 +393,5 @@
                tabres_child(ji,jj,:,:) = 0._wp 
                N_in = mbkt_parent(ji,jj)
+!               IF (( tmask(ji,jj,1) == 0._wp ).OR.(fspt(ji,jj)==0._wp)) N_in = 0
                zhtot = 0._wp
                DO jk=1,N_in !k2 = jpk of parent grid
@@ -530,4 +558,5 @@
                tabres_child(ji,jj,:) = 0._wp
                N_in = mbku_parent(ji,jj)
+!               IF (( umask(ji,jj,1) == 0._wp ).OR.(fspu(ji,jj)==0._wp)) N_in = 0
                zhtot = 0._wp
                DO jk=1,N_in
@@ -706,4 +735,5 @@
                tabres_child(ji,jj,:) = 0._wp
                N_in = mbkv_parent(ji,jj)
+!               IF (( vmask(ji,jj,1) == 0._wp ).OR.(fspv(ji,jj)==0._wp)) N_in = 0
                zhtot = 0._wp
                DO jk=1,N_in
Index: NEMO/branches/2019/dev_r11233_AGRIF-05_jchanut_vert_coord_interp/src/NST/agrif_oce_update.F90
===================================================================
--- NEMO/branches/2019/dev_r11233_AGRIF-05_jchanut_vert_coord_interp/src/NST/agrif_oce_update.F90	(revision 11799)
+++ NEMO/branches/2019/dev_r11233_AGRIF-05_jchanut_vert_coord_interp/src/NST/agrif_oce_update.F90	(revision 11802)
@@ -49,6 +49,6 @@
       IF (lwp.AND.lk_agrif_debug) Write(*,*) 'Update tracers  from grid Number',Agrif_Fixed()
 
-! jc_alt      Agrif_UseSpecialValueInUpdate = .FALSE.
-      Agrif_UseSpecialValueInUpdate = .TRUE.
+      Agrif_UseSpecialValueInUpdate = .FALSE.
+! jc_alt      Agrif_UseSpecialValueInUpdate = .TRUE.
       Agrif_SpecialValueFineGrid    = 0._wp
       ! 
@@ -300,7 +300,8 @@
                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._wp) * 999._wp
-!jc_alt                     tabres(ji,jj,jk,jn) = tsn(ji,jj,jk,jn) * e3t_n(ji,jj,jk)
+!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
@@ -310,7 +311,8 @@
             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._wp) * 999._wp
-! jc_alt                  tabres(ji,jj,jk,n2) = tmask(ji,jj,jk) * e3t_n(ji,jj,jk)
+!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
@@ -323,6 +325,7 @@
                N_in = 0
                DO jk=k1,k2 !k2 = jpk of child grid
-                  IF (tabres(ji,jj,jk,n2) < -900._wp  ) EXIT
-! jc_alt                  IF (tabres(ji,jj,jk,n2) == 0._wp  ) 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)
@@ -476,14 +479,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._wp)*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)  
-                  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
-! jc_alt                  tabres(ji,jj,jk,2) = zrhoy * umask(ji,jj,jk) * e2u(ji,jj) * e3u_n(ji,jj,jk)
+!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
@@ -498,6 +504,7 @@
                tabin(:) = 0._wp
                DO jk=k1,k2 !k2=jpk of child grid
-                  IF( tabres(ji,jj,jk,2) < -900._wp) EXIT
-! jc_alt                  IF( tabres(ji,jj,jk,2) == 0.) 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)
@@ -512,5 +519,5 @@
                IF (N_in * N_out > 0) THEN
                   h_diff = sum(h_out(1:N_out))-sum(h_in(1:N_in))
-                  excess  = 0._wp
+                  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. 
@@ -674,14 +681,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._wp) * 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) 
-                  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
-! jc_alt                  tabres(ji,jj,jk,2) = zrhox * e1v(ji,jj) * e3v_n(ji,jj,jk) * vmask(ji,jj,jk)
+!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
@@ -694,6 +704,7 @@
                N_in = 0
                DO jk=k1,k2
-                  IF (tabres(ji,jj,jk,2) < -900._wp) EXIT
-! jc_alt                  IF (tabres(ji,jj,jk,2) == 0) 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)
Index: NEMO/branches/2019/dev_r11233_AGRIF-05_jchanut_vert_coord_interp/src/NST/vremap.F90
===================================================================
--- NEMO/branches/2019/dev_r11233_AGRIF-05_jchanut_vert_coord_interp/src/NST/vremap.F90	(revision 11799)
+++ NEMO/branches/2019/dev_r11233_AGRIF-05_jchanut_vert_coord_interp/src/NST/vremap.F90	(revision 11802)
@@ -20,5 +20,5 @@
    PRIVATE
 
-   PUBLIC   reconstructandremap
+   PUBLIC   reconstructandremap, remap_linear
 
    !!----------------------------------------------------------------------
@@ -354,4 +354,43 @@
 #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) ) 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
