 MODULE bioloinit

#if defined key_substance && defined key_biolo

   !!======================================================================
   !!                   ***  MODULE  bioloinit  ***
   !! Ocean dynamics Bio :  Initializations, reading of files *.dat (rivers, discharges, bio variables...)
   !!
   !!   History :
   !!        !  2011-01 (R. Ramel Alyotech) Ionc library in fortran 90/95, netcdf4 and MPI
   !!        !  2012-07 (B.Thouvenin) report des mises a jour des differents utilisateurs pour la V906
   !!
   !!======================================================================

#include "toolcpp.h"

   !! * Modules used
   USE parameters, ONLY : rsh,rlg,riosh,lchain,imin,imax,jmin,jmax,kmax, &
                          limin,limax,ljmin,ljmax
#if defined key_N_tracer
   USE parameters, ONLY : nb_var_tracerN
#endif  
#if defined key_P_tracer
   USE parameters, ONLY : nb_var_tracerP
#endif
   !USE comsubstance,  ONLY :phytomoy,phytocarre
   USE comsubstance,  ONLY : cmes_3dmgl
   USE ionc4, ONLY : ionc4_openr,ionc4_read_dimt,ionc4_read_time,ionc4_read_xyt,ionc4_close
   USE_MPI toolmpi, ONLY : MASTER

   IMPLICIT NONE
   PRIVATE

   !! * Accessibility
   PUBLIC biolo_userinit                ! routine called by main.F90
   PUBLIC biolo_param                   ! routine called by init.F90
   PUBLIC biolo_init_iv,biolo_init_id   ! routine called by subreaddat.F90
#if defined key_N_tracer || defined key_P_tracer
   PUBLIC biolo_create_vartracer,biolo_create_vardiagtracer   ! routine called by subreaddat.F90
#endif

   !! * Interface
   INTERFACE biolo_userinit
!     MODULE PROCEDURE biolo_init_dinodiatzoo
     MODULE PROCEDURE biolo_init_nut4phy3zoo2
   END INTERFACE

   !! * Shared or public module variables
#ifdef key_parsub_newdt
!  rajout pour avoir ndt_part variable dans le temps et calcule en fonction de ws
   REAL(KIND=rsh),DIMENSION(:),ALLOCATABLE,PUBLIC   :: ws3max_bio
#endif
   INTEGER, PUBLIC   :: ihour_previous
   INTEGER, PUBLIC   :: &
            iv_nutr_NO3,    &   ! index for nitrate
            iv_nutr_SiOH,   &   ! index for silicium
            iv_nutr_PO4,    &   ! index for phosphate
            iv_nutr_Pads,   &   ! index for adsorbed phosphate
            iv_phyto_diat_N, &   ! index for diatoms as nitrogen
            iv_phyto_dino_N, &   ! index for dinoflagellates as nitrogen
            iv_detr_N,      &   ! index for organic detritus as nitrogen
            iv_detr_Si,     &   ! index for organic detritus as silicon
            iv_detr_P,      &   ! index for organic detritus as phosphate
            iv_nutr_NH4,    &   ! index for ammonium
            iv_zoo_meso_N,  &   ! index for mesozooplankton
            iv_phyto_nano_N,      &   ! index for nanopicoplankton
            iv_zoo_micr_N,  &   ! index for microzooplankton
            iv_spim,        &   ! index for suspended particulate inorganic matter
            iv_phyto_diat_pp,     &   ! index for diatoms production
            iv_phyto_dino_pp,     &   ! index for dinoflagellates production
            iv_phyto_nano_pp          ! index for nanoflagellates production
#if defined key_zoo_prod
   INTEGER, PUBLIC   :: &
            iv_zoo_micr_ps,       &   ! index for microzooplankton production
            iv_zoo_meso_ps            ! index for mesozooplankton production
#endif	    
#if defined key_biolo_opt2
   INTEGER, PUBLIC   :: &
!! Insertion VS juin2010
            iv_diss_N,           & ! index for dissolved nitrogen
            iv_diss_P,           & ! index for dissolved phosphate
            iv_diss_Si,          & ! index for dissolved silicate
!! fin insertion nvelles variables
! Insertion VS nov 2010
            iv_detr_fond_N,      & ! index for detritus cumulated in bottom of last wat layer
            iv_diss_fond_Nitr      ! index for diss nitr (N2) issued from det in last wat layer
#endif
#if defined key_psnz
   INTEGER, PUBLIC   :: &
            iv_phyto_psnz_N, &   ! index for PseudoNitzschia as nitrogen
            iv_phyto_psnz_Si,&   ! index for PseudoNitzschia as silicon
            iv_phyto_psnz_ad,&   ! index for PseudoNitzschia as domoic acid
            iv_phyto_psnz_pp     ! index for PseudoNitzschia primary production 
#endif
#if defined key_karenia
   INTEGER, PUBLIC   :: &
            iv_phyto_karenia_C, &   ! index for karenia as carbon
            iv_phyto_karenia_N, &   ! index for karenia as nitrogen
            iv_phyto_karenia_P, &   ! index for karenia as phosphorus
            iv_phyto_karenia_pp     ! index for karenia primary production 
#endif
#if defined key_phaeocystis
   INTEGER, PUBLIC   :: &
            iv_phyto_phaeocystis_colo_N, &   ! index for phaeocystis colonies as nitrogen
            iv_phyto_phaeocystis_cell_N, &   ! index for phaeocystis cells as nitrogen
            iv_phyto_phaeocystis_mucus,  &   ! index for phaeocystis mucus as mass
            iv_phyto_phaeocystis_pp          ! index for phaeocystis primary production 
#endif
#ifdef key_ulvas
   INTEGER, PUBLIC   :: &
            iv_ulv_sus_N,     &     ! index for suspended ulvas as nitrogen
            iv_ulv_benth_N,     &   ! index for benthic ulvas as nitrogen
            iv_ulv_susdrywght, &   ! index for suspended ulvas as dry weight
            iv_ulv_benthdrywght, & ! index for benthic ulvas as dry weight
            iv_ulv_sus_P,      &    ! index for suspended ulvas as phosphorus
            iv_ulv_benth_P,     &   ! index for benthic ulvas as phosphorus
            iv_ulv_suspp,      &   ! index for suspended ulvas production
            iv_ulv_benthpp         ! index for benthic ulvas production	    
#endif
#ifdef key_zostera
   INTEGER, PUBLIC   ::               &
                   iv_zost_LB,        &   ! index for zostera leaf biomass
                   iv_zost_RB,        &   ! index for zostera rhizomes and roots biomass
                   iv_zost_D,         &   ! index for zostera shoot density
                   iv_zost_LN,        &   ! index for zostera leaf nitrogen pool
                   iv_zost_RN,        &   ! index for zostera rhizomes and roots nitrogen pool
                   iv_zost_LP,        &   ! index for zostera leaf phophorus pool
                   iv_zost_RP,        &   ! index for zostera rhizomes and roots phosphorus pool
                   iv_detr_zost_N,    &   ! index for floating detrital N
                   iv_detr_zost_P,    &   ! index for floating detrital P
                   iv_zost_benth_N,   &   ! index for floating detrital N
                   iv_zost_benth_P,   &   ! index for floating detrital P
                   iv_zost_seed,      &   ! index for zostera seeds in the water column
                   iv_zost_benth_seed     ! index for zostera seeds in the sediment
!                   iv_zost_pp,        &   ! index for zostera cumulative production
!                   iv_zost_LNuptake,  &   ! index for zostera cumulative leaf N uptake
!                   iv_zost_LPuptake,  &   ! index for zostera cumulative leaf P uptake
!                   iv_zost_RNuptake,  &   ! index for zostera cumulative root N uptake
!                   iv_zost_RPuptake       ! index for zostera cumulative root P uptake
#endif
#ifdef key_oyster_SFG
   INTEGER, PUBLIC   :: &
            iv_oys_so,     &   ! index for oyster dry weight
            iv_oys_go,     &   ! index for oyster resgon weight
            iv_oys_co          ! index for oyster coq weight
#endif
#ifdef key_oxygen
   INTEGER, PUBLIC   :: &
            iv_oxygen          ! index for oxygen
#endif
   INTEGER, PUBLIC :: id_benthos_txf
#ifdef key_oyster_DEB
   INTEGER, PUBLIC   :: &
            iv_oysdeb_res,     &   ! index for oyster supplies
            iv_oysdeb_str,     &   ! index for oyster structures
            iv_oysdeb_gon          ! index for oyster gonades
        INTEGER, PUBLIC   :: &
            iv_oysdeb_res2,     &   ! index for oyster supplies
            iv_oysdeb_str2,     &   ! index for oyster structures
            iv_oysdeb_gon2          ! index for oyster gonades
        INTEGER, PUBLIC   :: &
            iv_oysdeb_res3,     &   ! index for oyster supplies
            iv_oysdeb_str3,     &   ! index for oyster structures
            iv_oysdeb_gon3          ! index for oyster gonades
#endif
#ifdef key_benthos
   INTEGER, PUBLIC   :: &
            iv_benth_N,     &   ! index for organic nitrogen in benthos
            iv_benth_Si,     &  ! index for organic silicon in benthos
            iv_benth_P          ! index for organic phosphorus in benthos
#ifdef key_diatbenth
   INTEGER, PUBLIC   :: iv_benth_phyto_diat_N   !index for benthic diatoms as nitrogen
#endif
#ifdef key_NPbenth
   INTEGER, PUBLIC   :: iv_benth_PO4,  iv_benth_NH4
#endif
#ifdef key_zostera
   INTEGER, PUBLIC   :: iv_benth_phyto_diat_N,  &  !index for benthic diatoms as nitrogen
                             iv_benth_PO4,           &
                             iv_benth_NH4
#endif
#endif
#ifdef key_microtracers
   INTEGER, PUBLIC   :: &
            iv_tracer_depth1, &       ! index for micro-tracer from depth 1
            iv_tracer_depth2,&        ! index for micro-tracer from depth 2
            iv_tracer_depth3,&        ! index for micro-tracer from depth 3
            iv_tracer_agedepth1,&     ! index for age of the micro-tracer from depth 1
            iv_tracer_agedepth2,&     ! index for age of the micro-tracer from depth 2
            iv_tracer_agedepth3,&     ! index for age of the micro-tracer from depth 3
            iv_tracer_cumuldepth1,&   ! index for cumulatiuve micro-tracer from depth 1
            iv_tracer_cumuldepth2,&   ! index for cumulatiuve micro-tracer from depth 2
            iv_tracer_cumuldepth3     ! index for cumulatiuve micro-tracer from depth 3
#endif
#if defined key_N_tracer
! index (rank model et rank file) for tracer variable coming from source
   INTEGER, dimension(:,:),ALLOCATABLE, PUBLIC   ::  iv_tracer_N,isubs_tracer_N 
! index for signed variable which is traced by corresponding tracer_variable (rank model et rank file)    
   INTEGER, dimension(:,:),ALLOCATABLE, PUBLIC   ::  iv_signed_N,isubs_signed_N    
   INTEGER, dimension(:),ALLOCATABLE,PUBLIC   :: iv_detr_tra_N,iv_nutr_NH4_tra_N,iv_nutr_NO3_tra_N,    &
                                                 iv_phyto_nano_tra_N,iv_phyto_diat_tra_N,iv_phyto_dino_tra_N,  &
                                                 iv_zoo_micr_tra_N,iv_zoo_meso_tra_N
#if defined key_benthos
   INTEGER, dimension(:),ALLOCATABLE,PUBLIC   :: iv_benth_tra_N
#endif
#if defined key_psnz
   INTEGER, dimension(:),ALLOCATABLE,PUBLIC   :: iv_phyto_psnz_tra_N
#endif
#if defined key_phaeocystis
   INTEGER, dimension(:),ALLOCATABLE,PUBLIC   :: iv_phyto_phaeocystis_colo_tra_N,iv_phyto_phaeocystis_cell_tra_N
#endif
#if defined key_karenia
   INTEGER, dimension(:),ALLOCATABLE,PUBLIC   :: iv_phyto_karenia_tra_N
#endif
#if defined key_ulvas
   INTEGER, dimension(:),ALLOCATABLE,PUBLIC   :: iv_ulv_benth_tra_N,iv_ulv_tra_N
#endif

#ifdef key_age_tracer
! index for the age (rank model et rank file)
   INTEGER, dimension(:,:),ALLOCATABLE, PUBLIC   ::  isubs_age_N,iv_age_N 
   INTEGER, dimension(:),ALLOCATABLE,PUBLIC   :: &
                         iv_detr_age_tra_N,iv_nutr_NH4_age_tra_N,iv_nutr_NO3_age_tra_N,iv_phyto_nano_age_tra_N, &
                         iv_phyto_diat_age_tra_N,iv_phyto_dino_age_tra_N,iv_zoo_micr_age_tra_N,iv_zoo_meso_age_tra_N
#if defined key_benthos
   INTEGER, dimension(:),ALLOCATABLE,PUBLIC   :: iv_benth_age_tra_N
#endif
#if defined key_psnz
   INTEGER, dimension(:),ALLOCATABLE,PUBLIC   :: iv_phyto_psnz_age_tra_N
#endif
#if defined key_phaeocystis
   INTEGER, dimension(:),ALLOCATABLE,PUBLIC   :: iv_phyto_phaeocystis_colo_age_tra_N,iv_phyto_phaeocystis_cell_age_tra_N
#endif
#if defined key_karenia
   INTEGER, dimension(:),ALLOCATABLE,PUBLIC   :: iv_phyto_karenia_age_tra_N
#endif
#if defined key_ulvas
   INTEGER, dimension(:),ALLOCATABLE,PUBLIC   :: iv_ulv_benth_age_tra_N,iv_ulv_age_tra_N
#endif
#endif
#endif

#if defined key_P_tracer
! index (rank model et rank file) for tracer variable coming from source 
   INTEGER, dimension(:,:),ALLOCATABLE, PUBLIC   ::  iv_tracer_P,isubs_tracer_P  
! index for signed variable which is traced by corresponding tracer_variable (rank model et rank file)
   INTEGER, dimension(:,:),ALLOCATABLE, PUBLIC   ::  iv_signed_P,isubs_signed_P  
   INTEGER, dimension(:),ALLOCATABLE,PUBLIC   :: iv_detr_tra_P,iv_nutr_PO4_tra_P,iv_nutr_Pads_tra_P,    &
                                                 iv_phyto_nano_tra_P,iv_phyto_diat_tra_P,iv_phyto_dino_tra_P, &
                                                 iv_zoo_micr_tra_P,iv_zoo_meso_tra_P
#if defined key_benthos
   INTEGER, dimension(:),ALLOCATABLE,PUBLIC   :: iv_benth_tra_P
#endif
#if defined key_psnz
   INTEGER, dimension(:),ALLOCATABLE,PUBLIC   :: iv_phyto_psnz_tra_P
#endif
#if defined key_phaeocystis
   INTEGER, dimension(:),ALLOCATABLE,PUBLIC   :: iv_phyto_phaeocystis_colo_tra_P,iv_phyto_phaeocystis_cell_tra_P
#endif
#if defined key_karenia
   INTEGER, dimension(:),ALLOCATABLE,PUBLIC   :: iv_phyto_karenia_tra_P
#endif
#if defined key_ulvas
   INTEGER, dimension(:),ALLOCATABLE,PUBLIC   :: iv_ulv_benth_tra_P,iv_ulv_tra_P
#endif

#ifdef key_age_tracer
   INTEGER, dimension(:,:),ALLOCATABLE, PUBLIC   ::  isubs_age_P,iv_age_P ! index for the age (rank model et rank file)
   INTEGER, dimension(:),ALLOCATABLE,PUBLIC   :: iv_detr_age_tra_P,iv_nutr_PO4_age_tra_P,iv_nutr_Pads_age_tra_P, &
                                                 iv_phyto_nano_age_tra_P,iv_phyto_diat_age_tra_P, &
                                                 iv_phyto_dino_age_tra_P,iv_zoo_micr_age_tra_P,iv_zoo_meso_age_tra_P
#if defined key_benthos
   INTEGER, dimension(:),ALLOCATABLE,PUBLIC   :: iv_benth_age_tra_P
#endif
#if defined key_psnz
   INTEGER, dimension(:),ALLOCATABLE,PUBLIC   :: iv_phyto_psnz_age_tra_P
#endif
#if defined key_phaeocystis
   INTEGER, dimension(:),ALLOCATABLE,PUBLIC   :: iv_phyto_phaeocystis_colo_age_tra_P,iv_phyto_phaeocystis_cell_age_tra_P
#endif
#if defined key_karenia
   INTEGER, dimension(:),ALLOCATABLE,PUBLIC   :: iv_phyto_karenia_age_tra_P
#endif
#if defined key_ulvas
   INTEGER, dimension(:),ALLOCATABLE,PUBLIC   :: iv_ulv_benth_age_tra_P,iv_ulv_age_tra_P
#endif
#endif
#endif

#ifdef key_suspensivores
   INTEGER, PUBLIC   :: &
            iv_benth_susp_N     ! index for suspensivores as nitrogen in benthos
#endif
#ifdef key_benthos_gener
   INTEGER, PUBLIC   :: &
            iv_benth_meio_N, &    ! index for bacterie+meiofaune as nitrogen in benthos
            iv_benth_deposi_N, &    ! index for deposivore+herbivore as nitrogen in benthos
            iv_benth_susp_N,   &  ! index for suspensivores as nitrogen in benthos
            iv_benth_carn_N     ! index for carnivore as nitrogen in benthos
#endif

#ifdef key_larve
         INTEGER, PUBLIC   :: &  
          iv_larve_1, &          !index for larve zone 1
          iv_larve_2, &          !index for larve zone 2
          iv_larve_3, &          !index for larve zone 3
          iv_larve_4, &          !index for larve zone 4
          iv_larve_5, &         !index for larve zone 5
          iv_larve_6, &
          i_ponte

#endif
 LOGICAL, PUBLIC     :: l_filtbenthsinusmes,l_SNeffect_settle,l_bioretro_extinct, &
                        l_phyzoodeteffect_settle,l_ChlNratio_var

 REAL(KIND=rsh), PUBLIC       ::     &
                   p_sali_thhold_bio,  &
                   p_N_remin,          &
                   p_P_remin,          &
                   p_Si_diss,          &
                   p_T_effect,         &
                   p_burial,           &
                   p_P_adsor,          &
                   p_P_desor,          &
                   p_P_adsormaxspim,   &
                   p_P_adsormaxsed,    &
                   p_phyto_ChlNratio,  &
                   rappaz,rapsiaz,     &
                   p_phyto_SiNratio,   &
                   p_phyto_NPratio,    &
                   p_phyto_CNratio,    &
                   p_phyto_ChlNratiomax, &
                   p_phyto_ChlN_ksmithextinct, &
                   p_nano_mumax,       &
                   p_nano_kNO3,        &
                   p_nano_kNH4,        &
                   p_nano_kPO4,        &
                   p_nano_thhold_mort, &
                   p_nano_mort,        &
                   p_nano_iksmith,     &
                   p_diat_mumax,       &
                   p_diat_kNO3,        &
                   p_diat_kNH4,        &
                   p_diat_kSi,         &
                   p_diat_kPO4,        &
                   p_diat_iksmith,     &
!#if defined key_biolo_opt2
                   p_diat_mort,        &
!#else
!                   p_diat_mortmax,     &
!#endif
                   p_diat_mort_sed,    &
                   p_diat_thhold_mort, &
                   p_dino_mumax,       &
                   p_dino_kNO3,        &
                   p_dino_kNH4,        &
                   p_dino_kPO4,        &
                   p_dino_mort,        &
                   p_dino_thhold_mort, &
                   p_dino_iksmith,     &
                   p_mesz_thrN,      &
                   p_mesz_kivlev,      &
                   p_mesz_thhold_mes_kivlev, &
                   p_mesz_thhold_mort, &
                   p_mesz_mumax,       &
                   p_mesz_assim,       &
                   p_mesz_excret,      &
                   p_mesz_mort1,       &
                   p_mesz_mort2,       &
                   p_zoo_CDWratio,     &
                   p_zoo_CNratio,      &
                   p_micz_mumax,       &
                   p_micz_kgraz,       &
                   p_micz_assim,       &
                   p_micz_excret,      &
                   p_micz_mort,        &
                   p_micz_thhold_mort, &
                   p_micz_thrnano,     &
                   p_phyto_photoratio, &
                   p_Nbent_remin,      &
                   p_Pbent_remin,      &
                   p_Sibent_dissol,    &
                   p_O2_kremin,        &
                   p_nitrifwat,        &
                   p_nitrifsed,        &
                   p_phyto_resp,       &
                   p_zoo_resp,         &
                   p_extincwat,        &
                   p_extincspim,       &
                   p_extincChl1,       &
                   p_extincChl2,       &
                   p_parradratio,      &
                   p_erodflux,         &
                   p_erodvitcrit,p_depovitcrit, &
                   p_erodcrittau,      &
                   p_detzoo_wsed,      &
                   p_detphy_wsed,      &
                   p_mesz_captdiat,    &
                   p_mesz_captdino,    &
                   p_mesz_captmicz,    &
                   p_micz_captdiat,    &
                   p_micz_captnano,    &
                   p_micz_captdet,     &
                   p_txfiltbenthmax

#if defined key_biolo_opt2
!! Insertion nveaux parametres en rapport avec ajout variables dissoutes VS juin 2010
 REAL(KIND=rsh), PUBLIC       ::     &
                   p_det_fragm,        &
                   p_diss_regmod,      & 
                   p_micz_diss
#else
 REAL(KIND=rsh), PUBLIC       ::   p_reminbenth
#endif

#if defined key_psnz
   REAL(KIND=rsh), PUBLIC       ::     &
                   p_psnz_mumax,       &
                   p_psnz_tempopt,     &
                   p_psnz_templethal,  &   
                   p_psnz_tempsigma,   &
                   p_psnz_beta,        &
                   p_psnz_kNO3,        &
                   p_psnz_kNH4,        &
                   p_psnz_kSi,         &
                   p_psnz_kPO4,        &
                   p_psnz_vmaxSi,      &
                   p_psnz_qminSi,      &
                   p_psnz_kqSi,        &
                   p_psnz_iksmith,     &
                  ! p_psnz_mortmax,     &
                   p_psnz_mort,        &
                   p_psnz_seuilSi,     &
                   p_psnz_prod_domoic
#endif
#if defined key_karenia
   REAL(KIND=rsh), PUBLIC       ::     &
                   p_karenia_mumax,       &
                   p_karenia_tempopt,     &
                   p_karenia_tempsigma,   &
                   p_karenia_templethal,  &
                   p_karenia_beta,        &
                   p_karenia_vmaxN,       &
                   p_karenia_kqN,         &
                   p_karenia_qminN,       &
                   p_karenia_vmaxP,       &
                   p_karenia_kqP,         &
                   p_karenia_qminP,       &
                   p_karenia_kNO3,        &
                   p_karenia_kNH4,        &
                   p_karenia_kPO4,        &
                   p_karenia_iksmith,     &
                   p_karenia_mort,        &
                   p_karenia_autotox_coef
#endif
#if defined key_phaeocystis
   REAL(KIND=rsh), PUBLIC       ::     &
                   p_phaeocystis_mumaxcolo,   &
                   p_phaeocystis_mumaxcell,   &
                   p_phaeocystis_tempopt,     &
                   p_phaeocystis_templethal,  &   
                   p_phaeocystis_tempsigma,   &
                   p_phaeocystis_beta,        &
                   p_phaeocystis_kNO3colo,    &
                   p_phaeocystis_kNO3cell,    &
                   p_phaeocystis_kNH4,        &
                   p_phaeocystis_kPO4colo,    &
                   p_phaeocystis_kPO4cell,    &
                   p_phaeocystis_iksmith,     &
                   p_phaeocystis_mort,        &
                   p_phaeocystis_lyse,        &
                   p_phaeocystis_coloinit,    &
                   p_phaeocystis_coloseuil,   &
                   p_phaeocystis_mucus_decay, &
                   p_mesz_captphaeocolo
#endif
#ifdef key_ulvas
   REAL(KIND=rsh), PUBLIC       ::     &
                   p_ulv_mumax,        &                      
                   p_ulv_iksmith,      &     
                   p_ulv_kNO3,         &        
                   p_ulv_kPO4,         &       
                   p_ulv_maxabsN,      &               
                   p_ulv_maxabsP,      &              
                   p_ulv_minNWratio,   &     
                   p_ulv_maxNWratio,   &      
                   p_ulv_minPWratio,   &      
                   p_ulv_maxPWratio,   &      
                   p_ulv_dryfreshratio, &      
                   p_ulv_susmort,      &      
                   p_ulv_depmort,      &       
                   p_ulv_extincwat,    &     
                   p_ulv_erodflux,     &    
                   p_ulv_erodcritv,    &        
                   p_ulv_settlcrittv 
#endif
#ifdef key_zostera
  REAL(KIND=rsh), PUBLIC       ::      &
                   p_zost_klai,        &
                   p_zost_leafabscoef, &
                   p_zost_Ik,          &
                   p_zost_maxprod0,    &
                   p_zost_T_prod,      &
                   p_zost_respf0,      &
                   p_zost_respr0,      &
                   p_zost_T_respf,     &
                   p_zost_T_respr,     &
                   p_zost_qphotos,     &
                   p_zost_LNquotamin,  &
                   p_zost_LNquotamax,  &
                   p_zost_RNquotamin,  &
                   p_zost_RNquotamax,  &
                   p_zost_KNH4L,       &
                   p_zost_KNH4R,       &
                   p_zost_KNO3L,       &
                   p_zost_delta1,      &
                   p_zost_delta2,      &
                   p_zost_LNnh4maxabs, &
                   p_zost_LNno3maxabs, &
                   p_zost_RNmaxabs,    &
                   p_zost_LPquotamin,  &
                   p_zost_LPquotamax,  &
                   p_zost_RPquotamin,  &
                   p_zost_RPquotamax,  &
                   p_zost_KPL,         &
                   p_zost_KPR,         &
                   p_zost_LPmaxabs,    &
                   p_zost_RPmaxabs,    &
                   p_zost_K,           &
                   p_zost_transfrate,  &
                   p_zost_reclamax,    &
                   p_zost_mort,        &
                   p_zost_T_mort,      &
                   p_zost_RECRmax,     &
                   p_zost_T_recr,      &
                   p_zost_KREC1,       &
                   p_zost_KREC2,       &
                   p_zost_SB1,         & 
                   p_zost_KGERM,       &
                   p_zost_SB0,         &
                   p_zost_ERSmax,      &
                   p_zost_seedprod,    &
                   p_zost_GERmax,      &          
                   p_zost_Smort
#endif
#ifdef key_oyster_benthos
           REAL(KIND=rsh), PUBLIC ::     &
                   p_huitre_DW,          &
                   p_huitre_thr_colmat,  &
                   p_huitre_temp1,       &
                   p_huitre_temp_opt,    &
                   p_huitre_thr_mes,     &
                   p_huitre_loi_mes1,    &
                   p_huitre_loi_mes2,    &
                   p_huitre_filt_std,    &
                   p_huitre_exp_allom,   &
                   p_huitre_loi_colmat
#endif
#ifdef key_oyster_SFG
           REAL(KIND=rsh), PUBLIC       ::     &
                    p_oys_absdet,              &
                    p_oys_absmaxmop,           &
                    p_oys_kreten,              &
                    p_oys_allfiltr,            &
                    p_oys_allres,              &
                    p_oys_yreten,              &
                    p_oys_CtoDWratio,          &
                    p_oys_stdfiltr,            & 
                    p_oys_paramfiltr,          &
                    p_oys_tempopt_filtr,       &
                    p_oys_sestfiltr_thr,       &
                    p_oys_yfilt,               &
                    p_oys_kfilt,               &
                    p_oys_colmparam,           &
                    p_oys_pseufeci_exp,        &
                    p_oys_pseufeco_exp,        &
                    p_oys_prodpseufeci_lev,    &
                    p_oys_prodpseufeco_lev,    &
                    p_oys_retmin,              &
                    p_oys_retmin_thr,          &
                    p_oys_prodpseufec_thr,     &
                    p_oys_subratio,            &
                    p_oys_colmat_thr
#endif
#ifdef key_oyster_DEB
           REAL(KIND=rsh), PUBLIC       ::     &
                   p_oysDEB_TA,                &
                   p_oysDEB_TAL,               &
                   p_oysDEB_TAH,               &
                   p_oysDEB_TL,                &
                   p_oysDEB_THing,             &
                   p_oysDEB_THresp,            &
                   p_oysDEB_Tseuilponte,       &                
                   p_oysDEB_Eg,                &
                   p_oysDEB_Em,                &
                   p_oysDEB_Kappa,             &    
                   p_oysDEB_Vp,                &
                   p_oysDEB_kR,                &
                   p_oysDEB_shape,             &
                   p_oysDEB_pxm0,              &
                   p_oysDEB_pammax,            &
                   p_oysDEB_ae,                &
                   p_oysDEB_pm0,               &
                   p_oysDEB_ERlim,             &
                   p_oysDEB_kchl,              &
                   p_oysDEB_muE 
#endif	  
#ifdef key_microtracers
   REAL(KIND=rsh), PUBLIC       ::      &
                   p_trace_debitinject, &
                   p_trace_depth1inject,&
                   p_trace_depth2inject,&
                   p_trace_depth3inject
#endif
#if defined key_N_tracer
   REAL(KIND=rsh),DIMENSION(:,:),ALLOCATABLE, PUBLIC       :: p_marque_tracerN
   INTEGER,PUBLIC                                          :: nb_source_tracerN,nb_source_river_tracerN,nb_source_marin_tracerN
   CHARACTER(LEN=lchain),DIMENSION(:),ALLOCATABLE, PUBLIC  :: name_source_tracerN
   REAL(KIND=rsh)                                          :: p_marqueNH4,p_marqueNO3,p_marquenanoN,p_marquedinoN,p_marquediatN,  &
                                                              p_marquemicrN,p_marquemesoN,p_marquedetN
   REAL(KIND=rsh),PUBLIC                                   :: tdeb_tracerN
   CHARACTER(LEN=lchain)                                   :: p_source_river1_tracerN,p_source_river2_tracerN,   &
                                                              p_source_river3_tracerN,p_source_river4_tracerN
#endif
#if defined key_P_tracer
   REAL(KIND=rsh),DIMENSION(:,:),ALLOCATABLE, PUBLIC       :: p_marque_tracerP
   INTEGER,PUBLIC                                          :: nb_source_tracerP,nb_source_river_tracerP,nb_source_marin_tracerP
   CHARACTER(LEN=lchain),DIMENSION(:),ALLOCATABLE, PUBLIC  :: name_source_tracerP
   REAL(KIND=rsh)                                          :: p_marquePO4,p_marquePads,p_marquedetP,p_marquenanoP,  &
                                                              p_marquedinoP,p_marquediatP,p_marquemicrP,p_marquemesoP
   REAL(KIND=rsh),PUBLIC                                   :: tdeb_tracerP
   CHARACTER(LEN=lchain)                                   :: p_source_river1_tracerP,p_source_river2_tracerP,  &
                                                              p_source_river3_tracerP,p_source_river4_tracerP
#endif

REAL(KIND=rsh), PUBLIC       ::     &
                   p_susp_satur_proie, &
                   p_susp_capdet,      &
                   p_susp_thrdet,      &
                   p_susp_thrphy,      &
                   p_susp_capphy,      &
                   p_susp_mort,        &
                   p_susp_pphysio,     &
                   p_susp_egest_det,   &
                   p_susp_egest_phy,   &
                   p_susp_thrmax_inhib,&
                   p_susp_inges,       &
                   p_susp_thrmin_inhib,&
                   p_meio_satur_proie, &
                   p_meio_capdet,      &
                   p_meio_thrdet,      &
                   p_meio_capdiat,     &
                   p_meio_thrdiat,     &
                   p_meio_mort,        &
                   p_meio_pphysio,     &
                   p_meio_egest_det,   &
                   p_meio_thrmax_inhib,&
                   p_meio_thrmin_inhib,&
                   p_meio_inges,       &
                   p_deposi_satur_proie,&
                   p_deposi_capdet,    &
                   p_deposi_thrdet,    &
                   p_deposi_capdiat,   &
                   p_deposi_capmeio,   &
                   p_deposi_thrmeio,   &
                   p_deposi_mort,      &
                   p_deposi_pphysio,   &
                   p_deposi_egest_meio,&
                   p_deposi_egest_det, &
                   p_deposi_egest_diat,&
                   p_deposi_thrmax_inhib,&
                   p_deposi_thrmin_inhib,&
                   p_deposi_inges,     &
                   p_carn_satur_proie, &
                   p_carn_capmeio,     &
                   p_carn_thrmeio,     &
                   p_carn_capdeposi,   &
                   p_carn_thrdeposi,   &
                   p_carn_satur_proie_susp,&
                   p_carn_capsusp,     &
                   p_carn_thrsusp,     &
                   p_carn_mort,        &
                   p_carn_pphysio,     &
                   p_carn_thrmax_inhib,&
                   p_carn_thrmin_inhib,&
                   p_carn_inges,       &
                   p_carn_egest
   ! number of diagnostic variables
   INTEGER, PUBLIC :: ndiag_1d,     &  ! 1 dimension (time)
                      ndiag_2d,     &  ! 2 dimensions (i,j)
                      ndiag_3d,     &  ! 3 d
                      ndiag_3d_wat, &  ! 3 d (k,i,j)
                      ndiag_3d_sed, &  ! 3 d (i,j,k)
                      ndiag_tot

   ! indexes of diagnostic variables
   INTEGER, PUBLIC :: id_diat_max,          &
                      id_diat_datemax,      &
                      id_diat_depthmax,     &
                      id_dino_max,          &
                      id_dino_datemax,      &
                      id_dino_depthmax,     &
                      id_nano_max,          &
                      id_nano_datemax,      &
                      id_nano_depthmax,     &
                      id_gradsali_max,      &
                      id_gradsali_depthmax, &
                      id_gradtemp_max,      &
                      id_gradtemp_depthmax, &
#ifdef key_biolo_opt2
                      id_spim_satused,      &
#endif
                      id_diat_limlight,     &
                      id_diat_limN,         &
                      id_diat_limSi,        &
                      id_diat_limP,         &
                      id_dino_limlight,     &
                      id_dino_limN,         &
                      id_dino_limP,         &
                      id_nano_limlight,     &
                      id_nano_limN,         &
                      id_nano_limP,         &
                      id_extinctioncoeff,   &
                      id_diat_columnprod,   &
                      id_dino_columnprod,   &
                      id_nano_columnprod,   &
                      id_totalchl,          &
                      id_columnprodtotal,   &
                      id_diatsettling,      &
                      id_detsettling,       &
                      id_spm_total
#if defined key_zoo_prod
   INTEGER, PUBLIC :: id_zoo_micr_columnprod,   &
                      id_zoo_meso_columnprod,   &
                      id_zoo_columnprodtotal
#endif	  		      
#if defined key_oyster_DEB
   INTEGER, PUBLIC :: id_oysDEB_FRpop,     &
                      id_oysDEB_PFpop,  &
                      id_oysDEB_Fpop,  &
                      id_oysDEB_DWtot,  &
                      id_oysDEB_kchlvble,  &
                      id_oysDEB_ER,  &
                      id_oysDEB_filtrate,  &
                      id_oysDEB_Wtot,  &
                      id_oysDEB_Istress,  &
                      id_oysDEB_Lgtot,  &
                      id_oysDEB_ChlC
 !  INTEGER, PUBLIC :: id_oysDEB_DWtot2,  &
 !                     id_oysDEB_Wtot2,  &
 !                     id_oysDEB_Lgtot2
 !  INTEGER, PUBLIC :: id_oysDEB_DWtot3,  &
 !                     id_oysDEB_Wtot3,  &
 !                     id_oysDEB_Lgtot3
   INTEGER, PUBLIC :: id_oysDEB_nbhuit
 !  INTEGER, PUBLIC :: id_oysDEB_nbhuit2
#endif
#if defined key_psnz
   INTEGER, PUBLIC :: id_psnz_limlight,     &
                      id_psnz_limN,         &
                      id_psnz_limSi,        &
                      id_psnz_limP,         &
                      id_psnz_proddomoic,   &
                      id_psnz_max,          &
                      id_psnz_datemax,      &
                      id_psnz_depthmax,     &
                      id_psnz_columnprod
#endif
#if defined key_karenia
   INTEGER, PUBLIC :: id_karenia_limlight,     &
                      id_karenia_limN,         &
                      id_karenia_limP,         &
                      id_karenia_max,          &
                      id_karenia_datemax,      &
                      id_karenia_depthmax,     &
                      id_karenia_columnprod
#endif
#if defined key_phaeocystis
   INTEGER, PUBLIC :: id_phaeocystis_limlight,     &
                      id_phaeocystis_limN,         &
                      id_phaeocystis_limP,         &
                      id_phaeocystis_max,          &
                      id_phaeocystis_datemax,      &
                      id_phaeocystis_depthmax,     &
                      id_phaeocystis_columnprod
#endif
#ifdef key_ulvas
   INTEGER, PUBLIC :: id_ulv_ratiosus,     &
                      id_ulv_susmort,      &
                      id_ulv_suslimlight,  &
                      id_ulv_suslimN,      &
                      id_ulv_suslimP,      &
                      id_ulv_suspumpN,     &
                      id_ulv_suspumpP,     &
                      id_ulv_settling,     &
                      id_ulv_ratiobenth,   &
                      id_ulv_benthmort,    &
                      id_ulv_benthlimlight,& 
                      id_ulv_benthlimN,    &
                      id_ulv_benthlimP,    &
                      id_ulv_benthpumpN,   &
                      id_ulv_benthpumpP,   &
                      id_ulv_resusbil,     &
                      id_ulv_resusN,       &
                      id_ulv_resusP
#endif
#ifdef key_zostera
   INTEGER, PUBLIC :: id_zost_LBDW,                &
                      id_zost_RBDW,                &
                      id_zost_Qcan,                &
                      id_zost_LAI,                 &
                      id_zost_limlum,              &
                      id_zost_limprodLN,           &
                      id_zost_limprodLP,           &
                      id_zost_limRN,               &
                      id_zost_limRP,               &
                      id_zost_effetchaleurzprod,   &
                      id_zost_effetchaleurzrespf,  &
                      id_zost_effetchaleurzrespr,  &
                      id_zost_limabsLnh4,          &
                      id_zost_limabsLno3,          &
                      id_zost_limabsLpo4,          &
                      id_zost_limabsRnh4,          &
                      id_zost_limabsRpo4,          &
                      id_zost_limselfshad,         &
                      id_zost_limRB,               &
                      id_zost_effetvent,           &
                      id_zost_Sgerm,               &
                      id_zost_ERS,                 &
                      id_zost_prod
#endif
#ifdef key_oyster_SFG
   INTEGER, PUBLIC :: id_oys_tcoq,          &
                      id_oys_tgam,          &
                      id_oys_gaincoq,       &
                      id_oys_gainsoma,      &
                      id_oys_gainrepr,      &
                      id_oys_orgafring,     &
                      id_oys_bilansoma,     &
                      id_oys_bilancoq,      &
                      id_oys_filt,          &
                      id_oys_resp,          &
                      id_oys_gameto,        &
                      id_oys_seuilponte,    &
                      id_oys_reposcoq,      &
                      id_oys_reposgam,      &
                      id_oys_ponte,         &
                      id_oys_absorg         
#endif
#ifdef key_oxygen
   INTEGER, PUBLIC :: id_oxy_sat                  
#endif
#ifdef key_microtracers
   INTEGER, PUBLIC   :: &
            id_tracer_maxdepth1, &   ! index for maximum value of micro-tracer from depth 1
            id_tracer_agedepth1, &   ! index for age of micro-tracer from depth 1
            id_tracer_meandepth1,&   ! index for mean value of micro-tracer from depth 1
            id_tracer_maxdepth2,&    ! index for maximum value of micro-tracer from depth 2
            id_tracer_agedepth2, &   ! index for age of micro-tracer from depth 2
            id_tracer_meandepth2,&   ! index for mean value of micro-tracer from depth 2
            id_tracer_maxdepth3,&    ! index for maximum value of micro-tracer from depth 3
            id_tracer_agedepth3, &   ! index for age of micro-tracer from depth 3
            id_tracer_meandepth3     ! index for mean value of micro-tracer from depth 3
#endif
#if defined key_N_tracer
   INTEGER, PUBLIC   :: ndiag_tracerN
! index for N-fraction from source  in signed variable
   INTEGER,DIMENSION(:,:),ALLOCATABLE, PUBLIC   :: id_tracer_signN 
#ifdef key_age_tracer
 ! index for age of N-fraction from source  in signed variable
   INTEGER,DIMENSION(:,:),ALLOCATABLE, PUBLIC   :: id_tracer_ageN 
#endif
#endif
#if defined key_P_tracer
   INTEGER, PUBLIC   :: ndiag_tracerP
! index for P-fraction from source  in signed variable
   INTEGER,DIMENSION(:,:),ALLOCATABLE, PUBLIC   :: id_tracer_signP 
#ifdef key_age_tracer
! index for age of P-fraction from source  in signed variable
   INTEGER,DIMENSION(:,:),ALLOCATABLE, PUBLIC   :: id_tracer_ageP  
#endif
#endif

  ! arrays of diagnostic variables
   REAL(KIND=rsh),ALLOCATABLE,DIMENSION(:)      ,PUBLIC :: diag_1d     !(index of var, time)
   REAL(KIND=rsh),ALLOCATABLE,DIMENSION(:,:,:)  ,PUBLIC :: diag_2d     ! (index of var, i, j)
   REAL(KIND=rsh),ALLOCATABLE,DIMENSION(:,:,:,:),PUBLIC :: diag_3d_wat !(index of var,k,i,j)
#ifdef key_sedim_anc
   REAL(KIND=rsh),ALLOCATABLE,DIMENSION(:,:,:,:),PUBLIC :: diag_3d_sed !(index of var,i,j,k)
#endif
   INTEGER,ALLOCATABLE,DIMENSION(:),PUBLIC :: idimv_r
   LOGICAL,ALLOCATABLE,DIMENSION(:),PUBLIC :: l_diag_sortie

   ! names and attributes of diagnostic variables
   CHARACTER(LEN=lchain),ALLOCATABLE,DIMENSION(:),PUBLIC :: name_vardiag,         &
                                                            long_name_vardiag,    &
                                                            standard_name_vardiag

   ! units of diagnostic variables
   CHARACTER(LEN=lchain),ALLOCATABLE,DIMENSION(:),PUBLIC :: unit_vardiag

   ! rank of diagnostic variables
   INTEGER,ALLOCATABLE,DIMENSION(:),PUBLIC :: irk_diag ! (reading order)

   ! values of attributes of diagnostic variables
   REAL(KIND=rsh),ALLOCATABLE,DIMENSION(:),PUBLIC :: valid_min_vardiag, valid_max_vardiag

   ! integration sur 1 jour (minuit_minuit) de l effet lumiere sur la croissance du phytoplancton
   REAL(KIND=rsh),ALLOCATABLE,DIMENSION(:,:,:)  ,PUBLIC :: effetlumiere_day_diat,effetlumiere_day_dino,effetlumiere_day_nano
#ifdef key_phaeocystis
   REAL(KIND=rsh),ALLOCATABLE,DIMENSION(:,:,:)  ,PUBLIC :: effetlumiere_day_phaeocystis
#endif
#ifdef key_karenia
   REAL(KIND=rsh),ALLOCATABLE,DIMENSION(:,:,:)  ,PUBLIC :: effetlumiere_day_karenia
#endif
#ifdef key_psnz
   REAL(KIND=rsh),ALLOCATABLE,DIMENSION(:,:,:)  ,PUBLIC :: effetlumiere_day_psnz
#endif

   !! * Private variables
   INTEGER                  :: idmin=99999,idmax=0, &  ! to get min and max indexes of diagnostic var.
                               ivmin=99999,ivmax=0     ! to get min and max indexes of substance var.


 CONTAINS

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

  SUBROUTINE biolo_param(rw)

   !&E---------------------------------------------------------------------
   !&E                 ***  ROUTINE biolo_param  ***
   !&E
   !&E ** Purpose : Read and write namelist relative to the module of biology
   !&E
   !&E ** Description :
   !&E
   !&E ** Called by : init
   !&E
   !&E ** External calls :
   !&E
   !&E ** Reference :
   !&E
   !&E ** History :
   !&E       !  2009-10  (V. Garnier)  Original code
   !&E
   !&E---------------------------------------------------------------------
   !! * Modules used
   USE comvars2d, ONLY : iscreenlog,l_testcase,ierrorlog
   USE parameters, ONLY : num_testcase
   USE_MPI toolmpi, ONLY : MASTER

#if defined key_N_tracer 
   USE parameters, ONLY : nb_sourceN
#endif
#if defined key_P_tracer 
   USE parameters, ONLY : nb_sourceP
#endif

   !! * Arguments
   CHARACTER(LEN=1), INTENT( in ) :: rw

   !! * Local declarations
   CHARACTER(LEN=lchain) :: filepc
#ifdef key_N_tracer
   CHARACTER(LEN=19) :: date_start_tracerN
#elif key_P_tracer
   CHARACTER(LEN=19) :: date_start_tracerP
#endif
   INTEGER               :: is,IERR_MPI
   REAL(KIND=rlg)        :: tool_datosec

   NAMELIST/namoptions/ l_filtbenthsinusmes,l_SNeffect_settle,l_phyzoodeteffect_settle,l_ChlNratio_var,  &
                        p_sali_thhold_bio,l_bioretro_extinct
#ifdef key_biolo_opt2
   NAMELIST/namorgmat/ p_N_remin,p_P_remin,p_Si_diss,p_T_effect,p_det_fragm,&
                       p_diss_regmod,p_micz_diss
#else
   NAMELIST/namorgmat/ p_N_remin,p_P_remin,p_Si_diss,p_T_effect,p_reminbenth
#endif
   NAMELIST/nampsorb/ p_P_adsor,p_P_desor,p_P_adsormaxspim,p_P_adsormaxsed
   NAMELIST/namgenphyto/ p_phyto_ChlNratio,p_phyto_SiNratio,p_phyto_NPratio,p_phyto_CNratio, &
                         p_phyto_ChlNratiomax,p_phyto_ChlN_ksmithextinct
   NAMELIST/namnanophyto/ p_nano_mumax,p_nano_kNO3,p_nano_kNH4,p_nano_kPO4,p_nano_mort, &
                          p_nano_iksmith,p_nano_thhold_mort
!#if defined key_biolo_opt2
   NAMELIST/namdiatom/ p_diat_mumax,p_diat_kNO3,p_diat_kNH4,p_diat_kSi,p_diat_kPO4,     &
                       p_diat_iksmith,p_diat_mort,p_diat_thhold_mort
!#else
!   NAMELIST/namdiatom/ p_diat_mumax,p_diat_kNO3,p_diat_kNH4,p_diat_kSi,p_diat_kPO4,     &
!                       p_diat_iksmith,p_diat_mortmax,p_diat_thhold_mort
!#endif
   NAMELIST/namdino/ p_dino_mumax,p_dino_kNO3,p_dino_kNH4,p_dino_kPO4,p_dino_mort,      &
                     p_dino_iksmith,p_dino_thhold_mort
#if defined key_psnz
   NAMELIST/nampsnz/ p_psnz_mumax,p_psnz_tempopt,p_psnz_tempsigma,p_psnz_kNO3,p_psnz_kNH4,p_psnz_kSi,p_psnz_kPO4,     &
                     p_psnz_vmaxSi,p_psnz_qminSi,p_psnz_kqSi,p_psnz_iksmith,p_psnz_mort,  &
                     p_psnz_seuilSi,p_psnz_prod_domoic,p_psnz_templethal,p_psnz_beta
                     !!p_psnz_vmaxSi,p_psnz_qminSi,p_psnz_kqSi,p_psnz_iksmith,p_psnz_mortmax,  &
#endif	     
#if defined key_karenia
   NAMELIST/namkarenia/ p_karenia_mumax,p_karenia_tempopt,p_karenia_tempsigma,p_karenia_vmaxN,p_karenia_kqN,    &
                        p_karenia_qminN,p_karenia_kNO3,p_karenia_kNH4,p_karenia_vmaxP,p_karenia_kqP,             &
                        p_karenia_qminP,p_karenia_kPO4,p_karenia_iksmith,p_karenia_mort,p_karenia_autotox_coef,  &
                        p_karenia_templethal,p_karenia_beta
#endif	
#if defined key_phaeocystis
   NAMELIST/namphaeocystis/ p_phaeocystis_mumaxcolo,p_phaeocystis_mumaxcell,p_phaeocystis_tempopt,    &
                            p_phaeocystis_tempsigma,p_phaeocystis_kNO3colo,p_phaeocystis_kNO3cell,    &
                            p_phaeocystis_kNH4,p_phaeocystis_kPO4colo,p_phaeocystis_kPO4cell,  &
                            p_phaeocystis_iksmith,p_phaeocystis_mort,p_phaeocystis_lyse,p_phaeocystis_coloinit,  &
                            p_phaeocystis_coloseuil,p_phaeocystis_mucus_decay,p_mesz_captphaeocolo,   &
                            p_phaeocystis_templethal, p_phaeocystis_beta
#endif     
   NAMELIST/nammesozoo/ p_mesz_thrN,p_mesz_kivlev,p_mesz_mumax,p_mesz_assim,      &
                        p_mesz_excret,p_mesz_mort1,p_mesz_mort2,p_zoo_CDWratio,    &
                        p_zoo_CNratio,p_mesz_thhold_mes_kivlev,p_mesz_thhold_mort
   NAMELIST/nammicrozoo/ p_micz_mumax,p_micz_kgraz,p_micz_assim,p_micz_excret,p_micz_mort,   &
                         p_micz_thrnano,p_micz_thhold_mort
   NAMELIST/namoxygen/ p_phyto_photoratio,p_Nbent_remin,p_Pbent_remin,p_Sibent_dissol,p_O2_kremin,&
                       p_nitrifwat,p_nitrifsed,p_phyto_resp,p_zoo_resp
   NAMELIST/namoptics/ p_extincwat,p_extincspim,p_extincChl1,p_extincChl2,p_parradratio
#if defined key_benthos
   NAMELIST/namsedbenthos/ p_erodflux,p_erodvitcrit,p_depovitcrit,p_detzoo_wsed,p_detphy_wsed,p_erodcrittau,  &
                           p_burial
#elif defined key_sedim_MUSTANG
   NAMELIST/namsediment/ p_diat_mort_sed,p_Nbent_remin,p_Pbent_remin,p_Sibent_dissol,p_nitrifsed, &
                         p_detzoo_wsed,p_detphy_wsed
#endif
   NAMELIST/namgrazing/ p_mesz_captdiat,p_mesz_captdino,p_mesz_captmicz,p_micz_captdiat,    &
                        p_micz_captnano,p_micz_captdet,p_txfiltbenthmax
#ifdef key_ulvas
   NAMELIST/namulva/ p_ulv_mumax,p_ulv_iksmith,p_ulv_kNO3,p_ulv_kPO4,p_ulv_maxabsN,   &
                     p_ulv_maxabsP,p_ulv_minNWratio,p_ulv_maxNWratio,p_ulv_minPWratio,  &
                     p_ulv_maxPWratio,p_ulv_dryfreshratio,p_ulv_susmort,p_ulv_depmort,   &
                     p_ulv_extincwat,p_ulv_erodflux,p_ulv_erodcritv,p_ulv_settlcrittv 
#endif
#ifdef key_zostera
  NAMELIST/namzostera/ p_zost_klai,p_zost_leafabscoef,p_zost_Ik,p_zost_maxprod0,p_zost_T_prod, &
                        p_zost_respf0,p_zost_respr0,p_zost_T_respf,p_zost_T_respr, p_zost_qphotos, &
                        p_zost_LNquotamin,p_zost_LNquotamax,p_zost_RNquotamin,p_zost_RNquotamax, &
                        p_zost_KNH4L,p_zost_KNH4R,p_zost_KNO3L,p_zost_delta1,p_zost_delta2, &
                        p_zost_LNnh4maxabs, p_zost_LNno3maxabs, &
                        p_zost_RNmaxabs,p_zost_LPquotamin,p_zost_LPquotamax,p_zost_RPquotamin, &
                        p_zost_RPquotamax,p_zost_KPL,p_zost_KPR,p_zost_LPmaxabs,p_zost_RPmaxabs, &
                        p_zost_K,p_zost_transfrate,p_zost_reclamax,p_zost_mort,p_zost_T_mort,p_zost_RECRmax, &
                        p_zost_T_recr,p_zost_KREC1,p_zost_KREC2,p_zost_SB1,p_zost_KGERM,p_zost_SB0, &
                        p_zost_ERSmax,p_zost_seedprod,p_zost_GERmax,p_zost_Smort
#endif
#ifdef key_oyster_benthos
   NAMELIST/namoysterfiltbent/ p_huitre_DW,p_huitre_thr_colmat,p_huitre_temp1,p_huitre_temp_opt,   &
                               p_huitre_thr_mes,p_huitre_loi_mes1,p_huitre_loi_mes2,p_huitre_filt_std, &
                               p_huitre_exp_allom,p_huitre_loi_colmat
#endif
#ifdef key_oyster_SFG
   NAMELIST/namoysterSFG/ p_oys_absdet,p_oys_absmaxmop,p_oys_kreten,p_oys_allfiltr,p_oys_allres,p_oys_yreten,p_oys_CtoDWratio, &
                       p_oys_stdfiltr,p_oys_paramfiltr,p_oys_tempopt_filtr,p_oys_sestfiltr_thr,p_oys_yfilt,     &
                       p_oys_kfilt,p_oys_colmparam,p_oys_pseufeci_exp,p_oys_pseufeco_exp,p_oys_prodpseufeci_lev,   &
                       p_oys_prodpseufeco_lev,p_oys_retmin,p_oys_retmin_thr,p_oys_prodpseufec_thr,        &
                       p_oys_subratio,p_oys_colmat_thr
#endif
#ifdef key_oyster_DEB
   NAMELIST/namoysterdeb/ p_oysDEB_TA,p_oysDEB_TAL,p_oysDEB_TAH,p_oysDEB_TL, &
                          p_oysDEB_THing,p_oysDEB_THresp,p_oysDEB_Tseuilponte, &
                          p_oysDEB_Eg,p_oysDEB_Em,p_oysDEB_Kappa,p_oysDEB_Vp, &
                          p_oysDEB_kR,p_oysDEB_shape,p_oysDEB_pxm0,p_oysDEB_pammax, &
                          p_oysDEB_ae,p_oysDEB_pm0,p_oysDEB_ERlim,p_oysDEB_kchl, &
                          p_oysDEB_muE
#endif
#if defined key_microtracers
   NAMELIST/nammicrotrace/ p_trace_debitinject,p_trace_depth1inject,p_trace_depth2inject,p_trace_depth3inject
#endif
#if defined key_N_tracer
   NAMELIST/namtracerN/ nb_source_river_tracerN,nb_source_marin_tracerN,date_start_tracerN,   &
                        p_source_river1_tracerN,p_source_river2_tracerN,p_source_river3_tracerN,  &
                        p_source_river4_tracerN,p_marqueNH4,p_marqueNO3,p_marquenanoN,p_marquedinoN,p_marquediatN,  &
                        p_marquemicrN,p_marquemesoN,p_marquedetN
#endif
#if defined key_P_tracer
   NAMELIST/namtracerP/ nb_source_river_tracerP,nb_source_marin_tracerP,date_start_tracerP,   &
                        p_source_river1_tracerP,p_source_river2_tracerP,p_source_river3_tracerP,  &
                        p_source_river4_tracerP,p_marquePO4,p_marquePads,p_marquedetP,p_marquenanoP,p_marquedinoP,  &
                        p_marquediatP,p_marquemicrP,p_marquemesoP
#endif
   !!----------------------------------------------------------------------
#ifdef key_benthos_gener
   NAMELIST/nammeio/    p_meio_satur_proie,p_meio_capdet,p_meio_thrdet,p_meio_capdiat,p_meio_thrdiat,  &
                        p_meio_mort,p_meio_pphysio,p_meio_egest_det,p_meio_thrmax_inhib,  &
                        p_meio_thrmin_inhib,p_meio_inges
   NAMELIST/namdeposi/  p_deposi_satur_proie,p_deposi_capdet,p_deposi_thrdet,p_deposi_capdiat,  &
                        p_deposi_capmeio,p_deposi_thrmeio,p_deposi_mort,p_deposi_pphysio,  &
                        p_deposi_egest_meio,p_deposi_egest_det,p_deposi_egest_diat,  &
                        p_deposi_thrmax_inhib,p_deposi_thrmin_inhib,p_deposi_inges 
   NAMELIST/namsuspens/ p_susp_satur_proie,p_susp_capdet,p_susp_thrdet,p_susp_capphy,p_susp_thrphy,      &
                        p_susp_mort,p_susp_pphysio,p_susp_egest_det,p_susp_egest_phy,p_susp_thrmax_inhib,   &
                        p_susp_thrmin_inhib,p_susp_inges
   NAMELIST/namcarn/    p_carn_satur_proie,p_carn_capmeio,p_carn_thrmeio,p_carn_capdeposi,  &
                        p_carn_thrdeposi,p_carn_satur_proie_susp,p_carn_capsusp,p_carn_thrsusp, &
                        p_carn_mort,p_carn_pphysio,p_carn_egest,p_carn_thrmax_inhib,p_carn_thrmin_inhib, &
                        p_carn_inges
#endif

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

IF(rw == 'r')THEN
! Lecture des namelists
!==========================
   IF(l_testcase .AND. (num_testcase==34 .or. num_testcase==35)) THEN
#ifdef key_biolo_opt2
     filepc='../inputs/parabiolo_debase_opt2.txt'
#else
#ifdef key_PREVI_alain
#if defined key_karenia && defined key_psnz && defined key_phaeocystis
     filepc='../inputs/parabiolo_previmer_modules.txt'
#else
     filepc='../inputs/parabiolo_previmer_benthos.txt'
#endif
#else
     filepc='../inputs/parabiolo_debase_nv.txt'
#endif
#endif
   ELSE
     filepc='./parabiolo.txt'
     IF_AGRIF (.NOT. Agrif_Root()) filepc='./parabiolo'//TRIM(Agrif_Cfixed())//'.txt'
   ENDIF

   OPEN(50,file=filepc,status='old',form='formatted', access='sequential')
   READ(50,namoptions)
   READ(50,namorgmat)
   READ(50,nampsorb)
   READ(50,namgenphyto)
   ! facteurs de conversion
   rapsiaz=p_phyto_SiNratio
   rappaz=1.0_rsh/p_phyto_NPratio
   
   READ(50,namnanophyto)
   READ(50,namdiatom)
   READ(50,namdino)
#if defined key_psnz
   READ(50,nampsnz)
#endif
#if defined key_karenia
   READ(50,namkarenia)
#endif
#if defined key_phaeocystis
   READ(50,namphaeocystis)
#endif
   READ(50,nammesozoo)
   READ(50,nammicrozoo)
   READ(50,namoxygen)
   READ(50,namoptics)
#if defined key_benthos
   READ(50,namsedbenthos)
#elif defined key_sedim_MUSTANG
   READ(50,namsediment)
#endif
   READ(50,namgrazing)
#ifdef key_ulvas  
   READ(50,namulva)
#endif
#ifdef key_zostera
   READ(50,namzostera)
#endif 
#ifdef key_oyster_benthos
   READ(50,namoysterfiltbent)
#endif
#ifdef key_oyster_SFG
   READ(50,namoysterSFG)
#endif
#ifdef key_oyster_DEB
   READ(50,namoysterDEB)
#endif
#if defined key_microtracers
   READ(50,nammicrotrace)
#endif
#if defined key_N_tracer
   READ(50,namtracerN)
   tdeb_tracerN=tool_datosec(date_start_tracerN)
   nb_source_tracerN=nb_source_river_tracerN+nb_source_marin_tracerN
   ALLOCATE(name_source_tracerN(nb_source_tracerN))
   DO is=1,nb_source_river_tracerN
      SELECT CASE(is)
            CASE (1)
             name_source_tracerN(is)=p_source_river1_tracerN
            CASE (2)
             name_source_tracerN(is)=p_source_river2_tracerN
            CASE (3)
             name_source_tracerN(is)=p_source_river3_tracerN
            CASE (4)
             name_source_tracerN(is)=p_source_river4_tracerN
            CASE DEFAULT
               WRITE(ierrorlog,*) ' '
               WRITE(ierrorlog,*) 'ERROR: NOT MORE THAN 4 RIVER SOURCES for TRACER N'
               WRITE(ierrorlog,*) '       CHECK in parabiolo.txt : nb_source_river_tracerN must be < 5' 
               WRITE(ierrorlog,*) '  Simulation stopped'
               CALL_MPI MPI_FINALIZE(IERR_MPI)
               STOP
      END SELECT
   ENDDO
   DO is=nb_source_river_tracerN+1,nb_source_tracerN
     name_source_tracerN(is)='MARIN'
   ENDDO
   IF(nb_source_tracerN /= nb_sourceN)THEN
      WRITE(ierrorlog,*)'ERROR : total number source of tracer in parabiolo.txt is different from nb_source in parameters'
      WRITE(ierrorlog,*)'The simulation is stopped'
      CALL_MPI MPI_FINALIZE(IERR_MPI)
      STOP
   ENDIF
#endif
#if defined key_P_tracer
   READ(50,namtracerP)
   tdeb_tracerP=tool_datosec(date_start_tracerP)
   nb_source_tracerP=nb_source_river_tracerP+nb_source_marin_tracerP
   ALLOCATE(name_source_tracerP(nb_source_tracerP))
   DO is=1,nb_source_river_tracerP
      SELECT CASE(is)
            CASE (1)
             name_source_tracerP(is)=p_source_river1_tracerP
            CASE (2)
             name_source_tracerP(is)=p_source_river2_tracerP
            CASE (3)
             name_source_tracerP(is)=p_source_river3_tracerP
            CASE (4)
             name_source_tracerP(is)=p_source_river4_tracerP
            CASE DEFAULT
               WRITE(ierrorlog,*) ' '
               WRITE(ierrorlog,*) 'ERROR: NOT MORE THAN 4 RIVER SOURCES for TRACER N'
               WRITE(ierrorlog,*) '       CHECK in parabiolo.txt : nb_source_river_tracerN must be < 5' 
               WRITE(ierrorlog,*) '  Simulation stopped'
               CALL_MPI MPI_FINALIZE(IERR_MPI)
               STOP
      END SELECT
   ENDDO
   DO is=nb_source_river_tracerP+1,nb_source_tracerP
     name_source_tracerP(is)='MARIN'
   ENDDO
   IF(nb_source_tracerP /= nb_sourceP)THEN
      WRITE(ierrorlog,*)'ERROR : total number source of tracer in parabiolo.txt is different from nb_source in parameters'
      WRITE(ierrorlog,*)'The simulation is stopped'
      CALL_MPI MPI_FINALIZE(IERR_MPI)
      STOP
   ENDIF
#endif
#ifdef key_benthos_gener
   READ(50,nammeio)
   READ(50,namdeposi)
   READ(50,namsuspens)
   READ(50,namcarn)
#endif
   CLOSE(50)                                  ! end reading of namelists

ELSE
! ecriture des namelists
!==========================
#ifdef key_biolo
   IF_MPI (MASTER) THEN
     WRITE(iscreenlog,namoptions)
     WRITE(iscreenlog,namorgmat)
     WRITE(iscreenlog,nampsorb)
     WRITE(iscreenlog,namgenphyto)
     WRITE(iscreenlog,namnanophyto)
     WRITE(iscreenlog,namdiatom)
     WRITE(iscreenlog,namdino)
     WRITE(iscreenlog,nammesozoo)
     WRITE(iscreenlog,nammicrozoo)
     WRITE(iscreenlog,namoxygen)
     WRITE(iscreenlog,namoptics)
#if defined key_benthos
     WRITE(iscreenlog,namsedbenthos)
#elif    defined key_sedim_MUSTANG
     WRITE(iscreenlog,namsediment)
#endif
     WRITE(iscreenlog,namgrazing)
#if defined key_microtracers
     WRITE(iscreenlog,nammicrotrace)
#endif
#ifdef key_ulvas
     WRITE(iscreenlog,namulva)
#endif
#ifdef key_oyster_benthos
     WRITE(iscreenlog,namoysterfiltbent)
#endif
#ifdef key_oyster_SFG
     WRITE(iscreenlog,namoysterSFG)
#endif
#ifdef key_oyster_DEB
     WRITE(iscreenlog,namoysterDEB)
#endif
#if defined key_psnz
     WRITE(iscreenlog,nampsnz)
#endif	     
#if defined key_karenia
     WRITE(iscreenlog,namkarenia)
#endif	
#if defined key_phaeocystis
     WRITE(iscreenlog,namphaeocystis)
#endif     
#if defined key_N_tracer
     WRITE(iscreenlog,namtracerN)
#endif
#if defined key_P_tracer
     WRITE(iscreenlog,namtracerP)
#endif
   ENDIF_MPI
#endif

ENDIF
  END SUBROUTINE biolo_param
   !!======================================================================

  SUBROUTINE biolo_init_iv(iv,standname)

   !&E---------------------------------------------------------------------
   !&E                 ***  ROUTINE biolo_init_iv  ***
   !&E
   !&E ** Purpose : Initialize indexes of state variables (substances only)
   !&E
   !&E ** Description :
   !&E
   !&E ** Called by : sub_read_var
   !&E
   !&E ** External calls :
   !&E
   !&E ** Reference :
   !&E
   !&E ** History :
   !&E       !  2009-10  (V. Garnier)  Original code
   !&E
   !&E---------------------------------------------------------------------
   !! * Modules used
   USE parameters, ONLY   : nb_var
   USE comvars2d, ONLY    : iscreenlog,ierrorlog
   USE comsubstance, ONLY : irk_mod
   USE toolmath, ONLY     : sumindex
#if defined key_N_tracer || defined key_P_tracer
   USE comsubstance, ONLY : name_var
#endif
   USE_MPI toolmpi, ONLY : MASTER

   !! * Arguments
   INTEGER,          INTENT( in ) :: iv
   CHARACTER(LEN=*), INTENT( in ) :: standname

   !! * Local declarations
   INTEGER               :: sumverif,IERR_MPI
#if defined key_N_tracer || defined key_P_tracer
   INTEGER               :: is,ivtra
#endif

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

   SELECT CASE( TRIM(ADJUSTL(ADJUSTR(standname))) )

     CASE('mole_concentration_of_nitrate_in_sea_water')
       iv_nutr_NO3 = irk_mod(iv)
     CASE('mole_concentration_of_silicate_in_sea_water')
       iv_nutr_SiOH = irk_mod(iv)
     CASE('mole_concentration_of_phosphate_in_sea_water')
       iv_nutr_PO4 = irk_mod(iv)
     CASE('mole_concentration_of_sorbed_phosphate_in_sea_water')
       iv_nutr_Pads = irk_mod(iv)
     CASE('mole_concentration_of_diatoms_expressed_as_nitrogen_in_sea_water')
       iv_phyto_diat_N = irk_mod(iv)
     CASE('mole_concentration_of_dinoflagellates_expressed_as_nitrogen_in_sea_water')
       iv_phyto_dino_N = irk_mod(iv)
     CASE('mole_concentration_of_organic_detritus_expressed_as_nitrogen_in_sea_water')
       iv_detr_N = irk_mod(iv)
     CASE('mole_concentration_of_organic_detritus_expressed_as_silicon_in_sea_water')
       iv_detr_Si = irk_mod(iv)
     CASE('mole_concentration_of_organic_detritus_expressed_as_phosphorus_in_sea_water')
       iv_detr_P = irk_mod(iv)
     CASE('mole_concentration_of_ammonium_in_sea_water')
       iv_nutr_NH4 = irk_mod(iv)
#if defined key_biolo_opt2
     CASE('mole_concentration_of_mesozooplankton_expressed_as_carbon_in_sea_water')
#else
     CASE('mole_concentration_of_mesozooplankton_expressed_as_nitrogen_in_sea_water')
#endif
       iv_zoo_meso_N = irk_mod(iv)
     CASE('mole_concentration_of_nanoplankton_expressed_as_nitrogen_in_sea_water')
       iv_phyto_nano_N = irk_mod(iv)
#if defined key_biolo_opt2
     CASE('mole_concentration_of_microzooplankton_expressed_as_carbon_in_sea_water')
#else
     CASE('mole_concentration_of_microzooplankton_expressed_as_nitrogen_in_sea_water')
#endif
       iv_zoo_micr_N = irk_mod(iv)
     CASE('mass_concentration_of_suspended_matter_in_sea_water')
       iv_spim = irk_mod(iv)
#if defined key_biolo_opt2
     CASE('cumulative_diatom_production_expressed_as_nitrogen_in_sea_water')
#else
     CASE('cumulative_diatom_production_expressed_as_carbon_in_sea_water')
#endif
       iv_phyto_diat_pp = irk_mod(iv)
#if defined key_biolo_opt2
     CASE('cumulative_dinoflagellate_production_expressed_as_nitrogen_in_sea_water')
#else
     CASE('cumulative_dinoflagellate_production_expressed_as_carbon_in_sea_water')
#endif
       iv_phyto_dino_pp = irk_mod(iv)
#if defined key_biolo_opt2
     CASE('cumulative_nanoflagellate_production_expressed_as_nitrogen_in_sea_water')
#else
     CASE('cumulative_nanoflagellate_production_expressed_as_carbon_in_sea_water')
#endif
       iv_phyto_nano_pp = irk_mod(iv)
#if defined key_psnz
     CASE('mole_concentration_of_pseudonitzschia_expressed_as_nitrogen_in_sea_water')
       iv_phyto_psnz_N = irk_mod(iv)
     CASE('mole_concentration_of_pseudonitzschia_expressed_as_silicon_in_sea_water')
       iv_phyto_psnz_Si = irk_mod(iv)
     CASE('mass_concentration_of_domoic_acid_in_sea_water')
       iv_phyto_psnz_ad = irk_mod(iv)
     CASE('cumulative_pseudonitzschia_production_expressed_as_carbon_in_sea_water')
       iv_phyto_psnz_pp = irk_mod(iv)
#endif
#if defined key_karenia
     CASE('mole_concentration_of_karenia_expressed_as_carbon_in_sea_water')
       iv_phyto_karenia_C = irk_mod(iv)
     CASE('mole_concentration_of_karenia_expressed_as_nitrogen_in_sea_water')
       iv_phyto_karenia_N = irk_mod(iv)
     CASE('mole_concentration_of_karenia_expressed_as_phosphorus_in_sea_water')
       iv_phyto_karenia_P = irk_mod(iv)
     CASE('cumulative_karenia_production_expressed_as_carbon_in_sea_water')
       iv_phyto_karenia_pp = irk_mod(iv)
#endif
#if defined key_phaeocystis
     CASE('mole_concentration_of_colonial_phaeocystis_expressed_as_nitrogen_in_sea_water')
       iv_phyto_phaeocystis_colo_N = irk_mod(iv)
     CASE('mole_concentration_of_phaeocystis_cells_expressed_as_nitrogen_in_sea_water')
       iv_phyto_phaeocystis_cell_N = irk_mod(iv)
     CASE('concentration_of_phaeocystis_mucus_expressed_as_mass_in_sea_water')
       iv_phyto_phaeocystis_mucus = irk_mod(iv)
     CASE('cumulative_phaeocystis_production_expressed_as_carbon_in_sea_water')
       iv_phyto_phaeocystis_pp = irk_mod(iv)
#endif
#ifdef key_zoo_prod
     CASE('cumulative_microzooplankton_production_expressed_as_carbon_in_sea_water')
       iv_zoo_micr_ps = irk_mod(iv)
     CASE('cumulative_mesozooplankton_production_expressed_as_carbon_in_sea_water')
       iv_zoo_meso_ps = irk_mod(iv)
#endif
#ifdef key_ulvas
     CASE('suspended_ulvas_nitrogen')
       iv_ulv_sus_N = irk_mod(iv)
     CASE('benthic_ulvas_nitrogen')
       iv_ulv_benth_N = irk_mod(iv)
     CASE('suspended_ulvas_dry_weight')
       iv_ulv_susdrywght = irk_mod(iv)
     CASE('benthic_ulvas_dry_weight')
       iv_ulv_benthdrywght = irk_mod(iv)
     CASE('suspended_ulvas_phosphorus')
       iv_ulv_sus_P = irk_mod(iv)
     CASE('benthic_ulvas_phosphorus')
       iv_ulv_benth_P = irk_mod(iv) 
     CASE('cumulative_suspended_ulvas_production')
       iv_ulv_suspp = irk_mod(iv)
     CASE('cumulative_benthic_ulvas_production')
       iv_ulv_benthpp = irk_mod(iv) 
#endif
#ifdef key_zostera
    CASE('zostera_leaf_biomass_per_m2')
       iv_zost_LB = irk_mod(iv)
     CASE('zostera_root_biomass_per_m2')
       iv_zost_RB = irk_mod(iv)
     CASE('zostera_shoot_density_per_m2')
       iv_zost_D = irk_mod(iv)
     CASE('zostera_leaf_nitrogen_pool_per_m2')
       iv_zost_LN = irk_mod(iv)
     CASE('zostera_root_nitrogen_pool_per_m2')
       iv_zost_RN = irk_mod(iv)
     CASE('zostera_leaf_phosphorus_pool_per_m2')
       iv_zost_LP = irk_mod(iv)
     CASE('zostera_root_phosphorus_pool_per_m2')
       iv_zost_RP = irk_mod(iv) 
     CASE('mole_concentration_of_zostera_floating_detritus_expressed_as_nitrogen')
       iv_detr_zost_N = irk_mod(iv)
     CASE('mole_concentration_of_zostera_floating_detritus_expressed_as_phosphorus')
       iv_detr_zost_P = irk_mod(iv)         
     CASE('mole_concentration_of_zostera_detritus_in_benthos_expressed_as_nitrogen')
       iv_zost_benth_N = irk_mod(iv)
     CASE('mole_concentration_of_zostera_detritus_in_benthos_expressed_as_phosphorus')
       iv_zost_benth_P = irk_mod(iv)         
     CASE('mole_concentration_of_zostera_seeds_in_water_column')
       iv_zost_seed = irk_mod(iv)
     CASE('mole_concentration_of_zostera_seeds_in_benthos')
       iv_zost_benth_seed = irk_mod(iv)         
     CASE('mole_concentration_of_ammonium_in_benthos')
       iv_benth_NH4 = irk_mod(iv)         
     CASE('mole_concentration_of_dissolved_phosphorus_in_benthos')
       iv_benth_PO4 = irk_mod(iv)         
!     CASE('cumulative_zostera_production')
!       iv_zost_pp = irk_mod(iv)         
!     CASE('cumulative_zostera_leaf_N_uptake')
!       iv_zost_LNuptake=irk_mod(iv)
!     CASE('cumulative_zostera_leaf_P_uptake')
!       iv_zost_LPuptake=irk_mod(iv)
!     CASE('cumulative_zostera_root_N_uptake')
!       iv_zost_RNuptake=irk_mod(iv)
!     CASE('cumulative_zostera_root_P_uptake')
!       iv_zost_RPuptake=irk_mod(iv)
#endif 
#ifdef key_oyster_SFG
     CASE('oyster_dry_soma_weight')
       iv_oys_so = irk_mod(iv)
     CASE('oyster_dry_resgon_weight')
       iv_oys_go = irk_mod(iv)
     CASE('oyster_coq_weight')
       iv_oys_co = irk_mod(iv)
#endif      
#ifdef key_oxygen
     CASE('dissolved_oxygen_in_water_column')
       iv_oxygen = irk_mod(iv)
#endif
#ifdef key_biolo_opt2
    !insertionVSjuin2010 3 nvelles variables dissoutes
     CASE('mole_concentration_of_dissolved_nitrogen')
       iv_diss_N = irk_mod(iv)
     CASE('mole_concentration_of_dissolved_phosphate')
       iv_diss_P = irk_mod(iv)
     CASE('mole_concentration_of_dissolved_silicate')
       iv_diss_Si = irk_mod(iv)
     !fin insertion
     !InsertionVSnov2010 2 nvelles variables pr equilibre au fond
     CASE('mole_concentration_of_dissolved_N2')
       iv_diss_fond_Nitr = irk_mod(iv)
      !fin insertion Nov 2010
#endif     
#ifdef key_oyster_DEB
     CASE('oysdeb_res')
       iv_oysdeb_res = irk_mod(iv)
     CASE('oysdeb_str')
       iv_oysdeb_str = irk_mod(iv)
     CASE('oysdeb_gon')
       iv_oysdeb_gon = irk_mod(iv)
     CASE('oysdeb_res2')
       iv_oysdeb_res2 = irk_mod(iv)
     CASE('oysdeb_str2')
       iv_oysdeb_str2 = irk_mod(iv)
     CASE('oysdeb_gon2')
       iv_oysdeb_gon2 = irk_mod(iv)
!     CASE('oysdeb_res3')
!       iv_oysdeb_res3 = irk_mod(iv)
!     CASE('oysdeb_str3')
!       iv_oysdeb_str3 = irk_mod(iv)
!     CASE('oysdeb_gon3')
!       iv_oysdeb_gon3 = irk_mod(iv)
#endif
#ifdef key_benthos
     CASE('mole_concentration_of_organic_detritus_expressed_as_nitrogen_in_benthos')
       iv_benth_N = irk_mod(iv)
     CASE('mole_concentration_of_organic_detritus_expressed_as_silicon_in_benthos')
       iv_benth_Si = irk_mod(iv)
     CASE('mole_concentration_of_organic_detritus_expressed_as_phosphorus_in_benthos')
       iv_benth_P = irk_mod(iv)
#if defined key_diatbenth 
     CASE('mole_concentration_of_benthic_diatoms_expressed_as_nitrogen_in_benthos')
       iv_benth_phyto_diat_N = irk_mod(iv)
#endif
#if defined key_NPbenth 
     CASE('mole_concentration_of_ammonium_in_benthos')
       iv_benth_NH4 = irk_mod(iv)         
     CASE('mole_concentration_of_dissolved_phosphorus_in_benthos')
       iv_benth_PO4 = irk_mod(iv)         
#endif
#if defined key_zostera
     CASE('mole_concentration_of_benthic_diatoms_expressed_as_nitrogen_in_benthos')
       iv_benth_phyto_diat_N = irk_mod(iv)
     CASE('mole_concentration_of_ammonium_in_benthos')
       iv_benth_NH4 = irk_mod(iv)         
     CASE('mole_concentration_of_dissolved_phosphorus_in_benthos')
       iv_benth_PO4 = irk_mod(iv)         
#endif

#endif
#ifdef key_suspensivores
     CASE('mole_concentration_of_suspensivores_expressed_as_nitrogen_in_benthos')
       iv_benth_susp_N = irk_mod(iv)
#endif
#ifdef key_benthos_gener
     CASE('mole_concentration_of_bacterie_meiofaune_expressed_as_nitrogen_in_benthos')
       iv_benth_meio_N = irk_mod(iv)
     CASE('mole_concentration_of_deposivore_herbivore_expressed_as_nitrogen_in_benthos')
       iv_benth_deposi_N = irk_mod(iv)
     CASE('mole_concentration_of_suspensivores_expressed_as_nitrogen_in_benthos')
       iv_benth_susp_N = irk_mod(iv)
     CASE('mole_concentration_of_carnivore_expressed_as_nitrogen_in_benthos')
       iv_benth_carn_N = irk_mod(iv)
#endif

#ifdef key_larve
    CASE('concentration_of_larvae_zone_1')
       iv_larve_1 = irk_mod(iv)
    CASE('concentration_of_larvae_zone_2')   
        iv_larve_2 = irk_mod(iv)
    CASE('concentration_of_larvae_zone_3')   
        iv_larve_3 = irk_mod(iv)
    CASE('concentration_of_larvae_zone_4')   
        iv_larve_4 = irk_mod(iv)
    CASE('concentration_of_larvae_zone_5')   
        iv_larve_5 = irk_mod(iv)
    CASE('concentration_of_larvae_zone_6')   
        iv_larve_6 = irk_mod(iv)
#endif
    CASE DEFAULT
#if defined key_N_tracer || defined key_P_tracer
#if defined key_N_tracer 
       DO is=1,nb_source_tracerN
         DO ivtra=1,nb_var_tracerN  
          IF(iv==isubs_tracer_N(ivtra,is)) THEN
            iv_tracer_N(ivtra,is)=irk_mod(iv)
            iv_signed_N(ivtra,is)=irk_mod(isubs_signed_N(ivtra,is))
#if defined key_age_tracer
            iv_age_N(ivtra,is)=irk_mod(iv+1)
#endif
            SELECT CASE( TRIM(ADJUSTL(ADJUSTR(name_var(isubs_signed_N(ivtra,is)))) ))
                CASE('mesozooplankton_nitrogen')
                   iv_zoo_meso_tra_N(is) = irk_mod(iv)
#if defined key_age_tracer
                   iv_zoo_meso_age_tra_N(is) = irk_mod(iv+1)
#endif
                CASE('microzooplankton_nitrogen')
                   iv_zoo_micr_tra_N(is) = irk_mod(iv)
#if defined key_age_tracer
                   iv_zoo_micr_age_tra_N(is) = irk_mod(iv+1)
#endif
#if defined key_benthos
                CASE('organic_nitrogen_benth')
                   iv_benth_tra_N(is) = irk_mod(iv)
#if defined key_age_tracer
                   iv_benth_age_tra_N(is) = irk_mod(iv+1)
#endif
#endif
                CASE('ammonium')
                   iv_nutr_NH4_tra_N(is) = irk_mod(iv)
#if defined key_age_tracer
                   iv_nutr_NH4_age_tra_N(is) = irk_mod(iv+1)
#endif
                CASE('nitrate')
                   iv_nutr_NO3_tra_N(is) = irk_mod(iv)
#if defined key_age_tracer
                   iv_nutr_NO3_age_tra_N(is) = irk_mod(iv+1)
#endif
                CASE('nanopicoplankton_nitrogen')
                   iv_phyto_nano_tra_N(is) = irk_mod(iv)
#if defined key_age_tracer
                   iv_phyto_nano_age_tra_N(is) = irk_mod(iv+1)
#endif
                CASE('diatom_nitrogen')
                   iv_phyto_diat_tra_N(is) = irk_mod(iv)
#if defined key_age_tracer
                   iv_phyto_diat_age_tra_N(is) = irk_mod(iv+1)
#endif
                CASE('dinoflagellate_nitrogen')
                   iv_phyto_dino_tra_N(is) = irk_mod(iv)
#if defined key_age_tracer
                   iv_phyto_dino_age_tra_N(is) = irk_mod(iv+1)
#endif
                CASE('detrital_nitrogen')
                   iv_detr_tra_N(is) = irk_mod(iv)
#if defined key_age_tracer
                   iv_detr_age_tra_N(is) = irk_mod(iv+1)
#endif
#if defined key_karenia
                CASE('karenia_nitrogen')
                   iv_phyto_karenia_tra_N(is) = irk_mod(iv)
#if defined key_age_tracer
                   iv_phyto_karenia_age_tra_N(is) = irk_mod(iv+1)
#endif
#endif
#if defined key_psnz
                CASE('pseudonitzschia_nitrogen')
                   iv_phyto_psnz_tra_N(is) = irk_mod(iv)
#if defined key_age_tracer
                   iv_phyto_psnz_age_tra_N(is) = irk_mod(iv+1)
#endif
#endif
#if defined key_phaeocystis
                CASE('colonial_phaeocystis_nitrogen')
                   iv_phyto_phaeocystis_colo_tra_N(is) = irk_mod(iv)
#if defined key_age_tracer
                   iv_phyto_phaeocystis_colo_age_tra_N(is) = irk_mod(iv+1)
#endif
                CASE('phaeocystis_cells_nitrogen')
                   iv_phyto_phaeocystis_cell_tra_N(is) = irk_mod(iv)
#if defined key_age_tracer
                   iv_phyto_phaeocystis_cell_age_tra_N(is) = irk_mod(iv+1)
#endif
#endif
#if defined key_ulvas
!!! ATTENTION 	: NOMS DES VARIABLES A VERIFIER
                CASE('ulves_nitrogen_benth')
                   iv_ulv_benth_tra_N(is) = irk_mod(iv)
#if defined key_age_tracer
                   iv_ulv_benth_age_tra_N(is) = irk_mod(iv+1)
#endif
                CASE('ulves_nitrogen_susp')
                   iv_ulv_tra_N(is) = irk_mod(iv)
#if defined key_age_tracer
                   iv_ulv_age_tra_N(is) = irk_mod(iv+1)
#endif
#endif

            END SELECT
          ENDIF
         ENDDO
       ENDDO
#else 
!! tracer P
       DO is=1,nb_source_tracerP
         DO ivtra=1,nb_var_tracerP  
          IF(iv==isubs_tracer_P(ivtra,is)) THEN
            iv_tracer_P(ivtra,is)=irk_mod(iv)
            iv_signed_P(ivtra,is)=irk_mod(isubs_signed_P(ivtra,is))
#if defined key_age_tracer
            iv_age_P(ivtra,is)=irk_mod(iv+1)
#endif
            SELECT CASE( TRIM(ADJUSTL(ADJUSTR(name_var(isubs_signed_P(ivtra,is)))) ))
                CASE('mesozooplankton_nitrogen')
                   iv_zoo_meso_tra_P(is) = irk_mod(iv)
#if defined key_age_tracer
                   iv_zoo_meso_age_tra_P(is) = irk_mod(iv+1)
#endif
                CASE('microzooplankton_nitrogen')
                   iv_zoo_micr_tra_P(is) = irk_mod(iv)
#if defined key_age_tracer
                   iv_zoo_micr_age_tra_P(is) = irk_mod(iv+1)
#endif
#if defined key_benthos
                CASE('detrital_phosphorus_benth')
                   iv_benth_tra_P(is) = irk_mod(iv)
#if defined key_age_tracer
                   iv_benth_age_tra_P(is) = irk_mod(iv+1)
#endif
#endif
                CASE('dissolved_phosphate')
                   iv_nutr_PO4_tra_P(is) = irk_mod(iv)
#if defined key_age_tracer
                   iv_nutr_PO4_age_tra_P(is) = irk_mod(iv+1)
#endif
                CASE('sorbed_phosphate')
                   iv_nutr_Pads_tra_P(is) = irk_mod(iv)
#if defined key_age_tracer
                   iv_nutr_Pads_age_tra_P(is) = irk_mod(iv+1)
#endif
                CASE('detrital_phosphorus')
                   iv_detr_tra_P(is) = irk_mod(iv)
#if defined key_age_tracer
                   iv_detr_age_tra_P(is) = irk_mod(iv+1)
#endif
                CASE('nanopicoplankton_nitrogen')
                   iv_phyto_nano_tra_P(is) = irk_mod(iv)
#if defined key_age_tracer
                   iv_phyto_nano_age_tra_P(is) = irk_mod(iv+1)
#endif
                CASE('diatom_nitrogen')
                   iv_phyto_diat_tra_P(is) = irk_mod(iv)
#if defined key_age_tracer
                   iv_phyto_diat_age_tra_P(is) = irk_mod(iv+1)
#endif
                CASE('dinoflagellate_nitrogen')
                   iv_phyto_dino_tra_P(is) = irk_mod(iv)
#if defined key_age_tracer
                   iv_phyto_dino_age_tra_P(is) = irk_mod(iv+1)
#endif
#if defined key_karenia
                CASE('karenia_nitrogen')
                   iv_phyto_karenia_tra_P(is) = irk_mod(iv)
#if defined key_age_tracer
                   iv_phyto_karenia_age_tra_P(is) = irk_mod(iv+1)
#endif
#endif
#if defined key_psnz
                CASE('pseudonitzschia_nitrogen')
                   iv_phyto_psnz_tra_P(is) = irk_mod(iv)
#if defined key_age_tracer
                   iv_phyto_psnz_age_tra_P(is) = irk_mod(iv+1)
#endif
#endif
#if defined key_phaeocystis
                CASE('colonial_phaeocystis_nitrogen')
                   iv_phyto_phaeocystis_colo_tra_P(is) = irk_mod(iv)
#if defined key_age_tracer
                   iv_phyto_phaeocystis_colo_age_tra_P(is) = irk_mod(iv+1)
#endif
                CASE('phaeocystis_cells_nitrogen')
                   iv_phyto_phaeocystis_cell_tra_P(is) = irk_mod(iv)
#if defined key_age_tracer
                   iv_phyto_phaeocystis_cell_age_tra_P(is) = irk_mod(iv+1)
#endif
#endif
            END SELECT
          ENDIF
         ENDDO
       ENDDO
#endif
#else
       print*, 'Invalid standard name of variable : ',TRIM(ADJUSTL(ADJUSTR(standname)))
#endif
   END SELECT

   ! smallest and largest indexes
   IF (iv >= ivmax) ivmax=iv
   IF (iv <= ivmin) ivmin=iv


   IF ( iv==nb_var) THEN
     IF_MPI (MASTER) THEN
       WRITE(iscreenlog,*) ' '
       WRITE(iscreenlog,*) '********************************'
       WRITE(iscreenlog,*) '          BIOLO_INIT_IV         '
       WRITE(iscreenlog,*) ' Initialization of iv_variables '
       WRITE(iscreenlog,*) '********************************'
       WRITE(iscreenlog,*) ' '
       WRITE(iscreenlog,*) 'iv_nutr_NH4 = ',iv_nutr_NH4
       WRITE(iscreenlog,*) 'iv_nutr_NO3 = ',iv_nutr_NO3
       WRITE(iscreenlog,*) 'iv_nutr_SiOH = ',iv_nutr_SiOH
       WRITE(iscreenlog,*) 'iv_nutr_PO4 = ',iv_nutr_PO4
       WRITE(iscreenlog,*) 'iv_nutr_Pads = ',iv_nutr_Pads
       WRITE(iscreenlog,*) 'iv_phyto_nano_N = ',iv_phyto_nano_N
       WRITE(iscreenlog,*) 'iv_phyto_diat_N = ',iv_phyto_diat_N
       WRITE(iscreenlog,*) 'iv_phyto_dino_N = ',iv_phyto_dino_N
       WRITE(iscreenlog,*) 'iv_zoo_meso_N = ',iv_zoo_meso_N
       WRITE(iscreenlog,*) 'iv_zoo_micr_N = ',iv_zoo_micr_N
       WRITE(iscreenlog,*) 'iv_detr_N = ',iv_detr_N
       WRITE(iscreenlog,*) 'iv_detr_Si = ',iv_detr_Si
       WRITE(iscreenlog,*) 'iv_detr_P = ',iv_detr_P
       WRITE(iscreenlog,*) 'iv_spim = ',iv_spim
       WRITE(iscreenlog,*) 'iv_phyto_nano_pp = ',iv_phyto_nano_pp
       WRITE(iscreenlog,*) 'iv_phyto_diat_pp = ',iv_phyto_diat_pp
       WRITE(iscreenlog,*) 'iv_phyto_dino_pp = ',iv_phyto_dino_pp
#if defined key_biolo_opt2
       WRITE(iscreenlog,*) 'iv_diss_N = ',iv_diss_N
       WRITE(iscreenlog,*) 'iv_diss_P = ',iv_diss_P
       WRITE(iscreenlog,*) 'iv_diss_Si = ',iv_diss_Si
       WRITE(iscreenlog,*) 'iv_diss_fond_Nitr = ',iv_diss_fond_Nitr
#endif
#if defined key_psnz
       WRITE(iscreenlog,*) 'iv_phyto_psnz_N = ',iv_phyto_psnz_N
       WRITE(iscreenlog,*) 'iv_phyto_psnz_Si = ',iv_phyto_psnz_Si
       WRITE(iscreenlog,*) 'iv_phyto_psnz_ad = ',iv_phyto_psnz_ad
       WRITE(iscreenlog,*) 'iv_phyto_psnz_pp = ',iv_phyto_psnz_pp          
#endif
#if defined key_karenia
       WRITE(iscreenlog,*) 'iv_phyto_karenia_C = ',iv_phyto_karenia_C
       WRITE(iscreenlog,*) 'iv_phyto_karenia_N = ',iv_phyto_karenia_N
       WRITE(iscreenlog,*) 'iv_phyto_karenia_P = ',iv_phyto_karenia_P
       WRITE(iscreenlog,*) 'iv_phyto_karenia_pp = ',iv_phyto_karenia_pp          
#endif
#if defined key_phaeocystis
       WRITE(iscreenlog,*) 'iv_phyto_phaeocystis_colo_N = ',iv_phyto_phaeocystis_colo_N
       WRITE(iscreenlog,*) 'iv_phyto_phaeocystis_cell_N = ',iv_phyto_phaeocystis_cell_N
       WRITE(iscreenlog,*) 'iv_phyto_phaeocystis_mucus = ',iv_phyto_phaeocystis_mucus
       WRITE(iscreenlog,*) 'iv_phyto_phaeocystis_pp = ',iv_phyto_phaeocystis_pp          
#endif
#ifdef key_zoo_prod
       WRITE(iscreenlog,*) 'iv_zoo_micr_ps = ',iv_zoo_micr_ps
       WRITE(iscreenlog,*) 'iv_zoo_meso_ps = ',iv_zoo_meso_ps
#endif
#ifdef key_ulvas
       WRITE(iscreenlog,*) 'iv_ulv_sus_N = ',iv_ulv_sus_N
       WRITE(iscreenlog,*) 'iv_ulv_benth_N = ',iv_ulv_benth_N
       WRITE(iscreenlog,*) 'iv_ulv_susdrywght = ',iv_ulv_susdrywght
       WRITE(iscreenlog,*) 'iv_ulv_benthdrywght = ',iv_ulv_benthdrywght 
       WRITE(iscreenlog,*) 'iv_ulv_sus_P = ',iv_ulv_sus_P
       WRITE(iscreenlog,*) 'iv_ulv_benth_P = ',iv_ulv_benth_P 
       WRITE(iscreenlog,*) 'iv_ulv_suspp = ',iv_ulv_suspp
       WRITE(iscreenlog,*) 'iv_ulv_benthpp = ',iv_ulv_benthpp  
#endif
#ifdef key_zostera
       WRITE(iscreenlog,*) 'iv_zost_LB = ',iv_zost_LB
       WRITE(iscreenlog,*) 'iv_zost_RB = ',iv_zost_RB
       WRITE(iscreenlog,*) 'iv_zost_D = ',iv_zost_D
       WRITE(iscreenlog,*) 'iv_zost_LN = ',iv_zost_LN
       WRITE(iscreenlog,*) 'iv_zost_RN = ',iv_zost_RN
       WRITE(iscreenlog,*) 'iv_zost_LP = ',iv_zost_LP
       WRITE(iscreenlog,*) 'iv_zost_RP = ',iv_zost_RP
       WRITE(iscreenlog,*) 'iv_detr_zost_N = ',iv_detr_zost_N
       WRITE(iscreenlog,*) 'iv_detr_zost_P = ',iv_detr_zost_P
       WRITE(iscreenlog,*) 'iv_zost_benth_N = ',iv_zost_benth_N
       WRITE(iscreenlog,*) 'iv_zost_benth_P = ',iv_zost_benth_P
       WRITE(iscreenlog,*) 'iv_zost_seed = ',iv_zost_seed
       WRITE(iscreenlog,*) 'iv_benth_seed = ',iv_zost_benth_seed
       WRITE(iscreenlog,*) 'iv_benth_NH4 = ',iv_benth_NH4
       WRITE(iscreenlog,*) 'iv_benth_PO4 = ',iv_benth_PO4
!      WRITE(iscreenlog,*) 'iv_zost_pp = ',iv_zost_pp
!      WRITE(iscreenlog,*) 'iv_zost_LNuptake = ',iv_zost_LNuptake
!      WRITE(iscreenlog,*) 'iv_zost_LPuptake = ',iv_zost_LPuptake
!      WRITE(iscreenlog,*) 'iv_zost_RNuptake = ',iv_zost_RNuptake
!      WRITE(iscreenlog,*) 'iv_zost_RPuptake = ',iv_zost_RPuptake
#endif  
#ifdef key_oyster_SFG
       WRITE(iscreenlog,*) 'iv_oys_so = ',iv_oys_so
       WRITE(iscreenlog,*) 'iv_oys_go = ',iv_oys_go
       WRITE(iscreenlog,*) 'iv_oys_co = ',iv_oys_co
#endif
#ifdef key_oxygen
       WRITE(iscreenlog,*) 'iv_oxygen = ',iv_oxygen
#endif
#ifdef key_oyster_DEB
     WRITE(iscreenlog,*) 'iv_oysdeb_res = ',iv_oysdeb_res
     WRITE(iscreenlog,*) 'iv_oysdeb_str = ',iv_oysdeb_str
     WRITE(iscreenlog,*) 'iv_oysdeb_gon = ',iv_oysdeb_gon
     WRITE(iscreenlog,*) 'iv_oysdeb_res2 = ',iv_oysdeb_res2
     WRITE(iscreenlog,*) 'iv_oysdeb_str2 = ',iv_oysdeb_str2
     WRITE(iscreenlog,*) 'iv_oysdeb_gon2 = ',iv_oysdeb_gon2
!     WRITE(iscreenlog,*) 'iv_oysdeb_res3 = ',iv_oysdeb_res3
!     WRITE(iscreenlog,*) 'iv_oysdeb_str3 = ',iv_oysdeb_str3
!     WRITE(iscreenlog,*) 'iv_oysdeb_gon3 = ',iv_oysdeb_gon3
#endif
#ifdef key_benthos
       WRITE(iscreenlog,*) 'iv_benth_N = ',iv_benth_N
       WRITE(iscreenlog,*) 'iv_benth_Si = ',iv_benth_Si
       WRITE(iscreenlog,*) 'iv_benth_P = ',iv_benth_P
#if defined key_diatbenth 
       WRITE(iscreenlog,*) 'iv_benth_phyto_diat_N = ',iv_benth_phyto_diat_N
#endif
#if defined key_NPbenth 
       WRITE(iscreenlog,*) 'iv_benth_NH4 = ',iv_benth_NH4
       WRITE(iscreenlog,*) 'iv_benth_PO4 = ',iv_benth_PO4
#endif
#if defined key_zostera
       WRITE(iscreenlog,*) 'iv_benth_phyto_diat_N = ',iv_benth_phyto_diat_N
       WRITE(iscreenlog,*) 'iv_benth_NH4 = ',iv_benth_NH4
       WRITE(iscreenlog,*) 'iv_benth_PO4 = ',iv_benth_PO4
#endif
#endif
#ifdef key_suspensivores
       WRITE(iscreenlog,*) 'iv_benth_susp_N = ',iv_benth_susp_N
#endif
#ifdef key_benthos_gener
       WRITE(iscreenlog,*) 'iv_benth_meio_N = ',iv_benth_meio_N
       WRITE(iscreenlog,*) 'iv_benth_deposi_N = ',iv_benth_deposi_N
       WRITE(iscreenlog,*) 'iv_benth_susp_N = ',iv_benth_susp_N
       WRITE(iscreenlog,*) 'iv_benth_carn_N = ',iv_benth_carn_N
#endif
#ifdef key_larve
       WRITE(iscreenlog,*) 'iv_larve_1 = ',iv_larve_1
       WRITE(iscreenlog,*) 'iv_larve_2 = ',iv_larve_2
       WRITE(iscreenlog,*) 'iv_larve_3 = ',iv_larve_3
       WRITE(iscreenlog,*) 'iv_larve_4 = ',iv_larve_4
       WRITE(iscreenlog,*) 'iv_larve_5 = ',iv_larve_5
       WRITE(iscreenlog,*) 'iv_larve_6 = ',iv_larve_6
#endif    
#if defined key_N_tracer
#if defined key_biolo_opt2
       WRITE(ierrorlog,*)'ERROR : option 2 of key_biolo (-key_biolo_opt2) is incompatible with key_N_tracer'
       WRITE(ierrorlog,*)'The simulation is stopped'
       CALL_MPI MPI_FINALIZE(IERR_MPI)
       STOP
#endif
       DO is=1,nb_source_tracerN
         WRITE(iscreenlog,*) 'tracer_N source ',is
         DO ivtra=1,nb_var_tracerN 
          WRITE(iscreenlog,*) iv_tracer_N(ivtra,is) ,'variable : ',  &
                                             TRIM(ADJUSTL(ADJUSTR(name_var(isubs_tracer_N(ivtra,is)))))
#if defined key_age_tracer
          WRITE(iscreenlog,*) iv_age_N(ivtra,is) ,'variable : ',  &
                                             TRIM(ADJUSTL(ADJUSTR(name_var(isubs_age_N(ivtra,is)))))
#endif
         ENDDO
         WRITE(iscreenlog,*) 'iv_nutr_NH4_tra_N(',is,' = ',iv_nutr_NH4_tra_N(is)
         WRITE(iscreenlog,*) 'iv_nutr_NO3_tra_N(',is,' = ',iv_nutr_NO3_tra_N(is)
         WRITE(iscreenlog,*) 'iv_phyto_nano_tra_N(',is,' = ',iv_phyto_nano_tra_N(is)
         WRITE(iscreenlog,*) 'iv_phyto_diat_tra_N(',is,' = ',iv_phyto_diat_tra_N(is)
         WRITE(iscreenlog,*) 'iv_phyto_dino_tra_N(',is,' = ',iv_phyto_dino_tra_N(is)
         WRITE(iscreenlog,*) 'iv_zoo_micr_tra_N(',is,' = ',iv_zoo_micr_tra_N(is)
         WRITE(iscreenlog,*) 'iv_zoo_meso_tra_N(',is,' = ',iv_zoo_meso_tra_N(is)
         WRITE(iscreenlog,*) 'iv_detr_tra_N(',is,' = ',iv_detr_tra_N(is)
#if defined key_age_tracer
         WRITE(iscreenlog,*) 'iv_nutr_NH4_age_tra_N(',is,' = ',iv_nutr_NH4_age_tra_N(is)
         WRITE(iscreenlog,*) 'iv_nutr_NO3_age_tra_N(',is,' = ',iv_nutr_NO3_age_tra_N(is)
         WRITE(iscreenlog,*) 'iv_phyto_nano_age_tra_N(',is,' = ',iv_phyto_nano_age_tra_N(is)
         WRITE(iscreenlog,*) 'iv_phyto_diat_age_tra_N(',is,' = ',iv_phyto_diat_age_tra_N(is)
         WRITE(iscreenlog,*) 'iv_phyto_dino_age_tra_N(',is,' = ',iv_phyto_dino_age_tra_N(is)
         WRITE(iscreenlog,*) 'iv_zoo_micr_age_tra_N(',is,' = ',iv_zoo_micr_age_tra_N(is)
         WRITE(iscreenlog,*) 'iv_zoo_meso_age_tra_N(',is,' = ',iv_zoo_meso_age_tra_N(is)
         WRITE(iscreenlog,*) 'iv_detr_age_tra_N(',is,' = ',iv_detr_age_tra_N(is)          
#endif
#if defined key_benthos
         WRITE(iscreenlog,*) 'iv_benth_tra_N(',is,' = ',iv_benth_tra_N(is)
#if defined key_age_tracer
         WRITE(iscreenlog,*) 'iv_benth_age_tra_N(',is,' = ',iv_benth_age_tra_N(is)
#endif
#endif
#if defined key_psnz
         WRITE(iscreenlog,*) 'iv_phyto_psnz_tra_N(',is,' = ',iv_phyto_psnz_tra_N(is)
#if defined key_age_tracer
         WRITE(iscreenlog,*) 'iv_phyto_psnz_age_tra_N(',is,' = ',iv_phyto_psnz_age_tra_N(is)
#endif
#endif
#if defined key_phaeocystis
         WRITE(iscreenlog,*) 'iv_phyto_phaeocystis_colo_tra_N(',is,' = ',iv_phyto_phaeocystis_colo_tra_N(is)
         WRITE(iscreenlog,*) 'iv_phyto_phaeocystis_cell_tra_N(',is,' = ',iv_phyto_phaeocystis_cell_tra_N(is)
#if defined key_age_tracer
         WRITE(iscreenlog,*) 'iv_phyto_phaeocystis_colo_age_tra_N(',is,' = ',iv_phyto_phaeocystis_colo_age_tra_N(is)
         WRITE(iscreenlog,*) 'iv_phyto_phaeocystis_cell_age_tra_N(',is,' = ',iv_phyto_phaeocystis_cell_age_tra_N(is)
#endif
#endif
#if defined key_karenia
         WRITE(iscreenlog,*) 'iv_phyto_karenia_tra_N(',is,' = ',iv_phyto_karenia_tra_N(is)
#if defined key_age_tracer
         WRITE(iscreenlog,*) 'iv_phyto_karenia_age_tra_N(',is,' = ',iv_phyto_karenia_age_tra_N(is)
#endif
#endif
#if defined key_ulvas
         WRITE(iscreenlog,*) 'iv_ulv_benth_tra_N(',is,' = ',iv_ulv_benth_tra_N(is)
         WRITE(iscreenlog,*) 'iv_ulv_tra_N(',is,' = ',iv_ulv_tra_N(is)
#if defined key_age_tracer
         WRITE(iscreenlog,*) 'iv_ulv_benth_age_tra_N(',is,' = ',iv_ulv_benth_age_tra_N(is)
         WRITE(iscreenlog,*) 'iv_ulv_age_tra_N(',is,' = ',iv_ulv_age_tra_N(is)

#endif
#endif
       ENDDO
#endif
#if defined key_P_tracer
#if defined key_biolo_opt2
       WRITE(ierrorlog,*)'ERROR : option 2 of key_biolo (-key_biolo_opt2) is incompatible with key_P_tracer'
       WRITE(ierrorlog,*)'The simulation is stopped'
       CALL_MPI MPI_FINALIZE(IERR_MPI)
       STOP
#endif
       DO is=1,nb_source_tracerP
         WRITE(iscreenlog,*) 'tracer_P source ',is
         DO ivtra=1,nb_var_tracerP 
          WRITE(iscreenlog,*) iv_tracer_P(ivtra,is) ,'variable : ',  &
                              TRIM(ADJUSTL(ADJUSTR(name_var(isubs_tracer_P(ivtra,is)))))
#if defined key_age_tracer
          WRITE(iscreenlog,*) iv_age_P(ivtra,is) ,'variable : ',  &
                              TRIM(ADJUSTL(ADJUSTR(name_var(isubs_age_P(ivtra,is)))))
#endif
         ENDDO
         WRITE(iscreenlog,*) 'iv_nutr_PO4_tra_P(',is,' = ',iv_nutr_PO4_tra_P(is)
         WRITE(iscreenlog,*) 'iv_nutr_Pads_tra_P(',is,' = ',iv_nutr_Pads_tra_P(is)
         WRITE(iscreenlog,*) 'iv_phyto_nano_tra_P(',is,' = ',iv_phyto_nano_tra_P(is)
         WRITE(iscreenlog,*) 'iv_phyto_diat_tra_P(',is,' = ',iv_phyto_diat_tra_P(is)
         WRITE(iscreenlog,*) 'iv_phyto_dino_tra_P(',is,' = ',iv_phyto_dino_tra_P(is)
         WRITE(iscreenlog,*) 'iv_zoo_micr_tra_P(',is,' = ',iv_zoo_micr_tra_P(is)
         WRITE(iscreenlog,*) 'iv_zoo_meso_tra_P(',is,' = ',iv_zoo_meso_tra_P(is)
         WRITE(iscreenlog,*) 'iv_detr_tra_P(',is,' = ',iv_detr_tra_P(is)
#if defined key_age_tracer
         WRITE(iscreenlog,*) 'iv_nutr_PO4_age_tra_P(',is,' = ',iv_nutr_PO4_age_tra_P(is)
         WRITE(iscreenlog,*) 'iv_nutr_Pads_age_tra_P(',is,' = ',iv_nutr_Pads_age_tra_P(is)
         WRITE(iscreenlog,*) 'iv_phyto_nano_age_tra_P(',is,' = ',iv_phyto_nano_age_tra_P(is)
         WRITE(iscreenlog,*) 'iv_phyto_diat_age_tra_P(',is,' = ',iv_phyto_diat_age_tra_P(is)
         WRITE(iscreenlog,*) 'iv_phyto_dino_age_tra_P(',is,' = ',iv_phyto_dino_age_tra_P(is)
         WRITE(iscreenlog,*) 'iv_zoo_micr_age_tra_P(',is,' = ',iv_zoo_micr_age_tra_P(is)
         WRITE(iscreenlog,*) 'iv_zoo_meso_age_tra_P(',is,' = ',iv_zoo_meso_age_tra_P(is)
         WRITE(iscreenlog,*) 'iv_detr_age_tra_P(',is,' = ',iv_detr_age_tra_P(is)          
#endif
#if defined key_benthos
         WRITE(iscreenlog,*) 'iv_benth_tra_P(',is,' = ',iv_benth_tra_P(is)
#if defined key_age_tracer
         WRITE(iscreenlog,*) 'iv_benth_age_tra_P(',is,' = ',iv_benth_age_tra_P(is)
#endif
#endif
#if defined key_psnz
         WRITE(iscreenlog,*) 'iv_phyto_psnz_tra_P(',is,' = ',iv_phyto_psnz_tra_P(is)
#if defined key_age_tracer
         WRITE(iscreenlog,*) 'iv_phyto_psnz_age_tra_P(',is,' = ',iv_phyto_psnz_age_tra_P(is)
#endif
#endif
#if defined key_phaeocystis
         WRITE(iscreenlog,*) 'iv_phyto_phaeocystis_colo_tra_P(',is,' = ',iv_phyto_phaeocystis_colo_tra_P(is)
         WRITE(iscreenlog,*) 'iv_phyto_phaeocystis_cell_tra_P(',is,' = ',iv_phyto_phaeocystis_cell_tra_P(is)
#if defined key_age_tracer
         WRITE(iscreenlog,*) 'iv_phyto_phaeocystis_colo_age_tra_P(',is,' = ',iv_phyto_phaeocystis_colo_age_tra_P(is)
         WRITE(iscreenlog,*) 'iv_phyto_phaeocystis_cell_age_tra_P(',is,' = ',iv_phyto_phaeocystis_cell_age_tra_P(is)
#endif
#endif
#if defined key_karenia
         WRITE(iscreenlog,*) 'iv_phyto_karenia_tra_P(',is,' = ',iv_phyto_karenia_tra_P(is)
#if defined key_age_tracer
         WRITE(iscreenlog,*) 'iv_phyto_karenia_age_tra_P(',is,' = ',iv_phyto_karenia_age_tra_P(is)
#endif
#endif
       ENDDO
#endif
       WRITE(iscreenlog,*) ' '
       WRITE(iscreenlog,*) '********************************'
       WRITE(iscreenlog,*) ' '

#if ! defined key_sedim_MUSTANG && ! defined key_conta
     sumverif = iv_nutr_NH4 + iv_nutr_NO3 + iv_nutr_SiOH + iv_nutr_PO4 + iv_nutr_Pads + &
                iv_phyto_nano_N + iv_phyto_diat_N + iv_phyto_dino_N +                   &
                iv_zoo_meso_N + iv_zoo_micr_N + iv_detr_N + iv_detr_Si + iv_detr_P +    &
#if defined key_biolo_opt2
                iv_diss_N+ iv_diss_P + iv_diss_Si + iv_diss_fond_Nitr+                  &
#endif
#if defined key_psnz
                iv_phyto_psnz_N + iv_phyto_psnz_Si + iv_phyto_psnz_ad + iv_phyto_psnz_pp + &
#endif
#if defined key_karenia
                iv_phyto_karenia_C + iv_phyto_karenia_N + iv_phyto_karenia_P + iv_phyto_karenia_pp + &
#endif
#if defined key_phaeocystis
                iv_phyto_phaeocystis_colo_N + iv_phyto_phaeocystis_cell_N +      &
                iv_phyto_phaeocystis_mucus + iv_phyto_phaeocystis_pp + &
#endif
#if defined key_zoo_prod
                iv_zoo_micr_ps + iv_zoo_meso_ps + &
#endif
#ifdef key_ulvas
                iv_ulv_sus_N + iv_ulv_benth_N +iv_ulv_susdrywght + &
                iv_ulv_benthdrywght + iv_ulv_sus_P + iv_ulv_benth_P + &
                iv_ulv_suspp + iv_ulv_benthpp + & 
#endif
#ifdef key_zostera
               iv_zost_LB+iv_zost_RB+iv_zost_D+iv_zost_LN+iv_zost_RN+iv_zost_LP+iv_zost_RP+ &
               iv_detr_zost_N+iv_detr_zost_P+iv_zost_benth_N+iv_zost_benth_P+iv_zost_seed+iv_zost_benth_seed +   &
!               iv_zost_pp+iv_zost_LNuptake+iv_zost_LPuptake+iv_zost_RNuptake+iv_zost_RPuptake
#endif
#ifdef key_oyster_SFG
                iv_oys_so+iv_oys_go+iv_oys_co + &
#endif  
#ifdef key_oxygen
                iv_oxygen + &
#endif
#ifdef key_oyster_DEB
                iv_oysdeb_res+iv_oysdeb_str+iv_oysdeb_gon + &
                iv_oysdeb_res2+iv_oysdeb_str2+iv_oysdeb_gon2 + &
!                iv_oysdeb_res3+iv_oysdeb_str3+iv_oysdeb_gon3 + &
#endif
#ifdef key_benthos
                iv_benth_N+iv_benth_Si+iv_benth_P + &
#if defined key_diatbenth
                iv_benth_phyto_diat_N + &
#if defined key_NPbenth
                iv_benth_NH4+iv_benth_PO4 + &
#endif
#elif key_zostera
                iv_benth_phyto_diat_N +iv_benth_NH4+iv_benth_PO4 + &
#endif
#endif
#if defined key_microtracers
                iv_tracer_depth1 + iv_tracer_depth2 + iv_tracer_depth3 + &
                iv_tracer_agedepth1 + iv_tracer_agedepth2 + iv_tracer_agedepth3 + &
                iv_tracer_cumuldepth1 + iv_tracer_cumuldepth2 + iv_tracer_cumuldepth3 + &
#endif
                iv_spim + iv_phyto_nano_pp + iv_phyto_diat_pp + iv_phyto_dino_pp

#if defined key_N_tracer
       DO is=1,nb_source_tracerN
         DO ivtra=1,nb_var_tracerN 
          sumverif = sumverif + iv_tracer_N(ivtra,is)
#if defined key_age_tracer
          sumverif = sumverif + iv_age_N(ivtra,is) 
#endif
         ENDDO
       ENDDO
#endif
#if defined key_P_tracer
       DO is=1,nb_source_tracerP
         DO ivtra=1,nb_var_tracerP 
          sumverif = sumverif + iv_tracer_P(ivtra,is)
#if defined key_age_tracer
          sumverif = sumverif + iv_age_P(ivtra,is) 
#endif
         ENDDO
       ENDDO
#endif 
       IF ( sumverif /= sumindex(ivmin,ivmax) ) THEN
         WRITE(ierrorlog,*)' '
         WRITE(ierrorlog,*)'BIOLO_INIT_IV'
         WRITE(ierrorlog,*)'the initialization of indexes of substances'
         WRITE(ierrorlog,*)'is not correct'
         WRITE(ierrorlog,*)'Rank min=',ivmin,'Rank max=',ivmax,'sumindex(ivmin,ivmax)=',sumindex(ivmin,ivmax)
         WRITE(ierrorlog,*)'sumverif=',sumverif
         WRITE(ierrorlog,*)'Have a look at simu.log and variable.dat files'
         WRITE(ierrorlog,*)'and inquire into the mistakes'
         WRITE(ierrorlog,*)' '
         WRITE(ierrorlog,*)'The simulation is stopped'
         STOP
       END IF
#endif
     ENDIF_MPI
   END IF   ! ends test on nb_var

  END SUBROUTINE biolo_init_iv

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

  SUBROUTINE biolo_init_id(id,standname)

   !&E---------------------------------------------------------------------
   !&E                 ***  ROUTINE biolo_init_id  ***
   !&E
   !&E ** Purpose : Initialize indexes of diagnostic variables
   !&E
   !&E ** Description :
   !&E
   !&E ** Called by : sub_read_vardiag
   !&E
   !&E ** External calls :
   !&E
   !&E ** Reference :
   !&E
   !&E ** History :
   !&E       !  2009-10  (V. Garnier)  Original code
   !&E
   !&E---------------------------------------------------------------------
   !! * Modules used
   USE comvars2d, ONLY : iscreenlog,ierrorlog
   USE toolmath,  ONLY : sumindex
#if defined key_N_tracer || defined key_P_tracer
   USE comsubstance, ONLY : name_var
#endif
   USE_MPI toolmpi, ONLY : MASTER

   !! * Arguments
   INTEGER,          INTENT( in ) :: id
   CHARACTER(LEN=*), INTENT( in ) :: standname

   !! * Local declarations
   INTEGER               :: sumverif
#if defined key_N_tracer || defined key_P_tracer
   INTEGER               :: is,ivtra,idiag
#endif

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

   SELECT CASE( TRIM(ADJUSTL(ADJUSTR(standname))) )

     CASE('maximum_diatom_mass_concentration_in_sea_water')
       id_diat_max = id
     CASE('date_of_maximum_diatom_mass_concentration_in_sea_water')
       id_diat_datemax = id
     CASE('depth_of_maximum_diatom_mass_concentration_in_sea_water')
       id_diat_depthmax = id
     CASE('maximum_dinoflagellate_mass_concentration_in_sea_water')
       id_dino_max = id
     CASE('date_of_maximum_dinoflagellate_mass_concentration_in_sea_water')
       id_dino_datemax = id
     CASE('depth_of_maximum_dinoflagellate_mass_concentration_in_sea_water')
       id_dino_depthmax = id
     CASE('maximum_nanoflagellate_mass_concentration_in_sea_water')
       id_nano_max = id
     CASE('date_of_maximum_nanoflagellate_mass_concentration_in_sea_water')
       id_nano_datemax = id
     CASE('depth_of_maximum_nanoflagellate_mass_concentration_in_sea_water')
       id_nano_depthmax = id
     CASE('maximum_vertical_gradient_of_sea_water_salinity')
       id_gradsali_max = id
     CASE('depth_of_maximum_vertical_gradient_of_sea_water_salinity')
       id_gradsali_depthmax = id
     CASE('maximum_vertical_gradient_of_sea_water_temperature')
       id_gradtemp_max = id
     CASE('depth_of_maximum_vertical_gradient_of_sea_water_temperature')
       id_gradtemp_depthmax = id
#if defined key_biolo_opt2
     CASE('corrected_concentration_of_suspended_matter_in_sea_water')
       id_spim_satused = id
#endif
     CASE('light_limitation_of_diatom_growth')
       id_diat_limlight = id
     CASE('nitrogen_limitation_of_diatom_growth')
       id_diat_limN = id
     CASE('silicon_limitation_of_diatom_growth')
       id_diat_limSi = id
     CASE('phosphate_limitation_of_diatom_growth')
       id_diat_limP = id
     CASE('light_limitation_of_dinoflagellate_growth')
       id_dino_limlight = id
     CASE('nitrogen_limitation_of_dinoflagellate_growth')
       id_dino_limN = id
     CASE('phosphate_limitation_of_dinoflagellate_growth')
       id_dino_limP = id
     CASE('light_limitation_of_nanoflagellate_growth')
       id_nano_limlight = id
     CASE('nitrogen_limitation_of_nanoflagellate_growth')
       id_nano_limN = id
     CASE('phosphate_limitation_of_nanoflagellate_growth')
       id_nano_limP = id
     CASE('light_extinction_in_sea_water')
       id_extinctioncoeff=id
#if defined key_biolo_opt2
     CASE('cumulated_production_of_diatoms_in_sea_water_column_expressed_in_nitrogen')
#else
     CASE('cumulated_production_of_diatoms_in_sea_water_column_expressed_in_carbon')
#endif
       id_diat_columnprod=id
#if defined key_biolo_opt2
     CASE('cumulated_production_of_dinoflagellates_in_sea_water_column_expressed_in_nitrogen')
#else
     CASE('cumulated_production_of_dinoflagellates_in_sea_water_column_expressed_in_carbon')
#endif
       id_dino_columnprod=id
#if defined key_biolo_opt2
     CASE('cumulated_production_of_nanoflagellates_in_sea_water_column_expressed_in_nitrogen')
#else
     CASE('cumulated_production_of_nanoflagellates_in_sea_water_column_expressed_in_carbon')
#endif
       id_nano_columnprod=id
     CASE('chlorophyll_mass_concentration_in_sea_water')
       id_totalchl=id
#if defined key_biolo_opt2
     CASE('cumulated_total_production_in_sea_water_column_expressed_in_nitrogen')
#else
     CASE('cumulated_total_production_in_sea_water_column_expressed_in_carbon')
#endif
       id_columnprodtotal=id
     CASE('diatom_sinking_velocity_in_sea_water')
       id_diatsettling=id
     CASE('detritus_sinking_velocity_in_sea_water')
       id_detsettling=id
     CASE('total_suspended_matter_in_sea_water')
       id_spm_total=id
     CASE('txfiltbenth')
        id_benthos_txf=id     
#if defined key_psnz
     CASE('maximum_pseudonitzschia_mass_concentration_in_sea_water')
       id_psnz_max = id
     CASE('date_of_maximum_pseudonitzschia_mass_concentration_in_sea_water')
       id_psnz_datemax = id
     CASE('depth_of_maximum_pseudonitzschia_mass_concentration_in_sea_water')
       id_psnz_depthmax = id
     CASE('light_limitation_of_pseudonitzschia_growth')
       id_psnz_limlight = id
     CASE('nitrogen_limitation_of_pseudonitzschia_growth')
       id_psnz_limN = id
     CASE('silicon_limitation_of_pseudonitzschia_growth')
       id_psnz_limSi = id
     CASE('phosphate_limitation_of_pseudonitzschia_growth')
       id_psnz_limP = id
     CASE('cumulated_production_of_pseudonitzschia_in_sea_water_column_expressed_in_carbon')
       id_psnz_columnprod=id
#endif
#if defined key_karenia
     CASE('maximum_karenia_mass_concentration_in_sea_water')
       id_karenia_max = id
     CASE('date_of_maximum_karenia_mass_concentration_in_sea_water')
       id_karenia_datemax = id
     CASE('depth_of_maximum_karenia_mass_concentration_in_sea_water')
       id_karenia_depthmax = id
     CASE('light_limitation_of_karenia_growth')
       id_karenia_limlight = id
     CASE('nitrogen_limitation_of_karenia_growth')
       id_karenia_limN = id
     CASE('phosphate_limitation_of_karenia_growth')
       id_karenia_limP = id
     CASE('cumulated_production_of_karenia_in_sea_water_column_expressed_in_carbon')
       id_karenia_columnprod=id
#endif
#if defined key_phaeocystis
     CASE('maximum_phaeocystis_mass_concentration_in_sea_water')
       id_phaeocystis_max = id
     CASE('date_of_maximum_phaeocystis_mass_concentration_in_sea_water')
       id_phaeocystis_datemax = id
     CASE('depth_of_maximum_phaeocystis_mass_concentration_in_sea_water')
       id_phaeocystis_depthmax = id
     CASE('light_limitation_of_phaeocystis_growth')
       id_phaeocystis_limlight = id
     CASE('nitrogen_limitation_of_phaeocystis_growth')
       id_phaeocystis_limN = id
     CASE('phosphate_limitation_of_phaeocystis_growth')
       id_phaeocystis_limP = id
     CASE('cumulated_production_of_phaeocystis_in_sea_water_column_expressed_in_carbon')
       id_phaeocystis_columnprod=id
#endif
#if defined key_zoo_prod
     CASE('cumulated_production_of_microzooplankton_in_sea_water_column_expressed_in_carbon')
       id_zoo_micr_columnprod=id
     CASE('cumulated_production_of_mesozooplankton_in_sea_water_column_expressed_in_carbon')
       id_zoo_meso_columnprod=id
     CASE('cumulated_total_zooplancton_production_in_sea_water_column_expressed_in_carbon')
       id_zoo_columnprodtotal=id
#endif
#ifdef key_ulvas
     CASE('suspended_ulva_growth')
       id_ulv_ratiosus=id
     CASE('suspended_ulva_mortality')
       id_ulv_susmort=id
     CASE('light_limitation_of_suspended_ulva_growth')
       id_ulv_suslimlight=id
     CASE('nitrogen_limitation_of_suspended_ulva_growth')
       id_ulv_suslimN=id
     CASE('phosphate_limitation_of_suspended_ulva_growth')
       id_ulv_suslimP=id
     CASE('nitrogen_pumping_by_suspended_ulva')
       id_ulv_suspumpN=id
     CASE('phosphate_pumping_by_suspended_ulva')
       id_ulv_suspumpP=id
     CASE('ulva_sinking_velocity_in_sea_water')
       id_ulv_settling=id
     CASE('settled_ulva_growth')
       id_ulv_ratiobenth=id
     CASE('settled_ulva_mortality')
       id_ulv_benthmort=id
     CASE('light_limitation_of_settled_ulva_growth')
       id_ulv_benthlimlight=id
     CASE('nitrogen_limitation_of_settled_ulva_growth')
      id_ulv_benthlimN=id
     CASE('phosphate_limitation_of_settled_ulva_growth')
      id_ulv_benthlimP=id
     CASE('nitrogen_pumping_by_settled_ulva')
      id_ulv_benthpumpN=id
     CASE('phosphate_pumping_by_settled_ulva')
      id_ulv_benthpumpP=id
     CASE('settl_resusp_bilan')
      id_ulv_resusbil=id
     CASE('nitrogen_resusp')
      id_ulv_resusN=id
     CASE('phosphate_resusp')
      id_ulv_resusP=id
#endif
#ifdef key_zostera
!     CASE('zostera_leaf_biomass_expressed_as_gDW_per_m2')
!       id_zost_LBDW=id
!     CASE('zostera_root_biomass_expressed_as_gDW_per_m2')
!       id_zost_RBDW=id
     CASE('light_at_the_top_of_the_canopy')
       id_zost_Qcan=id
     CASE('zostera_leaf_area_index')
       id_zost_LAI=id
     CASE('light_limitation_for_zostera_production')
       id_zost_limlum=id
     CASE('nitrogen_limitation_for_zostera_production')
       id_zost_limprodLN=id
     CASE('phosphorous_limitation_for_zostera_production')
       id_zost_limprodLP=id
     CASE('nitrogen_limitation_for_zostera_recruitment')
       id_zost_limRN=id
     CASE('phosphorous_limitation_for_zostera_recruitment')
       id_zost_limRP=id
!     CASE('temperature_effect_on_zostera_production')
!       id_zost_effetchaleurzprod=id
!     CASE('temperature_effect_on_leaf_respiration')
!       id_zost_effetchaleurzrespf=id
!     CASE('temperature_effect_on_root_respiration')
!       id_zost_effetchaleurzrespr=id
!     CASE('ammonium_limitation_for_leaf_absorption')
!       id_zost_limabsLnh4=id
!     CASE('nitrate_limitation_for_leaf_absorption')
!       id_zost_limabsLno3=id
!     CASE('phosphate_limitation_for_leaf_absorption')
!       id_zost_limabsLpo4=id
!     CASE('ammonium_limitation_for_root_absorption')
!       id_zost_limabsRnh4=id
!     CASE('phosphate_limitation_for_root_absorption')
!       id_zost_limabsRpo4=id
     CASE('selfshading_limitation_for_zostera_recruitment')
       id_zost_limselfshad=id
     CASE('root_biomass_limitation_for_zostera_recruitment')
       id_zost_limRB=id
!     CASE('wind_effect_on_leaf_mortality')
!       id_zost_effetvent=id
!     CASE('zostera_seed_germination_rate')
!       id_zost_Sgerm=id
!     CASE('zostera_sexual_reproduction_effort')
!       id_zost_ERS=id
     CASE('daily_zostera_production')
       id_zost_prod=id
#endif
#ifdef key_oyster_SFG
     CASE('occurence_of_spawn_coq')
       id_oys_tcoq=id
     CASE('occurence_of_spawn_gam')
       id_oys_tgam=id
     CASE('gain_coq')
       id_oys_gaincoq=id
     CASE('gain_soma') 
       id_oys_gainsoma=id
     CASE('gain_reprod')
       id_oys_gainrepr=id
     CASE('organic_ingered_fraction')
       id_oys_orgafring=id
     CASE('bilansoma')
       id_oys_bilansoma=id
     CASE('bilancoq')
       id_oys_bilancoq=id
     CASE('oyster_filtration')
       id_oys_filt=id
     CASE('oyster_respiration')
       id_oys_resp=id
     CASE('oyster_gameto')
       id_oys_gameto=id
     CASE('oyster_thresh')
       id_oys_seuilponte=id
     CASE('reposcoq')
       id_oys_reposcoq=id
     CASE('reposgam')
       id_oys_reposgam=id
     CASE('ponte')
       id_oys_ponte=id
     CASE('absorg')
       id_oys_absorg=id   
#endif
#ifdef key_oxygen
     CASE('oxygen_saturation')
       id_oxy_sat=id  
#endif
#if defined key_oyster_DEB  
     CASE('oyster_filtration')
       id_oysDEB_FRpop=id
     CASE('oyster_pseudofeces')
       id_oysDEB_PFpop=id
     CASE('oyster_feces')
       id_oysDEB_Fpop=id
     CASE('oyster_dry_weigth')
        id_oysDEB_DWtot=id
     CASE('variable_chlorophylle')
        id_oysDEB_kchlvble=id
     CASE('oyster_gonad-soma_ratio')
        id_oysDEB_ER=id
     CASE('oyster_filtration_rate')
        id_oysDEB_filtrate=id
     CASE('total_weigth')
        id_oysDEB_Wtot=id
     CASE('oyster_stress_indice')
        id_oysDEB_Istress=id
     CASE('oyster_total_length')
        id_oysDEB_Lgtot=id
     CASE('chloro_carbone_ratio')
        id_oysDEB_ChlC=id
 !    CASE('oyster_dry_weigth2')
 !       id_oysDEB_DWtot2=id
 !    CASE('total_weigth2')
!        id_oysDEB_Wtot2=id
!     CASE('oyster_total_length2')
!        id_oysDEB_Lgtot2=id
!     CASE('oyster_dry_weigth3')
!        id_oysDEB_DWtot3=id
!     CASE('total_weigth3')
!        id_oysDEB_Wtot3=id
!     CASE('oyster_total_length3')
!        id_oysDEB_Lgtot3=id
     CASE('number_oyster_co1')
        id_oysDEB_nbhuit=id
!     CASE('number_oyster_co2')
!        id_oysDEB_nbhuit2=id
#endif
#if defined key_microtracers
     CASE('maximum_microtraceur_1_mass_concentration_in_sea_water')
       id_tracer_maxdepth1 = id
     CASE('mean_microtraceur_1_mass_concentration_in_sea_water')
       id_tracer_meandepth1 = id
     CASE('age_of_microtraceur_1_mass_concentration_in_sea_water')
       id_tracer_agedepth1 = id       
     CASE('maximum_microtraceur_2_mass_concentration_in_sea_water')
       id_tracer_maxdepth2 = id
     CASE('mean_microtraceur_2_mass_concentration_in_sea_water')
       id_tracer_meandepth2 = id
     CASE('age_of_microtraceur_2_mass_concentration_in_sea_water')
       id_tracer_agedepth2 = id              
     CASE('maximum_microtraceur_3_mass_concentration_in_sea_water')
       id_tracer_maxdepth3 = id
     CASE('mean_microtraceur_3_mass_concentration_in_sea_water')
       id_tracer_meandepth3 = id
     CASE('age_of_microtraceur_3_mass_concentration_in_sea_water')
       id_tracer_agedepth3 = id              
#endif     
     CASE DEFAULT
#if ! defined key_N_tracer && ! defined key_P_tracer
       IF_MPI (MASTER) THEN
             write(iscreenlog,*) 'Invalid standard name of diagnostic variable : ', &
                                             TRIM(ADJUSTL(ADJUSTR(standname)))
       ENDIF_MPI
#endif     
   END SELECT

   ! smallest and largest indexes
   IF (id >= idmax) idmax=id
   IF (id <= idmin) idmin=id


   IF ( id==ndiag_tot) THEN
   IF_MPI (MASTER) THEN
     WRITE(iscreenlog,*) ' '
     WRITE(iscreenlog,*) '********************************'
     WRITE(iscreenlog,*) '          BIOLO_INIT_ID         '
     WRITE(iscreenlog,*) ' Initialization of id_variables '
     WRITE(iscreenlog,*) '********************************'
     WRITE(iscreenlog,*) ' '
     WRITE(iscreenlog,*) 'id_diat_max = ',id_diat_max
     WRITE(iscreenlog,*) 'id_diat_datemax = ',id_diat_datemax
     WRITE(iscreenlog,*) 'id_diat_depthmax = ',id_diat_depthmax
     WRITE(iscreenlog,*) 'id_dino_max = ',id_dino_max
     WRITE(iscreenlog,*) 'id_dino_datemax = ',id_dino_datemax
     WRITE(iscreenlog,*) 'id_dino_depthmax = ',id_dino_depthmax
     WRITE(iscreenlog,*) 'id_nano_max = ',id_nano_max
     WRITE(iscreenlog,*) 'id_nano_datemax = ',id_nano_datemax
     WRITE(iscreenlog,*) 'id_nano_depthmax = ',id_nano_depthmax
     WRITE(iscreenlog,*) 'id_gradsali_max = ',id_gradsali_max
     WRITE(iscreenlog,*) 'id_gradsali_depthmax = ',id_gradsali_depthmax
     WRITE(iscreenlog,*) 'id_gradtemp_max = ',id_gradtemp_max
     WRITE(iscreenlog,*) 'id_gradtemp_depthmax = ',id_gradtemp_depthmax
#if defined key_biolo_opt2
     WRITE(iscreenlog,*) 'id_spim_satused = ',id_spim_satused
#endif
     WRITE(iscreenlog,*) 'id_diat_limlight = ',id_diat_limlight
     WRITE(iscreenlog,*) 'id_diat_limN = ',id_diat_limN
     WRITE(iscreenlog,*) 'id_diat_limSi = ',id_diat_limSi
     WRITE(iscreenlog,*) 'id_diat_limP = ',id_diat_limP
     WRITE(iscreenlog,*) 'id_dino_limlight = ',id_dino_limlight
     WRITE(iscreenlog,*) 'id_dino_limN = ',id_dino_limN
     WRITE(iscreenlog,*) 'id_dino_limP = ',id_dino_limP
     WRITE(iscreenlog,*) 'id_nano_limlight = ',id_nano_limlight
     WRITE(iscreenlog,*) 'id_nano_limN = ',id_nano_limN
     WRITE(iscreenlog,*) 'id_nano_limP = ',id_nano_limP
     WRITE(iscreenlog,*) 'id_extinctioncoeff = ',id_extinctioncoeff
     WRITE(iscreenlog,*) 'id_diat_columnprod = ',id_diat_columnprod
     WRITE(iscreenlog,*) 'id_dino_columnprod = ',id_dino_columnprod
     WRITE(iscreenlog,*) 'id_nano_columnprod = ',id_nano_columnprod
     WRITE(iscreenlog,*) 'id_totalchl = ',id_totalchl
     WRITE(iscreenlog,*) 'id_columnprodtotal = ',id_columnprodtotal
     WRITE(iscreenlog,*) 'id_diatsettling = ',id_diatsettling
     WRITE(iscreenlog,*) 'id_detsettling = ',id_detsettling
     WRITE(iscreenlog,*) 'id_spm_total = ',id_spm_total
     WRITE(iscreenlog,*) 'id_benthos_txf=' ,id_benthos_txf
#if defined key_psnz
     WRITE(iscreenlog,*) 'id_psnz_max = ',id_psnz_max
     WRITE(iscreenlog,*) 'id_psnz_datemax = ',id_psnz_datemax
     WRITE(iscreenlog,*) 'id_psnz_depthmax = ',id_psnz_depthmax
     WRITE(iscreenlog,*) 'id_psnz_limlight = ',id_psnz_limlight
     WRITE(iscreenlog,*) 'id_psnz_limN = ',id_psnz_limN
     WRITE(iscreenlog,*) 'id_psnz_limP = ',id_psnz_limP
     WRITE(iscreenlog,*) 'id_psnz_limSi = ',id_psnz_limSi
     WRITE(iscreenlog,*) 'id_psnz_columnprod = ',id_psnz_columnprod
#endif
#if defined key_karenia
     WRITE(iscreenlog,*) 'id_karenia_max = ',id_karenia_max
     WRITE(iscreenlog,*) 'id_karenia_datemax = ',id_karenia_datemax
     WRITE(iscreenlog,*) 'id_karenia_depthmax = ',id_karenia_depthmax
     WRITE(iscreenlog,*) 'id_karenia_limlight = ',id_karenia_limlight
     WRITE(iscreenlog,*) 'id_karenia_limN = ',id_karenia_limN
     WRITE(iscreenlog,*) 'id_karenia_limP = ',id_karenia_limP
     WRITE(iscreenlog,*) 'id_karenia_columnprod = ',id_karenia_columnprod
#endif
#if defined key_phaeocystis
     WRITE(iscreenlog,*) 'id_phaeocystis_max = ',id_phaeocystis_max
     WRITE(iscreenlog,*) 'id_phaeocystis_datemax = ',id_phaeocystis_datemax
     WRITE(iscreenlog,*) 'id_phaeocystis_depthmax = ',id_phaeocystis_depthmax
     WRITE(iscreenlog,*) 'id_phaeocystis_limlight = ',id_phaeocystis_limlight
     WRITE(iscreenlog,*) 'id_phaeocystis_limN = ',id_phaeocystis_limN
     WRITE(iscreenlog,*) 'id_phaeocystis_limP = ',id_phaeocystis_limP
     WRITE(iscreenlog,*) 'id_phaeocystis_columnprod = ',id_phaeocystis_columnprod
#endif
#if defined key_zoo_prod
     WRITE(iscreenlog,*) 'id_zoo_micr_columnprod = ',id_zoo_micr_columnprod
     WRITE(iscreenlog,*) 'id_zoo_meso_columnprod = ',id_zoo_meso_columnprod
     WRITE(iscreenlog,*) 'id_zoo_columnprodtotal = ',id_zoo_columnprodtotal
#endif
#ifdef key_ulvas
     WRITE(iscreenlog,*) 'id_ulv_ratiosus=',id_ulv_ratiosus
     WRITE(iscreenlog,*) 'id_ulv_susmort=',id_ulv_susmort
     WRITE(iscreenlog,*) 'id_ulv_suslimlight=',id_ulv_suslimlight
     WRITE(iscreenlog,*) 'id_ulv_suslimN=',id_ulv_suslimN
     WRITE(iscreenlog,*) 'id_ulv_suslimP=',id_ulv_suslimP
     WRITE(iscreenlog,*) 'id_ulv_suspumpN=',id_ulv_suspumpN
     WRITE(iscreenlog,*) 'id_ulv_suspumpP=',id_ulv_suspumpP
     WRITE(iscreenlog,*) 'id_ulv_settling=',id_ulv_settling
     WRITE(iscreenlog,*) 'id_ulv_ratiobenth=',id_ulv_ratiobenth
     WRITE(iscreenlog,*) 'id_ulv_benthmort=',id_ulv_benthmort
     WRITE(iscreenlog,*) 'id_ulv_benthlimlight=',id_ulv_benthlimlight
     WRITE(iscreenlog,*) 'id_ulv_benthlimN=',id_ulv_benthlimN
     WRITE(iscreenlog,*) 'id_ulv_benthlimP=',id_ulv_benthlimP
     WRITE(iscreenlog,*) 'id_ulv_benthpumpN=',id_ulv_benthpumpN
     WRITE(iscreenlog,*) 'id_ulv_benthpumpP=',id_ulv_benthpumpP
     WRITE(iscreenlog,*) 'id_ulv_resusbil=',id_ulv_resusbil
     WRITE(iscreenlog,*) 'id_ulv_resusN=', id_ulv_resusN   
     WRITE(iscreenlog,*) 'id_ulv_resusP=',id_ulv_resusP  
#endif
#ifdef key_zostera
!     WRITE(iscreenlog,*) 'id_zost_LBDW  = ',id_zost_LBDW
!     WRITE(iscreenlog,*) 'id_zost_RBDW  = ',id_zost_RBDW
     WRITE(iscreenlog,*) 'id_zost_Qcan  = ',id_zost_Qcan
     WRITE(iscreenlog,*) 'id_zost_LAI  = ',id_zost_LAI
     WRITE(iscreenlog,*) 'id_zost_limlum  = ',id_zost_limlum
     WRITE(iscreenlog,*) 'id_zost_limprodLN  = ',id_zost_limprodLN
     WRITE(iscreenlog,*) 'id_zost_limprodLP  = ',id_zost_limprodLP
     WRITE(iscreenlog,*) 'id_zost_limRN  = ',id_zost_limRN
     WRITE(iscreenlog,*) 'id_zost_limRP  = ',id_zost_limRP
!     WRITE(iscreenlog,*) 'id_zost_effetchaleurzprod  = ',id_zost_effetchaleurzprod
!     WRITE(iscreenlog,*) 'id_zost_effetchaleurzrespf  = ',id_zost_effetchaleurzrespf
!     WRITE(iscreenlog,*) 'id_zost_effetchaleurzrespr  = ',id_zost_effetchaleurzrespr
!     WRITE(iscreenlog,*) 'id_zost_limabsLnh4  = ',id_zost_limabsLnh4
!     WRITE(iscreenlog,*) 'id_zost_limabsLno3  = ',id_zost_limabsLno3
!     WRITE(iscreenlog,*) 'id_zost_limabsLpo4  = ',id_zost_limabsLpo4
!     WRITE(iscreenlog,*) 'id_zost_limabsRnh4  = ',id_zost_limabsRnh4
!     WRITE(iscreenlog,*) 'id_zost_limabsRpo4  = ',id_zost_limabsRpo4
     WRITE(iscreenlog,*) 'id_zost_limselfshad  = ',id_zost_limselfshad
     WRITE(iscreenlog,*) 'id_zost_limRB  = ',id_zost_limRB
!     WRITE(iscreenlog,*) 'id_zost_effetvent  = ',id_zost_effetvent
!     WRITE(iscreenlog,*) 'id_zost_Sgerm  = ',id_zost_Sgerm
!     WRITE(iscreenlog,*) 'id_zost_ERS  = ',id_zost_ERS
     WRITE(iscreenlog,*) 'id_zost_prod  = ',id_zost_prod
#endif
#ifdef key_oyster_SFG
     WRITE(iscreenlog,*) 'id_oys_tcoq=',id_oys_tcoq
     WRITE(iscreenlog,*) 'id_oys_tgam=',id_oys_tgam
     WRITE(iscreenlog,*) 'id_oys_gaincoq=',id_oys_gaincoq
     WRITE(iscreenlog,*) 'id_oys_gainsoma=',id_oys_gainsoma
     WRITE(iscreenlog,*) 'id_oys_gainrepr=',id_oys_gainrepr
     WRITE(iscreenlog,*) 'id_oys_orgafring=',id_oys_orgafring
     WRITE(iscreenlog,*) 'id_oys_bilansoma=',id_oys_bilansoma
     WRITE(iscreenlog,*) 'id_oys_bilancoq=',id_oys_bilancoq
     WRITE(iscreenlog,*) 'id_oys_filt=',id_oys_filt
     WRITE(iscreenlog,*) 'id_oys_resp=',id_oys_resp
     WRITE(iscreenlog,*) 'id_oys_gameto=',id_oys_gameto
     WRITE(iscreenlog,*) 'id_oys_seuilponte=',id_oys_seuilponte
     WRITE(iscreenlog,*) 'id_oys_reposcoq=',id_oys_reposcoq
     WRITE(iscreenlog,*) 'id_oys_reposgam=',id_oys_reposgam
     WRITE(iscreenlog,*) 'id_oys_ponte=',id_oys_ponte
     WRITE(iscreenlog,*) 'id_oys_absorg=',id_oys_absorg                
#endif
#if defined key_oyster_DEB
     WRITE(iscreenlog,*) 'id_oysDEB_FRpop=' ,id_oysDEB_FRpop
     WRITE(iscreenlog,*) 'id_oysDEB_PFpop=', id_oysDEB_PFpop
     WRITE(iscreenlog,*) 'id_oysDEB_Fpop=',id_oysDEB_Fpop
     WRITE(iscreenlog,*) 'id_oysDEB_DWtot=',id_oysDEB_DWtot
     WRITE(iscreenlog,*) 'id_oysDEB_kchlvble=',id_oysDEB_kchlvble
     WRITE(iscreenlog,*) 'id_oysDEB_ER=',id_oysDEB_ER
     WRITE(iscreenlog,*) 'id_oysDEB_filtrate=',id_oysDEB_filtrate
     WRITE(iscreenlog,*) 'id_oysDEB_Wtot=',id_oysDEB_Wtot
     WRITE(iscreenlog,*) 'id_oysDEB_Istress=',id_oysDEB_Istress
     WRITE(iscreenlog,*) 'id_oysDEB_Lgtot=',id_oysDEB_Lgtot
     WRITE(iscreenlog,*) 'id_oysDEB_ChlC=',id_oysDEB_ChlC
!     WRITE(iscreenlog,*) 'id_oysDEB_DWtot2=',id_oysDEB_DWtot2
!     WRITE(iscreenlog,*) 'id_oysDEB_Wtot2=',id_oysDEB_Wtot2
!     WRITE(iscreenlog,*) 'id_oysDEB_Lgtot2=',id_oysDEB_Lgtot2
!     WRITE(iscreenlog,*) 'id_oysDEB_DWtot3=',id_oysDEB_DWtot3
!     WRITE(iscreenlog,*) 'id_oysDEB_Wtot3=',id_oysDEB_Wtot3
!     WRITE(iscreenlog,*) 'id_oysDEB_Lgtot3=',id_oysDEB_Lgtot3
     WRITE(iscreenlog,*) 'id_oysDEB_nbhuit=',id_oysDEB_nbhuit
!     WRITE(iscreenlog,*) 'id_oysDEB_nbhuit2=',id_oysDEB_nbhuit2
#endif
#ifdef key_oxygen
    WRITE(iscreenlog,*) 'id_oxy_sat=',id_oxy_sat
#endif
#if defined key_microtracers
     WRITE(iscreenlog,*) 'id_tracer_maxdepth1 = ',id_tracer_maxdepth1
     WRITE(iscreenlog,*) 'id_tracer_meandepth1 = ',id_tracer_meandepth1
     WRITE(iscreenlog,*) 'id_tracer_agedepth1 = ',id_tracer_agedepth1
     WRITE(iscreenlog,*) 'id_tracer_maxdepth2 = ',id_tracer_maxdepth2
     WRITE(iscreenlog,*) 'id_tracer_meandepth2 = ',id_tracer_meandepth2
     WRITE(iscreenlog,*) 'id_tracer_agedepth2 = ',id_tracer_agedepth2
     WRITE(iscreenlog,*) 'id_tracer_maxdepth3 = ',id_tracer_maxdepth3
     WRITE(iscreenlog,*) 'id_tracer_meandepth3 = ',id_tracer_meandepth3
     WRITE(iscreenlog,*) 'id_tracer_agedepth3 = ',id_tracer_agedepth3
#endif
#if defined key_N_tracer
       DO is=1,nb_source_tracerN
         DO ivtra=1,nb_var_tracerN 
          WRITE(iscreenlog,*) 'tracer_N source ',is,' : ',id_tracer_signN(ivtra,is) ,' : ',  &
                               TRIM(ADJUSTL(ADJUSTR(name_vardiag(id_tracer_signN(ivtra,is)))))
#if defined key_age_tracer
          WRITE(iscreenlog,*) 'age_N source ',is,' : ',id_tracer_ageN(ivtra,is) ,' : ',  &
                               TRIM(ADJUSTL(ADJUSTR(name_vardiag(id_tracer_ageN(ivtra,is)))))
#endif
         ENDDO
#if defined key_age_tracer
         idiag=id_tracer_signN(nb_var_tracerN,is)+2
#else
         idiag=id_tracer_signN(nb_var_tracerN,is)+1
#endif

#if defined key_age_tracer
          WRITE(iscreenlog,*) 'tracer_N source ',is,' : ',idiag ,' : ',TRIM(ADJUSTL(ADJUSTR(name_vardiag(id-1))))
          idiag=idiag+1
          WRITE(iscreenlog,*) 'age_N source ',is,' : ',idiag ,' : ',TRIM(ADJUSTL(ADJUSTR(name_vardiag(id))))
#else
         WRITE(iscreenlog,*) 'tracer_N source ',is,' : ',idiag ,' : ',TRIM(ADJUSTL(ADJUSTR(name_vardiag(id))))
#endif      
      ENDDO
#endif
#if defined key_P_tracer
       DO is=1,nb_source_tracerP
         WRITE(iscreenlog,*) 'tracer_P source ',is
         DO ivtra=1,nb_var_tracerP 
          WRITE(iscreenlog,*) id_tracer_signP(ivtra,is) ,' : ',TRIM(ADJUSTL(ADJUSTR(name_vardiag(id_tracer_signP(ivtra,is)))))
#if defined key_age_tracer
          WRITE(iscreenlog,*) id_tracer_ageP(ivtra,is) ,' : ',TRIM(ADJUSTL(ADJUSTR(name_vardiag(id_tracer_ageP(ivtra,is)))))
#endif
         ENDDO
#if defined key_age_tracer
         idiag=id_tracer_signP(nb_var_tracerP,is)+2
#else
         idiag=id_tracer_signP(nb_var_tracerP,is)+1
#endif

#if defined key_age_tracer
          WRITE(iscreenlog,*) idiag ,' : ',TRIM(ADJUSTL(ADJUSTR(name_vardiag(id-1))))
          idiag=idiag+1
          WRITE(iscreenlog,*) idiag ,' : ',TRIM(ADJUSTL(ADJUSTR(name_vardiag(id))))
#else
         WRITE(iscreenlog,*) idiag ,' : ',TRIM(ADJUSTL(ADJUSTR(name_vardiag(id))))
#endif      
      ENDDO
#endif

     WRITE(iscreenlog,*) ' '
     WRITE(iscreenlog,*) '********************************'
     WRITE(iscreenlog,*) ' '

#if ! defined key_sedim_MUSTANG && ! defined key_conta
     sumverif = id_diat_max + id_diat_datemax + id_diat_depthmax + &
              id_dino_max + id_dino_datemax + id_dino_depthmax + &
              id_nano_max + id_nano_datemax + id_nano_depthmax + &
              id_gradsali_max + id_gradsali_depthmax +           &
              id_gradtemp_max + id_gradtemp_depthmax  + &
#if defined key_biolo_opt2
              id_spim_satused + &
#endif
              id_diat_limlight + id_diat_limN + id_diat_limSi + id_diat_limP + &
              id_dino_limlight + id_dino_limN + id_dino_limP +   &
              id_nano_limlight + id_nano_limN + id_nano_limP +   &
              id_extinctioncoeff + id_diat_columnprod +          &
              id_dino_columnprod + id_nano_columnprod +          &
              id_benthos_txf + &
#if defined key_oyster_DEB
              id_oysDEB_FRpop+ id_oysDEB_PFpop+id_oysDEB_Fpop + &
              id_oysDEB_DWtot+id_oysDEB_kchlvble+id_oysDEB_ER+ &
              id_oysDEB_filtrate+id_oysDEB_Wtot+id_oysDEB_Istress+ &
              id_oysDEB_Lgtot + id_oysDEB_ChlC + &
!              id_oysDEB_DWtot2+id_oysDEB_Wtot2+id_oysDEB_Lgtot2 + &
!              id_oysDEB_DWtot3+id_oysDEB_Wtot3+id_oysDEB_Lgtot3 + &
!              id_oysDEB_nbhuit2 + &
              id_oysDEB_nbhuit  + &
#endif

#if defined key_psnz
              id_psnz_max + id_psnz_datemax + id_psnz_depthmax + &
              id_psnz_limlight + id_psnz_limN + id_psnz_limP + id_psnz_limSi + id_psnz_columnprod + id_psnz_proddomoic + &
#endif
#if defined key_karenia
              id_karenia_max + id_karenia_datemax + id_karenia_depthmax + &
              id_karenia_limlight + id_karenia_limN + id_karenia_limP + id_karenia_columnprod + &
#endif
#if defined key_phaeocystis
              id_phaeocystis_max + id_phaeocystis_datemax + id_phaeocystis_depthmax + &
              id_phaeocystis_limlight + id_phaeocystis_limN + id_phaeocystis_limP + id_phaeocystis_columnprod + &
#endif
#ifdef key_zoo_prod
              id_zoo_micr_columnprod + id_zoo_meso_columnprod + id_zoo_columnprodtotal + &      
#endif
#ifdef key_zostera
              id_zost_Qcan + id_zost_LAI + id_zost_limlum + id_zost_limprodLN + id_zost_limprodLP + &
              id_zost_limRN + id_zost_limRP + id_zost_limselfshad + id_zost_limRB + id_zost_prod + &
!              id_zost_LBDW + id_zost_RBDW + id_zost_effetchaleurzprod + id_zost_effetchaleurzrespf + &
!              id_zost_effetchaleurzrespr + id_zost_limabsLnh4 + id_zost_limabsLno3 + id_zost_limabsLpo4 + &
!              id_zost_limabsRnh4 + id_zost_limabsRpo4 + id_zost_effetvent + id_zost_Sgerm + id_zost_ERS + &
#endif
#ifdef key_ulvas
              id_ulv_ratiosus+id_ulv_susmort+id_ulv_suslimlight+  &
              id_ulv_suslimN+id_ulv_suslimP+id_ulv_suspumpN+id_ulv_suspumpP+  &
              id_ulv_settling+id_ulv_ratiobenth+id_ulv_benthmort+  &
              id_ulv_benthlimlight+id_ulv_benthlimN+id_ulv_benthlimP+   &
              id_ulv_benthpumpN+id_ulv_benthpumpP+id_ulv_resusbil+   &
              id_ulv_resusN+id_ulv_resusP + &
#endif
#ifdef key_oyster_SFG 
              id_oys_tcoq+id_oys_tgam+id_oys_gaincoq+id_oys_gainsoma + &
              id_oys_gainrepr+id_oys_orgafring+id_oys_bilansoma+id_oys_bilancoq + &
              id_oys_filt+id_oys_resp+id_oys_gameto+id_oys_seuilponte+id_oys_reposcoq + &
              id_oys_reposgam+id_oys_ponte+id_oys_absorg + &               
#endif
#ifdef key_oxygen 
              id_oxy_sat  + &              
#endif
#if defined key_microtracers
              id_tracer_maxdepth1 + id_tracer_meandepth1 + id_tracer_agedepth1 + &
              id_tracer_maxdepth2 + id_tracer_meandepth2 + id_tracer_agedepth2 + &
              id_tracer_maxdepth3 + id_tracer_meandepth3 + id_tracer_agedepth3 + &
#endif
              id_totalchl + id_columnprodtotal + id_spm_total +  &
              id_diatsettling + id_detsettling

#if defined key_N_tracer
       DO is=1,nb_source_tracerN
         DO ivtra=1,nb_var_tracerN 
          sumverif = sumverif + id_tracer_signN(ivtra,is)
#if defined key_age_tracer
          sumverif = sumverif + id_tracer_ageN(ivtra,is) 
#endif
         ENDDO
#if defined key_age_tracer
         sumverif=sumverif+id_tracer_signN(nb_var_tracerN,is)+2+id_tracer_signN(nb_var_tracerN,is)+3
#else
         sumverif=sumverif+id_tracer_signN(nb_var_tracerN,is)+1
#endif
       ENDDO
#endif
#if defined key_P_tracer
       DO is=1,nb_source_tracerP
         DO ivtra=1,nb_var_tracerP 
          sumverif = sumverif + id_tracer_signP(ivtra,is)
#if defined key_age_tracer
          sumverif = sumverif + id_tracer_ageP(ivtra,is) 
#endif
         ENDDO
#if defined key_age_tracer
         sumverif=sumverif+id_tracer_signP(nb_var_tracerP,is)+2+id_tracer_signP(nb_var_tracerP,is)+3
#else
         sumverif=sumverif+id_tracer_signP(nb_var_tracerP,is)+1
#endif
       ENDDO
#endif
     IF ( sumverif /= sumindex(idmin,idmax) ) THEN
       write(ierrorlog,*)' '
       write(ierrorlog,*)'BIOLO_INIT_ID'
       write(ierrorlog,*)'the initialization of indexes of diagnostic variables'
       write(ierrorlog,*)'is not correct'
       write(ierrorlog,*)'Rank min=',idmin,'Rank max=',idmax,'sumindex(idmin,idmax)=',sumindex(idmin,idmax)
       write(ierrorlog,*)'sumverif=',sumverif
       write(ierrorlog,*)'Have a look at simu.log and vardiag.dat files'
       write(ierrorlog,*)'and inquire into the mistakes'
       write(ierrorlog,*)' '
       write(ierrorlog,*)'The simulation is stopped'
       STOP
     END IF
#endif
   ENDIF_MPI
   END IF   ! ends test on ndiag_tot

  END SUBROUTINE biolo_init_id

   !!======================================================================
#if defined key_N_tracer || defined key_P_tracer
  SUBROUTINE biolo_create_vartracer(tocd_r,t90_r,flx_atm_r,cv_rain_r,cini_wat_r,cini_air_r, &
                                    l_out_subs_r,init_cv_name_r,obc_cv_name_r,              &
                                    ws_free_opt_r,ws_free_min_r,ws_free_max_r,              &
                                    ws_free_para_r,ws_hind_opt_r,ws_hind_para_r)

   !&E---------------------------------------------------------------------
   !&E                 ***  ROUTINE biolo_create_vartracer ***
   !&E
   !&E ** Purpose : create variables tracer 
   !&E
   !&E ** Description :
   !&E
   !&E ** Called by : sub_read_var
   !&E
   !&E ** External calls :
   !&E
   !&E ** Reference :
   !&E
   !&E ** History :
   !&E       !  2009-10  (V. Garnier)  Original code
   !&E
   !&E---------------------------------------------------------------------
   !! * Modules used
   USE comsubstance
   USE comvars2d, ONLY : iscreenlog,ierrorlog

   !! * Arguments
   REAL(KIND=rsh), DIMENSION(nb_var),INTENT(inout)         :: tocd_r,t90_r,flx_atm_r
   REAL(KIND=rsh), DIMENSION(nb_var),INTENT(inout)         :: cini_wat_r,cv_rain_r,cini_air_r
   CHARACTER(LEN=lchain), DIMENSION(nb_var),INTENT(inout)  :: obc_cv_name_r,init_cv_name_r
   LOGICAL, DIMENSION(nb_var),INTENT(inout)                :: l_out_subs_r
   REAL(KIND=rsh), DIMENSION(4,nb_var),intent(inout)       :: ws_free_para_r
   REAL(KIND=rsh), DIMENSION(nb_var),intent(inout)         :: ws_free_min_r,ws_free_max_r
   REAL(KIND=rsh), DIMENSION(2,nb_var),intent(inout)       :: ws_hind_para_r
   INTEGER       , DIMENSION(nb_var),intent(inout)         :: ws_hind_opt_r,ws_free_opt_r


   !! * Local declarations
    INTEGER                  :: nn,eof,ind_white,is,js,ks,ivtra,ii,nb_var_tracer,IERR_MPI
    INTEGER                  :: iss,isubs,isubs_age,iv,ivv
    CHARACTER(LEN=5)         :: comment
    CHARACTER(LEN=lchain), DIMENSION(nb_var) :: name_var_tracer
    CHARACTER(LEN=lchain)    :: name_ss
    LOGICAL                  :: ex
#if defined key_P_tracer
    CHARACTER(LEN=lchain)    :: name_varP,name_varP2
    INTEGER                  :: lenname,pos
#endif
   !!----------------------------------------------------------------------
   !! * Executable part
     nb_var_tracer=0
#if defined key_N_tracer
! definiton des variables a tracer pour l azote (8 dans le modele de base)
     nb_var_tracer=nb_var_tracer+8
     name_var_tracer(1)='ammonium'
     name_var_tracer(2)='nitrate'
     name_var_tracer(3)='nanopicoplankton_nitrogen'
     name_var_tracer(4)='diatom_nitrogen'
     name_var_tracer(5)='dinoflagellate_nitrogen'
     name_var_tracer(6)='microzooplankton_nitrogen'
     name_var_tracer(7)='mesozooplankton_nitrogen'
     name_var_tracer(8)='detrital_nitrogen'
     
#if defined key_psnz
     nb_var_tracer=nb_var_tracer+1
     name_var_tracer(nb_var_tracer)='pseudonitzschia_nitrogen'
#endif
#if defined key_karenia
     nb_var_tracer=nb_var_tracer+1
     name_var_tracer(nb_var_tracer)='karenia_nitrogen'
#endif
#if defined key_phaeocystis
     name_var_tracer(nb_var_tracer+1)='colonial_phaeocystis_nitrogen'
     name_var_tracer(nb_var_tracer+2)='phaeocystis_cells_nitrogen'
     nb_var_tracer=nb_var_tracer+2
#endif
#if defined key_benthos
     nb_var_tracer=nb_var_tracer+1
     name_var_tracer(nb_var_tracer)='organic_nitrogen_benth'
#endif
#if defined key_ulvas
!!!!!!! ATTENTION VERIFIER LES NOMS !!!!!!!!!!!!!!!!!
     name_var_tracer(nb_var_tracer+1)='ulves_susp'
     name_var_tracer(nb_var_tracer+2)='ulves_benth'
     nb_var_tracer=nb_var_tracer+2
#endif
#endif
#if defined key_P_tracer
! definiton des variables a tracer pour le phosphore (8 dans le modele de base)

     name_var_tracer(nb_var_tracer+1)='dissolved_phosphate'
     name_var_tracer(nb_var_tracer+2)='sorbed_phosphate'
     name_var_tracer(nb_var_tracer+3)='nanopicoplankton_nitrogen'
     name_var_tracer(nb_var_tracer+4)='diatom_nitrogen'
     name_var_tracer(nb_var_tracer+5)='dinoflagellate_nitrogen'
     name_var_tracer(nb_var_tracer+6)='microzooplankton_nitrogen'
     name_var_tracer(nb_var_tracer+7)='mesozooplankton_nitrogen'
     name_var_tracer(nb_var_tracer+8)='detrital_phosphorus'
     nb_var_tracer=nb_var_tracer+8
#if defined key_psnz
     nb_var_tracer=nb_var_tracer+1
     name_var_tracer(nb_var_tracer)='pseudonitzschia_phosphorus'
#endif
#if defined key_karenia
     nb_var_tracer=nb_var_tracer+1
     name_var_tracer(nb_var_tracer)='karenia_phosphorus'
#endif
#if defined key_phaeocystis
     name_var_tracer(nb_var_tracer+1)='colonial_phaeocystis_phosphorus'
     name_var_tracer(nb_var_tracer+2)='phaeocystis_cells_phosphorus'
     nb_var_tracer=nb_var_tracer+2
#endif
#if defined key_benthos
     nb_var_tracer=nb_var_tracer+1
     name_var_tracer(nb_var_tracer)='detrital_phosphorus_benth'
#endif
#endif

     call biolo_alloc_vartracer
     
     isubs=nv_tot
#if defined key_N_tracer
     DO is=1,nb_source_tracerN
      name_ss=name_source_tracerN(is)
      name_ss=name_ss(1:5)
       DO ivtra=1,nb_var_tracerN
        DO iv=1,nv_tot
         IF(TRIM(ADJUSTL(ADJUSTR(name_var(iv)))) == name_var_tracer(ivtra)) THEN
            isubs_signed_N(ivtra,is)=iv
            isubs=isubs+1
            isubs_tracer_N(ivtra,is)=isubs
#if defined key_age_tracer
            isubs_age=isubs+1
            isubs_age_N(ivtra,is)=isubs_age
            name_var(isubs_age)=TRIM(ADJUSTL(ADJUSTR(name_var(iv))))//TRIM(ADJUSTL(ADJUSTR(name_ss)))//'_age'
            long_name_var(isubs_age)=TRIM(ADJUSTL(ADJUSTR(long_name_var(iv))))//TRIM(ADJUSTL(ADJUSTR(name_ss)))//'_age'
            standard_name_var(isubs_age)=TRIM(ADJUSTL(ADJUSTR(standard_name_var(iv))))//TRIM(ADJUSTL(ADJUSTR(name_ss)))//'_age'
            unit_var(isubs_age)='days'
            valid_min_var(isubs_age)=0.0_rsh
            valid_max_var(isubs_age)=1000.0_rsh

#else
            isubs_age=isubs
#endif
            name_var(isubs)=TRIM(ADJUSTL(ADJUSTR(name_var(iv))))//TRIM(ADJUSTL(ADJUSTR(name_ss)))//'_tracer'
            long_name_var(isubs)=TRIM(ADJUSTL(ADJUSTR(long_name_var(iv))))//TRIM(ADJUSTL(ADJUSTR(name_ss)))//'_tracer'
            standard_name_var(isubs)=TRIM(ADJUSTL(ADJUSTR(standard_name_var(iv))))//TRIM(ADJUSTL(ADJUSTR(name_ss)))//'_tracer'
            unit_var(isubs)=unit_var(iv)
            valid_min_var(isubs)=valid_min_var(iv)
            valid_max_var(isubs)=valid_max_var(iv)
            itypv_r(isubs:isubs_age)=itypv_r(iv)
            IF (itypv_r(iv)< 5) THEN
               ws_free_min_r(isubs:isubs_age)=ws_free_min_r(iv)
               ws_free_max_r(isubs:isubs_age)=ws_free_max_r(iv)
               DO ivv=isubs,isubs_age
                 ws_free_para_r(:,ivv)=ws_free_para_r(:,iv)
                 ws_hind_para_r(:,ivv)=ws_hind_para_r(:,iv)
               ENDDO
               ws_free_opt_r(isubs:isubs_age)=ws_free_opt_r(iv)
               ws_hind_opt_r(isubs:isubs_age)=ws_hind_opt_r(iv)
               tocd_r(isubs:isubs_age)= tocd_r(iv)     
               ros_r(isubs:isubs_age)= ros_r(iv)      
               diam_r(isubs:isubs_age)=diam_r(iv)
            ELSE IF(itypv_r(iv)== 5) THEN
               name_varpc_assoc(isubs:isubs_age)= name_varpc_assoc(iv)
            END IF 
            t90_r(isubs:isubs_age)=0.0_rsh
            flx_atm_r(isubs:isubs_age)=0.0_rsh
            cv_rain_r(isubs:isubs_age)=0.0_rsh
            cini_wat_r(isubs:isubs_age)=0.0_rsh
            cini_sed_r(isubs:isubs_age)=0.0_rsh
            cini_air_r(isubs:isubs_age)=0.0_rsh
            l_out_subs_r(isubs:isubs_age)=.false.
            init_cv_name_r(isubs:isubs_age)='none'
            obc_cv_name_r(isubs:isubs_age)='none'
            IF (itypv_r(isubs)==1) THEN
             nv_grav=nv_grav+1+(isubs_age-isubs)
            ELSE IF (itypv_r(isubs)==2) THEN
             nv_sand=nv_sand+1+(isubs_age-isubs)
            ELSE IF (itypv_r(isubs)==3) THEN
             nv_mud=nv_mud+1+(isubs_age-isubs)
             nv_cp=nv_cp+1+(isubs_age-isubs)
            ELSE IF (itypv_r(isubs)==4 ) THEN
             nv_ncp=nv_ncp+1+(isubs_age-isubs)
            ELSE IF (itypv_r(isubs)==5) THEN
             nv_sorb=nv_sorb+1+(isubs_age-isubs)
            ELSE IF (itypv_r(isubs)==6) THEN
             nv_dis=nv_dis+1+(isubs_age-isubs)
            ELSE IF (itypv_r(isubs)==7) THEN
             nv_fix=nv_fix+1+(isubs_age-isubs)

            END IF
#if defined key_age_tracer
            isubs=isubs+1
#endif

!   definition des variables diagnostiques

            exit
         ENDIF
       ENDDO 
! definition des p_marque (seulement parmi les 8 variables nitrogen du modele de base)
       SELECT CASE( TRIM(ADJUSTL(ADJUSTR(name_var(isubs_signed_N(ivtra,is))))) )
         CASE ('ammonium') 
           p_marque_tracerN(ivtra,is)=p_marqueNH4
         CASE('nitrate') 
           p_marque_tracerN(ivtra,is)=p_marqueNO3 
         CASE('nanopicoplankton_nitrogen') 
           p_marque_tracerN(ivtra,is)=p_marquenanoN 
         CASE('diatom_nitrogen') 
           p_marque_tracerN(ivtra,is)=p_marquediatN 
         CASE('dinoflagellate_nitrogen') 
           p_marque_tracerN(ivtra,is)=p_marquedinoN 
         CASE('microzooplankton_nitrogen') 
           p_marque_tracerN(ivtra,is)=p_marquemicrN
         CASE('mesozooplankton_nitrogen') 
           p_marque_tracerN(ivtra,is)=p_marquemesoN 
         CASE('detrital_nitrogen') 
           p_marque_tracerN(ivtra,is)=p_marquedetN 
         CASE DEFAULT
           p_marque_tracerN(ivtra,is)=0
         END SELECT
 
      ENDDO
     ENDDO
#endif
#if defined key_P_tracer
     DO is=1,nb_source_tracerP
      name_ss=name_source_tracerP(is)
      name_ss=name_ss(1:5)
       DO ivtra=1,nb_var_tracerP
        DO iv=1,nv_tot
         IF(TRIM(ADJUSTL(ADJUSTR(name_var(iv)))) == name_var_tracer(ivtra)) THEN
            isubs_signed_P(ivtra,is)=iv
            isubs=isubs+1
            isubs_tracer_P(ivtra,is)=isubs
            name_varP=name_var(iv)
            pos=index(name_varP,"nitrogen")
            lenname=len(name_varP)
            IF (pos==0) then
              name_varP2=name_varP
            ELSE
              name_varP2=name_varP(1:pos-1)//'phosphorus'//name_varP(pos+8:lenname)
            ENDIF
#if defined key_age_tracer
            isubs_age=isubs+1
            isubs_age_P(ivtra,is)=isubs_age
            name_var(isubs_age)=TRIM(ADJUSTL(ADJUSTR(name_varP2)))//'_'//TRIM(ADJUSTL(ADJUSTR(name_ss)))//'_age'
            long_name_var(isubs_age)=TRIM(ADJUSTL(ADJUSTR(name_varP2)))//'_'//TRIM(ADJUSTL(ADJUSTR(name_ss)))//'_age'
            standard_name_var(isubs_age)=TRIM(ADJUSTL(ADJUSTR(name_varP2)))//'_'//TRIM(ADJUSTL(ADJUSTR(name_ss)))//'_age'
            unit_var(isubs_age)='days'
            valid_min_var(isubs_age)=0.0_rsh
            valid_max_var(isubs_age)=1000.0_rsh

#else
            isubs_age=isubs
#endif
            name_var(isubs)=TRIM(ADJUSTL(ADJUSTR(name_varP2)))//'_'//TRIM(ADJUSTL(ADJUSTR(name_ss)))//'_tracer'
            long_name_var(isubs)=TRIM(ADJUSTL(ADJUSTR(name_varP2)))//'_'//TRIM(ADJUSTL(ADJUSTR(name_ss)))//'_tracer'
            standard_name_var(isubs)=TRIM(ADJUSTL(ADJUSTR(name_varP2)))//'_'//TRIM(ADJUSTL(ADJUSTR(name_ss)))//'_tracer'
            unit_var(isubs)=unit_var(iv)
            valid_min_var(isubs)=valid_min_var(iv)
            valid_max_var(isubs)=valid_max_var(iv)
            itypv_r(isubs:isubs_age)=itypv_r(iv)
            IF (itypv_r(iv)< 5) THEN
               ws_free_min_r(isubs:isubs_age)=ws_free_min_r(iv)
               ws_free_max_r(isubs:isubs_age)=ws_free_max_r(iv)
               DO ivv=isubs,isubs_age
                 ws_free_para_r(:,ivv)=ws_free_para_r(:,iv)
                 ws_hind_para_r(:,ivv)=ws_hind_para_r(:,iv)
               ENDDO
               ws_free_opt_r(isubs:isubs_age)=ws_free_opt_r(iv)
               ws_hind_opt_r(isubs:isubs_age)=ws_hind_opt_r(iv)
               tocd_r(isubs:isubs_age)= tocd_r(iv)     
               ros_r(isubs:isubs_age)= ros_r(iv)      
               diam_r(isubs:isubs_age)=diam_r(iv)
            ELSE IF(itypv_r(iv)== 5) THEN
               name_varpc_assoc(isubs:isubs_age)= name_varpc_assoc(iv)
            END IF 
            t90_r(isubs:isubs_age)=0.0_rsh
            flx_atm_r(isubs:isubs_age)=0.0_rsh
            cv_rain_r(isubs:isubs_age)=0.0_rsh
            cini_wat_r(isubs:isubs_age)=0.0_rsh
            cini_sed_r(isubs:isubs_age)=0.0_rsh
            cini_air_r(isubs:isubs_age)=0.0_rsh
            l_out_subs_r(isubs:isubs_age)=.false.
            init_cv_name_r(isubs:isubs_age)='none'
            obc_cv_name_r(isubs:isubs_age)='none'
            IF (itypv_r(isubs)==1) THEN
             nv_grav=nv_grav+1+(isubs_age-isubs)
            ELSE IF (itypv_r(isubs)==2) THEN
             nv_sand=nv_sand+1+(isubs_age-isubs)
            ELSE IF (itypv_r(isubs)==3) THEN
             nv_mud=nv_mud+1+(isubs_age-isubs)
             nv_cp=nv_cp+1+(isubs_age-isubs)
            ELSE IF (itypv_r(isubs)==4 ) THEN
             nv_ncp=nv_ncp+1+(isubs_age-isubs)
            ELSE IF (itypv_r(isubs)==5) THEN
             nv_sorb=nv_sorb+1+(isubs_age-isubs)
            ELSE IF (itypv_r(isubs)==6) THEN
             nv_dis=nv_dis+1+(isubs_age-isubs)
            ELSE IF (itypv_r(isubs)==7) THEN
             nv_fix=nv_fix+1+(isubs_age-isubs)

            END IF
#if defined key_age_tracer
            isubs=isubs+1
#endif

!   definition des variables diagnostiques

            exit
         ENDIF
       ENDDO 
! definition des p_marque (seulement parmi les 3 variables phosphore du modele de base)
       SELECT CASE( TRIM(ADJUSTL(ADJUSTR(name_var(isubs_signed_P(ivtra,is))))) )
         CASE ('dissolved_phosphate') 
           p_marque_tracerP(ivtra,is)=p_marquePO4
         CASE('sorbed_phosphate') 
           p_marque_tracerP(ivtra,is)=p_marquePads 
         CASE('nanopicoplankton_nitrogen') 
           p_marque_tracerP(ivtra,is)=p_marquenanoP 
         CASE('diatom_nitrogen') 
           p_marque_tracerP(ivtra,is)=p_marquediatP 
         CASE('dinoflagellate_nitrogen') 
           p_marque_tracerP(ivtra,is)=p_marquedinoP 
         CASE('microzooplankton_nitrogen') 
           p_marque_tracerP(ivtra,is)=p_marquemicrP
         CASE('mesozooplankton_nitrogen') 
           p_marque_tracerP(ivtra,is)=p_marquemesoP 
         CASE('detrital_phosphorus') 
           p_marque_tracerP(ivtra,is)=p_marquedetP 
         CASE DEFAULT
           p_marque_tracerP(ivtra,is)=0
         END SELECT
 
      ENDDO
     ENDDO
#endif

     nvpc=nv_cp+nv_mud+nv_sand+nv_grav
     nvp=nvpc+nv_ncp+nv_sorb
     nv_adv=nvp+nv_dis
     nv_state=nv_adv+nv_fix
     nv_tot=nv_state+nv_dri+nv_int

     IF(nv_tot /= isubs)THEN
       IF_MPI (MASTER) THEN
         WRITE(ierrorlog,*)'WARNING with the total number of variables with tracer and age variables :',nv_tot
         WRITE(ierrorlog,*)'nv_tot new=',nv_tot,' is DIFFERENT from isubs',isubs
         do iv=1,isubs
          write(ierrorlog,*)iv,name_var(iv)
         enddo
         WRITE(ierrorlog,*)'The simulation is stopped'
         CALL_MPI MPI_FINALIZE(IERR_MPI)
         STOP
       ENDIF_MPI
     END IF
 
  END SUBROUTINE biolo_create_vartracer
#endif
   !!======================================================================
#if defined key_N_tracer || defined key_P_tracer
  SUBROUTINE biolo_alloc_vartracer

   !&E---------------------------------------------------------------------
   !&E                 ***  ROUTINE biolo_alloc_vartracer ***
   !&E
   !&E ** Purpose : allocate variables tracer 
   !&E
   !&E ** Description :
   !&E
   !&E ** Called by : biolo_create_vartracer
   !&E
   !&E ** External calls :
   !&E
   !&E ** Reference :
   !&E
   !&E ** History :
   !&E       !  2009-10  (V. Garnier)  Original code
   !&E
   !&E---------------------------------------------------------------------
   !! * Modules used
#if defined key_N_tracer
     ALLOCATE(p_marque_tracerN(nb_var_tracerN,nb_source_tracerN))
     ALLOCATE(isubs_tracer_N(nb_var_tracerN,nb_source_tracerN))
     ALLOCATE(iv_tracer_N(nb_var_tracerN,nb_source_tracerN))
     ALLOCATE(iv_signed_N(nb_var_tracerN,nb_source_tracerN))
     ALLOCATE(isubs_signed_N(nb_var_tracerN,nb_source_tracerN))
     ALLOCATE(id_tracer_signN(nb_var_tracerN,nb_source_tracerN))
     p_marque_tracerN(:,:)=0
     isubs_signed_N(:,:)=0
     isubs_tracer_N(:,:)=0
#if defined key_age_tracer
     ALLOCATE(iv_age_N(nb_var_tracerN,nb_source_tracerN))
     ALLOCATE(isubs_age_N(nb_var_tracerN,nb_source_tracerN))
     ALLOCATE(id_tracer_ageN(nb_var_tracerN,nb_source_tracerN))
     isubs_age_N(:,:)=0
     iv_age_N(:,:)=0
#endif

       ALLOCATE(iv_zoo_meso_tra_N(nb_source_tracerN))
       ALLOCATE(iv_zoo_micr_tra_N(nb_source_tracerN))
       ALLOCATE(iv_nutr_NH4_tra_N(nb_source_tracerN))
       ALLOCATE(iv_nutr_NO3_tra_N(nb_source_tracerN))
       ALLOCATE(iv_phyto_nano_tra_N(nb_source_tracerN))
       ALLOCATE(iv_phyto_diat_tra_N(nb_source_tracerN))
       ALLOCATE(iv_phyto_dino_tra_N(nb_source_tracerN))
       ALLOCATE(iv_detr_tra_N(nb_source_tracerN))
#if defined key_age_tracer
       ALLOCATE(iv_zoo_meso_age_tra_N(nb_source_tracerN))
       ALLOCATE(iv_zoo_micr_age_tra_N(nb_source_tracerN))
       ALLOCATE(iv_nutr_NH4_age_tra_N(nb_source_tracerN))
       ALLOCATE(iv_nutr_NO3_age_tra_N(nb_source_tracerN))
       ALLOCATE(iv_phyto_nano_age_tra_N(nb_source_tracerN))
       ALLOCATE(iv_phyto_diat_age_tra_N(nb_source_tracerN))
       ALLOCATE(iv_phyto_dino_age_tra_N(nb_source_tracerN))
       ALLOCATE(iv_detr_age_tra_N(nb_source_tracerN))
#endif
#if defined key_benthos
       ALLOCATE(iv_benth_tra_N(nb_source_tracerN))
#if defined key_age_tracer
       ALLOCATE(iv_benth_age_tra_N(nb_source_tracerN))
#endif
#endif
#if defined key_karenia
       ALLOCATE(iv_phyto_karenia_tra_N(nb_source_tracerN))
#if defined key_age_tracer
       ALLOCATE(iv_phyto_karenia_age_tra_N(nb_source_tracerN))
#endif
#endif
#if defined key_psnz
       ALLOCATE(iv_phyto_psnz_tra_N(nb_source_tracerN))
#if defined key_age_tracer
       ALLOCATE(iv_phyto_psnz_age_tra_N(nb_source_tracerN))
#endif
#endif
#if defined key_phaeocystis
       ALLOCATE(iv_phyto_phaeocystis_colo_tra_N(nb_source_tracerN))
       ALLOCATE(iv_phyto_phaeocystis_cell_tra_N(nb_source_tracerN))
#if defined key_age_tracer
       ALLOCATE(iv_phyto_phaeocystis_colo_age_tra_N(nb_source_tracerN))
       ALLOCATE(iv_phyto_phaeocystis_cell_age_tra_N(nb_source_tracerN))
#endif
#endif
#if defined key_ulvas
       ALLOCATE(iv_ulv_benth_tra_N(nb_source_tracerN))
       ALLOCATE(iv_ulv_tra_N(nb_source_tracerN))
#if defined key_age_tracer
       ALLOCATE(iv_ulv_benth_age_tra_N(nb_source_tracerN))
       ALLOCATE(iv_ulv_age_tra_N(nb_source_tracerN))
#endif
#endif

! P tracer
!!!!!!!!!!!!!
#else
     ALLOCATE(p_marque_tracerP(nb_var_tracerP,nb_source_tracerP))
     ALLOCATE(isubs_tracer_P(nb_var_tracerP,nb_source_tracerP))
     ALLOCATE(iv_tracer_P(nb_var_tracerP,nb_source_tracerP))
     ALLOCATE(iv_signed_P(nb_var_tracerP,nb_source_tracerP))
     ALLOCATE(isubs_signed_P(nb_var_tracerP,nb_source_tracerP))
     ALLOCATE(id_tracer_signP(nb_var_tracerP,nb_source_tracerP))
     p_marque_tracerP(:,:)=0
     isubs_signed_P(:,:)=0
     isubs_tracer_P(:,:)=0
#if defined key_age_tracer
     ALLOCATE(iv_age_P(nb_var_tracerP,nb_source_tracerP))
     ALLOCATE(isubs_age_P(nb_var_tracerP,nb_source_tracerP))
     ALLOCATE(id_tracer_ageP(nb_var_tracerP,nb_source_tracerP))
     isubs_age_P(:,:)=0
     iv_age_P(:,:)=0
#endif
       ALLOCATE(iv_nutr_PO4_tra_P(nb_source_tracerP))
       ALLOCATE(iv_nutr_Pads_tra_P(nb_source_tracerP))
       ALLOCATE(iv_detr_tra_P(nb_source_tracerP))
       ALLOCATE(iv_zoo_meso_tra_P(nb_source_tracerP))
       ALLOCATE(iv_zoo_micr_tra_P(nb_source_tracerP))
       ALLOCATE(iv_phyto_nano_tra_P(nb_source_tracerP))
       ALLOCATE(iv_phyto_diat_tra_P(nb_source_tracerP))
       ALLOCATE(iv_phyto_dino_tra_P(nb_source_tracerP))
#if defined key_age_tracer
       ALLOCATE(iv_zoo_meso_age_tra_P(nb_source_tracerP))
       ALLOCATE(iv_zoo_micr_age_tra_P(nb_source_tracerP))
       ALLOCATE(iv_nutr_PO4_age_tra_P(nb_source_tracerP))
       ALLOCATE(iv_nutr_Pads_age_tra_P(nb_source_tracerP))
       ALLOCATE(iv_detr_age_tra_P(nb_source_tracerP))
       ALLOCATE(iv_phyto_nano_age_tra_P(nb_source_tracerP))
       ALLOCATE(iv_phyto_diat_age_tra_P(nb_source_tracerP))
       ALLOCATE(iv_phyto_dino_age_tra_P(nb_source_tracerP))
#endif
#if defined key_benthos
       ALLOCATE(iv_benth_tra_P(nb_source_tracerP))
#if defined key_age_tracer
       ALLOCATE(iv_benth_age_tra_P(nb_source_tracerP))
#endif
#endif
#if defined key_karenia
       ALLOCATE(iv_phyto_karenia_tra_P(nb_source_tracerP))
#if defined key_age_tracer
       ALLOCATE(iv_phyto_karenia_age_tra_P(nb_source_tracerP))
#endif
#endif
#if defined key_psnz
       ALLOCATE(iv_phyto_psnz_tra_P(nb_source_tracerP))
#if defined key_age_tracer
       ALLOCATE(iv_phyto_psnz_age_tra_P(nb_source_tracerP))
#endif
#endif
#if defined key_phaeocystis
       ALLOCATE(iv_phyto_phaeocystis_colo_tra_P(nb_source_tracerP))
       ALLOCATE(iv_phyto_phaeocystis_cell_tra_P(nb_source_tracerP))
#if defined key_age_tracer
       ALLOCATE(iv_phyto_phaeocystis_colo_age_tra_P(nb_source_tracerP))
       ALLOCATE(iv_phyto_phaeocystis_cell_age_tra_P(nb_source_tracerP))
#endif
#endif

#endif

 END SUBROUTINE  biolo_alloc_vartracer
#endif

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

#if defined key_N_tracer || defined key_P_tracer
  SUBROUTINE biolo_create_vardiagtracer

   !&E---------------------------------------------------------------------
   !&E                 ***  ROUTINE biolo_create_vardiagtracer ***
   !&E
   !&E ** Purpose : create diagnostics variables tracer 
   !&E
   !&E ** Description :
   !&E
   !&E ** Called by : sub_read_var
   !&E
   !&E ** External calls :
   !&E
   !&E ** Reference :
   !&E
   !&E ** History :
   !&E       !  2009-10  (V. Garnier)  Original code
   !&E
   !&E---------------------------------------------------------------------
   !! * Modules used
   USE comsubstance, ONLY : name_var,long_name_var,standard_name_var,valid_min_var,valid_max_var

   !! * Arguments

   !! * Local declarations
    INTEGER                  :: id,is,ivtra
    CHARACTER(LEN=lchain)    :: name_ss
   !!----------------------------------------------------------------------
   !! * Executable part
      id=ndiag_1d+ndiag_2d+ndiag_3d
#if defined key_N_tracer
       DO is=1,nb_source_tracerN
        name_ss=name_source_tracerN(is)
        name_ss=name_ss(1:5)
         DO ivtra=1,nb_var_tracerN 
            id=id+1 
            name_vardiag(id)=TRIM(ADJUSTL(ADJUSTR(name_var(isubs_tracer_N(ivtra,is)))))//'_sign'
            long_name_vardiag(id)=TRIM(ADJUSTL(ADJUSTR(long_name_var(isubs_tracer_N(ivtra,is)))))//'_sign'
            standard_name_vardiag(id)=TRIM(ADJUSTL(ADJUSTR(standard_name_var(isubs_tracer_N(ivtra,is)))))//'_sign'
            unit_vardiag(id)='unitless'
            l_diag_sortie(id)=.TRUE.
            valid_min_vardiag(id)=valid_min_var(isubs_tracer_N(ivtra,is))
            valid_max_vardiag(id)=valid_max_var(isubs_tracer_N(ivtra,is))
            id_tracer_signN(ivtra,is)=id
            idimv_r(id)=3
            ndiag_3d=ndiag_3d+1
            ndiag_3d_wat=ndiag_3d_wat+1
#if defined key_age_tracer
            id=id+1
            name_vardiag(id)=TRIM(ADJUSTL(ADJUSTR(name_var(isubs_tracer_N(ivtra,is)))))//'_age'
            long_name_vardiag(id)=TRIM(ADJUSTL(ADJUSTR(long_name_var(isubs_tracer_N(ivtra,is)))))//'_age'
            standard_name_vardiag(id)=TRIM(ADJUSTL(ADJUSTR(standard_name_var(isubs_tracer_N(ivtra,is)))))//'_age'
            unit_vardiag(id)='days'
            l_diag_sortie(id)=.TRUE.
            valid_min_vardiag(id)=0
            valid_max_vardiag(id)=730
            idimv_r(id)=3
            ndiag_3d=ndiag_3d+1
            ndiag_3d_wat=ndiag_3d_wat+1
            id_tracer_ageN(ivtra,is)=id
#endif
         ENDDO
 !!une (ou 2 pour age) variable diagnostique en plus pour phyto total
         id=id+1 
         name_vardiag(id)='phytoplankton_sign_N_'//TRIM(ADJUSTL(ADJUSTR(name_ss)))
         long_name_vardiag(id)='phytoplankton_sign_N'//TRIM(ADJUSTL(ADJUSTR(name_ss)))
         standard_name_vardiag(id)='nitrogen_fraction_in_phytoplankton_from_source_'//TRIM(ADJUSTL(ADJUSTR(name_ss)))
         unit_vardiag(id)='unitless'
         l_diag_sortie(id)=.TRUE.
         valid_min_vardiag(id)=0.0_rsh
         valid_max_vardiag(id)=730.0_rsh
         idimv_r(id)=3
         ndiag_3d=ndiag_3d+1
         ndiag_3d_wat=ndiag_3d_wat+1
#if defined key_age_tracer
         id=id+1
         name_vardiag(id)='phytoplankton_age_N_'//TRIM(ADJUSTL(ADJUSTR(name_ss)))
         long_name_vardiag(id)='phytoplankton_age_N_'//TRIM(ADJUSTL(ADJUSTR(name_ss)))
         standard_name_vardiag(id)='age_of_nitrogen_fraction_in_phytoplankton_from_source_'//TRIM(ADJUSTL(ADJUSTR(name_ss)))
         unit_vardiag(id)='days'
         l_diag_sortie(id)=.TRUE.
         valid_min_vardiag(id)=0.0_rsh
         valid_max_vardiag(id)=730.0_rsh
         idimv_r(id)=3
         ndiag_3d=ndiag_3d+1
         ndiag_3d_wat=ndiag_3d_wat+1
#endif         
       ENDDO
! P tracer
!!!!!!!!!!
#else
       DO is=1,nb_source_tracerP
        name_ss=name_source_tracerP(is)
        name_ss=name_ss(1:5)
         DO ivtra=1,nb_var_tracerP 
            id=id+1 
            name_vardiag(id)=TRIM(ADJUSTL(ADJUSTR(name_var(isubs_tracer_P(ivtra,is)))))//'_sign'
            long_name_vardiag(id)=TRIM(ADJUSTL(ADJUSTR(long_name_var(isubs_tracer_P(ivtra,is)))))//'_sign'
            standard_name_vardiag(id)=TRIM(ADJUSTL(ADJUSTR(standard_name_var(isubs_tracer_P(ivtra,is)))))//'_sign'
            unit_vardiag(id)='unitless'
            l_diag_sortie(id)=.TRUE.
            valid_min_vardiag(id)=valid_min_var(isubs_tracer_P(ivtra,is))
            valid_max_vardiag(id)=valid_max_var(isubs_tracer_P(ivtra,is))
            id_tracer_signP(ivtra,is)=id
            idimv_r(id)=3
            ndiag_3d=ndiag_3d+1
            ndiag_3d_wat=ndiag_3d_wat+1
#if defined key_age_tracer
            id=id+1
            name_vardiag(id)=TRIM(ADJUSTL(ADJUSTR(name_var(isubs_tracer_P(ivtra,is)))))//'_age'
            long_name_vardiag(id)=TRIM(ADJUSTL(ADJUSTR(long_name_var(isubs_tracer_P(ivtra,is)))))//'_age'
            standard_name_vardiag(id)=TRIM(ADJUSTL(ADJUSTR(standard_name_var(isubs_tracer_P(ivtra,is)))))//'_age'
            unit_vardiag(id)='days'
            l_diag_sortie(id)=.TRUE.
            valid_min_vardiag(id)=0
            valid_max_vardiag(id)=730
            idimv_r(id)=3
            ndiag_3d=ndiag_3d+1
            ndiag_3d_wat=ndiag_3d_wat+1
            id_tracer_ageP(ivtra,is)=id
#endif
         ENDDO
 !!une (ou 2 pour age) variable diagnostique en plus pour phyto total
         id=id+1 
         name_vardiag(id)='phytoplankton_sign_P_'//TRIM(ADJUSTL(ADJUSTR(name_ss)))
         long_name_vardiag(id)='phytoplankton_sign_P'//TRIM(ADJUSTL(ADJUSTR(name_ss)))
         standard_name_vardiag(id)='phosphorus_fraction_in_phytoplankton_from_source_'//TRIM(ADJUSTL(ADJUSTR(name_ss)))
         unit_vardiag(id)='unitless'
         l_diag_sortie(id)=.TRUE.
         valid_min_vardiag(id)=0.0_rsh
         valid_max_vardiag(id)=730.0_rsh
         idimv_r(id)=3
         ndiag_3d=ndiag_3d+1
         ndiag_3d_wat=ndiag_3d_wat+1
#if defined key_age_tracer
         id=id+1
         name_vardiag(id)='phytoplankton_age_P_'//TRIM(ADJUSTL(ADJUSTR(name_ss)))
         long_name_vardiag(id)='phytoplankton_age_P_'//TRIM(ADJUSTL(ADJUSTR(name_ss)))
         standard_name_vardiag(id)='age_of_phorphorus_fraction_in_phytoplankton_from_source_'//TRIM(ADJUSTL(ADJUSTR(name_ss)))
         unit_vardiag(id)='days'
         l_diag_sortie(id)=.TRUE.
         valid_min_vardiag(id)=0.0_rsh
         valid_max_vardiag(id)=730.0_rsh
         idimv_r(id)=3
         ndiag_3d=ndiag_3d+1
         ndiag_3d_wat=ndiag_3d_wat+1
#endif         
       ENDDO
#endif
 END SUBROUTINE  biolo_create_vardiagtracer
#endif
   !!======================================================================
  SUBROUTINE biolo_init_nut4phy3zoo2(cv_wat)

#if defined key_substance && defined key_biolo

   !&E---------------------------------------------------------------------
   !&E                 ***  ROUTINE biolo_init_nut4phy3zoo2  ***
   !&E
   !&E ** Purpose : Local initialisations, reading of special files
   !&E
   !&E ** Description :
   !&E
   !&E ** Called by : main
   !&E
   !&E ** External calls :
   !&E
   !&E ** Reference :
   !&E
   !&E ** History :
   !&E       !  2006-10  (M. Sourisseau)  Original code
   !&E       !  2008-01  (M. Sourisseau)  Introduction MES satellitale (climato)
   !&E       !  2008-01  (P. Karleskind)  Initialisation idateinf=1
   !&E
   !&E---------------------------------------------------------------------
   !! * Modules used
   USE parameters,    ONLY : valmanq,nb_var,liminm1,limaxp2,ljminm1,ljmaxp2
   USE comvars2d,     ONLY : l_initfromfile,t,h0fond,h0,iscreenlog,cdate,id,ig     &
                             ,l_init_rtime,file_init,ierrorlog
#ifdef key_agrif
   USE comvars2d,     ONLY : tdebagrif_messat
#endif
   USE comsubstance,  ONLY : irk_mod,nvp,imud1,ws_free_min, ws_free_max                       
#ifdef key_messat
   USE comsubstance,  ONLY : messat,l_messat_clim,filemessat_clim,idateinf,idatesup &
                             ,date_s_annee,idimt_messat,t_clim_messat               &
                             ,messat_obs,l_messat_obs,filemessat_obs                &
                            ,idimt_messat_obs,t_obs_messat
#endif
#ifdef key_oyster_benthos
   USE comsubstance,  ONLY : nbhuitre,nbhuitre2,hautable
   USE comvars2d,     ONLY : dx,dy
#elif key_oyster_DEB
   USE comsubstance,  ONLY : nbhuitre,hautable,chlorofondmoy,tempfondmax,txmorthuitco1,txmorthuitco2
   USE comvars2d,     ONLY : dx,dy
#elif key_oyster_SFG
   USE comsubstance,  ONLY : nbhuitre,hautable
#endif

   USE_MPI toolmpi,      ONLY : ex_i_rsh,ex_j_rsh
   USE_MPI toolmpi, ONLY : MASTER

   IMPLICIT NONE

   !! * Arguments
   REAL(KIND=rsh),DIMENSION(nb_var,kmax,liminm1:limaxp2,ljminm1:ljmaxp2),INTENT(inout) :: cv_wat

   !! * Local declarations
   INTEGER  :: k,i,j,iv
#ifdef key_messat
   INTEGER                       :: itmes,it,ijour,imois,ian,iheure,iminu,isec
   INTEGER                       :: jjulien,tool_julien,IERR_MPI
   INTEGER, DIMENSION(51)        :: t_clim_messat_int
   CHARACTER(LEN=19)             :: date_start,tool_sectodat
   CHARACTER(LEN=lchain)         :: nomfic
   REAL(kind=rsh)                :: lon,lat,moy
   REAL(kind=riosh), DIMENSION(imin:imax,jmin:jmax) :: tab_mes
   REAL(kind=rlg)                :: tbid
   !INTEGER                       :: ionc4_read_dimt
#endif
#if defined key_oyster_benthos || defined key_oyster_DEB
   !REAL(kind=rsh)                :: surfcad,nbfilt,nbmail
   REAL(kind=rsh)                :: biom_huitre,poids_indv
   REAL(kind=rsh)                :: surface_cadastre,densite_huitre
   INTEGER                       :: ih,jh
   !INTEGER                       :: itm
   CHARACTER(LEN=lchain)         :: fic_benthos
   REAL(kind=rsh), DIMENSION(imin:imax,jmin:jmax)        :: zlit1
#endif
#if defined key_oyster_DEB
   CHARACTER(LEN=lchain)         :: fic_chloro
#elif key_oyster_SFG
    INTEGER                       :: compt,compt2   ! compteurs qui servent pour tester la profondeur de la maille
#endif

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

   IF_MPI (MASTER) THEN
     WRITE(iscreenlog,*) ' '
     WRITE(iscreenlog,*) '**************************************************'
     WRITE(iscreenlog,*) '**************** BLO_USERINIT.F90 ****************'
     WRITE(iscreenlog,*) '**************************************************'
   ENDIF_MPI

   ! Initializations
   !----------------
   cmes_3dmgl(:,:,:)  =0.0_rsh
   !phytomoy(:,:)  =0.0_rsh
   !phytocarre(:,:)=0.0_rsh

#ifdef key_parsub_newdt
   ! rajout pour calcul de ndt_part en fonction du temps, calcule en fonction de ws
   ALLOCATE(ws3max_bio(nvp))
   ws3max_bio(:)=0.0_rsh
   DO iv=imud1,nvp
    ws3max_bio(iv)=(ws_free_min(iv)+ws_free_min(iv))*0.5_rsh
   ENDDO

#endif


   ! Modifications of global initializations
   !----------------------------------------
   IF(.NOT.l_initfromfile) THEN

   END IF
#ifdef key_benthos
   !remise a zero des vars "benthiques" quand k<>1  
     cv_wat(iv_benth_N,2:kmax,:,:) = 0.0_rsh
     cv_wat(iv_benth_Si,2:kmax,:,:) = 0.0_rsh
     cv_wat(iv_benth_P,2:kmax,:,:) = 0.0_rsh
#ifdef key_NPbenth
     cv_wat(iv_benth_PO4,2:kmax,:,:) = 0.0_rsh
     cv_wat(iv_benth_NH4,2:kmax,:,:) = 0.0_rsh
#endif
#ifdef key_zostera
     cv_wat(iv_benth_PO4,2:kmax,:,:) = 0.0_rsh
     cv_wat(iv_benth_NH4,2:kmax,:,:) = 0.0_rsh
     cv_wat(iv_zost_benth_N,2:kmax,:,:) = 0.0_rsh
     cv_wat(iv_zost_benth_P,2:kmax,:,:) = 0.0_rsh
     cv_wat(iv_zost_benth_seed,2:kmax,:,:) = 0.0_rsh
#endif
#endif

   ! Read special files
   !-------------------
#if defined key_messat

   ! initialization satellite MES
   messat(:,:,:)=0.0_rsh
   DO j=ljmin,ljmax
     DO i=MAX0(limin,ig(j)+1),MIN0(limax,id(j)-1)
       IF (h0(i,j) .EQ. -valmanq) THEN
         messat(i,j,:)=valmanq
       END IF
     END DO
   END DO

   IF ((l_messat_clim .EQV. .TRUE.).and.(l_messat_obs .EQV. .TRUE.)) THEN
     IF_MPI (MASTER) THEN
       WRITE(ierrorlog,*)'ATTENTION : Les climato MES Sat et les observations MES'   &
      //' Sat ne peuvent pas etre utilisees simultanement. Voir dans parasubs.txt'
       WRITE(ierrorlog,*)'The simulation is stopped'
       CALL_MPI MPI_FINALIZE(IERR_MPI)
       STOP
     ENDIF_MPI
   END IF

   ! read  climato
   !----------------------------------------
   IF (l_messat_clim .EQV. .TRUE.) THEN
     IF_MPI (MASTER) THEN
       WRITE(iscreenlog,*)'------------------------------------------------'
       WRITE(iscreenlog,*)'lecture fichier climato pour mes-sat  '
       WRITE(iscreenlog,*)'     donnees en g.l-1', TRIM(filemessat_clim)
     ENDIF_MPI
    CALL ionc4_openr(filemessat_clim)
    idimt_messat=ionc4_read_dimt(filemessat_clim)
    !idimt_messat=26  !attention entree en dur de la taille du fichier- a modif
    DO it=1,idimt_messat
     CALL ionc4_read_time(filemessat_clim,it,t_clim_messat(it))
    END DO

    !!reading
    DO it=1,idimt_messat
     CALL ionc4_read_xyt(filemessat_clim,'MES',tab_mes,imin,imax,jmin,jmax,it)
     DO j=ljmin,ljmax
       DO i=MAX0(limin,ig(j)+1),MIN0(limax,id(j)-1)
         IF(h0(i,j).GT.-valmanq) THEN
            IF (tab_mes(i,j).LT.valmanq) THEN
             messat(i,j,it)=tab_mes(i,j)
             IF(messat(i,j,it) .LT. 0.0_rsh) THEN
                   IF_MPI (MASTER) WRITE(iscreenlog,*)'pb maille ',i,j,it,messat(i,j,it)
             END IF
            ELSE
             IF_MPI (MASTER) WRITE(iscreenlog,*)'pas de MES climato en ',i,j,it,tab_mes(i,j)
            END IF
          END IF
       END DO
     END DO
     IF_MPI (MASTER) WRITE(iscreenlog,*) t_clim_messat(it)
    END DO

    CALL ionc4_close(filemessat_clim)

#ifdef key_agrif
    IF (.NOT. l_initfromfile) THEN
     date_start=tool_sectodat(tdebagrif_messat)
    ELSE
     date_start=tool_sectodat(t)
    END IF
#else
    date_start=tool_sectodat(t)
#endif
    CALL tool_decompdate(date_start,ijour,imois,ian,iheure,iminu,isec)
    jjulien=tool_julien(ijour,imois,ian)-tool_julien(1,1,ian)+1
    date_s_annee=jjulien*24*60*60

    it=1
    idateinf=1
    t_clim_messat_int(1:idimt_messat)=INT(t_clim_messat(1:idimt_messat))
    IF (date_s_annee .LE. t_clim_messat_int(1)) THEN
      idatesup=1
      idateinf=idimt_messat
    ELSE
      DO WHILE ((it .LT. idimt_messat) .AND.      &
             (t_clim_messat_int(it+1) .LT. date_s_annee))
        it=it+1
        idateinf=it
      END DO
      IF (idateinf .EQ. idimt_messat) THEN
        idatesup=1
      ELSE
        idatesup=idateinf+1
      END IF
    END IF
    IF_MPI (MASTER) THEN
      WRITE(iscreenlog,*) 'Fin de lecture fichier climato satellite MES'
      WRITE(iscreenlog,*) it,' champs MES lus'
      WRITE(iscreenlog,*) ' champs MES interp entre', idateinf,' et ',idatesup
      WRITE(iscreenlog,*) 'date du run  = ',date_s_annee
      WRITE(iscreenlog,*)'----------------------------------------------------'
      WRITE(iscreenlog,*)''
    ENDIF_MPI

   END IF !endif sur l_messat_clim

   IF (l_messat_obs .EQV. .TRUE.) THEN

    IF_MPI (MASTER) THEN
      WRITE(iscreenlog,*)'------------------------------------------------'
      WRITE(iscreenlog,*)'lecture fichier obs moyennes quizaines pour mes-sat  '
      WRITE(iscreenlog,*)'     donnees en g.l-1', TRIM(filemessat_obs)
    ENDIF_MPI

    CALL ionc4_openr(filemessat_obs)
    idimt_messat_obs=ionc4_read_dimt(filemessat_obs)
!   idimt_messat=26*6  !attention entree en dur de la taille du fichier- a modif
    ALLOCATE(messat_obs(limin:limax,ljmin:ljmax,idimt_messat_obs))
    ALLOCATE(t_obs_messat(idimt_messat_obs))
    DO it=1,idimt_messat_obs
      CALL ionc4_read_time(filemessat_obs,it,t_obs_messat(it))
      IF_MPI (MASTER) WRITE(iscreenlog,*)'it_messat=',it,t_obs_messat(it)
    END DO

    !!reading
    DO it=1,idimt_messat_obs
      CALL ionc4_read_xyt(filemessat_obs,'MES_SAT',tab_mes,imin,imax,jmin,jmax,it)
!     CALL ionc4_read_xyt(filemessat_clim,'MES_SAT',tab_mes,limin,limax,ljmin,ljmax,it)
      DO j=ljmin,ljmax
       DO i=MAX0(limin,ig(j)+1),MIN0(limax,id(j)-1)
 !!MORGAN
     ! IF (tab_mes(i,j).LT.0.0_rsh) THEN
     !     tab_mes(i,j)=valmanq
     ! END IF
 !!!FIN MORGAN
         IF(h0(i,j).GT.-valmanq) THEN
            IF (tab_mes(i,j).LT.valmanq) THEN
             messat_obs(i,j,it)=tab_mes(i,j)
             IF(messat_obs(i,j,it) .LT. 0.0_rsh) THEN
              IF_MPI (MASTER) WRITE(iscreenlog,*)'pb maille ',i,j,it,messat_obs(i,j,it)
             END IF
            ELSE
             IF_MPI (MASTER) WRITE(iscreenlog,*)'pas de MES climato en ',i,j,it,tab_mes(i,j)
            END IF
          END IF
       END DO
      END DO
      IF_MPI (MASTER) WRITE(iscreenlog,*) t_obs_messat(it)
    END DO

    CALL ionc4_close(filemessat_obs)

    it=1
    idateinf=1
    tbid=t
    IF ((l_initfromfile .EQV. .TRUE.).and.(l_init_rtime .EQV. .TRUE.)) then
       CALL ionc4_openr(file_init)
       CALL ionc4_read_time(file_init,1,tbid)
       CALL ionc4_close(file_init)
    END IF
    date_start=tool_sectodat(tbid)
    IF_MPI (MASTER) WRITE(iscreenlog,*)'date_start=',date_start
    IF (tbid .LE. t_obs_messat(1)) THEN
       IF_MPI (MASTER) THEN
          WRITE(ierrorlog,*)'la date de depart est anterieure a la premiere date du fichier messat'
          CALL_MPI MPI_FINALIZE(IERR_MPI)
         STOP
       ENDIF_MPI
    ELSE
       DO WHILE ((it .LT. idimt_messat_obs) .AND.(t_obs_messat(it+1) .LT. tbid))
          it=it+1
          idateinf=it
       END DO
       IF (idateinf .EQ. idimt_messat_obs) THEN
         IF_MPI (MASTER) THEN
            WRITE(ierrorlog,*)'la date de depart est posterieure a la derniere date du fichier messat'    
            CALL_MPI MPI_FINALIZE(IERR_MPI)
            STOP
         ENDIF_MPI
       ELSE
         idatesup=idateinf+1
       END IF
    END IF
   
    IF_MPI (MASTER) THEN
     WRITE(iscreenlog,*) 'Fin de lecture fichier observation quinzaine satellite MES'
     WRITE(iscreenlog,*) it,' champs MES lus'
     WRITE(iscreenlog,*) ' champs MES interp entre', idateinf,' et ',idatesup
     WRITE(iscreenlog,*) 'date du run  = ',tbid
     WRITE(iscreenlog,*) ' champs MES interp entre', t_obs_messat(idateinf),' et ',t_obs_messat(idatesup)
     WRITE(iscreenlog,*)'----------------------------------------------------'
     WRITE(iscreenlog,*)''
     WRITE(iscreenlog,*) 'date du run  = ',tbid
     WRITE(iscreenlog,*) ' champs MES interp entre', idateinf,' et ',idatesup
     WRITE(iscreenlog,*) ' champs MES interp entre', t_obs_messat(idateinf),' et ',t_obs_messat(idatesup)
    ENDIF_MPI

   END IF !endif sur l_messat_obs

#endif

#if defined key_oyster_benthos || defined key_oyster_DEB || defined key_oyster_SFG

    ALLOCATE(nbhuitre(limin:limax,ljmin:ljmax))
!    ALLOCATE(nbhuitre2(limin:limax,ljmin:ljmax))
!    ALLOCATE(nbhuitre3(limin:limax,ljmin:ljmax))
    ALLOCATE(hautable(limin:limax,ljmin:ljmax))
    hautable(:,:)=0.0_rsh
    nbhuitre(:,:)=0.0_rsh
!    nbhuitre2(:,:)=0.0_rsh
!    nbhuitre3(:,:)=0.0_rsh
#endif

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!   initialisation de la couverture benthos
!   a programmer par l utilisateur
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

! des exemples :
! Baie de Quiberon
!   open(119,file='../../inputs/huitres_vilo.txt')
!121    read(119,*,end=120)ih,jh 
!       IF(ih.ge.limin.and.ih.le.limax.and.jh.ge.ljmin.and.jh.le.ljmax) THEN  
!         nbhuitre(ih,jh)=1.
!         hautable(ih,jh)=0.
!       ENDIF
!      goto 121
!120 close(119) 
!    surface_cadastre =  2.7781778E+07
!    DO i=limin,limax
!      DO j=ljmin,ljmax
!        IF (nbhuitre(i,j).ne.0) THEN
!              nbhuitre(i,j) = (20.e9/35.)/ surface_cadastre*dx(i,j)*dy(i,j)
!        ENDIF
!      ENDDO
!    ENDDO

!  exemple Baie de Bougneuf
!   fic_benthos='../../inputs/BENTHOS/couvbenthos_bnuf_vilo.nc'
!   call ionc4_openr(fic_benthos)
!   WRITE(iscreenlog,*)'------------------------------------------------'
!   WRITE(iscreenlog,*)'lecture couverture huitre cultivees'
!   WRITE(iscreenlog,*)'     donnees en gPF/m2', trim(fic_bgnf)
!   call ionc4_read_xy(fic_benthos,'couverture_huitres',zlit1,imin,imax,jmin,jmax)!
!   DO j=ljmin,ljmax
!       DO i=MAX0(limin,ig(j)+1),MIN0(limax,id(j)-1)
!         IF(zlit1(i,j).gt.0.) THEN
!            nbhuitre(i,j)=11.5*dx(i,j)*dy(i,j)
!            nbhuitre2(i,j)=60.*dx(i,j)*dy(i,j)
! !            nbhuitre3(i,j)=30.*dx(i,j)*dy(i,j)
!            hautable(i,j)=1.
!         ENDIF
!       ENDDO
!   ENDDO
!   DO j=ljmin,ljmax
!     DO i=MAX0(limin,ig(j)+1),MIN0(limax,id(j)-1)
!       IF (nbhuitre(i,j).ne.0) then
!         WRITE(*,*) 'nombre huitre init par maille i,j =' , i,j,nbhuitre(i,j)
!         WRITE(*,*) 'densitehuitre init par maille i,j =' , i,j,nbhuitre(i,j)/(dx(i,j)*dy(i,j))
!         WRITE(*,*) 'nombre huitre2 init par maille i,j =' , i,j,nbhuitre2(i,j)
!         WRITE(*,*) 'densite huitre2 init par maille i,j =' , i,j,nbhuitre2(i,j)/(dx(i,j)*dy(i,j))
!!         WRITE(*,*) 'nombre huitre3 init par maille i,j =' , i,j,nbhuitre3(i,j)
!!         WRITE(*,*) 'densite huitre3 init par maille i,j =' , i,j,nbhuitre3(i,j)/(dx(i,j)*dy(i,j))
!         WRITE(*,*) 'surface maille i,j =' , dx(i,j),dy(i,j),dx(i,j)*dy(i,j)
!         WRITE(*,*) 'hauteur table conchyl maille i,j =' , i,j,hautable(i,j)
!       ENDIF
!     ENDDO
!   ENDDO

#ifdef key_oyster_DEB
    !ALLOCATE(chlorofondmoy(limin:limax,ljmin:ljmax))
    !chlorofondmoy=0.
    !ALLOCATE(tempfondmax(limin:limax,ljmin:ljmax))
    !tempfondmax=0.
!lecture de la chlorophylle moyenne pour calcul du Xk variable
!   fic_chloro='../../inputs/BENTHOS/chloro_fond_moyenne.nc'
    !fic_chloro='../../inputs/BENTHOS/chloro_temp_fond.nc'
    !call ionc4_openr(fic_chloro)

    !WRITE(iscreenlog,*)'------------------------------------------------'
    !WRITE(iscreenlog,*)'lecture de la chloro fond moyenne pour calcul de Xk'
    !WRITE(iscreenlog,*)'     donnees en microg.l-1', trim(fic_chloro)
    !call ionc4_read_xy(fic_chloro,'Chloro_moy_fond',zlit1,imin,imax,jmin,jmax)!
    !DO j=ljmin,ljmax
    !   DO i=MAX0(limin,ig(j)+1),MIN0(limax,id(j)-1)
    !     IF(zlit1(i,j).ge.0.) THEN
    !       chlorofondmoy(i,j)=zlit1(i,j)
    !     ENDIF
    !  ENDDO
    !ENDDO
    !write(*,*)'chloro_fond_moy=',chlorofondmoy(78,99)
    !zlit1(:,:)=0.
    !WRITE(iscreenlog,*)'------------------------------------------------'
    !WRITE(iscreenlog,*)'lecture de la temperature fond max pour calcul de Xk'
    !WRITE(iscreenlog,*)'     donnees en degres Celsius', trim(fic_chloro)
    !call ionc4_read_xy(fic_chloro,'temp_max_fond',zlit1,imin,imax,jmin,jmax)!
    !DO j=ljmin,ljmax
    !   DO i=MAX0(limin,ig(j)+1),MIN0(limax,id(j)-1)
    !     IF(zlit1(i,j).ge.0.) then
    !       tempfondmax(i,j)=zlit1(i,j)
    !     ENDIF
    !  ENDDO
    !ENDDO
    !write(*,*)'tempfondmax=',tempfondmax(78,99)
    !call ionc4_close(fic_chloro)
#endif    
#ifdef key_oyster_SFG
    nbhuitre=0.0_rsh
    DO compt=limin,limax
        DO compt2=ljmin,ljmax
                IF (h0(compt,compt2) < 30.0_rsh) THEN
                        nbhuitre(compt,compt2)=1.0_rsh
                        write(iscreenlog,*)'1 huitre ajoutee en ',compt,compt2
                ENDIF
        ENDDO
    ENDDO
#endif
#if defined key_oyster_benthos || defined key_oyster_DEB
  ! autre version
   ! surface_cadastre=0.
   ! open(110,file='../../inputs/cadastre.txt')
!112    read(110,*,end=111)ih,jh,nbhuitre(ih,jh)
   !    surface_cadastre=surface_cadastre+dx(ih,jh)*dy(ih,jh)
   !    goto 112
 !! 111 close(110)
    surface_cadastre =  2.7781778E+10

!     biomasse totale huitre
    biom_huitre=3000e3
!     poids moyen d une huitre
    poids_indv=0.1
!   densite d huitre sur le secteur des parcs ind/m2
    densite_huitre=biom_huitre/poids_indv/surface_cadastre
    IF_MPI (MASTER) THEN
       write(iscreenlog,*)'densite_huitre=',densite_huitre
    ENDIF_MPI
!nombre d huitres par maille
    DO i=limin,limax
      DO j=ljmin,ljmax
        IF(h0(i,j).lt.25.0_rsh .AND. h0(i,j) > -valmanq) THEN
            nbhuitre(i,j)=densite_huitre*dx(i,j)*dy(i,j)
            hautable(i,j)=1.0_rsh
        ENDIF
      ENDDO
    ENDDO
    DO i=limin,limax
      DO j=ljmin,ljmax
        IF(nbhuitre(i,j).gt.0.) THEN
         IF_MPI (MASTER) THEN
            write(iscreenlog,*)'i,j,nbhuitre=',i,j,nbhuitre(i,j)
         ENDIF_MPI
        ENDIF
      ENDDO
    ENDDO
#endif

! if cv_wat has been assigned in this routine
!   CALL_MPI ex_i_rsh(-1,2,nb_var*kmax,liminm1,limaxp2,ljminm1,ljmaxp2,cv_wat(:,:,liminm1:limaxp2,ljminm1:ljmaxp2))
!   CALL_MPI ex_j_rsh(-1,2,nb_var*kmax,liminm1,limaxp2,ljminm1,ljmaxp2,cv_wat(:,:,liminm1:limaxp2,ljminm1:ljmaxp2))

#ifdef key_oyster_DEB
      write(*,*)'debut init huitre deb'
      DO  i=limin,limax
      DO  j=ljmin,ljmax
        IF ((nbhuitre(i,j).ne.0.0_rsh) .and. (.NOT.l_init_rtime)) THEN
!         cv_wat(iv_oysdeb_res,1,i,j)=5000.0_rsh
!         cv_wat(iv_oysdeb_gon,1,i,j)=500.0_rsh
!         cv_wat(iv_oysdeb_str,1,i,j)=1900.0_rsh
         cv_wat(iv_oysdeb_res,1,i,j)=50.0_rsh
         cv_wat(iv_oysdeb_gon,1,i,j)=500.0_rsh
         cv_wat(iv_oysdeb_str,1,i,j)=310.0_rsh
!         cv_wat(iv_oysdeb_gon,1,i,j)=2656.0_rsh
        ENDIF
        !IF ((nbhuitre2(i,j).ne.0.0_rsh) .and. (.NOT.l_init_rtime)) THEN
!         cv_wat(iv_oysdeb_res,1,i,j)=5000.0_rsh
!         cv_wat(iv_oysdeb_gon,1,i,j)=500.0_rsh
!         cv_wat(iv_oysdeb_str,1,i,j)=1900.0_rsh
!       Poids initial référence
!         cv_wat(iv_oysdeb_res2,1,i,j)=880.0_rsh
!         cv_wat(iv_oysdeb_gon2,1,i,j)=891.0_rsh
!         cv_wat(iv_oysdeb_str2,1,i,j)=5449.0_rsh
!       Poids initial faible
!         cv_wat(iv_oysdeb_res2,1,i,j)=30.0_rsh
!         cv_wat(iv_oysdeb_gon2,1,i,j)=0.0_rsh
!         cv_wat(iv_oysdeb_str2,1,i,j)=1170.0_rsh
!       Poids initial fort
        ! cv_wat(iv_oysdeb_res2,1,i,j)=465.0_rsh
        ! cv_wat(iv_oysdeb_gon2,1,i,j)=271.0_rsh
        ! cv_wat(iv_oysdeb_str2,1,i,j)=8214.0_rsh
        !ENDIF
!	if ((nbhuitre3(i,j).ne.0.0_rsh).and.(.NOT.l_init_rtime)) then
!         cv_wat(iv_oysdeb_res3,1,i,j)=1641.0_rsh
!         cv_wat(iv_oysdeb_gon3,1,i,j)=8339.0_rsh
!         cv_wat(iv_oysdeb_str3,1,i,j)=10160.0_rsh
!        endif
      ENDDO
      ENDDO    
      write(*,*)'fin init huitre deb'
!   Mortalites journaliere par mois et par cohortes
!       do itm=1,12
!         txmorthuitco1(itm)=2.7e-4*2.
!         txmorthuitco2(itm)=2.7e-4
!       enddo 

!    Cas faibles mortalites
!    Cohorte 1
!      txmorthuitco1(1)=1.33e-4
!      txmorthuitco1(2)=1.33e-4
!      txmorthuitco1(3)=4.1e-5
!      txmorthuitco1(4)=0.
!      txmorthuitco1(5)=2.76e-4
!      txmorthuitco1(6)=6.0e-4
!      txmorthuitco1(7)=9.07e-4
!      txmorthuitco1(8)=1.21e-3
!      txmorthuitco1(9)=1.52e-3
!      txmorthuitco1(10)=1.12e-3
!      txmorthuitco1(11)=7.17e-4
!      txmorthuitco1(12)=5.0e-4
!    Cohorte 2
!      txmorthuitco2(1)=0.
!      txmorthuitco2(2)=2.67e-4
!      txmorthuitco2(3)=2.86e-4
!      txmorthuitco2(4)=2.81e-4
!      txmorthuitco2(5)=3.5e-4
!      txmorthuitco2(6)=8.37e-4
!      txmorthuitco2(7)=1.63e-4
!      txmorthuitco2(8)=6.07e-5
!      txmorthuitco2(9)=5.43e-4
!      txmorthuitco2(10)=8.97e-5
!      txmorthuitco2(11)=2.99e-4
!      txmorthuitco2(12)=2.35e-4
!
!    Cas fortes mortalites
!    Cohorte 1
      txmorthuitco1(1)=0.
      txmorthuitco1(2)=0.
      txmorthuitco1(3)=2.36e-4
      txmorthuitco1(4)=1.11e-3
      txmorthuitco1(5)=3.63e-3
      txmorthuitco1(6)=9.17e-3
      txmorthuitco1(7)=1.39e-3
      txmorthuitco1(8)=9.83e-4
      txmorthuitco1(9)=2.06e-3
      txmorthuitco1(10)=7.53e-4
      txmorthuitco1(11)=5.27e-4
      txmorthuitco1(12)=3.50e-4
!    Cohorte 2
      !txmorthuitco2(1)=1.63e-4
      !txmorthuitco2(2)=0.
      !txmorthuitco2(3)=2.01e-4
      !txmorthuitco2(4)=1.20e-3
      !txmorthuitco2(5)=1.39e-3
      !txmorthuitco2(6)=2.46e-3
      !txmorthuitco2(7)=4.83e-4
      !txmorthuitco2(8)=1.66e-4
      !txmorthuitco2(9)=1.25e-3
      !txmorthuitco2(10)=3.73e-4
      !txmorthuitco2(11)=1.86e-4
      !txmorthuitco2(12)=6.63e-4
      
! if cv_wat has been assigned in this routine
!   CALL_MPI ex_i_rsh(-1,2,nb_var*kmax,liminm1,limaxp2,ljminm1,ljmaxp2,cv_wat(:,:,liminm1:limaxp2,ljminm1:ljmaxp2))

#endif 
!#ifdef key_larve
!		i_ponte=0
!#endif
#else
  WRITE(iscreenlog,*) 'biolo_init_nut4phy3zoo2 : You should not have seen this print! error?'
#endif

  END SUBROUTINE biolo_init_nut4phy3zoo2

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

  SUBROUTINE biolo_init_dinodiatzoo(cv_wat)

#if defined key_substance && defined key_biolo

   !&E---------------------------------------------------------------------
   !&E                 ***  ROUTINE biolo_init_dinodiatzoo  ***
   !&E
   !&E ** Purpose : Local initialisations, reading of special files
   !&E
   !&E ** Description :
   !&E
   !&E ** Called by : main
   !&E
   !&E ** External calls :
   !&E
   !&E ** Reference :
   !&E
   !&E ** History :
   !&E       !  2006-10  (P. Cugier V. Garnier)  Original code
   !&E
   !&E---------------------------------------------------------------------
   !! * Modules used
   USE parameters,    ONLY : valmanq,nb_var,liminm1,limaxp2,ljminm1,ljmaxp2
   USE comvars2d,     ONLY : l_initfromfile,t,h0fond,h0,iscreenlog,ierrorlog
   USE comsubstance,  ONLY : irk_mod,cmes_3dmgl
#ifdef key_messat
   USE comsubstance,  ONLY : messat
#endif
   USE_MPI toolmpi,      ONLY : ex_i_rsh,ex_j_rsh
   USE_MPI toolmpi, ONLY : MASTER

   IMPLICIT NONE

   !! * Arguments
   REAL(KIND=rsh),DIMENSION(nb_var,kmax,liminm1:limaxp2,ljminm1:ljmaxp2),INTENT(inout) :: cv_wat

   !! * Local declarations
#ifdef key_messat
   INTEGER                       :: k,i,j,                                     &
                                    itmes,it,ijour,imois,ian,iheure,iminu,isec
   CHARACTER(LEN=19)             :: date_start,tool_sectodat
   CHARACTER(LEN=lchain)         :: nomfic
   REAL(kind=rsh)                :: lon,lat,moy 
   REAL(kind=rsh), DIMENSION(1:12)                             :: messatp
   REAL(kind=riosh), DIMENSION(imin:imax,jmin:jmax)            :: tab_mes

#endif

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

   IF_MPI (MASTER) THEN
     WRITE(iscreenlog,*) ' '
     WRITE(iscreenlog,*) '**************************************************'
     WRITE(iscreenlog,*) '**************** BLO_USERINIT.F90 ****************'
     WRITE(iscreenlog,*) '**************************************************'
   ENDIF_MPI

   ! Initializations
   !----------------
   !phytomoy(:,:)  =0.0_rsh
   !phytocarre(:,:)=0.0_rsh
   cmes_3dmgl(:,:,:)  =0.0_rsh

   ! Modifications of global initializations
   !----------------------------------------
   IF(.NOT.l_initfromfile) THEN
                                    ! initialize dino and diat
     WHERE(cv_wat(iv_phyto_diat_N,:,:,:) < 0.5_rsh) cv_wat(iv_phyto_diat_N,:,:,:)=0.5_rsh
     cv_wat(iv_phyto_dino_N,:,:,:)=0.025_rsh


#if defined key_PREVI_alain
                                    ! initialize MES1 and Phosp. part. in Seine river seulement pour MANGA
     cv_wat(iv_phyto_diat_pp,:,345:362,231:238)=0.05_rsh
     cv_wat(iv_nutr_Pads, :,345:362,231:238)=0.35_rsh

                                    ! no diat dino and zoo in Seine river
     cv_wat(iv_phyto_diat_N,:,345:362,231:238)=0.0_rsh
     cv_wat(iv_phyto_dino_N,:,345:362,231:238)=0.0_rsh
     cv_wat(iv_phyto_nano_N,:,345:362,231:238)=0.0_rsh
                                   ! initialize MES1 and Phosp. part. in Loire river seulement pour MANGA
     cv_wat(iv_phyto_diat_pp,:,323:328,90:114)=0.05_rsh
     cv_wat(iv_nutr_Pads, :,323:328,90:114)=0.35_rsh

                                    ! no diat dino and zoo in Seine river
     cv_wat(iv_phyto_diat_N,:,323:328,90:114)=0.0_rsh
     cv_wat(iv_phyto_dino_N,:,323:328,90:114)=0.0_rsh
     cv_wat(iv_phyto_nano_N,:,323:328,90:114)=0.0_rsh
#endif

     ! Adaptation des parametres liee a la conversion des biomasses
     ! zooplanctoniques de microgrammes/L poids sec en micromoles/L azote
     p_mesz_mort2=p_mesz_mort2/p_zoo_CDWratio*p_zoo_CNratio*12.0_rsh

   END IF

   ! Read special files
   !-------------------
#if defined key_messat

   ! initialization satellite MES
   messat(:,:,:)=0.0_rsh
   DO i=imin,imax
     DO j=jmin,jmax
       IF (h0(i,j) > -valmanq) THEN
         messat(i,j,:)=0.002_rsh
       END IF
     END DO
   END DO

   ! read satellite MES
   !-------------------
   IF_MPI (MASTER) THEN
     WRITE(iscreenlog,*)'------------------------------------------------'
     WRITE(iscreenlog,*)'debut de lecture des donnees satellite MES'
     WRITE(iscreenlog,*)'          donnees en mg.l-1 '
   ENDIF_MPI

   OPEN(69,file='../../inputs/FORCAGES/climato_messat_roses.txt')
   READ(69,*)
   DO itmes=1,24440
     READ(69,12)i,j,lon,lat,(messatp(it),it=1,12)
     IF(h0(i,j) > -valmanq) THEN
       DO it=1,12
         IF (messatp(it) < 900.00_rsh) THEN
           messat(i,j,it)=messatp(it)/1000.0_rsh
         ELSE
           messat(i,j,it)=valmanq
           IF(h0(i,j) <= h0fond) messat(i,j,it)=valmanq
         END IF
       END DO
     END IF
   END DO
   IF_MPI (MASTER)WRITE(iscreenlog,*) 'lecmessat 1 ',messat(145,110,1:12)

   ! read monthly climatologies from SEAWiFS
   !----------------------------------------

   ! initialize name of file
   date_start=tool_sectodat(t)
   CALL tool_decompdate(date_start,ijour,imois,ian,iheure,iminu,isec)
   IF(imois.EQ.12) ian=ian+1
   WRITE(nomfic,102)ian

   IF_MPI (MASTER) THEN
     WRITE(iscreenlog,*)'------------------------------------------------'
     WRITE(iscreenlog,*)'lecture fichier climatologies mensuelles ', TRIM(nomfic)
     WRITE(iscreenlog,*)'pour annee',ian
   ENDIF_MPI

   !reading
   CALL ionc4_openr(nomfic)
   DO it=1,12
     CALL ionc4_read_xyt(nomfic,'MES',tab_mes,imin,imax,jmin,jmax,it)
     DO j=jmin,jmax
       DO i=imin,imax
         IF(h0(i,j).GT.-valmanq) THEN
           ! reinitialize cells for river mouths : escaut, tamise et seine
           IF ((j.EQ.45.AND.i.GE.103).OR.                                &
              (j.EQ.100.AND.i.GT.165).OR.                               &
              (j.EQ.102.AND.i.LT.110)) THEN
              messat(i,j,it)=0.03_rsh
           ! reinitialize cells for rade de Brest or for MES too low : min = 0.3 mg
           ELSE IF (i.GT.20.AND.j.LE.17.AND.j.GE.11.AND.it.LE.3)THEN
             IF (tab_mes(i,j) < 3.5_rsh)                                 &
               messat(i,j,it)=MAX(tab_mes(i,j)/1000.0_rsh,0.0035_rsh)
           ELSE
            IF (tab_mes(i,j).GT.0.0_rsh .AND. tab_mes(i,j).LT.30.0_rsh)         &
            messat(i,j,it)=tab_mes(i,j)/1000.0_rsh
            IF (tab_mes(i,j).EQ.0.0_rsh) WRITE(iscreenlog,*)'!!',i,j,it,tab_mes(i,j),h0(i,j)
           END IF
         END IF
       END DO
     END DO
   END DO

   !verification
   DO j=jmin,jmax
     DO i=imin,imax
       DO it=1,12
         IF (messat(i,j,it).LT.0.0_rsh) WRITE(iscreenlog,*)'pb maille ',i,j,it,messat(i,j,it) 
       END DO
     END DO
   END DO

   IF_MPI (MASTER) THEN
     WRITE(iscreenlog,*) 'lecmessat 2 ',messat(145,110,1:12)
     WRITE(iscreenlog,*) 'Fin de lecture des donnees satellite MES'
     WRITE(iscreenlog,*)itmes,' donnees MES lues'
     WRITE(iscreenlog,*)'-----------------------------------------------'
     WRITE(iscreenlog,*)''
   ENDIF_MPI

   CLOSE(69)
 102  FORMAT(                                                           &
     &'../../inputs/CLIM/Climato_mensuelle_SeaWiFS_interpole_',i4,'.nc')
12    FORMAT(i3,1x,i3,2x,f6.3,2x,f6.3,12(1x,f7.3))

   CALL_MPI ex_i_rsh(-1,2,nb_var*kmax,liminm1,limaxp2,ljminm1,ljmaxp2,cv_wat(:,:,liminm1:limaxp2,ljminm1:ljmaxp2))
   CALL_MPI ex_j_rsh(-1,2,nb_var*kmax,liminm1,limaxp2,ljminm1,ljmaxp2,cv_wat(:,:,liminm1:limaxp2,ljminm1:ljmaxp2))

#endif

#else
  WRITE(iscreenlog,*) 'biolo_init_dinodiatzoo : You should not have seen this print! error?'
#endif

  END SUBROUTINE biolo_init_dinodiatzoo

#endif

 END MODULE

