Index: branches/2017/dev_r8126_UKMO_AGRIF_vert_interp/NEMOGCM/NEMO/NST_SRC/agrif_opa_interp.F90
===================================================================
--- branches/2017/dev_r8126_UKMO_AGRIF_vert_interp/NEMOGCM/NEMO/NST_SRC/agrif_opa_interp.F90	(revision 8595)
+++ branches/2017/dev_r8126_UKMO_AGRIF_vert_interp/NEMOGCM/NEMO/NST_SRC/agrif_opa_interp.F90	(revision 8596)
@@ -617,25 +617,32 @@
 
       zrhoxy = Agrif_rhox()*Agrif_rhoy()
+
       IF (before) THEN         
-         DO jn = n1,n2-1
+            IF(Agrif_UseSpecialValue) THEN 
+               Agrif_SpecialValue = -999._wp
+            ELSE
+               Agrif_SpecialValue = 0._wp
+            ENDIF
+            DO jn = n1,n2-1
+               DO jk=k1,k2
+                  DO jj=j1,j2
+                     DO ji=i1,i2
+                        ptab(ji,jj,jk,jn) = tsn(ji,jj,jk,jn) * e1e2t(ji,jj) * e3t_n(ji,jj,jk) * tmask(ji,jj,jk) - &
+                                          & (tmask(ji,jj,jk)-1) * Agrif_SpecialValue
+                     END DO
+                  END DO
+               END DO
+            END DO
             DO jk=k1,k2
                DO jj=j1,j2
                   DO ji=i1,i2
-                     ptab(ji,jj,jk,jn) = tsn(ji,jj,jk,jn) * e1e2t(ji,jj) * e3t_n(ji,jj,jk)
+                     ptab(ji,jj,jk,n2) = tmask(ji,jj,jk) * e1e2t(ji,jj) * e3t_n(ji,jj,jk) 
                   END DO
                END DO
             END DO
-         END DO
-         DO jk=k1,k2
-            DO jj=j1,j2
-               DO ji=i1,i2
-                  ptab(ji,jj,jk,n2) = tmask(ji,jj,jk) * e1e2t(ji,jj) * e3t_n(ji,jj,jk) 
-               END DO
-            END DO
-         END DO
-
       ELSE 
+         Agrif_SpecialValue = 0._wp !reset now interpolation is done
 ! VERTICAL REFINEMENT BEGIN
-
+#ifdef key_vertical         
          ptab_child(:,:,:,:) = 0.
          do jj=j1,j2
@@ -677,4 +684,18 @@
          enddo
          enddo
+#else
+         do jk=k1,k2
+            do jj=j1,j2
+               do ji=i1,i2
+                 ! This will be slow - Is there a way to speed it up and avoid divide by zero?
+                 IF (ptab(ji,jj,jk,n2) .NE. 0) THEN
+                    ptab_child(ji,jj,jk,n1:n2-1) = ptab(ji,jj,jk,n1:n2-1)/ptab(ji,jj,jk,n2)
+                 ELSE
+                    ptab_child(ji,jj,jk,n1:n2-1) = 0._wp
+                 ENDIF
+               enddo
+            enddo
+         enddo
+#endif
    
 
@@ -840,5 +861,5 @@
 
 
-   SUBROUTINE interpun( ptab, i1, i2, j1, j2, k1, k2, before )
+   SUBROUTINE interpun( ptab, i1, i2, j1, j2, k1, k2, m1, m2, before, nb, ndir )
       !!----------------------------------------------------------------------
       !!   *** ROUTINE interpun ***
@@ -891,4 +912,6 @@
 
          ptab_child(:,:,:) = 0.
+#ifdef key_vertical
+! VERTICAL REFINEMENT BEGIN
          DO jj=j1,j2
             DO ji=i1,i2
@@ -938,11 +961,16 @@
 ! remove division of ua by fs e3u (already done) and also zrhoy and e2u
 ! VERTICAL REFINEMENT END
-
          DO jk = 1, jpkm1
             DO jj=j1,j2
                ua(i1:i2,jj,jk) = ptab_child(i1:i2,jj,jk)
-!/(zrhoy*e2u(i1:i2,jj)))
-            END DO
-         END DO
+            END DO
+         END DO
+#else
+         DO jk = 1, jpkm1
+            DO jj=j1,j2
+               ua(i1:i2,jj,jk) = umask(i1:i2,jj,jk) * ptab(i1:i2,jj,jk,1) / ( zrhoy * e2u(i1:i2,jj) * e3u_n(i1:i2,jj,jk) )
+            END DO
+         END DO
+#endif
       ENDIF
       ! 
@@ -950,5 +978,5 @@
 
 
-   SUBROUTINE interpvn( ptab, i1, i2, j1, j2, k1, k2, before )
+   SUBROUTINE interpvn( ptab, i1, i2, j1, j2, k1, k2, m1, m2, before, nb, ndir )
       !!----------------------------------------------------------------------
       !!   *** ROUTINE interpvn ***
@@ -991,10 +1019,10 @@
          END DO
       ELSE        
+         Agrif_SpecialValue = 0._wp !Reset special value to zero now interpolation is done
+         ptab_child(:,:,:) = 0.
+#ifdef key_vertical
 ! VERTICAL REFINEMENT BEGIN
-         ptab_child(:,:,:) = 0.
          southern_side = (nb == 2).AND.(ndir == 1)
          northern_side = (nb == 2).AND.(ndir == 2)
-
-         Agrif_SpecialValue = 0._wp !Reset special value to zero now interpolation is done
 
          do jj=j1,j2
@@ -1041,10 +1069,16 @@
 ! in the following
 ! remove division of va by fs e3v, zrhox and e1v (already done)
+            DO jk=1,jpkm1
+               DO jj=j1,j2
+                  va(i1:i2,jj,jk) = ptab_child(i1:i2,jj,jk)
+               END DO
+            END DO
 ! VERTICAL REFINEMENT END
-         DO jk=1,jpkm1
-            DO jj=j1,j2
-               va(i1:i2,jj,jk) = ptab_child(i1:i2,jj,jk)
-            END DO
-         END DO
+#else 
+            DO jk=1,jpkm1
+               va(i1:i2,j1:j2,jk) = vmask(i1:i2,j1:j2,jk) * ptab(i1:i2,j1:j2,jk,1) / &
+                                    & ( zrhox * e1v(i1:i2,j1:j2) * e3v_n(i1:i2,j1:j2,jk) )
+            END DO
+#endif 
       ENDIF
       !        
Index: branches/2017/dev_r8126_UKMO_AGRIF_vert_interp/NEMOGCM/NEMO/NST_SRC/agrif_opa_update.F90
===================================================================
--- branches/2017/dev_r8126_UKMO_AGRIF_vert_interp/NEMOGCM/NEMO/NST_SRC/agrif_opa_update.F90	(revision 8595)
+++ branches/2017/dev_r8126_UKMO_AGRIF_vert_interp/NEMOGCM/NEMO/NST_SRC/agrif_opa_update.F90	(revision 8596)
@@ -199,26 +199,37 @@
       !
       IF (before) THEN
-         zrho_xy = Agrif_rhox() * Agrif_rhoy() 
-         DO jn = n1,n2-1
+# if defined key_vertical
+            zrho_xy = Agrif_rhox() * Agrif_rhoy() 
+            DO jn = n1,n2-1
+               DO jk=k1,k2
+                  DO jj=j1,j2
+                     DO ji=i1,i2
+                        tabres(ji,jj,jk,jn) = zrho_xy * tsn(ji,jj,jk,jn) * e1e2t(ji,jj) * e3t_n(ji,jj,jk)
+                     END DO
+                  END DO
+               END DO
+            END DO
             DO jk=k1,k2
                DO jj=j1,j2
                   DO ji=i1,i2
-                     tabres(ji,jj,jk,jn) = zrho_xy * tsn(ji,jj,jk,jn) * e1e2t(ji,jj) * e3t_n(ji,jj,jk)
+                     tabres(ji,jj,jk,n2) = tmask(ji,jj,jk) * zrho_xy * e1e2t(ji,jj) * e3t_n(ji,jj,jk) 
                   END DO
                END DO
             END DO
-         END DO
-         DO jk=k1,k2
-            DO jj=j1,j2
-               DO ji=i1,i2
-                  tabres(ji,jj,jk,n2) = tmask(ji,jj,jk) * zrho_xy * e1e2t(ji,jj) * e3t_n(ji,jj,jk) 
-               END DO
-            END DO
-         END DO
-         
+#else
+            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)
+                     END DO
+                  END DO
+               END DO
+            END DO        
+#endif
       ELSE
 ! VERTICAL REFINEMENT BEGIN
          tabres_child(:,:,:,:) = 0.
-
+# if defined key_vertical
          DO jj=j1,j2
          DO ji=i1,i2
@@ -243,8 +254,7 @@
 !               h_in(N_in) = h_diff
 !               tabin(N_in,:) = tabin(N_in-1,:)
-             IF (h_diff < 0) THEN
+             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 *,'Nval = ',N_out,mbathy(ji,jj)
-             print *,'BATHY = ',gdepw_0(ji,jj,mbathy(ji,jj)+1),sum(e3t_0(ji,jj,1:mbathy(ji,jj)))
+             print *, tabres(ji,j1:j2,1,n2)
              STOP
 !               N_out = N_out + 1
@@ -257,4 +267,7 @@
          ENDDO
          ENDDO
+#else
+            tabres_child(:,:,:,:) = tabres(:,:,:,1:jpts)
+#endif
          
 ! WARNING :
@@ -317,4 +330,5 @@
       IF( before ) THEN
          zrhoy = Agrif_Rhoy()
+# if defined key_vertical
          DO jk=k1,k2
             DO jj=j1,j2
@@ -325,8 +339,13 @@
             END DO
          END DO
-      ELSE
+#else
+            DO jk = k1,k2
+               tabres(i1:i2,j1:j2,jk,1) = zrhoy * e2u(i1:i2,j1:j2) * e3u_n(i1:i2,j1:j2,jk) * un(i1:i2,j1:j2,jk)
+            END DO
+#endif
+      ELSE
+         tabres_child(:,:,:) = 0.
+# if defined key_vertical
 ! VERTICAL REFINEMENT BEGIN
-         tabres_child(:,:,:) = 0.
-         
          DO jj=j1,j2
          DO ji=i1,i2
@@ -347,5 +366,5 @@
              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 < 0.) then
+             if (h_diff < -1.e-4) then
              print *,'CHECK YOUR BATHY ...'
              stop
@@ -359,4 +378,13 @@
          ENDDO
          ENDDO
+#else
+            DO jk=1,jpk
+               DO jj=j1,j2
+                  DO ji=i1,i2
+                     tabres_child(:,:,:) = tabres(:,:,:,1)* r1_e2u(ji,jj) / e3u_n(ji,jj,jk)
+                  END DO
+               END DO
+            END DO
+#endif
          
 ! WARNING :
@@ -408,4 +436,5 @@
       IF (before) THEN
          zrhox = Agrif_Rhox()
+#if defined key_vertical
          DO jk=k1,k2
             DO jj=j1,j2
@@ -416,8 +445,17 @@
             END DO
          END DO
-      ELSE
+#else
+            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) * vn(ji,jj,jk)
+                  END DO
+               END DO
+            END DO
+#endif
+      ELSE
+         tabres_child(:,:,:) = 0.
 ! VERTICAL REFINEMENT BEGIN
-         tabres_child(:,:,:) = 0.
-         
+#if defined key_vertical
          DO jj=j1,j2
          DO ji=i1,i2
@@ -438,5 +476,5 @@
              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 < 0.) then
+             if (h_diff < -1.e-4) then
              print *,'CHECK YOUR BATHY ...'
              stop
@@ -450,4 +488,13 @@
          ENDDO
          ENDDO
+#else
+            DO jk=k1,k2
+               DO jj=j1,j2
+                  DO ji=i1,i2
+                     tabres(ji,jj,jk,1) = e1v(ji,jj) * e3v_n(ji,jj,jk) * vn(ji,jj,jk)
+                  END DO
+               END DO
+            END DO
+#endif
          
 ! WARNING :
