  SUBROUTINE cas_obstsedflumecycl

!&E---------------------------------------------------------------------
!&E                 ***  ROUTINE cas_obstsedflumecycl  ***
!&E
!&E ** Purpose : test case for flume experiments with cyclic boundary conditions
!&E              sediment and obstructions
!&E
!&E ** Description : The flume is by default a 2DV flume, 4 m long and 0.215 m
!&E                  deep. It is forced through a force applied on momentum equation
!&E                  This test-case only required the following CPP keys:
!&E                  -Dkey_obstructions
!&E                  using -Dkey_dyn_adv_quick and -Dkey_tssub_adv_ultimatequickestmacho
!&E                  prevent generation of model instabilities at the edges of obstructions patch
!&E                  You also can use the CPP key : -Dkey_castestobstructions3D
!&E
!&E ** Called by : cas_init
!&E
!&E ** External calls :
!&E
!&E ** Used ij-arrays :
!&E
!&E ** Modified variables :
!&E
!&E ** Reference :
!&E
!&E ** History :
!&E       !  2014-08-11  Original code (F. Ganthy) adapted from caskelvin
!&E       !  2016-09 (F. Ganthy) optimization on Abdelrhman 2007 method
!&E                              for computation on obstruction height :
!&E                              add number of obstruction segment to user-defined
!&E                              parameters
!&E       ! 2017-10 (F. Ganthy) Add new cpp keys related to new test-case options
!&E       ! 2017-10 (F. Ganthy) Some modifications:
!&E                             - Allowing multiple obstructions type in a single grid cell
!&E                             - Allowing 3D obstructions
!&E                             - Add simplified obstructions kind
!&E       ! 2017-11 (F. Ganthy) Remove useless variables related to turbulence coefficients
!&E
!&E---------------------------------------------------------------------





























































!! * Modules used
   USE parameters, ONLY : rsh,rlg,riolg,kmax,grav,pi,imin,imax,jmin,jmax, &
                          limin,liminp1,limax,ljmin,ljminp1,ljminp2,ljmax, &
                          ljmaxm1,ljminm2,ljmaxp2,liminm2,limaxp2, &
                          limaxp1,ljmaxp1,valmanq, &
                          ishift_obc_west,ishift_obc_east,jshift_obc_south,jshift_obc_north
   USE comvars2d, ONLY : fisac,gwac,fu,fv,dtmin,dtmax,dt,halfdt,suffix,l_obc_cycl_x, &
                         l_obc_cycl_y,icon,qmax,t,l_modele2d,h0,hx,h0fond, &
                         jh,jb,ig,id,hminfrot,kx,ky,hm,dhj,fvisc,out_dir,vis2d,vish_xe,vish_phi
   USE comvarp2d, ONLY : ssh,u,v
   USE comvarp3d, ONLY : uz,vz,ect,psi
   USE comvars3d, ONLY : kzinit,nzinit,qmaxz,turb_nbeq,turb_2eq_option,l_stateeq_lin,saliref_lin, &
                         saliref,bgdiff
   USE comturb, ONLY   : eps
   USE obccombine, ONLY : l_obc_cycl
   USE toolmpi, ONLY : ex_i_rsh,ex_j_rsh,ex_peri_x_rsh,ex_peri_y_rsh
   USE output,    ONLY : pasor,l_out_temp,fileresu,tdebsor,tfinsor, &
                         iextmin,iextmax,jextmin,jextmax

   USE casinit,   ONLY : cas_init_param,cas_init_grid,cas_init_bathy,  &
                         cas_init_io,cas_init_obc,cas_init_meteo,      &
                         cas_init_visc,cas_init_turb,cas_init_tspar,   &
                         cas_init_progvar,cas_init_misc,               &

                         cas_init_river
   USE comfluxdo, ONLY : phieau
   USE comvars2d, ONLY : uforcing



   IMPLICIT NONE

!! * Arguments

!! * Local declarations
   CHARACTER(LEN=19) :: date_start,date_end,date_start3d,date_startagrif,date_startout,date_endout
   INTEGER           :: i,j,iobst,k
   INTEGER           :: nj_wall_n,nj_wall_s
   REAL(KIND=rsh)    :: dxval,dyval
   REAL(KIND=rsh)    :: fuval
   REAL(KIND=rsh)    :: z0bottom,z0surface,depthcst
   REAL(KIND=rlg)    :: tool_datosec


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

     !PRINT*, 'enter CAS_OBSTSEDFLUMECYCL2DV routine'


! general parametrization (each parameter can be reassigned)
! -----------------------

! dynamics
   CALL cas_init_param

! over-assignement

! tracers : among others, saliref=saliref_lin=35.5_rsh,
! tetaref=tetaref_lin=10.0_rsh
   CALL cas_init_tspar

! over-assignement
   kx = 1.0_rsh
   ky = 1.0_rsh
   icon=2
   qmax=8.0_rsh
   qmaxz=10.0_rsh
   saliref=35.50_rsh
   l_stateeq_lin=.FALSE.
   saliref_lin=saliref


! Bathymetry
! ----------

! assignement : input variables for cas_init_bathy routine

   depthcst = 0.215_rsh

   nj_wall_s = 2  ! land over nj_wall_s cells (from jmin row) at the southern part of the domain
   nj_wall_n = 1  ! land over nj_wall_n cells at the northern part of the domain

   h0fond   = 0.01_rsh
   hm       = 0.01_rsh
   dhj      = 0.1_rsh


! flat bottom, plus walls
   CALL cas_init_bathy(depthcst,nj_wall_n=nj_wall_n,nj_wall_s=nj_wall_s)

! over-assignement

! grid parametrization
! --------------------

! assignement : input variables for cas_init_grid routine

   dxval=0.05_rsh
   dyval=0.05_rsh

   fisac=0.0_riolg
   gwac=0.0_riolg

   CALL cas_init_grid(dxval,dyval)

! over-assignement
   fu(:,:) = 0.0_rsh
   fv(:,:) = 0.0_rsh

! IO parametrization
! ------------------

! assignement : input variables for cas_init_io routine
   date_start=   '01/01/1900 00:00:00'
   date_end=   '01/01/1900 00:30:00'
   date_start3d=  '01/01/1900 00:00:00'
   date_startagrif='01/01/1900 00:00:00'

   dtmin=0.0025_rlg
   dtmax=0.0025_rlg
   dt=0.0025_rlg
   suffix='obstsedflumecycl2dv'

   halfdt=dt*0.5_rlg

   CALL cas_init_io(date_start,date_end,date_start3d,date_startagrif,suffix)

! over-assignement
   iextmin(1) = imin
   iextmax(1) = imax

   jextmin(1) = 2
   jextmax(1) = 2

   pasor(1)=10.0_rlg
! Name of results file :
! =========================================
   fileresu(1) = 'results.nc'
! =========================================
   fileresu(1)   = TRIM(out_dir)//TRIM(fileresu(1))
   date_startout = '01/01/1900 00:00:00'
   date_endout   = date_end
   tdebsor(1)    = tool_datosec(date_startout)
   tfinsor(1)    = tool_datosec(date_endout)

! open boundaries
! ---------------

! no open boundary
   CALL cas_init_obc

! over-assignement
! used scheme to manage obc
   l_obc_cycl = .TRUE.
   l_obc_cycl_x=.TRUE.
! physics introduced into the simulated area (tide or ogcm solution)

! viscosity
!-----------

! none
   CALL cas_init_visc
! over-assignement
   fvisc           = 0.1_rsh
   vis2d(:,:)      = fvisc*0.01_rsh*dyval**1.15_rsh
   vish_xe(:,:,:)  = fvisc*0.01_rsh*dyval**1.15_rsh
   vish_phi(:,:,:) = fvisc*0.01_rsh*dyval**1.15_rsh


! turbulence
! ----------

   z0bottom   =1.0e-5
   z0surface  =1.0e-5_rsh
   kzinit=0.000001_rsh
   nzinit=0.000001_rsh

! Gaspard parametrization
   CALL cas_init_turb(kzinit,nzinit,z0surface,z0bottom)

! over-assignement
   bgdiff          = 1.0e-6
   turb_nbeq       = 2
   turb_2eq_option = 2
   hminfrot        = 0.01_rsh
   ect(:,:,:)      = 1.0e-8
   psi(:,:,:)      = 1.0e-12
   eps(:,:,:)      = 1.0e-12
   phieau(:,:,:)   = 0.0_rlg


! meteorology
! -----------

! no forcing
   CALL cas_init_meteo


! River and outflows
! -------------------

! no river
   CALL cas_init_river


! initialization of the pronostic variables
! -----------------------------------------

! set to 0,tetaref,saliref
   CALL cas_init_progvar


! Miscellaneous
! ------------

! Domain of calculation
! Percent of wet surface on each cell
   CALL cas_init_misc

! over-assignement
   id(:)=id(:)-ishift_obc_east
   ig(:)=ig(:)+ishift_obc_west
   jh(:)=jh(:)-jshift_obc_north
   jb(:)=jb(:)+jshift_obc_south

! Dynamics : forcing



! Obstructions
!--------------



     !PRINT*, 'exit CAS_OBSTSEDFLUMECYCL2DV routine'



  END SUBROUTINE cas_obstsedflumecycl
