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 9133)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/NST_SRC/agrif_opa_interp.F90	(revision 9134)
@@ -106,11 +106,10 @@
          ibdy2 = 1+nbghostcells 
          !
-         ! Smoothing
-         ! ---------
          IF( .NOT.ln_dynspg_ts ) THEN  ! Store transport
             ua_b(ibdy1:ibdy2,:) = 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)
+                  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
@@ -121,16 +120,16 @@
          !
          IF( .NOT.lk_agrif_clp ) THEN
-            DO jk=1,jpkm1                 ! Smooth
+            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))
-                  ua(ibdy2,jj,jk) = ua(ibdy2,jj,jk) * umask(ibdy2,jj,jk)
-               END DO
-            END DO
-         ENDIF
-         !
-         zub(ibdy1:ibdy2,:) = 0._wp              ! Correct transport
+               END DO
+            END DO
+         ENDIF
+         !
+         zub(ibdy1:ibdy2,:) = 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)
+               zub(ibdy1:ibdy2,jj) = zub(ibdy1:ibdy2,jj) & 
+                  & + e3u_a(ibdy1:ibdy2,jj,jk)  * ua(ibdy1:ibdy2,jj,jk)*umask(ibdy1:ibdy2,jj,jk)
             END DO
          END DO
@@ -141,5 +140,6 @@
          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)
+               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
@@ -149,5 +149,6 @@
             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)
+                  zvb(ibdy1:ibdy2,jj) = zvb(ibdy1:ibdy2,jj) & 
+                     & + e3v_a(ibdy1:ibdy2,jj,jk) * va(ibdy1:ibdy2,jj,jk) * vmask(ibdy1:ibdy2,jj,jk)
                END DO
             END DO
@@ -157,9 +158,16 @@
             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
-         !
+                  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 
       ENDIF
 
@@ -169,11 +177,10 @@
          ibdy2 = nlci-2 
          !
-         ! Smoothing
-         ! ---------
          IF( .NOT.ln_dynspg_ts ) THEN  ! Store transport
             ua_b(ibdy1:ibdy2,:) = 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)
+                  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
@@ -184,16 +191,16 @@
          !
          IF( .NOT.lk_agrif_clp ) THEN
-            DO jk=1,jpkm1                 ! Smooth
+            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))
-                  ua(ibdy1,jj,jk) = ua(ibdy1,jj,jk) * umask(ibdy1,jj,jk)
-               END DO
-            END DO
-         ENDIF
-         !
-         zub(ibdy1:ibdy2,:) = 0._wp              ! Correct transport
+               END DO
+            END DO
+         ENDIF
+         !
+         zub(ibdy1:ibdy2,:) = 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)
+               zub(ibdy1:ibdy2,jj) = zub(ibdy1:ibdy2,jj) & 
+                  & + e3u_a(ibdy1:ibdy2,jj,jk)  * ua(ibdy1:ibdy2,jj,jk) * umask(ibdy1:ibdy2,jj,jk)
             END DO
          END DO
@@ -204,5 +211,6 @@
          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)
+               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
@@ -214,5 +222,6 @@
             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)
+                  zvb(ibdy1:ibdy2,jj) = zvb(ibdy1:ibdy2,jj) &
+                     & + e3v_a(ibdy1:ibdy2,jj,jk) * va(ibdy1:ibdy2,jj,jk) * vmask(ibdy1:ibdy2,jj,jk)
                END DO
             END DO
@@ -222,9 +231,16 @@
             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
-         !
+                  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 
       ENDIF
 
@@ -234,11 +250,10 @@
          jbdy2 = 1+nbghostcells 
          !
-         ! Smoothing
-         ! ---------
          IF( .NOT.ln_dynspg_ts ) THEN  ! Store transport
             va_b(:,jbdy1:jbdy2) = 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)
+                  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)
                END DO
             END DO
@@ -249,16 +264,16 @@
          !
          IF ( .NOT.lk_agrif_clp ) THEN
-            DO jk = 1, jpkm1              ! Smooth
+            DO jk = 1, jpkm1           ! Smooth
                DO ji = i1, i2
-                  va(ji,jbdy2,jk) = 0.25_wp * vmask(ji,jbdy2,jk)    &
-                     &        * ( 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(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
          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,jbdy1:jbdy2) = zvb(ji,jbdy1:jbdy2) & 
+                  & + e3v_a(ji,jbdy1:jbdy2,jk) * va(ji,jbdy1:jbdy2,jk) * vmask(ji,jbdy1:jbdy2,jk)
             END DO
          END DO
@@ -266,15 +281,18 @@
             zvb(ji,jbdy1:jbdy2) = zvb(ji,jbdy1:jbdy2) * r1_hv_a(ji,jbdy1:jbdy2)
          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)
+               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
             
          IF( ln_dynspg_ts ) THEN       ! Set tangential velocities to time splitting estimate
-            zub(:,2) = 0._wp
+            zub(:,jbdy1:jbdy2) = 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,jbdy1:jbdy2) = zub(ji,jbdy1:jbdy2) & 
+                     & + e3u_a(ji,jbdy1:jbdy2,jk) * ua(ji,jbdy1:jbdy2,jk) * umask(ji,jbdy1:jbdy2,jk)
                END DO
             END DO
@@ -285,9 +303,16 @@
             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
-         !
+                  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 
       ENDIF
 
@@ -297,11 +322,10 @@
          jbdy2 = nlcj-2 
          !
-         ! Smoothing
-         ! ---------
          IF( .NOT.ln_dynspg_ts ) THEN  ! Store transport
             va_b(:,jbdy1:jbdy2) = 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)
+                  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)
                END DO
             END DO
@@ -312,16 +336,16 @@
          !
          IF ( .NOT.lk_agrif_clp ) THEN
-            DO jk = 1, jpkm1              ! Smooth
+            DO jk = 1, jpkm1           ! Smooth
                DO ji = i1, i2
-                  va(ji,jbdy1,jk) = 0.25_wp * vmask(ji,jbdy1,jk)    &
-                     &        * ( 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(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
          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,jbdy1:jbdy2) = zvb(ji,jbdy1:jbdy2) & 
+                  & + e3v_a(ji,jbdy1:jbdy2,jk) * va(ji,jbdy1:jbdy2,jk) * vmask(ji,jbdy1:jbdy2,jk)
             END DO
          END DO
@@ -329,7 +353,9 @@
             zvb(ji,jbdy1:jbdy2) = zvb(ji,jbdy1:jbdy2) * r1_hv_a(ji,jbdy1:jbdy2)
          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)
+               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
@@ -338,8 +364,9 @@
             jbdy1 = jbdy1 + 1
             jbdy2 = jbdy2 + 1 
-            zub(:,2) = 0._wp
+            zub(:,jbdy1:jbdy2) = 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,jbdy1:jbdy2) = zub(ji,jbdy1:jbdy2) & 
+                     & + e3u_a(ji,jbdy1:jbdy2,jk) * ua(ji,jbdy1:jbdy2,jk) * umask(ji,jbdy1:jbdy2,jk)
                END DO
             END DO
@@ -350,9 +377,16 @@
             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
-         !
+                  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 
       ENDIF
       !
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 9133)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/NST_SRC/agrif_user.F90	(revision 9134)
@@ -413,8 +413,8 @@
 
    IF( ln_zdftke.OR.ln_zdfgls ) THEN
-!      CALL agrif_declare_variable((/2,2,0/),(/ind3,ind3,0/),(/'x','y','N'/),(/1,1,1/),(/jpi,jpj,jpk/), en_id)
-!      CALL agrif_declare_variable((/2,2,0/),(/ind3,ind3,0/),(/'x','y','N'/),(/1,1,1/),(/jpi,jpj,jpk/),avt_id)
+!      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/),(/jpi,jpj,jpk,2/),avm_id)
+      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)
@@ -603,7 +603,13 @@
    ! 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_lim3
