   SUBROUTINE cas_1DVbio

!&E---------------------------------------------------------------------
!&E                 ***  ROUTINE cas_1DVbio  ***
!&E
!&E ** Purpose : definition of a test case for biolo (1DV)
!&E
!&E ** Description :
!&E
!&E ** Called by : cas_init
!&E
!&E ** External calls :
!&E
!&E ** Used ij-arrays :
!&E
!&E ** Modified variables : hx, hy, h0, sal, temp, dy, dhx, dhy, dsigu, dsigw
!&E                         surf, fisac, gwac, dgac, dfiac, fu, fv, sig, sigw
!&E                         tfiusr, tfivsr, goulet, govlet, ig, id, jb, jh
!&E                         ssh,u,v,uz,vz
!&E
!&E ** Reference :
!&E
!&E ** History :
!&E       !  2005-10-13  Original code
!&E       !  2008-12    (V. Garnier) shift of sigma values : -1 < sig < 0
!&E
!&E---------------------------------------------------------------------





























































!! * Modules used
   USE parameters, ONLY : rsh,rlg,riolg,valmanq,kmax,imin,imax,lchain,&
                          ljminm1,ljmaxp2,liminm1,limaxp2,liminp1,limax
   USE comvarp3d, ONLY : ect

   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 output,    ONLY : pasor,l_out_sal,l_out_temp,fileresu,tdebsor,tfinsor, &
                         l_out_buoy,l_out_wind,l_out_zaxis_w,l_out_turb,   &
                         iextmin,iextmax,jextmin,jextmax
   USE toolgeom,  ONLY : f_zu
   USE comvarp2d, ONLY : temp
   USE comvars3d, ONLY : tetaref,saliref,nzinit,kzinit,qmaxz,l_stateeq_lin,  &
                         turb_0eq_option,turb_nbeq,turb_2eq_option,bgdiff,OptionSF
   USE comvars2d, ONLY : fisac,gwac,dtmin,dtmax,dt,suffix,fvisc,kx,ky,qmax,halfdt, &
                         icon,fu,fv,h0,tobs,hminfrot,iscreenlog, &
                         h0_g,hx_g,hy_g,h0fond,hm,vis2d,vish_xe,vish_phi
   USE comdiag,   ONLY : l_diag,file_diag,tdebdiag,tfindiag
   USE comturb,   ONLY : eps
   USE cometdyn,   ONLY : wind_veloc,cds
   USE cometemp,   ONLY : sflx_solarcst,sflx_rad_maxdepth


   USE comsubstance
   USE comdiag,   ONLY : l_diag
   USE casinit,   ONLY : cas_init_subs,cas_init_subs_disspart,cas_init_outflow,cas_init_subs_budget


   USE parameters, ONLY : ksdmax
   USE comMUSTANG
   USE casinit,   ONLY : cas_init_sedim



   IMPLICIT NONE

!! * Arguments
!! * Local declarations
   CHARACTER(LEN=19) :: date_start,date_end,date_start3d,date_startagrif
   CHARACTER(LEN=19) :: date_startout,date_endout
   INTEGER           :: i,j,k,isubs,ig,iv
   INTEGER           :: ni_wall_e,ni_wall_w,nj_wall_n,nj_wall_s
   INTEGER           :: IERR_MPI
   REAL(KIND=rsh)    :: dxval,dyval,x
   REAL(KIND=rsh)    :: z0bottom,z0surface,depthcst,zr
   REAL(KIND=rlg)    :: tool_datosec
   LOGICAL           :: l_filesubs

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

   !PRINT*, 'enter CAS_1DVBIO routine'

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

! dynamics
! --------
   CALL cas_init_param

! over-assignement
   h0fond=0.01_rsh
   hm=1.0_rsh

! 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
   qmax=8.0_rsh
   qmaxz=10.0_rsh
   saliref=35.0_rsh
   l_stateeq_lin=.FALSE.


! bathymetry
! ----------
! assignement : input variables for cas_init_bathy routine
   depthcst = 300.0_rsh
   ni_wall_e = 1  ! land over ni_wall_e cells at the eastern part of the domain
   ni_wall_w = 2  ! land over ni_wall_w cells (from imin column) at the western part of the domain
   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


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


! grid parametrization
! --------------------
! assignement : input variables for cas_init_grid routine

! parametres de forme
!---------------------
   dxval = 5000.0_rsh
   dyval = 5000.0_rsh
   fisac=1.0_riolg
   gwac=1.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/02/1900 00:00:00'
!date_end=   '31/12/1901 00:00:00'
   date_end=   '31/05/1901 00:00:00'
   date_start3d=  '01/01/1900 00:00:00'
   date_startagrif='01/01/1900 00:00:00'
   dtmin=30.0_rlg
   dtmax=400.0_rlg
   dt=30.0_rlg
   halfdt=dt*0.5_rlg
   suffix='1DVbio'

   date_startsub='01/03/1900 00:00:00'
   tdebsubs=tool_datosec(date_startsub)

! consolidation only if  l_consolid=.true.  or l_diffused or l_bioturb
   date_start_sed=date_start
   tstart_sed=tool_datosec(date_start_sed)
   tstart_sed=MAX(tstart_sed,tdebsubs)
   t_sed=tstart_sed
   dt_sed=500.0_rlg


!  l_nc4par = .TRUE.

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

! over-assignement
   iextmin(1)=2
   iextmax(1)=2
   jextmin(1)=2
   jextmax(1)=2
   pasor(1)=600.0_rlg
   tobs=2.0_rlg*3600.0_rlg

   date_startout='01/01/1900 00:00:00'
   date_endout=date_end
   tdebsor(1)=tool_datosec(date_startout)
   tfinsor(1)=tool_datosec(date_endout)
!pasor(1)=3.0_rsh*86400.0_rlg
   pasor(1)=0.25_rsh*86400.0_rlg

   l_diag=.FALSE.


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

! no open boundary
   CALL cas_init_obc

! over-assignement


! viscosity
!-----------
! none
   CALL cas_init_visc
   fvisc=0.1_rsh                                          ! =0 in casturb
   vis2d(:,:) = fvisc*0.01_rsh*dyval**1.15_rsh            ! =0 in casturb
   vish_xe(:,:,:) = fvisc*0.01_rsh*dyval**1.15_rsh        ! =0 in casturb
   vish_phi(:,:,:)= fvisc*0.01_rsh*dyval**1.15_rsh        ! =0 in casturb

! over-assignement
!   fvisc=0.1_rsh                                     ! =0 in casturb
!   vis2d(:,:) = fvisc*0.01_rsh*dyval**1.15_rsh       ! =0 in casturb
!   vish_xe(:,:,:) = fvisc*0.01_rsh*dyval**1.15_rsh   ! =0 in casturb
!   vish_phi(:,:,:)= fvisc*0.01_rsh*dyval**1.15_rsh   ! =0 in casturb


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

   z0bottom=0.0035
   z0surface=1.0_rsh
   nzinit=0.001_rsh
   kzinit=0.001_rsh


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

! over-assignement
! comme casturb
   bgdiff=0.0001_rsh
   turb_nbeq=2
   turb_0eq_option=0
   turb_2eq_option=2
   ect(:,:,:)=0.0001_rsh
   eps(:,:,:)=0.0001_rsh
   OptionSF=5

! meteorology
! -----------
   CALL cas_init_meteo

! over-assignement
   wind_veloc = SQRT(1.0_rsh)
!wind_veloc = 0._rsh
   cds=0.0011_rsh
   sflx_solarcst=100.0_rsh
   sflx_rad_maxdepth=300.0_rsh
!  tosx(:,:)=-cds*10.0_rsh*10.0_rsh
!  tosx(:,:)=-wind_veloc*wind_veloc*SIN((wind_dir)*pi/180.0_rsh)
!  tosy(:,:)=cds*10.0_rsh* 0.0_rsh
!  tosy(:,:)=-wind_veloc*wind_veloc*COS((wind_dir)*pi/180.0_rsh)
   
! initialization of the pronostic variables
! -----------------------------------------

! initialization of the pronostic variables
! -----------------------------------------
! set to 0,tetaref,saliref
   CALL cas_init_progvar

! over-assignement
! dynamics

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

!! N0 = 10e-2 s-1
!! EOS lineaire avec -g.dboz/dz = -g * alpha * T | alpha=0.0016)
   DO j=ljminm1,ljmaxp2
     DO i=liminm1,limaxp2
       IF (h0(i,j) > -valmanq) THEN
         DO k=1,kmax
           zr=-f_zu(h0(i,j),0.0_rsh,k,i,j)
           temp(k,i,j)= tetaref - 0.0001_rsh/(9.81_rsh*0.0016)*zr
         END DO
       ELSE
         temp(:,i,j) = valmanq
       END IF
     END DO
   END DO


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

! Substances
!
!--------------

! Initialization of the number of variables depending on their type
! (gravel,sand,mud,constitutive,non-constitutive,dissolved,fixed,driving or intermediate)
!----------------------------------------------------------------------------------------
   nv_dis=1
   nvp=1
   nvpc=1
   nv_mud=1
   nv_fix=0
   nv_dri=0
   nv_int=0
   nv_sand=0
   nv_grav=0
   nv_cp=0
   nv_ncp=0
   nv_sorb=0
   name_var(nb_var)='subs_DISS'
   name_filesubs = 'bidon'
   l_filesubs=.TRUE.
   IF (l_filesubs) THEN  ! we use "sub_read_var" instead of "cas_init_subs"

     CALL cas_init_subs_budget(date_start)
   ELSE
! allocation et initialisation des tableaux cv_wat,f90,t90...
     CALL cas_init_subs(date_start)   ! nvp must be defined before
! over-assignement
      cini_wat(1)=0.05_rsh
      cini_wat(2)=100.0_rsh
   ENDIF

! DO isubs=1,nv_adv
!    obc_cv_wat_w(isubs,:,:,:)=cini_wat(isubs)
!     obc_cv_wat_s(isubs,:,:,:)=cini_wat(isubs)
!     obc_cv_wat_n(isubs,:,:,:)=cini_wat(isubs)
!   ENDDO
   l_bilan=.TRUE.
   dtout_budget=6.0_rlg  ! in hours

! si il existe des variables particulaires
   IF (nvp>0) THEN

! variables dissoutes et particulaires : lecture directe d un fichier de donnees des variables si l_filesubs=.TRUE.
      CALL cas_init_subs_disspart(l_filesubs)

! over-assignement
      DO j=ljminm1,ljmaxp2
        DO i=liminm1,limaxp2
          IF (h0(i,j) > -valmanq) THEN
            DO k=1,kmax
              zr=-f_zu(h0(i,j),0.0_rsh,k,i,j)
!          cv_wat(1,k,i,j)= 0.1 - 0.00001_rsh/(9.81_rsh*0.0016)*zr
!          cv_wat(2,k,i,j)= 50. - 0.001_rsh/(9.81_rsh*0.0016)*zr
             temp(k,i,j)= tetaref - 0.0001_rsh/(9.81_rsh*0.0016)*zr
             cv_wat(:,k,i,j) = cini_wat(:)
            END DO

          ELSE
             cv_wat(:,:,i,j) = valmanq
             temp(:,i,j) = valmanq
          END IF
        END DO
       END DO
 
   ENDIF


    

   
! River and outflows
! -------------------
!! no river

  END SUBROUTINE cas_1DVbio

