Index: branches/2015/dev_r5776_UKMO2_OBS_efficiency_improvs/NEMOGCM/NEMO/NST_SRC/agrif_opa_interp.F90
===================================================================
--- branches/2015/dev_r5776_UKMO2_OBS_efficiency_improvs/NEMOGCM/NEMO/NST_SRC/agrif_opa_interp.F90	(revision 5795)
+++ branches/2015/dev_r5776_UKMO2_OBS_efficiency_improvs/NEMOGCM/NEMO/NST_SRC/agrif_opa_interp.F90	(revision 6041)
@@ -22,5 +22,4 @@
    USE oce
    USE dom_oce      
-   USE sol_oce
    USE agrif_oce
    USE phycst
@@ -29,5 +28,4 @@
    USE lib_mpp
    USE wrk_nemo
-   USE dynspg_oce
    USE zdf_oce
  
@@ -38,5 +36,5 @@
 
    PUBLIC   Agrif_tra, Agrif_dyn, Agrif_ssh, Agrif_dyn_ts, Agrif_ssh_ts, Agrif_dta_ts
-   PUBLIC   interpun, interpvn, interpun2d, interpvn2d 
+   PUBLIC   interpun, interpvn
    PUBLIC   interptsn,  interpsshn
    PUBLIC   interpunb, interpvnb, interpub2b, interpvb2b
@@ -80,13 +78,10 @@
       !!
       INTEGER :: ji,jj,jk, j1,j2, i1,i2
-      REAL(wp) :: timeref
-      REAL(wp) :: z2dt, znugdt
-      REAL(wp) :: zrhox, zrhoy
-      REAL(wp), POINTER, DIMENSION(:,:) :: spgv1, spgu1
+      REAL(wp), POINTER, DIMENSION(:,:) :: zub, zvb
       !!----------------------------------------------------------------------  
 
       IF( Agrif_Root() )   RETURN
 
-      CALL wrk_alloc( jpi, jpj, spgv1, spgu1 )
+      CALL wrk_alloc( jpi, jpj, zub, zvb )
 
       Agrif_SpecialValue=0.
@@ -96,22 +91,6 @@
       CALL Agrif_Bc_variable(vn_interp_id,procname=interpvn)
 
-#if defined key_dynspg_flt
-      CALL Agrif_Bc_variable(e1u_id,calledweight=1., procname=interpun2d)
-      CALL Agrif_Bc_variable(e2v_id,calledweight=1., procname=interpvn2d)
-#endif
-
       Agrif_UseSpecialValue = .FALSE.
-
-      zrhox = Agrif_Rhox()
-      zrhoy = Agrif_Rhoy()
-
-      timeref = 1.
-      ! time step: leap-frog
-      z2dt = 2. * rdt
-      ! time step: Euler if restart from rest
-      IF( neuler == 0 .AND. kt == nit000 ) z2dt = rdt
-      ! coefficients
-      znugdt =  grav * z2dt    
-
+ 
       ! prevent smoothing in ghost cells
       i1=1
@@ -126,295 +105,279 @@
 
       IF((nbondi == -1).OR.(nbondi == 2)) THEN
-#if defined key_dynspg_flt
-         DO jk=1,jpkm1
+
+         ! Smoothing
+         ! ---------
+         IF ( .NOT.ln_dynspg_ts ) THEN ! Store transport
+            ua_b(2,:)=0._wp
+            DO jk=1,jpkm1
+               DO jj=1,jpj
+                  ua_b(2,jj) = ua_b(2,jj) + fse3u_a(2,jj,jk) * ua(2,jj,jk)
+               END DO
+            END DO
+            DO jj=1,jpj
+               ua_b(2,jj) = ua_b(2,jj) * hur_a(2,jj)            
+            END DO
+         ENDIF
+
+         DO jk=1,jpkm1                 ! Smooth
             DO jj=j1,j2
-               ua(2,jj,jk) = (ua(2,jj,jk) - z2dt * znugdt * laplacu(2,jj))*umask(2,jj,jk)
-            END DO
-         END DO
-
-         spgu(2,:)=0.
-
+               ua(2,jj,jk) = 0.25_wp*(ua(1,jj,jk)+2._wp*ua(2,jj,jk)+ua(3,jj,jk))
+               ua(2,jj,jk) = ua(2,jj,jk) * umask(2,jj,jk)
+            END DO
+         END DO
+
+         zub(2,:)=0._wp                ! Correct transport
          DO jk=1,jpkm1
             DO jj=1,jpj
-               spgu(2,jj)=spgu(2,jj)+fse3u(2,jj,jk)*ua(2,jj,jk)
-            END DO
-         END DO
-
+               zub(2,jj) = zub(2,jj) + fse3u_a(2,jj,jk) * ua(2,jj,jk)
+            END DO
+         END DO
          DO jj=1,jpj
-            IF (umask(2,jj,1).NE.0.) THEN
-               spgu(2,jj)=spgu(2,jj)/hu(2,jj)
-            ENDIF
-         END DO
-#else
-         spgu(2,:) = ua_b(2,:)
-#endif
-
-         DO jk=1,jpkm1
+            zub(2,jj) = zub(2,jj) * hur_a(2,jj)
+         END DO
+
+         DO jk=1,jpkm1
+            DO jj=1,jpj
+               ua(2,jj,jk) = (ua(2,jj,jk)+ua_b(2,jj)-zub(2,jj))*umask(2,jj,jk)
+            END DO
+         END DO
+
+         ! Set tangential velocities to time splitting estimate
+         !-----------------------------------------------------
+         IF ( ln_dynspg_ts) THEN
+            zvb(2,:)=0._wp
+            DO jk=1,jpkm1
+               DO jj=1,jpj
+                  zvb(2,jj) = zvb(2,jj) + fse3v_a(2,jj,jk) * va(2,jj,jk)
+               END DO
+            END DO
+            DO jj=1,jpj
+               zvb(2,jj) = zvb(2,jj) * hvr_a(2,jj)
+            END DO
+            DO jk=1,jpkm1
+               DO jj=1,jpj
+                  va(2,jj,jk) = (va(2,jj,jk)+va_b(2,jj)-zvb(2,jj))*vmask(2,jj,jk)
+               END DO
+            END DO
+         ENDIF
+
+         ! Mask domain edges:
+         !-------------------
+         DO jk=1,jpkm1
+            DO jj=1,jpj
+               ua(1,jj,jk) = 0._wp
+               va(1,jj,jk) = 0._wp
+            END DO
+         END DO         
+
+      ENDIF
+
+      IF((nbondi == 1).OR.(nbondi == 2)) THEN
+
+         ! Smoothing
+         ! ---------
+         IF ( .NOT.ln_dynspg_ts ) THEN ! Store transport
+            ua_b(nlci-2,:)=0._wp
+            DO jk=1,jpkm1
+               DO jj=1,jpj
+                  ua_b(nlci-2,jj) = ua_b(nlci-2,jj) + fse3u_a(nlci-2,jj,jk) * ua(nlci-2,jj,jk)
+               END DO
+            END DO
+            DO jj=1,jpj
+               ua_b(nlci-2,jj) = ua_b(nlci-2,jj) * hur_a(nlci-2,jj)            
+            END DO
+         ENDIF
+
+         DO jk=1,jpkm1                 ! Smooth
             DO jj=j1,j2
-               ua(2,jj,jk) = 0.25*(ua(1,jj,jk)+2.*ua(2,jj,jk)+ua(3,jj,jk))
-               ua(2,jj,jk) = ua(2,jj,jk) * umask(2,jj,jk)
-            END DO
-         END DO
-
-         spgu1(2,:)=0.
-
+               ua(nlci-2,jj,jk) = 0.25_wp*(ua(nlci-3,jj,jk)+2._wp*ua(nlci-2,jj,jk)+ua(nlci-1,jj,jk))
+               ua(nlci-2,jj,jk) = ua(nlci-2,jj,jk) * umask(nlci-2,jj,jk)
+            END DO
+         END DO
+
+         zub(nlci-2,:)=0._wp           ! Correct transport
          DO jk=1,jpkm1
             DO jj=1,jpj
-               spgu1(2,jj)=spgu1(2,jj)+fse3u(2,jj,jk)*ua(2,jj,jk)
-            END DO
-         END DO
-
+               zub(nlci-2,jj) = zub(nlci-2,jj) + fse3u_a(nlci-2,jj,jk) * ua(nlci-2,jj,jk)
+            END DO
+         END DO
          DO jj=1,jpj
-            IF (umask(2,jj,1).NE.0.) THEN
-               spgu1(2,jj)=spgu1(2,jj)/hu(2,jj)
-            ENDIF
-         END DO
-
-         DO jk=1,jpkm1
-            DO jj=j1,j2
-               ua(2,jj,jk) = (ua(2,jj,jk)+spgu(2,jj)-spgu1(2,jj))*umask(2,jj,jk)
-            END DO
-         END DO
-
-#if defined key_dynspg_ts
+            zub(nlci-2,jj) = zub(nlci-2,jj) * hur_a(nlci-2,jj)
+         END DO
+
+         DO jk=1,jpkm1
+            DO jj=1,jpj
+               ua(nlci-2,jj,jk) = (ua(nlci-2,jj,jk)+ua_b(nlci-2,jj)-zub(nlci-2,jj))*umask(nlci-2,jj,jk)
+            END DO
+         END DO
+
          ! Set tangential velocities to time splitting estimate
-         spgv1(2,:)=0.
-         DO jk=1,jpkm1
+         !-----------------------------------------------------
+         IF ( ln_dynspg_ts) THEN
+            zvb(nlci-1,:)=0._wp
+            DO jk=1,jpkm1
+               DO jj=1,jpj
+                  zvb(nlci-1,jj) = zvb(nlci-1,jj) + fse3v_a(nlci-1,jj,jk) * va(nlci-1,jj,jk)
+               END DO
+            END DO
             DO jj=1,jpj
-               spgv1(2,jj)=spgv1(2,jj)+fse3v_a(2,jj,jk)*va(2,jj,jk)
-            END DO
-         END DO
-         DO jj=1,jpj
-            spgv1(2,jj)=spgv1(2,jj)*hvr_a(2,jj)
-         END DO
+               zvb(nlci-1,jj) = zvb(nlci-1,jj) * hvr_a(nlci-1,jj)
+            END DO
+            DO jk=1,jpkm1
+               DO jj=1,jpj
+                  va(nlci-1,jj,jk) = (va(nlci-1,jj,jk)+va_b(nlci-1,jj)-zvb(nlci-1,jj))*vmask(nlci-1,jj,jk)
+               END DO
+            END DO
+         ENDIF
+
+         ! Mask domain edges:
+         !-------------------
          DO jk=1,jpkm1
             DO jj=1,jpj
-               va(2,jj,jk) = (va(2,jj,jk)+va_b(2,jj)-spgv1(2,jj))*vmask(2,jj,jk)
-            END DO
-         END DO
-#endif
-
-      ENDIF
-
-      IF((nbondi == 1).OR.(nbondi == 2)) THEN
-#if defined key_dynspg_flt
-         DO jk=1,jpkm1
-            DO jj=j1,j2
-               ua(nlci-2,jj,jk) = (ua(nlci-2,jj,jk)- z2dt * znugdt * laplacu(nlci-2,jj))*umask(nlci-2,jj,jk)
-            END DO
-         END DO
-         spgu(nlci-2,:)=0.
-         DO jk=1,jpkm1
-            DO jj=1,jpj
-               spgu(nlci-2,jj)=spgu(nlci-2,jj)+fse3u(nlci-2,jj,jk)*ua(nlci-2,jj,jk)
-            ENDDO
-         ENDDO
-         DO jj=1,jpj
-            IF (umask(nlci-2,jj,1).NE.0.) THEN
-               spgu(nlci-2,jj)=spgu(nlci-2,jj)/hu(nlci-2,jj)
-            ENDIF
-         END DO
-#else
-         spgu(nlci-2,:) = ua_b(nlci-2,:)
-#endif
-         DO jk=1,jpkm1
-            DO jj=j1,j2
-               ua(nlci-2,jj,jk) = 0.25*(ua(nlci-3,jj,jk)+2.*ua(nlci-2,jj,jk)+ua(nlci-1,jj,jk))
-
-               ua(nlci-2,jj,jk) = ua(nlci-2,jj,jk) * umask(nlci-2,jj,jk)
-
-            END DO
-         END DO
-         spgu1(nlci-2,:)=0.
-         DO jk=1,jpkm1
-            DO jj=1,jpj
-               spgu1(nlci-2,jj)=spgu1(nlci-2,jj)+fse3u(nlci-2,jj,jk)*ua(nlci-2,jj,jk)*umask(nlci-2,jj,jk)
-            END DO
-         END DO
-         DO jj=1,jpj
-            IF (umask(nlci-2,jj,1).NE.0.) THEN
-               spgu1(nlci-2,jj)=spgu1(nlci-2,jj)/hu(nlci-2,jj)
-            ENDIF
-         END DO
-         DO jk=1,jpkm1
-            DO jj=j1,j2
-               ua(nlci-2,jj,jk) = (ua(nlci-2,jj,jk)+spgu(nlci-2,jj)-spgu1(nlci-2,jj))*umask(nlci-2,jj,jk)
-            END DO
-         END DO
-
-#if defined key_dynspg_ts
+               ua(nlci-1,jj,jk) = 0._wp
+               va(nlci  ,jj,jk) = 0._wp
+            END DO
+         END DO 
+
+      ENDIF
+
+      IF((nbondj == -1).OR.(nbondj == 2)) THEN
+
+         ! Smoothing
+         ! ---------
+         IF ( .NOT.ln_dynspg_ts ) THEN ! Store transport
+            va_b(:,2)=0._wp
+            DO jk=1,jpkm1
+               DO ji=1,jpi
+                  va_b(ji,2) = va_b(ji,2) + fse3v_a(ji,2,jk) * va(ji,2,jk)
+               END DO
+            END DO
+            DO ji=1,jpi
+               va_b(ji,2) = va_b(ji,2) * hvr_a(ji,2)            
+            END DO
+         ENDIF
+
+         DO jk=1,jpkm1                 ! Smooth
+            DO ji=i1,i2
+               va(ji,2,jk)=0.25_wp*(va(ji,1,jk)+2._wp*va(ji,2,jk)+va(ji,3,jk))
+               va(ji,2,jk)=va(ji,2,jk)*vmask(ji,2,jk)
+            END DO
+         END DO
+
+         zvb(:,2)=0._wp                ! Correct transport
+         DO jk=1,jpkm1
+            DO ji=1,jpi
+               zvb(ji,2) = zvb(ji,2) + fse3v_a(ji,2,jk) * va(ji,2,jk) * vmask(ji,2,jk)
+            END DO
+         END DO
+         DO ji=1,jpi
+            zvb(ji,2) = zvb(ji,2) * hvr_a(ji,2)
+         END DO
+         DO jk=1,jpkm1
+            DO ji=1,jpi
+               va(ji,2,jk) = (va(ji,2,jk)+va_b(ji,2)-zvb(ji,2))*vmask(ji,2,jk)
+            END DO
+         END DO
+
          ! Set tangential velocities to time splitting estimate
-         spgv1(nlci-1,:)=0._wp
-         DO jk=1,jpkm1
-            DO jj=1,jpj
-               spgv1(nlci-1,jj)=spgv1(nlci-1,jj)+fse3v_a(nlci-1,jj,jk)*va(nlci-1,jj,jk)*vmask(nlci-1,jj,jk)
-            END DO
-         END DO
-
-         DO jj=1,jpj
-            spgv1(nlci-1,jj)=spgv1(nlci-1,jj)*hvr_a(nlci-1,jj)
-         END DO
-
-         DO jk=1,jpkm1
-            DO jj=1,jpj
-               va(nlci-1,jj,jk) = (va(nlci-1,jj,jk)+va_b(nlci-1,jj)-spgv1(nlci-1,jj))*vmask(nlci-1,jj,jk)
-            END DO
-         END DO
-#endif
-
-      ENDIF
-
-      IF((nbondj == -1).OR.(nbondj == 2)) THEN
-
-#if defined key_dynspg_flt
-         DO jk=1,jpkm1
+         !-----------------------------------------------------
+         IF ( ln_dynspg_ts ) THEN
+            zub(:,2)=0._wp
+            DO jk=1,jpkm1
+               DO ji=1,jpi
+                  zub(ji,2) = zub(ji,2) + fse3u_a(ji,2,jk) * ua(ji,2,jk) * umask(ji,2,jk)
+               END DO
+            END DO
             DO ji=1,jpi
-               va(ji,2,jk) = (va(ji,2,jk) - z2dt * znugdt * laplacv(ji,2))*vmask(ji,2,jk)
-            END DO
-         END DO
-
-         spgv(:,2)=0.
-
+               zub(ji,2) = zub(ji,2) * hur_a(ji,2)
+            END DO
+
+            DO jk=1,jpkm1
+               DO ji=1,jpi
+                  ua(ji,2,jk) = (ua(ji,2,jk)+ua_b(ji,2)-zub(ji,2))*umask(ji,2,jk)
+               END DO
+            END DO
+         ENDIF
+
+         ! Mask domain edges:
+         !-------------------
          DO jk=1,jpkm1
             DO ji=1,jpi
-               spgv(ji,2)=spgv(ji,2)+fse3v(ji,2,jk)*va(ji,2,jk)
-            END DO
-         END DO
-
+               ua(ji,1,jk) = 0._wp
+               va(ji,1,jk) = 0._wp
+            END DO
+         END DO 
+
+      ENDIF
+
+      IF((nbondj == 1).OR.(nbondj == 2)) THEN
+         ! Smoothing
+         ! ---------
+         IF ( .NOT.ln_dynspg_ts ) THEN ! Store transport
+            va_b(:,nlcj-2)=0._wp
+            DO jk=1,jpkm1
+               DO ji=1,jpi
+                  va_b(ji,nlcj-2) = va_b(ji,nlcj-2) + fse3v_a(ji,nlcj-2,jk) * va(ji,nlcj-2,jk)
+               END DO
+            END DO
+            DO ji=1,jpi
+               va_b(ji,nlcj-2) = va_b(ji,nlcj-2) * hvr_a(ji,nlcj-2)            
+            END DO
+         ENDIF
+
+         DO jk=1,jpkm1                 ! Smooth
+            DO ji=i1,i2
+               va(ji,nlcj-2,jk)=0.25_wp*(va(ji,nlcj-3,jk)+2._wp*va(ji,nlcj-2,jk)+va(ji,nlcj-1,jk))
+               va(ji,nlcj-2,jk)=va(ji,nlcj-2,jk)*vmask(ji,nlcj-2,jk)
+            END DO
+         END DO
+
+         zvb(:,nlcj-2)=0._wp           ! Correct transport
+         DO jk=1,jpkm1
+            DO ji=1,jpi
+               zvb(ji,nlcj-2) = zvb(ji,nlcj-2) + fse3v_a(ji,nlcj-2,jk) * va(ji,nlcj-2,jk) * vmask(ji,nlcj-2,jk)
+            END DO
+         END DO
          DO ji=1,jpi
-            IF (vmask(ji,2,1).NE.0.) THEN
-               spgv(ji,2)=spgv(ji,2)/hv(ji,2)
-            ENDIF
-         END DO
-#else
-         spgv(:,2)=va_b(:,2)
-#endif
-
-         DO jk=1,jpkm1
-            DO ji=i1,i2
-               va(ji,2,jk)=0.25*(va(ji,1,jk)+2.*va(ji,2,jk)+va(ji,3,jk))
-               va(ji,2,jk)=va(ji,2,jk)*vmask(ji,2,jk)
-            END DO
-         END DO
-
-         spgv1(:,2)=0.
-
+            zvb(ji,nlcj-2) = zvb(ji,nlcj-2) * hvr_a(ji,nlcj-2)
+         END DO
          DO jk=1,jpkm1
             DO ji=1,jpi
-               spgv1(ji,2)=spgv1(ji,2)+fse3v(ji,2,jk)*va(ji,2,jk)*vmask(ji,2,jk)
-            END DO
-         END DO
-
-         DO ji=1,jpi
-            IF (vmask(ji,2,1).NE.0.) THEN
-               spgv1(ji,2)=spgv1(ji,2)/hv(ji,2)
-            ENDIF
-         END DO
-
-         DO jk=1,jpkm1
+               va(ji,nlcj-2,jk) = (va(ji,nlcj-2,jk)+va_b(ji,nlcj-2)-zvb(ji,nlcj-2))*vmask(ji,nlcj-2,jk)
+            END DO
+         END DO
+
+         ! Set tangential velocities to time splitting estimate
+         !-----------------------------------------------------
+         IF ( ln_dynspg_ts ) THEN
+            zub(:,nlcj-1)=0._wp
+            DO jk=1,jpkm1
+               DO ji=1,jpi
+                  zub(ji,nlcj-1) = zub(ji,nlcj-1) + fse3u_a(ji,nlcj-1,jk) * ua(ji,nlcj-1,jk) * umask(ji,nlcj-1,jk)
+               END DO
+            END DO
             DO ji=1,jpi
-               va(ji,2,jk) = (va(ji,2,jk)+spgv(ji,2)-spgv1(ji,2))*vmask(ji,2,jk)
-            END DO
-         END DO
-
-#if defined key_dynspg_ts
-         ! Set tangential velocities to time splitting estimate
-         spgu1(:,2)=0._wp
+               zub(ji,nlcj-1) = zub(ji,nlcj-1) * hur_a(ji,nlcj-1)
+            END DO
+
+            DO jk=1,jpkm1
+               DO ji=1,jpi
+                  ua(ji,nlcj-1,jk) = (ua(ji,nlcj-1,jk)+ua_b(ji,nlcj-1)-zub(ji,nlcj-1))*umask(ji,nlcj-1,jk)
+               END DO
+            END DO
+         ENDIF
+
+         ! Mask domain edges:
+         !-------------------
          DO jk=1,jpkm1
             DO ji=1,jpi
-               spgu1(ji,2)=spgu1(ji,2)+fse3u_a(ji,2,jk)*ua(ji,2,jk)*umask(ji,2,jk)
-            END DO
-         END DO
-
-         DO ji=1,jpi
-            spgu1(ji,2)=spgu1(ji,2)*hur_a(ji,2)
-         END DO
-
-         DO jk=1,jpkm1
-            DO ji=1,jpi
-               ua(ji,2,jk) = (ua(ji,2,jk)+ua_b(ji,2)-spgu1(ji,2))*umask(ji,2,jk)
-            END DO
-         END DO
-#endif
-      ENDIF
-
-      IF((nbondj == 1).OR.(nbondj == 2)) THEN
-
-#if defined key_dynspg_flt
-         DO jk=1,jpkm1
-            DO ji=1,jpi
-               va(ji,nlcj-2,jk) = (va(ji,nlcj-2,jk)-z2dt * znugdt * laplacv(ji,nlcj-2))*vmask(ji,nlcj-2,jk)
-            END DO
-         END DO
-
-
-         spgv(:,nlcj-2)=0.
-
-         DO jk=1,jpkm1
-            DO ji=1,jpi
-               spgv(ji,nlcj-2)=spgv(ji,nlcj-2)+fse3v(ji,nlcj-2,jk)*va(ji,nlcj-2,jk)
-            END DO
-         END DO
-
-         DO ji=1,jpi
-            IF (vmask(ji,nlcj-2,1).NE.0.) THEN
-               spgv(ji,nlcj-2)=spgv(ji,nlcj-2)/hv(ji,nlcj-2)
-            ENDIF
-         END DO
-
-#else
-         spgv(:,nlcj-2)=va_b(:,nlcj-2)
-#endif
-
-         DO jk=1,jpkm1
-            DO ji=i1,i2
-               va(ji,nlcj-2,jk)=0.25*(va(ji,nlcj-3,jk)+2.*va(ji,nlcj-2,jk)+va(ji,nlcj-1,jk))
-               va(ji,nlcj-2,jk) = va(ji,nlcj-2,jk) * vmask(ji,nlcj-2,jk)
-            END DO
-         END DO
-
-         spgv1(:,nlcj-2)=0.
-
-         DO jk=1,jpkm1
-            DO ji=1,jpi
-               spgv1(ji,nlcj-2)=spgv1(ji,nlcj-2)+fse3v(ji,nlcj-2,jk)*va(ji,nlcj-2,jk)
-            END DO
-         END DO
-
-         DO ji=1,jpi
-            IF (vmask(ji,nlcj-2,1).NE.0.) THEN
-               spgv1(ji,nlcj-2)=spgv1(ji,nlcj-2)/hv(ji,nlcj-2)
-            ENDIF
-         END DO
-
-         DO jk=1,jpkm1
-            DO ji=1,jpi
-               va(ji,nlcj-2,jk) = (va(ji,nlcj-2,jk)+spgv(ji,nlcj-2)-spgv1(ji,nlcj-2))*vmask(ji,nlcj-2,jk)
-            END DO
-         END DO
-
-#if defined key_dynspg_ts
-         ! Set tangential velocities to time splitting estimate
-         spgu1(:,nlcj-1)=0._wp
-         DO jk=1,jpkm1
-            DO ji=1,jpi
-               spgu1(ji,nlcj-1)=spgu1(ji,nlcj-1)+fse3u_a(ji,nlcj-1,jk)*ua(ji,nlcj-1,jk)
-            END DO
-         END DO
-
-         DO ji=1,jpi
-            spgu1(ji,nlcj-1)=spgu1(ji,nlcj-1)*hur_a(ji,nlcj-1)
-         END DO
-
-         DO jk=1,jpkm1
-            DO ji=1,jpi
-               ua(ji,nlcj-1,jk) = (ua(ji,nlcj-1,jk)+ua_b(ji,nlcj-1)-spgu1(ji,nlcj-1))*umask(ji,nlcj-1,jk)
-            END DO
-         END DO
-#endif
-
-      ENDIF
-      !
-      CALL wrk_dealloc( jpi, jpj, spgv1, spgu1 )
+               ua(ji,nlcj  ,jk) = 0._wp
+               va(ji,nlcj-1,jk) = 0._wp
+            END DO
+         END DO 
+
+      ENDIF
+      !
+      CALL wrk_dealloc( jpi, jpj, zub, zvb )
       !
    END SUBROUTINE Agrif_dyn
@@ -687,4 +650,5 @@
                   END DO
                END DO
+               tsa(nlci,j1:j2,k1:k2,jn) = 0._wp
             ENDDO
          ENDIF
@@ -706,4 +670,5 @@
                   END DO
                END DO
+               tsa(i1:i2,nlcj,k1:k2,jn) = 0._wp
             ENDDO
          ENDIF
@@ -724,4 +689,5 @@
                   END DO
                END DO
+               tsa(1,j1:j2,k1:k2,jn) = 0._wp
             END DO
          ENDIF
@@ -742,4 +708,5 @@
                   END DO
                END DO
+               tsa(i1:i2,1,k1:k2,jn) = 0._wp
             ENDDO
          ENDIF
@@ -828,37 +795,4 @@
    END SUBROUTINE interpun
 
-
-   SUBROUTINE interpun2d(ptab,i1,i2,j1,j2,before)
-      !!---------------------------------------------
-      !!   *** ROUTINE interpun ***
-      !!---------------------------------------------    
-      !
-      INTEGER, INTENT(in) :: i1,i2,j1,j2
-      REAL(wp), DIMENSION(i1:i2,j1:j2), INTENT(inout) :: ptab
-      LOGICAL, INTENT(in) :: before
-      !
-      INTEGER :: ji,jj
-      REAL(wp) :: ztref
-      REAL(wp) :: zrhoy	
-      !!---------------------------------------------    
-      !
-      ztref = 1.
-
-      IF (before) THEN 
-         DO jj=j1,j2
-            DO ji=i1,MIN(i2,nlci-1)
-               ptab(ji,jj) = e2u(ji,jj) * ((gcx(ji+1,jj) - gcx(ji,jj))/e1u(ji,jj)) 
-            END DO
-         END DO
-      ELSE
-         zrhoy = Agrif_Rhoy()
-         DO jj=j1,j2
-            laplacu(i1:i2,jj) = ztref * (ptab(i1:i2,jj)/(zrhoy*e2u(i1:i2,jj))) !*umask(i1:i2,jj,1)
-         END DO
-      ENDIF
-      ! 
-   END SUBROUTINE interpun2d
-
-
    SUBROUTINE interpvn(ptab,i1,i2,j1,j2,k1,k2, before)
       !!---------------------------------------------
@@ -895,35 +829,4 @@
       !        
    END SUBROUTINE interpvn
-
-   SUBROUTINE interpvn2d(ptab,i1,i2,j1,j2,before)
-      !!---------------------------------------------
-      !!   *** ROUTINE interpvn ***
-      !!---------------------------------------------    
-      !
-      INTEGER, INTENT(in) :: i1,i2,j1,j2
-      REAL(wp), DIMENSION(i1:i2,j1:j2), INTENT(inout) :: ptab
-      LOGICAL, INTENT(in) :: before
-      !
-      INTEGER :: ji,jj
-      REAL(wp) :: zrhox	
-      REAL(wp) :: ztref
-      !!---------------------------------------------    
-      ! 
-      ztref = 1.    
-      IF (before) THEN 
-         !interpv entre 1 et k2 et interpv2d en jpkp1
-         DO jj=j1,MIN(j2,nlcj-1)
-            DO ji=i1,i2
-               ptab(ji,jj) = e1v(ji,jj) * ((gcx(ji,jj+1) - gcx(ji,jj))/e2v(ji,jj)) * vmask(ji,jj,1)
-            END DO
-         END DO
-      ELSE           
-         zrhox = Agrif_Rhox()
-         DO ji=i1,i2
-            laplacv(ji,j1:j2) = ztref * (ptab(ji,j1:j2)/(zrhox*e1v(ji,j1:j2)))
-         END DO
-      ENDIF
-      !      
-   END SUBROUTINE interpvn2d
 
    SUBROUTINE interpunb(ptab,i1,i2,j1,j2,before,nb,ndir)
Index: branches/2015/dev_r5776_UKMO2_OBS_efficiency_improvs/NEMOGCM/NEMO/NST_SRC/agrif_opa_sponge.F90
===================================================================
--- branches/2015/dev_r5776_UKMO2_OBS_efficiency_improvs/NEMOGCM/NEMO/NST_SRC/agrif_opa_sponge.F90	(revision 5795)
+++ branches/2015/dev_r5776_UKMO2_OBS_efficiency_improvs/NEMOGCM/NEMO/NST_SRC/agrif_opa_sponge.F90	(revision 6041)
@@ -210,6 +210,6 @@
                DO jj = j1,j2-1
                   DO ji = i1,i2-1
-                     zabe1 = fsaht_spu(ji,jj) * umask(ji,jj,jk) * re2u_e1u(ji,jj) * fse3u_n(ji,jj,jk)
-                     zabe2 = fsaht_spv(ji,jj) * vmask(ji,jj,jk) * re1v_e2v(ji,jj) * fse3v_n(ji,jj,jk)
+                     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)
                      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) )
@@ -239,5 +239,5 @@
 
                      IF (.NOT. tabspongedone_tsn(ji,jj)) THEN 
-                        zbtr = r1_e12t(ji,jj) / fse3t_n(ji,jj,jk)
+                        zbtr = r1_e1e2t(ji,jj) / fse3t_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)  )
@@ -290,5 +290,5 @@
             DO jj = j1,j2
                DO ji = i1+1,i2   ! vector opt.
-                  zbtr = r1_e12t(ji,jj) / fse3t_n(ji,jj,jk) * fsahm_spt(ji,jj)
+                  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
@@ -298,5 +298,5 @@
             DO jj = j1,j2-1
                DO ji = i1,i2   ! vector opt.
-                  zbtr = r1_e12f(ji,jj) * fse3f_n(ji,jj,jk) * fsahm_spf(ji,jj)
+                  zbtr = r1_e1e2f(ji,jj) * fse3f_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) & 
@@ -396,5 +396,5 @@
             DO jj = j1+1,j2
                DO ji = i1,i2   ! vector opt.
-                  zbtr = r1_e12t(ji,jj) / fse3t_n(ji,jj,jk) * fsahm_spt(ji,jj)
+                  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
@@ -403,5 +403,5 @@
             DO jj = j1,j2
                DO ji = i1,i2-1   ! vector opt.
-                  zbtr = r1_e12f(ji,jj) * fse3f_n(ji,jj,jk) * fsahm_spf(ji,jj)
+                  zbtr = r1_e1e2f(ji,jj) * fse3f_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) &
Index: branches/2015/dev_r5776_UKMO2_OBS_efficiency_improvs/NEMOGCM/NEMO/NST_SRC/agrif_opa_update.F90
===================================================================
--- branches/2015/dev_r5776_UKMO2_OBS_efficiency_improvs/NEMOGCM/NEMO/NST_SRC/agrif_opa_update.F90	(revision 5795)
+++ branches/2015/dev_r5776_UKMO2_OBS_efficiency_improvs/NEMOGCM/NEMO/NST_SRC/agrif_opa_update.F90	(revision 6041)
@@ -11,5 +11,4 @@
    USE lib_mpp
    USE wrk_nemo  
-   USE dynspg_oce
    USE zdf_oce        ! vertical physics: ocean variables 
 
@@ -107,6 +106,5 @@
 # endif
 
-# if defined key_dynspg_ts
-      IF (ln_bt_fw) THEN
+      IF ( ln_dynspg_ts.AND.ln_bt_fw ) THEN
          ! Update time integrated transports
          IF (mod(nbcline,nbclineupdate) == 0) THEN
@@ -128,5 +126,4 @@
          ENDIF
       END IF
-# endif
       !
       nbcline = nbcline + 1
@@ -360,10 +357,10 @@
                !
                ! Update barotropic velocities:
-#if defined key_dynspg_ts
-               IF (.NOT.(lk_agrif_fstep.AND.(neuler==0))) THEN ! Add asselin part
-                  zcorr = tabres(ji,jj) - un_b(ji,jj)
-                  ub_b(ji,jj) = ub_b(ji,jj) + atfp * zcorr * umask(ji,jj,1)
-               END IF
-#endif               
+               IF ( .NOT.ln_dynspg_ts .OR. (ln_dynspg_ts.AND.(.NOT.ln_bt_fw)) ) THEN
+                  IF (.NOT.(lk_agrif_fstep.AND.(neuler==0))) THEN ! Add asselin part
+                     zcorr = tabres(ji,jj) - un_b(ji,jj)
+                     ub_b(ji,jj) = ub_b(ji,jj) + atfp * zcorr * umask(ji,jj,1)
+                  END IF
+               ENDIF             
                un_b(ji,jj) = tabres(ji,jj) * umask(ji,jj,1)
                !       
@@ -425,10 +422,10 @@
                !
                ! Update barotropic velocities:
-#if defined key_dynspg_ts
-               IF (.NOT.(lk_agrif_fstep.AND.(neuler==0))) THEN ! Add asselin part
-                  zcorr = tabres(ji,jj) - vn_b(ji,jj)
-                  vb_b(ji,jj) = vb_b(ji,jj) + atfp * zcorr * vmask(ji,jj,1)
-               END IF
-#endif               
+               IF ( .NOT.ln_dynspg_ts .OR. (ln_dynspg_ts.AND.(.NOT.ln_bt_fw)) ) THEN
+                  IF (.NOT.(lk_agrif_fstep.AND.(neuler==0))) THEN ! Add asselin part
+                     zcorr = tabres(ji,jj) - vn_b(ji,jj)
+                     vb_b(ji,jj) = vb_b(ji,jj) + atfp * zcorr * vmask(ji,jj,1)
+                  END IF
+               ENDIF              
                vn_b(ji,jj) = tabres(ji,jj) * vmask(ji,jj,1)
                !       
@@ -470,14 +467,15 @@
          END DO
       ELSE
-#if ! defined key_dynspg_ts
-         IF (.NOT.(lk_agrif_fstep.AND.(neuler==0))) THEN
-            DO jj=j1,j2
-               DO ji=i1,i2
-                  sshb(ji,jj) =   sshb(ji,jj) &
-                        & + atfp * ( tabres(ji,jj) - sshn(ji,jj) ) * tmask(ji,jj,1)
-               END DO
-            END DO
+         IF ( .NOT.ln_dynspg_ts .OR. (ln_dynspg_ts.AND.(.NOT.ln_bt_fw)) ) THEN
+            IF (.NOT.(lk_agrif_fstep.AND.(neuler==0))) THEN
+               DO jj=j1,j2
+                  DO ji=i1,i2
+                     sshb(ji,jj) =   sshb(ji,jj) &
+                           & + atfp * ( tabres(ji,jj) - sshn(ji,jj) ) * tmask(ji,jj,1)
+                  END DO
+               END DO
+            ENDIF
          ENDIF
-#endif
+
          DO jj=j1,j2
             DO ji=i1,i2
Index: branches/2015/dev_r5776_UKMO2_OBS_efficiency_improvs/NEMOGCM/NEMO/NST_SRC/agrif_top_interp.F90
===================================================================
--- branches/2015/dev_r5776_UKMO2_OBS_efficiency_improvs/NEMOGCM/NEMO/NST_SRC/agrif_top_interp.F90	(revision 5795)
+++ branches/2015/dev_r5776_UKMO2_OBS_efficiency_improvs/NEMOGCM/NEMO/NST_SRC/agrif_top_interp.F90	(revision 6041)
@@ -4,5 +4,4 @@
    USE oce
    USE dom_oce      
-   USE sol_oce
    USE agrif_oce
    USE agrif_top_sponge
Index: branches/2015/dev_r5776_UKMO2_OBS_efficiency_improvs/NEMOGCM/NEMO/NST_SRC/agrif_top_sponge.F90
===================================================================
--- branches/2015/dev_r5776_UKMO2_OBS_efficiency_improvs/NEMOGCM/NEMO/NST_SRC/agrif_top_sponge.F90	(revision 5795)
+++ branches/2015/dev_r5776_UKMO2_OBS_efficiency_improvs/NEMOGCM/NEMO/NST_SRC/agrif_top_sponge.F90	(revision 6041)
@@ -74,6 +74,6 @@
                DO jj = j1,j2-1
                   DO ji = i1,i2-1
-                     zabe1 = fsaht_spu(ji,jj) * umask(ji,jj,jk) * re2u_e1u(ji,jj) * fse3u_n(ji,jj,jk)
-                     zabe2 = fsaht_spv(ji,jj) * vmask(ji,jj,jk) * re1v_e2v(ji,jj) * fse3v_n(ji,jj,jk)
+                     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)
                      ztu(ji,jj) = zabe1 * ( trbdiff(ji+1,jj  ,jk,jn) - trbdiff(ji,jj,jk,jn) )
                      ztv(ji,jj) = zabe2 * ( trbdiff(ji  ,jj+1,jk,jn) - trbdiff(ji,jj,jk,jn) )
@@ -85,5 +85,5 @@
 
                      IF (.NOT. tabspongedone_trn(ji,jj)) THEN 
-                        zbtr = r1_e12t(ji,jj) / fse3t(ji,jj,jk)
+                        zbtr = r1_e1e2t(ji,jj) / fse3t(ji,jj,jk)
                         ! horizontal diffusive trends
                         ztra = zbtr * (  ztu(ji,jj) - ztu(ji-1,jj  ) + ztv(ji,jj) - ztv(ji  ,jj-1)  )
Index: branches/2015/dev_r5776_UKMO2_OBS_efficiency_improvs/NEMOGCM/NEMO/NST_SRC/agrif_user.F90
===================================================================
--- branches/2015/dev_r5776_UKMO2_OBS_efficiency_improvs/NEMOGCM/NEMO/NST_SRC/agrif_user.F90	(revision 5795)
+++ branches/2015/dev_r5776_UKMO2_OBS_efficiency_improvs/NEMOGCM/NEMO/NST_SRC/agrif_user.F90	(revision 6041)
@@ -104,5 +104,4 @@
    USE dom_oce
    USE nemogcm
-   USE sol_oce
    USE in_out_manager
    USE agrif_opa_update
@@ -172,5 +171,4 @@
    USE dom_oce
    USE nemogcm
-   USE sol_oce
    USE lib_mpp
    USE in_out_manager
@@ -210,18 +208,18 @@
    CALL Agrif_Bc_variable(vn_sponge_id,calledweight=1.,procname=interpvn_sponge)
 
-#if defined key_dynspg_ts
    Agrif_UseSpecialValue = .TRUE.
    CALL Agrif_Bc_variable(sshn_id,calledweight=1., procname=interpsshn )
 
-   Agrif_UseSpecialValue = ln_spc_dyn
-   CALL Agrif_Bc_variable(unb_id,calledweight=1.,procname=interpunb)
-   CALL Agrif_Bc_variable(vnb_id,calledweight=1.,procname=interpvnb)
-   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 ; hbdy_w(:) =0.e0
-   ubdy_e(:) = 0.e0 ; vbdy_e(:) = 0.e0 ; hbdy_e(:) =0.e0 
-   ubdy_n(:) = 0.e0 ; vbdy_n(:) = 0.e0 ; hbdy_n(:) =0.e0 
-   ubdy_s(:) = 0.e0 ; vbdy_s(:) = 0.e0 ; hbdy_s(:) =0.e0
-#endif
+   IF ( ln_dynspg_ts ) THEN
+      Agrif_UseSpecialValue = ln_spc_dyn
+      CALL Agrif_Bc_variable(unb_id,calledweight=1.,procname=interpunb)
+      CALL Agrif_Bc_variable(vnb_id,calledweight=1.,procname=interpvnb)
+      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 ; hbdy_w(:) =0.e0
+      ubdy_e(:) = 0.e0 ; vbdy_e(:) = 0.e0 ; hbdy_e(:) =0.e0 
+      ubdy_n(:) = 0.e0 ; vbdy_n(:) = 0.e0 ; hbdy_n(:) =0.e0 
+      ubdy_s(:) = 0.e0 ; vbdy_s(:) = 0.e0 ; hbdy_s(:) =0.e0
+   ENDIF
 
    Agrif_UseSpecialValue = .FALSE. 
@@ -278,4 +276,17 @@
          ENDIF
       ENDIF
+
+      ! Check free surface scheme
+      IF ( ( Agrif_Parent(ln_dynspg_ts ).AND.ln_dynspg_exp ).OR.&
+         & ( Agrif_Parent(ln_dynspg_exp).AND.ln_dynspg_ts ) ) THEN
+         WRITE(*,*) 'incompatible free surface scheme between grids'
+         WRITE(*,*) 'parent grid ln_dynspg_ts  :', Agrif_Parent(ln_dynspg_ts )
+         WRITE(*,*) 'parent grid ln_dynspg_exp :', Agrif_Parent(ln_dynspg_exp)
+         WRITE(*,*) 'child grid  ln_dynspg_ts  :', ln_dynspg_ts
+         WRITE(*,*) 'child grid  ln_dynspg_exp :', ln_dynspg_exp
+         WRITE(*,*) 'those logicals should be identical'                  
+         STOP
+      ENDIF
+
       ! check if masks and bathymetries match
       IF(ln_chk_bathy) THEN
@@ -319,5 +330,5 @@
    !
    Agrif_UseSpecialValueInUpdate = .FALSE.
-   nbcline = 0
+   nbcline = 0 
    lk_agrif_doupd = .FALSE.
    !
