 MODULE parameters

   !!======================================================================
   !!                   ***  MODULE parameters  ***
   !! 
   !! ** Description : parameters for a rank 0 configuration
   !! 
   !!
   !! ** Reference :
   !!                T. Duhaut, M. Honnorat, L. Debreu, 2008 : Rapport
   !!                contrat PREVIMER - Ref : 06/2 210 290 (pages 100-125)
   !!
   !! ** History :
   !!       !  2008-07 (L. Debreu, M. Honnorat, T. Duhaut) time scheme
   !!       !  2008-09 (G. Galibert / ALTRAN) attributes of output files
   !!                   to respect NetCDF OCO v1.1 file format
   !!                   modification of rg_valmanq_io and addition of dg_valmanq_io
   !!
   !!======================================================================
   !! * Modules used

   !! * Shared or public module variables

   INTEGER,PARAMETER :: riosh=4,riolg=8,rlg=8,rsh=8,lchain=200
   CHARACTER(len=4),PARAMETER :: nrac='LOIR'
   LOGICAL,PARAMETER :: l_testcase=.FALSE.
   INTEGER,PARAMETER :: num_testcase=0

   INTEGER,PARAMETER :: no=0 ! rank
   INTEGER           &
#if ! defined key_agrif
          ,PARAMETER &
#endif
                     :: imin=0,imax=466,jmin=0,jmax=251 ! configuration rang_0
! obc_width=number of lines (or columns) in your obc files - 1
   INTEGER,PARAMETER :: kmax=10,obc_width=35
   ! shift of obc for non-linear advection terms
   INTEGER          &
#if ! defined key_agrif
         ,PARAMETER &
#endif
           :: ishift_obc_west=0,ishift_obc_east=0,jshift_obc_south=0,jshift_obc_north=0

#ifdef key_tide_saverotatedobc
   INTEGER,PARAMETER :: imin_child=0,jmin_child=0,imax_child=131,jmax_child=100
#endif
#ifdef key_lagoon
   INTEGER,PARAMETER :: nbgraumax=3
#ifdef key_lagoon_spec
   INTEGER,PARAMETER :: nbparc=618
#endif
#endif

#ifdef key_substance

#ifdef key_sedim_MUSTANG
   !!**************************************************************************************                             
   !! for SEDIMENT MODULE : give ksdmin, ksdmax, nb_var_sedconstit 
   !!                       + nb_var_base (others variables) if not key_biolo 
   !!**************************************************************************************                             
   !!
   !!   . maximum number of layers (ksdmax)
   !! =====================================
   INTEGER,PARAMETER :: ksdmin=1,ksdmax=100
   !!
   !!   . number of constitutive particulate variables (GRAV, SAND, MUDS) : nb_var_sedconstit
   !! ====================================================================================
   INTEGER,PARAMETER :: nb_var_sedconstit=5
 
   !!   . number of all other variables (DISS, NCP, MUDB, FIXE, INT, DRIV)) : nb_var_base (only if .not.key_biolo)
   !! ====================================================================================
#if ! defined key_biolo
   INTEGER,PARAMETER :: nb_var_base=0
#endif 
 
#else
   INTEGER,PARAMETER :: nb_var_sedconstit=0
   
   !!********************************************************************************************
   !! IF NO SEDIMENT MODULE  : 	give nb_var_base (except if key_biolo)                             
   !! exact number of simulate variables 
   !! sum of state (dissolved and particulate) + fixed +intermediate + driving variables  
   !!===========================================================================================
#if ! defined key_biolo
   INTEGER,PARAMETER :: nb_var_base=1
#endif 
   !!********************************************************************************************                             
#endif
! fin  key_sedim_MUSTANG                                

#if defined key_biolo
   INTEGER,PARAMETER :: nb_var_base=0
   
  !!********************************************************************************************
  !!  MODULE ECOMARS (key_biolo): nb_var is automatically computed
  !! roots modules (option 1 by default or option 2 : key_biolo_opt2)
  !! number of biological simulate variables nb_var_bio
  !!       all dissolved and particulate) + fixed +intermediate + driving variables
  !!       except particulate constitutive variables (GRAV,SAND, MUDS) if key_sedim
  !!============================================================================================

#ifdef key_biolo_opt2

! option 2 : Marc : 4 variables supplementaires (N2, et N,P,Si detritique dissous)
! MES : constitutive particulate variable ( in nb_var_sedconstit)
#ifdef key_sedim_MUSTANG
   INTEGER,PARAMETER :: nb_var_bio=20
#else
   INTEGER,PARAMETER :: nb_var_bio=21
#endif

#else
! option 1 par defaut : Alain, Philippe 
#ifdef key_sedim_MUSTANG
! MES : constitutive particulate variable ( in nb_var_sedconstit)
   INTEGER,PARAMETER :: nb_var_bio=16
#else
   INTEGER,PARAMETER :: nb_var_bio=17
#endif

#endif

  !!***************************************
  !! optionnal modules 
  !! number of additional variables
  !!========================================
#ifdef key_psnz
   INTEGER,PARAMETER :: nb_var_psnz=4
#else
   INTEGER,PARAMETER :: nb_var_psnz=0
#endif
#ifdef key_karenia
   INTEGER,PARAMETER :: nb_var_karenia=3
#else
   INTEGER,PARAMETER :: nb_var_karenia=0
#endif 
#ifdef key_phaeocystis
   INTEGER,PARAMETER :: nb_var_phaeocystis=4
#else
   INTEGER,PARAMETER :: nb_var_phaeocystis=0
#endif 
#ifdef key_zoo_prod
   INTEGER,PARAMETER :: nb_var_zoo_ps=2
#else
   INTEGER,PARAMETER :: nb_var_zoo_ps=0
#endif
#ifdef key_ulvas
   INTEGER,PARAMETER :: nb_var_ulv=8
#else
   INTEGER,PARAMETER :: nb_var_ulv=0
#endif
#if defined key_oyster_SFG || defined key_oyster_DEB
   INTEGER,PARAMETER :: nb_var_oys=3
#else
   INTEGER,PARAMETER :: nb_var_oys=0
#endif
#ifdef key_oxygen
   INTEGER,PARAMETER :: nb_var_oxy=1
#else
   INTEGER,PARAMETER :: nb_var_oxy=0
#endif
#ifdef key_microtracers
   INTEGER,PARAMETER :: nb_var_microtracers=6
#else
   INTEGER,PARAMETER :: nb_var_microtracers=0
#endif 
#ifdef key_benthos
   INTEGER,PARAMETER :: nb_var_benth_det=3
#ifdef key_diatbenth
#ifdef key_NPbenth
   INTEGER,PARAMETER :: nb_var_benth_plus=3
#else
   INTEGER,PARAMETER :: nb_var_benth_plus=1
#endif
#elif key_zostera
   INTEGER,PARAMETER :: nb_var_benth_plus=3
#else
   INTEGER,PARAMETER :: nb_var_benth_plus=0
#endif
#else
   INTEGER,PARAMETER :: nb_var_benth_det=0
   INTEGER,PARAMETER :: nb_var_benth_plus=0
#endif
#ifdef key_suspensivores
   INTEGER,PARAMETER :: nb_var_benth_susp=1
#else
   INTEGER,PARAMETER :: nb_var_benth_susp=0
#endif
#ifdef key_benthos_gener
   INTEGER,PARAMETER :: nb_var_benth_gener=4
#else
   INTEGER,PARAMETER :: nb_var_benth_gener=0
#endif
#ifdef key_larve
  INTEGER,PARAMETER :: nb_var_larve=6
#else
   INTEGER,PARAMETER :: nb_var_larve=0
#endif
#ifdef key_N_tracer
   INTEGER,PARAMETER :: nb_sourceN=1
   INTEGER,PARAMETER :: nb_var_tracerN_defaut=8
!  modele de base=8, ajouter 1 pour Karenia ou pour Pseudo-Nitzschia   
#ifdef key_psnz
   INTEGER,PARAMETER :: nb_var_tracerN_psnz=1
#else
   INTEGER,PARAMETER :: nb_var_tracerN_psnz=0
#endif
#ifdef key_karenia
   INTEGER,PARAMETER :: nb_var_tracerN_kar=1
#else
   INTEGER,PARAMETER :: nb_var_tracerN_kar=0
#endif 
#ifdef key_phaeocystis
   INTEGER,PARAMETER :: nb_var_tracerN_phae=2
#else
   INTEGER,PARAMETER :: nb_var_tracerN_phae=0
#endif 
#ifdef key_ulvas
   INTEGER,PARAMETER :: nb_var_tracerN_ulv=2
#else
   INTEGER,PARAMETER :: nb_var_tracerN_ulv=0
#endif
#ifdef key_benthos
   INTEGER,PARAMETER :: nb_var_tracerN_bent=1
#else
   INTEGER,PARAMETER :: nb_var_tracerN_bent=0
#endif
   INTEGER,PARAMETER :: nb_var_tracerN= nb_var_tracerN_defaut+nb_var_tracerN_bent+nb_var_tracerN_ulv+nb_var_tracerN_phae+nb_var_tracerN_kar+nb_var_tracerN_psnz
#ifdef key_age_tracer
   INTEGER,PARAMETER :: nb_var_N_age_tracer=nb_var_tracerN
#else    
   INTEGER,PARAMETER :: nb_var_N_age_tracer=0
#endif 
#else    
   INTEGER,PARAMETER :: nb_sourceN=0
   INTEGER,PARAMETER :: nb_var_tracerN=0
   INTEGER,PARAMETER :: nb_var_N_age_tracer=0
#endif
#ifdef key_P_tracer
   INTEGER,PARAMETER :: nb_sourceP=2
   INTEGER,PARAMETER :: nb_var_tracerP_defaut=8
!  modele de base=8, ajouter 1 pour Karenia ou pour Pseudo-Nitzschia   
#ifdef key_psnz
   INTEGER,PARAMETER :: nb_var_tracerP_psnz=1
#else
   INTEGER,PARAMETER :: nb_var_tracerP_psnz=0
#endif
#ifdef key_karenia
   INTEGER,PARAMETER :: nb_var_tracerP_kar=1
#else
   INTEGER,PARAMETER :: nb_var_tracerP_kar=0
#endif 
#ifdef key_phaeocystis
   INTEGER,PARAMETER :: nb_var_tracerP_phae=2
#else
   INTEGER,PARAMETER :: nb_var_tracerP_phae=0
#endif 
#ifdef key_benthos
   INTEGER,PARAMETER :: nb_var_tracerP_bent=1
#else
   INTEGER,PARAMETER :: nb_var_tracerP_bent=0
#endif
   INTEGER,PARAMETER :: nb_var_tracerP= nb_var_tracerP_defaut+nb_var_tracerP_bent+nb_var_tracerP_phae+nb_var_tracerP_kar+nb_var_tracerP_psnz
#ifdef key_age_tracer
   INTEGER,PARAMETER :: nb_var_P_age_tracer=nb_var_tracerP
#else    
   INTEGER,PARAMETER :: nb_var_P_age_tracer=0
#endif
#else    
   INTEGER,PARAMETER :: nb_sourceP=0
   INTEGER,PARAMETER :: nb_var_tracerP=0
   INTEGER,PARAMETER :: nb_var_P_age_tracer=0
#endif
#ifdef key_zostera
   INTEGER,PARAMETER :: nb_var_zost=13
#else
   INTEGER,PARAMETER :: nb_var_zost=0
#endif

!!  fin key_biolo
#endif

  !!***************************************
  !! particular testcase 
  !!========================================
#if defined key_castestsub
   INTEGER,PARAMETER :: nb_var_cas=5
#elif key_castestconta
   INTEGER,PARAMETER :: nb_var_cas=8
#elif key_castestsablovase
   INTEGER,PARAMETER :: nb_var_cas=3
#else
  !!***************************************
  !! general case 
  !!========================================
   INTEGER,PARAMETER :: nb_var_cas=nb_var_base+nb_var_sedconstit
#endif

  !!***************************************
  !! Contaminant
  !!========================================
#ifdef key_contaminant
   INTEGER,PARAMETER :: ntypreac=7         !! nb types de reactions deja programmeess
!!  4 parameters for preliminary and temporary arrays of contaminants
   INTEGER,PARAMETER  :: nfracvmax=10       !! nb max fractions possibles regroupees dans une variable
   INTEGER,PARAMETER  :: nflimcomax=10      !! nb max limiting functions for generic reaction of contaminant
   INTEGER,PARAMETER  :: nrecomax=20        !! nb max reaction affected contaminant
   INTEGER,PARAMETER  :: nvactcomax=10      !! nb max active variables for contaminant
#endif

#endif
   INTEGER,PARAMETER :: nbpartmax=1,nbtachmax=1
   INTEGER,PARAMETER :: ngridmax=10,nmarmax=144,nbchprox=1

   ! global variables for characteristics method (obc)
   ! coefficient used when correcting matrixes
   REAL(KIND=rsh),PARAMETER :: al1=1.0_rsh,al2=1.0_rsh,al3=-1.0_rsh,ac0=1.0_rsh-al1/4.0_rsh, &
                               ac1=al2+al3/2.0_rsh,ac2=al2/4.0_rsh+al3/2.0_rsh

   ! implicit and explicit coefficients
   REAL(kind=rsh)  ,PARAMETER :: cfroe=0.5_rsh,cfroi=1.0_rsh-cfroe
   ! alphap (p for previous) must be lower than 0.5
   ! alphan (n for next)
   REAL(kind=rsh)  ,PARAMETER :: alphap=0.45_rsh,alphan=1.0_rsh-alphap
   REAL(kind=rsh)  ,PARAMETER :: valmanq=999.0_rsh
   REAL(kind=riosh),PARAMETER :: rg_valmanq_io=999.0_riosh
    REAL(kind=riolg),PARAMETER :: dg_valmanq_io=-1.7e+38
   !REAL(kind=riolg),PARAMETER :: dg_valmanq_io=-9.e+33
   REAL(kind=rlg)  ,PARAMETER :: pi=3.141592654_rlg,tref=59958230400_rlg,epsilon=0.00000001_rlg
   REAL(KIND=rsh)  ,PARAMETER :: grav=9.81_rsh
   REAL(KIND=rlg)  ,PARAMETER :: exp1=2.718281828_rlg
#ifdef key_grid_curv
   ! to adapt to your grid : min and max dx to compute surf  to avoid a division by 0
   REAL(KIND=rlg)  ,PARAMETER :: dxmin=10.0,dxmax=5000.0
   ! Missing value of lon,lat,dx .. etc in case there is no mesh
   REAL(kind=riolg),PARAMETER :: valmanq_curv=-999
#endif

#ifdef key_agrif
   INTEGER :: imaxm2=imax-2
   INTEGER :: jmaxm2=jmax-2
   INTEGER :: lax=imax+jmax
   INTEGER,PARAMETER :: nb_connect=3 ! nb of mesh similar between mother and child grids
#endif

   INTEGER :: ljmin=jmin,ljminp1=jmin+1+jshift_obc_south,ljminp2=jmin+2+jshift_obc_south, &
              ljminm1=jmin,ljminm2=jmin,ljminp1m2=jmin+1+jshift_obc_south,ljminp1m1=jmin+1+jshift_obc_south
   INTEGER :: ljmax=jmax,ljmaxm1=jmax-1-jshift_obc_north,ljmaxm1p1=jmax-1-jshift_obc_north, &
              ljmaxp1=jmax,ljmaxp2=jmax,ljmaxp3=jmax
   INTEGER :: limin=imin,liminp1=imin+1+ishift_obc_west,liminp2=imin+2+ishift_obc_west, &
              liminm1=imin,liminm2=imin,liminp1m2=imin+1+ishift_obc_west,liminp1m1=imin+1+ishift_obc_west
   INTEGER :: limax=imax,limaxm1=imax-1-ishift_obc_east,limaxm1p1=imax-1-ishift_obc_east, &
              limaxp1=imax,limaxp2=imax,limaxp3=imax

#ifdef key_substance
#ifdef key_biolo
INTEGER, PARAMETER :: nb_var=nb_var_bio+nb_var_base+nb_var_psnz+nb_var_karenia+nb_var_phaeocystis+nb_var_ulv+nb_var_oys+nb_var_oxy + &
                      +nb_var_zoo_ps+nb_var_microtracers+nb_var_tracerN*nb_sourceN+nb_var_N_age_tracer*nb_sourceN+nb_var_tracerP*nb_sourceP+ &
                      nb_var_P_age_tracer*nb_sourceP+nb_var_benth_det+nb_var_benth_plus+nb_var_benth_susp+nb_var_benth_gener + &
                      nb_var_larve+nb_var_zost+nb_var_sedconstit
#else
   INTEGER,PARAMETER :: nb_var=nb_var_cas
#endif
#endif

 END MODULE parameters
