Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/NST_SRC/agrif_oce.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/NST_SRC/agrif_oce.F90	(revision 9115)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/NST_SRC/agrif_oce.F90	(revision 9116)
@@ -46,8 +46,8 @@
 
    ! 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_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
 
 
@@ -91,8 +91,8 @@
          &      tabspongedone_v  (jpi,jpj), STAT = ierr(1) )
 
-      ALLOCATE( ubdy_w(jpj), vbdy_w(jpj), hbdy_w(jpj),   &
-         &      ubdy_e(jpj), vbdy_e(jpj), hbdy_e(jpj),   & 
-         &      ubdy_n(jpi), vbdy_n(jpi), hbdy_n(jpi),   & 
-         &      ubdy_s(jpi), vbdy_s(jpi), hbdy_s(jpi), STAT = ierr(2) )
+      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) )
 
       agrif_oce_alloc = MAXVAL(ierr)
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/NST_SRC/agrif_opa_interp.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/NST_SRC/agrif_opa_interp.F90	(revision 9115)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/NST_SRC/agrif_opa_interp.F90	(revision 9116)
@@ -373,7 +373,7 @@
       IF((nbondi == -1).OR.(nbondi == 2)) THEN
          DO jj=1,jpj
-            va_e(2:nbghostcells+1,jj) = vbdy_w(jj) * hvr_e(2:nbghostcells+1,jj)
+            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(jj) * hur_e(2:nbghostcells+1,jj)
+            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) &
@@ -384,7 +384,7 @@
       IF((nbondi == 1).OR.(nbondi == 2)) THEN
          DO jj=1,jpj
-            va_e(nlci-nbghostcells:nlci-1,jj)   = vbdy_e(jj) * hvr_e(nlci-nbghostcells:nlci-1,jj)
+            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(jj) * hur_e(nlci-nbghostcells-1:nlci-2,jj)
+            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) &
@@ -395,7 +395,7 @@
       IF((nbondj == -1).OR.(nbondj == 2)) THEN
          DO ji=1,jpi
-            ua_e(ji,2:nbghostcells+1) = ubdy_s(ji) * hur_e(ji,2:nbghostcells+1)
+            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) * hvr_e(ji,2:nbghostcells+1)
+            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) &
@@ -406,7 +406,7 @@
       IF((nbondj == 1).OR.(nbondj == 2)) THEN
          DO ji=1,jpi
-            ua_e(ji,nlcj-nbghostcells:nlcj-1)   = ubdy_n(ji) * hur_e(ji,nlcj-nbghostcells:nlcj-1)
+            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) * hvr_e(ji,nlcj-nbghostcells-1:nlcj-2)
+            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) &
@@ -451,8 +451,8 @@
       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_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
          CALL Agrif_Bc_variable( unb_id, procname=interpunb )
          CALL Agrif_Bc_variable( vnb_id, procname=interpvnb )
@@ -474,5 +474,5 @@
       IF( Agrif_Root() )   RETURN
       !      
-      ! Linear interpolation in time of sea level
+      ! Linear time interpolation of sea level
       !
       Agrif_SpecialValue    = 0._wp
@@ -481,9 +481,10 @@
       Agrif_UseSpecialValue = .FALSE.
       !
+      ! --- West --- !
       IF((nbondi == -1).OR.(nbondi == 2)) THEN
          indx = 1+nbghostcells
          DO jj = 1, jpj
             DO ji = 2, indx
-               ssha(ji,jj) = hbdy_w(jj)
+               ssha(ji,jj) = hbdy_w(ji-1,jj)
             ENDDO
          ENDDO
@@ -495,5 +496,5 @@
          DO jj = 1, jpj
             DO ji = indx, nlci-1
-               ssha(indx,jj) = hbdy_e(jj)
+               ssha(ji,jj) = hbdy_e(ji-indx+1,jj)
             ENDDO
          ENDDO
@@ -505,5 +506,5 @@
          DO jj = 2, indy
             DO ji = 1, jpi
-               ssha(ji,indy) = hbdy_s(ji)
+               ssha(ji,jj) = hbdy_s(ji,jj-1)
             ENDDO
          ENDDO
@@ -513,7 +514,7 @@
       IF((nbondj == 1).OR.(nbondj == 2)) THEN
          indy = nlcj-nbghostcells
-         DO jj = indx, nlcj-1
+         DO jj = indy, nlcj-1
             DO ji = 1, jpi
-               ssha(ji,indy) = hbdy_n(ji)
+               ssha(ji,jj) = hbdy_n(ji,jj-indy+1)
             ENDDO
          ENDDO
@@ -529,5 +530,5 @@
       INTEGER, INTENT(in) ::   jn
       !!
-      INTEGER :: ji, jj
+      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)
@@ -535,26 +536,42 @@
       IF( Agrif_Root() )   RETURN
       !
+      ! --- West --- !
       IF((nbondi == -1).OR.(nbondi == 2)) THEN
+         indx = 1+nbghostcells
          DO jj = 1, jpj
-            ssha_e(2:nbghostcells+1,jj) = hbdy_w(jj)
-         END DO
-      ENDIF
-      !
+            DO ji = 2, indx
+               ssha_e(ji,jj) = hbdy_w(ji-1,jj)
+            ENDDO
+         ENDDO
+      ENDIF
+      !
+      ! --- East --- !
       IF((nbondi == 1).OR.(nbondi == 2)) THEN
+         indx = nlci-nbghostcells
          DO jj = 1, jpj
-            ssha_e(nlci-nbghostcells:nlci-1,jj) = hbdy_e(jj)
-         END DO
-      ENDIF
-      !
+            DO ji = indx, nlci-1
+               ssha_e(ji,jj) = hbdy_e(ji-indx+1,jj)
+            ENDDO
+         ENDDO
+      ENDIF
+      !
+      ! --- South --- !
       IF((nbondj == -1).OR.(nbondj == 2)) THEN
-         DO ji = 1, jpi
-            ssha_e(ji,2:nbghostcells+1) = hbdy_s(ji)
-         END DO
-      ENDIF
-      !
+         indy = 1+nbghostcells
+         DO jj = 2, indy
+            DO ji = 1, jpi
+               ssha_e(ji,jj) = hbdy_s(ji,jj-1)
+            ENDDO
+         ENDDO
+      ENDIF
+      !
+      ! --- North --- !
       IF((nbondj == 1).OR.(nbondj == 2)) THEN
-         DO ji = 1, jpi
-            ssha_e(ji,nlcj-nbghostcells:nlcj-1) = hbdy_n(ji)
-         END DO
+         indy = nlcj-nbghostcells
+         DO jj = indy, nlcj-1
+            DO ji = 1, jpi
+               ssha_e(ji,jj) = hbdy_n(ji,jj-indy+1)
+            ENDDO
+         ENDDO
       ENDIF
       !
@@ -592,5 +609,5 @@
       INTEGER                                     , INTENT(in   ) ::   nb , ndir
       !
-      INTEGER  ::   ji, jj, jk, jn, iref, jref   ! dummy loop indices
+      INTEGER  ::   ji, jj, jk, jn, iref, jref, ibdy, jbdy   ! dummy loop indices
       INTEGER  ::   imin, imax, jmin, jmax, N_in, N_out
       REAL(wp) ::   zrhox, z1, z2, z3, z4, z5, z6, z7
@@ -600,8 +617,7 @@
       REAL(wp), DIMENSION(k1:k2,n1:n2-1) :: tabin
       REAL(wp), DIMENSION(k1:k2) :: h_in
-      REAL(wp), DIMENSION(1:jpk) :: h_out(1:jpk)
-      REAL(wp) :: h_diff, zrhoxy
-
-      zrhoxy = Agrif_rhox()*Agrif_rhoy()
+      REAL(wp), DIMENSION(1:jpk) :: h_out
+      REAL(wp) :: h_diff
+
       IF( before ) THEN         
          DO jn = 1,jpts
@@ -662,7 +678,7 @@
 # endif
          !
-         IF( lk_agrif_clp ) THEN  ! Clamped bcs
-            tsa(i1:i2,j1:j2,k1:k2,n1:n2) = ptab_child(i1:i2,j1:j2,k1:k2,n1:n2)
-         ELSE                         ! smoothing
+         tsa(i1:i2,j1:j2,1:jpk,1:jpts) = ptab_child(i1:i2,j1:j2,1:jpk,1:jpts)
+
+         IF ( .NOT.lk_agrif_clp ) THEN 
             !
             zrhox = Agrif_Rhox()
@@ -686,99 +702,87 @@
             !
             IF( eastern_side ) THEN
+               ibdy = nlci-nbghostcells
                DO jn = 1, jpts
-                  tsa(nlci,j1:j2,k1:k2,jn) = z1 * ptab_child(nlci,j1:j2,k1:k2,jn) + z2 * ptab_child(nlci-1,j1:j2,k1:k2,jn)
+                  tsa(ibdy+1,jmin:jmax,k1:k2,jn) = z1 * ptab_child(ibdy+1,jmin:jmax,k1:k2,jn) + z2 * ptab_child(ibdy,jmin:jmax,k1:k2,jn)
                   DO jk = 1, jpkm1
                      DO jj = jmin,jmax
-                        IF( umask(nlci-2,jj,jk) == 0._wp ) THEN
-                           tsa(nlci-1,jj,jk,jn) = tsa(nlci,jj,jk,jn) * tmask(nlci-1,jj,jk)
+                        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(nlci-1,jj,jk,jn)=(z4*tsa(nlci,jj,jk,jn)+z3*tsa(nlci-2,jj,jk,jn))*tmask(nlci-1,jj,jk)
-                           IF( un(nlci-2,jj,jk) > 0._wp ) THEN
-                              tsa(nlci-1,jj,jk,jn)=( z6*tsa(nlci-2,jj,jk,jn)+z5*tsa(nlci,jj,jk,jn) & 
-                                                   + z7*tsa(nlci-3,jj,jk,jn) ) * tmask(nlci-1,jj,jk)
+                           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
-                  tsa(nlci,j1:j2,k1:k2,jn) = 0._wp
+                  ! Restore ghost points:
+                  tsa(ibdy+1,jmin:jmax,k1:k2,jn) = ptab_child(ibdy+1,jmin:jmax,k1:k2,jn) * tmask(ibdy+1,jmin:jmax,k1:k2)
                END DO
             ENDIF
             ! 
-            IF( northern_side ) THEN            
+            IF( northern_side ) THEN
+               jbdy = nlcj-nbghostcells         
                DO jn = 1, jpts
-                  tsa(i1:i2,nlcj,k1:k2,jn) = z1 * ptab_child(i1:i2,nlcj,k1:k2,jn) + z2 * ptab_child(i1:i2,nlcj-1,k1:k2,jn)
+                  tsa(imin:imax,jbdy+1,k1:k2,jn) = z1 * ptab_child(imin:imax,jbdy+1,k1:k2,jn) + z2 * ptab_child(imin:imax,jbdy,k1:k2,jn)
                   DO jk = 1, jpkm1
                      DO ji = imin,imax
-                        IF( vmask(ji,nlcj-2,jk) == 0._wp ) THEN
-                           tsa(ji,nlcj-1,jk,jn) = tsa(ji,nlcj,jk,jn) * tmask(ji,nlcj-1,jk)
+                        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,nlcj-1,jk,jn)=(z4*tsa(ji,nlcj,jk,jn)+z3*tsa(ji,nlcj-2,jk,jn))*tmask(ji,nlcj-1,jk)        
-                           IF (vn(ji,nlcj-2,jk) > 0._wp ) THEN
-                              tsa(ji,nlcj-1,jk,jn)=( z6*tsa(ji,nlcj-2,jk,jn)+z5*tsa(ji,nlcj,jk,jn)  &
-                                                   + z7*tsa(ji,nlcj-3,jk,jn) ) * tmask(ji,nlcj-1,jk)
+                           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
-                  tsa(i1:i2,nlcj,k1:k2,jn) = 0._wp
+                  ! Restore ghost points:
+                  tsa(imin:imax,jbdy+1,k1:k2,jn) = ptab_child(imin:imax,jbdy+1,k1:k2,jn) * tmask(imin:imax,jbdy+1,k1:k2)
                END DO
             ENDIF
             !
-            IF( western_side ) THEN            
+            IF( western_side ) THEN    
+               ibdy = 1+nbghostcells       
                DO jn = 1, jpts
-                  tsa(1,j1:j2,k1:k2,jn) = z1 * ptab_child(1,j1:j2,k1:k2,jn) + z2 * ptab_child(2,j1:j2,k1:k2,jn)
+                  tsa(ibdy-1,jmin:jmax,k1:k2,jn) = z1 * ptab_child(ibdy-1,jmin:jmax,k1:k2,jn) + z2 * ptab_child(ibdy,jmin:jmax,k1:k2,jn)
                   DO jk = 1, jpkm1
                      DO jj = jmin,jmax
-                        IF( umask(2,jj,jk) == 0._wp ) THEN
-                           tsa(2,jj,jk,jn) = tsa(1,jj,jk,jn) * tmask(2,jj,jk)
+                        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(2,jj,jk,jn)=(z4*tsa(1,jj,jk,jn)+z3*tsa(3,jj,jk,jn))*tmask(2,jj,jk)        
-                           IF( un(2,jj,jk) < 0._wp ) THEN
-                              tsa(2,jj,jk,jn)=(z6*tsa(3,jj,jk,jn)+z5*tsa(1,jj,jk,jn)+z7*tsa(4,jj,jk,jn))*tmask(2,jj,jk)
+                           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
-                  tsa(1,j1:j2,k1:k2,jn) = 0._wp
+                  ! Restore ghost points:
+                  tsa(ibdy-1,jmin:jmax,k1:k2,jn) = ptab_child(ibdy-1,jmin:jmax,k1:k2,jn) * tmask(ibdy-1,jmin:jmax,k1:k2)
                END DO
             ENDIF
             !
-            IF( southern_side ) THEN           
+            IF( southern_side ) THEN  
+               jbdy=1+nbghostcells        
                DO jn = 1, jpts
-                  tsa(i1:i2,1,k1:k2,jn) = z1 * ptab_child(i1:i2,1,k1:k2,jn) + z2 * ptab_child(i1:i2,2,k1:k2,jn)
+                  tsa(imin:imax,jbdy-1,k1:k2,jn) = z1 * ptab_child(imin:imax,jbdy-1,k1:k2,jn) + z2 * ptab_child(imin:imax,jbdy,k1:k2,jn)
                   DO jk = 1, jpk      
                      DO ji=imin,imax
-                        IF( vmask(ji,2,jk) == 0._wp ) THEN
-                           tsa(ji,2,jk,jn)=tsa(ji,1,jk,jn) * tmask(ji,2,jk)
+                        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,2,jk,jn)=(z4*tsa(ji,1,jk,jn)+z3*tsa(ji,3,jk,jn))*tmask(ji,2,jk)
-                           IF( vn(ji,2,jk) < 0._wp ) THEN
-                              tsa(ji,2,jk,jn)=(z6*tsa(ji,3,jk,jn)+z5*tsa(ji,1,jk,jn)+z7*tsa(ji,4,jk,jn))*tmask(ji,2,jk)
+                           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
-                  tsa(i1:i2,1,k1:k2,jn) = 0._wp
-               END DO
-            ENDIF
-            !
-            !
-            ! Treatment of corners
-            ! 
-            ! East south
-            IF ((eastern_side).AND.((nbondj == -1).OR.(nbondj == 2))) THEN
-               tsa(nlci-1,2,:,:) = ptab_child(nlci-1,2,:,1:jpts)
-            ENDIF
-            ! East north
-            IF ((eastern_side).AND.((nbondj == 1).OR.(nbondj == 2))) THEN
-               tsa(nlci-1,nlcj-1,:,:) = ptab_child(nlci-1,nlcj-1,:,1:jpts)
-            ENDIF
-            ! West south
-            IF ((western_side).AND.((nbondj == -1).OR.(nbondj == 2))) THEN
-               tsa(2,2,:,:) = ptab_child(2,2,:,1:jpts)
-            ENDIF
-            ! West north
-            IF ((western_side).AND.((nbondj == 1).OR.(nbondj == 2))) THEN
-               tsa(2,nlcj-1,:,:) = ptab_child(2,nlcj-1,:,1:jpts)
+                  ! Restore ghost points:
+                  tsa(imin:imax,jbdy-1,k1:k2,jn) = tsa(imin:imax,jbdy-1,k1:k2,jn) * tmask(imin:imax,jbdy-1,k1:k2)
+               END DO
             ENDIF
             !
@@ -808,8 +812,8 @@
          northern_side = (nb == 2).AND.(ndir == 2)
          !! clem ghost
-         IF(western_side)  hbdy_w(j1:j2) = ptab(i2,j1:j2) * tmask(i2,j1:j2,1)
-         IF(eastern_side)  hbdy_e(j1:j2) = ptab(i1,j1:j2) * tmask(i1,j1:j2,1)
-         IF(southern_side) hbdy_s(i1:i2) = ptab(i1:i2,j2) * tmask(i1:i2,j2,1) 
-         IF(northern_side) hbdy_n(i1:i2) = ptab(i1:i2,j1) * tmask(i1:i2,j1,1)
+         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)
       ENDIF
       !
@@ -836,5 +840,4 @@
       !!---------------------------------------------    
       !
-      zrhoy = Agrif_rhoy()
       IF (before) THEN 
          DO jk=1,jpk
@@ -1023,14 +1026,14 @@
          ENDIF
          !   
-         IF(western_side)   ubdy_w(j1:j2) = ubdy_w(j1:j2) + ztcoeff * ptab(i2,j1:j2)  
-         IF(eastern_side)   ubdy_e(j1:j2) = ubdy_e(j1:j2) + ztcoeff * ptab(i1,j1:j2)  
-         IF(southern_side)  ubdy_s(i1:i2) = ubdy_s(i1:i2) + ztcoeff * ptab(i1:i2,j2)
-         IF(northern_side)  ubdy_n(i1:i2) = ubdy_n(i1:i2) + ztcoeff * ptab(i1:i2,j1) 
+         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(j1:j2) = ubdy_w(j1:j2) / (zrhoy*e2u(i2,j1:j2)) * umask(i2,j1:j2,1)
-            IF(eastern_side)   ubdy_e(j1:j2) = ubdy_e(j1:j2) / (zrhoy*e2u(i1,j1:j2)) * umask(i1,j1:j2,1)
-            IF(southern_side)  ubdy_s(i1:i2) = ubdy_s(i1:i2) / (zrhoy*e2u(i1:i2,j2)) * umask(i1:i2,j2,1)
-            IF(northern_side)  ubdy_n(i1:i2) = ubdy_n(i1:i2) / (zrhoy*e2u(i1:i2,j1)) * umask(i1:i2,j1,1)
+            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
@@ -1075,14 +1078,14 @@
          ENDIF
          !! clem ghost
-         IF(western_side)   vbdy_w(j1:j2) = vbdy_w(j1:j2) + ztcoeff * ptab(i2,j1:j2)  
-         IF(eastern_side)   vbdy_e(j1:j2) = vbdy_e(j1:j2) + ztcoeff * ptab(i1,j1:j2)   
-         IF(southern_side)  vbdy_s(i1:i2) = vbdy_s(i1:i2) + ztcoeff * ptab(i1:i2,j2)
-         IF(northern_side)  vbdy_n(i1:i2) = vbdy_n(i1:i2) + ztcoeff * ptab(i1:i2,j1) 
+         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(j1:j2) = vbdy_w(j1:j2) / (zrhox*e1v(i2,j1:j2)) * vmask(i2,j1:j2,1)
-            IF(eastern_side)   vbdy_e(j1:j2) = vbdy_e(j1:j2) / (zrhox*e1v(i1,j1:j2)) * vmask(i1,j1:j2,1)
-            IF(southern_side)  vbdy_s(i1:i2) = vbdy_s(i1:i2) / (zrhox*e1v(i1:i2,j2)) * vmask(i1:i2,j2,1)
-            IF(northern_side)  vbdy_n(i1:i2) = vbdy_n(i1:i2) / (zrhox*e1v(i1:i2,j1)) * vmask(i1:i2,j1,1)
+            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
       ENDIF
@@ -1123,8 +1126,8 @@
             &           - zt0**2._wp * (-2._wp*zt0 + 3._wp)    ) 
          !! clem ghost
-         IF(western_side ) ubdy_w(j1:j2) = zat * ptab(i2,j1:j2)  
-         IF(eastern_side ) ubdy_e(j1:j2) = zat * ptab(i1,j1:j2)  
-         IF(southern_side) ubdy_s(i1:i2) = zat * ptab(i1:i2,j2)
-         IF(northern_side) ubdy_n(i1:i2) = zat * ptab(i1:i2,j1) 
+         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
       ! 
@@ -1165,8 +1168,8 @@
             &           - zt0**2._wp * (-2._wp*zt0 + 3._wp)    ) 
          !
-         IF(western_side )   vbdy_w(j1:j2) = zat * ptab(i2,j1:j2)  
-         IF(eastern_side )   vbdy_e(j1:j2) = zat * ptab(i1,j1:j2)  
-         IF(southern_side)   vbdy_s(i1:i2) = zat * ptab(i1:i2,j2)
-         IF(northern_side)   vbdy_n(i1:i2) = zat * ptab(i1:i2,j1) 
+         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) 
       ENDIF
       !      
@@ -1309,15 +1312,12 @@
       !!                  ***  ROUTINE interavm  ***
       !!----------------------------------------------------------------------  
-      INTEGER                              , INTENT(in   ) ::   i1, i2, j1, j2, k1, k2, m1, m2
+      INTEGER                                    , INTENT(in   ) ::   i1, i2, j1, j2, k1, k2, m1, m2
       REAL(wp),DIMENSION(i1:i2,j1:j2,k1:k2,m1:m2), INTENT(inout) ::   ptab
-      LOGICAL                              , INTENT(in   ) ::   before
-      REAL(wp), DIMENSION(k1:k2) :: tabin
-      REAL(wp) :: h_in(k1:k2)
-      REAL(wp) :: h_out(1:jpk)
-      REAL(wp) :: zrhoxy
+      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
       !!----------------------------------------------------------------------  
       !      
-      zrhoxy = Agrif_rhox()*Agrif_rhoy()
       IF (before) THEN         
          DO jk=k1,k2
@@ -1332,5 +1332,5 @@
            DO jj=j1,j2
               DO ji=i1,i2
-                 ptab(ji,jj,jk,2) = wmask(ji,jj,jk) * e1e2t(ji,jj) * e3w_n(ji,jj,jk) 
+                 ptab(ji,jj,jk,2) = wmask(ji,jj,jk) * e3w_n(ji,jj,jk) 
               END DO
            END DO
@@ -1347,5 +1347,5 @@
                   N_in = N_in + 1
                   tabin(jk) = ptab(ji,jj,jk,1)
-                  h_in(N_in) = ptab(ji,jj,jk,2)/(e1e2t(ji,jj)*zrhoxy)
+                  h_in(N_in) = ptab(ji,jj,jk,2)
                END DO
                N_out = 0
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/NST_SRC/agrif_opa_update.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/NST_SRC/agrif_opa_update.F90	(revision 9115)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/NST_SRC/agrif_opa_update.F90	(revision 9116)
@@ -261,7 +261,4 @@
       ! 2) BEFORE fields:
       !------------------
-!      IF (     (.NOT.(lk_agrif_fstep.AND.(neuler==0)).AND.(ln_dynspg_exp)) &
-!         & .OR.(.NOT.(lk_agrif_fstep.AND.(neuler==0)).AND.(ln_dynspg_ts    &
-!         & .AND.(.NOT.ln_bt_fw)))) THEN
       IF (.NOT.(lk_agrif_fstep.AND.(neuler==0) )) THEN
          !
@@ -305,5 +302,4 @@
       INTEGER  :: N_in, N_out
       REAL(wp) :: h_diff
-      REAL(wp) :: zrho_xy
       REAL(wp) :: tabin(k1:k2,n1:n2)
       !!---------------------------------------------
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/NST_SRC/agrif_user.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/NST_SRC/agrif_user.F90	(revision 9115)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/NST_SRC/agrif_user.F90	(revision 9116)
@@ -218,5 +218,5 @@
    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
+   hbdy_w(:,:) = 0.e0 ; hbdy_e(:,:) = 0.e0 ; hbdy_n(:,:) = 0.e0 ; hbdy_s(:,:) = 0.e0
    ssha(:,:) = 0.e0
 
@@ -227,8 +227,8 @@
       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
+      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
 
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DYN/divhor.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DYN/divhor.F90	(revision 9115)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DYN/divhor.F90	(revision 9116)
@@ -87,8 +87,8 @@
 #if defined key_agrif
       IF( .NOT. Agrif_Root() ) THEN
-         IF( nbondi == -1 .OR. nbondi == 2 )   hdivn( 2:nbghostcells+1,:        ,:) = 0._wp      ! west
-         IF( nbondi ==  1 .OR. nbondi == 2 )   hdivn( nlci-nbghostcells:nlci-1,:,:) = 0._wp      ! east
-         IF( nbondj == -1 .OR. nbondj == 2 )   hdivn( :,2:nbghostcells+1        ,:) = 0._wp      ! south
-         IF( nbondj ==  1 .OR. nbondj == 2 )   hdivn( :,nlcj-nbghostcells:nlcj-1,:) = 0._wp      ! north
+         IF( nbondi == -1 .OR. nbondi == 2 )   hdivn(   2   ,  :   ,:) = 0._wp      ! west
+         IF( nbondi ==  1 .OR. nbondi == 2 )   hdivn( nlci-1,  :   ,:) = 0._wp      ! east
+         IF( nbondj == -1 .OR. nbondj == 2 )   hdivn(   :   ,  2   ,:) = 0._wp      ! south
+         IF( nbondj ==  1 .OR. nbondj == 2 )   hdivn(   :   ,nlcj-1,:) = 0._wp      ! north
       ENDIF
 #endif
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DYN/dynspg_ts.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DYN/dynspg_ts.F90	(revision 9115)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DYN/dynspg_ts.F90	(revision 9116)
@@ -785,20 +785,20 @@
             IF((nbondi == -1).OR.(nbondi == 2)) THEN
                DO jj = 1, jpj
-                  zwx(2:nbghostcells+1,jj) = ubdy_w(jj) * e2u(2:nbghostcells+1,jj)
+                  zwx(2:nbghostcells+1,jj) = ubdy_w(1:nbghostcells,jj) * e2u(2:nbghostcells+1,jj)
                END DO
             ENDIF
             IF((nbondi ==  1).OR.(nbondi == 2)) THEN
                DO jj=1,jpj
-                  zwx(nlci-nbghostcells-1:nlci-2,jj) = ubdy_e(jj) * e2u(nlci-nbghostcells-1:nlci-2,jj)
+                  zwx(nlci-nbghostcells-1:nlci-2,jj) = ubdy_e(1:nbghostcells,jj) * e2u(nlci-nbghostcells-1:nlci-2,jj)
                END DO
             ENDIF
             IF((nbondj == -1).OR.(nbondj == 2)) THEN
                DO ji=1,jpi
-                  zwy(ji,2:nbghostcells+1) = vbdy_s(ji) * e1v(ji,2:nbghostcells+1)
+                  zwy(ji,2:nbghostcells+1) = vbdy_s(ji,1:nbghostcells) * e1v(ji,2:nbghostcells+1)
                END DO
             ENDIF
             IF((nbondj ==  1).OR.(nbondj == 2)) THEN
                DO ji=1,jpi
-                  zwy(ji,nlcj-nbghostcells-1:nlcj-2) = vbdy_n(ji) * e1v(ji,nlcj-nbghostcells-1:nlcj-2)
+                  zwy(ji,nlcj-nbghostcells-1:nlcj-2) = vbdy_n(ji,1:nbghostcells) * e1v(ji,nlcj-nbghostcells-1:nlcj-2)
                END DO
             ENDIF
