   !!======================================================================

  SUBROUTINE agrif_obc_v(uv)
!
!********************************************************************
!
!     objet    :  conditions aux limites ouvertes en vitesse.
!                 On remplit le cadre de v.
!
!
!
!     appelant         : stepv, step2dyx
!                      :
!     appeles          :
!                      :
!     canal d ecriture :
!                      :
!     canal de lecture :
!                      :
!     cle cpp          :
!                      :
!     variables in     : jh, jb, ig, id, hy, h0fond, valmanq
!                      :
!     variables out    :
!                      :
!     variables inout  : v
!                      :
!     dernieres modifs : 13/10/2005
!                      : 12/12/2007 F. Dumas
   !&E       !  2009-05  (F. Dumas)  AGRIF pour nouveau schema temporel
!                      :
!***********************************************************

#include "toolcpp.h"

#ifdef key_agrif
   USE parameters
   USE comvars2d
   USE comvarp2d
   USE agrifcommonid
   USE_MPI toolmpi, ONLY : ex_i_rsh,ex_j_rsh

   IMPLICIT NONE

   INTEGER :: i,j
   REAL(KIND=rsh),DIMENSION(liminm2:limaxp2,ljminm2:ljmaxp2),INTENT(inout) :: uv

   EXTERNAL :: interpv_stepu

   !!----------------------------------------------------------------------
   !! * Executable part

   PRINT_DBG*, 'enter AGRIF_OBC_V routine',Agrif_Root()

! Initialization

   agrif_SpecialValue=0.
   c_agrif_interp='v_bc'

   nesting_tabtemp_2d(:,:,1) = uv
   CALL Agrif_Bc_variable(v_id,procname=interpv_stepu)
   uv = nesting_tabtemp_2d(:,:,1)

   agrif_SpecialValue=valmanq

   IF (Agrif_Grandmother()) THEN

     DO j=ljminp1,ljmaxm1

       ! Western boundary
       i=ig(j)
       IF_MPI (limin==imin .AND. limin==i-1) THEN
         IF (hy(i,j) /= -valmanq-h0fond) uv(i,j)=uv(i+1,j)
       ENDIF_MPI

       ! Eastern boundary
       i=id(j)
       IF_MPI (limax==imax .AND. limax==i) THEN
         IF (hy(i,j) /= -valmanq-h0fond) uv(i,j)=uv(i-1,j)
       ENDIF_MPI

     END DO

     DO i=liminp2,limaxm1

       ! Southern boundary
       j=jb(i)-1
       IF_MPI (ljmin==jmin .AND. ljmin==j) THEN
         IF (hy(i,j) /= -valmanq-h0fond) uv(i,j)=uv(i,j+1)
       ENDIF_MPI

       ! Northern open boundary
       j=jh(i)
       IF_MPI (ljmax==jmax .AND. ljmax==j) THEN
         IF (hy(i,j) /= -valmanq-h0fond) uv(i,j)=uv(i,j-1)
       ENDIF_MPI

     END DO

   END IF    ! end Grand Mother

OMPMPINOAGRIF barrier
OMPMPINOAGRIF master
   CALL_MPI ex_i_rsh(-2,2,1,liminm2,limaxp2,ljminm2,ljmaxp2,uv(liminm2:limaxp2,ljminm2:ljmaxp2))
!part really usefull call ex_j_rsh(-2,2,1,limin,limaxp1,ljminm2,ljmaxp2,uv(limin:limaxp1,ljminm2:ljmaxp2))
!larger exchanges to make transfer in step2d* and step3d* easier
   CALL_MPI ex_j_rsh(-2,2,1,liminm2,limaxp2,ljminm2,ljmaxp2,uv(liminm2:limaxp2,ljminm2:ljmaxp2))
OMPMPINOAGRIF end master
OMPMPINOAGRIF barrier
OMPMPINOAGRIF flush(uv)

   PRINT_DBG*, 'exit AGRIF_OBC_V routine',Agrif_Root()

   RETURN

#else
   USE parameters, ONLY : rsh,liminm2,limaxp2,ljminm2,ljmaxp2
   REAL(KIND=rsh),DIMENSION(liminm2:limaxp2,ljminm2:ljmaxp2),INTENT(inout) :: uv
#endif

  END SUBROUTINE agrif_obc_v

   !!======================================================================

#ifdef key_agrif

  SUBROUTINE interpv_stepu(tabres,i1,i2,j1,j2,k1,k2,before)

   !&E       !
   !&E       !  2015-09  (M. Honnorat, V. Garnier) MPI
   !&E       !

   USE parameters
   USE comvarp3d
   USE comvars2d
   USE comvarp2d
   USE agrifcommonid
   IMPLICIT NONE

   INTEGER, INTENT(IN)      :: i1,i2,j1,j2,k1,k2
   REAL,    INTENT(INOUT)   :: tabres(i1:i2,j1:j2,k1:k2)
   LOGICAL, INTENT(IN)      :: before

   INTEGER :: i,j

!   REAL hey_loc(i1:i2,j1:j2)
!   INTEGER igdv_loc(i1:i2,j1:j2)
!   REAL hzey_loc(1:kmax,i1:i2,j1:j2)
!   INTEGER test

   !!----------------------------------------------------------------------
   !! * Executable part

   PRINT_DBG*, 'enter INTERPV_STEPU routine',Agrif_Root()

!   hey_loc(i1:i2,j1:j2)=0.0

   IF (before) THEN
!     test = 2
!     CALL agrif_dyn3d_height_mask(ssh,igdv_loc,hey_loc, &
!#if defined key_siggen || defined key_gencoord
!                                  hzey_loc, &
!#endif
!                                  i1,i2,j1,j2,test)

!cval remettre les lignes commentees (!cval) et decommenter l appel a
!agrif_dyn3d_height_mask si souci avec les bancs decouvrants
     DO j=j1,j2
       DO i=i1,i2
!cval         IF (igdv_loc(i,j) /= 4) THEN
!           tabres(i,j,1) = hey_loc(i,j)*v(i,j)
           tabres(i,j,2) = v(i,j)
!cval         ELSE
!cval           tabres(i,j,:) = 0.
!cval         END IF
       END DO
     END DO

   ELSE                 ! child

     SELECT CASE(c_agrif_interp)

       CASE('v_init')

         DO j=MAX(j1,ljmin),MIN(j2,ljmax)
           DO i=MAX(i1,limin),MIN(i2,limax)
             IF (hy(i,j) == -valmanq-h0fond) THEN
               nesting_tabtemp_2d(i,j,1) = 0.0_rsh
             ELSE
               nesting_tabtemp_2d(i,j,1) = tabres(i,j,2)
             END IF
           END DO
         END DO

       CASE('v_bc')

         DO j=MAX(j1,ljmin),MIN(j2,ljmax)
           DO i=MAX(i1,limin),MIN(i2,limax)
             IF (hy(i,j) == -valmanq-h0fond) THEN
               IF (i==imin+1.or.i==imax.or.j==jmin.or.j==jmax) nesting_tabtemp_2d(i,j,1) = 0.0_rsh
             ELSE
               IF ((i==imin+1.or.i==imax.or.j==jmin.or.j==jmax)) THEN
                 nesting_tabtemp_2d(i,j,1) = tabres(i,j,2)
               END IF
             END IF
           END DO
         END DO

     END SELECT

   END IF

   PRINT_DBG*, 'exit INTERPV_STEPU routine',Agrif_Root()

   RETURN

  END SUBROUTINE interpv_stepu

   !!======================================================================

#endif
