   SUBROUTINE cas_bioplat

   !&E---------------------------------------------------------------------
   !&E                 ***  subroutine cas_bioplat  ***
   !&E
   !&E ** Purpose : definition of a test case for biolo (PLATEAU)
   !&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---------------------------------------------------------------------

#include "toolcpp.h"

   !! * Modules used
   USE parameters, ONLY : rsh,rlg,riolg,valmanq,kmax,imin,imax,jmin,jmax,lchain,&
                          ljminm1,ljmaxp2,liminm1,limaxp2,liminp1,limax,epsilon, &
                          liminm2,ljminm2,pi,limin,limax,ljmin,ljmax,limaxp1,ljmaxp1
   USE comvarp3d, ONLY : ect
#if defined key_siggen || defined key_gencoord
   USE comsiggen,  ONLY : hc_sig_g,hcx_sig_g,hcy_sig_g,hc,hc_sig,hcx_sig,hcy_sig,  &
                          theta_sig,b_sig,hc
#endif
   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,ssh
   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,halfdt,suffix,fvisc,kx,ky,qmax,dhx_g,dhy_g, &
                         icon,fu,fv,h0,tobs,hminfrot,iscreenlog,l_corio_cst,dhx,dhy, &
                         h0_g,hx_g,hy_g,h0fond,hm,vis2d,vish_xe,vish_phi,dhxy_g,dhxy, &
                         hrdef,dhj,hx,hy,dfiac,dgac,l_saverestart_1file,saverestart_step, &
                         jhemisph,l_saverestart_bydate,l_init_rtime
   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 comcolig2d, ONLY : me,mn,ms,mo,whx,why
   USE obccombine, ONLY : l_obc_north,l_obc_west,l_obc_mars,l_obc_tide
   USE cometdyn  , ONLY : tosx,tosy,wind_veloc,wind_dir
#if defined key_substance
   USE comsubstance
   USE comdiag,   ONLY : l_diag
   USE casinit,   ONLY : cas_init_subs,cas_init_subs_disspart,cas_init_outflow,cas_init_subs_budget
#endif
#ifdef key_sedim_MUSTANG
   USE parameters, ONLY : ksdmax
   USE comMUSTANG
   USE casinit,   ONLY : cas_init_sedim
#endif
#if defined key_castestriver
   USE comfluxdo,  ONLY : nbfl,iriv,jriv,kriv,debmoy,tmfle,amtfle,l_tempriv,l_flestat,  &
                          nomriviere,river_thickness                                     
#endif
#if defined key_biolo
   USE bioloinit
   USE subreaddat, ONLY : sub_read_vardiag
   USE comvars2d, ONLY : nvalmax
#if defined key_N_tracer
   USE parameters, ONLY : nb_var_tracerN 
#endif
#if defined key_P_tracer
   USE parameters, ONLY : nb_var_tracerP 
#endif
#endif


   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,nbrejb
   INTEGER           :: ni_wall_e,ni_wall_w,nj_wall_n,nj_wall_s
   INTEGER,DIMENSION(imin:imax,jmin:jmax)        :: ms_g,mn_g      ! wall (mur) at the South and North
   INTEGER,DIMENSION(imin:imax,jmin:jmax)        :: me_g,mo_g      ! wall (mur) at the East and West
   INTEGER,DIMENSION(imin:imax,jmin:jmax)        :: whx_g,why_g    ! wall at locations hx and hy
   INTEGER           :: IERR_MPI
   REAL(KIND=rsh)    :: dxval,dyval,x
   REAL(KIND=rsh)    :: z0bottom,z0surface,depthcst,zr
   CHARACTER(LEN=19) :: tool_sectodat
   INTEGER           :: iiv,indgrp
   INTEGER           :: iplat1,iplat2,jmil
   REAL(KIND=rsh),DIMENSION(imin:imax,jmin:jmax) :: hx_t,hy_t
   REAL(KIND=rsh),DIMENSION(imin:imax) :: dist_x
   REAL(KIND=rsh),DIMENSION(jmin:jmax) :: dist_y
   REAL(KIND=rsh)    :: rt,radi,dtemp,hdeep,hshallow,ws3maxloc,hplateau
   REAL(KIND=rsh)    :: dist_cotesud,dist_centre
   REAL(KIND=rlg)    :: tool_datosec,date_startshift_0
   LOGICAL           :: l_filesubs

!#ifdef key_sedim_MUSTANG
!   REAL(KIND=rsh)    :: dzsf,somalp
!#if defined key_castestsub || defined key_castestconta
!   LOGICAL           :: l_varassoc
!   INTEGER           :: ivpc
!#endif
!#endif
#ifdef key_substance
   REAL(KIND=rlg)    :: tdb,tfi
   INTEGER           :: n
#if defined key_N_tracer || defined key_P_tracer
   INTEGER                             :: is,ivtra,nbrej_tracer
#endif
#endif
  LOGICAL           :: l_nc4par

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

   PRINT_DBG*, 'enter CAS_PLATEAUBIO routine'

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

   ! dynamics
   CALL cas_init_param

   ! over-assignement
   l_corio_cst=.FALSE.
   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


  ! Bathymetry
   ! ----------
   nj_wall_s = 2  ! land over nj_wall_s cells (from jmin row) at the southern part of the domain
   ni_wall_e = 1  ! land over nj_wall_e cells at the eastern part of the domain
   nj_wall_n=0
   ni_wall_w=0
#if defined key_siggen || defined key_gencoord
   hc= 5.0_rsh 
#endif

!!! SPECIFIC DEFINITION OF BATHYMETRIE FOR THIS TEST CASE
!!------------------------------------------------------------
   ! depth of the domain
   ! -------------------
   hshallow=10.0_rsh
   hplateau=100.0_rsh
   hdeep=hplateau
   iplat1=imin
   iplat2=iplat1+2
   hx_g(imin+ni_wall_w:iplat1,jmin+nj_wall_s:jmax)=hdeep
   hy_g(imin+ni_wall_w:iplat1,jmin+nj_wall_s:jmax)=hdeep

   DO i=iplat1+1,iplat2
     hx_g(i,jmin+nj_wall_s:jmax)=hdeep-REAL(i-iplat1-1,rsh)/REAL(iplat2-iplat1-1,rsh)*(hdeep-hplateau)
     hy_g(i,jmin+nj_wall_s:jmax)=hdeep-REAL(i-iplat1-1,rsh)/REAL(iplat2-iplat1-1,rsh)*(hdeep-hplateau)
   END DO
   DO i=iplat2+1,imax-ni_wall_e-1
     hx_g(i,jmin+nj_wall_s:jmax)=hplateau-REAL(i-iplat2-1,rsh)/REAL(imax-iplat2-1,rsh)*(hplateau-hshallow)
     hy_g(i,jmin+nj_wall_s:jmax)=hplateau-REAL(i-iplat2-1,rsh)/REAL(imax-iplat2-1,rsh)*(hplateau-hshallow)
   END DO
   hy_g(imax-ni_wall_e,jmin+nj_wall_s:jmax)=hplateau-REAL(i-iplat2-1,rsh)/REAL(imax-iplat2-1,rsh)*(hplateau-hshallow)
   jmil=(jmax+jmin)*0.5
   DO i=imin+ni_wall_w+1,imax-ni_wall_e
   DO j=jmin+nj_wall_s,jmax
      h0_g(i,j)=MAX(hx_g(i,j),hy_g(i,j),hx_g(i-1,j),hy_g(i,j-1))
   ENDDO
   ENDDO
   h0_g(imin,jmin+nj_wall_s:jmax)=hx_g(imin,jmin+nj_wall_s:jmax)

   ! wall mask
   ! ---------
   me_g(:,:)=1
   mo_g(:,:)=1
   ms_g(:,:)=1
   mn_g(:,:)=1
   whx_g(:,:)=1
   why_g(:,:)=1

  ! grid parametrization need for bathy
   ! ---------------------------------------
   dxval = 4000.0_rsh
   dyval = 4000.0_rsh
   hx_g(:,jmin:jmin+nj_wall_s-1)=-valmanq-h0fond
   hy_g(:,jmin:jmin+nj_wall_s-1)=-valmanq-h0fond
   h0_g(:,jmin:jmin+nj_wall_s-1)=-valmanq

!  côte sud en arc de cercle
   DO j=jmil,jmin,-1
    dist_y(j)=(jmil-j)*dyval
   ENDDO
   dist_cotesud=dist_y(jmin)
   DO i=imin,imax
    dist_x(i)=(i-imin)*dxval
   ENDDO
   DO i=imin+ni_wall_w+1,imax-ni_wall_e
   DO j=jmin+nj_wall_s,jmil
     dist_centre=sqrt(dist_x(i)**2+dist_y(j)**2)
     IF(dist_centre >= dist_cotesud ) THEN
        hx_g(i,j)=-valmanq-h0fond
        whx_g(i,j)=0
        IF(hx_g(i-1,j)== -valmanq-h0fond) THEN
                 hy_g(i,j)=-valmanq-h0fond
                 mn_g(i,j)=0
                 why_g(i,j)=0
        ENDIF
        h0_g(i,j)=MAX(hx_g(i,j),hy_g(i,j),hx_g(i-1,j),hy_g(i,j-1))
        me_g(i,j)=0
        ms_g(i,j)=0
     ENDIF
    ENDDO
   ENDDO

   depthcst = 0.0_rsh

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

   WHERE (ms_g(limin:limax,ljmin:ljmax) == 0) ms(limin:limax,ljmin:ljmax)=0
   WHERE (mn_g(limin:limax,ljmin:ljmax) == 0) mn(limin:limax,ljmin:ljmax)=0
   WHERE (me_g(limin:limax,ljmin:ljmax) == 0) me(limin:limax,ljmin:ljmax)=0
   WHERE (mo_g(limin:limax,ljmin:ljmax) == 0) mo(limin:limax,ljmin:ljmax)=0
   WHERE (whx_g(limin:limax,ljmin:ljmax) == 0) whx(limin:limax,ljmin:ljmax)=0
   WHERE (why_g(limin:limax,ljmin:ljmax) == 0) why(limin:limax,ljmin:ljmax)=0


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

   ! assignement : input variables for cas_init_grid routine
   ! already assigned (see higher) because of bathymetrie definition
   !dxval = 4000.0_rsh
   !dyval = 4000.0_rsh
   radi=57.29578_rsh
   rt=6.367e+6
   dfiac=dyval*radi/rt
   dgac=dyval*radi/rt/COS(41.0_riolg/radi)
   fisac=41.0_riolg-REAL(jmax,riolg)/2.0_riolg*dfiac
   gwac=20.0_riolg

#if defined key_siggen || defined key_gencoord
   theta_sig= 4.0_rsh ! entre 0 et 20
  ! theta_sig= 0.0000001_rsh ! entre 0 et 20
   b_sig= 1.0_rsh     ! entre 0 et 1
#endif
   jhemisph=1

   CALL cas_init_grid(dxval,dyval)

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

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

! time lag (in days) between the run starting time and date_start
   date_startshift_0=0.0_rlg

   dtmin=50.0_rlg
   dtmax=200.0_rlg
   dt=100.0_rlg
   halfdt=dt*0.5_rlg
   suffix='bioplat'
#ifdef key_substance
   date_startsub='01/01/1900 01:00:00'
   tdebsubs=tool_datosec(date_startsub)
#ifdef key_sedim_MUSTANG
   ! 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
#endif
#endif
   l_nc4par = .TRUE.

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

   ! over-assignement
   tobs=2.0_rlg*3600.0_rlg
   l_init_rtime=.FALSE.
   l_saverestart_1file=.FALSE.
   l_saverestart_bydate=.TRUE.
   saverestart_step=6.0_rlg*31.0_rlg*24.0_rlg*3600.0_rlg   ! in hours
   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.5_rsh*86400.0_rlg
#if defined key_biolo
   l_diag=.TRUE.
#else
   l_diag=.FALSE.
#endif

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

   ! no open boundary
   CALL cas_init_obc

   ! over-assignement
   l_obc_north=.TRUE.
   l_obc_west=.TRUE.
   l_obc_mars = .TRUE.
   l_obc_tide=.TRUE.
!   l_obc_ogcm_relax=.FALSE.

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

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

   ! turbulence
   ! ----------
   z0bottom   =0.0035
   z0surface  =0.1_rsh
   kzinit=0.00001_rsh
   nzinit=0.001_rsh

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

   ! over-assignement
   turb_nbeq=1
   ect(:,:,:)=0.000001_rsh
   bgdiff=0.000001_rsh

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

   ! no forcing
   CALL cas_init_meteo

   ! over-assignement
   wind_veloc=6.0_rsh
   wind_dir=90.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
   ! -----------------------------------------

   ! set to 0,tetaref,saliref
   CALL cas_init_progvar

  ! over-assignement
   ssh(:,:)  = MAX(1.0_rsh,-h0(liminm2:limaxp2,ljminm2:ljmaxp2))
   ! dynamics
#if defined key_siggen || defined key_gencoord
   call init_height(ssh)
#endif

   ! 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
   !--------------
#if defined key_substance
   ! 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"
#ifdef key_biolo
       ! par defaut : modele de base
       ! 17 variables d etat : on lit un fichier variable.dat de base dans inputs
       ! et pour les cles speciales avec encore plus de varables
       ! on lira d autres fichiers
#ifdef key_biolo_opt2
         name_filesubs = '../inputs/variable_bio_debase2.dat'
#else
       ! biolo option 1
         name_filesubs = '../inputs/variable_bio_debase1.dat'
#if defined key_benthos && defined key_oxygen
         name_filesubs = '../inputs/variable_bio_bentO2.dat'
#endif
#if defined key_benthos && defined key_oxygen && defined key_N_tracer && defined key_psnz
         name_filesubs = '../inputs/variable_bio_bentO2psnz.dat'
#endif
#if defined key_benthos && defined key_oyster_DEB
         name_filesubs = '../inputs/variable_bio_oysterDEB.dat'
#endif
#if defined key_benthos && defined key_oyster_SFG
         name_filesubs = '../inputs/variable_bio_oysterSFG.dat'
#endif
#if defined key_karenia && defined key_psnz && defined key_phaeocystis && defined key_oxygen && defined key_benthos
         name_filesubs = '../inputs/variable_bio_previmer.dat'
#endif
#endif
#endif
     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
#if defined key_N_tracer || defined key_P_tracer
   l_bilan=.FALSE.
#else
   l_bilan=.TRUE.
#endif
   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

#ifdef key_biolo
   !   VARIABLES DIAGNOSTIQUES
   ! ---------------------------------------
 ! lecture des parametres pour key_biolo ranges dans inputs comme le fichier de variables

   filevardiag='../inputs/vardiag_biodebase.dat'
#ifdef key_biolo_opt2
   filevardiag='../inputs/vardiag_biodebase_opt2.dat'
#else
#ifdef key_oxygen
   filevardiag = '../inputs/vardiag_biobentO2.dat'
#endif
#if defined key_benthos && defined key_oyster_DEB
   filevardiag = '../inputs/vardiag_bio_oysterDEB.dat'
#endif
#if defined key_benthos && defined key_oyster_SFG
   filevardiag = '../inputs/vardiag_bio_oysterSFG.dat'
#endif
#if defined key_benthos && defined key_oxygen && defined key_N_tracer && defined key_psnz
   filevardiag = '../inputs/vardiag_biobentO2psnz.dat'
#endif
#if defined key_karenia && defined key_psnz && defined key_phaeocystis && defined key_oxygen && defined key_benthos
   filevardiag = '../inputs/vardiag_bioprevimer.dat'
#endif
#endif
   call sub_read_vardiag
   call biolo_userinit(cv_wat)
   call biolo_param('w')

   !pas besoin d appeler subs_part_castestbiolo car fait dans sub_read_var appelle par init_subs_castestbiolo

      sub_flx_atm(iv_nutr_NO3)=0.000001_rsh
      sub_flx_atm(iv_nutr_SiOH)=0.000001_rsh
      sub_flx_atm(iv_nutr_PO4)=0.000001_rsh
      l_subflxatm=.true.
      sflx_sub_atm_depth=0.5_rsh
#endif

#endif
   
   ! River
   ! ----------
#if defined key_castestriver     
   nbfl=1
   CALL cas_init_river(nbfl)

   ! over-assignement

   iriv(1)=49
   jriv(1)=50
   kriv(1)=20
   river_thickness(1)=100.0_rsh
   nomriviere(1)='RIV1'
   debmoy(1)=500.0_rsh
   tmfle(1)=15.0_rsh
   amtfle(1)=5.0_rsh

#if defined key_substance
#if defined key_biolo 
     !  si cle key_castestriver : initialisation of variables fluxes
     ! number of variable which are injected threw the river            
   nbrej=6
   nbrejb=nbrej
#if defined key_N_tracer 
   nbrej=nbrejb+nb_var_tracerN
#endif
#if defined key_P_tracer
   nbrej=nbrejb+nb_var_tracerP
#endif
#else 
   nbrej=2
#endif

   CALL cas_init_outflow

   ! over-assignement
   numriv(:)=1 
   l_rejflux(:)=.true.

!#if defined key_N_tracer
!        nbrej_tracer= nbrej + nb_source_river_tracerN* nb_var_tracerN 
!       ALLOCATE(xrej(nbrej_tracer),yrej(nbrej_tracer),krej(nbrej_tracer))
!       ALLOCATE(nucon(nbrej_tracer),numriv(nbrej_tracer))
!       ALLOCATE(l_rejflux(nbrej_tracer),valrej(nvalmax,nbrej_tracer))
!#endif

#if defined key_biolo    
   nucon(1)=1              ! MES                                                     
   nucon(2)=iv_nutr_Pads   ! sorbed phosphate                                               
   nucon(3)=iv_nutr_NH4  ! ammonium
   nucon(4)=iv_nutr_SiOH  ! dissolved silicate
   nucon(5)=iv_nutr_PO4 ! dissolved phosphate
   nucon(6)=iv_nutr_NO3 ! dissolved nitrate

   ! Flux rejetes par la riviere (masse=mmole/s sauf pour MES= kg/s)
    valrej(:,1)=0.050_rsh*debmoy(1)
    valrej(:,2)=0.0_rsh*debmoy(1)
    valrej(:,3)=5.0_rsh*debmoy(1)
    valrej(:,4)=5.0_rsh*debmoy(1)
    valrej(:,5)=50.0_rsh/16.0_rsh*debmoy(1)
    valrej(:,6)=50.0_rsh*debmoy(1)
#if defined key_N_tracer
     ! definition of tracer sources points
     DO is=1,nb_source_river_tracerN
        DO k = 1,nbfl
           IF (TRIM(nomriviere(k)) == TRIM(name_source_tracerN(is)) ) THEN
             DO ivtra=1,nb_var_tracerN
               nbrejb=nbrejb+1
               nucon(nbrejb)=iv_tracer_N(ivtra,is)
               xrej(nbrejb)=iriv(k)
               yrej(nbrejb)=jriv(k)
               krej(nbrejb)=kriv(k)
               DO iiv=1,nbrej-ivtra-nb_var_tracerN*(is-1)
                IF(iv_signed_N(ivtra,is)== nucon(iiv))then
                   valrej(:,nbrejb)=p_marque_tracerN(ivtra,is)*valrej(:,nb_var_tracerN*(is-1)+iiv)
                   exit
                ELSE
                   valrej(:,nbrejb)=0.0_rsh
                ENDIF
               ENDDO
               l_rejflux(nbrejb)=l_rejflux(iiv)
               numriv(nbrejb)=k
             ENDDO
             exit
           ENDIF
        ENDDO    
    ENDDO    
#endif
#if defined key_P_tracer
     ! definition of tracer sources points
     DO is=1,nb_source_river_tracerP
        DO k = 1,nbfl
           IF (TRIM(nomriviere(k)) == TRIM(name_source_tracerP(is)) ) THEN
             DO ivtra=1,nb_var_tracerP
               nbrejb=nbrejb+1
               nucon(nbrejb)=iv_tracer_P(ivtra,is)
               xrej(nbrejb)=iriv(k)
               yrej(nbrejb)=jriv(k)
               krej(nbrejb)=kriv(k)
               DO iiv=1,nbrej-ivtra-nb_var_tracerP*(is-1)
                IF(iv_signed_P(ivtra,is)== nucon(iiv))then
                   valrej(:,nbrejb)=p_marque_tracerP(ivtra,is)*valrej(:,nb_var_tracerP*(is-1)+iiv)
                   exit
                ENDIF
               ENDDO
               l_rejflux(nbrejb)=l_rejflux(iiv)
               numriv(nbrejb)=k
             ENDDO
             exit
           ENDIF
        ENDDO    
    ENDDO    
#endif

#else                                                              
   nucon(1)=1              ! MES                                                     
   nucon(2)=2   ! dissoute                                               

   ! Flux rejetes par la riviere (masse=mmole/s sauf pour MES= kg/s)                                                       
    valrej(:,1)=0.025_rsh*debmoy(1)
    valrej(:,2)=1._rsh*debmoy(1)
#endif
#endif
#endif

  END SUBROUTINE cas_bioplat



