Index: branches/2015/dev_r5803_NOC_WAD/NEMOGCM/NEMO/NST_SRC/agrif_opa_sponge.F90
===================================================================
--- branches/2015/dev_r5803_NOC_WAD/NEMOGCM/NEMO/NST_SRC/agrif_opa_sponge.F90	(revision 5870)
+++ branches/2015/dev_r5803_NOC_WAD/NEMOGCM/NEMO/NST_SRC/agrif_opa_sponge.F90	(revision 6141)
@@ -2,4 +2,10 @@
 
 MODULE agrif_opa_sponge
+   !!======================================================================
+   !!                ***  MODULE agrif_opa_update  ***
+   !! AGRIF :   
+   !!======================================================================
+   !! History :  
+   !!----------------------------------------------------------------------
 #if defined key_agrif  && ! defined key_offline
    USE par_oce
@@ -17,12 +23,9 @@
    PUBLIC interptsn_sponge, interpun_sponge, interpvn_sponge
 
-   !! * Substitutions
-#  include "domzgr_substitute.h90"
    !!----------------------------------------------------------------------
-   !! NEMO/NST 3.3 , NEMO Consortium (2010)
+   !! NEMO/NST 3.7 , NEMO Consortium (2015)
    !! $Id$
    !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
-
 CONTAINS
 
@@ -31,7 +34,7 @@
       !!   *** ROUTINE Agrif_Sponge_Tra ***
       !!---------------------------------------------
-      !!
       REAL(wp) :: timecoeff
-
+      !!---------------------------------------------
+      !
 #if defined SPONGE
       timecoeff = REAL(Agrif_NbStepint(),wp)/Agrif_rhot()
@@ -46,13 +49,14 @@
       Agrif_UseSpecialValue = .FALSE.
 #endif
-
+      !
    END SUBROUTINE Agrif_Sponge_Tra
 
+
    SUBROUTINE Agrif_Sponge_dyn
       !!---------------------------------------------
       !!   *** ROUTINE Agrif_Sponge_dyn ***
       !!---------------------------------------------
-      !!
       REAL(wp) :: timecoeff
+      !!---------------------------------------------
 
 #if defined SPONGE
@@ -72,6 +76,7 @@
       Agrif_UseSpecialValue = .FALSE.
 #endif
-
+      !
    END SUBROUTINE Agrif_Sponge_dyn
+
 
    SUBROUTINE Agrif_Sponge
@@ -183,6 +188,7 @@
       !
 #endif
-
+      !
    END SUBROUTINE Agrif_Sponge
+
 
    SUBROUTINE interptsn_sponge(tabres,i1,i2,j1,j2,k1,k2,n1,n2,before)
@@ -193,6 +199,5 @@
       REAL(wp), DIMENSION(i1:i2,j1:j2,k1:k2,n1:n2), INTENT(inout) :: tabres
       LOGICAL, INTENT(in) :: before
-
-
+      !
       INTEGER  ::   ji, jj, jk, jn   ! dummy loop indices
       INTEGER  ::   iku, ikv
@@ -201,8 +206,8 @@
       REAL(wp), DIMENSION(i1:i2,j1:j2,k1:k2,n1:n2) ::tsbdiff
       !
-      IF (before) THEN
+      IF( before ) THEN
          tabres(i1:i2,j1:j2,k1:k2,n1:n2) = tsn(i1:i2,j1:j2,k1:k2,n1:n2)
       ELSE   
-   
+         !
          tsbdiff(:,:,:,:) = tsb(i1:i2,j1:j2,:,:) - tabres(:,:,:,:)    
          DO jn = 1, jpts            
@@ -210,11 +215,11 @@
                DO jj = j1,j2-1
                   DO ji = i1,i2-1
-                     zabe1 = fsaht_spu(ji,jj) * umask(ji,jj,jk) * e2_e1u(ji,jj) * fse3u_n(ji,jj,jk)
-                     zabe2 = fsaht_spv(ji,jj) * vmask(ji,jj,jk) * e1_e2v(ji,jj) * fse3v_n(ji,jj,jk)
+                     zabe1 = fsaht_spu(ji,jj) * umask(ji,jj,jk) * e2_e1u(ji,jj) * e3u_n(ji,jj,jk)
+                     zabe2 = fsaht_spv(ji,jj) * vmask(ji,jj,jk) * e1_e2v(ji,jj) * e3v_n(ji,jj,jk)
                      ztu(ji,jj,jk) = zabe1 * ( tsbdiff(ji+1,jj  ,jk,jn) - tsbdiff(ji,jj,jk,jn) ) 
                      ztv(ji,jj,jk) = zabe2 * ( tsbdiff(ji  ,jj+1,jk,jn) - tsbdiff(ji,jj,jk,jn) )
-                  ENDDO
-               ENDDO
-
+                  END DO
+               END DO
+               !
                IF( ln_zps ) THEN      ! set gradient at partial step level
                   DO jj = j1,j2-1
@@ -223,21 +228,16 @@
                         iku = mbku(ji,jj)
                         ikv = mbkv(ji,jj)
-                        IF( iku == jk ) THEN
-                           ztu(ji,jj,jk) = 0._wp
-                        ENDIF
-                        IF( ikv == jk ) THEN
-                           ztv(ji,jj,jk) = 0._wp
-                        ENDIF
+                        IF( iku == jk )   ztu(ji,jj,jk) = 0._wp
+                        IF( ikv == jk )   ztv(ji,jj,jk) = 0._wp
                      END DO
                   END DO
                ENDIF
-            ENDDO
-
+            END DO
+            !
             DO jk = 1, jpkm1
                DO jj = j1+1,j2-1
                   DO ji = i1+1,i2-1
-
                      IF (.NOT. tabspongedone_tsn(ji,jj)) THEN 
-                        zbtr = r1_e1e2t(ji,jj) / fse3t_n(ji,jj,jk)
+                        zbtr = r1_e1e2t(ji,jj) / e3t_n(ji,jj,jk)
                         ! horizontal diffusive trends
                         ztsa = zbtr * (  ztu(ji,jj,jk) - ztu(ji-1,jj,jk) + ztv(ji,jj,jk) - ztv(ji  ,jj-1,jk)  )
@@ -245,16 +245,16 @@
                         tsa(ji,jj,jk,jn) = tsa(ji,jj,jk,jn) + ztsa
                      ENDIF
-
-                  ENDDO
-               ENDDO
-
-            ENDDO
-         ENDDO
-
+                  END DO
+               END DO
+            END DO
+            !
+         END DO
+         !
          tabspongedone_tsn(i1+1:i2-1,j1+1:j2-1) = .TRUE.
-
-      ENDIF
-
+         !
+      ENDIF
+      !
    END SUBROUTINE interptsn_sponge
+
 
    SUBROUTINE interpun_sponge(tabres,i1,i2,j1,j2,k1,k2, before)
@@ -273,13 +273,11 @@
       REAL(wp), DIMENSION(i1:i2,j1:j2,k1:k2) :: rotdiff, hdivdiff
       INTEGER :: jmax
-      !
-
-
-      IF (before) THEN
+      !!---------------------------------------------    
+      !
+      IF( before ) THEN
          tabres = un(i1:i2,j1:j2,:)
       ELSE
-
          ubdiff(i1:i2,j1:j2,:) = (ub(i1:i2,j1:j2,:) - tabres(:,:,:))*umask(i1:i2,j1:j2,:)
-
+         !
          DO jk = 1, jpkm1                                 ! Horizontal slab
             !                                             ! ===============
@@ -290,7 +288,7 @@
             DO jj = j1,j2
                DO ji = i1+1,i2   ! vector opt.
-                  zbtr = r1_e1e2t(ji,jj) / fse3t_n(ji,jj,jk) * fsahm_spt(ji,jj)
-                  hdivdiff(ji,jj,jk) = (  e2u(ji  ,jj)*fse3u_n(ji  ,jj,jk) * ubdiff(ji  ,jj,jk) &
-                                     &   -e2u(ji-1,jj)*fse3u_n(ji-1,jj,jk) * ubdiff(ji-1,jj,jk) ) * zbtr
+                  zbtr = r1_e1e2t(ji,jj) / e3t_n(ji,jj,jk) * fsahm_spt(ji,jj)
+                  hdivdiff(ji,jj,jk) = (  e2u(ji  ,jj)*e3u_n(ji  ,jj,jk) * ubdiff(ji  ,jj,jk) &
+                                     &   -e2u(ji-1,jj)*e3u_n(ji-1,jj,jk) * ubdiff(ji-1,jj,jk) ) * zbtr
                END DO
             END DO
@@ -298,5 +296,5 @@
             DO jj = j1,j2-1
                DO ji = i1,i2   ! vector opt.
-                  zbtr = r1_e1e2f(ji,jj) * fse3f_n(ji,jj,jk) * fsahm_spf(ji,jj)
+                  zbtr = r1_e1e2f(ji,jj) * e3f_n(ji,jj,jk) * fsahm_spf(ji,jj)
                   rotdiff(ji,jj,jk) = (-e1u(ji,jj+1) * ubdiff(ji,jj+1,jk) &
                                        +e1u(ji,jj  ) * ubdiff(ji,jj  ,jk) & 
@@ -304,10 +302,6 @@
                END DO
             END DO
-         ENDDO
-
-         !
-
-
-
+         END DO
+         !
          DO jj = j1+1, j2-1
             DO ji = i1+1, i2-1   ! vector opt.
@@ -318,5 +312,5 @@
                      ze1v = hdivdiff(ji,jj,jk)
                      ! horizontal diffusive trends
-                     zua = - ( ze2u - rotdiff (ji,jj-1,jk)) / ( e2u(ji,jj) * fse3u_n(ji,jj,jk) )   &
+                     zua = - ( ze2u - rotdiff (ji,jj-1,jk)) / ( e2u(ji,jj) * e3u_n(ji,jj,jk) )   &
                            + ( hdivdiff(ji+1,jj,jk) - ze1v  ) / e1u(ji,jj)
 
@@ -344,5 +338,5 @@
 
                      ! horizontal diffusive trends
-                     zva = + ( ze2u - rotdiff (ji-1,jj,jk)) / ( e1v(ji,jj) * fse3v_n(ji,jj,jk) )   &
+                     zva = + ( ze2u - rotdiff (ji-1,jj,jk)) / ( e1v(ji,jj) * e3v_n(ji,jj,jk) )   &
                            + ( hdivdiff(ji,jj+1,jk) - ze1v  ) / e2v(ji,jj)
 
@@ -351,14 +345,12 @@
                   END DO
                ENDIF
-
-            END DO
-         END DO
-
-
+               !
+            END DO
+         END DO
+         !
          tabspongedone_v(i1+1:i2,j1+1:jmax) = .TRUE.
-
-      ENDIF
-
-
+         !
+      ENDIF
+      !
    END SUBROUTINE interpun_sponge
 
@@ -372,20 +364,18 @@
       LOGICAL, INTENT(in) :: before
       INTEGER, INTENT(in) :: nb , ndir
-
-      INTEGER :: ji,jj,jk
-
-      REAL(wp) :: ze2u, ze1v, zua, zva, zbtr
-
+      !
+      INTEGER  ::   ji, jj, jk
+      REAL(wp) ::   ze2u, ze1v, zua, zva, zbtr
       REAL(wp), DIMENSION(i1:i2,j1:j2,k1:k2) :: vbdiff
       REAL(wp), DIMENSION(i1:i2,j1:j2,k1:k2) :: rotdiff, hdivdiff
       INTEGER :: imax
-      !
-
-      IF (before) THEN 
+      !!--------------------------------------------- 
+
+      IF( before ) THEN 
          tabres = vn(i1:i2,j1:j2,:)
       ELSE
-
+         !
          vbdiff(i1:i2,j1:j2,:) = (vb(i1:i2,j1:j2,:) - tabres(:,:,:))*vmask(i1:i2,j1:j2,:)
-
+         !
          DO jk = 1, jpkm1                                 ! Horizontal slab
             !                                             ! ===============
@@ -396,18 +386,17 @@
             DO jj = j1+1,j2
                DO ji = i1,i2   ! vector opt.
-                  zbtr = r1_e1e2t(ji,jj) / fse3t_n(ji,jj,jk) * fsahm_spt(ji,jj)
-                  hdivdiff(ji,jj,jk) = ( e1v(ji,jj  ) * fse3v(ji,jj  ,jk) * vbdiff(ji,jj  ,jk)  &
-                                     &  -e1v(ji,jj-1) * fse3v(ji,jj-1,jk) * vbdiff(ji,jj-1,jk)  ) * zbtr
+                  zbtr = r1_e1e2t(ji,jj) / e3t_n(ji,jj,jk) * fsahm_spt(ji,jj)
+                  hdivdiff(ji,jj,jk) = ( e1v(ji,jj  ) * e3v_n(ji,jj  ,jk) * vbdiff(ji,jj  ,jk)  &
+                                     &  -e1v(ji,jj-1) * e3v_n(ji,jj-1,jk) * vbdiff(ji,jj-1,jk)  ) * zbtr
                END DO
             END DO
             DO jj = j1,j2
                DO ji = i1,i2-1   ! vector opt.
-                  zbtr = r1_e1e2f(ji,jj) * fse3f_n(ji,jj,jk) * fsahm_spf(ji,jj)
+                  zbtr = r1_e1e2f(ji,jj) * e3f_n(ji,jj,jk) * fsahm_spf(ji,jj)
                   rotdiff(ji,jj,jk) = ( e2v(ji+1,jj) * vbdiff(ji+1,jj,jk) & 
-                                    &  -e2v(ji  ,jj) * vbdiff(ji  ,jj,jk) &
-                                    & ) * fmask(ji,jj,jk) * zbtr
-               END DO
-            END DO
-         ENDDO
+                                    &  -e2v(ji  ,jj) * vbdiff(ji  ,jj,jk)  ) * fmask(ji,jj,jk) * zbtr
+               END DO
+            END DO
+         END DO
 
          !                                                ! ===============
@@ -415,40 +404,27 @@
 
          imax = i2-1
-         IF ((nbondi == 1).OR.(nbondi == 2)) imax = MIN(imax,nlci-3)
+         IF ((nbondi == 1).OR.(nbondi == 2))   imax = MIN(imax,nlci-3)
 
          DO jj = j1+1, j2
             DO ji = i1+1, imax   ! vector opt.
-               IF (.NOT. tabspongedone_u(ji,jj)) THEN
-                  DO jk = 1, jpkm1                                 ! Horizontal slab
-                     ze2u = rotdiff (ji,jj,jk)
-                     ze1v = hdivdiff(ji,jj,jk)
-                     ! horizontal diffusive trends
-                     zua = - ( ze2u - rotdiff (ji,jj-1,jk)) / ( e2u(ji,jj) * fse3u_n(ji,jj,jk) ) + ( hdivdiff(ji+1,jj,jk) - ze1v) &
-                           / e1u(ji,jj)
-
-
-                     ! add it to the general momentum trends
-                     ua(ji,jj,jk) = ua(ji,jj,jk) + zua
-                  END DO
-
-               ENDIF
-            END DO
-         END DO
-
+               IF( .NOT. tabspongedone_u(ji,jj) ) THEN
+                  DO jk = 1, jpkm1
+                     ua(ji,jj,jk) = ua(ji,jj,jk)                                                               &
+                        & - ( rotdiff (ji  ,jj,jk) - rotdiff (ji,jj-1,jk)) / ( e2u(ji,jj) * e3u_n(ji,jj,jk) )  &
+                        & + ( hdivdiff(ji+1,jj,jk) - hdivdiff(ji,jj  ,jk)) * r1_e1u(ji,jj)
+                  END DO
+               ENDIF
+            END DO
+         END DO
+         !
          tabspongedone_u(i1+1:imax,j1+1:j2) = .TRUE.
-
+         !
          DO jj = j1+1, j2-1
             DO ji = i1+1, i2-1   ! vector opt.
-               IF (.NOT. tabspongedone_v(ji,jj)) THEN
-                  DO jk = 1, jpkm1                                 ! Horizontal slab
-                     ze2u = rotdiff (ji,jj,jk)
-                     ze1v = hdivdiff(ji,jj,jk)
-                     ! horizontal diffusive trends
-
-                     zva = + ( ze2u - rotdiff (ji-1,jj,jk)) / ( e1v(ji,jj) * fse3v_n(ji,jj,jk) ) + ( hdivdiff(ji,jj+1,jk) - ze1v) &
-                           / e2v(ji,jj)
-
-                     ! add it to the general momentum trends
-                     va(ji,jj,jk) = va(ji,jj,jk) + zva
+               IF( .NOT. tabspongedone_v(ji,jj) ) THEN
+                  DO jk = 1, jpkm1
+                     va(ji,jj,jk) = va(ji,jj,jk)                                                                  &
+                        &  + ( rotdiff (ji,jj  ,jk) - rotdiff (ji-1,jj,jk) ) / ( e1v(ji,jj) * e3v_n(ji,jj,jk) )   &
+                        &  + ( hdivdiff(ji,jj+1,jk) - hdivdiff(ji  ,jj,jk) ) * r1_e2v(ji,jj)
                   END DO
                ENDIF
@@ -457,10 +433,9 @@
          tabspongedone_v(i1+1:i2-1,j1+1:j2-1) = .TRUE.
       ENDIF
-
+      !
    END SUBROUTINE interpvn_sponge
 
 #else
 CONTAINS
-
    SUBROUTINE agrif_opa_sponge_empty
       !!---------------------------------------------
@@ -471,3 +446,4 @@
 #endif
 
+   !!======================================================================
 END MODULE agrif_opa_sponge
