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 8901)
+++ /branches/2017/dev_r8126_UKMO_AGRIF_vert_interp/NEMOGCM/NEMO/NST_SRC/agrif_opa_interp.F90	(revision 8902)
@@ -617,5 +617,5 @@
                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,jn) = tsn(ji,jj,jk,jn)
                  END DO
               END DO
@@ -648,5 +648,5 @@
                   IF (ptab(ji,jj,jk,n2) == 0) EXIT
                   N_in = N_in + 1
-                  tabin(jk,:) = ptab(ji,jj,jk,n1:n2-1)/(ptab(ji,jj,jk,n2))
+                  tabin(jk,:) = ptab(ji,jj,jk,n1:n2-1)
                   h_in(N_in) = ptab(ji,jj,jk,n2)/(e1e2t(ji,jj)*zrhoxy)
                END DO
@@ -669,5 +669,5 @@
             DO jj=j1,j2
                DO ji=i1,i2
-                  ptab_child(ji,jj,jk,n1:n2-1) = ptab(ji,jj,jk,n1:n2-1)/(zrhoxy*e1e2t(ji,jj)*e3t_n(ji,jj,jk)
+                  ptab_child(ji,jj,jk,n1:n2-1) = ptab(ji,jj,jk,n1:n2-1)
                ENDDO
             ENDDO
Index: /branches/2017/dev_r8126_UKMO_AGRIF_vert_interp/NEMOGCM/NEMO/NST_SRC/agrif_opa_sponge.F90
===================================================================
--- /branches/2017/dev_r8126_UKMO_AGRIF_vert_interp/NEMOGCM/NEMO/NST_SRC/agrif_opa_sponge.F90	(revision 8901)
+++ /branches/2017/dev_r8126_UKMO_AGRIF_vert_interp/NEMOGCM/NEMO/NST_SRC/agrif_opa_sponge.F90	(revision 8902)
@@ -216,5 +216,5 @@
                DO jj=j1,j2
                   DO ji=i1,i2
-                     tabres(ji,jj,jk,jn) = tsn(ji,jj,jk,jn) * e1e2t(ji,jj) * e3t_n(ji,jj,jk)
+                     tabres(ji,jj,jk,jn) = tsn(ji,jj,jk,jn)
                   END DO
                END DO
@@ -239,5 +239,5 @@
                IF (tabres(ji,jj,jk,n2) == 0) EXIT
                N_in = N_in + 1
-               tabin(jk,:) = tabres(ji,jj,jk,n1:n2-1)/tabres(ji,jj,jk,n2)
+               tabin(jk,:) = tabres(ji,jj,jk,n1:n2-1)
                h_in(N_in) = tabres(ji,jj,jk,n2)/(e1e2t(ji,jj)*zrhoxy)
              END DO
@@ -264,5 +264,5 @@
             do jj=j1,j2
                do ji=i1,i2
-                  tsbdiff(ji,jj,jk,n1:n2-1) = tsb(ji,jj,jk,n1:n2) - tmask(ji,jj,jk)*tabres(ji,jj,jk,n1:n2-1)/e3t_n(ji,jj,jk)
+                  tsbdiff(ji,jj,jk,n1:n2-1) = tsb(ji,jj,jk,n1:n2) - tmask(ji,jj,jk)*tabres(ji,jj,jk,n1:n2-1)
                enddo
             enddo
@@ -397,5 +397,5 @@
          END DO         
 #else
-         ubdiff(i1:i2,j1:j2,:) = (ub(i1:i2,j1:j2,:) - tabres(:,:,:))*umask(i1:i2,j1:j2,:)
+         ubdiff(i1:i2,j1:j2,:) = (ub(i1:i2,j1:j2,:) - tabres(:,:,:,1))*umask(i1:i2,j1:j2,:)
 #endif
          !
@@ -506,5 +506,5 @@
          END DO
 #else
-         tabres = vn(i1:i2,j1:j2,:)
+         tabres(i1:i2,j1:j2,:,m1) = vn(i1:i2,j1:j2,:)
 #endif
       ELSE
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 8901)
+++ /branches/2017/dev_r8126_UKMO_AGRIF_vert_interp/NEMOGCM/NEMO/NST_SRC/agrif_opa_update.F90	(revision 8902)
@@ -187,5 +187,4 @@
       !!
       INTEGER :: ji,jj,jk,jn
-! VERTICAL REFINEMENT BEGIN
       REAL(wp), DIMENSION(i1:i2,j1:j2,1:jpk,n1:n2) :: tabres_child
       REAL(wp) :: h_in(k1:k2)
@@ -195,81 +194,75 @@
       REAL(wp) :: zrho_xy
       REAL(wp) :: tabin(k1:k2,n1:n2)
-! VERTICAL REFINEMENT END
       !!---------------------------------------------
       !
       IF (before) THEN
 # if defined key_vertical
-            AGRIF_SpecialValue = -999._wp
-            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) = (tsn(ji,jj,jk,jn) * e1e2t(ji,jj) * e3t_n(ji,jj,jk) ) &
-                                              * tmask(ji,jj,jk) * zrho_xy + (tmask(ji,jj,jk)-1)*999._wp
-                     END DO
-                  END DO
-               END DO
-            END DO
+         AGRIF_SpecialValue = -999._wp
+         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,n2) = tmask(ji,jj,jk) * e1e2t(ji,jj) * e3t_n(ji,jj,jk) * zrho_xy  &
-                                              + (tmask(ji,jj,jk)-1)*999._wp
+                     tabres(ji,jj,jk,jn) = (tsn(ji,jj,jk,jn) * e1e2t(ji,jj) * e3t_n(ji,jj,jk) ) &
+                                           * tmask(ji,jj,jk) * zrho_xy + (tmask(ji,jj,jk)-1)*999._wp
                   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) * e1e2t(ji,jj) * e3t_n(ji,jj,jk) * zrho_xy  &
+                                           + (tmask(ji,jj,jk)-1)*999._wp
+               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
+         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
+         END DO        
 #endif
       ELSE
-! VERTICAL REFINEMENT BEGIN
          tabres_child(:,:,:,:) = 0.
 # if defined key_vertical
          AGRIF_SpecialValue = 0._wp
          DO jj=j1,j2
-         DO ji=i1,i2
-           N_in = 0
-           DO jk=k1,k2 !k2 = jpk of child grid
-             IF (tabres(ji,jj,jk,n2) == 0  ) EXIT
-             N_in = N_in + 1
-             tabin(jk,:) = tabres(ji,jj,jk,n1:n2-1)/tabres(ji,jj,jk,n2)
-             h_in(N_in) = tabres(ji,jj,jk,n2)/e1e2t(ji,jj)
-           ENDDO
-           N_out = 0
-           DO jk=1,jpk ! jpk of parent grid
-             IF (tmask(ji,jj,jk) < -900) EXIT ! TODO: Will not work with ISF
-             N_out = N_out + 1
-             h_out(N_out) = e3t_n(ji,jj,jk) !Parent 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))
-             IF (h_diff < -1.e-4) THEN
-                print *,'CHECK YOUR bathy T points ...',ji,jj,h_diff,e1e2t(ji,jj),sum(h_in(1:N_in)),sum(h_out(1:N_out)), N_in, 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
-          ENDIF
-         ENDDO
+            DO ji=i1,i2
+               N_in = 0
+               DO jk=k1,k2 !k2 = jpk of child grid
+                  IF (tabres(ji,jj,jk,n2) == 0  ) EXIT
+                  N_in = N_in + 1
+                  tabin(jk,:) = tabres(ji,jj,jk,n1:n2-1)/tabres(ji,jj,jk,n2)
+                  h_in(N_in) = tabres(ji,jj,jk,n2)/e1e2t(ji,jj)
+               ENDDO
+               N_out = 0
+               DO jk=1,jpk ! jpk of parent grid
+                  IF (tmask(ji,jj,jk) < -900) EXIT ! TODO: Will not work with ISF
+                  N_out = N_out + 1
+                  h_out(N_out) = e3t_n(ji,jj,jk) !Parent grid scale factors. Could multiply by e1e2t here instead of division above
+               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
+               ENDIF
+            ENDDO
          ENDDO
 #else
-            tabres_child(:,:,:,:) = tabres(:,:,:,1:jpts)
+         tabres_child(:,:,:,:) = tabres(:,:,:,1:jpts)
 #endif
-! WARNING :
-! tabres replaced by tabres_child in the following
-! k1 k2 replaced by 1 jpk
-! VERTICAL REFINEMENT END
          IF (.NOT.(lk_agrif_fstep.AND.(neuler==0))) THEN
             ! Add asselin part
@@ -281,5 +274,5 @@
                            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)
+                                 &          - tsn(ji,jj,jk,jn) ) * tmask(ji,jj,jk)
                         ENDIF
                      ENDDO
@@ -325,5 +318,4 @@
       ! 
       IF( before ) THEN
-         print *, i1,i2,j1,j2,k1,k2
          zrhoy = Agrif_Rhoy()
 # if defined key_vertical
@@ -340,7 +332,7 @@
          END DO
 #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
+         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
@@ -349,43 +341,43 @@
          AGRIF_SpecialValue = 0._wp
          DO jj=j1,j2
-         DO ji=i1,i2
-           N_in = 0
-           h_in(:) = 0._wp
-           tabin(:) = 0._wp
-           DO jk=k1,k2 !k2=jpk of child grid
-             IF( tabres(ji,jj,jk,2) < -900) EXIT
-             N_in = N_in + 1
-             tabin(jk) = tabres(ji,jj,jk,1)/tabres(ji,jj,jk,2)
-             h_in(N_in) = tabres(ji,jj,jk,2)/e2u(ji,jj)
-           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_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.e-4) then
+            DO ji=i1,i2
+               N_in = 0
+               h_in(:) = 0._wp
+               tabin(:) = 0._wp
+               DO jk=k1,k2 !k2=jpk of child grid
+                  IF( tabres(ji,jj,jk,2) < -900) EXIT
+                  N_in = N_in + 1
+                  tabin(jk) = tabres(ji,jj,jk,1)/tabres(ji,jj,jk,2)
+                  h_in(N_in) = tabres(ji,jj,jk,2)/e2u(ji,jj)
+               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_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.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))
-                   excess = excess + tabin(jk)*thick*e2u(ji,jj)
-                   tabin(jk) = tabin(jk)*(1. - thick/h_in(jk))
-                   h_diff = h_diff + thick
-                   IF ( h_diff == 0) THEN
-                      N_in = jk
-                      h_in(jk) = h_in(jk) - thick
-                      EXIT
-                   ENDIF
-                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)
-             tabres_child(ji,jj,N_out) = tabres_child(ji,jj,N_out) + excess/(e2u(ji,jj)*h_out(N_out))
-           ENDIF
+                     excess = 0._wp
+                     DO jk=N_in,1,-1
+                        thick = MIN(-1*h_diff, h_in(jk))
+                        excess = excess + tabin(jk)*thick*e2u(ji,jj)
+                        tabin(jk) = tabin(jk)*(1. - thick/h_in(jk))
+                        h_diff = h_diff + thick
+                        IF ( h_diff == 0) THEN
+                           N_in = jk
+                           h_in(jk) = h_in(jk) - thick
+                           EXIT
+                        ENDIF
+                     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)
+                  tabres_child(ji,jj,N_out) = tabres_child(ji,jj,N_out) + excess/(e2u(ji,jj)*h_out(N_out))
+               ENDIF
+            ENDDO
          ENDDO
-      ENDDO
 #else
             DO jk=1,jpk
@@ -463,49 +455,49 @@
          AGRIF_SpecialValue = 0._wp
          DO jj=j1,j2
-         DO ji=i1,i2
-           N_in = 0
-           DO jk=k1,k2
-             IF (tabres(ji,jj,jk,2) < -900) EXIT
-             N_in = N_in + 1
-             tabin(jk) = tabres(ji,jj,jk,1)/tabres(ji,jj,jk,2)
-             h_in(N_in) = tabres(ji,jj,jk,2)/e1v(ji,jj)
-           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_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.e-4) then
+            DO ji=i1,i2
+               N_in = 0
+               DO jk=k1,k2
+                  IF (tabres(ji,jj,jk,2) < -900) EXIT
+                  N_in = N_in + 1
+                  tabin(jk) = tabres(ji,jj,jk,1)/tabres(ji,jj,jk,2)
+                  h_in(N_in) = tabres(ji,jj,jk,2)/e1v(ji,jj)
+               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_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.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))
-                   excess = excess + tabin(jk)*thick*e2u(ji,jj)
-                   tabin(jk) = tabin(jk)*(1. - thick/h_in(jk))
-                   h_diff = h_diff + thick
-                   IF ( h_diff == 0) THEN
-                      N_in = jk
-                      h_in(jk) = h_in(jk) - thick
-                      EXIT
-                   ENDIF
-                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)
-             tabres_child(ji,jj,N_out) = tabres_child(ji,jj,N_out) + excess/(e1v(ji,jj)*h_out(N_out))
-          ENDIF
-         ENDDO
+                     excess = 0._wp
+                     DO jk=N_in,1,-1
+                        thick = MIN(-1*h_diff, h_in(jk))
+                        excess = excess + tabin(jk)*thick*e2u(ji,jj)
+                        tabin(jk) = tabin(jk)*(1. - thick/h_in(jk))
+                        h_diff = h_diff + thick
+                        IF ( h_diff == 0) THEN
+                           N_in = jk
+                           h_in(jk) = h_in(jk) - thick
+                           EXIT
+                        ENDIF
+                     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)
+                  tabres_child(ji,jj,N_out) = tabres_child(ji,jj,N_out) + excess/(e1v(ji,jj)*h_out(N_out))
+               ENDIF
+            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
+         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
 
Index: /branches/2017/dev_r8126_UKMO_AGRIF_vert_interp/NEMOGCM/NEMO/OPA_SRC/nemogcm.F90
===================================================================
--- /branches/2017/dev_r8126_UKMO_AGRIF_vert_interp/NEMOGCM/NEMO/OPA_SRC/nemogcm.F90	(revision 8901)
+++ /branches/2017/dev_r8126_UKMO_AGRIF_vert_interp/NEMOGCM/NEMO/OPA_SRC/nemogcm.F90	(revision 8902)
@@ -372,5 +372,5 @@
       ! Save maximum number of levels in jpkglo, then define all vertical grids with this number.
       ! Suppress once vertical online interpolation is ok
-      IF(.NOT.Agrif_Root())   jpkglo = Agrif_Parent( jpkglo )
+!      IF(.NOT.Agrif_Root())   jpkglo = Agrif_Parent( jpkglo )
 #endif
       jpim1 = jpi-1                                            ! inner domain indices
