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

  SUBROUTINE obc2d_cas(xe)

   !&E---------------------------------------------------------------------
   !&E                 ***  ROUTINE obc2d_cas  ***
   !&E
   !&E ** Purpose : Prescribe the tide level for different test cases
   !&E
   !&E ** Description :
   !&E
   !&E ** Called by : step2dxy.F90, step2dyx.F90, step3dxy.F90, step3dyx.F90
   !&E
   !&E ** External calls :
   !&E
   !&E ** Used ij-arrays :
   !&E
   !&E ** Modified variables : xe
   !&E
   !&E ** Reference :
   !&E
   !&E ** History :
   !&E       !  1987-02  (J.-C. Salomon, P. Lazure)  Original code
   !&E       !  2011-11  (V. Garnier) Spatial extension of ssh(liminm2:limaxp2,ljminm2:ljmaxp2)
   !&E
   !&E---------------------------------------------------------------------

#include "toolcpp.h"

   !! * Modules used
   USE parameters
   USE comvars2d
   USE comstatic
   USE obccombine, ONLY : obc_tide_sshn,obc_tide_sshs, obc_tide_sshe,obc_tide_sshw
   USE_MPI toolmpi,ONLY : ex_i_rsh,ex_j_rsh
#ifdef key_castest_estuary
   USE comaree, ONLY : tide_ampli_moy,tide_ampli_var,surelev
   USE comsubstance,    ONLY : tdebsubs
#endif

   IMPLICIT NONE

   !! * Arguments
   REAL(KIND=rsh), DIMENSION(liminm2:limaxp2,ljminm2:ljmaxp2), INTENT( out ) :: xe

   !! * Local declarations
   INTEGER                                    :: i,j,l
   REAL(KIND=rsh)                             :: x,h1,h2,hautd,yy,k1,k2,k3,k4

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

!   IF (num_testcase == 33) obc_tide_sshw(:) = 0.5_rsh*sin(2*pi*t/(12.0_rlg*3600.0_rlg))
   IF (num_testcase == 33) obc_tide_sshw(:) = 2.0_rsh*sin(2*pi*t/(12.0_rlg*3600.0_rlg))

#ifdef key_castest_estuary
   IF (num_testcase == 41) obc_tide_sshw(:) = tide_ampli_moy*(1.0_rsh+tide_ampli_var    &
                                              *sin(2*pi*t/(14.0_rlg*86400.0_rlg)))      &
                                              *sin(2*pi*t/(12.0_rlg*3600.0_rlg))        &
                                              +(t-tdebsubs)*surelev/31536000.0_rlg
#endif

   IF (num_testcase == 21) obc_tide_sshw(:) = 1.0_rsh*sin(2*pi*(t-tdeb)/44712.0_rlg)

   IF (num_testcase == 9) obc_tide_sshe(:)=0.001_rsh*cos(2*pi*(t-tdeb)/44712.0_rlg)

   IF (num_testcase == 10) obc_tide_sshe(:)=3.0_rsh *cos(2*pi*(t-tdeb)/44712.0_rlg)

   IF(num_testcase == 23 .AND. limax==imax) xe(imax,:) = 0.0_rsh
   IF(num_testcase == 23 .AND. limin==imin) xe(imin+1,:) = 0.0_rsh

   IF(num_testcase == 38 .AND. limax==imax) xe(imax,:) = 0.0_rsh

#if defined key_wave_qeuler_dynamics && defined key_castest
   IF(num_testcase == 35 .AND. limax==imax) obc_tide_sshe(:) = 0.0_rsh
#endif

   IF (num_testcase == 15) THEN
       k1=1.0_rsh
!       IF (t<tdeb+3.*86400.d0) k1=1.0+(t-86400.d0*3-tdeb)/(3.d0*86400.d0)
       obc_tide_sshs(:)=0.5_rsh*k1*cos(0.0001_rlg*(t-tdeb))
!      print*,k1,xe(3,jmin+1)
   END IF

   IF (num_testcase == 1) THEN

     k1=1.0_rsh
     k2=0.5625_rsh
     k3=0.25_rsh
     k4=0.0625_rsh

     DO j=ljminp2,ljmaxm1
      IF_MPI (limin==imin) THEN
       i=ig(j)
       xe(i,j)  =k1*0.0_rsh+(1.0_rsh-k1)*xe(i,j)
       xe(i+1,j)=k2*0.0_rsh+(1.0_rsh-k2)*xe(i+1,j)
       xe(i+2,j)=k3*0.0_rsh+(1.0_rsh-k3)*xe(i+2,j)
       xe(i+3,j)=k4*0.0_rsh+(1.0_rsh-k4)*xe(i+3,j)
       obc_tide_sshw(j)=xe(i,j)
      ENDIF_MPI
      IF_MPI (limax==imax) THEN
       i=id(j)
       xe(i,j)  =k1*0.0_rsh+(1.0_rsh-k1)*xe(i,j)
       xe(i-1,j)=k2*0.0_rsh+(1.0_rsh-k2)*xe(i-1,j)
       xe(i-2,j)=k3*0.0_rsh+(1.0_rsh-k3)*xe(i-2,j)
       xe(i-3,j)=k4*0.0_rsh+(1.0_rsh-k4)*xe(i-3,j)
       obc_tide_sshe(j)=xe(i,j)
      ENDIF_MPI
     END DO

     DO i=liminp2,limaxm1
      IF_MPI (ljmin==jmin) THEN
       j=jb(i)
       xe(i,j)  =k1*0.0_rsh+(1.0_rsh-k1)*xe(i,j)
       xe(i,j+1)=k2*0.0_rsh+(1.0_rsh-k2)*xe(i,j+1)
       xe(i,j+2)=k3*0.0_rsh+(1.0_rsh-k3)*xe(i,j+2)
       xe(i,j+3)=k4*0.0_rsh+(1.0_rsh-k4)*xe(i,j+3)
       obc_tide_sshs(i)=xe(i,j)
      ENDIF_MPI
      IF_MPI (ljmax==jmax) THEN
       j=jh(i)
       xe(i,j)  =k1*0.0_rsh+(1.0_rsh-k1)*xe(i,j)
       xe(i,j-1)=k2*0.0_rsh+(1.0_rsh-k2)*xe(i,j-1)
       xe(i,j-2)=k3*0.0_rsh+(1.0_rsh-k3)*xe(i,j-2)
       xe(i,j-3)=k4*0.0_rsh+(1.0_rsh-k4)*xe(i,j-3)
       obc_tide_sshn(i)=xe(i,j)
      ENDIF_MPI
     END DO

     CALL_MPI ex_i_rsh(-2,2,1,liminm2,limaxp2,ljminm2,ljmaxp2,xe(liminm2:limaxp2,ljminm2:ljmaxp2))
     CALL_MPI ex_j_rsh(-2,2,1,liminm2,limaxp2,ljminm2,ljmaxp2,xe(liminm2:limaxp2,ljminm2:ljmaxp2))

   END IF

   PRINT_DBG*, 'exit OBC2D_CAS routine'

  END SUBROUTINE obc2d_cas
