Index: branches/2017/dev_METO_MERCATOR_2017/NEMOGCM/NEMO/NST_SRC/agrif_opa_interp.F90
===================================================================
--- branches/2017/dev_METO_MERCATOR_2017/NEMOGCM/NEMO/NST_SRC/agrif_opa_interp.F90	(revision 8991)
+++ branches/2017/dev_METO_MERCATOR_2017/NEMOGCM/NEMO/NST_SRC/agrif_opa_interp.F90	(revision 8993)
@@ -24,4 +24,5 @@
    USE agrif_oce
    USE phycst
+   USE dynspg_ts, ONLY: un_adv, vn_adv
    !
    USE in_out_manager
@@ -38,6 +39,6 @@
    PUBLIC   interpunb, interpvnb, interpub2b, interpvb2b
    PUBLIC   interpe3t, interpumsk, interpvmsk
-# if defined key_zdftke
-   PUBLIC   Agrif_tke, interpavm
+# if defined key_zdftke || defined key_zdfgls
+   PUBLIC   Agrif_avm, interpavm
 # endif
 
@@ -116,10 +117,12 @@
          ENDIF
          !
-         DO jk=1,jpkm1                 ! Smooth
-            DO jj=j1,j2
-               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
+         IF (.NOT.lk_agrif_clp) THEN
+            DO jk=1,jpkm1              ! Smooth
+               DO jj=j1,j2
+                  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
+         END IF
          !
          zub(2,:) = 0._wp              ! Correct transport
@@ -185,10 +188,12 @@
          ENDIF
 
-         DO jk = 1, jpkm1              ! Smooth
-            DO jj = j1, j2
-               ua(nlci-2,jj,jk) = 0.25_wp * umask(nlci-2,jj,jk)      &
-                  &             * ( ua(nlci-3,jj,jk) + 2._wp*ua(nlci-2,jj,jk) + ua(nlci-1,jj,jk) )
-            END DO
-         END DO
+         IF (.NOT.lk_agrif_clp) THEN
+            DO jk = 1, jpkm1           ! Smooth
+               DO jj = j1, j2
+                  ua(nlci-2,jj,jk) = 0.25_wp * umask(nlci-2,jj,jk)      &
+                     &             * ( ua(nlci-3,jj,jk) + 2._wp*ua(nlci-2,jj,jk) + ua(nlci-1,jj,jk) )
+               END DO
+            END DO
+         ENDIF
 
          zub(nlci-2,:) = 0._wp        ! Correct transport
@@ -254,10 +259,12 @@
          ENDIF
          !
-         DO jk = 1, jpkm1              ! Smooth
-            DO ji = i1, i2
-               va(ji,2,jk) = 0.25_wp * vmask(ji,2,jk)    &
-                  &        * ( va(ji,1,jk) + 2._wp*va(ji,2,jk) + va(ji,3,jk) )
-            END DO
-         END DO
+         IF (.NOT.lk_agrif_clp) THEN
+            DO jk = 1, jpkm1              ! Smooth
+               DO ji = i1, i2
+                  va(ji,2,jk) = 0.25_wp * vmask(ji,2,jk)    &
+                     &        * ( va(ji,1,jk) + 2._wp*va(ji,2,jk) + va(ji,3,jk) )
+               END DO
+            END DO
+         ENDIF
          !
          zvb(:,2) = 0._wp              ! Correct transport
@@ -323,10 +330,12 @@
          ENDIF
          !
-         DO jk = 1, jpkm1              ! Smooth
-            DO ji = i1, i2
-               va(ji,nlcj-2,jk) = 0.25_wp * vmask(ji,nlcj-2,jk)   &
-                  &             * ( va(ji,nlcj-3,jk) + 2._wp * va(ji,nlcj-2,jk) + va(ji,nlcj-1,jk) )
-            END DO
-         END DO
+         IF (.NOT.lk_agrif_clp) THEN
+            DO jk = 1, jpkm1           ! Smooth
+               DO ji = i1, i2
+                  va(ji,nlcj-2,jk) = 0.25_wp * vmask(ji,nlcj-2,jk)   &
+                     &             * ( va(ji,nlcj-3,jk) + 2._wp * va(ji,nlcj-2,jk) + va(ji,nlcj-1,jk) )
+               END DO
+            END DO
+         ENDIF
          !
          zvb(:,nlcj-2) = 0._wp         ! Correct transport
@@ -449,5 +458,4 @@
       INTEGER :: ji, jj
       LOGICAL :: ll_int_cons
-      REAL(wp) :: zrhot, zt
       !!----------------------------------------------------------------------  
       !
@@ -456,21 +464,9 @@
       ll_int_cons = ln_bt_fw ! Assume conservative temporal integration in the forward case only
       !
-      zrhot = Agrif_rhot()
-      !
-      ! "Central" time index for interpolation:
-      IF( ln_bt_fw ) THEN
-         zt = REAL( Agrif_NbStepint()+0.5_wp, wp ) / zrhot
-      ELSE
-         zt = REAL( Agrif_NbStepint()       , wp ) / zrhot
-      ENDIF
-      !
-      ! Linear interpolation of sea level
-      Agrif_SpecialValue    = 0._wp
-      Agrif_UseSpecialValue = .TRUE.
-      CALL Agrif_Bc_variable( sshn_id, calledweight=zt, procname=interpsshn )
-      Agrif_UseSpecialValue = .FALSE.
+      ! Enforce volume conservation if no time refinement:  
+      IF ( Agrif_rhot()==1 ) ll_int_cons=.TRUE.  
       !
       ! Interpolate barotropic fluxes
-      Agrif_SpecialValue=0.
+      Agrif_SpecialValue=0._wp
       Agrif_UseSpecialValue = ln_spc_dyn
       !
@@ -491,6 +487,6 @@
          ubdy_n(:) = 0._wp   ;   vbdy_n(:) = 0._wp 
          ubdy_s(:) = 0._wp   ;   vbdy_s(:) = 0._wp
-         CALL Agrif_Bc_variable( unb_id, calledweight=zt, procname=interpunb )
-         CALL Agrif_Bc_variable( vnb_id, calledweight=zt, procname=interpvnb )
+         CALL Agrif_Bc_variable( unb_id, procname=interpunb )
+         CALL Agrif_Bc_variable( vnb_id, procname=interpvnb )
       ENDIF
       Agrif_UseSpecialValue = .FALSE.
@@ -501,30 +497,42 @@
    SUBROUTINE Agrif_ssh( kt )
       !!----------------------------------------------------------------------
-      !!                  ***  ROUTINE Agrif_DYN  ***
+      !!                  ***  ROUTINE Agrif_ssh  ***
       !!----------------------------------------------------------------------  
       INTEGER, INTENT(in) ::   kt
       !!
+      INTEGER :: ji, jj
       !!----------------------------------------------------------------------  
       !
       IF( Agrif_Root() )   RETURN
+      !      
+      ! Linear interpolation in time of sea level
+      !
+      Agrif_SpecialValue    = 0._wp
+      Agrif_UseSpecialValue = .TRUE.
+      CALL Agrif_Bc_variable(sshn_id, procname=interpsshn )
+      Agrif_UseSpecialValue = .FALSE.
       !
       IF((nbondi == -1).OR.(nbondi == 2)) THEN
-         ssha(2,:)=ssha(3,:)
-         sshn(2,:)=sshn(3,:)
+         DO jj=1,jpj
+            ssha(2,jj) = hbdy_w(jj)
+         END DO
       ENDIF
       !
       IF((nbondi == 1).OR.(nbondi == 2)) THEN
-         ssha(nlci-1,:)=ssha(nlci-2,:)
-         sshn(nlci-1,:)=sshn(nlci-2,:)
+         DO jj=1,jpj
+            ssha(nlci-1,jj) = hbdy_e(jj)
+         END DO
       ENDIF
       !
       IF((nbondj == -1).OR.(nbondj == 2)) THEN
-         ssha(:,2)=ssha(:,3)
-         sshn(:,2)=sshn(:,3)
+         DO ji=1,jpi
+            ssha(ji,2) = hbdy_s(ji)
+         END DO
       ENDIF
       !
       IF((nbondj == 1).OR.(nbondj == 2)) THEN
-         ssha(:,nlcj-1)=ssha(:,nlcj-2)
-         sshn(:,nlcj-1)=sshn(:,nlcj-2)
+         DO ji=1,jpi
+            ssha(ji,nlcj-1) = hbdy_n(ji)
+         END DO
       ENDIF
       !
@@ -541,4 +549,7 @@
       !!----------------------------------------------------------------------  
       !
+      !
+      IF( Agrif_Root() )   RETURN
+      !
       IF((nbondi == -1).OR.(nbondi == 2)) THEN
          DO jj = 1, jpj
@@ -567,15 +578,19 @@
    END SUBROUTINE Agrif_ssh_ts
 
-# if defined key_zdftke
-
-   SUBROUTINE Agrif_tke
-      !!----------------------------------------------------------------------
-      !!                  ***  ROUTINE Agrif_tke  ***
+# if defined key_zdftke || defined key_zdfgls
+
+   SUBROUTINE Agrif_avm
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE Agrif_avm  ***
       !!----------------------------------------------------------------------  
       REAL(wp) ::   zalpha
       !!----------------------------------------------------------------------  
       !
-      zalpha = REAL( Agrif_NbStepint() + Agrif_IRhot() - 1, wp ) / REAL( Agrif_IRhot(), wp )
-      IF( zalpha > 1. )   zalpha = 1.
+      IF( Agrif_Root() )   RETURN
+      !
+!      zalpha = REAL( Agrif_NbStepint() + Agrif_IRhot() - 1, wp ) / REAL( Agrif_IRhot(), wp )
+!      IF( zalpha > 1. )   zalpha = 1.
+      zalpha = 1._wp ! JC: proper time interpolation impossible  
+                     ! => use last available value from parent 
       !
       Agrif_SpecialValue    = 0.e0
@@ -586,5 +601,5 @@
       Agrif_UseSpecialValue = .FALSE.
       !
-   END SUBROUTINE Agrif_tke
+   END SUBROUTINE Agrif_avm
    
 # endif
@@ -609,4 +624,16 @@
          ptab(i1:i2,j1:j2,k1:k2,n1:n2) = tsn(i1:i2,j1:j2,k1:k2,n1:n2)
       ELSE
+         IF (lk_agrif_clp) THEN
+            DO jn = 1, jpts
+               DO jk = 1, jpkm1
+                  DO ji = i1,i2
+                     DO jj = j1,j2
+                        tsa(ji,jj,jk,jn) = ptab(ji,jj,jk,jn)
+                     END DO
+                  END DO
+               END DO
+            END DO           
+            return
+         ENDIF
          !
          western_side  = (nb == 1).AND.(ndir == 1)
@@ -781,5 +808,5 @@
       !
       IF( before ) THEN 
-         DO jk = k1, jpk
+         DO jk = 1, jpkm1
             ptab(i1:i2,j1:j2,jk) = e2u(i1:i2,j1:j2) * e3u_n(i1:i2,j1:j2,jk) * un(i1:i2,j1:j2,jk)
          END DO
@@ -788,5 +815,5 @@
          DO jk = 1, jpkm1
             DO jj=j1,j2
-               ua(i1:i2,jj,jk) = ptab(i1:i2,jj,jk) / ( zrhoy * e2u(i1:i2,jj) * e3u_n(i1:i2,jj,jk) )
+               ua(i1:i2,jj,jk) = ptab(i1:i2,jj,jk) / ( zrhoy * e2u(i1:i2,jj) * e3u_a(i1:i2,jj,jk) )
             END DO
          END DO
@@ -808,6 +835,6 @@
       !!----------------------------------------------------------------------
       !      
-      IF( before ) THEN       !interpv entre 1 et k2 et interpv2d en jpkp1
-         DO jk = k1, jpk
+      IF( before ) THEN  
+         DO jk = 1, jpkm1
             ptab(i1:i2,j1:j2,jk) = e1v(i1:i2,j1:j2) * e3v_n(i1:i2,j1:j2,jk) * vn(i1:i2,j1:j2,jk)
          END DO
@@ -815,5 +842,5 @@
          zrhox= Agrif_Rhox()
          DO jk = 1, jpkm1
-            va(i1:i2,j1:j2,jk) = ptab(i1:i2,j1:j2,jk) / ( zrhox * e1v(i1:i2,j1:j2) * e3v_n(i1:i2,j1:j2,jk) )
+            va(i1:i2,j1:j2,jk) = ptab(i1:i2,j1:j2,jk) / ( zrhox * e1v(i1:i2,j1:j2) * e3v_a(i1:i2,j1:j2,jk) )
          END DO
       ENDIF
@@ -978,5 +1005,9 @@
       !!----------------------------------------------------------------------  
       IF( before ) THEN
-         ptab(i1:i2,j1:j2) = e2u(i1:i2,j1:j2) * ub2_b(i1:i2,j1:j2)
+         IF ( ln_bt_fw ) THEN
+            ptab(i1:i2,j1:j2) = e2u(i1:i2,j1:j2) * ub2_b(i1:i2,j1:j2)
+         ELSE
+            ptab(i1:i2,j1:j2) = e2u(i1:i2,j1:j2) * un_adv(i1:i2,j1:j2)
+         ENDIF
       ELSE
          western_side  = (nb == 1).AND.(ndir == 1)
@@ -1016,5 +1047,9 @@
       !
       IF( before ) THEN
-         ptab(i1:i2,j1:j2) = e1v(i1:i2,j1:j2) * vb2_b(i1:i2,j1:j2)
+         IF ( ln_bt_fw ) THEN
+            ptab(i1:i2,j1:j2) = e1v(i1:i2,j1:j2) * vb2_b(i1:i2,j1:j2)
+         ELSE
+            ptab(i1:i2,j1:j2) = e1v(i1:i2,j1:j2) * vn_adv(i1:i2,j1:j2)
+         ENDIF
       ELSE      
          western_side  = (nb == 1).AND.(ndir == 1)
@@ -1175,5 +1210,5 @@
    END SUBROUTINE interpvmsk
 
-# if defined key_zdftke
+# if defined key_zdftke || defined key_zdfgls
 
    SUBROUTINE interpavm( ptab, i1, i2, j1, j2, k1, k2, before )
@@ -1189,10 +1224,10 @@
          ptab (i1:i2,j1:j2,k1:k2) = avm_k(i1:i2,j1:j2,k1:k2)
       ELSE
-         avm_k(i1:i2,j1:j2,k1:k2) = ptab (i1:i2,j1:j2,k1:k2)
+         avm  (i1:i2,j1:j2,k1:k2) = ptab (i1:i2,j1:j2,k1:k2)
       ENDIF
       !
    END SUBROUTINE interpavm
 
-# endif /* key_zdftke */
+# endif /* key_zdftke || key_zdfgls */
 
 #else
