 MODULE biolodyncellwat

#if defined key_substance && defined key_biolo
   !!======================================================================
   !!                   ***  MODULE  biolodyn  ***
   !! Biologic dynamics: Calcul des variations dues aux phenomenes biologiques
   !!                    ayant lieu a l interieur d une maille dans l eau
   !!======================================================================
   !! * Modules used
   USE parameters,   ONLY : rsh,rlg,kmax,epsilon
   USE comvars2d,    ONLY : h0,t,cdate,jjulien,iheure,imois,ijour,ian,iminu,isec
   USE comsubstance, ONLY : irk_mod,dtbio,nv_state,ws3,ws_free_min, ws_free_max
   USE bioloinit
   USE toolgeom,     ONLY : f_dzu

   IMPLICIT NONE
   PRIVATE

   !! * Accessibility
   PUBLIC biolo_dyn_cellwat ! routine called by biolo_sksc_wat.F90

   !! * Interface
   INTERFACE biolo_dyn_cellwat
!     MODULE PROCEDURE incellwat_dinodiatzoo
     MODULE PROCEDURE incellwat_nut4phy3zoo2
   END INTERFACE    

   !! * Shared module variables
   ! pas de temps biologique
   ! -------------------------------
   REAL(KIND=rlg)      :: dtbiojour
   CHARACTER(LEN=19)   ::  tool_sectodat 
    
   ! reporte dans bioloinit en PUBLIC
   ! REAL(KIND=rsh) :: rappaz,rapsiaz  

   INTEGER :: ibbenth,ibsurf
   
   ! epaisseur des couches et surface libre
   ! --------------------------------------
   REAL(KIND=rsh) :: epn

   ! profondeur colonne d eau
   ! ------------------------
   REAL(KIND=rsh) :: d
   
   ! variables temperature, salinite
   ! -------------------------------
   REAL(KIND=rsh) :: temper,tempabs,sali
   REAL(KIND=rsh) :: effetchaleur,effetturbidite
   
   ! variables phytoplancton
   ! -----------------------
   REAL(KIND=rsh) :: fact_phyto_ChlNratio
   REAL(KIND=rsh) :: rationdiat,diatmorteau,effetselnutdiat
   REAL(KIND=rsh) :: rationdino,dinomorteau
   REAL(KIND=rsh) :: rationnano,nanomorteau

 
#ifdef key_karenia
   REAL(KIND=rsh) :: rationkarenia,kareniamorteau,fractionno3karenia,fractionnh4karenia
   REAL(KIND=rsh) :: effetlumierekarenia,effetselnutkarenia,uptakeN,uptakeP
#endif
#ifdef key_psnz
   REAL(KIND=rsh) :: rationpsnz,psnzmorteau,fractionno3psnz,fractionnh4psnz,effetlumierepsnz,effetselnutpsnz
#endif
#ifdef key_phaeocystis
   REAL(KIND=rsh) :: rationphaeocystiscell,fractionno3phaeocystiscell,fractionnh4phaeocystiscell,phaeocystismortcell
   REAL(KIND=rsh) :: rationphaeocystiscolo,fractionno3phaeocystiscolo,fractionnh4phaeocystiscolo,phaeocystismortcolo
   REAL(KIND=rsh) :: initcolonie,effetlumierephaeocystis,phaeocystislysecolo,effetselnutphaeocystiscolo   
   REAL(KIND=rsh) :: effetselnutphaeocystiscell
#endif

#ifdef key_ulvas
   ! variables ulves
   ! ---------------
   REAL(KIND=rsh) :: ulvemorteau,ulvebenthmortsed,pompageazoteulve,pompageazoteulvebenth   
   REAL(KIND=rsh) :: rationulve,rationulvebenth,partulvessurface,vitessechuteulve,ulveresuspazote
   REAL(KIND=rsh) :: fractionno3,fractionnh4
#endif

   ! variables mesozooplancton
   ! -------------------------   
   REAL(KIND=rsh) :: rationmesozoo
   REAL(KIND=rsh) :: broumesozoodiat,broumesozoodino,broumesozoomicrozoo
   REAL(KIND=rsh) :: txmortmesozoo,assimilmesozoo,excretionmesozoo 
   REAL(KIND=rsh) :: rNC
     
#ifdef key_phaeocystis
   REAL(KIND=rsh) :: broumesozoophaeocolo
#endif
#ifdef key_karenia
   REAL(KIND=rsh) :: broumesozookarenia
#endif
#ifdef key_psnz
   REAL(KIND=rsh) :: broumesozoopsnz
#endif
   ! variables microzooplancton
   ! --------------------------
   REAL(KIND=rsh) :: rationmicrozoo,excretionmicrozoo
   REAL(KIND=rsh) :: txmortmicrozoo,broumicrozoonano
   REAL(KIND=rsh) :: broumicrozoodet,broumicrozoodiat,assimilmicrozoo
#ifdef key_phaeocystis
   REAL(KIND=rsh) :: broumicrozoophaeocell
#endif
#ifdef key_psnz
   REAL(KIND=rsh) :: broumicrozoopsnz
#endif       

   ! parametrisation broutage par benthos
   ! ------------------------------------
   REAL(kind=rsh) :: detresuspazote,detresusppho,vitessechutedet,vitessechutediat
   
   ! variables mineralisation
   ! ------------------------
   REAL(KIND=rsh) :: xnitrifeau,reminazdeteau,reminpdeteau,dissolsiliceeau 

   ! parametrisation broutage par benthos
   ! ------------------------------------
   REAL(KIND=rsh)           :: txfiltbenthij


#if defined key_NPbenth
   ! "mailles" de sediment 
   ! ---------------------
   REAL(KIND=rsh),PARAMETER :: epnsed=0.4_rsh ! epaisseur (m) de la "maille de sediment" (bricole)
   REAL(KIND=rsh),PARAMETER :: deltaz = 0.3_rsh    ! distance (m) fixe entre la maille de fond et le "sediment" (bricole)
#endif  
#if defined key_zostera
   ! "mailles" de sediment 
   ! ---------------------
   REAL(KIND=rsh),PARAMETER :: epnsed=0.4_rsh ! epaisseur (m) de la "maille de sediment" (bricole)
   REAL(KIND=rsh),PARAMETER :: deltaz = 0.3_rsh    ! distance (m) fixe entre la maille de fond et le "sediment" (bricole)
   REAL(KIND=rsh) :: Gross_Prod_zost,Leaf_Resp_zost,Root_Resp_zost
#endif

!ATTENTION
! Toutes les variables comunes au module (servant a plusieurs subroutines internes)
! doivent etre declarees en PRIVATE pour chaque thread OMP si elles dependent de i,j,k
! (donc differentes selon les processeurs OMP (ou threads)
!$OMP THREADPRIVATE(ibbenth,ibsurf,d,epn,sali,temper,tempabs,effetchaleur &
!$OMP ,effetturbidite,txfiltbenthij,fact_phyto_ChlNratio,rationdiat,diatmorteau &
!$OMP ,rationdino,dinomorteau,rationnano,nanomorteau &
#ifdef key_karenia
!$OMP ,kareniamorteau,fractionno3karenia,fractionnh4karenia,effetlumierekarenia &
!$OMP ,effetselnutkarenia,uptakeN,uptakeP,broumesozookarenia,rationkarenia  &
#endif
#ifdef key_psnz
!$OMP ,rationpsnz,psnzmorteau,fractionno3psnz,fractionnh4psnz  &
!$OMP ,effetlumierepsnz,effetselnutpsnz,broumicrozoopsnz,broumesozoopsnz  &
#endif
#ifdef key_phaeocystis
!$OMP ,rationphaeocystiscell,fractionno3phaeocystiscell,fractionnh4phaeocystiscell,phaeocystismortcell  &
!$OMP ,rationphaeocystiscolo,fractionno3phaeocystiscolo,fractionnh4phaeocystiscolo,phaeocystismortcolo  &
!$OMP ,initcolonie,effetlumierephaeocystis,phaeocystislysecolo,effetselnutphaeocystiscolo  & 
!$OMP ,effetselnutphaeocystiscell,broumicrozoophaeocell,broumesozoophaeocolo &
#endif
#if defined key_zostera
!$OMP ,Gross_Prod_zost,Leaf_Resp_zost,Root_Resp_zost  &
#endif
!$OMP ,rationmesozoo,broumesozoodiat,broumesozoodino,broumesozoomicrozoo,txmortmicrozoo,broumicrozoonano &
!$OMP ,broumicrozoodet,broumicrozoodiat,assimilmicrozoo,rationmicrozoo,excretionmicrozoo,detresuspazote &
!$OMP ,detresusppho,vitessechutedet,vitessechutediat,xnitrifeau,reminazdeteau,reminpdeteau,dissolsiliceeau  &
!$OMP ,assimilmesozoo,txmortmesozoo,effetselnutdiat,excretionmesozoo)


 CONTAINS


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

  SUBROUTINE incellwat_nut4phy3zoo2(km,im,jm,xe,txfiltbenth,c,dc)

   !&E---------------------------------------------------------------------
   !&E                 ***  ROUTINE incellwat_nut4phy3zoo2  ***
   !&E
   !&E ** Purpose : Calcul des variations dues aux phenomenes biologiques
   !&E              ayant lieu a l interieur d une maille dans l eau
   !&E
   !&E ** Description :
   !&E
   !&E ** Called by :
   !&E
   !&E ** External calls :
   !&E
   !&E ** Reference :
   !&E
   !&E ** History :
   !&E       !          (M. Sourisseau A. Menesguen P. Cugier) Original code
   !&E       !  2008-01 (M. Sourisseau) evolutions
   !&E       !  2008-05 (M. Sourisseau) link between microzoo and diatoms
   !&E       !  2012-10  (B. Thouvenin) fusion des versions biolo et mise a jour V906
   !&E       !  2013     (B.Thouvenin) mutiples modifications ane adjustments for OMP and other corrections 
   !&E       !  2013-09 (B.Thouvenin) integration of module tracer_N (A. Menesguen)
   !&E       !  2014-04 (B.Thouvenin) integration of module tracer_P (A. Menesguen) + update module Benthos
   !&E       !  2014-05 (B.Thouvenin) integration of key_zoo_prod (A. MENESGUEN)
   !&E       !  2014-05 (B.Thouvenin) update for option 1 (+ key_diatbenth) (A. MENESGUEN,  M. DUSSAUZ)
   !&E       !  2014-06 (B.Thouvenin) integration of zostere module  (+ key_zostera) (M. PLUS)
   !&E       !  2014-07 (A. Menesguen, M. Dussauz) effetturbidite get as an argument
   !&E       !  2015-03 (B. Thouvenin) integration of OysterDEB module (P. CUGIER)
   !&E       !  2015-03 (B. Thouvenin) integration of OysterSFG module (modele Scope for Growth de Barille, 1997) (A. MENESGUEN)
   !&E
   !&E---------------------------------------------------------------------
   !! * Modules used
   USE comsubstance, ONLY : attenuation,extinction,extinction_ave4d,alumplafond,cmes_3dmgl
   USE comvars2d,    ONLY : tdeb,hm
   USE comvarp2d,    ONLY : temp,sal
   USE comvarp3d,    ONLY : ect
#ifdef key_oyster_benthos
   USE comsubstance, ONLY : nbhuitre,nbhuitre2
   USE comvars2d,    ONLY : dx,dy
#elif key_oyster_DEB
   USE comsubstance, ONLY : nbhuitre
#elif key_oyster_SFG
   USE comsubstance, ONLY : nbhuitre
#endif
#if defined key_N_tracer
   USE parameters, ONLY : nb_var_tracerN 
#endif
#if defined key_P_tracer
   USE parameters, ONLY : nb_var_tracerP 
#endif

   !! * Arguments
   INTEGER, INTENT( in ) ::   km,im,jm      ! ocean spatial-step index
   REAL(KIND=rsh),             INTENT(in) :: xe     !ssh
   REAL(KIND=rsh),             INTENT(in) :: txfiltbenth
   REAL(KIND=rsh),DIMENSION(:),INTENT(in) :: c
   REAL(KIND=rsh),DIMENSION(:),INTENT(inout) :: dc

   !! * Local declarations
   !!----------------------------------------------------------------------
#if defined key_N_tracer || defined key_P_tracer
   INTEGER                  :: is,ivtra,iv_tra,iv_sign,ivage
#endif 

   ! indices de boucles
   ! ------------------
   INTEGER :: iv,k
      
   ! variables lumiere
   ! ------------------------
   REAL(KIND=rsh) :: fluxrelatifsurf,fluxrelatiffond
   REAL(KIND=rsh) :: effetlumierediat,effetlumieredino,effetlumierenano
   
   ! variables diatomees
   ! -------------------
   REAL(KIND=rsh) :: effetnitdiat,effetamdiat,diat_iksmith
   REAL(KIND=rsh) :: effetazotediat,effetsilice,effetphosphorediat
   REAL(KIND=rsh) :: pslimdiat,Si

   ! variables dinoflagelles
   ! -----------------------
   REAL(KIND=rsh) :: effetnitdino,effetamdino,effetselnutdino
   REAL(KIND=rsh) :: pslimdino,effetazotedino,dino_iksmith
   REAL(KIND=rsh) :: effetphosphoredino

   ! variables nano_pico_phytoplancton
   ! ---------------------------------
   REAL(KIND=rsh) :: effetnitnano,effetamnano,effetazotenano,effetselnutnano
   REAL(KIND=rsh) :: effetphosphorenano,pslimnano,nano_iksmith

   REAL(KIND=rsh) :: fractionno3diat, fractionno3dino,fractionno3nano
   REAL(KIND=rsh) :: fractionnh4diat, fractionnh4dino,fractionnh4nano

   ! variables mesozooplancton
   ! -------------------------   
   REAL(KIND=rsh) :: totproiebrut,totproie,fmesozoo
   REAL(KIND=rsh) :: captdiatmeso,captdino,captmicrozoo,captmicrozooN
   REAL(KIND=rsh) :: meso_kivlev
   
   ! variables microzooplancton
   ! --------------------------
   REAL(KIND=rsh) :: fmicrozoo,captnano,captdet,captdinomicro
   REAL(KIND=rsh) :: captdiatmicro,broumicrozoodino  
#ifdef key_psnz
   REAL(KIND=rsh) :: captpsnz
#endif
#ifdef key_phaeocystis
   REAL(KIND=rsh) :: captphaeocell,captphaeocolo
#endif     
#ifdef key_karenia
   REAL(KIND=rsh) :: captkarenia
#endif
#ifdef key_biolo_opt2
   REAL(KIND=rsh) :: dissolMOPeau  
#endif
   ! processus d adsorption/desorption
   ! ---------------------------------
   REAL(KIND=rsh) :: desorpeau,adsorpeau
   REAL(KIND=rsh) :: varads,cmaxdesorp,saturmesp,cmaxadsorp
   
#if ! defined key_biolo_opt2
   REAL(KIND=rsh)           :: p_mesz_thrN_turb
#endif
#if defined key_biolo_opt2
   ! sedimentation mat detr azotee derniere couche
   REAL(KIND=rsh) :: fractionDET_N
   REAL(KIND=rsh) :: fractionDET_P
   REAL(KIND=rsh) :: fractionDET_Si
   REAL(KIND=rsh) :: fractionDIAT_N
   REAL(KIND=rsh) :: fractionDIAT_P
   REAL(KIND=rsh) :: fractionDIAT_Si
#endif
#ifdef key_oyster_benthos
!   filtration benthos par huitres
!   -------------------------------
   REAL(KIND=rsh)           :: cmes1,colmat_huitre,effettemp_huitre,filtmes,filt
#endif   


  !! * Executable part

   ! test pour identification des mailles de fond
   ! --------------------------------------------
   ibbenth=0
   IF (km.eq.1) ibbenth=1

   ! test pour identification des mailles de surface
   ! -----------------------------------------------
   ibsurf=0
   IF (km.eq.kmax) ibsurf=1

   ! profondeur
   d=h0(im,jm)+xe
   IF(d<hm) THEN
    ! calcul en 2D
    epn=d
    ibbenth=1
    ibsurf=1
   ELSE
    epn=f_dzu(h0(im,jm),xe,km,im,jm)
   ENDIF
   
   ! calcul de la date en clair et conversion en jour
   ! ------------------------------------------------   
   !cdate = tool_sectodat(t)
   !CALL tool_decompdate(cdate,ijour,imois,ian,iheure,iminu,isec) 
   dtbiojour=dtbio/86400.0_rlg

   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
   ! saisir le code apres cette limite
   ! =================================
   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

   !+++++++++++++++++++++++++++++
   ! Calculs communs
   !+++++++++++++++++++++++++++++

   ! salinite
   sali=max(0.0_rsh,sal(km,im,jm))
IF(sali < p_sali_thhold_bio) THEN
   dc(iv_nutr_NH4)=0.0_rsh
   dc(iv_nutr_NO3)=0.0_rsh
   dc(iv_nutr_SiOH)=0.0_rsh
   dc(iv_nutr_PO4)=0.0_rsh
   dc(iv_nutr_Pads)=0.0_rsh
   dc(iv_phyto_nano_N)=0.0_rsh
   dc(iv_phyto_diat_N)=0.0_rsh
   dc(iv_phyto_dino_N)=0.0_rsh
   dc(iv_detr_N)=0.0_rsh
   dc(iv_detr_Si)=0.0_rsh
   dc(iv_detr_P)=0.0_rsh
   dc(iv_zoo_meso_N)=0.0_rsh
   dc(iv_zoo_micr_N)=0.0_rsh
   dc(iv_spim)=0.0_rsh
   dc(iv_phyto_nano_pp)=0.0_rsh
   dc(iv_phyto_dino_pp)=0.0_rsh
   dc(iv_phyto_diat_pp)=0.0_rsh
   dc(iv_phyto_nano_pp)=0.0_rsh
   diag_3d_wat(:,km,im,jm)=0.0_rsh
#if defined key_psnz
   dc(iv_phyto_psnz_N)=0.0_rsh
   dc(iv_phyto_psnz_Si)=0.0_rsh
   dc(iv_phyto_psnz_ad)=0.0_rsh
   dc(iv_phyto_psnz_pp)=0.0_rsh
#endif
#if defined key_karenia
   dc(iv_phyto_karenia_N)=0.0_rsh
   dc(iv_phyto_karenia_C)=0.0_rsh
   dc(iv_phyto_karenia_P)=0.0_rsh
   dc(iv_phyto_karenia_pp)=0.0_rsh
#endif
#if defined key_phaeocystis
   dc(iv_phyto_phaeocystis_colo_N)=0.0_rsh
   dc(iv_phyto_phaeocystis_cell_N)=0.0_rsh
   dc(iv_phyto_phaeocystis_mucus)=0.0_rsh
   dc(iv_phyto_phaeocystis_pp)=0.0_rsh
#endif
#if defined key_zoo_prod
   dc(iv_zoo_micr_ps)=0.0_rsh
   dc(iv_zoo_meso_ps)=0.0_rsh
#endif
#ifdef key_oxygen
   dc(iv_oxygen)=0.0_rsh
#endif
#ifdef key_benthos
   dc(iv_benth_N)=0.0_rsh
   dc(iv_benth_Si)=0.0_rsh
   dc(iv_benth_P)=0.0_rsh
#if defined key_diatbenth
   dc(iv_benth_phyto_diat_N)=0.0_rsh
#endif
#if defined key_NPbenth
   dc(iv_benth_NH4)=0.0_rsh
   dc(iv_benth_PO4)=0.0_rsh
#endif
#if defined key_zostera
   dc(iv_benth_phyto_diat_N)=0.0_rsh
   dc(iv_benth_NH4)=0.0_rsh
   dc(iv_benth_PO4)=0.0_rsh
#endif
#endif
#if defined key_N_tracer
          DO is=1,nb_source_tracerN
            DO ivtra=1,nb_var_tracerN 
             iv_tra=iv_tracer_N(ivtra,is)
             dc(iv_tra)=0.0_rsh
#ifdef key_age_tracer
             ivage=iv_age_N(ivtra,is)
             dc(ivage)=0.0_rsh
#endif
            ENDDO
          ENDDO
#endif
#if defined key_P_tracer
          DO is=1,nb_source_tracerP
            DO ivtra=1,nb_var_tracerP 
             iv_tra=iv_tracer_P(ivtra,is)
             dc(iv_tra)=0.0_rsh
#ifdef key_age_tracer
             ivage=iv_age_P(ivtra,is)
             dc(ivage)=0.0_rsh
#endif
            ENDDO
          ENDDO
#endif
ELSE

   ! temperature & effetchaleur
   tempabs=temp(km,im,jm)+273.15_rsh
   temper=max(0.0_rsh,temp(km,im,jm))
   ! 
   IF (temper > 30.0_rsh) THEN
    write(*,*) '!!!!!tempwat>30 !!!!!!! (forcee a 15degres)',ijour,imois,iheure,km,im,jm,temper
    temper=15.0_rsh
    tempabs=temper+273.15_rsh                 
   ENDIF
   effetchaleur=exp(p_T_effect*temper)
#ifdef key_physadaptation
     effetturbidite=extinction(km,im,jm)/p_phyto_ChlN_ksmithextinct/   &
                    (sqrt(1+(extinction(km,im,jm)/p_phyto_ChlN_ksmithextinct)**2))
#else
     IF(l_ChlNratio_var) THEN
         effetturbidite=extinction(km,im,jm)/p_phyto_ChlN_ksmithextinct/   &
                     (sqrt(1+(extinction(km,im,jm)/p_phyto_ChlN_ksmithextinct)**2))
     ELSE
         effetturbidite=1.0_rsh
     ENDIF
#endif

   ! facteurs de conversion deja calcules une seule fois dans bioloinit 
   ! au moment de la lecture des parametres
   !rapsiaz=p_phyto_SiNratio
   !rappaz=1.0_rsh/p_phyto_NPratio

#if defined key_sedim_MUSTANG && ! defined key_sedim_partial
   txfiltbenthij=0.0_rsh
#elif ! defined key_biolo_opt2  
   !IF(l_filtbenthsinusmes) THEN
     ! Introduction d une pression de Broutage, d apres Marie SAVINA
     ! -------------------------------------------------------------  
     ! txfiltbenth = taux sinusoidal de filtration du benthos en m3/j/m2
     ! deja calcule quelque soit i,j,k dans biolosinksource
     !foncsinus=(1.0_rsh+SIN(2.0_rsh*3.14159_rsh/365.0_rsh*(jjulien-125)))/2.0_rsh
     !txfiltbenth=(p_txfiltbenthmax*(0.3_rsh+0.7_rsh*foncsinus))

     ! and txfiltbenth fonction des MES (filtration baisse avec la turbiditÃ©)
      txfiltbenthij=MAX(-0.0333_rsh*cmes_3dmgl(km,im,jm)+1,0.0_rsh)*txfiltbenth  !de 0 mg/L a 30 mg/L
   !ENDIF
#else
   txfiltbenthij=txfiltbenth
#endif

!   Filtrage benthique par huitres/moules/crepidules
!  ==================================================
    IF (ibbenth.eq.1) THEN

    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    !!!!!!!!     HUITRES     !!!!!!!!!!!!!!!!
    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#ifdef key_oyster_benthos
      IF(nbhuitre(im,jm).ne.0.0_rsh) THEN

          cmes1=c(iv_spim)*1000.0_rsh  !c passe en mg/l
          colmat_huitre=min(0.,(p_huitre_thr_colmat-cmes1))        
          effettemp_huitre=p_huitre_temp1*(temper-p_huitre_temp_opt)**2
          IF (cmes1.gt.p_huitre_thr_mes) THEN
            filtmes=p_huitre_loi_mes1*cmes1+p_huitre_loi_mes2
          ELSE
            filtmes=p_huitre_filt_std
          ENDIF
          filt=filtmes-effettemp_huitre
          filt=filt*(p_huitre_DW**p_huitre_exp_allom)
          filt=filt*exp(p_huitre_loi_colmat*colmat_huitre)
          filt=max(filt,0.)
          txfiltbenthij=filt*nbhuitre(im,jm)*24.0_rsh*1.e-3/(dx(im,jm)*dy(im,jm))
          write(*,*)'i,j,filt,txfiltbenthij=',im,jm,filt,txfiltbenthij
      ENDIF
#endif
      IF(id_benthos_txf .NE. 0)diag_2d(irk_diag(id_benthos_txf),im,jm)=txfiltbenthij/epn
    ENDIF

   !++++++++++++++++++++++++++++++++++++++++++++++++++++++
   ! Croissance et mortalite du phytoplancton de base
   !++++++++++++++++++++++++++++++++++++++++++++++++++++++
#ifdef key_ulvas
   IF (c(iv_nutr_NO3) .ne. 0.0_rsh .or. c(iv_nutr_NH4) .ne. 0.0_rsh) THEN
     fractionno3=c(iv_nutr_NO3)/(c(iv_nutr_NO3)+c(iv_nutr_NH4))
     fractionnh4=c(iv_nutr_NH4)/(c(iv_nutr_NO3)+c(iv_nutr_NH4))
   ELSE
     fractionno3=0.0_rsh
     fractionnh4=0.0_rsh
   END IF
#endif

   ! DIATOMEES
   ! ---------
   ! Effetlumiere formulation de Steele
   ! Formulation de Smith integree sur la profondeur de la boite
   !  avec l hypothese que Ik=Iopt/2.5
   ! ............................................................
#ifdef key_physadaptation
! Cas ou Ik varie selon la turbidite et la saison
   diat_iksmith=p_diat_iksmith*(1.0_rsh+0.5_rsh*SIN(2.0_rsh*3.14159_rsh/365.0_rsh*(jjulien-100)))  &
                *(1.0_rsh-effetturbidite/2.0_rsh )  
!               *(1.0_rsh-effetturbidite )
!   diat_iksmith=p_diat_iksmith*(1.0_rsh-effetturbidite)
#else
   diat_iksmith=p_diat_iksmith
#endif

   fluxrelatifsurf=p_parradratio*alumplafond(km,im,jm)/(diat_iksmith+0.0000000001_rsh)
   fluxrelatiffond=fluxrelatifsurf*attenuation(km,im,jm)
   effetlumierediat=1.0_rsh/epn/extinction(km,im,jm)*                     &
      log((fluxrelatifsurf+sqrt(1.0_rsh+fluxrelatifsurf*                  &
      fluxrelatifsurf))/(fluxrelatiffond+                                 &
      sqrt(1.0_rsh+fluxrelatiffond*fluxrelatiffond)))

    IF ((effetlumierediat.lt.0.0_rsh).or.(effetlumierediat.gt.1.0_rsh)) &
    print*,'effetlumierediat=',effetlumierediat,'im,jm,km=',im,jm,km,'alumplafond=',alumplafond(km,im,jm) &
                              ,'epn=',epn,'attenuation=',attenuation(km,im,jm)                           &
                              ,'diat_iksmith',diat_iksmith,'extinction(km,im,jm)',extinction(km,im,jm)   &
                              ,'fluxrelatifsurf',fluxrelatifsurf,'fluxrelatiffond',fluxrelatiffond


   effetnitdiat=c(iv_nutr_NO3)/(c(iv_nutr_NO3)+p_diat_kNO3+               &
                   (c(iv_nutr_NH4)*p_diat_kNO3/p_diat_kNH4))
   effetamdiat=c(iv_nutr_NH4)/(c(iv_nutr_NH4)+p_diat_kNH4+                &
                   (c(iv_nutr_NO3)*p_diat_kNH4/p_diat_kNO3))
   effetazotediat=effetnitdiat+effetamdiat
#if ! defined key_biolo_opt2
   Si=max(0.0_rsh,c(iv_nutr_SiOH))
   effetsilice=Si/(Si+p_diat_kSi)
#else
   effetsilice=c(iv_nutr_SiOH)/(c(iv_nutr_SiOH)+p_diat_kSi)
#endif
   effetphosphorediat=c(iv_nutr_PO4)/(c(iv_nutr_PO4)+p_diat_kPO4)

   effetselnutdiat=min(effetazotediat,effetsilice,effetphosphorediat)

   pslimdiat=min(effetlumierediat,effetselnutdiat)
   rationdiat=p_diat_mumax*effetchaleur*pslimdiat
!!ESSAI MORGAN 31/10/2013 pour mer du Nord
! rationdiat=p_diat_mumax*max(exp(p_T_effect*10.0_rsh),effetchaleur)*pslimdiat  

!#if defined key_biolo_opt2
   diatmorteau=p_diat_mort*effetchaleur
!#else
!   diatmorteau=p_diat_mortmax*(1-effetselnutdiat**0.2)
!#endif
   IF(c(iv_phyto_diat_N).le.p_diat_thhold_mort) diatmorteau=0.0_rsh

!   xintvertdiat=14.e-3*rationdiat*c(iv_phyto_diat_N)*epn

   ! DINOFLAGELLES
   ! -------------
   ! Effetlumiere formulation de Steele

   ! Formulation de Smith integree sur la profondeur de la boite
   !  avec l hypothese que Ik=Iopt/2.5
   ! ............................................................
!#ifdef key_physadaptation
   ! Cas ou Ik varie selon la turbidite  
!   dino_iksmith=p_dino_iksmith*(1.0_rsh-effetturbidite)
!#else
   dino_iksmith=p_dino_iksmith
!#endif
   fluxrelatifsurf=p_parradratio*alumplafond(km,im,jm)/(dino_iksmith+0.0000000001_rsh)
   fluxrelatiffond=fluxrelatifsurf*attenuation(km,im,jm)
   effetlumieredino=1.0_rsh/epn/extinction(km,im,jm)*                     &
      log((fluxrelatifsurf+sqrt(1.0_rsh+fluxrelatifsurf*                  &
      fluxrelatifsurf))/(fluxrelatiffond+                                 &
      sqrt(1.0_rsh+fluxrelatiffond*fluxrelatiffond)))

   IF ((effetlumieredino.lt.0.0_rsh).or.(effetlumieredino.gt.1.0_rsh)) &
   print*,'effetlumieredino=',effetlumieredino,'km=',km,'alumplafond=',alumplafond(km,im,jm),  &
          'epn=',epn,'attenuation=',attenuation(km,im,jm)

   effetnitdino=c(iv_nutr_NO3)/(c(iv_nutr_NO3)+p_dino_kNO3+                                 &
                   (c(iv_nutr_NH4)*p_dino_kNO3/p_dino_kNH4))
   effetamdino=c(iv_nutr_NH4)/(c(iv_nutr_NH4)+p_dino_kNH4+                                &
                   (c(iv_nutr_NO3)*p_dino_kNH4/p_dino_kNO3))
   effetazotedino=effetnitdino+effetamdino 
   effetphosphoredino=c(iv_nutr_PO4)/(c(iv_nutr_PO4)+p_dino_kPO4)
   effetselnutdino=min(effetazotedino,effetphosphoredino)
   pslimdino=min(effetlumieredino,effetselnutdino)
   rationdino=p_dino_mumax*effetchaleur*pslimdino

#if ! defined key_biolo_opt2
  ! taux max de croissance diminue dans les zones a forte ECT(croissance nulle pour ect.ge.0.0005 m2.s-2)
  ! rationdino=rationdino*max(0.0_rsh,(1.0_rsh-ect(km,im,jm)/0.0005_rsh)) !!rationdino2 et 4
  ! version Alain 23 octobre 2015
   rationdino=rationdino*max(0.0_rsh,(1.0_rsh-ect(km,im,jm)/0.002_rsh))
#endif

   dinomorteau=p_dino_mort*effetchaleur

   IF(c(iv_phyto_dino_N).le.p_dino_thhold_mort) dinomorteau=0.0_rsh

!   xintvertdino=14.e-3*rationdino*c(iv_phyto_dino_N)*epn

   ! NANOPICOPLANCTON
   ! ----------------
   ! Formulation de Smith integree sur la profondeur de la boite
   !  avec l hypothese que Ik=Iopt/2.5
   ! ............................................................
!#ifdef key_physadaptation
!   nano_iksmith=p_nano_iksmith*(1.0_rsh-effetturbidite)
!#else
   nano_iksmith=p_nano_iksmith
!#endif
   fluxrelatifsurf=p_parradratio*alumplafond(km,im,jm)/(nano_iksmith+0.0000000001_rsh)
   fluxrelatiffond=fluxrelatifsurf*attenuation(km,im,jm)
   effetlumierenano=1.0_rsh/epn/extinction(km,im,jm)*                     &
      log((fluxrelatifsurf+sqrt(1.0_rsh+fluxrelatifsurf*                  &
      fluxrelatifsurf))/(fluxrelatiffond+                                 &
      sqrt(1.0_rsh+fluxrelatiffond*fluxrelatiffond)))

   IF ((effetlumierenano.lt.0.0_rsh).or.(effetlumierenano.gt.1.0_rsh)) &
   print*,'effetlumierenano=',effetlumierenano,'km=',km,'alumplafond=',alumplafond(km,im,jm),  &
           'epn=',epn,'attenuation=',attenuation(km,im,jm)



   effetnitnano=c(iv_nutr_NO3)/(c(iv_nutr_NO3)+p_nano_kNO3+                                 &
                     (c(iv_nutr_NH4)*p_nano_kNO3/p_nano_kNH4))
   effetamnano=c(iv_nutr_NH4)/(c(iv_nutr_NH4)+p_nano_kNH4+                                &
                     (c(iv_nutr_NO3)*p_nano_kNH4/p_nano_kNO3))
   effetazotenano=effetnitnano+effetamnano

   effetphosphorenano=c(iv_nutr_PO4)/(c(iv_nutr_PO4)+p_nano_kPO4)
   effetselnutnano=min(effetazotenano,effetphosphorenano)
   pslimnano=min(effetlumierenano,effetselnutnano)
   rationnano=p_nano_mumax*effetchaleur*pslimnano

   IF (effetazotediat.gt.0.000001_rsh) THEN
           fractionno3diat=effetnitdiat/effetazotediat
           fractionnh4diat=effetamdiat/effetazotediat
   ELSE
           fractionno3diat=0.0_rsh
           fractionnh4diat=0.0_rsh
   ENDIF
   IF (effetazotedino.gt.0.000001_rsh) THEN
           fractionno3dino=effetnitdino/effetazotedino
           fractionnh4dino=effetamdino/effetazotedino
   ELSE
           fractionno3dino=0.0_rsh
           fractionnh4dino=0.0_rsh
   ENDIF
   IF (effetazotenano.gt.0.000001_rsh) THEN
           fractionno3nano=effetnitnano/effetazotenano
           fractionnh4nano=effetamnano/effetazotenano
   ELSE
           fractionno3nano=0.0_rsh
           fractionnh4nano=0.0_rsh

   ENDIF

   nanomorteau=p_nano_mort*effetchaleur
   IF (c(iv_phyto_nano_N).lt.p_nano_thhold_mort) nanomorteau=0.0_rsh

!   xintvertnano=14.e-3*rationnano*c(iv_phyto_nano_N)*epn

   !+++++++++++++++++++++++++++++++++++++++++++++
   ! Croissance et mortalite du zooplancton
   !+++++++++++++++++++++++++++++++++++++++++++++

   ! MESOZOOPLANCTON
   ! ----------------
! concentrations de proies visibles 
#if defined key_biolo_opt2
! limitation excretion par rapport au broutage (virg 17sept2011) entre autre sur les mcrozoo

   IF (c(iv_phyto_diat_N) .gt. 0.01_rsh) THEN
     captdiatmeso=c(iv_phyto_diat_N)*p_mesz_captdiat        !en microMolN.l-1
   ELSE
     captdiatmeso=0.0_rsh
   ENDIF
   IF (c(iv_phyto_dino_N) .gt. 0.01_rsh) THEN 
     captdino=c(iv_phyto_dino_N)*p_mesz_captdino        !en microMolN.l-1
   ELSE
     captdino=0.0_rsh
   ENDIF
   rNC=1.0_rsh/(12.0_rsh*p_zoo_CNratio)  !en micromolN.microgC-1
   ! dans l option 2 le zoo est exprime en carbone
   IF((c(iv_zoo_micr_N)*rNC) .gt. 0.01_rsh) THEN
     captmicrozoo=c(iv_zoo_micr_N)*p_mesz_captmicz   !en microMolN.l-1
   ELSE
     captmicrozoo=0.0_rsh
   ENDIF
   captmicrozooN=captmicrozoo*rNC    ! en microMolN.l-1
   totproiebrut=captdiatmeso+captdino+captmicrozooN
#else
   captdiatmeso=c(iv_phyto_diat_N)*p_mesz_captdiat        !en microMolN.l-1
   captdino=c(iv_phyto_dino_N)*p_mesz_captdino        !en microMolN.l-1
   captmicrozoo=c(iv_zoo_micr_N)*p_mesz_captmicz   !en microMolN.l-1
   rNC=1.0_rsh
   captmicrozooN=captmicrozoo*rNC    ! en microMolN.l-1
   ! dans l option 1 le zoo est exprime en azote
   totproiebrut=captdiatmeso+captdino+captmicrozoo
   p_mesz_thrN_turb=p_mesz_thrN*effetturbidite
#endif

#ifdef key_psnz
   captpsnz=c(iv_phyto_psnz_N)*p_mesz_captdiat
   !! test Alain ??captpsnz=c(iv_phyto_psnz_N)*p_mesz_captdiat/5.0_rsh
   totproiebrut=totproiebrut+captpsnz
#endif
#ifdef key_phaeocystis   
   captphaeocolo=c(iv_phyto_phaeocystis_colo_N)*p_mesz_captphaeocolo   ! microMolN.l-1
   totproiebrut=totproiebrut+captphaeocolo
#endif
#ifdef key_karenia
  ! Cas de predation identique sur Karenia et autres dinoflagelles
    captkarenia=c(iv_phyto_karenia_N)*p_mesz_captdino
  ! Cas de predation nulle sur Karenia
  ! captkarenia=0.0_rsh
   totproiebrut=totproiebrut+captkarenia
#endif


!   IF (captdiatmeso.ne.0.0_rsh .or. captdino.ne.0.0_rsh .or. captmicrozooN.ne.0.0_rsh) THEN
#if defined key_biolo_opt2
   totproie=totproiebrut
   IF (totproiebrut .gt.0.005_rsh) THEN
#else
   totproie=max(0.0_rsh,(totproiebrut-p_mesz_thrN_turb)) ! en microgMolN.l-1
   IF (totproie .ne. 0.0_rsh) THEN
#endif

      ! Cas ou le parametre d Ivlev varie selon la turbidite
#ifdef key_physadaptation
     IF (cmes_3dmgl(km,im,jm).le.p_mesz_thhold_mes_kivlev) THEN
         meso_kivlev=p_mesz_kivlev
     ELSE
        meso_kivlev=p_mesz_kivlev*min(1.0_rsh,(1.0_rsh-effetturbidite))
     ENDIF
       ! meso_kivlev=p_mesz_kivlev*min(1.0_rsh,(1.0_rsh-(extinction(km,im,jm)-0.5_rsh)/p_phyto_ChlN_ksmithextinct/   &
     !!  (sqrt(1+((extinction(km,im,jm)-0.5_rsh)/p_phyto_ChlN_ksmithextinct)**2))))
     !!   meso_kivlev=max(0.02_rsh,-cmes_3dmgl(km,im,jm)*0.023_rsh+0.25_rsh)
     !!   meso_kivlev=max(0.02_rsh,-cmes_3dmgl(km,im,jm)*0.023_rsh+p_mesz_kivlev)
     !!   meso_kivlev=min(p_mesz_kivlev,0.05_rsh/(((cmes_3dmgl(km,im,jm)+1.e-10_rsh)/5.0_rsh) &
     !!             /sqrt(1+((cmes_3dmgl(km,im,jm)/5.0_rsh)**2))))
#else
      meso_kivlev=p_mesz_kivlev
#endif

      fmesozoo=1.0_rsh-exp(-meso_kivlev*totproie)              ! food lim [0-1]
      rationmesozoo=p_mesz_mumax*effetchaleur*fmesozoo     ! specif growth rate d-1
#if defined key_biolo_opt2
!     Cas ou le taux d assimilation varie selon le taux de repletion  
!     assimilation depend de quantitee ingeree Hofmann & Hambler, 1988 J.M.R  
         assimilmesozoo=0.3_rsh*(3.0_rsh-0.67_rsh*fmesozoo)       ! ass rate s.u.
#else
!      assimilation constante
!         assimilmesozoo=p_mesz_assim
        assimilmesozoo=0.3_rsh*(3.0_rsh-0.67_rsh*fmesozoo)       ! ass rate s.u.
#endif
      broumesozoodiat=rationmesozoo*captdiatmeso/totproiebrut                 ! d-1
      broumesozoodino=rationmesozoo*captdino/totproiebrut                 ! d-1
      ! captmicrozooN=captmicrozoo dans option 1 : converti en azote dans l option2
      broumesozoomicrozoo=rationmesozoo*captmicrozooN/totproiebrut         ! d-1
#ifdef key_psnz   
      broumesozoopsnz=rationmesozoo*captpsnz/totproiebrut                 ! d-1   
#endif
#ifdef key_karenia   
      broumesozookarenia=rationmesozoo*captkarenia/totproiebrut                 ! d-1   
#endif
#ifdef key_phaeocystis   
      broumesozoophaeocolo=rationmesozoo*captphaeocolo/totproiebrut       ! d-1   
#endif

   ELSE
     totproiebrut=0.0_rsh
     totproie=0.0_rsh
     fmesozoo=0.0_rsh
     assimilmesozoo=0.0_rsh
     rationmesozoo=0.0_rsh
     broumesozoodiat=0.0_rsh
     broumesozoodino=0.0_rsh
     broumesozoomicrozoo=0.0_rsh
#ifdef key_psnz   
     broumesozoopsnz=0.0_rsh   
#endif
#ifdef key_karenia   
     broumesozookarenia=0.0_rsh                 ! d-1   
#endif
#ifdef key_phaeocystis   
     broumesozoophaeocolo=0.0_rsh   
#endif
   ENDIF

   excretionmesozoo=p_mesz_excret*effetchaleur*fmesozoo ! specif excret rate d-1
!   txmortmesozoo=max(p_mesz_mort1*effetchaleur,p_mesz_mort2*effetchaleur*c(iv_zoo_meso_N)) ! specif mort rate d-1
   txmortmesozoo=(p_mesz_mort1+p_mesz_mort2*c(iv_zoo_meso_N))*effetchaleur ! specif mort rate d-1

   IF (c(iv_zoo_meso_N).lt.p_mesz_thhold_mort)  txmortmesozoo=0.0_rsh ! ATTENTION bidouille


   ! MICROZOOPLANCTON
   ! ----------------
! concentrations de proies visibles 
#if defined key_biolo_opt2
! limitation excretion par rapport au broutage (virg 17sept2011) entre autre sur les mcrozoo
   IF (c(iv_phyto_nano_N) .gt. 0.01_rsh) THEN 
     captnano=c(iv_phyto_nano_N)*p_micz_captnano                     !en microMolN.l-1
   ELSE
     captnano=0.0_rsh
   ENDIF
   IF (c(iv_detr_N).gt.0.01_rsh) THEN
     captdet=min(c(iv_detr_N),c(iv_detr_P)*p_phyto_NPratio)*p_micz_captdet     !en microMolN.l-1
   ELSE
     captdet=0.0_rsh 
   ENDIF
   IF(c(iv_phyto_diat_N) .gt. 0.01_rsh) THEN
     captdiatmicro=c(iv_phyto_diat_N)*p_micz_captdiat    ! microMolN.l-1
   ELSE
     captdiatmicro=0.0_rsh
   ENDIF
   captdinomicro=0.0_rsh
   totproiebrut=(captnano+captdet+captdiatmicro)
#else
   captnano=c(iv_phyto_nano_N)*p_micz_captnano                     !en microMolN.l-1
   captdet=min(c(iv_detr_N),c(iv_detr_P)*p_phyto_NPratio)*p_micz_captdet     !en microMolN.l-1
   !captdinomicro=c(iv_phyto_dino_N)*p_mesz_captdino*2.0_rsh        !en microMolN.l-1
   ! modif Alain Octobre 2015
   captdinomicro=c(iv_phyto_dino_N)*p_mesz_captdino                          !en microMolN.l-1
#if defined key_physadaptation
   !captdiatmicro=0.0_rsh
!   IF (h0(im,jm).gt.60.0_rsh) captdiatmicro=c(iv_phyto_diat_N)*p_micz_captdiat    ! microMolN.l-1
   ! Modulation de la capturabilite des diatomees par la profondeur (grosses especes cotieres, petites oceaniques)
   captdiatmicro=c(iv_phyto_diat_N)*p_micz_captdiat*(.01_rsh+.99_rsh*min(200.0_rsh,h0(im,jm))/200.0_rsh)
#else
   captdiatmicro=c(iv_phyto_diat_N)*p_micz_captdiat    ! microMolN.l-1
#endif	        
   totproiebrut=captdiatmicro+captnano+captdet+captdinomicro
#endif

#ifdef key_psnz
#if defined key_biolo_opt2
   captpsnz=c(iv_phyto_psnz_N)*p_micz_captnano
#else
!   captpsnz=c(iv_phyto_psnz_N)*p_micz_captnano
   !captpsnz=0.0_rsh
   !if (h0(im,jm).gt.60.0_rsh) captpsnz=c(iv_phyto_psnz_N)*p_micz_captdiat    ! microMolN.l-1
   IF(c(iv_phyto_psnz_N) .gt. 0.01_rsh) THEN
     captpsnz=c(iv_phyto_psnz_N)*p_micz_captdiat
   ELSE
     captpsnz=0.0_rsh
   ENDIF    
   ! modif alain 20 octobre 2015
   ! Modulation de la capturabilite des diatomees par la profondeur (grosses especes cotieres, petites oceaniques)
   captpsnz=c(iv_phyto_psnz_N)*p_micz_captdiat*(.01_rsh+.99_rsh*min(200.0_rsh,h0(im,jm))/200.0_rsh)
#endif
   totproiebrut=totproiebrut+captpsnz
#endif
#ifdef key_phaeocystis   
   IF(c(iv_phyto_phaeocystis_cell_N) .gt. 0.01_rsh) THEN
     captphaeocell=c(iv_phyto_phaeocystis_cell_N)*p_micz_captnano               ! microMolN.l-1
   ELSE
     captphaeocell=0.0_rsh
   ENDIF   
   totproiebrut=totproiebrut+captphaeocell
#endif
#if defined key_biolo_opt2
   totproie=totproiebrut
   IF (totproiebrut .gt.0.005_rsh) THEN
#else
   totproie=max(0.0_rsh,(totproiebrut-p_micz_thrnano)) ! en microgMolN.l-1
   IF (totproie .ne. 0.0_rsh) THEN
#endif
      fmicrozoo=totproie/(p_micz_kgraz+totproie)                              ! food lim [0-1]
      rationmicrozoo=p_micz_mumax*effetchaleur*fmicrozoo      ! specif growth rate d-1
#if defined key_biolo_opt2
!  version  assimilation constante
      assimilmicrozoo=p_micz_assim
#else
!  assimilation depend de quantitee ingeree Hofmann & Hambler, 1988 J.M.R  
      assimilmicrozoo=0.3_rsh*(3.0_rsh-0.67_rsh*fmicrozoo)        ! ass rate s.u.
#endif
      broumicrozoonano=rationmicrozoo*captnano/totproiebrut                   ! d-1
      broumicrozoodet=rationmicrozoo*captdet/totproiebrut                     ! d-1
      broumicrozoodiat=rationmicrozoo*captdiatmicro/totproiebrut                   ! d-1
      broumicrozoodino=rationmicrozoo*captdinomicro/totproiebrut                   ! d-1
#ifdef key_psnz   
      broumicrozoopsnz=rationmicrozoo*captpsnz/totproiebrut                 ! d-1   
#endif
#ifdef key_phaeocystis   
      broumicrozoophaeocell=rationmicrozoo*captphaeocell/totproiebrut         ! d-1   
#endif
   ELSE
      fmicrozoo=0.0_rsh
      assimilmicrozoo=0.0_rsh
      rationmicrozoo=0.0_rsh
      broumicrozoonano=0.0_rsh
      broumicrozoodet=0.0_rsh
      broumicrozoodiat=0.0_rsh
      broumicrozoodino=0.0_rsh
#ifdef key_psnz   
      broumicrozoopsnz=0.0_rsh   
#endif
#ifdef key_phaeocystis   
      broumicrozoophaeocell=0.0_rsh   
#endif
   ENDIF

   excretionmicrozoo=p_micz_excret*effetchaleur*fmicrozoo ! specif excret rate d-1
   txmortmicrozoo=(p_micz_mort+p_mesz_mort2*c(iv_zoo_micr_N))*effetchaleur! specif excret rate d-1

   IF (c(iv_zoo_micr_N).lt.p_micz_thhold_mort) txmortmicrozoo=0.0_rsh ! ATTENTION bidouille

#if defined key_oxygen
   IF (c(iv_oxygen).lt.0.2_rsh) THEN
      txmortmicrozoo=100.0_rsh*txmortmicrozoo
      txmortmesozoo=100.0_rsh*txmortmesozoo  
   ENDIF
#endif
   !+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   ! Remineralisation de la matiere detritique dans l eau
   !+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

   reminazdeteau=p_N_remin*effetchaleur
   xnitrifeau=p_nitrifwat*effetchaleur

   reminpdeteau=p_P_remin*effetchaleur

   dissolsiliceeau=p_Si_diss*effetchaleur
   
#if defined key_biolo_opt2
   dissolMOPeau=p_det_fragm*effetchaleur
#endif
#if defined key_oxygen
   IF (c(iv_oxygen).lt.0.2_rsh) THEN
      reminazdeteau=0.0_rsh
      xnitrifeau=0.0_rsh
      reminpdeteau=0.0_rsh  
   ENDIF
#endif


   !+++++++++++++++++++++++++++++++++++++++++++++++++++++++
   ! Adsorption et desorption du phosphore dans l eau
   !+++++++++++++++++++++++++++++++++++++++++++++++++++++++

   ! adsorption
   saturmesp=max(0.0_rsh,(p_P_adsormaxspim*c(iv_spim)-c(iv_nutr_Pads)))  !c(iv_spim) en g/l
   adsorpeau=p_P_adsor*saturmesp
   cmaxadsorp=adsorpeau*c(iv_nutr_PO4)*dtbiojour
   IF (cmaxadsorp.ge.c(iv_nutr_PO4))  adsorpeau=0.9_rlg/dtbiojour

   ! desorption
   IF(c(iv_spim).gt.0.000001_rsh) THEN
     varads=min(1.0_rsh,c(iv_nutr_Pads)/(p_P_adsormaxspim*c(iv_spim)))
   ELSE
     varads=0.0_rsh
   END IF
   desorpeau=p_P_desor*varads
   cmaxdesorp=desorpeau*c(iv_nutr_Pads)*dtbiojour
   IF (cmaxdesorp.ge.c(iv_nutr_Pads)) desorpeau=0.9_rlg/dtbiojour


#if defined key_biolo_opt2
!INSERTION VS Nov2010
!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
!Calcule fraction de la matiere detr azotee qui va jusqu au fond
!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
!
   IF (km.eq.1) THEN 
   fractionDIAT_N=c(iv_phyto_diat_N)*(min((ws3(2,iv_phyto_diat_N,im,jm)*dtbio/epn),1.0_rsh))
   fractionDIAT_P=fractionDIAT_N*rappaz
   fractionDIAT_Si=fractionDIAT_N*rapsiaz
   fractionDET_N=c(iv_detr_N)*(min((ws3(2,iv_detr_N,im,jm)*dtbio/epn),1.0_rsh))
   fractionDET_Si=c(iv_detr_Si)*(min((ws3(2,iv_detr_Si,im,jm)*dtbio/epn),1.0_rsh))
   fractionDET_P=c(iv_detr_P)*(min((ws3(2,iv_detr_P,im,jm)*dtbio/epn),1.0_rsh))
   ELSE
   fractionDIAT_N=0.0_rsh
   fractionDIAT_P=0.0_rsh
   fractionDIAT_Si=0.0_rsh
   fractionDET_N=0.0_rsh
   fractionDET_Si=0.0_rsh
   fractionDET_P=0.0_rsh
   ENDIF
#endif

   !+++++++++++++++++++++++++++++++++++++++++++++++
   ! EQUATIONS D EVOLUTION  ! concentration en jour-1
   !+++++++++++++++++++++++++++++++++++++++++++++++

   ! Evolution de l ammonium
   ! -----------------------

    dc(iv_nutr_NH4)=-fractionnh4diat*rationdiat*c(iv_phyto_diat_N)            &
                   -fractionnh4dino*rationdino*c(iv_phyto_dino_N)            &
                   -fractionnh4nano*rationnano*c(iv_phyto_nano_N)            &
                   -xnitrifeau*c(iv_nutr_NH4)                                           &
                   +(excretionmesozoo*c(iv_zoo_meso_N)+excretionmicrozoo*c(iv_zoo_micr_N))*rNC &
#if defined key_biolo_opt2
                   +reminazdeteau*c(iv_diss_N)                               &                 
                   +(1.0_rsh-assimilmicrozoo)*rationmicrozoo*(1.0_rsh-p_micz_diss)*c(iv_zoo_micr_N)*rNC
#else
                   +reminazdeteau*c(iv_detr_N)
#endif


   ! Evolution du nitrate
   ! --------------------
   dc(iv_nutr_NO3)=xnitrifeau*c(iv_nutr_NH4)  &
                   -fractionno3diat*rationdiat*c(iv_phyto_diat_N)            &
                   -fractionno3dino*rationdino*c(iv_phyto_dino_N)            &
                   -fractionno3nano*rationnano*c(iv_phyto_nano_N)

   ! Evolution de la silice dissoute
   ! -------------------------------
   dc(iv_nutr_SiOH)= -rapsiaz*rationdiat*c(iv_phyto_diat_N)       &
#if defined key_biolo_opt2
                    +dissolsiliceeau*c(iv_diss_Si)
#else
                    +dissolsiliceeau*c(iv_detr_Si)
#endif

   ! Evolution du phosphate dissous
   ! ------------------------------
   dc(iv_nutr_PO4)=desorpeau*c(iv_nutr_Pads)            &
                  -adsorpeau*c(iv_nutr_PO4)             &
                  -rappaz*(rationdiat*c(iv_phyto_diat_N)+rationdino*c(iv_phyto_dino_N)+rationnano*c(iv_phyto_nano_N)) &
                  +rappaz*((excretionmesozoo*c(iv_zoo_meso_N)+excretionmicrozoo*c(iv_zoo_micr_N))*rNC)                &
#if defined key_biolo_opt2
                  +reminpdeteau*c(iv_diss_P)            &
                  +(1.0_rsh-assimilmicrozoo)*rationmicrozoo*(1.0_rsh-p_micz_diss)*c(iv_zoo_micr_N)*rappaz*rNC
#else
                  +reminpdeteau*c(iv_detr_P)
#endif

   ! Evolution du phosphate adsorbe
   ! --------
   dc(iv_nutr_Pads)=adsorpeau*c(iv_nutr_PO4)-desorpeau*c(iv_nutr_Pads)

   ! Evolution de l azote du nano_pico_phytoplancton  (micromolN.l-1)
   ! -----------------------------------------------------------------
   dc(iv_phyto_nano_N)=c(iv_phyto_nano_N)*(rationnano-nanomorteau)-broumicrozoonano*c(iv_zoo_micr_N)*rNC
#if ! defined key_biolo_opt2 && (! defined key_sedim_MUSTANG || defined key_sedim_partial) 
!  pas de prise en compte du filtrage benthique ici si key_sedim_MUSTANG et Bio dans sedim (sera avec la bio dans les sediments)
   dc(iv_phyto_nano_N)=dc(iv_phyto_nano_N)-txfiltbenthij*ibbenth/epn*c(iv_phyto_nano_N)
#endif

   ! Evolution de l azote des diatomees
   ! ----------------------------------
   dc(iv_phyto_diat_N)=c(iv_phyto_diat_N)*(rationdiat-diatmorteau) &
                      -broumesozoodiat*c(iv_zoo_meso_N)*rNC        &
                      -broumicrozoodiat*c(iv_zoo_micr_N)*rNC 
#if defined key_biolo_opt2
  dc(iv_phyto_diat_N)=dc(iv_phyto_diat_N)-fractionDIAT_N
#elif (! defined key_sedim_MUSTANG || defined key_sedim_partial) 
!  pas de prise en compte du filtrage benthique ici si key_sedim_MUSTANG et Bio dans sedim (sera avec la bio dans les sediments)
  dc(iv_phyto_diat_N)=dc(iv_phyto_diat_N)-c(iv_phyto_diat_N)*txfiltbenthij*ibbenth/epn
#endif

   ! Evolution de l azote des dinoflagelles
   ! --------------------------------------
   dc(iv_phyto_dino_N)=(rationdino-dinomorteau)*c(iv_phyto_dino_N)  &
                       -broumesozoodino*c(iv_zoo_meso_N)*rNC        &
                       -broumicrozoodino*c(iv_zoo_micr_N)*rNC
#if ! defined key_biolo_opt2 && (! defined key_sedim_MUSTANG || defined key_sedim_partial) 
!  pas de prise en compte du filtrage benthique ici si key_sedim_MUSTANG et Bio dans sedim (sera avec la bio dans les sediments)
   dc(iv_phyto_dino_N)=dc(iv_phyto_dino_N)-txfiltbenthij*ibbenth/epn*c(iv_phyto_dino_N)
#endif

   ! Evolution de l azote detritique
   ! -------------------------------
   dc(iv_detr_N)=diatmorteau*c(iv_phyto_diat_N)                                                     &
                +(txmortmesozoo+(1.0_rsh-assimilmesozoo)*rationmesozoo)*c(iv_zoo_meso_N)*rNC       &
                +(txmortmicrozoo-broumicrozoodet)*c(iv_zoo_micr_N)*rNC                              &
#if defined key_biolo_opt2
                -dissolMOPeau*c(iv_detr_N)                                                          &
                -fractionDET_N
#else
                 +dinomorteau*c(iv_phyto_dino_N)                                                    &
                 +nanomorteau*c(iv_phyto_nano_N)                                                    &
                 -reminazdeteau*c(iv_detr_N)                                                        &
                 +(1.0_rsh-assimilmicrozoo)*rationmicrozoo*c(iv_zoo_micr_N)*rNC
#if ! defined key_benthos && ! defined key_sedim_MUSTANG
    dc(iv_detr_N)=dc(iv_detr_N)+txfiltbenthij*ibbenth/epn*(c(iv_phyto_diat_N)+c(iv_phyto_dino_N)+c(iv_phyto_nano_N))
#endif
#endif


   ! Evolution de la silice particulaire
   ! -----------------------------------
   dc(iv_detr_Si)=rapsiaz*diatmorteau*c(iv_phyto_diat_N)         &
                 +broumesozoodiat*c(iv_zoo_meso_N)*rNC*rapsiaz   &
#if defined key_biolo_opt2
                 -dissolMOPeau*c(iv_detr_Si)                     &
                 -fractionDET_Si
#else
                 -dissolsiliceeau*c(iv_detr_Si)               &
                 +broumicrozoodiat*c(iv_zoo_micr_N)*rNC*rapsiaz
#if ! defined key_benthos && ! defined key_sedim_MUSTANG
   dc(iv_detr_Si)=dc(iv_detr_Si)+rapsiaz*txfiltbenthij*ibbenth/epn*c(iv_phyto_diat_N)
#endif  
#endif                     

   ! Evolution du phosphore detritique
   ! ---------------------------------
   dc(iv_detr_P)=diatmorteau*c(iv_phyto_diat_N)*rappaz                                        &
                -broumicrozoodet*c(iv_zoo_micr_N)*rNC*rappaz                                  &
#if defined key_biolo_opt2
                +txmortmesozoo*c(iv_zoo_meso_N)*rNC*rappaz                                    &
                +(1.0_rsh-assimilmesozoo)*rationmesozoo*c(iv_zoo_meso_N)*rNC*rappaz           &
                +txmortmicrozoo*c(iv_zoo_micr_N)*rNC*rappaz                                   &
                -dissolMOPeau*c(iv_detr_P)                                                    &
                -fractionDET_P 
#else
                 -reminpdeteau*c(iv_detr_P)                                                   &
                 +(dinomorteau*c(iv_phyto_dino_N)+nanomorteau*c(iv_phyto_nano_N))*rappaz      &
                 +((txmortmesozoo+(1.0_rsh-assimilmesozoo)*rationmesozoo)*c(iv_zoo_meso_N)    &
                 +(txmortmicrozoo+(1.0_rsh-assimilmicrozoo)*rationmicrozoo)*c(iv_zoo_micr_N)) &
                       *rNC*rappaz
#if ! defined key_benthos && ! defined key_sedim_MUSTANG
   dc(iv_detr_P)=dc(iv_detr_P)+txfiltbenthij*ibbenth/epn*(c(iv_phyto_diat_N)+c(iv_phyto_dino_N)+c(iv_phyto_nano_N))*rappaz
#endif
#endif                                                                  

   ! Evolution de l azote du mesozooplancton (microgC/l for option 2, microgN/l for option 1)
   ! -------------------------------------------------
   dc(iv_zoo_meso_N)=(rationmesozoo*assimilmesozoo-excretionmesozoo-txmortmesozoo)*c(iv_zoo_meso_N)

   ! Evolution de l azote du microzooplancton  (microgC.l-1 for option 2, microgN/l for option 1)
   ! -----------------------------------------------------------
   dc(iv_zoo_micr_N)=c(iv_zoo_micr_N)*(rationmicrozoo*assimilmicrozoo-excretionmicrozoo)       &
                     -txmortmicrozoo*c(iv_zoo_micr_N)                                          &
                     -broumesozoomicrozoo*c(iv_zoo_meso_N)

   ! Evolution de la masse de MES  (g.l-1)
   ! -------------------------------------
   dc(iv_spim)=0.0_rsh

#if defined key_biolo_opt2
   ! Evolution de l azote small particulaire
   ! ---------------------------------------
   dc(iv_diss_N)=(1.0_rsh-assimilmicrozoo)*rationmicrozoo*p_micz_diss*c(iv_zoo_micr_N)*rNC &
                -reminazdeteau*c(iv_diss_N) &
                +dissolMOPeau*c(iv_detr_N) &
                +dinomorteau*c(iv_phyto_dino_N)  &
                +nanomorteau*c(iv_phyto_nano_N) &
                +0.25*fractionDIAT_N   &
                +0.25*fractionDET_N


   ! Evolution du N2 accumule dans la derniere couche, perdu pour le cycle N
   ! ------------------------------------------------------------------------- 
   dc(iv_diss_fond_Nitr)=0.75*fractionDIAT_N & 
                        +0.75*fractionDET_N
                        

   ! Evolution de la silice small particulaire
   ! ------------------------------------------
   dc(iv_diss_Si)=-dissolsiliceeau*c(iv_diss_Si) &
                 +dissolMOPeau*c(iv_detr_Si) &
                 +broumicrozoodiat*c(iv_zoo_micr_N)*rNC*rapsiaz &
                 +fractionDET_Si &
                 +fractionDIAT_Si

   ! Evolution du phosphore small particulaire
   ! ------------------------------------------
   dc(iv_diss_P)=-reminpdeteau*c(iv_diss_P) &
                +(1.0_rsh-assimilmicrozoo)*rationmicrozoo*p_micz_diss*c(iv_zoo_micr_N)*rNC*rappaz &
                +nanomorteau*c(iv_phyto_nano_N)*rappaz &
                +dinomorteau*c(iv_phyto_dino_N)*rappaz &
                +dissolMOPeau*c(iv_detr_P) &
                +fractionDET_P &
                +fractionDIAT_P
#endif

   ! Production carbonee cumulee des nanoflagelles de la maille (im,jm,km)
   ! ---------------------------------------------------------------------
#if defined key_biolo_opt2
   ! Production azotee (option 2)
   dc(iv_phyto_nano_pp)=14.e-3*rationnano*c(iv_phyto_nano_N)*epn
#else
   ! Production carbonee (option 1) 
   dc(iv_phyto_nano_pp)=epn*12.e-3*p_phyto_CNratio*rationnano*c(iv_phyto_nano_N)
#endif

   ! Production cumulee des diatomees de la maille (im,jm,km)
   ! ------------------------------------------------------------------------------------------------
#if defined key_biolo_opt2
   ! Production azotee (option 2)
   dc(iv_phyto_diat_pp)=14.e-3*rationdiat*c(iv_phyto_diat_N)*epn
#else
   ! Production carbonee (option 1) 
   dc(iv_phyto_diat_pp)=epn*12.e-3*p_phyto_CNratio*rationdiat*c(iv_phyto_diat_N)
#endif

   ! Production carbonee cumulee des dinoflagelles de la maille (im,jm,km)
   ! ------------------------------------
#if defined key_biolo_opt2
   ! Production azotee (option 2)
   dc(iv_phyto_dino_pp)=14.e-3*rationdino*c(iv_phyto_dino_N)*epn
#else
   ! Production carbonee (option 1) 
   dc(iv_phyto_dino_pp)=epn*12.e-3*p_phyto_CNratio*rationdino*c(iv_phyto_dino_N)
#endif

   ! Production cumulee du zooplancton de la maille (im,jm,km)
   ! ------------------------------------------------------------
#if defined key_zoo_prod
   ! Production carbonee (option 1) 
   dc(iv_zoo_micr_ps)=epn*12.e-3*p_zoo_CNratio*rationmicrozoo*assimilmicrozoo*c(iv_zoo_micr_N)
   dc(iv_zoo_meso_ps)=epn*12.e-3*p_zoo_CNratio*rationmesozoo*assimilmesozoo*c(iv_zoo_meso_N)
#endif

  ! ++++++++++++++++++++++++++++++++++++++++++++++++
  !   ENREGISTREMENT VARIABLES DIAGNOSTIQUES
  ! ++++++++++++++++++++++++++++++++++++++++++++++++
! version Alain : moyenne entre 0h et ecriture (12h)
  ! IF (iheure.eq.0) diag_3d_wat(irk_diag(id_diat_limlight),km,im,jm)=0.0_rsh   
  ! f=1000.0_rsh*diag_3d_wat(irk_diag(id_diat_limlight),km,im,jm)
  ! npas=int((f-int(f))*1000.0_rsh)
  ! f=aint(f)/1000.0_rsh
  ! diag_3d_wat(irk_diag(id_diat_limlight),km,im,jm)=aint((1000.0_rsh*(npas*f+effetlumierediat)/(npas+1)))/1000.0_rsh +  &
  !                                                    float(npas+1)/1.e+6_rsh  
! somme a chaque pas de temps _ moyenne a minuit pour memoriser la variable diagnostique
   effetlumiere_day_diat(km,im,jm)=effetlumiere_day_diat(km,im,jm)+effetlumierediat*dtbio
!  IF(km==10 .and.im==20 .and.jm==20)write(*,*)'limlight diat',effetlumierediat,dtbio
   IF(iheure==0 .and. iminu ==0 .and. isec <= dtbio) THEN
      diag_3d_wat(irk_diag(id_diat_limlight),km,im,jm)=effetlumiere_day_diat(km,im,jm)/86400.0_rsh
!      IF(km==10 .and.im==20 .and.jm==20)write(*,*)'limlight',diag_3d_wat(irk_diag(id_diat_limlight),km,im,jm)
      effetlumiere_day_diat(km,im,jm)=0.0_rsh
   ENDIF

   diag_3d_wat(irk_diag(id_diat_limN),km,im,jm)=effetazotediat
   diag_3d_wat(irk_diag(id_diat_limSi),km,im,jm)=effetsilice
   diag_3d_wat(irk_diag(id_diat_limP),km,im,jm)=effetphosphorediat
! version Alain : moyenne entre 0h et ecriture (12h)
   !if (iheure.eq.0) diag_3d_wat(irk_diag(id_dino_limlight),km,im,jm)=0.0_rsh
   !f=1000.0_rsh*diag_3d_wat(irk_diag(id_dino_limlight),km,im,jm)
   !npas=int((f-int(f))*1000.0_rsh)
   !f=aint(f)/1000.0_rsh
   !diag_3d_wat(irk_diag(id_dino_limlight),km,im,jm)=aint((1000.0_rsh*(npas*f+effetlumieredino)/(npas+1)))/1000.0_rsh + &
!                                                     float(npas+1)/1.e+6_rsh
! somme a chaque pas de temps _ moyenne a minuit pour memoriser la variable diagnostique
   effetlumiere_day_dino(km,im,jm)=effetlumiere_day_dino(km,im,jm)+effetlumieredino*dtbio
   IF(iheure==0 .and. iminu ==0 .and. isec <= dtbio) THEN
      diag_3d_wat(irk_diag(id_dino_limlight),km,im,jm)=effetlumiere_day_dino(km,im,jm)/86400.0_rsh
      effetlumiere_day_dino(km,im,jm)=0.0_rsh
   ENDIF

   diag_3d_wat(irk_diag(id_dino_limN),km,im,jm)=effetazotedino
   diag_3d_wat(irk_diag(id_dino_limP),km,im,jm)=effetphosphoredino
! version Alain : moyenne entre 0h et ecriture (12h)
   !if (iheure.eq.0) diag_3d_wat(irk_diag(id_nano_limlight),km,im,jm)=0.0_rsh
   !f=1000.0_rsh*diag_3d_wat(irk_diag(id_nano_limlight),km,im,jm)
   !npas=int((f-int(f))*1000.0_rsh)
   !f=aint(f)/1000.0_rsh
   !diag_3d_wat(irk_diag(id_nano_limlight),km,im,jm)=aint((1000.0_rsh*(npas*f+effetlumierenano)/(npas+1)))/1000.0_rsh + &
!                                                    float(npas+1)/1.e+6_rsh
! somme a chaque pas de temps _ moyenne a minuit pour memoriser la variable diagnostique
   effetlumiere_day_nano(km,im,jm)=effetlumiere_day_nano(km,im,jm)+effetlumierenano*dtbio
   IF(iheure==0 .and. iminu ==0 .and. isec <= dtbio) THEN
      diag_3d_wat(irk_diag(id_nano_limlight),km,im,jm)=effetlumiere_day_nano(km,im,jm)/86400.0_rsh
      effetlumiere_day_nano(km,im,jm)=0.0_rsh
   ENDIF

   diag_3d_wat(irk_diag(id_nano_limN),km,im,jm)=effetazotenano
   diag_3d_wat(irk_diag(id_nano_limP),km,im,jm)=effetphosphorenano

!   chlorophylle [mgChl/m3]
!  Cas ou on stocke simplement l azote phyto total
   !fact_phyto_ChlNratio=1.0_rsh
   IF(l_ChlNratio_var) THEN
      IF((t-tdeb) > 345600.00_rlg) THEN
        ! Cas ou on transforme l azote en chloro par un rapport Chloro/N dependant de l extinction
        !   lumineuse moyennee sur les 4 jours precedents
        fact_phyto_ChlNratio=p_phyto_ChlNratiomax*extinction_ave4d(km,im,jm)/p_phyto_ChlN_ksmithextinct/  &
                             (sqrt(1+(extinction_ave4d(km,im,jm)/p_phyto_ChlN_ksmithextinct)**2))
      ELSE
        fact_phyto_ChlNratio=p_phyto_ChlNratiomax*effetturbidite    
      ENDIF
      if(fact_phyto_ChlNratio<0.7_rsh) then 
         fact_phyto_ChlNratio=0.7_rsh
      ENDIF
   ELSE
      fact_phyto_ChlNratio=p_phyto_ChlNratio
   ENDIF
   diag_3d_wat(irk_diag(id_totalchl),km,im,jm)=(c(iv_phyto_diat_N)+c(iv_phyto_dino_N)+c(iv_phyto_nano_N)) &
                                                *fact_phyto_ChlNratio


#if defined key_psnz
   ! Evolution des variables liees a Pseudo-Nitzschia
   ! ------------------------------------------------
   call incellwat_pseudonitzschia(km,im,jm,xe,c,dc,Si)



#endif
#if defined key_karenia
   ! Evolution des variables liees a Karenia
   ! ---------------------------------------
   call incellwat_karenia(km,im,jm,xe,c,dc)
#endif
#if defined key_phaeocystis
   ! Evolution des variables liees a Phaeocystis
   ! -------------------------------------------
   call incellwat_phaeocystis(km,im,jm,xe,c,dc)
#endif

!   vitesses de chute des diatomees et du detritique enregistrees a la fin de la subroutine
#if ! defined key_biolo_opt2
   !++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   ! modification des vitesses de chute de chaque variable bio si option 1 
   ! ws3 des diatomees seront modifiees si l_SNeffect_settle=true (effet des sels nuts sur chute des diatomees)
   !                                    si key_physadaptation (modulation par la profondeur)
   ! ws3 du materiel detritique seront modifiees si l_phyzoodeteffect_settle=true (modulation en fonction de l origine)
   !                                    si key_physadaptation (modulation par la profondeur)        

    call biolo_settling(km,im,jm,c)

   !++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#endif        

   ! enregistrement de la variable diagnostique : vitesse de chute
   !   vitesses de chute des diatomees et du detritique
   diag_3d_wat(irk_diag(id_diatsettling),km,im,jm)=ws3(km,iv_phyto_diat_N,im,jm)*86400.0_rsh
   diag_3d_wat(irk_diag(id_detsettling),km,im,jm)=ws3(km,iv_detr_N,im,jm)*86400.0_rsh

#if defined key_ulvas
   ! Evolution des ulves  	ATTENTION arguments a lister
   ! ATTENTION NON inclus DANS LA NOUVELLE VERSION
   ! -------------------
   call incellwat_ulvas(km,im,jm,xe,c,dc)
#endif
#if defined key_zostera
   ! Evolution des variables liees aux herbiers de zosteres
   ! ------------------------------------------------------
   call incellwat_zostera(km,im,jm,xe,c,dc)
#endif

#if defined key_benthos
   ! Evolution des 3 variables N,Si,P dans le sediment
   ! ------------------------------------------------
     IF (ibbenth.eq.1) call incellwat_benthos(km,im,jm,xe,c,dc)
#endif
#if defined key_suspensivores
   ! Evolution de la variable generique  suspensivore
   ! ------------------------------------------------
   call incellwat_suspensivores(km,im,jm,xe,c,dc)
#endif
#if defined key_benthos_gener
   ! Evolution de 4 variables benthiques generiques : Bacterie+Meifaune, Deposivore-Herbivore, suspensivore, Carnivore
   ! ATTENTION NON OPERATIONNEL DANS LA NOUVELLE VERSION
   ! -------------------------------------------------------
   call incellwat_benthos_generique(km,im,jm,xe,c,dc)
#endif

#if defined key_microtracers
   ! Evolution des variables liees aux micro-traceurs
   ! ATTENTION NON inclus DANS LA NOUVELLE VERSION
   ! ------------------------------------------------
   call incellwat_microtracers(km,im,jm,xe,c,dc)
#endif
#if defined key_oxygen
   ! Evolution de la variable oxygene
   ! --------------------------------
   call incellwat_oxygen(km,im,jm,xe,c,dc,             &
                         effetselnutdino,effetselnutnano, &
                         effetlumierediat,effetlumieredino,effetlumierenano)
#endif
#if defined key_oyster_SFG
   ! Evolution des huitres selon le modele SFG (Scope for growth) de Barille (1997)
   ! -------------------------------------------------------------------------------
   IF (ibbenth.eq.1) call incellwat_oysterSFG(km,im,jm,xe,c,dc)
#endif
#if defined key_oyster_DEB
   ! Evolution des huitres selon le modele DEB
   ! -------------------------------------------------------
   IF (ibbenth.eq.1) call incellwat_oysterDEB(km,im,jm,xe,c,dc)
   
#endif

#if defined key_N_tracer
   !   Tracage de l azote 
   !   --------------------
   call incellwat_nitrogentracer(km,im,jm,xe,c,dc, &
             fractionnh4diat,fractionnh4dino,fractionnh4nano,  &
             fractionno3diat,fractionno3dino,fractionno3nano)
#endif

#if defined key_P_tracer
   !   Tracage du phosphore 
   ! ATTENTION probleme possible pour karenia
   !   --------------------
   call incellwat_phosphoretracer(km,im,jm,xe,c,dc,adsorpeau,desorpeau)
#endif

! version Alain
!     ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
!     VERIFICATION conservativite bilan de matiere en mmolN/m3 en quelques mailles
!     ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++   
!   tout mis dans une subroutine pour alleger
!  point 20,45 : Manche OUtes
! point 38,44 : point sortie de la Seine
!     IF((im == 20.and.jm == 45.and.(km == 1 .or. km == kmax)) .or. (im == 38.and.jm == 44.and. km == kmax)) THEN
!       call verif_bilan_NP(km,im,jm,dc,c,  &
!                             ,broumesozoomicrozoo)
!     ENDIF

! fin du test sur la salinite (si trop faible, pas de reaction biologique)
ENDIF

  END SUBROUTINE incellwat_nut4phy3zoo2

   !!======================================================================
#if defined key_benthos
   
SUBROUTINE incellwat_benthos(km,im,jm,xe,c,dc)

   !&E---------------------------------------------------------------------
   !&E                 ***  ROUTINE incellwat_benthos  ***
   !&E
   !&E ** Purpose : Calcul du stockage du detritique dans 3 ou 4 variables benthiques
   !&E              
   !&E
   !&E ** Description :
   !&E
   !&E ** Called by :  incellwat_nut4phy3zoo2
   !&E
   !&E ** External calls :
   !&E
   !&E ** Reference :
   !&E
   !&E ** History :
   !&E       !  2010-02    (A. Menesguen, M. Dussauze) Original code
   !&E       !  ???????    (  )  evolutions
   !&E
   !&E---------------------------------------------------------------------
   !! * Modules used
   USE comsubstance, ONLY : attenuation,extinction,alumplafond,ws_free_min, ws_free_max
   USE comvars2d,    ONLY : h0,hm,dx,dy
   USE comvarp2d,    ONLY  : u,v
   USE comvarp3d,    ONLY  : uz,vz
   
 
   !! * Arguments
   INTEGER, INTENT( in ) ::   km,im,jm      ! ocean spatial-step index
   REAL(KIND=rsh),             INTENT(in) :: xe     !ssh
   REAL(KIND=rsh),DIMENSION(:),INTENT(in) :: c
   REAL(KIND=rsh),DIMENSION(:),INTENT(inout) :: dc
   
   !! * Local declarations

   ! Erosion/depot du detritique
   ! ------------------------
   REAL(KIND=rsh) :: ufond,detresuspsil,detresusp
   REAL(KIND=rsh) :: erodvitcrit,reminbenth
   
   REAL(KIND=rlg) :: tool_datosec
   REAL(KIND=rsh) :: diatmortsed,factvitessmax
#if defined key_diatbenth || defined key_zostera
   REAL(KIND=rsh) :: diatresusp
#endif
#if defined key_NPbenth
   REAL(KIND=rsh),PARAMETER :: p_kzf = 0.00000005_rsh      ! coef. de diffusion du dissous eau/sed (m2.s-1)
   REAL(KIND=rsh) :: diffusion_PO4,diffusion_NH4
#endif
#if defined key_zostera
   REAL(KIND=rsh) :: vitessechuteseed,vitessechutezostdet,seedresusp,detNzostresusp,detPzostresusp
   REAL(KIND=rsh),PARAMETER :: p_kzf = 0.00000005_rsh      ! coef. de diffusion du dissous eau/sed (m2.s-1)
   REAL(KIND=rsh) :: diffusion_PO4,diffusion_NH4
#endif

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

 
   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
   ! saisir le code apres cette limite
   ! =================================
   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 

   !++++++++++++++++++++++++++++++++++++
   ! Processus lies au benthos 
   !++++++++++++++++++++++++++++++++++++
         
    IF(d.le.hm) THEN
!    ufond=sqrt(u(im,jm)*u(im,jm)+v(im,jm)*v(im,jm))
      IF(im.gt.1.and.jm.gt.1) ufond=0.5_rsh*sqrt((u(im-1,jm)+u(im,jm))**2.+(v(im,jm)+v(im,jm-1))**2.)
      IF(im.eq.1.and.jm.gt.1) ufond=0.5_rsh*sqrt((u(im,jm)+u(im,jm))**2.+(v(im,jm)+v(im,jm-1))**2.)
      IF(im.gt.1.and.jm.eq.1) ufond=0.5_rsh*sqrt((u(im-1,jm)+u(im,jm))**2.+(v(im,jm)+v(im,jm))**2.)
      IF(im.eq.1.and.jm.eq.1) ufond=sqrt(u(im,jm)*u(im,jm)+v(im,jm)*v(im,jm))
 
    ELSE
!    ufond=sqrt(uz(1,im,jm)*uz(1,im,jm)+vz(1,im,jm)*vz(1,im,jm))
      IF(im.gt.1.and.jm.gt.1) ufond=0.5_rsh*sqrt((uz(1,im-1,jm)+uz(1,im,jm))**2.+(vz(1,im,jm)+vz(1,im,jm-1))**2.)
      IF(im.eq.1.and.jm.gt.1) ufond=0.5_rsh*sqrt((uz(1,im,jm)+uz(1,im,jm))**2.+(vz(1,im,jm)+vz(1,im,jm-1))**2.)
      IF(im.gt.1.and.jm.eq.1) ufond=0.5_rsh*sqrt((uz(1,im-1,jm)+uz(1,im,jm))**2.+(vz(1,im,jm)+vz(1,im,jm))**2.)
      IF(im.eq.1.and.jm.eq.1) ufond=sqrt(uz(1,im,jm)*uz(1,im,jm)+vz(1,im,jm)*vz(1,im,jm))
    ENDIF
    
    ! p_enfouissement=0.005_rsh replaced by p_burial in namelist namsediment (parabiolo.txt)

    reminbenth=p_reminbenth
    erodvitcrit=p_erodvitcrit

    detresusp=(p_erodflux*max(0.0_rsh,(ufond/erodvitcrit-1.0_rsh)))
    !detresusp=(p_erodflux*max(0.0_rsh,(ufond**2/erodvitcrit**2-1.0_rsh)))


    IF (c(iv_benth_N) > 1.e-4) THEN 
      detresuspazote=detresusp
      IF (detresuspazote*dtbio > c(iv_benth_N)) THEN
         detresuspazote=0.95_rsh*c(iv_benth_N)/dtbio
      END IF
      detresuspazote=detresuspazote*86400.0_rsh
    ELSE
      detresuspazote=0.0_rsh
    END IF
   
    IF (c(iv_benth_Si) > 1.e-4) THEN
      detresuspsil=detresusp*rapsiaz
      IF (detresuspsil*dtbio > c(iv_benth_Si)) THEN 
        detresuspsil=0.95_rsh*c(iv_benth_Si)/dtbio
      END IF 
      detresuspsil=detresuspsil*86400.0_rsh
    ELSE
      detresuspsil=0.0_rsh
    END IF
     
    IF (c(iv_benth_P) > 1.e-4) THEN
      detresusppho=detresusp*rappaz
      IF (detresusppho*dtbio > c(iv_benth_P)) THEN
        detresusppho=0.95_rsh*c(iv_benth_P)/dtbio
      END IF     
      detresusppho=detresusppho*86400.0_rsh
    ELSE
      detresusppho=0.0_rsh
    END IF

#if defined key_diatbenth || defined key_zostera

    IF (c(iv_benth_phyto_diat_N) > 1.e-15) THEN
      diatresusp=detresusp
      IF (diatresusp*dtbio > c(iv_benth_phyto_diat_N)) THEN
!  ??        diatresusp=0.95_rsh*c(iv_benth_phyto_diat_N)/dtbio
        diatresusp=c(iv_benth_phyto_diat_N)/dtbio
      END IF        
      diatresusp=diatresusp*86400._rsh
    ELSE
      diatresusp=0._rsh
    END IF
#endif
#if defined key_zostera 
    IF (c(iv_zost_benth_seed) > 1.e-15) THEN
      seedresusp=detresusp
      IF (seedresusp*dtbio > c(iv_zost_benth_seed)) THEN
        seedresusp=c(iv_zost_benth_seed)/dtbio
!   ??      seedresusp=0.95_rsh*c(iv_zost_benth_seed)/dtbio
      END IF        
      seedresusp=seedresusp*86400._rsh
    ELSE
      seedresusp=0._rsh
    END IF

    IF (c(iv_zost_benth_N) > 1.e-15) THEN
      detNzostresusp=detresusp
      IF (detNzostresusp*dtbio > c(iv_zost_benth_N)) THEN
        detNzostresusp=c(iv_zost_benth_N)/dtbio
      END IF        
      detNzostresusp=detNzostresusp*86400._rsh
    ELSE
      detNzostresusp=0._rsh
    END IF

    IF (c(iv_zost_benth_P) > 1.e-15) THEN
      detPzostresusp=detresusp
      IF (detPzostresusp*dtbio > c(iv_zost_benth_P)) THEN
        detPzostresusp=c(iv_zost_benth_P)/dtbio
      END IF        
      detPzostresusp=detPzostresusp*86400._rsh
    ELSE
      detPzostresusp=0._rsh
    END IF
#endif   

    !vitesse de chute en m.jour-1

    ! ********ATTENTION*********
    ! pour l instant en dur : choix en vitesse au carre : (1-u^2/(p_depovitcrit)^2)
    ! mais on pourait choisir en vitesse  :  (1-u/p_depovitcrit)
    factvitessmax=max(0.,(1.0_rsh-ufond/p_depovitcrit))
    !factvitessmax=max(0.,(1.0_rsh-ufond**2./p_depovitcrit**2.))

    vitessechutedet=min(0.95_rsh*epn,dtbio*ws3(1,iv_detr_N,im,jm)*factvitessmax)/dtbiojour
#if defined key_NPbenth
   ! diffusion a l interface eau-sed (mmole/m2/j)
   ! --------------------------------------------
    IF(epn.gt.0.01) THEN
      diffusion_PO4 = p_kzf/deltaz*(c(iv_benth_PO4) - c(iv_nutr_PO4))*86400.0_rsh ! positif vers la colonne d eau
      diffusion_NH4 = p_kzf/deltaz*(c(iv_benth_NH4) - c(iv_nutr_NH4))*86400.0_rsh
    ELSE
      diffusion_PO4 = 0.0_rsh
      diffusion_NH4 = 0.0_rsh
    ENDIF
#endif
#if defined key_zostera
!    vitessechuteseed=ws3(2,iv_zost_seed,im,jm)*max(0.,(1.0_rsh-ufond**2./vitseuil_dep**2.))*86400.0_rsh
!    vitessechutezostdet=ws3(2,iv_detr_zost_N,im,jm)*max(0.,(1.0_rsh-ufond**2./vitseuil_dep**2.))*86400.0_rsh
    vitessechuteseed=min(0.95_rsh*epn,dtbio*ws3(1,iv_zost_seed,im,jm)*factvitessmax)/dtbiojour
    vitessechutezostdet=min(0.95_rsh*epn,dtbio*ws3(1,iv_detr_zost_N,im,jm)*factvitessmax)/dtbiojour

   ! diffusion a l interface eau-sed (mmole/m2/j)
   ! --------------------------------------------
    IF(epn.gt.0.01) THEN
      diffusion_PO4 = p_kzf/deltaz*(c(iv_benth_PO4) - c(iv_nutr_PO4))*86400.0_rsh ! positif vers la colonne d eau
      diffusion_NH4 = p_kzf/deltaz*(c(iv_benth_NH4) - c(iv_nutr_NH4))*86400.0_rsh
    ELSE
      diffusion_PO4 = 0.0_rsh
      diffusion_NH4 = 0.0_rsh
    ENDIF

#endif
 
    vitessechutediat=min(0.95_rsh*epn,dtbio*ws3(1,iv_phyto_diat_N,im,jm)*factvitessmax)/dtbiojour
#if defined key_diatbenth || defined key_zostera
    !  diatmortsed=effetchaleur*p_diat_mort*2.0
    !  modification car p_diatmort n est plus connu dans l option 1 (p_diat_mortmax limite par sels nuts 
    !  au lieu de p_diatmort limite par effetchaleur)
        !diatmortsed=effetchaleur*p_diat_mortmax*0.3_rsh
      diatmortsed=effetchaleur*p_diat_mort*0.3_rsh

   ! Evolution de l azote organique benthique en mmol.m-2.jour-1
   ! ----------------------------------------
      dc(iv_benth_N)=(-detresuspazote+vitessechutedet*c(iv_detr_N)) &
                    -(reminazdeteau*reminbenth+p_burial)*c(iv_benth_N)   &
                    +diatmortsed*c(iv_benth_phyto_diat_N)         &
                    +txfiltbenthij*(c(iv_phyto_diat_N)+c(iv_phyto_dino_N)+c(iv_phyto_nano_N))
            
#else
   ! Evolution de l azote organique benthique en mmol.m-2.jour-1
   ! ----------------------------------------
   ! modif Alain 20 octobre 2015 : rajout chute des diatomees
      dc(iv_benth_N)=(-detresuspazote+vitessechutedet*c(iv_detr_N)+vitessechutediat*c(iv_phyto_diat_N)) &
                    -(reminazdeteau*reminbenth+p_burial)*c(iv_benth_N)   &
                    +txfiltbenthij*(c(iv_phyto_diat_N)+c(iv_phyto_dino_N)+c(iv_phyto_nano_N))
#endif
   
#if defined key_psnz
    dc(iv_benth_N)=dc(iv_benth_N)+txfiltbenthij*c(iv_phyto_psnz_N)
#endif
#if defined key_karenia
    dc(iv_benth_N)=dc(iv_benth_N)+txfiltbenthij*c(iv_phyto_karenia_N)
#endif
#ifdef key_phaeocystis
    dc(iv_benth_N)=dc(iv_benth_N)+txfiltbenthij*c(iv_phyto_phaeocystis_cell_N)
#endif
#ifdef key_ulvas
   dc(iv_benth_N)=dc(iv_benth_N)+ulvebenthmortsed*c(iv_ulv_benth_N)/0.014_rsh
#endif
                               
   ! Evolution du silicium organique benthique en mmol.m-2.jour-1
   ! -----------------------------------------
    dc(iv_benth_Si)=-detresuspsil+vitessechutedet*c(iv_detr_Si) &
                    -(dissolsiliceeau*reminbenth+p_burial)*c(iv_benth_Si) &
                    +rapsiaz*txfiltbenthij*c(iv_phyto_diat_N)
#if defined key_diatbenth || defined key_zostera
    dc(iv_benth_Si)=dc(iv_benth_Si)+diatmortsed*c(iv_benth_phyto_diat_N)*p_phyto_SiNratio
#else
   ! modif Alain 20 octobre 2015 : rajout chute des diatomees
    dc(iv_benth_Si)=dc(iv_benth_Si)+vitessechutediat*c(iv_phyto_diat_N)*rapsiaz
#endif
#if defined key_psnz
    dc(iv_benth_Si)=dc(iv_benth_Si)+txfiltbenthij*c(iv_phyto_psnz_Si)
#endif
 
   ! Evolution du phosphore organique benthique en mmol.m-2.jour-1
   ! ------------------------------------------
   dc(iv_benth_P)=(-detresusppho+vitessechutedet*c(iv_detr_P)) &
                    -(reminpdeteau*reminbenth+p_burial)*c(iv_benth_P)  &
                    +txfiltbenthij*(c(iv_phyto_diat_N)+c(iv_phyto_dino_N)+c(iv_phyto_nano_N))*rappaz
#if defined key_diatbenth || defined key_zostera
   dc(iv_benth_P)=dc(iv_benth_P)+diatmortsed*c(iv_benth_phyto_diat_N)/p_phyto_NPratio 
#else
   dc(iv_benth_P)=dc(iv_benth_P)+vitessechutediat*c(iv_phyto_diat_N)*rappaz
#endif
#if defined key_psnz
   dc(iv_benth_P)=dc(iv_benth_P)+txfiltbenthij*c(iv_phyto_psnz_N)*rappaz
#endif
#if defined key_karenia
   dc(iv_benth_P)=dc(iv_benth_P)+txfiltbenthij*c(iv_phyto_karenia_C)/(p_phyto_NPratio*p_phyto_CNratio)
!    dc(iv_benth_P)=dc(iv_benth_P)+txfiltbenthij*c(iv_phyto_karenia_N)*rappaz
#endif
#ifdef key_phaeocystis
   dc(iv_benth_P)=dc(iv_benth_P)+txfiltbenthij*c(iv_phyto_phaeocystis_cell_N)*rappaz
#endif
#ifdef key_ulvas
   dc(iv_benth_P)=dc(iv_benth_P)+ulvebenthmortsed*c(iv_ulv_benth_P)/0.031_rsh
#endif

   ! Evolution de l azote detritique en micromol.l-1.jour-1
   ! -------------------------------
   dc(iv_detr_N)=dc(iv_detr_N)-(-detresuspazote+vitessechutedet*c(iv_detr_N))/epn
  
   ! Evolution de la silice detritique en micromol.l-1.jour-1
   ! ---------------------------------
   dc(iv_detr_Si)=dc(iv_detr_Si)-(-detresuspsil+vitessechutedet*c(iv_detr_Si))/epn
   
   ! Evolution du phosphore detritique en micromol.l-1.jour-1
   ! ------------------------------
   dc(iv_detr_P)=dc(iv_detr_P)-(-detresusppho+vitessechutedet*c(iv_detr_P))/epn
      
   ! Evolution du silicium dissous
   ! ------------------------------
   dc(iv_nutr_SiOH)=dc(iv_nutr_SiOH)+(dissolsiliceeau*reminbenth)*c(iv_benth_Si)/epn
   
#if defined key_diatbenth || defined key_zostera
   ! Evolution des diatomes benthiques en mmol.m-2.jour-1
   ! ------------------------------
   dc(iv_benth_phyto_diat_N)=(-diatresusp+vitessechutediat*c(iv_phyto_diat_N))  &
                              -diatmortsed*c(iv_benth_phyto_diat_N)

   ! Evolution des diatomes pelagiques
   ! --------------------------------
   dc(iv_phyto_diat_N)=dc(iv_phyto_diat_N)-(vitessechutediat*c(iv_phyto_diat_N)-diatresusp)/epn
#else
   dc(iv_phyto_diat_N)=dc(iv_phyto_diat_N)-vitessechutediat*c(iv_phyto_diat_N)/epn
#endif
#if defined key_NPbenth
   ! Evolution du phosphore dissous benthique (mmol/m3ei/j)
   ! ----------------------------------------------------
    dc(iv_benth_PO4)=dc(iv_benth_PO4)+((reminpdeteau*p_reminbenth)*c(iv_benth_P)  &
                     -diffusion_PO4)/epnsed

   ! Evolution de l ammonium benthique (mmol/m3ei/j)
   ! -----------------------------------------------
    dc(iv_benth_NH4)=dc(iv_benth_NH4)+((reminazdeteau*p_reminbenth)*c(iv_benth_N)  &
                     -diffusion_NH4)/epnsed
    
   ! Evolution du phosphore dissous
   ! ------------------------------   
    dc(iv_nutr_PO4)=dc(iv_nutr_PO4)+diffusion_PO4/epn

   ! Evolution de l ammonium
   ! -----------------------
    dc(iv_nutr_NH4)=dc(iv_nutr_NH4)+diffusion_NH4/epn

#elif defined key_zostera
   ! Evolution de l azote detritique peu labile (mmol/m2/j)
   ! ------------------------------------------------------
    dc(iv_zost_benth_N)=dc(iv_zost_benth_N)-detNzostresusp+vitessechutezostdet*c(iv_detr_zost_N)  &
                        -(reminazdeteau*reminbenth/10._rsh)*c(iv_zost_benth_N)

   ! Evolution du phosphore detritique peu labile (mmol/m2/j)
   ! ------------------------------------------------------
    dc(iv_zost_benth_P)=dc(iv_zost_benth_P)-detPzostresusp+vitessechutezostdet*c(iv_detr_zost_P)  &
                        -(reminpdeteau*reminbenth/10._rsh)*c(iv_zost_benth_P)
   ! Evolution du phosphore dissous benthique (mmol/m3ei/j)
   ! ----------------------------------------------------
    dc(iv_benth_PO4)=dc(iv_benth_PO4)+((reminpdeteau*p_reminbenth)*c(iv_benth_P)  &
                     +(reminpdeteau*p_reminbenth/10._rsh)*c(iv_zost_benth_P)  &
                     -diffusion_PO4)/epnsed

   ! Evolution de l ammonium benthique (mmol/m3ei/j)
   ! -----------------------------------------------
    dc(iv_benth_NH4)=dc(iv_benth_NH4)+((reminazdeteau*p_reminbenth)*c(iv_benth_N)  &
                     +(reminazdeteau*p_reminbenth/10._rsh)*c(iv_zost_benth_N)  &
                     -diffusion_NH4)/epnsed
   
   ! Evolution des graines de zosteres derivantes (mmolC/m3/j)
   ! -----------------------------------------------------------
    dc(iv_zost_seed)=dc(iv_zost_seed)-(-seedresusp+vitessechuteseed*c(iv_zost_seed))/epn

   ! Evolution des graines de zosteres benthiques (mmolC/m2/j)
   ! -----------------------------------------------------------
    dc(iv_zost_benth_seed)=dc(iv_zost_benth_seed)-seedresusp+vitessechuteseed*c(iv_zost_seed)

   ! Evolution du phosphore dissous
   ! ------------------------------   
    dc(iv_nutr_PO4)=dc(iv_nutr_PO4)+diffusion_PO4/epn

   ! Evolution de l ammonium
   ! -----------------------
    dc(iv_nutr_NH4)=dc(iv_nutr_NH4)+diffusion_NH4/epn

#else
   ! Evolution du phosphore dissous
   ! ------------------------------   
    dc(iv_nutr_PO4)=dc(iv_nutr_PO4)+(reminpdeteau*reminbenth)*c(iv_benth_P)/epn
  
   ! Evolution de l ammonium
   ! ------------------------------
    dc(iv_nutr_NH4)=dc(iv_nutr_NH4)+(reminazdeteau*reminbenth)*c(iv_benth_N)/epn
#endif

   END SUBROUTINE incellwat_benthos
#endif
   !!======================================================================

#ifdef key_benthos_gener
  SUBROUTINE incellwat_benthos_4comp(km,im,jm,xe,c,dc)

   !&E---------------------------------------------------------------------
   !&E                 ***  ROUTINE incellwat_benthos  ***
   !&E
   !&E ** Purpose : Calcul d une variable suspensivore generique
   !&E              
   !&E
   !&E ** Description :
   !&E
   !&E ** Called by :  incellwat_nut4phy3zoo2
   !&E
   !&E ** External calls :
   !&E
   !&E ** Reference :
   !&E
   !&E ** History :
   !&E       !  2010-11    (P. Cugier, A. Menesguen) Original code
   !&E       !  ???????    (  )  evolutions
   !&E
   !&E---------------------------------------------------------------------
   !! * Modules used
   USE comsubstance, ONLY : attenuation,extinction,alumplafond
   USE comvars2d,    ONLY : h0,hm,dx,dy
   USE comvarp2d,    ONLY  : u,v
   USE comvarp3d,    ONLY  : uz,vz
   
 
   !! * Arguments
   INTEGER, INTENT( in ) ::   km,im,jm      ! ocean spatial-step index
   REAL(KIND=rsh),             INTENT(in) :: xe     !ssh
   REAL(KIND=rsh),DIMENSION(:),INTENT(in) :: c
   REAL(KIND=rsh),DIMENSION(:),INTENT(inout) :: dc

   
   !! * Local declarations

   ! indices de boucles
   ! ------------------
   INTEGER :: toto
    
   ! variables Meiofaune et Bacteries
   ! --------------------------------
   REAL(KIND=rsh) :: db,dbf,alimdb_bm,alimdbf_bm
   REAL(KIND=rsh) :: pertbm,perte_mort_bm,perte_excr_bm,somlim,egestmoybm,bmeiosurfacique
   REAL(KIND=rsh) :: autolimbm,consommationazotedetpelagic,consommationazotedetpelagic1,dcmax

   ! variables Deposivores Herbivores
   ! --------------------------------
   REAL(KIND=rsh) :: alimdb_dh,alimdbf_dh,alimbm_dh
   REAL(KIND=rsh) :: pertdh,perte_mort_dh,perte_excr_dh,egestmoydh,bdeposivsurfacique
   REAL(KIND=rsh) :: autolimdh

   ! variables suspensivore
   ! ----------------------
   REAL(KIND=rsh) :: phytoeaufond,ndeteaufond,pdeteaufond,propdiat,propdino,propnano
   REAL(KIND=rsh) :: propphyt,vitessecourant,alimdetp_su,alimphy_su,facto2mort
   REAL(KIND=rsh) :: pertsu,perte_mort_su,perte_excr_su,egestmoysu,bsuspensivsurfacique
   REAL(KIND=rsh) :: autolimsu
   REAL(KIND=rsh) :: tauxcorrectif,somorga,seuil_courant_susp

   ! variables Carnivores
   ! --------------------
   REAL(KIND=rsh) :: alimbm_cp,alimdh_cp,alimsu_cp
   REAL(KIND=rsh) :: pertcp,perte_mort_cp,perte_excr_cp,bcarnivsurfacique
   REAL(KIND=rsh) :: autolimcp,consommationazotedetbenthic,consommationazotedetbenthic1
   REAL(KIND=rsh) :: perteazotesolide


   REAL(KIND=rsh) :: dcNtotal,dc1,dc2,dc3,dc4,dc5,dc6,dc7,dc8,dc9,dc10,dc11

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

   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
   ! saisir le code apres cette limite
   ! =================================
   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
   
      IF(ibbenth.eq.1) THEN
        phytoeaufond=c(iv_phyto_diat_N)+c(iv_phyto_dino_N)+c(iv_phyto_nano_N)
        ndeteaufond=c(iv_detr_N)
        pdeteaufond=c(iv_detr_P)
        somorga=phytoeaufond
        IF(somorga.gt.0.) THEN
        propdiat=c(iv_phyto_diat_N)/phytoeaufond
        propdino=c(iv_phyto_dino_N)/phytoeaufond
        propnano=c(iv_phyto_nano_N)/phytoeaufond
        ELSE
        propdiat=0.
        propdino=0.
        propnano=0.
        ENDIF
        vitessecourant=0.
        IF(d.le.hm) THEN
!       vitessecourant=sqrt(u(im,jm)*u(im,jm)+v(im,jm)*v(im,jm))
         IF(im.gt.1.and.jm.gt.1) vitessecourant=0.5*sqrt((u(im-1,jm)+u(im,jm))**2.+(v(im,jm)+v(im,jm-1))**2.)
         IF(im.eq.1.and.jm.gt.1) vitessecourant=0.5*sqrt((u(im,jm)+u(im,jm))**2.+(v(im,jm)+v(im,jm-1))**2.)
         IF(im.gt.1.and.jm.eq.1) vitessecourant=0.5*sqrt((u(im-1,jm)+u(im,jm))**2.+(v(im,jm)+v(im,jm))**2.)
         IF(im.eq.1.and.jm.eq.1) vitessecourant=sqrt(u(im,jm)*u(im,jm)+v(im,jm)*v(im,jm))
 
        ELSE
!       vitessecourant=sqrt(uz(1,im,jm)*uz(1,im,jm)+vz(1,im,jm)*vz(1,im,jm))
         IF(im.gt.1.and.jm.gt.1) vitessecourant=0.5*sqrt((uz(1,im-1,jm)+uz(1,im,jm))**2.+(vz(1,im,jm)+vz(1,im,jm-1))**2.)
         IF(im.eq.1.and.jm.gt.1) vitessecourant=0.5*sqrt((uz(1,im,jm)+uz(1,im,jm))**2.+(vz(1,im,jm)+vz(1,im,jm-1))**2.)
         IF(im.gt.1.and.jm.eq.1) vitessecourant=0.5*sqrt((uz(1,im-1,jm)+uz(1,im,jm))**2.+(vz(1,im,jm)+vz(1,im,jm))**2.)
         IF(im.eq.1.and.jm.eq.1) vitessecourant=sqrt(uz(1,im,jm)*uz(1,im,jm)+vz(1,im,jm)*vz(1,im,jm))
        ENDIF

        facto2mort=1.2


!	Meiofaune et Bacteries
!	======================

        db= c(iv_benth_N)/1000.0_rsh
        bmeiosurfacique=c(iv_benth_meio_N)
        alimdb_bm=0.
        IF(db.ge.p_meio_satur_proie) THEN
          alimdb_bm =p_meio_capdet
        ELSE
          IF(db.le.p_meio_thrdet) THEN
            alimdb_bm =0.
          ELSE
            alimdb_bm=(db-p_meio_thrdet)/(p_meio_satur_proie-p_meio_thrdet)*p_meio_capdet
          ENDIF
        ENDIF

        dbf=c(iv_benth_phyto_diat_N)/1000.0_rsh
        alimdbf_bm=0.
        IF(dbf.ge.p_meio_satur_proie) THEN
          alimdbf_bm =p_meio_capdiat
        ELSE
          IF(dbf.le.p_meio_thrdiat) THEN
           alimdbf_bm =0.
         ELSE
           alimdbf_bm=(dbf-p_meio_thrdiat)/(p_meio_satur_proie-p_meio_thrdiat)*p_meio_capdiat
         ENDIF
       ENDIF

        perte_mort_bm=p_meio_mort*facto2mort
       perte_excr_bm=p_meio_pphysio
       pertbm=perte_mort_bm+perte_excr_bm
       somlim=alimdb_bm+alimdbf_bm
       IF(somlim.gt.0.) THEN
        egestmoybm = (alimdb_bm/somlim*p_meio_egest_det+alimdbf_bm  &
               /somlim*p_meio_egest_det) /(p_meio_egest_det+p_meio_egest_det)

       IF(bmeiosurfacique.ge.p_meio_thrmax_inhib) THEN
          autolimbm = pertbm/(p_meio_inges*(1-egestmoybm))
       ELSE
          IF(bmeiosurfacique.le.p_meio_thrmin_inhib) THEN
          autolimbm = 1.
         ELSE
          autolimbm = 1.-(1.-pertbm/(p_meio_inges*(1-egestmoybm)))*   &
              (bmeiosurfacique-p_meio_thrmin_inhib)/(p_meio_thrmax_inhib-p_meio_thrmin_inhib) 
          ENDIF
       ENDIF

      ENDIF

!	Deposivores Herbivores
!	======================

        bdeposivsurfacique=c(iv_benth_deposi_N)
       alimdb_dh =0.
       IF(db.ge.p_deposi_satur_proie) THEN
         alimdb_dh =p_deposi_capdet
       ELSE
       IF(db.le.p_deposi_thrdet) THEN
         alimdb_dh =0.
       ELSE
       alimdb_dh=(db-p_deposi_thrdet)/(p_deposi_satur_proie-p_deposi_thrdet)*p_deposi_capdet
       ENDIF
       ENDIF

        alimdbf_dh =0.
        if(dbf.ge.p_deposi_satur_proie) THEN
          alimdbf_dh =p_deposi_capdiat
        else
        if(dbf.le.p_deposi_thrdet) THEN
          alimdbf_dh =0.
        else
        alimdbf_dh=(dbf-p_deposi_thrdet)/(p_deposi_satur_proie-p_deposi_thrdet)*p_deposi_capdiat
        endif
        endif

        alimbm_dh=0.
                IF(bmeiosurfacique.ge.p_deposi_satur_proie) THEN
          alimbm_dh =p_deposi_capmeio
        else
          IF(bmeiosurfacique.le.p_deposi_thrmeio) THEN
            alimbm_dh =0.
          ELSE
          alimbm_dh=(c(iv_benth_meio_N)-p_deposi_thrmeio)/(p_deposi_satur_proie-  &
                   p_deposi_thrmeio)*p_deposi_capmeio
          ENDIF
        endif

        perte_mort_dh=p_deposi_mort*facto2mort
                cr_dh=p_deposi_pphysio
        pertdh=perte_mort_dh+perte_excr_dh
        somlim=alimdb_dh+alimdbf_dh+alimbm_dh
        if(somlim.gt.0.) THEN
         egestmoydh =(alimbm_dh/somlim*p_deposi_egest_meio+alimdb_dh  &
             /somlim*p_deposi_egest_det+alimdbf_dh/somlim*p_deposi_egest_diat)  &
             /(p_deposi_egest_meio+p_deposi_egest_det+p_deposi_egest_diat)

         IF(bdeposivsurfacique.ge.p_deposi_thrmax_inhib) THEN
           autolimdh = pertdh/(p_deposi_inges*(1-egestmoydh))
         ELSE
          IF(bdeposivsurfacique.le.p_deposi_thrmin_inhib) THEN
           autolimdh = 1.
          ELSE
           autolimdh = 1.-(1.-pertdh/(p_deposi_inges*(1-egestmoydh)))*   &
           (bdeposivsurfacique-p_deposi_thrmin_inhib)/(p_deposi_thrmax_inhib-p_deposi_thrmin_inhib) 
          ENDIF
         ENDIF

        endif


!	Suspensivores
!	=============

        seuil_courant_susp=10.8
        bsuspensivsurfacique=c(iv_benth_susp_N)
        alimdetp_su=0.
        if ((ndeteaufond.ge.p_susp_satur_proie).and.(vitessecourant.le.seuil_courant_susp)) THEN
         alimdetp_su=p_susp_capdet
        else
         IF((ndeteaufond.le.p_susp_thrdet).or.(vitessecourant.gt.seuil_courant_susp)) THEN
          alimdetp_su=0.
         ELSE
          alimdetp_su=(ndeteaufond-p_susp_thrdet)/(p_susp_satur_proie-p_susp_thrdet)*p_susp_capdet
         ENDIF
        endif

        alimphy_su=0.   
        if ((phytoeaufond.ge.p_susp_satur_proie).and.(vitessecourant.le.seuil_courant_susp)) THEN
         alimphy_su=p_susp_capphy
        else
         IF((phytoeaufond.le.p_susp_thrphy).or.(vitessecourant.gt.seuil_courant_susp)) THEN
          alimphy_su=0.
         ELSE
        alimphy_su=(phytoeaufond-p_susp_thrphy)/(p_susp_satur_proie-p_susp_thrphy)*p_susp_capphy
         ENDIF
        endif

        perte_mort_su=p_susp_mort*facto2mort
        perte_excr_su=p_susp_pphysio
        pertsu=perte_mort_su+perte_excr_su
        somlim= alimdetp_su+alimphy_su
        if(somlim.gt.0.) THEN

         egestmoysu =(alimdetp_su/somlim*p_susp_egest_det+alimphy_su/somlim*p_susp_egest_phy)  &
                     /(p_susp_egest_det+p_susp_egest_phy)

         IF(bsuspensivsurfacique.ge.p_susp_thrmax_inhib) THEN
          autolimsu = pertsu/(p_susp_inges*(1-egestmoysu))
         ELSE
          IF(bsuspensivsurfacique.le.p_susp_thrmin_inhib) THEN
           autolimsu = 1.
          ELSE
           autolimsu = 1.-(1.-pertsu/(p_susp_inges*(1-egestmoysu)))*   &
           (bsuspensivsurfacique-p_susp_thrmin_inhib)/(p_susp_thrmax_inhib-p_susp_thrmin_inhib) 
          ENDIF
         ENDIF
        ENDIF

!   Limitation de la consommation de detritique pelagique par le minimum
!    des stocks pelagiques de N et P detritiques
        consommationazotedetpelagic=(c(iv_benth_susp_N)*p_susp_inges*autolimsu  &
          *alimdetp_su*effetchaleur)*ibbenth
        IF (consommationazotedetpelagic.gt.0.) THEN
        consommationazotedetpelagic1=amin1((ndeteaufond/dtbio*86400.0_rlg*epn/1000.),              &
        (pdeteaufond/dtbio*86400.0_rlg*epn/1000.*p_phyto_NPratio),consommationazotedetpelagic)
        tauxcorrectif=consommationazotedetpelagic1/consommationazotedetpelagic
        alimdetp_su=alimdetp_su*tauxcorrectif
        ENDIF

!	
!	Carnivores + Poissons
!	=====================

        bcarnivsurfacique=c(iv_benth_carn_N)

        alimbm_cp=0.
        if(bmeiosurfacique.ge.p_carn_satur_proie) THEN
        alimbm_cp=p_carn_capmeio
        else
        if(bmeiosurfacique.le.p_carn_thrmeio) THEN
        alimbm_cp=0.
        else
        alimbm_cp=(bmeiosurfacique-p_carn_thrmeio)/(p_carn_satur_proie-p_carn_thrmeio)*p_carn_capmeio
         ENDIF
        endif        
        alimdh_cp=0.
        if(bdeposivsurfacique.ge.p_carn_satur_proie) THEN
        alimdh_cp=p_carn_capdeposi
        else
        if(bdeposivsurfacique.le.p_carn_thrdeposi) THEN
        alimdh_cp=0.
        else
        alimdh_cp=(bdeposivsurfacique-p_carn_thrdeposi)/(p_carn_satur_proie-p_carn_thrdeposi)*p_carn_capdeposi
         ENDIF
        endif

        alimsu_cp=0.
        if(bsuspensivsurfacique.ge.p_carn_satur_proie_susp) THEN
        alimsu_cp=p_carn_capsusp
        else
        if(bsuspensivsurfacique.le.p_carn_thrsusp) THEN
        alimsu_cp=0.
        else
        alimsu_cp=(bsuspensivsurfacique-p_carn_thrsusp)/(p_carn_satur_proie_susp-p_carn_thrsusp)*p_carn_capsusp
         ENDIF
        endif

        perte_mort_cp=p_carn_mort*facto2mort
        perte_excr_cp=p_carn_pphysio
        pertcp=perte_mort_cp+perte_excr_cp

        IF(bcarnivsurfacique.ge.p_carn_thrmax_inhib) THEN
          autolimcp = pertcp/(p_carn_inges*(1-p_carn_egest))
        ELSE
         IF(bcarnivsurfacique.le.p_carn_thrmin_inhib) THEN
          autolimcp = 1.
         ELSE
        autolimcp = 1.-(1.-pertcp/(p_carn_inges*(1-p_carn_egest)))*   &
               (bcarnivsurfacique-p_carn_thrmin_inhib)/(p_carn_thrmax_inhib-p_carn_thrmin_inhib) 
         ENDIF
        ENDIF


!   Limitation de la consommation de detritique benthique par le minimum
!    des stocks sedimentaires de N et P detritiques

        consommationazotedetbenthic=(c(iv_benth_meio_N)*p_meio_inges*autolimbm*alimdb_bm+   &
                    c(iv_benth_deposi_N)*p_deposi_inges*autolimdh*alimdb_dh)*effetchaleur*1000.
        IF (consommationazotedetbenthic.gt.0.) THEN
        consommationazotedetbenthic1=amin1((c(iv_benth_N)/dtbio*86400.0_rlg),   &
                   (c(iv_benth_P)/dtbio*86400.0_rlg*p_phyto_NPratio),consommationazotedetbenthic)
        tauxcorrectif=consommationazotedetbenthic1/consommationazotedetbenthic
        alimdb_bm=alimdb_bm*tauxcorrectif
        alimdb_dh=alimdb_dh*tauxcorrectif
        consommationazotedetbenthic=consommationazotedetbenthic*tauxcorrectif
        ENDIF

!        perteazotesolide=(bmeiosurfacique*(p_meio_inges*autolimbm*p_meio_egest_det*  &
!	     (alimdb_bm+alimdbf_bm)+p_meio_mort) +bdeposivsurfacique*   &
!	     (p_deposi_inges*autolimdh*(p_deposi_egest_det*alimdb_dh+   &
!	     p_deposi_egest_diat*alimdbf_dh+p_deposi_egest_meio*alimbm_dh)+   &
!	     p_deposi_mort)+bsuspensivsurfacique*p_susp_mort+bcarnivsurfacique*   &
!	     (p_carn_inges*autolimcp*p_carn_egest*(alimbm_cp+alimdh_cp+alimsu_cp)+  &
!	     p_carn_mort))*effetchaleur*1000.0_rsh/epn
        perteazotesolide=(bmeiosurfacique*(p_meio_inges*autolimbm*p_meio_egest_det*  &
             (alimdb_bm+alimdbf_bm)+perte_mort_bm) +bdeposivsurfacique*   &
             (p_deposi_inges*autolimdh*(p_deposi_egest_det*alimdb_dh+   &
             p_deposi_egest_diat*alimdbf_dh+p_deposi_egest_meio*alimbm_dh)+   &
             perte_mort_dh)+bsuspensivsurfacique*perte_mort_su+bcarnivsurfacique*   &
             (p_carn_inges*autolimcp*p_carn_egest*(alimbm_cp+alimdh_cp+alimsu_cp)+  &
             perte_mort_cp))*effetchaleur*1000.0_rsh


      ENDIF
      
 
   !++++++++++++++++++++++++++++++++++++
   ! Processus lies au benthos generique 
   !++++++++++++++++++++++++++++++++++++
     
! 	Evolution des bacteries+meiofaune benthiques (molN/m2)
!        -------------------------------------------------------

        dc(iv_benth_meio_N)=ibbenth*(c(iv_benth_meio_N)*effetchaleur*((p_meio_inges* &
              (1-p_meio_egest_det)*(alimdb_bm+alimdbf_bm)*autolimbm)-pertbm)-  &
               c(iv_benth_deposi_N)*effetchaleur*p_deposi_inges*autolimdh*alimbm_dh-  &
               c(iv_benth_carn_N)*effetchaleur*p_carn_inges*autolimcp*alimbm_cp)

!        dcmax=-c(iv_benth_meio_N)/dtbio*86400.0_rlg*ibbenth
!        IF (dc(iv_benth_meio_N).lt.dcmax) THEN
!          dc(iv_benth_meio_N)=dcmax*0.95
!!          print*,'Variable Meiofaune devenant negative en boite ',ib,',couche ', kb
!        ENDIF

! 	Evolution des deposivores herbivores (molN/m2)
!        -------------------------------------------------------

        dc(iv_benth_deposi_N) =ibbenth*(c(iv_benth_deposi_N)*effetchaleur*((p_deposi_inges*  &
                     autolimdh*((1-p_deposi_egest_det)*alimdb_dh+(1-p_deposi_egest_diat)*   &
                     alimdbf_dh+(1-p_deposi_egest_meio)*alimbm_dh))-pertdh)-    &
                     c(iv_benth_carn_N)*effetchaleur*p_carn_inges*autolimcp*alimdh_cp)

!        dcmax=-c(iv_benth_deposi_N)/dtbio*86400.0_rlg*ibbenth
!        IF (dc(iv_benth_deposi_N).lt.dcmax) THEN
!          dc(iv_benth_deposi_N)=dcmax*0.95
!!          print*,'Variable Deposivores devenant negative en boite ',ib,',couche ', kb
!        ENDIF

! 	Evolution des suspensivores (molN/m2)
!        ------------------------------------

        dc(iv_benth_susp_N) =ibbenth *(c(iv_benth_susp_N)*effetchaleur*   &
           (p_susp_inges*autolimsu*((1-p_susp_egest_det)*alimdetp_su+   &
           (1-p_susp_egest_phy)*alimphy_su)-pertsu)        &
           -c(iv_benth_carn_N)*effetchaleur*p_carn_inges*autolimcp*alimsu_cp)

!        dcmax=-c(iv_benth_susp_N)/dtbio*86400.0_rlg*ibbenth
!        IF (dc(iv_benth_susp_N).lt.dcmax) THEN
!          dc(iv_benth_susp_N)=dcmax*0.95
!!         print*,'Variable Deposivores devenant negative en maille ',im,',',jm
!        ENDIF

! 	Evolution des carnivores (molN/m2)
!        ---------------------------------

        dc(iv_benth_carn_N) =ibbenth *(c(iv_benth_carn_N)*effetchaleur*((p_carn_inges*autolimcp*  &
                  (1-p_carn_egest)*(alimbm_cp+alimdh_cp+alimsu_cp))-pertcp))

!        dcmax=-c(iv_benth_carn_N)/dtbio*86400.0_rlg*ibbenth
!        IF (dc(iv_benth_carn_N).lt.dcmax) THEN
!          dc(iv_benth_carn_N)=dcmax*0.95
!!          print*,'Variable Carnivores devenant negative en boite ',ib,',couche ', kb
!        ENDIF
   
   ! Evolution des diatomees pelagiques
   ! ------------------------------
    dc(iv_phyto_diat_N)=dc(iv_phyto_diat_N)-ibbenth*(bsuspensivsurfacique*p_susp_inges    &
                 *propdiat*autolimsu*alimphy_su*effetchaleur*1000._rsh/epn)
!    dc1=-ibbenth*(bsuspensivsurfacique*p_susp_inges    &
!                 *propdiat*autolimsu*alimphy_su*effetchaleur*1000._rsh/epn)
   
   ! Evolution des diatomes benthiques en mmol.m-2.jour-1
   ! ------------------------------
    dc(iv_benth_phyto_diat_N)=dc(iv_benth_phyto_diat_N)-ibbenth*(bdeposivsurfacique*p_deposi_inges  &
                  *autolimdh*alimdbf_dh*effetchaleur*1000.0_rsh+ &
                  bmeiosurfacique*p_meio_inges*autolimbm*alimdbf_bm*effetchaleur*1000.0_rsh)
!      dc2=-ibbenth*(bdeposivsurfacique*p_deposi_inges  &
!                  *autolimdh*alimdbf_dh*effetchaleur*1000.0_rsh+ &
!		  bmeiosurfacique*p_meio_inges*autolimbm*alimdbf_bm*effetchaleur*1000.0_rsh)
!      IF (im.eq.233.and.jm.eq.93.and.km.eq.1) write(*,*)'dc2=',bdeposivsurfacique,p_deposi_inges, &
!      autolimdh,alimdbf_dh,bmeiosurfacique,p_meio_inges,autolimbm,alimdbf_bm

   ! Evolution des dinoflagelles
   ! ------------------------------
    dc(iv_phyto_dino_N)=dc(iv_phyto_dino_N)-ibbenth*bsuspensivsurfacique*p_susp_inges    &
                 *propdino*autolimsu*alimphy_su*effetchaleur*1000._rsh/epn
!    dc3=-ibbenth*bsuspensivsurfacique*p_susp_inges    &
!                 *propdino*autolimsu*alimphy_su*effetchaleur*1000._rsh/epn

   ! Evolution des Nanoflagelles
   ! ------------------------------
    dc(iv_phyto_nano_N)=dc(iv_phyto_nano_N)-ibbenth*bsuspensivsurfacique*p_susp_inges    &
                 *propnano*autolimsu*alimphy_su*effetchaleur*1000._rsh/epn
!    dc4=-ibbenth*bsuspensivsurfacique*p_susp_inges    &
!                 *propnano*autolimsu*alimphy_su*effetchaleur*1000._rsh/epn

   ! Evolution de l azote detritique
   ! ------------------------------
      dc(iv_detr_N)=dc(iv_detr_N)-ibbenth*bsuspensivsurfacique*p_susp_inges   &
         *autolimsu*alimdetp_su*1000._rsh*effetchaleur/epn     
!      dc5=-ibbenth*bsuspensivsurfacique*p_susp_inges   &
!         *autolimsu*alimdetp_su*1000._rsh*effetchaleur/epn
    
   ! Evolution de la silice detritique
   ! ------------------------------
      dc(iv_detr_Si)=dc(iv_detr_Si)+ibbenth*(bsuspensivsurfacique*p_susp_inges    &
                 *propdiat*autolimsu*alimphy_su*effetchaleur*1000._rsh/epn)*p_phyto_SiNratio
!      dc6=+ibbenth*(bsuspensivsurfacique*p_susp_inges    &
!                 *propdiat*autolimsu*alimphy_su*effetchaleur*1000._rsh/epn)*p_phyto_SiNratio

   ! Evolution du phosphore detritique
   ! ------------------------------
      dc(iv_detr_P)=dc(iv_detr_P)-ibbenth*bsuspensivsurfacique*p_susp_inges*autolimsu*   &
           alimdetp_su*1000._rsh*effetchaleur/p_phyto_NPratio/epn     
!      dc7=-ibbenth*bsuspensivsurfacique*p_susp_inges*autolimsu*   &
!           alimdetp_su*1000._rsh*effetchaleur/p_phyto_NPratio/epn

   ! Evolution de l ammonium
   ! -----------------------
    dc(iv_nutr_NH4)=dc(iv_nutr_NH4)+ibbenth*effetchaleur*1000._rsh/epn*  &
                    (bmeiosurfacique*perte_excr_bm+bdeposivsurfacique*perte_excr_dh+  &
                     bsuspensivsurfacique*perte_excr_su+bcarnivsurfacique*perte_excr_cp)
!      dc11=ibbenth*effetchaleur*1000._rsh/epn*  &
!                    (bmeiosurfacique*perte_excr_bm+bdeposivsurfacique*perte_excr_dh+  &
!		     bsuspensivsurfacique*perte_excr_su+bcarnivsurfacique*perte_excr_cp)

   ! Evolution de l azote organique benthique
   ! ------------------------------
      dc(iv_benth_N)=dc(iv_benth_N)+(perteazotesolide-consommationazotedetbenthic)*ibbenth  &
                    +ibbenth*bsuspensivsurfacique*p_susp_inges   &
         *autolimsu*(p_susp_egest_det*alimdetp_su+p_susp_egest_phy*alimphy_su)*1000._rsh*effetchaleur
!      dc8=(perteazotesolide-consommationazotedetbenthic)*ibbenth  &
!                    +ibbenth*bsuspensivsurfacique*p_susp_inges   &
!         *autolimsu*(p_susp_egest_det*alimdetp_su+p_susp_egest_phy*alimphy_su)*1000._rsh*effetchaleur

   ! Evolution du phosphore organique benthique
   ! ------------------------------
      dc(iv_benth_P)=dc(iv_benth_P)+(perteazotesolide-consommationazotedetbenthic)/p_phyto_NPratio*ibbenth  &
                    +ibbenth*bsuspensivsurfacique*p_susp_inges*autolimsu*   &
                   (p_susp_egest_det*alimdetp_su+p_susp_egest_phy*alimphy_su    &
                    )*1000._rsh*effetchaleur/p_phyto_NPratio
!      dc9=(perteazotesolide-consommationazotedetbenthic)/p_phyto_NPratio*ibbenth  &
!                    +ibbenth*bsuspensivsurfacique*p_susp_inges*autolimsu*   &
!                   (p_susp_egest_det*alimdetp_su+p_susp_egest_phy*alimphy_su    &
!	            )*1000._rsh*effetchaleur/p_phyto_NPratio

   ! Evolution de la silice organique benthique
   ! ------------------------------
      dc(iv_benth_Si)=dc(iv_benth_Si)+(bdeposivsurfacique*p_deposi_inges*autolimdh*alimdbf_dh   &
                 +bsuspensivsurfacique*p_susp_inges*propdiat*autolimsu*alimphy_su    &
                 +bmeiosurfacique*p_meio_inges*autolimbm*alimdbf_bm)*effetchaleur*1000._rsh*ibbenth*p_phyto_SiNratio
!      dc10=(bdeposivsurfacique*p_deposi_inges*autolimdh*alimdbf_dh   &
!		 +bsuspensivsurfacique*p_susp_inges*propdiat*autolimsu*alimphy_su    &
!                 +bmeiosurfacique*p_meio_inges*autolimbm*alimdbf_bm)*effetchaleur*1000._rsh*ibbenth*p_phyto_SiNratio
!
!      dcNtotal=((dc(iv_benth_meio_N)+dc(iv_benth_deposi_N)+dc(iv_benth_susp_N)+dc(iv_benth_carn_N))*1000.  &
!            +(dc1+dc3+dc4+dc5+dc11)*epn+dc2+dc8)*ibbenth
!
!      IF (im.eq.233.and.jm.eq.93.and.km.eq.1) write(*,*)'dcNtotal=',dcNtotal


   END SUBROUTINE incellwat_benthos_4comp
#endif

   !!======================================================================
#ifdef key_benthos_old

  SUBROUTINE incellwat_benthos_old(km,im,jm,xe,c,dc)

   !&E---------------------------------------------------------------------
   !&E                 ***  ROUTINE incellwat_benthos  ***
   !&E
   !&E ** Purpose : Calcul du stockage du detritique dans 3 variables benthiques
   !&E              
   !&E
   !&E ** Description :
   !&E
   !&E ** Called by :  incellwat_nut4phy3zoo2
   !&E
   !&E ** External calls :
   !&E
   !&E ** Reference :
   !&E
   !&E ** History :
   !&E       !  2010-02    (A. Menesguen, M. Dussauze) Original code
   !&E       !  ???????    (  )  evolutions
   !&E
   !&E---------------------------------------------------------------------
   !! * Modules used
   USE comsubstance, ONLY : attenuation,extinction,alumplafond
   USE comvars2d,    ONLY : h0,hm,dx,dy
   
 
   !! * Arguments
   INTEGER, INTENT( in ) ::   km,im,jm      ! ocean spatial-step index
   REAL(KIND=rsh),             INTENT(in) :: xe     !ssh
   REAL(KIND=rsh),DIMENSION(:),INTENT(in) :: c
   REAL(KIND=rsh),DIMENSION(:),INTENT(inout) :: dc

   
   !! * Local declarations

   ! indices de boucles
   ! ------------------
   INTEGER :: toto
   
   !!---------------------------------------------------------------------
   !! * Executable part


   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
   ! saisir le code apres cette limite
   ! =================================
   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 
 
   !++++++++++++++++++++++++++++++++++++
   ! Processus lies au benthos 
   !++++++++++++++++++++++++++++++++++++
     
   ! Evolution de l azote organique benthique
   ! ------------------------------
   
    dc(iv_benth_N)=(c(iv_detr_N)*MIN(0.70_rlg,REAL(ABS(ws3(2,iv_detr_N,im,jm)),rlg)/epn*dtbio)*86400.0_rsh/dtbio)*ibbenth   &
           -(reminazdeteau*p_reminbenth)*c(iv_benth_N)*ibbenth  !&		   
          ! -(reminazdeteau*0.3_rsh)*c(iv_benth_N)*ibbenth
         !+(c(iv_phyto_diat_N)*MIN(0.95_rlg,REAL(ABS(ws3(2,iv_phyto_diat_N,im,jm)),rlg)/epn*dtbio)*86400.0_rsh/dtbio)*ibbenth
                             
   ! Evolution du silicium organique benthique
   ! ------------------------------
!    dc(iv_benth_Si)=(c(iv_detr_Si)*MIN(0.95_rlg,REAL(ABS(ws3(2,iv_detr_Si,im,jm)),rlg)/epn*dtbio)*86400.0_rsh/dtbio)*ibbenth &
    dc(iv_benth_Si)=(c(iv_detr_Si)*MIN(0.70_rlg,REAL(ABS(ws3(2,iv_detr_Si,im,jm)),rlg)/epn*dtbio)*86400.0_rsh/dtbio)*ibbenth &
                     -(dissolsiliceeau*p_reminbenth)*c(iv_benth_Si)*ibbenth !& 
       ! -(dissolsiliceeau*0.3_rsh)*c(iv_benth_Si)*ibbenth
       !+(c(iv_phyto_diat_N)*MIN(0.95_rlg,REAL(ABS(ws3(2,iv_phyto_diat_N,im,jm)),rlg)/epn*dtbio)*86400.0_rsh/dtbio)*rapsiaz*ibbenth
   
   ! Evolution du phosphore organique benthique
   ! ------------------------------
!    dc(iv_benth_P)=(c(iv_detr_P)*MIN(0.95_rlg,REAL(ABS(ws3(2,iv_detr_P,im,jm)),rlg)/epn*dtbio)*86400.0_rsh/dtbio)*ibbenth &
    dc(iv_benth_P)=(c(iv_detr_P)*MIN(0.70_rlg,REAL(ABS(ws3(2,iv_detr_P,im,jm)),rlg)/epn*dtbio)*86400.0_rsh/dtbio)*ibbenth &
                   -(reminpdeteau*p_reminbenth)*c(iv_benth_P)*ibbenth  !&
       !-(reminpdeteau*0.3_rsh)*c(iv_benth_P)*ibbenth
       !+(c(iv_phyto_diat_N)*MIN(0.95_rlg,REAL(ABS(ws3(2,iv_phyto_diat_N,im,jm)),rlg)/epn*dtbio)*86400.0_rsh/dtbio)*rappaz*ibbenth
   
   ! Evolution du silicium dissous
   ! ------------------------------
      dc(iv_nutr_SiOH)=dc(iv_nutr_SiOH)+(dissolsiliceeau*p_reminbenth)*c(iv_benth_Si)*ibbenth
      
   ! Evolution du phosphore dissous
   ! ------------------------------   
      dc(iv_nutr_PO4)=dc(iv_nutr_PO4)+(reminpdeteau*p_reminbenth)*c(iv_benth_P)*ibbenth

   ! Evolution de l azote detritique
   ! ------------------------------
!      dc(iv_detr_N)=dc(iv_detr_N)  &
!           -(c(iv_detr_N)*MIN(0.95_rlg,REAL(ABS(ws3(2,iv_detr_N,im,jm)),rlg)/epn*dtbio)*86400.0_rsh/dtbio)*ibbenth
      dc(iv_detr_N)=dc(iv_detr_N)- &
             (c(iv_detr_N)*MIN(0.70_rlg,REAL(ABS(ws3(2,iv_detr_N,im,jm)),rlg)/epn*dtbio)*86400.0_rsh/dtbio)*ibbenth
      
   ! Evolution de la silice detritique
   ! ------------------------------
!      dc(iv_detr_Si)=dc(iv_detr_Si)- &
!            (c(iv_detr_Si)*MIN(0.95_rlg,REAL(ABS(ws3(2,iv_detr_Si,im,jm)),rlg)/epn*dtbio)*86400.0_rsh/dtbio)*ibbenth
      dc(iv_detr_Si)=dc(iv_detr_Si)-  & 
             (c(iv_detr_Si)*MIN(0.70_rlg,REAL(ABS(ws3(2,iv_detr_Si,im,jm)),rlg)/epn*dtbio)*86400.0_rsh/dtbio)*ibbenth
      
   ! Evolution du phosphore detritique
   ! ------------------------------
!      dc(iv_detr_P)=dc(iv_detr_P)- &
!             (c(iv_detr_P)*MIN(0.95_rlg,REAL(ABS(ws3(2,iv_detr_P,im,jm)),rlg)/epn*dtbio)*86400.0_rsh/dtbio)*ibbenth
      dc(iv_detr_P)=dc(iv_detr_P)- &
              (c(iv_detr_P)*MIN(0.70_rlg,REAL(ABS(ws3(2,iv_detr_P,im,jm)),rlg)/epn*dtbio)*86400.0_rsh/dtbio)*ibbenth
      
   ! Evolution de l ammonium
   ! ------------------------------
    dc(iv_nutr_NH4)=dc(iv_nutr_NH4)+(reminazdeteau*p_reminbenth)*c(iv_benth_N)*ibbenth
    
   ! Evolution des diatomees
   ! ------------------------------
   ! dc(iv_phyto_diat_N)=dc(iv_phyto_diat_N)- &
   !          (c(iv_phyto_diat_N)*MIN(0.95_rlg,REAL(ABS(ws3(2,iv_phyto_diat_N,im,jm)),rlg)/epn*dtbio)*86400.0_rsh/dtbio)*ibbenth
    
    
   END SUBROUTINE incellwat_benthos_old
#endif
   !!======================================================================

#ifdef key_suspensivores

  SUBROUTINE incellwat_suspensivores(km,im,jm,xe,c,dc)

   !&E---------------------------------------------------------------------
   !&E                 ***  ROUTINE incellwat_suspensivores  ***
   !&E
   !&E ** Purpose : Calcul d une variable suspensivore generique
   !&E              
   !&E
   !&E ** Description :
   !&E
   !&E ** Called by :  incellwat_nut4phy3zoo2
   !&E
   !&E ** External calls :
   !&E
   !&E ** Reference :
   !&E
   !&E ** History :
   !&E       !  2010-11    (P. Cugier, A. Menesguen) Original code
   !&E       !  ???????    (  )  evolutions
   !&E
   !&E---------------------------------------------------------------------
   !! * Modules used
   USE comsubstance, ONLY : attenuation,extinction,alumplafond
   USE comvars2d,    ONLY : h0,hm,dx,dy
   USE comvarp2d,    ONLY  : u,v
   USE comvarp3d,    ONLY  : uz,vz
   
 
   !! * Arguments
   INTEGER, INTENT( in ) ::   km,im,jm      ! ocean spatial-step index
   REAL(KIND=rsh),             INTENT(in) :: xe     !ssh
   REAL(KIND=rsh),DIMENSION(:),INTENT(in) :: c
   REAL(KIND=rsh),DIMENSION(:),INTENT(inout) :: dc

   
   !! * Local declarations

   ! indices de boucles
   ! ------------------
   INTEGER :: iv,k,toto
   REAL(KIND=rlg)                            :: tjour
   
   ! variables temperature, salinite
   ! -------------------------------
   REAL(KIND=rsh) :: effetchaleurT
 

    
   ! variables suspensivore
   ! ----------------------
   REAL(KIND=rsh) :: phytoeaufond,ndeteaufond,pdeteaufond,propdiat,propdino,propnano
   REAL(KIND=rsh) :: propphyt,vitessecourant,alimdetp_su,alimphy_su,facto2mort
   REAL(KIND=rsh) :: pertsu,somlim,egestmoysu,bsuspensivsurfacique
   REAL(KIND=rsh) :: autolimsu,consommationazotedetpelagic,consommationazotedetpelagic1,dcmax
   REAL(KIND=rsh) :: tauxcorrectif,somorga,seuil_courant_susp

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


   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
   ! saisir le code apres cette limite
   ! =================================
   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

   !+++++++++++++++++++++++++++++
   ! Calculs communs
   !+++++++++++++++++++++++++++++

   ! salinite
   sali=sal(km,im,jm)
   ! temperature & effetchaleur
   tempabs=temp(km,im,jm)+273.15_rsh
   temper=temp(km,im,jm)
   IF (temper > 30.0_rsh) THEN
    write(*,*) 'tempwat',km,im,jm,temper
    temper=15.0_rsh
   ENDIF
   effetchaleur=exp(p_T_effect*temper)
     
   
      IF(ibbenth.eq.1) THEN
        phytoeaufond=c(iv_phyto_diat_N)+c(iv_phyto_dino_N)+c(iv_phyto_nano_N)
        ndeteaufond=c(iv_detr_N)
        pdeteaufond=c(iv_detr_P)
        somorga=phytoeaufond+c(iv_detr_N)
        IF(somorga.gt.0.) THEN
        propdiat=c(iv_phyto_diat_N)/phytoeaufond
        propdino=c(iv_phyto_dino_N)/phytoeaufond
        propnano=c(iv_phyto_nano_N)/phytoeaufond
        propphyt=phytoeaufond/(phytoeaufond+c(iv_detr_N))
        ELSE
        propdiat=0.
        propdino=0.
        propnano=0.
        propphyt=0.
        ENDIF
        vitessecourant=0.
        IF(d.le.hm) THEN
!       vitessecourant=sqrt(u(im,jm)*u(im,jm)+v(im,jm)*v(im,jm))
         IF(im.gt.1.and.jm.gt.1) vitessecourant=0.5*sqrt((u(im-1,jm)+u(im,jm))**2.+(v(im,jm)+v(im,jm-1))**2.)
         IF(im.eq.1.and.jm.gt.1) vitessecourant=0.5*sqrt((u(im,jm)+u(im,jm))**2.+(v(im,jm)+v(im,jm-1))**2.)
         IF(im.gt.1.and.jm.eq.1) vitessecourant=0.5*sqrt((u(im-1,jm)+u(im,jm))**2.+(v(im,jm)+v(im,jm))**2.)
         IF(im.eq.1.and.jm.eq.1) vitessecourant=sqrt(u(im,jm)*u(im,jm)+v(im,jm)*v(im,jm))
 
        ELSE
!       vitessecourant=sqrt(uz(1,im,jm)*uz(1,im,jm)+vz(1,im,jm)*vz(1,im,jm))
         IF(im.gt.1.and.jm.gt.1) vitessecourant=0.5*sqrt((uz(1,im-1,jm)+uz(1,im,jm))**2.+(vz(1,im,jm)+vz(1,im,jm-1))**2.)
         IF(im.eq.1.and.jm.gt.1) vitessecourant=0.5*sqrt((uz(1,im,jm)+uz(1,im,jm))**2.+(vz(1,im,jm)+vz(1,im,jm-1))**2.)
         IF(im.gt.1.and.jm.eq.1) vitessecourant=0.5*sqrt((uz(1,im-1,jm)+uz(1,im,jm))**2.+(vz(1,im,jm)+vz(1,im,jm))**2.)
         IF(im.eq.1.and.jm.eq.1) vitessecourant=sqrt(uz(1,im,jm)*uz(1,im,jm)+vz(1,im,jm)*vz(1,im,jm))
        ENDIF
!	Suspensivores
!	=============

        seuil_courant_susp=10.0
        IF ((ndeteaufond.ge.p_susp_satur_proie).and.(vitessecourant.le.seuil_courant_susp)) THEN
         alimdetp_su=p_susp_capdet
        ELSE
         IF((ndeteaufond.le.p_susp_thrdet).or.(vitessecourant.gt.seuil_courant_susp)) THEN
          alimdetp_su=0.
         ELSE
          alimdetp_su=(ndeteaufond-p_susp_thrdet)/(p_susp_satur_proie-p_susp_thrdet)*p_susp_capdet
         ENDIF
        ENDIF

        IF ((phytoeaufond.ge.p_susp_satur_proie).and.(vitessecourant.le.seuil_courant_susp)) THEN
         alimphy_su=p_susp_capphy
        ELSE
         IF((phytoeaufond.le.p_susp_thrphy).or.(vitessecourant.gt.seuil_courant_susp)) THEN
          alimphy_su=0.
         ELSE
        alimphy_su=(phytoeaufond-p_susp_thrphy)/(p_susp_satur_proie-p_susp_thrphy)*p_susp_capphy
         ENDIF
        ENDIF

        facto2mort=1.2
        pertsu= p_susp_mort*facto2mort+p_susp_pphysio
        somlim= alimdetp_su+alimphy_su
        IF(somlim.gt.0.) THEN

         egestmoysu =(alimdetp_su/somlim*p_susp_egest_det+alimphy_su/somlim*p_susp_egest_phy)  &
                     /(p_susp_egest_det+p_susp_egest_phy)

         bsuspensivsurfacique=c(iv_benth_susp_N)
         IF(bsuspensivsurfacique.ge.p_susp_thrmax_inhib) THEN
          autolimsu = pertsu/(p_susp_inges*(1-egestmoysu))
         ELSE
          IF(bsuspensivsurfacique.le.p_susp_thrmin_inhib) THEN
           autolimsu = 1.
          ELSE
           autolimsu = 1.-(1.-pertsu/(p_susp_inges*(1-egestmoysu)))*   &
           (bsuspensivsurfacique-p_susp_thrmin_inhib)/(p_susp_thrmax_inhib-p_susp_thrmin_inhib) 
          ENDIF
         ENDIF
        ENDIF

!   Limitation de la consommation de detritique pelagique par le minimum
!    des stocks pelagiques de N et P detritiques

        consommationazotedetpelagic=(c(iv_benth_susp_N)*p_susp_inges*autolimsu  &
          *alimdetp_su*effetchaleur)*ibbenth
        IF (consommationazotedetpelagic.gt.0.) THEN
        consommationazotedetpelagic1=amin1((ndeteaufond/dtbio*86400.0_rlg),              &
        (pdeteaufond/dtbio*86400.0_rlg*p_phyto_NPratio),consommationazotedetpelagic)
        tauxcorrectif=consommationazotedetpelagic1/consommationazotedetpelagic
        alimdetp_su=alimdetp_su*tauxcorrectif
        ENDIF

      ENDIF
 
   !++++++++++++++++++++++++++++++++++++
   ! Processus lies au suspensivores 
   !++++++++++++++++++++++++++++++++++++
     
! 	Evolution des suspensivores (molN/m2)

        dc(iv_benth_susp_N) =ibbenth *(c(iv_benth_susp_N)*effetchaleur*   &
           (p_susp_inges*autolimsu*((1-p_susp_egest_det)*alimdetp_su+   &
          (1-p_susp_egest_phy)*alimphy_su)-pertsu))        !&
!	   -c(18)*effetchaleur*bioparam(112)*autolimcp*alimsu_cp)

        dcmax=-c(iv_benth_susp_N)/dtbio*86400.0_rlg*ibbenth
        IF (dc(iv_benth_susp_N).lt.dcmax) THEN
          dc(iv_benth_susp_N)=dcmax*0.95
!         print*,'Variable Deposivores devenant negative en maille ',im,',',jm
        ENDIF
   
   ! Evolution des diatomees
   ! ------------------------------
    dc(iv_phyto_diat_N)=dc(iv_phyto_diat_N)-ibbenth*bsuspensivsurfacique*p_susp_inges    &
                 *propdiat*autolimsu*alimphy_su*effetchaleur*1000._rsh/epn
   
   ! Evolution des dinoflagelles
   ! ------------------------------
    dc(iv_phyto_dino_N)=dc(iv_phyto_dino_N)-ibbenth*bsuspensivsurfacique*p_susp_inges    &
                 *propdino*autolimsu*alimphy_su*effetchaleur*1000._rsh/epn

   ! Evolution des Nanoflagelles
   ! ------------------------------
    dc(iv_phyto_nano_N)=dc(iv_phyto_nano_N)-ibbenth*bsuspensivsurfacique*p_susp_inges    &
                 *propnano*autolimsu*alimphy_su*effetchaleur*1000._rsh/epn

   ! Evolution de l azote detritique
   ! ------------------------------
      dc(iv_detr_N)=dc(iv_detr_N)+ibbenth*bsuspensivsurfacique*p_susp_inges   &
         *autolimsu*(p_susp_egest_det*alimdetp_su+p_susp_egest_phy*alimphy_su   &
         -(1.-propphyt)*alimdetp_su)*1000._rsh*effetchaleur/epn     
    
   ! Evolution de la silice detritique
   ! ------------------------------
      dc(iv_detr_Si)=dc(iv_detr_Si)+ibbenth*bsuspensivsurfacique*p_susp_inges*autolimsu   &
            *propdiat*alimphy_su*1000._rsh*effetchaleur*p_phyto_SiNratio/epn          	

   ! Evolution du phosphore detritique
   ! ------------------------------
      dc(iv_detr_P)=dc(iv_detr_P)+ibbenth*bsuspensivsurfacique*p_susp_inges*autolimsu*   &
           (p_susp_egest_det*alimdetp_su+p_susp_egest_phy*alimphy_su    &
           -(1.-propphyt)*alimdetp_su)*1000._rsh*effetchaleur/p_phyto_NPratio/epn     


   END SUBROUTINE incellwat_suspensivores
#endif

   !!======================================================================
     SUBROUTINE verif_bilan_NP(km,im,jm,dc,c)
   !&E---------------------------------------------------------------------
   !&E                 ***  ROUTINE verif_bilan_NP  ***
   !&E
   !&E ** Purpose : VERIFICATION conservativite bilan de matiere en N et P
   !&E              en mmolN/m3 en quelques mailles
   !&E
   !&E ** Description :
   !&E
   !&E ** Called by :
   !&E
   !&E ** External calls :
   !&E
   !&E ** Reference :
   !&E
   !&E ** History :
   !&E       !         Benedicte issu de la version r1023 de Alain (MANGA4)
   !&E
   !&E---------------------------------------------------------------------
   !! * Modules used
   
   !! * Arguments
   INTEGER, INTENT(in)                       :: km,im,jm      ! ocean spatial-step index
   REAL(KIND=rsh),DIMENSION(:),INTENT(in)    :: dc,c

   ! test de conservativite de N et P
   ! --------------------------------
   REAL(KIND=rsh) :: somdcN,somdcP

   
!     Conservativite en azote dans la maille im,jm 20 45 couche de fond (Manche ouest)    
!     -----------------------------------------------------------------------------
    somdcN=dc(iv_nutr_NH4)+dc(iv_nutr_NO3)+dc(iv_phyto_diat_N)+dc(iv_phyto_dino_N)+dc(iv_phyto_nano_N)+ &
           dc(iv_detr_N)+dc(iv_zoo_meso_N)+dc(iv_zoo_micr_N) 
#if defined key_benthos
        somdcN=somdcN+(dc(iv_benth_N)+p_burial*c(iv_benth_N))/epn   
#endif
#if defined key_psnz
        somdcN=somdcN+dc(iv_phyto_psnz_N)   
#endif
#if defined key_karenia
        somdcN=somdcN+dc(iv_phyto_karenia_N)
#endif
#if defined key_phaeocystis
        somdcN=somdcN+dc(iv_phyto_phaeocystis_colo_N)+dc(iv_phyto_phaeocystis_cell_N) 
#endif
#if defined key_ulvas
        somdcN=somdcN+dc(iv_ulv_sus_N)+ dc(iv_ulv_benth_N)/epn/0.014  
#endif
        IF(abs(somdcN) > 1.0e-4) THEN
          write(*,*)'____________________________________________________'
          write(*,*)'!!!! PB conservativite N: somdcN =',somdcN
          write(*,*)'!!!! maille i, j, k:',im,jm,km
          write(*,*)'dc: NH4,NO3,diat,dino,nano,detr ',dc(iv_nutr_NH4),dc(iv_nutr_NO3),dc(iv_phyto_diat_N), &
                                                       dc(iv_phyto_dino_N),dc(iv_phyto_nano_N),dc(iv_detr_N)
          write(*,*)'dc: mesozoo,microzoo',dc(iv_zoo_meso_N),dc(iv_zoo_micr_N)
#if defined key_benthos
          write(*,*)'dc: benthos=   ',dc(iv_benth_N)/epn   
#endif
#if defined key_psnz
          write(*,*)'dc: psnz=   ',dc(iv_phyto_psnz_N)   
#endif
#if defined key_karenia
          write(*,*)'dc: karenia=   ',dc(iv_phyto_karenia_N)
#endif
#if defined key_phaeocystis
          write(*,*)'dc: phaeocystis_colo, phaeocystis_cell=   ',dc(iv_phyto_phaeocystis_colo_N),dc(iv_phyto_phaeocystis_cell_N)
#endif
#if defined key_ulvas
          write(*,*)'dc: suspended ulvas, benthic ulvas=   ',dc(iv_ulv_sus_N),dc(iv_ulv_benth_N)/epn/0.014   
#endif
          write(*,*) 'assimilmesozoo=',assimilmesozoo,'broumesozoodiat=',broumesozoodiat,'rationmesozoo=',rationmesozoo  
          write(*,*) 'broumesozoodino=',broumesozoodino,'broumesozoomicrozoo=',broumesozoomicrozoo 
!          stop
        ENDIF


!     Conservativite en phosphore dans la maille 20 45 couche de fond (Manche ouest) 
!     ---------------------------------------------------------------------------------
        somdcP=dc(iv_nutr_PO4)+dc(iv_nutr_Pads)+dc(iv_detr_P)+ &
              (dc(iv_phyto_diat_N)+dc(iv_phyto_dino_N)+dc(iv_phyto_nano_N)+dc(iv_zoo_meso_N)+dc(iv_zoo_micr_N))*rappaz 
#if defined key_benthos
        somdcP=somdcP+(dc(iv_benth_P)+p_burial*c(iv_benth_P))/epn   
#endif
#if defined key_psnz
        somdcP=somdcP+dc(iv_phyto_psnz_N)*rappaz   
#endif
#if defined key_karenia
        somdcP=somdcP+dc(iv_phyto_karenia_C)/(p_phyto_NPratio*p_phyto_CNratio)
!        somdcP=somdcP+dc(iv_phyto_karenia_N)*rappaz
#endif
#if defined key_phaeocystis
        somdcP=somdcP+(dc(iv_phyto_phaeocystis_colo_N)+dc(iv_phyto_phaeocystis_cell_N))*rappaz 
#endif
#if defined key_ulvas
        somdcP=somdcP+dc(iv_ulv_sus_P)+ dc(iv_ulv_benth_P)/epn/0.031  
#endif
        IF(abs(somdcP) > 1.0e-4) THEN
          write(*,*)'____________________________________________________'
          write(*,*)'!!!! PB conservativite P: somdcP =',somdcP
          write(*,*)'!!!! maille i, j, k:',im,jm,km
          write(*,*)'dc: PO4,Pads,diat,dino,nano,detr=   ',dc(iv_nutr_PO4),dc(iv_nutr_Pads), &
                        dc(iv_phyto_diat_N)*rappaz,dc(iv_phyto_dino_N)*rappaz,dc(iv_phyto_nano_N)*rappaz,dc(iv_detr_P)
          write(*,*)'dc: mesozoo,microzoo=  ',dc(iv_zoo_meso_N)*rappaz,dc(iv_zoo_micr_N)*rappaz
#if defined key_benthos
          write(*,*)'dc: benthos=   ',dc(iv_benth_P)/epn   
#endif
#if defined key_psnz
          write(*,*)'dc: psnz=   ',dc(iv_phyto_psnz_N)*rappaz   
#endif
#if defined key_karenia
          write(*,*)'dc: karenia=   ',dc(iv_phyto_karenia_C)/(p_phyto_NPratio*p_phyto_CNratio)
!          write(*,*)'dc: karenia=   ',dc(iv_phyto_karenia_N)*rappaz
#endif
#if defined key_phaeocystis
          write(*,*)'dc: phaeocystis_colo, phaeocystis_cell=   ',  &
                       dc(iv_phyto_phaeocystis_colo_N)*rappaz,dc(iv_phyto_phaeocystis_cell_N)*rappaz 
#endif
#if defined key_ulvas
          write(*,*)'dc: suspended ulvas, benthic ulvas=   ',dc(iv_ulv_sus_P),dc(iv_ulv_benth_P)/epn/0.031   
#endif
          write(*,*) 'assimilmesozoo=',assimilmesozoo,'broumesozoodiat=',broumesozoodiat,'rationmesozoo=',rationmesozoo  
          write(*,*) 'broumesozoodino=',broumesozoodino,'broumesozoomicrozoo=',broumesozoomicrozoo 
!          stop
        ENDIF
     
   END SUBROUTINE verif_bilan_NP

   !!======================================================================
#ifdef key_karenia

  SUBROUTINE incellwat_karenia(km,im,jm,xe,c,dc)

   !&E---------------------------------------------------------------------
   !&E                 ***  ROUTINE incellwat_karenia  ***
   !&E
   !&E ** Purpose : Calcul des variations dues a la presence de Karenia
   !&E              a l interieur d une maille d eau
   !&E
   !&E ** Description :
   !&E
   !&E ** Called by :  incellwat_nut4phy3zoo2
   !&E
   !&E ** External calls :
   !&E
   !&E ** Reference :
   !&E
   !&E ** History :
   !&E       !  2010-03    (A. Vanhoutte, A. Menesguen ) Original code
   !&E       !  ???????    (  )  evolutions
   !&E
   !&E---------------------------------------------------------------------
   !! * Modules used
   USE comsubstance, ONLY : attenuation,extinction,alumplafond
   USE comturb,   ONLY : eps
   USE comvarp3d, ONLY : ect
   USE comvars3d, ONLY : kz
   USE comvarp2d,    ONLY : temp,sal
   USE toolgeom,     ONLY : f_dzu

   !! * Arguments
   INTEGER, INTENT(in)                       :: km,im,jm      ! ocean spatial-step index
   REAL(KIND=rsh),INTENT(in)                 :: xe            ! ssh
   REAL(KIND=rsh),DIMENSION(:),INTENT(in)    :: c
   REAL(KIND=rsh),DIMENSION(:),INTENT(inout) :: dc

   !! * Local declarations
   
   REAL(KIND=rsh) :: deltadensite,salisup
   REAL(KIND=rlg) :: row,rost
   REAL(KIND=rsh) :: fluxrelatifsurf,fluxrelatiffond

   !REAL(KIND=rsh) :: f
   !INTEGER        :: npas
         
   ! variables karenia
   ! -----------------
   REAL(KIND=rsh) :: effetchaleurkarenia,effetno3karenia,effetnh4karenia,quotaN,quotaP
   REAL(KIND=rsh) :: effetazotekarenia,effetphosphorekarenia,pslimkarenia,alpha

#if defined key_N_tracer || defined key_P_tracer
   INTEGER                                   :: is
#endif   

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

   deltadensite=0.0_rsh
   IF (km.lt.kmax) THEN
     ! Calcul de la difference de densite avec la couche superieure
     ! density of pure water at temperature temper
     row = 999.842594_rlg + (  6.793952d-02 + ( - 9.095290d-03 +                &
       (1.001685d-04 - 1.120083d-06*temper + 6.536332d-09*temper*temper)*temper )*temper  )*temper
     ! density of sea water at salinity sali and temperature temper
     rost = row + sali * (   0.824493_rlg + (  -4.0899d-03 + ( 7.6438d-05 +                   &
                (-8.2467d-07+5.3875d-09*temper)*temper )*temper)*temper) +             &
                sali**1.5_rlg * ( -5.72466d-03 + (1.0227d-04-1.6546d-06*temper)*temper) +  &
                sali*sali*4.8314d-04
     deltadensite=rost
     salisup=max(0.0_rsh,sal(km+1,im,jm))
     row = 999.842594_rlg + (  6.793952d-02 + ( - 9.095290d-03 + (1.001685d-04 - 1.120083d-06*temp(km+1,im,jm)  &
          + 6.536332d-09*temp(km+1,im,jm)*temp(km+1,im,jm))*temp(km+1,im,jm) )*temp(km+1,im,jm)  )*temp(km+1,im,jm)
     rost = row + salisup * (   0.824493_rlg + (  -4.0899d-03 + ( 7.6438d-05 +                   &
                (-8.2467d-07+5.3875d-09*temp(km+1,im,jm))*temp(km+1,im,jm) )*temp(km+1,im,jm))*temp(km+1,im,jm)) + &
                salisup**1.5_rlg * ( -5.72466d-03 + (1.0227d-04-1.6546d-06*temp(km+1,im,jm))*temp(km+1,im,jm)) +  &
                salisup*salisup*4.8314d-04 
     deltadensite=abs(deltadensite-rost)/((epn+REAL(f_dzu(h0(im,jm),xe,km+1,im,jm),rsh))/2.0_rsh)
   ENDIF
           
   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
   ! saisir le code apres cette limite
   ! =================================
   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

   ! effetchaleur : courbe de Gauss(moyenne: p_karenia_tempopt, ecart-type: p_karenia_tempsigma)
   !effetchaleurkarenia=exp(-((temper-p_karenia_tempopt)/p_karenia_tempsigma)**2/2.0_rsh)
   ! Modif Alain octobre 2015
   ! effetchaleur : courbe de Blanchard et al. (1996)
      effetchaleurkarenia=0.0_rsh   
      if (temper.lt.p_karenia_templethal)  effetchaleurkarenia=((p_karenia_templethal-temper)/(p_karenia_templethal-p_karenia_tempopt))**p_karenia_beta*exp(-p_karenia_beta*((p_karenia_templethal-temper)/ &
                   (p_karenia_templethal-p_karenia_tempopt)-1))      
              
   ! Formulation de Smith integree sur la profondeur de la boite
   ! ............................................................
   
   fluxrelatifsurf=p_parradratio*alumplafond(km,im,jm)/p_karenia_iksmith
   fluxrelatiffond=fluxrelatifsurf*attenuation(km,im,jm)
   effetlumierekarenia=1.0_rsh/epn/extinction(km,im,jm)*log((fluxrelatifsurf+         &
         sqrt(1.0_rsh+fluxrelatifsurf*fluxrelatifsurf))/(fluxrelatiffond+           &
         sqrt(1.0_rsh+fluxrelatiffond*fluxrelatiffond)))
   IF ((effetlumierekarenia.lt.0.0_rsh).or.(effetlumierekarenia.gt.1.0_rsh)) &
      print*,'effetlumierekar=',effetlumierekarenia,'km=',km,'alumplafond=',alumplafond(km,im,jm), &
                  'attenuation=',attenuation(km,im,jm)
   
   ! effet des nutriments

   effetno3karenia=c(iv_nutr_NO3)/(c(iv_nutr_NO3)+p_karenia_kNO3+(c(iv_nutr_NH4)*p_karenia_kNO3/p_karenia_kNH4))
   effetnh4karenia=c(iv_nutr_NH4)/(c(iv_nutr_NH4)+p_karenia_kNH4+(c(iv_nutr_NO3)*p_karenia_kNH4/p_karenia_kNO3))
   ! modele sans quota azote
! rajouter un booleen pour le choix du modele avec ou sans quota azote
   effetazotekarenia=effetno3karenia+effetnh4karenia
   IF (((c(iv_nutr_NO3).gt.1.e-8_rsh).or.(c(iv_nutr_NH4).gt.1.e-8_rsh)).and.(effetazotekarenia.gt.0.0_rsh)) THEN
           fractionno3karenia=effetno3karenia/effetazotekarenia
           fractionnh4karenia=effetnh4karenia/effetazotekarenia
   ELSE
           fractionno3karenia=0.0_rsh
           fractionnh4karenia=0.0_rsh
   ENDIF    
   ! modele avec quota azote
   uptakeN=0.0_rsh
   effetazotekarenia=0.0_rsh
   IF (c(iv_phyto_karenia_C) .gt. 1.e-10) THEN
       quotaN=c(iv_phyto_karenia_N)/c(iv_phyto_karenia_C)
       IF (quotaN.ge.p_karenia_qminN) THEN
         effetazotekarenia=(quotaN-p_karenia_qminN)/(p_karenia_kqN+quotaN-p_karenia_qminN)
         IF (effetazotekarenia.gt.1.0_rsh) print*,'effetazotekarenia=',effetazotekarenia,'qN=',quotaN, &
            'Nkarenia=',c(iv_phyto_karenia_N),'Ckarenia=',c(iv_phyto_karenia_C)
       ENDIF
       IF (quotaN.lt.(10.0_rsh*p_karenia_qminN)) uptakeN=min((p_karenia_vmaxN*(effetno3karenia+effetnh4karenia)) &
           ,((0.9_rsh*(c(iv_nutr_NH4)*fractionnh4karenia+c(iv_nutr_NO3)*fractionno3karenia)/dtbiojour+    &
           (dc(iv_nutr_NH4)*fractionnh4karenia+dc(iv_nutr_NO3)*fractionno3karenia))/c(iv_phyto_karenia_C)))
   ENDIF
      
   ! modele sans quota phosphore
   effetphosphorekarenia=c(iv_nutr_PO4)/(c(iv_nutr_PO4)+p_karenia_kPO4)     

   ! modele avec quota phosphore
     ! mis en commentaire pour eviter les goto
     ! il faudra se donner un booleen pour le choix du modele
    ! uptakeP=0.0_rsh
    ! effetphosphorekarenia=0.0_rsh
    ! IF (c(iv_phyto_karenia_C) .gt. 1.e-10) THEN
    !   quotaP=c(iv_phyto_karenia_P)/c(iv_phyto_karenia_C)
    !   IF (quotaP.lt.p_karenia_qminP) THEN
    !   ELSE
    !     effetphosphorekarenia=(quotaP-p_karenia_qminP)/(p_karenia_kqP+quotaP-p_karenia_qminP)
    !     IF (effetphosphorekarenia.gt.1.0_rsh) print*,'effetphosphorekarenia=',effetphosphorekarenia,'qP=',quotaP, &
    !        'Pkarenia=',c(iv_phyto_karenia_P),'Ckarenia=',c(iv_phyto_karenia_C)
    !   ENDIF
    !   IF (quotaP.lt.(10.0_rsh*p_karenia_qminP)) uptakeP=p_karenia_vmaxP*c(iv_nutr_PO4)/(c(iv_nutr_PO4)+p_karenia_kPO4)
    ! ENDIF
     
    effetselnutkarenia=min(effetazotekarenia,effetphosphorekarenia)
   
   pslimkarenia=min(effetlumierekarenia,effetselnutkarenia)
   rationkarenia=p_karenia_mumax*(0.15_rsh+0.85_rsh*effetchaleurkarenia)*pslimkarenia

   ! taux max de croissance diminue dans les zones a forte ECT(croissance nulle pour ect.ge.0.0005 m2.s-2)
   rationkarenia=rationkarenia*max(0.0_rsh,(1.0_rsh-ect(km,im,jm)/0.0005_rsh))

   
   ! mortalite simple du 1er ordre diminuee dans les clines raides (divisee par 5 si gradient de densite.ge.0.2 m-1)
   !kareniamorteau=p_karenia_mort*effetchaleur*max(0.2_rsh,(1.0_rsh-4.0_rsh*deltadensite))
    kareniamorteau=p_karenia_mort*effetchaleur
    !kareniamorteau=0.15_rsh*(1-effetselnutkarenia**0.2) 
   
       
   ! mortalite du 2nd ordre liee aux collisions
     ! mis en commentaire pour eviter les goto
     ! il faudra se donner un booleen pour le choix du modele
   !alpha=0.05_rsh
   !if ((temper.gt.16.0_rsh).and.(temper.lt.20.0_rsh)) alpha=0.05_rsh+0.95_rsh*(temper-16.0_rsh)/4.0_rsh
   !if (temper.ge.20.0_rsh) alpha=1.0_rsh
   !! IF(im == 20.and.jm == 45.and.km == 30) print*, 'mortalite 2nd ordre=',  &
   !! sqrt(eps(km,im,jm)*1.e+6/7.5_rsh)*86400.0_rsh*alpha*p_karenia_autotox_coef*c(iv_phyto_karenia_N)
   ! kareniamorteau=max(kareniamorteau,
   !            sqrt(eps(km,im,jm)*1.e+6/7.5_rsh)*86400.0_rsh*alpha*p_karenia_autotox_coef*c(iv_phyto_karenia_N))  
   
   IF (c(iv_phyto_karenia_N).lt.0.01_rsh) kareniamorteau=0.0_rsh
          
   ! Evolution de l ammonium  (micromoles/L N)
   ! -----------------------------------------
   dc(iv_nutr_NH4)=dc(iv_nutr_NH4)-fractionnh4karenia*uptakeN*c(iv_phyto_karenia_C)
   !   dc(iv_nutr_NH4)=dc(iv_nutr_NH4)-fractionnh4karenia*rationkarenia*c(iv_phyto_karenia_N)

   ! Evolution du nitrate  (micromoles/L N)
   ! --------------------------------------   
   dc(iv_nutr_NO3)=dc(iv_nutr_NO3)-fractionno3karenia*uptakeN*c(iv_phyto_karenia_C)
   !  dc(iv_nutr_NO3)=dc(iv_nutr_NO3)-fractionno3karenia*rationkarenia*c(iv_phyto_karenia_N)
      
   ! Evolution du phosphate dissous  (micromoles/L P)
   ! ------------------------------------------------   
   dc(iv_nutr_PO4)=dc(iv_nutr_PO4)-rationkarenia*c(iv_phyto_karenia_C)/(p_phyto_NPratio*p_phyto_CNratio)
   !   dc(iv_nutr_PO4)=dc(iv_nutr_PO4)-rationkarenia*rappaz*c(iv_phyto_karenia_N)

   ! Evolution du carbone des Karenia (micromoles/L C)
   ! --------------------------------
   IF (c(iv_phyto_karenia_N) .gt. 1.e-10) THEN 
        dc(iv_phyto_karenia_C)=c(iv_phyto_karenia_C)*(rationkarenia-kareniamorteau-txfiltbenthij*ibbenth/epn) &
                            -broumesozookarenia*c(iv_zoo_meso_N)*c(iv_phyto_karenia_C)/c(iv_phyto_karenia_N) 
   ENDIF
          
   ! Evolution de l azote des Karenia (micromoles/L N)
   ! -------------------------------------------------
   dc(iv_phyto_karenia_N)=c(iv_phyto_karenia_C)*uptakeN-(kareniamorteau+txfiltbenthij*ibbenth/epn)*c(iv_phyto_karenia_N) &
                           -broumesozookarenia*c(iv_zoo_meso_N)
   !  dc(iv_phyto_karenia_N)=(rationkarenia-(kareniamorteau+txfiltbenthij*ibbenth/epn))*c(iv_phyto_karenia_N) &
   !                         -broumesozookarenia*c(iv_zoo_meso_N)
    
   ! Evolution du phosphore des Karenia (micromoles/L P)
   ! ---------------------------------------------------
   !   dc(iv_phyto_karenia_P)=c(iv_phyto_karenia_C)*uptakeP-(kareniamorteau+txfiltbenthij*ibbenth/epn)*c(iv_phyto_karenia_P) 
   !  IF (c(iv_phyto_karenia_N).gt.0.0_rsh) dc(iv_phyto_karenia_P)=dc(iv_phyto_karenia_P)-  &
   !                                     broumesozookarenia*c(iv_zoo_meso_N)*c(iv_phyto_karenia_P)/c(iv_phyto_karenia_N)
    
   ! Production carbonee des Karenia dans la couche k, cumulee depuis le 1er janvier
   ! -------------------------------------------------------------------------------
   dc(iv_phyto_karenia_pp)=12.e-3_rsh*rationkarenia*c(iv_phyto_karenia_C)*epn
   !  dc(iv_phyto_karenia_pp)=12.e-3_rsh*p_phyto_CNratio*rationkarenia*c(iv_phyto_karenia_N)*epn

   ! Evolution de l azote detritique  (micromoles/L N)
   ! -------------------------------------------------   
   dc(iv_detr_N)=dc(iv_detr_N)+ kareniamorteau*c(iv_phyto_karenia_N)
#if ! defined key_benthos
   dc(iv_detr_N)=dc(iv_detr_N)+txfiltbenthij*ibbenth/epn*c(iv_phyto_karenia_N)
#endif

   ! Evolution du phosphore detritique  (micromoles/L P)         rappaz*psnzmorteau*c(iv_phyto_psnz_N)
   ! ---------------------------------------------------
   dc(iv_detr_P)=dc(iv_detr_P)+c(iv_phyto_karenia_C)/(p_phyto_NPratio*p_phyto_CNratio)*kareniamorteau  
   IF (c(iv_phyto_karenia_N).gt.0.0_rsh) dc(iv_detr_P)=dc(iv_detr_P) &
      + c(iv_phyto_karenia_C)/(p_phyto_NPratio*p_phyto_CNratio)*broumesozookarenia*(1.0_rsh-assimilmesozoo)*c(iv_zoo_meso_N)  &
           *(1.0_rsh/c(iv_phyto_karenia_N)/(p_phyto_NPratio*p_phyto_CNratio))  &
          -rappaz*broumesozookarenia*(1.0_rsh-assimilmesozoo)*c(iv_zoo_meso_N)

   !  dc(iv_detr_P)=dc(iv_detr_P)+rappaz*kareniamorteau*c(iv_phyto_karenia_N)
#if ! defined key_benthos
   dc(iv_detr_P)=dc(iv_detr_P)+txfiltbenthij*ibbenth/epn*c(iv_phyto_karenia_C)/(p_phyto_NPratio*p_phyto_CNratio)
   ! dc(iv_detr_P)=dc(iv_detr_P)+rappaz*txfiltbenthij*ibbenth/epn*c(iv_phyto_karenia_N)
#endif

   !++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   ! calcul des vitesses de chute de Karenia  
   !++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

   !   Vitesse de chute annulee dans les fortes thermoclines	   
   ! IF (km<kmax) THEN
   !     dcdz=ABS(temper-temp(km+1,im,jm))/dzu
   !     IF (dcdz>0.7_rsh) ws3(km,iv_phyto_karenia_N,im,jm)=0.0_rsh
   ! ENDIF
    
   !   Vitesse sinusoidale   
    ws3(km,iv_phyto_karenia_N,im,jm)=0.0_rsh
   ! nouvelle version ete 2014 : vitesse de chute des Karenia mise a zero
    !IF (kz(km,im,jm) >= 0.006_rsh) ws3(km,iv_phyto_karenia_N,im,jm)=0.0003*SIN(2.0_rsh*3.14159_rsh/24.0_rsh*(iheure-18.0_rsh))
    !IF (km==1) ws3(km,iv_phyto_karenia_N,im,jm)=min(0.0_rsh,ws3(km,iv_phyto_karenia_N,im,jm))
    !IF (km==kmax) ws3(km,iv_phyto_karenia_N,im,jm)=max(0.0_rsh,ws3(km,iv_phyto_karenia_N,im,jm))
! version Alain Octobre 2015
    ws3(km,iv_phyto_karenia_N,im,jm)=0.001*SIN(2.0_rsh*3.14159_rsh/24.0_rsh*(iheure+9.0_rsh))
    IF (km==1) ws3(km,iv_phyto_karenia_N,im,jm)=min(0.0_rsh,ws3(km,iv_phyto_karenia_N,im,jm))
    IF (km==kmax) ws3(km,iv_phyto_karenia_N,im,jm)=max(0.0_rsh,ws3(km,iv_phyto_karenia_N,im,jm))

   ! bornage de la vitesse de chute des variables particulaires en chaque maille
   ! ---------------------------------------------------------------------------
    ws3(km,iv_phyto_karenia_N,im,jm)=sign(MIN(0.95_rlg*epn/dtbio,REAL(ABS(ws3(km,iv_phyto_karenia_N,im,jm)),rlg)),  &
                                          ws3(km,iv_phyto_karenia_N,im,jm))
#ifdef key_parsub_newdt   
    IF (ws3(km,iv_phyto_karenia_N,im,jm)>ws3max_bio(iv_phyto_karenia_N))  &
                                     ws3max_bio(iv_phyto_karenia_N)=ws3(km,iv_phyto_karenia_N,im,jm)
#endif        
   
    ws3(km,iv_phyto_karenia_C,im,jm)=ws3(km,iv_phyto_karenia_N,im,jm)
!   ws3(km,iv_phyto_karenia_P,im,jm)=ws3(km,iv_phyto_karenia_N,im,jm)
#ifdef key_parsub_newdt   
    ws3max_bio(iv_phyto_karenia_C)=ws3max_bio(iv_phyto_karenia_N)
!    ws3max_bio(iv_phyto_karenia_P)=ws3max_bio(iv_phyto_karenia_N)
#endif      
#ifdef key_N_tracer
    DO is=1,nb_source_tracerN
       ws3(km,iv_phyto_karenia_tra_N(is),im,jm)=ws3(km,iv_phyto_karenia_N,im,jm)
#ifdef key_parsub_newdt   
       ws3max_bio(iv_phyto_karenia_tra_N(is))=ws3max_bio(iv_phyto_karenia_N)
#endif	
#ifdef key_age_tracer
       ws3(km,iv_phyto_karenia_age_tra_N(is),im,jm)=ws3(km,iv_phyto_karenia_N,im,jm)
#ifdef key_parsub_newdt   
       ws3max_bio(iv_phyto_karenia_age_tra_N(is))=ws3max_bio(iv_phyto_karenia_N)
#endif	
#endif
    ENDDO
#endif	
#ifdef key_P_tracer
    DO is=1,nb_source_tracerP
       ws3(km,iv_phyto_karenia_tra_P(is),im,jm)=ws3(km,iv_phyto_karenia_N,im,jm)
#ifdef key_parsub_newdt   
       ws3max_bio(iv_phyto_karenia_tra_P(is))=ws3max_bio(iv_phyto_karenia_N)
#endif	
#ifdef key_age_tracer
       ws3(km,iv_phyto_karenia_age_tra_P(is),im,jm)=ws3(km,iv_phyto_karenia_N,im,jm)
#ifdef key_parsub_newdt   
       ws3max_bio(iv_phyto_karenia_age_tra_P(is))=ws3max_bio(iv_phyto_karenia_N)
#endif	
#endif
    ENDDO
#endif	
  ! ++++++++++++++++++++++++++++++++++++++++++++++++
  !   ENREGISTREMENT VARIABLES DIAGNOSTIQUES
  ! ++++++++++++++++++++++++++++++++++++++++++++++++
   
   !if (iheure==0) diag_3d_wat(irk_diag(id_karenia_limlight),km,im,jm)=0.0_rsh
   !f=1000.0_rsh*diag_3d_wat(irk_diag(id_karenia_limlight),km,im,jm)
   !npas=int((f-int(f))*1000.0_rsh)
   !f=aint(f)/1000.0_rsh
   !diag_3d_wat(irk_diag(id_karenia_limlight),km,im,jm)=aint((1000.0_rsh*(npas*f+effetlumierekarenia)/(npas+1)))/1000.0_rsh + &
   !                                                    float(npas+1)/1.e+6_rsh
! somme a chaque pas de temps _ moyenne a minuit pour memoriser la variable diagnostique
   effetlumiere_day_karenia(km,im,jm)=effetlumiere_day_karenia(km,im,jm)+effetlumierekarenia*dtbio
   IF(iheure==0 .and. iminu ==0 .and. isec <= dtbio) THEN
      diag_3d_wat(irk_diag(id_karenia_limlight),km,im,jm)=effetlumiere_day_karenia(km,im,jm)/86400.0_rsh
      effetlumiere_day_karenia(km,im,jm)=0.0_rsh
   ENDIF

   diag_3d_wat(irk_diag(id_karenia_limN),km,im,jm)=effetazotekarenia
   !diag_3d_wat(irk_diag(id_karenia_limN),km,im,jm)=uptakeN
   diag_3d_wat(irk_diag(id_karenia_limP),km,im,jm)=effetphosphorekarenia
   !diag_3d_wat(irk_diag(id_karenia_limP),km,im,jm)=max(0.0_rsh,(1.0_rsh-ect(km,im,jm)/0.0005_rsh))

   !   chlorophylle [mgCChl/m3]  
   diag_3d_wat(irk_diag(id_totalchl),km,im,jm)=diag_3d_wat(irk_diag(id_totalchl),km,im,jm)+c(iv_phyto_karenia_C)*0.5
   !diag_3d_wat(irk_diag(id_totalchl),km,im,jm)=diag_3d_wat(irk_diag(id_totalchl),km,im,jm)+c(iv_phyto_karenia_N)*phyto_ChlNratio


   END SUBROUTINE incellwat_karenia
#endif
!   ===========================
#ifdef key_psnz

! modif Alain Octobre 2015 : rajout de Si et effetselnutpsnz
  SUBROUTINE incellwat_pseudonitzschia(km,im,jm,xe,c,dc,Si)

   !&E---------------------------------------------------------------------
   !&E                 ***  ROUTINE incellwat_pseudonitzschia  ***
   !&E
   !&E ** Purpose : Calcul des variations dues a la presence de Pseudo-Nitzschia
   !&E              a l interieur d une maille d eau
   !&E
   !&E ** Description :
   !&E
   !&E ** Called by :  incellwat_nut4phy3zoo2
   !&E
   !&E ** External calls :
   !&E
   !&E ** Reference :
   !&E
   !&E ** History :
   !&E       !  2010-02    (C. Penard A. Menesguen ) Original code
   !&E       !  ???????    (  )  evolutions
   !&E
   !&E---------------------------------------------------------------------
   !! * Modules used
   USE comsubstance, ONLY : attenuation,extinction,alumplafond,cmes_3dmgl


   !! * Arguments
   INTEGER, INTENT(in)                       :: km,im,jm      ! ocean spatial-step index
   REAL(KIND=rsh),INTENT(in)                 :: xe            ! ssh
   REAL(KIND=rsh),DIMENSION(:),INTENT(in)    :: c
   REAL(KIND=rsh),DIMENSION(:),INTENT(inout) :: dc
   REAL(KIND=rsh),INTENT(in)  :: Si

   !! * Local declarations
   
   REAL(KIND=rsh) :: effetchutepsnz
   REAL(KIND=rsh) :: fluxrelatifsurf,fluxrelatiffond

   !REAL(KIND=rsh) :: f
   !INTEGER        ::  npas
      
   ! variables pseudo nitzschia
   ! --------------------------
   REAL(KIND=rsh) :: effetchaleurpsnz,effetsalinitepsnz,effetno3psnz,effetnh4psnz
   REAL(KIND=rsh) :: effetazotepsnz,effetsilicepsnz,effetphosphorepsnz,pslimpsnz
   REAL(KIND=rsh) :: quotaSi,uptakeSi,prodacidedomo,effetlumierepsnz_24h

#if defined key_N_tracer || defined key_P_tracer
   INTEGER                                   :: is
#endif   
   !!----------------------------------------------------------------------
   !! * Executable part
  
   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
   ! saisir le code apres cette limite
   ! =================================
   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

   ! effetchaleur : courbe de Gauss(moyenne: p_psnz_tempopt, ecart-type: p_psnz_tempsigma)
    !  effetchaleurpsnz=exp(-((temper-p_psnz_tempopt)/p_psnz_tempsigma)**2/2.0_rsh)
! Modif Alain Octobre 2015
   ! effetchaleur : courbe de Blanchard et al. (1996)
      effetchaleurpsnz=0.0_rsh   
      if (temper.lt.p_psnz_templethal)  effetchaleurpsnz=((p_psnz_templethal-temper)/(p_psnz_templethal-p_psnz_tempopt))**p_psnz_beta*exp(-p_psnz_beta*((p_psnz_templethal-temper)/ &
                   (p_psnz_templethal-p_psnz_tempopt)-1))           
    ! Effet de la salinite: courbe de Gauss(moyenne: p_psnz_saliopt, ecart-type: p_psnz_salisigma)
      effetsalinitepsnz=exp(-((sali-30.0_rsh)/10.0_rsh)**2/2.0_rsh)
   
   ! Formulation de Smith integree sur la profondeur de la boite
   ! ............................................................
   fluxrelatifsurf=p_parradratio*alumplafond(km,im,jm)/p_psnz_iksmith
   fluxrelatiffond=fluxrelatifsurf*attenuation(km,im,jm)
   effetlumierepsnz=1.0_rsh/epn/extinction(km,im,jm)*log((fluxrelatifsurf+         &
         sqrt(1.0_rsh+fluxrelatifsurf*fluxrelatifsurf))/(fluxrelatiffond+          &
         sqrt(1.0_rsh+fluxrelatiffond*fluxrelatiffond)))

   ! effet des nutriments

   effetno3psnz=c(iv_nutr_NO3)/(c(iv_nutr_NO3)+p_psnz_kNO3+(c(iv_nutr_NH4)*p_psnz_kNO3/p_psnz_kNH4))
   effetnh4psnz=c(iv_nutr_NH4)/(c(iv_nutr_NH4)+p_psnz_kNH4+(c(iv_nutr_NO3)*p_psnz_kNH4/p_psnz_kNO3))
   effetazotepsnz=effetno3psnz+effetnh4psnz
   IF (((c(iv_nutr_NO3).gt.1.e-8_rsh).or.(c(iv_nutr_NH4).gt.1.e-8_rsh)).and.(effetazotepsnz.gt.0.0_rsh)) THEN
           fractionno3psnz=effetno3psnz/effetazotepsnz
           fractionnh4psnz=effetnh4psnz/effetazotepsnz
   ELSE
           fractionno3psnz=0.0_rsh
           fractionnh4psnz=0.0_rsh
   ENDIF

   uptakeSi=0.0_rsh
   effetsilicepsnz=0.0_rsh
   ! Modif Alain Octobre 2015 : SI non calcule ici
   !Si=max(0.0_rsh,c(iv_nutr_SiOH))
   IF (c(iv_phyto_psnz_N) .gt. 1.e-10) THEN
      quotaSi=c(iv_phyto_psnz_Si)/c(iv_phyto_psnz_N)
      IF (quotaSi.lt.p_psnz_qminSi) THEN
      ELSE
       !effetsilicepsnz=(quotaSi-p_psnz_qminSi)/(p_psnz_kqSi+quotaSi-p_psnz_qminSi)
       ! Modif Alain Octobre 2015
       effetsilicepsnz=(quotaSi-p_psnz_qminSi)/(p_psnz_kqSi+quotaSi-p_psnz_qminSi)/(4.0_rsh/(4.0_rsh+p_psnz_kqSi))
       IF (effetsilicepsnz.gt.1.0_rsh) print*,'effetsilicepsnz=',effetsilicepsnz,'qSi=',quotaSi,'Npsnz=',c(iv_phyto_psnz_N)
      ENDIF       
       ! Modif Alain Octobre 2015 test suivant mis en commentaire
      !IF (quotaSi.lt.(5.0_rsh*p_psnz_qminSi)) uptakeSi=min((p_psnz_vmaxSi*Si/(p_psnz_kSi+Si)),  &
      !                ((0.9_rsh*Si/dtbiojour+dc(iv_nutr_SiOH))/c(iv_phyto_psnz_N)))  
   ENDIF
   effetphosphorepsnz=c(iv_nutr_PO4)/(c(iv_nutr_PO4)+p_psnz_kPO4)

   effetselnutpsnz=min(effetazotepsnz,min(effetsilicepsnz,effetphosphorepsnz))
   
   pslimpsnz=min(effetlumierepsnz,effetselnutpsnz)
   rationpsnz=p_psnz_mumax*(0.15_rsh+0.85_rsh*effetchaleurpsnz)*effetsalinitepsnz*pslimpsnz

   ! Modif Alain Octobre 2015 
   psnzmorteau=0.3_rsh*(1-effetselnutpsnz**0.2)
   !psnzmorteau=p_psnz_mort*effetchaleur
   !psnzmorteau=p_psnz_mortmax*(1-effetselnutpsnz**0.2)
   IF (c(iv_phyto_psnz_N).lt.0.01_rsh) psnzmorteau=0.0_rsh

 
   ! Source et puits d acide domoique
   ! --------------------------------

   prodacidedomo=-0.01_rsh*c(iv_phyto_psnz_ad)
   IF (c(iv_phyto_psnz_N) .gt. 1.e-10) THEN


   ! Modif Alain Octobre 2015
       !IF ((c(iv_phyto_psnz_Si)/c(iv_phyto_psnz_N)).lt.p_psnz_seuilSi)  THEN
       ! prodacidedomo=prodacidedomo+max(p_psnz_prod_domoic*c(iv_phyto_psnz_N),0.0_rsh)
       !ENDIF
   !   Formulation utilisant le quota de Si selon Davidson et Fehling
   !    if ((c(iv_phyto_psnz_Si)/c(iv_phyto_psnz_N)).lt.p_psnz_seuilSi)  &
   !   Formulation utilisant l'effet limitant de la silice
        if(effetsilicepsnz.lt.p_psnz_seuilSi) &
        prodacidedomo=prodacidedomo+p_psnz_prod_domoic*max(c(iv_phyto_psnz_N),0.0_rsh)
   ENDIF
    
   ! Evolution de l ammonium  (micromoles/L N)
   ! -----------------------------------------
      dc(iv_nutr_NH4)=dc(iv_nutr_NH4)-fractionnh4psnz*rationpsnz*c(iv_phyto_psnz_N)
      
   ! Evolution du nitrate  (micromoles/L N)
   ! --------------------------------------   
      dc(iv_nutr_NO3)=dc(iv_nutr_NO3)-fractionno3psnz*rationpsnz*c(iv_phyto_psnz_N)
      
   ! Evolution du phosphate dissous  (micromoles/L P)
   ! ------------------------------------------------   
      dc(iv_nutr_PO4)=dc(iv_nutr_PO4)-rationpsnz*c(iv_phyto_psnz_N)*rappaz
 
   ! Evolution du silicate  (micromoles/L Si)
   ! --------------------------------------   
      dc(iv_nutr_SiOH)=dc(iv_nutr_SiOH)-uptakeSi*c(iv_phyto_psnz_N)  
      
   ! Evolution de l azote des Pseudo-Nitzschia
   ! -----------------------------------------
   
      dc(iv_phyto_psnz_N)=c(iv_phyto_psnz_N)*(rationpsnz-psnzmorteau-txfiltbenthij*ibbenth/epn)  &
                          -broumesozoopsnz*c(iv_zoo_meso_N) -broumicrozoopsnz*c(iv_zoo_micr_N)

   ! Evolution du silicium des Pseudo-Nitzschia (micromoles/L N)
   ! -----------------------------------------------------------
      IF (c(iv_phyto_psnz_N) .gt. 1.e-10) THEN 
      dc(iv_phyto_psnz_Si)=c(iv_phyto_psnz_N)*uptakeSi-(psnzmorteau+txfiltbenthij*ibbenth/epn)*c(iv_phyto_psnz_Si) &
                            -(broumesozoopsnz*c(iv_zoo_meso_N)+broumicrozoopsnz*c(iv_zoo_micr_N))*quotaSi
      ENDIF

   ! Evolution de l acide domoique dans l ensemble eau+cellules (microgrammes/L)
   ! ----------------------------------------------------------
      dc(iv_phyto_psnz_ad)=prodacidedomo
  
   ! Production carbonee des Pseudo-Nitzschia dans la couche k, cumulee depuis le 1er janvier
   ! ----------------------------------------------------------------------------------------
      dc(iv_phyto_psnz_pp)=12.e-3_rsh*p_phyto_CNratio*rationpsnz*c(iv_phyto_psnz_N)*epn
            
   ! Evolution de l azote detritique  (micromoles/L N)
   ! -------------------------------------------------   
      dc(iv_detr_N)=dc(iv_detr_N)+ psnzmorteau*C(iv_phyto_psnz_N)
#if ! defined key_benthos
   dc(iv_detr_N)=dc(iv_detr_N)+txfiltbenthij*ibbenth/epn*c(iv_phyto_psnz_N)
#endif
      
   ! Evolution de la silice particulaire  (micromoles/L Si)
   ! ------------------------------------------------------
      dc(iv_detr_Si)=dc(iv_detr_Si)+ psnzmorteau*c(iv_phyto_psnz_Si)
      IF (c(iv_phyto_psnz_N) .gt. 1.e-10) THEN 
      dc(iv_detr_Si)=dc(iv_detr_Si)+ (broumesozoopsnz*c(iv_zoo_meso_N)+broumicrozoopsnz*c(iv_zoo_micr_N))*quotaSi
      ENDIF  
#if ! defined key_benthos
   dc(iv_detr_Si)=dc(iv_detr_Si)+txfiltbenthij*ibbenth/epn*c(iv_phyto_psnz_Si)
#endif    
   ! Evolution du phosphore detritique  (micromoles/L P)
   ! ---------------------------------------------------
      dc(iv_detr_P)=dc(iv_detr_P)+rappaz*psnzmorteau*c(iv_phyto_psnz_N)
#if ! defined key_benthos
   dc(iv_detr_P)=dc(iv_detr_P)+txfiltbenthij*ibbenth/epn*c(iv_phyto_psnz_N)*rappaz
#endif

   !++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   ! calcul des vitesses de chute de Pseusonitischia si choix 
   !++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   IF(l_SNeffect_settle) THEN
           effetchutepsnz=effetselnutpsnz**0.2_rsh
           ws3(km,iv_phyto_psnz_N,im,jm)=(ws_free_min(iv_phyto_psnz_N)*effetchutepsnz+      &
                                  ws_free_max(iv_phyto_psnz_N)*(1.-effetchutepsnz))
           ws3(km,iv_phyto_psnz_Si,im,jm)=ws3(km,iv_phyto_psnz_N,im,jm)
           ws3(km,iv_phyto_psnz_ad,im,jm)=ws3(km,iv_phyto_psnz_N,im,jm)
#ifdef key_parsub_newdt   
           IF (ws3(km,iv_phyto_psnz_N,im,jm)>ws3max_bio(iv_phyto_psnz_N)) &
                                       ws3max_bio(iv_phyto_psnz_N)= ws3(km,iv_phyto_psnz_N,im,jm)
           ws3max_bio(iv_phyto_psnz_Si)=ws3max_bio(iv_phyto_psnz_N)
#endif        

#ifdef key_N_tracer
    DO is=1,nb_source_tracerN
           ws3(km,iv_phyto_psnz_tra_N(is),im,jm)=ws3(km,iv_phyto_psnz_N,im,jm)
#ifdef key_parsub_newdt   
           ws3max_bio(iv_phyto_psnz_tra_N(is))=ws3max_bio(iv_phyto_psnz_N)
#endif        
#ifdef key_age_tracer
           ws3(km,iv_phyto_psnz_age_tra_N(is),im,jm)=ws3(km,iv_phyto_psnz_N,im,jm)
#ifdef key_parsub_newdt   
           ws3max_bio(iv_phyto_psnz_age_tra_N(is))=ws3max_bio(iv_phyto_psnz_N)
#endif        
#endif
    ENDDO
#endif	
#ifdef key_P_tracer
    DO is=1,nb_source_tracerP
           ws3(km,iv_phyto_psnz_tra_P(is),im,jm)=ws3(km,iv_phyto_psnz_N,im,jm)
#ifdef key_parsub_newdt   
           ws3max_bio(iv_phyto_psnz_tra_P(is))=ws3max_bio(iv_phyto_psnz_N)
#endif        
#ifdef key_age_tracer
           ws3(km,iv_phyto_psnz_age_tra_P(is),im,jm)=ws3(km,iv_phyto_psnz_N,im,jm)
#ifdef key_parsub_newdt   
           ws3max_bio(iv_phyto_psnz_age_tra_P(is))=ws3max_bio(iv_phyto_psnz_N)
#endif        
#endif
    ENDDO
#endif	

   ENDIF

  ! ++++++++++++++++++++++++++++++++++++++++++++++++
  !   ENREGISTREMENT VARIABLES DIAGNOSTIQUES
  ! ++++++++++++++++++++++++++++++++++++++++++++++++
  
   !if (iheure.eq.0) diag_3d_wat(irk_diag(id_psnz_limlight),km,im,jm)=0.0_rsh   
   !f=1000.0_rsh*diag_3d_wat(irk_diag(id_psnz_limlight),km,im,jm)
   !npas=int((f-int(f))*1000.0_rsh)
   !f=aint(f)/1000.0_rsh
   !diag_3d_wat(irk_diag(id_psnz_limlight),km,im,jm)=aint((1000.0_rsh*(npas*f+effetlumierepsnz)/(npas+1)))/1000.0_rsh + &
   !                                                    float(npas+1)/1.e+6_rsh
! somme a chaque pas de temps _ moyenne a minuit pour memoriser la variable diagnostique
   effetlumiere_day_psnz(km,im,jm)=effetlumiere_day_psnz(km,im,jm)+effetlumierepsnz*dtbio
   IF(iheure==0 .and. iminu ==0 .and. isec <= dtbio) THEN
      diag_3d_wat(irk_diag(id_psnz_limlight),km,im,jm)=effetlumiere_day_psnz(km,im,jm)/86400.0_rsh
      effetlumiere_day_psnz(km,im,jm)=0.0_rsh
   ENDIF

   diag_3d_wat(irk_diag(id_psnz_limN),km,im,jm)=effetazotepsnz
   diag_3d_wat(irk_diag(id_psnz_limSi),km,im,jm)=effetsilicepsnz
   diag_3d_wat(irk_diag(id_psnz_limP),km,im,jm)=effetphosphorepsnz

  !   chlorophylle [mgCChl/m3]   
   diag_3d_wat(irk_diag(id_totalchl),km,im,jm)=diag_3d_wat(irk_diag(id_totalchl),km,im,jm)+ &
                                                 c(iv_phyto_psnz_N)*fact_phyto_ChlNratio

   END SUBROUTINE incellwat_pseudonitzschia
#endif
   !!======================================================================
#ifdef key_phaeocystis

  SUBROUTINE incellwat_phaeocystis(km,im,jm,xe,c,dc)

   !&E---------------------------------------------------------------------
   !&E                 ***  ROUTINE incellwat_phaeocystis  ***
   !&E
   !&E ** Purpose : Calcul des variations dues a la presence de phaeocystis
   !&E              a l interieur d une maille d eau
   !&E
   !&E ** Description :
   !&E
   !&E ** Called by :  incellwat_nut4phy3zoo2
   !&E
   !&E ** External calls :
   !&E
   !&E ** Reference :
   !&E
   !&E ** History :
   !&E       !  2010-03    (A. Vanhoutte, A. Menesguen ) Original code
   !&E       !  ???????    (  )  evolutions
   !&E
   !&E---------------------------------------------------------------------
   !! * Modules used
   USE comsubstance, ONLY : attenuation,extinction,alumplafond


   !! * Arguments
   INTEGER, INTENT(in)                       :: km,im,jm     ! ocean spatial-step index
   REAL(KIND=rsh),INTENT(in)                 :: xe            ! ssh
   REAL(KIND=rsh),DIMENSION(:),INTENT(in)    :: c
   REAL(KIND=rsh),DIMENSION(:),INTENT(inout) :: dc

   !! * Local declarations
   
   REAL(KIND=rsh) :: f
   INTEGER        :: npas
   REAL(KIND=rsh) :: fluxrelatifsurf,fluxrelatiffond
 
   ! variables phaeocystis
   ! ---------------------
   REAL(KIND=rsh) :: effetchaleurphaeocystis,phaeocystis_iksmith
   REAL(KIND=rsh) :: effetno3phaeocystiscolo,effetnh4phaeocystiscolo,effetazotephaeocystiscolo,effetphosphorephaeocystiscolo, &
                     pslimphaeocystiscolo,effetno3phaeocystiscell,effetnh4phaeocystiscell,effetazotephaeocystiscell, & 
                     effetphosphorephaeocystiscell,pslimphaeocystiscell
   REAL(KIND=rsh) :: mucusprod,Ctomucusratio
     
   !!---------------------------------------------------------------------------------------------------------------------------------------------------
   !! * Executable part
      
   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
   ! saisir le code apres cette limite
   ! =================================
   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

   ! effetchaleur : courbe de Gauss(moyenne: p_phaeocystis_tempopt, ecart-type: p_phaeocystis_tempsigma)
   !   effetchaleurphaeocystis=exp(-((temper-p_phaeocystis_tempopt)/p_phaeocystis_tempsigma)**2/2.0_rsh)
   ! Modif Alain Octobre 2015
   ! effetchaleur : courbe de Blanchard et al. (1996)
      effetchaleurphaeocystis=0.0_rsh   
      if (temper.lt.p_phaeocystis_templethal)  effetchaleurphaeocystis=((p_phaeocystis_templethal-temper)/(p_phaeocystis_templethal-p_phaeocystis_tempopt))**p_phaeocystis_beta*exp(-p_phaeocystis_beta*((p_phaeocystis_templethal-temper)/ &
                   (p_phaeocystis_templethal-p_phaeocystis_tempopt)-1))      
   
#ifdef key_physadaptation
! !!!!!!ATTENTION  Ik varie selon la turbidite (Amelioration des resultats sur les cotes belges)
   phaeocystis_iksmith=p_phaeocystis_iksmith*(1.0_rsh-effetturbidite)
#else
   phaeocystis_iksmith=p_phaeocystis_iksmith
#endif
         
   ! Formulation de Smith integree sur la profondeur de la boite
   ! ............................................................
!  test par precaution au cas ou (1-effeturbidte=0.
!  mis en commentaire si phaeocystis_iksmith ne varie pas avec l effet turbidite
! le remettre si cela rechange
   IF ( phaeocystis_iksmith == 0.0_rsh) THEN
      fluxrelatifsurf=0.0_rsh
   ELSE
     fluxrelatifsurf=p_parradratio*alumplafond(km,im,jm)/phaeocystis_iksmith
   ENDIF
   fluxrelatiffond=fluxrelatifsurf*attenuation(km,im,jm)
   effetlumierephaeocystis=1.0_rsh/epn/extinction(km,im,jm)*log((fluxrelatifsurf+         &
         sqrt(1.0_rsh+fluxrelatifsurf*fluxrelatifsurf))/(fluxrelatiffond+           &
         sqrt(1.0_rsh+fluxrelatiffond*fluxrelatiffond)))

   ! effet des nutriments sur les colonies

   effetno3phaeocystiscolo=c(iv_nutr_NO3)/(c(iv_nutr_NO3)+p_phaeocystis_kNO3colo+ &
                           (c(iv_nutr_NH4)*p_phaeocystis_kNO3colo/p_phaeocystis_kNH4))
   effetnh4phaeocystiscolo=c(iv_nutr_NH4)/(c(iv_nutr_NH4)+  &
                           p_phaeocystis_kNH4+(c(iv_nutr_NO3)*p_phaeocystis_kNH4/p_phaeocystis_kNO3colo))
   effetazotephaeocystiscolo=effetno3phaeocystiscolo+effetnh4phaeocystiscolo
   IF (((c(iv_nutr_NO3).gt.1.e-8_rsh).or.(c(iv_nutr_NH4).gt.1.e-8_rsh)).and. &
                                           (effetazotephaeocystiscolo.gt.0.0_rsh)) THEN
           fractionno3phaeocystiscolo=effetno3phaeocystiscolo/effetazotephaeocystiscolo
           fractionnh4phaeocystiscolo=effetnh4phaeocystiscolo/effetazotephaeocystiscolo
   ELSE
           fractionno3phaeocystiscolo=0.0_rsh
           fractionnh4phaeocystiscolo=0.0_rsh
   ENDIF

   effetphosphorephaeocystiscolo=c(iv_nutr_PO4)/(c(iv_nutr_PO4)+p_phaeocystis_kPO4colo)
   effetselnutphaeocystiscolo=min(effetazotephaeocystiscolo,effetphosphorephaeocystiscolo)

   ! effet des nutriments sur les cellules libres

   effetno3phaeocystiscell=c(iv_nutr_NO3)/(c(iv_nutr_NO3)+p_phaeocystis_kNO3cell+  &
                           (c(iv_nutr_NH4)*p_phaeocystis_kNO3cell/p_phaeocystis_kNH4))
   effetnh4phaeocystiscell=c(iv_nutr_NH4)/(c(iv_nutr_NH4)+p_phaeocystis_kNH4+  &
                           (c(iv_nutr_NO3)*p_phaeocystis_kNH4/p_phaeocystis_kNO3cell))
   effetazotephaeocystiscell=effetno3phaeocystiscell+effetnh4phaeocystiscell
   IF (((c(iv_nutr_NO3).gt.1.e-8_rsh).or.(c(iv_nutr_NH4).gt.1.e-8_rsh)).and.(effetazotephaeocystiscell.gt.0.0_rsh)) THEN
           fractionno3phaeocystiscell=effetno3phaeocystiscell/effetazotephaeocystiscell
           fractionnh4phaeocystiscell=effetnh4phaeocystiscell/effetazotephaeocystiscell
   ELSE
           fractionno3phaeocystiscell=0.0_rsh
           fractionnh4phaeocystiscell=0.0_rsh
   ENDIF

   effetphosphorephaeocystiscell=c(iv_nutr_PO4)/(c(iv_nutr_PO4)+p_phaeocystis_kPO4cell)

   effetselnutphaeocystiscell=min(effetazotephaeocystiscell,effetphosphorephaeocystiscell)  

   ! taux de croissance global   
   pslimphaeocystiscolo=min(effetlumierephaeocystis,effetselnutphaeocystiscolo)
   rationphaeocystiscolo=p_phaeocystis_mumaxcolo*(0.15_rsh+0.85_rsh*effetchaleurphaeocystis)*pslimphaeocystiscolo
   pslimphaeocystiscell=min(effetlumierephaeocystis,effetselnutphaeocystiscell)
   rationphaeocystiscell=p_phaeocystis_mumaxcell*(0.15_rsh+0.85_rsh*effetchaleurphaeocystis)*pslimphaeocystiscell
  
   !formation de colonies
   initcolonie=0.0_rsh
   IF(c(iv_phyto_phaeocystis_cell_N).gt.p_phaeocystis_coloseuil) initcolonie=p_phaeocystis_coloinit

   ! mortalite du 1er ordre
   phaeocystismortcolo=p_phaeocystis_mort*effetchaleur
   IF (c(iv_phyto_phaeocystis_colo_N).lt.0.01_rsh) phaeocystismortcolo=0.0_rsh
   phaeocystismortcell=p_phaeocystis_mort*effetchaleur   
   IF (c(iv_phyto_phaeocystis_cell_N).lt.0.01_rsh) phaeocystismortcell=0.0_rsh
   ! rupture des colonies trop mucilagineuses (contenu en biomasse vivante faible)
   Ctomucusratio=c(iv_phyto_phaeocystis_colo_N)*p_phyto_CNratio*12.0_rsh/1000.0_rsh/(c(iv_phyto_phaeocystis_mucus)+epsilon)
   !if ((im.eq.55).and.(jm.eq.59).and.(km.eq.30)) print*,'Ctomucusratio= ',Ctomucusratio
   IF (Ctomucusratio.le.0.1_rsh)  phaeocystismortcolo=phaeocystismortcolo*3.0_rsh
   ! lyse des colonies senescentes
   phaeocystislysecolo=p_phaeocystis_lyse*effetchaleur*(1.0_rsh-effetselnutphaeocystiscolo)

   ! production de mucus en fonction du rapport C/mucus   
   mucusprod=0.0_rsh
   IF(Ctomucusratio.gt.0.1_rsh) THEN
     IF(rationphaeocystiscolo.gt.1.15_rsh) mucusprod=rationphaeocystiscolo*1.2_rsh
   ENDIF
   IF(effetselnutphaeocystiscolo.lt.0.4_rsh) mucusprod=mucusprod*2.0_rsh

   ! Evolution de l ammonium  (micromoles/L N)
   ! -----------------------------------------
      dc(iv_nutr_NH4)=dc(iv_nutr_NH4)-fractionnh4phaeocystiscolo*rationphaeocystiscolo*c(iv_phyto_phaeocystis_colo_N)  &
                                     -fractionnh4phaeocystiscell*rationphaeocystiscell*c(iv_phyto_phaeocystis_cell_N)
 !  IF (dc(iv_nutr_NH4).lt.(-c(iv_nutr_NH4)/dtbiojour)) print*,'NH4phaeo  i=',im,'j=',jm,'k=',km
      
   ! Evolution du nitrate  (micromoles/L N)
   ! --------------------------------------   
      dc(iv_nutr_NO3)=dc(iv_nutr_NO3)-fractionno3phaeocystiscolo*rationphaeocystiscolo*c(iv_phyto_phaeocystis_colo_N)  &
                                     -fractionno3phaeocystiscell*rationphaeocystiscell*c(iv_phyto_phaeocystis_cell_N)
   IF (dc(iv_nutr_NO3).lt.(-c(iv_nutr_NO3)/dtbiojour)) print*,'NO3 initial ',c(iv_nutr_NO3),' epuise en:  i=',im,'j=',jm,'k=',km
      
   ! Evolution du phosphate dissous  (micromoles/L P)
   ! ------------------------------------------------   
      dc(iv_nutr_PO4)=dc(iv_nutr_PO4)-(rationphaeocystiscolo*c(iv_phyto_phaeocystis_colo_N)+  &
                                       rationphaeocystiscell*c(iv_phyto_phaeocystis_cell_N))*rappaz
   
   ! Evolution de l azote des phaeocystis coloniaux
   ! ----------------------------------------------
      dc(iv_phyto_phaeocystis_colo_N)=c(iv_phyto_phaeocystis_colo_N)*  &
                                      (rationphaeocystiscolo-phaeocystismortcolo-phaeocystislysecolo)  &
                                 -broumesozoophaeocolo*c(iv_zoo_meso_N)+c(iv_phyto_phaeocystis_cell_N)*initcolonie

   ! Evolution de l azote des phaeocystis unicellulaires
   ! ---------------------------------------------------
      dc(iv_phyto_phaeocystis_cell_N)=c(iv_phyto_phaeocystis_cell_N)*(rationphaeocystiscell- &
                                      phaeocystismortcell-txfiltbenthij*ibbenth/epn)  &
                                 -broumicrozoophaeocell*c(iv_zoo_micr_N) - c(iv_phyto_phaeocystis_cell_N)*initcolonie
        
   ! Production carbonee des phaeocystis dans la couche k, cumulee depuis le 1er janvier
   ! -----------------------------------------------------------------------------------    
      dc(iv_phyto_phaeocystis_pp)=12.e-3_rsh*p_phyto_CNratio*epn*(rationphaeocystiscolo*c(iv_phyto_phaeocystis_colo_N)  &
                                  +rationphaeocystiscell*c(iv_phyto_phaeocystis_cell_N))

   ! Production de mucus
   ! -------------------     
      dc(iv_phyto_phaeocystis_mucus)=mucusprod*c(iv_phyto_phaeocystis_colo_N) -  &
                                     p_phaeocystis_mucus_decay*c(iv_phyto_phaeocystis_mucus)

      
   ! Evolution de l azote detritique  (micromoles/L N)
   ! -------------------------------------------------   
      dc(iv_detr_N)=dc(iv_detr_N)+ (phaeocystismortcolo+phaeocystislysecolo)*C(iv_phyto_phaeocystis_colo_N)+ &
                                    phaeocystismortcell*C(iv_phyto_phaeocystis_cell_N)
#if ! defined key_benthos
   dc(iv_detr_N)=dc(iv_detr_N)+txfiltbenthij*ibbenth/epn*c(iv_phyto_phaeocystis_cell_N)
#endif
   ! Evolution du phosphore detritique  (micromoles/L P)
   ! ---------------------------------------------------
      dc(iv_detr_P)=dc(iv_detr_P)+rappaz*((phaeocystismortcolo+phaeocystislysecolo)*C(iv_phyto_phaeocystis_colo_N)+ &
                                   phaeocystismortcell*C(iv_phyto_phaeocystis_cell_N))
#if ! defined key_benthos
   dc(iv_detr_P)=dc(iv_detr_P)+txfiltbenthij*ibbenth/epn*c(iv_phyto_phaeocystis_cell_N)*rappaz
#endif

   !++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   ! calcul des vitesses de chute des colonies et du mucus de Phaeocystis en chaque maille
   !++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   ! mis en commentaire car pas de modification par rapport au calcul habituel, deja execute dans biolodynzwat  
   ! ws3(km,iv_phyto_phaeocystis_colo_N,im,jm)=(ws_free_min(iv_phyto_phaeocystis_colo_N)+ &
   !                                            ws_free_max(iv_phyto_phaeocystis_colo_N))/2.0_rsh
   ! ws3(km,iv_phyto_phaeocystis_mucus,im,jm)=(ws_free_min(iv_phyto_phaeocystis_mucus)+ &
   !                                            ws_free_max(iv_phyto_phaeocystis_mucus))/2.0_rsh
!#ifdef key_parsub_newdt   
   ! IF (ws3(km,iv_phyto_phaeocystis_colo_N,im,jm)>ws3max_bio(iv_phyto_phaeocystis_colo_N)) &
   !                               ws3max_bio(iv_phyto_phaeocystis_colo_N)=ws3(km,iv_phyto_phaeocystis_colo_N,im,jm)
   ! IF (ws3(km,iv_phyto_phaeocystis_mucus,im,jm)>ws3max_bio(iv_phyto_phaeocystis_mucus)) &
   !                                 ws3max_bio(iv_phyto_phaeocystis_mucus)=ws3(km,iv_phyto_phaeocystis_mucus,im,jm)
!#endif        

!#endif




  ! ++++++++++++++++++++++++++++++++++++++++++++++++
  !   ENREGISTREMENT VARIABLES DIAGNOSTIQUES
  ! ++++++++++++++++++++++++++++++++++++++++++++++++
   
   !if (iheure.eq.0) diag_3d_wat(irk_diag(id_phaeocystis_limlight),km,im,jm)=0.0_rsh  
   !f=1000.0_rsh*diag_3d_wat(irk_diag(id_phaeocystis_limlight),km,im,jm)
   !npas=int((f-int(f))*1000.0_rsh)
   !f=aint(f)/1000.0_rsh
   !diag_3d_wat(irk_diag(id_phaeocystis_limlight),km,im,jm)=  &
   !                   aint((1000.0_rsh*(npas*f+effetlumierephaeocystis)/(npas+1)))/1000.0_rsh + float(npas+1)/1.e+6_rsh
! somme a chaque pas de temps _ moyenne a minuit pour memoriser la variable diagnostique
   effetlumiere_day_phaeocystis(km,im,jm)=effetlumiere_day_phaeocystis(km,im,jm)+effetlumierephaeocystis*dtbio
   IF(iheure==0 .and. iminu ==0 .and. isec <= dtbio) THEN
      diag_3d_wat(irk_diag(id_phaeocystis_limlight),km,im,jm)=effetlumiere_day_phaeocystis(km,im,jm)/86400.0_rsh
      effetlumiere_day_phaeocystis(km,im,jm)=0.0_rsh
   ENDIF

   diag_3d_wat(irk_diag(id_phaeocystis_limN),km,im,jm)=effetazotephaeocystiscolo
   diag_3d_wat(irk_diag(id_phaeocystis_limP),km,im,jm)=effetphosphorephaeocystiscolo
  !   chlorophylle [mgCChl/m3]
   diag_3d_wat(irk_diag(id_totalchl),km,im,jm)=diag_3d_wat(irk_diag(id_totalchl),km,im,jm)+ &
                                          (c(iv_phyto_phaeocystis_colo_N)+c(iv_phyto_phaeocystis_cell_N))*fact_phyto_ChlNratio  

   END SUBROUTINE incellwat_phaeocystis
#endif
   !!======================================================================     
#ifdef key_oxygen
! Modif Alain Octobre 2015
  SUBROUTINE incellwat_oxygen(km,im,jm,xe,c,dc,       &
                              effetselnutdino,effetselnutnano,  &
                              effetlumierediat,effetlumieredino,effetlumierenano)

   !&E---------------------------------------------------------------------
   !&E                 ***  ROUTINE incellwat_oxygen  ***
   !&E
   !&E ** Purpose : Calcul de la variable oxygene
   !&E              
   !&E
   !&E ** Description :
   !&E
   !&E ** Called by :  incellwat_nut4phy3zoo2
   !&E
   !&E ** External calls :
   !&E
   !&E ** Reference :
   !&E
   !&E ** History :
   !&E       !  2010-02    (A.Chapelle) Original code
   !&E       !  ???????    (  )  evolutions
   !&E
   !&E---------------------------------------------------------------------
   !! * Modules used
   USE comsubstance, ONLY : attenuation,extinction,alumplafond
   USE comvars2d,    ONLY : hm,dx,dy
   USE cometemp,     ONLY   : ventvent  
 
   !! * Arguments
   INTEGER, INTENT( in ) ::   km,im,jm      ! ocean spatial-step index
   REAL(KIND=rsh),             INTENT(in) :: xe     !ssh
   REAL(KIND=rsh),DIMENSION(:),INTENT(in) :: c
   REAL(KIND=rsh),DIMENSION(:),INTENT(inout) :: dc
   ! Modif Alain Octobre 2015
   REAL(KIND=rsh),INTENT(in)  :: effetselnutdino,effetselnutnano,  &
                              effetlumierediat,effetlumieredino,effetlumierenano

   !! * Local declarations

   ! indices de boucles
   ! ------------------
   INTEGER                                   :: toto,ibsurf1
   
   ! variables oxygene
   ! ------------------
   REAL(KIND=rsh) :: ophotos,oresphyto,orespzoo,oremineau,onitrifeau, &
                     gst,o2sat,oair,perteo2,schmidt
  ! Modif Alain Ocotbre 2015
   REAL(KIND=rsh) :: effetnutdiat,effetnutdino,effetnutnano, &
                     effetnutphaeocell,effetnutphaeocolo,effetnutkarenia,effetnutpsnz
     
   !!----------------------------------------------------------------------
   !! * Executable part

     ! test pour identification des mailles profondeurs de melange (non utilise)
   ! ------------------------------------------------------------
 !  ibsurf1=0
 !  IF (depthbottom(km,im,jm).lt.7.0_rsh) ibsurf1=1
 !  depthbottom must be replaced by - (f_zw(h0(im,jm),xe(im,jm),km,im,jm)-xe(im,jm))

   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
   ! saisir le code apres cette limite
   ! =================================
   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

   !++++++++++++++++++++++++++++++++++++
   ! Processus lies a l oxygene dissous 
   !++++++++++++++++++++++++++++++++++++

   ! production et consommation d oxygene dans l eau
   ! -----------------------------------------------
   !ophotos=p_phyto_photoratio*0.212_rsh*(rationdiat*c(iv_phyto_diat_N)+ &
   !                                      rationdino*c(iv_phyto_dino_N)+rationnano*c(iv_phyto_nano_N))
   ! Modif Alain Octobre 2015
   !ophotos=p_phyto_photoratio*0.212_rsh*effetchaleur*(p_diat_mumax*effetlumierediat*c(iv_phyto_diat_N)+  &
   !        p_dino_mumax*effetlumieredino*c(iv_phyto_dino_N)+p_nano_mumax*effetlumierenano*c(iv_phyto_nano_N))
    effetnutdiat=1.0_rsh
    if (effetselnutdiat.le.0.3_rsh) effetnutdiat=effetselnutdiat
    effetnutdino=1.0_rsh
    if (effetselnutdino.le.0.3_rsh) effetnutdino=effetselnutdino
    effetnutnano=1.0_rsh
    if (effetselnutnano.le.0.3_rsh) effetnutnano=effetselnutnano
        ophotos=p_phyto_photoratio*0.212_rsh*effetchaleur*                              &
            (p_diat_mumax*min(effetlumierediat,effetnutdiat)*c(iv_phyto_diat_N)+  &
             p_dino_mumax*min(effetlumieredino,effetnutdino)*c(iv_phyto_dino_N)+  &
             p_nano_mumax*min(effetlumierenano,effetnutnano)*c(iv_phyto_nano_N))   
#ifdef key_psnz  
   ! Modif Alain Octobre 2015
   !ophotos=ophotos+p_phyto_photoratio*0.212_rsh*(rationpsnz*c(iv_phyto_psnz_N))
    effetnutpsnz=1.0_rsh
    if (effetselnutpsnz.le.0.3_rsh) effetnutpsnz=effetselnutpsnz
    ophotos=ophotos+p_phyto_photoratio*0.212_rsh*p_psnz_mumax*min(effetlumierepsnz,effetnutpsnz)*c(iv_phyto_psnz_N)
#endif
#ifdef key_karenia  
   ! Modif Alain Octobre 2015
   !ophotos=ophotos+p_phyto_photoratio*0.212_rsh*(rationkarenia*c(iv_phyto_karenia_N))
    effetnutkarenia=1.0_rsh
    if (effetselnutkarenia.le.0.3_rsh) effetnutkarenia=effetselnutkarenia
    ophotos=ophotos+p_phyto_photoratio*0.212_rsh*p_karenia_mumax*min(effetlumierekarenia,effetnutkarenia)*c(iv_phyto_karenia_N)
#endif
#ifdef key_phaeocystis  
   ! Modif Alain Octobre 2015
   !ophotos=ophotos+p_phyto_photoratio*0.212_rsh*(rationphaeocystiscolo*c(iv_phyto_phaeocystis_colo_N) &
   !     +rationphaeocystiscell*c(iv_phyto_phaeocystis_cell_N))
    effetnutphaeocolo=1.0_rsh
    if (effetselnutphaeocystiscolo.le.0.3_rsh) effetnutphaeocolo=effetselnutphaeocystiscolo
    effetnutphaeocell=1.0_rsh
    if (effetselnutphaeocystiscell.le.0.3_rsh) effetnutphaeocell=effetselnutphaeocystiscell
    ophotos=ophotos+p_phyto_photoratio*0.212_rsh*(p_phaeocystis_mumaxcolo*min(effetlumierephaeocystis,effetnutphaeocolo)*c(iv_phyto_phaeocystis_colo_N) &
        +p_phaeocystis_mumaxcell*min(effetlumierephaeocystis,effetnutphaeocell)*c(iv_phyto_phaeocystis_cell_N))
#endif
#ifdef key_ulve
   ! le 0.44 permet de passer de gPoidsSec.l-1 en gC.l-1 
   ! le 0.001*32/12 permet de passer de gC.l-1 en mgO2.l-1
   ophotos=ophotos+0.44*0.001*32/12(rationulve*c(iv_ulv_susdrywght)+ &
                                    rationulvebenth*c(iv_ulv_susdrywght)*ibbenth*partulvessurface/epn)
#endif     
#ifdef key_zostera
   IF(c(iv_zost_LB)>0.0_rsh) THEN
     ophotos = ophotos + Gross_Prod_zost*c(iv_zost_LB)/epn
   ENDIF
#endif

   ! Modif Alain Octobre 2015
    oresphyto=0.0_rsh
    orespzoo=0.0_rsh
    IF (c(iv_oxygen).gt.0.2_rsh) then  
     ! le 0.001*6.625*32=0.212 permet de passer de micromolN.l-1 en mgO2.l-1
     oresphyto=p_phyto_resp*((1.0_rsh-effetlumierediat)*c(iv_phyto_diat_N)+(1.0_rsh-effetlumieredino)*c(iv_phyto_dino_N)  &
                       +(1.0_rsh-effetlumierenano)*c(iv_phyto_nano_N))*0.212_rsh*effetchaleur
     !oresphyto=((0.01_rsh+(1.0_rsh-effetlumierediat)*0.05_rsh)*c(iv_phyto_diat_N)*0.212_rsh              &
     !         +(0.01_rsh+(1.0_rsh-effetlumieredino)*0.05_rsh)*c(iv_phyto_dino_N)*0.212_rsh            &
     !         +(0.01_rsh+(1.0_rsh-effetlumierenano)*0.05_rsh)*c(iv_phyto_nano_N)*0.212_rsh)*effetchaleur
#ifdef key_psnz
     oresphyto=oresphyto+  &
        p_phyto_resp*(1.0_rsh-effetlumierepsnz)*c(iv_phyto_psnz_N)*0.212_rsh*effetchaleur
     !oresphyto=oresphyto+ &
     !     ((0.01_rsh+(1.0_rsh-effetlumierepsnz)*0.04_rsh)*c(iv_phyto_psnz_N)*0.212_rsh)*effetchaleur
#endif
#ifdef key_karenia
      oresphyto=oresphyto+  &
        p_phyto_resp*(1.0_rsh-effetlumierekarenia)*c(iv_phyto_karenia_N)*0.212_rsh*effetchaleur
     !oresphyto=oresphyto+  &
     !     ((0.01_rsh+(1.0_rsh-effetlumierekarenia)*0.04_rsh)*c(iv_phyto_karenia_N)*0.212_rsh)*effetchaleur
#endif
#ifdef key_phaeocystis
     oresphyto=oresphyto+  &
       p_phyto_resp*((1.0_rsh-effetlumierephaeocystis)*c(iv_phyto_phaeocystis_colo_N)+  &
       (1.0_rsh-effetlumierephaeocystis)*c(iv_phyto_phaeocystis_cell_N))*0.212_rsh*effetchaleur
     !oresphyto=oresphyto+  &
     !    ((0.01_rsh+(1.0_rsh-effetlumierephaeocystis)*0.04_rsh)*c(iv_phyto_phaeocystis_colo_N)*0.212_rsh)*effetchaleur+  &
     !    ((0.01_rsh+(1.0_rsh-effetlumierephaeocystis)*0.04_rsh)*c(iv_phyto_phaeocystis_cell_N)*0.212_rsh)*effetchaleur
#endif 

     orespzoo=p_zoo_resp*(c(iv_zoo_meso_N)+c(iv_zoo_micr_N))*0.212_rsh*effetchaleur
   ENDIF
   oremineau=reminazdeteau*c(iv_detr_N)*0.212_rsh
#ifdef key_benthos   
  ! Modif Alain Octobre 2015 : oremineau mis en commentaire ??
   !oremineau=oremineau+(reminazdeteau*p_reminbenth)*c(iv_benth_N)*0.212_rsh*ibbenth/epn
   !! OU oremineau=oremineau+(reminazdeteau*0.07_rsh)*c(iv_benth_N)*0.212_rsh*ibbenth/epn
#endif  
   onitrifeau=xnitrifeau*c(iv_nutr_NH4)*0.064_rsh
   perteo2=oresphyto+orespzoo+oremineau+onitrifeau
#ifdef key_zostera
   IF(c(iv_zost_LB)>0.0_rsh) THEN
     perteo2 = perteo2 + Leaf_Resp_zost*c(iv_zost_LB)/epn + Root_Resp_zost*c(iv_zost_RB)/epn
   ENDIF
#endif
    
   ! reoxygenation
   ! -------------
   gst=-173.4292_rsh+249.6329_rsh*100.0_rsh/tempabs+143.3483_rsh*log(tempabs/100.0_rsh)    &
         -21.8492_rsh*tempabs/100.0_rsh+sali*(-0.033096_rsh+0.014259_rsh*tempabs/100.0_rsh &
         -0.0017_rsh*(tempabs/100.0_rsh)**2)
   o2sat=1.429_rsh*exp(gst)
   !Formule de Riley et Stephan (1988)
   !oair=(0.64_rsh+0.0256_rsh*(ventvent(im,jm)/0.447_rsh)**2)*(o2sat-c(iv_oxygen))/epn
   schmidt=(1800.6_rsh-120.1_rsh*temper+3.7818_rsh*temper**2-0.047608_rsh*temper**3)*(1.0_rsh+0.00314_rsh*sali)
   !Formule de Wanninkhof (1992)
   !le facteur 0.31 cm/h est converti en 24*0.31/100=0.0744 m/jour
   !oair=0.0744_rsh*(ventvent(im,jm)**2)/sqrt(schmidt/660.0_rsh)*(o2sat-c(iv_oxygen))/epn
   !Formule de Wanninkhof & McGillis (1999)
   !le facteur 0.0283 cm/h est converti en 24*0.0283/100=0.00679 m/jour
   oair=0.00679_rsh*(ventvent(im,jm)**3)/sqrt(schmidt/660.0_rsh)*(o2sat-c(iv_oxygen))/epn

   oair=oair*ibsurf
   ! Evolution de l oxygene dissous
   ! ------------------------------
   dc(iv_oxygen)=ophotos+oair-perteo2

   ! pourcentage de saturation de l oxygene
   diag_3d_wat(irk_diag(id_oxy_sat),km,im,jm)=c(iv_oxygen)/o2sat

   ! Evolution du nitrate (avec denitrification)
   ! ------------------------------
 !  IF((c(iv_oxygen)/o2sat).le.0.05_rsh) THEN
 !  dc(iv_nutr_NO3)=dc(iv_nutr_NO3)-((-0.2_rsh/o2sat)*c(iv_oxygen)+0.2_rsh)*c(iv_nutr_NO3)*ibbenth
 !  END IF
   
 
  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  ! saisir le code avant cette limite
  ! =================================
  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!


   END SUBROUTINE incellwat_oxygen
#endif
   !!======================================================================
#if defined key_N_tracer
  SUBROUTINE incellwat_nitrogentracer(km,im,jm,xe,c,dc,   &
             fractionnh4diat,fractionnh4dino,fractionnh4nano,  &
             fractionno3diat,fractionno3dino,fractionno3nano )
 
   !&E---------------------------------------------------------------------
   !&E                 ***  ROUTINE incellwat_nitrogentracer  ***
   !&E
   !&E ** Purpose : Tracage dans l ecosysteme de l azote emis par la source A
   !&E
   !&E ** Description :
   !&E
   !&E ** Called by :  incellwat_nut4phy3zoo2
   !&E
   !&E ** External calls :
   !&E
   !&E ** Reference :
   !&E
   !&E ** History :
   !&E       !  2010-03    (A. Menesguen ) Original code
   !&E       !  ???????    (  )  evolutions
   !&E
   !&E---------------------------------------------------------------------
   !! * Modules used

   USE parameters, ONLY : nb_var_tracerN
   USE comsubstance, ONLY : attenuation,extinction,alumplafond,name_var
   USE bioloinit, ONLY : tdeb_tracerN

        
   !! * Arguments
   INTEGER, INTENT(in)                       :: km,im,jm      ! ocean spatial-step index
   REAL(KIND=rsh),INTENT(in)                 :: xe            ! ssh
   REAL(KIND=rsh),DIMENSION(:),INTENT(in)    :: c
   REAL(KIND=rsh),DIMENSION(:),INTENT(inout) :: dc
   REAL(KIND=rsh),INTENT(in)                 :: fractionnh4diat,fractionnh4dino,fractionnh4nano,  &
                                                fractionno3diat,fractionno3dino,fractionno3nano
            
   !! * Local declarations
   INTEGER                                   :: is,ivtra,iv_tra,iv_sign,id_sign,ivage
   REAL(KIND=rlg),DIMENSION(nv_state)        :: signature_N,age_N 
   REAL(KIND=rlg)                            :: age_max 
   REAL(KIND=rsh)                            :: Nphytototal,phytototal_tra_N 
   REAL (KIND=rsh), PARAMETER                :: seuil_N_tracer=1.e-6_rsh,seuil_N_age_tracer=0.01_rsh
   REAL (KIND=rsh), PARAMETER                :: seuil_N_tracer_diag=seuil_N_tracer*500.0_rsh,seuil_N_age_tracer_phytot=0.02_rsh
   !!REAL(kind=rsh)  ,PARAMETER              :: epsil=0.0000001_rsh
   !!----------------------------------------------------------------------
   !! * Executable part

   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
   ! saisir le code apres cette limite
   ! =================================
   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

   ! Calcul de la fraction de traceur dans les variables azoteees  (s.u)
   ! ------------------------------------------------------------
   DO is=1,nb_source_tracerN
      DO ivtra=1,nb_var_tracerN 
        iv_tra=iv_tracer_N(ivtra,is)
        signature_N(iv_tra)=0.0_rsh
        iv_sign=iv_signed_N(ivtra,is)
        IF (c(iv_sign).gt.seuil_N_tracer) signature_N(iv_tra)=c(iv_tra)/c(iv_sign)
        IF (signature_N(iv_tra).gt.100.0_rsh)  print*,'im=',im,'jm=',jm,'km=',km,'signature_N', &
                             TRIM(ADJUSTL(ADJUSTR(name_var(isubs_tracer_N(ivtra,is))))),signature_N(iv_tra)

#ifdef key_age_tracer
   ! Calcul des ages du traceur dans les variables azoteees  (jours)
   ! ----------------------------------------------------------------
        ivage=iv_age_N(ivtra,is)
        age_N(ivage)=0.0_rsh
       ! IF (c(iv_tra).gt.seuil_N_tracer) age_N(ivage)=c(ivage)c(iv_tra)
        IF (signature_N(iv_tra) .GT. seuil_N_age_tracer) age_N(ivage)=c(ivage)/c(iv_tra)
#endif
      ENDDO
   
       
   ! Evolution de variables traceurs marques (micromoles/L N)
   ! -------------------------------------------------
   ! ammonium
      dc(iv_nutr_NH4_tra_N(is))=reminazdeteau*c(iv_detr_tra_N(is))    &
                      -(fractionnh4diat*rationdiat*c(iv_phyto_diat_N)+fractionnh4dino*rationdino*c(iv_phyto_dino_N)+ &
                        fractionnh4nano*rationnano*c(iv_phyto_nano_N))   &
                      *signature_N(iv_nutr_NH4_tra_N(is))-xnitrifeau*c(iv_nutr_NH4_tra_N(is))+ &
                        excretionmesozoo*c(iv_zoo_meso_tra_N(is)) +excretionmicrozoo*c(iv_zoo_micr_tra_N(is))
 
#ifdef key_karenia
      dc(iv_nutr_NH4_tra_N(is))=dc(iv_nutr_NH4_tra_N(is))- &
                                fractionnh4karenia*uptakeN*c(iv_phyto_karenia_C)*signature_N(iv_nutr_NH4_tra_N(is))   
#endif
#ifdef key_phaeocystis
      dc(iv_nutr_NH4_tra_N(is))=dc(iv_nutr_NH4_tra_N(is))- &
                                (fractionnh4phaeocystiscolo*rationphaeocystiscolo*c(iv_phyto_phaeocystis_colo_N)  &
                                 +fractionnh4phaeocystiscell*rationphaeocystiscell*c(iv_phyto_phaeocystis_cell_N)) &
                                    *signature_N(iv_nutr_NH4_tra_N(is))
#endif
#ifdef key_psnz
      dc(iv_nutr_NH4_tra_N(is))=dc(iv_nutr_NH4_tra_N(is))- &
                                fractionnh4psnz*rationpsnz*c(iv_phyto_psnz_N)*signature_N(iv_nutr_NH4_tra_N(is))
#endif
#ifdef key_ulvas
      dc(iv_nutr_NH4_tra_N(is))=dc(iv_nutr_NH4_tra_N(is))- &
                                fractionnh4*signature_N(iv_nutr_NH4_tra_N(is))*(pompageazoteulve*c(iv_ulv_susdrywght)   &
                                +pompageazoteulvebenth*c(iv_ulv_benthdrywght)*partulvessurface*ibbenth/epn)
#endif
#ifdef key_benthos
      dc(iv_nutr_NH4_tra_N(is))=dc(iv_nutr_NH4_tra_N(is))+reminazdeteau*p_reminbenth*c(iv_benth_tra_N(is))*ibbenth/epn
#endif

#ifdef key_age_tracer
      dc(iv_nutr_NH4_age_tra_N(is))=c(iv_nutr_NH4_tra_N(is))+reminazdeteau*c(iv_detr_age_tra_N(is))      &
                 -(fractionnh4diat*rationdiat*c(iv_phyto_diat_N)+  &
                   fractionnh4dino*rationdino*c(iv_phyto_dino_N)+fractionnh4nano*rationnano*c(iv_phyto_nano_N))      &
                  *signature_N(iv_nutr_NH4_tra_N(is))*age_N(iv_nutr_NH4_age_tra_N(is))-xnitrifeau*c(iv_nutr_NH4_age_tra_N(is)) &
                  +excretionmesozoo*c(iv_zoo_meso_age_tra_N(is))+excretionmicrozoo*c(iv_zoo_micr_age_tra_N(is))	  
#ifdef key_karenia
       dc(iv_nutr_NH4_age_tra_N(is))=dc(iv_nutr_NH4_age_tra_N(is))- fractionnh4karenia*uptakeN*   &
                             c(iv_phyto_karenia_C)*signature_N(iv_nutr_NH4_tra_N(is))*age_N(iv_nutr_NH4_age_tra_N(is))
#endif
#ifdef key_phaeocystis
       dc(iv_nutr_NH4_age_tra_N(is))=dc(iv_nutr_NH4_age_tra_N(is))- &
                         (fractionnh4phaeocystiscolo*rationphaeocystiscolo*c(iv_phyto_phaeocystis_colo_N)    &
                         +fractionnh4phaeocystiscell*rationphaeocystiscell*c(iv_phyto_phaeocystis_cell_N))*  &
                                     signature_N(iv_nutr_NH4_tra_N(is))*age_N(iv_nutr_NH4_age_tra_N(is))
#endif
#ifdef key_psnz
       dc(iv_nutr_NH4_age_tra_N(is))=dc(iv_nutr_NH4_age_tra_N(is))    &
                         -fractionnh4psnz*rationpsnz*c(iv_phyto_psnz_N)*signature_N(iv_nutr_NH4_tra_N(is))* &
                                     age_N(iv_nutr_NH4_age_tra_N(is))
#endif
#ifdef key_ulvas
       dc(iv_nutr_NH4_age_tra_N(is))=dc(iv_nutr_NH4_age_tra_N(is))  &
                        -fractionnh4*signature_N(iv_nutr_NH4_tra_N(is))*age_N(iv_nutr_NH4_age_tra_N(is))* &
                           (pompageazoteulve*c(iv_ulv_susdrywght)           &
                        +pompageazoteulvebenth*c(iv_ulv_benthdrywght)*partulvessurface*ibbenth/epn)
#endif
#ifdef key_benthos
       dc(iv_nutr_NH4_age_tra_N(is))=dc(iv_nutr_NH4_age_tra_N(is))+  &
                           reminazdeteau*p_reminbenth*c(iv_benth_age_tra_N(is))*ibbenth/epn
#endif
#endif
   
   ! Evolution du nitrate marque (micromoles/L N)
   ! ----------------------------------------------
       dc(iv_nutr_NO3_tra_N(is))=xnitrifeau*c(iv_nutr_NH4_tra_N(is))- &
                                        (fractionno3diat*rationdiat*c(iv_phyto_diat_N)+  &
                                         fractionno3dino*rationdino*c(iv_phyto_dino_N)+  &
                                         fractionno3nano*rationnano*c(iv_phyto_nano_N))  &
                                               *signature_N(iv_nutr_NO3_tra_N(is))

#ifdef key_karenia
       dc(iv_nutr_NO3_tra_N(is))=dc(iv_nutr_NO3_tra_N(is))-  &
                                          fractionno3karenia*uptakeN*c(iv_phyto_karenia_C)  &
                                               *signature_N(iv_nutr_NO3_tra_N(is)) 
#endif
#ifdef key_phaeocystis
       dc(iv_nutr_NO3_tra_N(is))=dc(iv_nutr_NO3_tra_N(is))-  &
                                 (fractionno3phaeocystiscolo*rationphaeocystiscolo*c(iv_phyto_phaeocystis_colo_N)  &
                                 +fractionno3phaeocystiscell*rationphaeocystiscell*c(iv_phyto_phaeocystis_cell_N))  &
                                               *signature_N(iv_nutr_NO3_tra_N(is))
#endif
#ifdef key_psnz
       dc(iv_nutr_NO3_tra_N(is))=dc(iv_nutr_NO3_tra_N(is))-  &
                                 fractionno3psnz*rationpsnz*c(iv_phyto_psnz_N)*signature_N(iv_nutr_NO3_tra_N(is))
#endif
#ifdef key_ulvas
       dc(iv_nutr_NO3_tra_N(is))=dc(iv_nutr_NO3_tra_N(is))-  &
                                  fractionno3*signature_N(iv_nutr_NO3_tra_N(is))*(pompageazoteulve*c(iv_ulv_susdrywght)   &
                                   +pompageazoteulvebenth*c(iv_ulv_benthdrywght)*partulvessurface*ibbenth/epn)
#endif

#ifdef key_age_tracer
       dc(iv_nutr_NO3_age_tra_N(is))=c(iv_nutr_NO3_tra_N(is))+xnitrifeau*c(iv_nutr_NH4_age_tra_N(is))  &
                                 -(fractionno3diat*rationdiat*c(iv_phyto_diat_N)+  &
                                   fractionno3dino*rationdino*c(iv_phyto_dino_N)+  &
                                   fractionno3nano*rationnano*c(iv_phyto_nano_N))   &
                                   *signature_N(iv_nutr_NO3_tra_N(is))*age_N(iv_nutr_NO3_age_tra_N(is))
#ifdef key_karenia
        dc(iv_nutr_NO3_age_tra_N(is))=dc(iv_nutr_NO3_age_tra_N(is))     &
                                    - fractionno3karenia*uptakeN*c(iv_phyto_karenia_C)  &
                                   *signature_N(iv_nutr_NO3_tra_N(is))*age_N(iv_nutr_NO3_age_tra_N(is)) 
#endif
#ifdef key_phaeocystis
        dc(iv_nutr_NO3_age_tra_N(is))=dc(iv_nutr_NO3_age_tra_N(is))    &
                - (fractionno3phaeocystiscolo*rationphaeocystiscolo*c(iv_phyto_phaeocystis_colo_N)      &
                   +fractionno3phaeocystiscell*rationphaeocystiscell*c(iv_phyto_phaeocystis_cell_N))    &
                                    *signature_N(iv_nutr_NO3_tra_N(is))*age_N(iv_nutr_NO3_age_tra_N(is))
#endif
#ifdef key_psnz
        dc(iv_nutr_NO3_age_tra_N(is))=dc(iv_nutr_NO3_age_tra_N(is))   &
                                      -fractionno3psnz*rationpsnz*c(iv_phyto_psnz_N)  &
                                    *signature_N(iv_nutr_NO3_tra_N(is))*age_N(iv_nutr_NO3_age_tra_N(is))
#endif
#ifdef key_ulvas
        dc(iv_nutr_NO3_age_tra_N(is))=dc(iv_nutr_NO3_age_tra_N(is))   &
                                      -fractionno3*signature_N(iv_nutr_NO3_tra_N(is))*age_N(iv_nutr_NO3_age_tra_N(is))  &
                                        *(pompageazoteulve*c(iv_ulv_susdrywght)                   &
                                         +pompageazoteulvebenth*c(iv_ulv_benthdrywght)*partulvessurface*ibbenth/epn)
#endif
#endif
   
   ! Evolution de l azote marque des diatomees  (micromoles/L N)
   ! -------------------------------------------------------------
       dc(iv_phyto_diat_tra_N(is))=rationdiat*c(iv_phyto_diat_N)*  &
                     (fractionnh4diat*signature_N(iv_nutr_NH4_tra_N(is))+  &
                      fractionno3diat*signature_N(iv_nutr_NO3_tra_N(is)))  &
                     -(diatmorteau+txfiltbenthij*ibbenth/epn)*c(iv_phyto_diat_tra_N(is))    &
                     -(broumesozoodiat*c(iv_zoo_meso_N)+broumicrozoodiat*c(iv_zoo_micr_N))  &
                                       *signature_N(iv_phyto_diat_tra_N(is))

#ifdef key_age_tracer
       dc(iv_phyto_diat_age_tra_N(is))=c(iv_phyto_diat_tra_N(is)) +rationdiat*c(iv_phyto_diat_N)* &
                      (fractionnh4diat*signature_N(iv_nutr_NH4_tra_N(is))*age_N(iv_nutr_NH4_age_tra_N(is))   &
                       +fractionno3diat*signature_N(iv_nutr_NO3_tra_N(is))*age_N(iv_nutr_NO3_age_tra_N(is)))  &
                     -(diatmorteau+txfiltbenthij*ibbenth/epn)*c(iv_phyto_diat_age_tra_N(is))    &
                     -(broumesozoodiat*c(iv_zoo_meso_N)+broumicrozoodiat*c(iv_zoo_micr_N))   &
                        *signature_N(iv_phyto_diat_tra_N(is))*age_N(iv_phyto_diat_age_tra_N(is))
#endif
   
   ! Evolution de l azote marque des dinoflagelles  (micromoles/L N)
   ! -----------------------------------------------------------------
       dc(iv_phyto_dino_tra_N(is))=rationdino*c(iv_phyto_dino_N)*  &
                      (fractionnh4dino*signature_N(iv_nutr_NH4_tra_N(is))+fractionno3dino*signature_N(iv_nutr_NO3_tra_N(is)))  &
                      -(dinomorteau+txfiltbenthij*ibbenth/epn)*c(iv_phyto_dino_tra_N(is))-broumesozoodino*c(iv_zoo_meso_N)  &
                             *signature_N(iv_phyto_dino_tra_N(is))

#ifdef key_age_tracer  
       dc(iv_phyto_dino_age_tra_N(is))=c(iv_phyto_dino_tra_N(is)) +rationdino*c(iv_phyto_dino_N)* &
                       (fractionnh4dino*signature_N(iv_nutr_NH4_tra_N(is))*age_N(iv_nutr_NH4_age_tra_N(is))   &
                       +fractionno3dino*signature_N(iv_nutr_NO3_tra_N(is))*age_N(iv_nutr_NO3_age_tra_N(is)))  &
                       -(dinomorteau+txfiltbenthij*ibbenth/epn)*c(iv_phyto_dino_age_tra_N(is))   &
                        -broumesozoodino*c(iv_zoo_meso_N)*signature_N(iv_phyto_dino_tra_N(is))*age_N(iv_phyto_dino_age_tra_N(is))
#endif
   
   ! Evolution de l azote marque des nanoflagelles  (micromoles/L N)
   ! -----------------------------------------------------------------
       dc(iv_phyto_nano_tra_N(is))=rationnano*c(iv_phyto_nano_N)*  &
                         (fractionnh4nano*signature_N(iv_nutr_NH4_tra_N(is))+   &
                          fractionno3nano*signature_N(iv_nutr_NO3_tra_N(is)))  &
                         -(nanomorteau+txfiltbenthij*ibbenth/epn)*c(iv_phyto_nano_tra_N(is)) &
                              -broumicrozoonano*c(iv_zoo_micr_N)*signature_N(iv_phyto_nano_tra_N(is))

#ifdef key_age_tracer  
       dc(iv_phyto_nano_age_tra_N(is))=c(iv_phyto_nano_tra_N(is))+rationnano*c(iv_phyto_nano_N)*  &
                       (fractionnh4nano*signature_N(iv_nutr_NH4_tra_N(is))*age_N(iv_nutr_NH4_age_tra_N(is))   &
                       +fractionno3nano*signature_N(iv_nutr_NO3_tra_N(is))*age_N(iv_nutr_NO3_age_tra_N(is)))  &
                       -(nanomorteau+txfiltbenthij*ibbenth/epn)*c(iv_phyto_nano_age_tra_N(is))   &
                       -broumicrozoonano*c(iv_zoo_micr_N)*signature_N(iv_phyto_nano_tra_N(is))*age_N(iv_phyto_nano_age_tra_N(is))
#endif
      
#ifdef key_karenia

   ! Evolution de l azote marque de Karenia mikimotoi (cellules/L)
   ! ---------------------------------------------------------------   
       dc(iv_phyto_karenia_tra_N(is))= uptakeN*c(iv_phyto_karenia_C)*  &
                                       (fractionnh4karenia*signature_N(iv_nutr_NH4_tra_N(is))  &
                                       +fractionno3karenia*signature_N(iv_nutr_NO3_tra_N(is)))  &
                                       -(kareniamorteau+txfiltbenthij*ibbenth/epn)*c(iv_phyto_karenia_tra_N(is))  &
                                        -broumesozookarenia*c(iv_zoo_meso_N)*signature_N(iv_phyto_karenia_tra_N(is))
#ifdef key_age_tracer
       dc(iv_phyto_karenia_age_tra_N(is))=c(iv_phyto_karenia_tra_N(is)) +uptakeN*c(iv_phyto_karenia_C)* &
                      (fractionnh4karenia*signature_N(iv_nutr_NH4_tra_N(is))*age_N(iv_nutr_NH4_age_tra_N(is))   &
                      +fractionno3karenia*signature_N(iv_nutr_NO3_tra_N(is))*age_N(iv_nutr_NO3_age_tra_N(is)))  &
                      -(kareniamorteau+txfiltbenthij*ibbenth/epn)*c(iv_phyto_karenia_age_tra_N(is))   &
                      -broumesozookarenia*c(iv_zoo_meso_N)*signature_N(iv_phyto_karenia_tra_N(is))  &
                                         *age_N(iv_phyto_karenia_age_tra_N(is))
#endif
#endif

#ifdef key_phaeocystis

   ! Evolution de l azote marque des colonies de Phaeocystis globosa (micromoles/L N)
   ! ----------------------------------------------------------------------------------
       dc(iv_phyto_phaeocystis_colo_tra_N(is))=rationphaeocystiscolo*c(iv_phyto_phaeocystis_colo_N)* &
                     (fractionnh4phaeocystiscolo*signature_N(iv_nutr_NH4_tra_N(is))  & 
                     +fractionno3phaeocystiscolo*signature_N(iv_nutr_NO3_tra_N(is)))- &
                     (phaeocystismortcolo+phaeocystislysecolo)*c(iv_phyto_phaeocystis_colo_tra_N(is))   &
                     -broumesozoophaeocolo*c(iv_zoo_meso_N)*signature_N(iv_phyto_phaeocystis_colo_tra_N(is))+ &
                      initcolonie*c(iv_phyto_phaeocystis_cell_tra_N(is))
#ifdef key_age_tracer
       dc(iv_phyto_phaeocystis_colo_age_tra_N(is))=c(iv_phyto_phaeocystis_colo_tra_N(is))  &
                      +rationphaeocystiscolo*c(iv_phyto_phaeocystis_colo_N)* &
                       (fractionnh4phaeocystiscolo*signature_N(iv_nutr_NH4_tra_N(is))*age_N(iv_nutr_NH4_age_tra_N(is))  & 
                       +fractionno3phaeocystiscolo*signature_N(iv_nutr_NO3_tra_N(is))*age_N(iv_nutr_NO3_age_tra_N(is)))  &
                      -(phaeocystismortcolo+phaeocystislysecolo)*c(iv_phyto_phaeocystis_colo_age_tra_N(is))   &
                      -broumesozoophaeocolo*c(iv_zoo_meso_N)*signature_N(iv_phyto_phaeocystis_colo_tra_N(is))   &
                   *age_N(iv_phyto_phaeocystis_colo_age_tra_N(is))+initcolonie*c(iv_phyto_phaeocystis_cell_age_tra_N(is))
#endif

   ! Evolution de l azote marque des cellules libres de Phaeocystis globosa (micromoles/L N)
   ! -----------------------------------------------------------------------------------------
       dc(iv_phyto_phaeocystis_cell_tra_N(is))=rationphaeocystiscell*c(iv_phyto_phaeocystis_cell_N)*  &
                         (fractionnh4phaeocystiscell*signature_N(iv_nutr_NH4_tra_N(is))    & 
                         +fractionno3phaeocystiscell*signature_N(iv_nutr_NO3_tra_N(is)))-  &
                         (phaeocystismortcell+txfiltbenthij*ibbenth/epn)*c(iv_phyto_phaeocystis_cell_tra_N(is))   &
                         -broumicrozoophaeocell*c(iv_zoo_micr_N)*signature_N(iv_phyto_phaeocystis_cell_tra_N(is)) &
                          -initcolonie*c(iv_phyto_phaeocystis_cell_tra_N(is))
#ifdef key_age_tracer
      dc(iv_phyto_phaeocystis_cell_age_tra_N(is))=c(iv_phyto_phaeocystis_cell_tra_N(is))  &
                           +rationphaeocystiscell*c(iv_phyto_phaeocystis_cell_N)*  &
                          (fractionnh4phaeocystiscell*signature_N(iv_nutr_NH4_tra_N(is))*age_N(iv_nutr_NH4_age_tra_N(is))  & 
                          +fractionno3phaeocystiscell*signature_N(iv_nutr_NO3_tra_N(is))*age_N(iv_nutr_NO3_age_tra_N(is))) &
                      -(phaeocystismortcell+txfiltbenthij*ibbenth/epn)*c(iv_phyto_phaeocystis_cell_age_tra_N(is))   &
                      -broumicrozoophaeocell*c(iv_zoo_micr_N)*signature_N(iv_phyto_phaeocystis_cell_tra_N(is))    &
                        *age_N(iv_phyto_phaeocystis_cell_age_tra_N(is))-initcolonie*c(iv_phyto_phaeocystis_cell_age_tra_N(is))
#endif
#endif

#ifdef key_psnz

   ! Evolution de l azote marque des Pseudo-Nitzschia (micromoles/L N)
   ! -------------------------------------------------------------------
       dc(iv_phyto_psnz_tra_N(is))=rationpsnz*c(iv_phyto_psnz_N)*  &
                                    (fractionnh4psnz*signature_N(iv_nutr_NH4_tra_N(is))+  &
                                     fractionno3psnz*signature_N(iv_nutr_NO3_tra_N(is)))  &
                                    -(psnzmorteau+txfiltbenthij*ibbenth/epn)*c(iv_phyto_psnz_tra_N(is))   &
                                     -(broumicrozoopsnz*c(iv_zoo_micr_N)+broumesozoopsnz*c(iv_zoo_meso_N))  &
                                                 *signature_N(iv_phyto_psnz_tra_N(is))
#ifdef key_age_tracer
       dc(iv_phyto_psnz_age_tra_N(is))=c(iv_phyto_psnz_tra_N(is)) +rationpsnz*c(iv_phyto_psnz_N)* &
                       (fractionnh4psnz*signature_N(iv_nutr_NH4_tra_N(is))*age_N(iv_nutr_NH4_age_tra_N(is))  &
                        +fractionno3psnz*signature_N(iv_nutr_NO3_tra_N(is))*age_N(iv_nutr_NO3_age_tra_N(is)))  &
                      -(psnzmorteau+txfiltbenthij*ibbenth/epn)*c(iv_phyto_psnz_age_tra_N(is))  &
                      -(broumicrozoopsnz*c(iv_zoo_micr_N)+broumesozoopsnz*c(iv_zoo_meso_N))  &
                                       *signature_N(iv_phyto_psnz_tra_N(is))*age_N(iv_phyto_psnz_age_tra_N(is))
#endif
#endif

#ifdef key_ulvas
   ! Evolution de l azote marque des ulves en suspension [gN.m-3]
   ! --------------------------------------------------------------
   ! le 0.014 permet de passer de micromolN.l-1 en mgN.l-1 (ou gN.m-3)
       dc(iv_ulv_tra_N(is))=0.014_rsh*pompageazoteulve*c(iv_ulv_susdrywght)*  &
                            (fractionnh4*signature_N(iv_nutr_NH4_tra_N(is))  &
                            +fractionno3*signature_N(iv_nutr_NO3_tra_N(is)))    &
                              -ulvemorteau*c(iv_ulv_tra_N(is))+(ulveresuspazote*signature_N(iv_ulv_benth_tra_N(is)) &
                              -vitessechuteulve*c(iv_ulv_tra_N(is)))/epn*ibbenth
#ifdef key_age_tracer
       dc(iv_ulv_sus_age_tra_N(is))=c(iv_ulv_sus_tra_N(is)) +0.014_rsh*pompageazoteulve*c(iv_ulv_susdrywght)  &
                     *(fractionnh4*signature_N(iv_nutr_NH4_tra_N(is))*age_N(iv_nutr_NH4_age_tra_N(is))   &
                      +fractionno3*signature_N(iv_nutr_NO3_tra_N(is))*age_N(iv_nutr_NO3_age_tra_N(is)))    &
                      -ulvemorteau*c(iv_ulv_sus_age_tra_N(is))  &
                      +(ulveresuspazote*signature_N(iv_ulv_benth_tra_N(is))*age_N(iv_ulv_benth_age_tra_N(is)) &
                      -vitessechuteulve*c(iv_ulv_sus_age_tra_N(is)))/epn*ibbenth
#endif

   ! Evolution de l azote marque des ulves en depot [gN.m-2]
   ! ---------------------------------------------------------
   ! le 0.014 permet de passer de micromolN.l-1 en mgN.l-1 (ou gN.m-3)
       dc(iv_ulv_benth_tra_N(is))=(0.014_rsh*pompageazoteulvebenth*c(iv_ulv_benthdrywght)*partulvessurface* &
                      (fractionnh4*signature_N(iv_nutr_NH4_tra_N(is))    &
                      +fractionno3*signature_N(iv_nutr_NO3_tra_N(is)))          &
                      -ulvebenthmortsed*c(iv_ulv_benth_tra_N(is))  &
                      -ulveresuspazote*signature_N(iv_ulv_benth_tra_N(is))+vitessechuteulve*c(iv_ulv_sus_tra_N(is)))*ibbenth  
#ifdef key_age_tracer
      dc(iv_ulv_benth_age_tra_N(is))=c(iv_ulv_benth_tra_N(is))   &
                    +(0.014_rsh*pompageazoteulvebenth*c(iv_ulv_benthdrywght)*partulvessurface* &
                         (fractionnh4*signature_N(iv_nutr_NH4_tra_N(is))*age_N(iv_nutr_NH4_age_tra_N(is))  &
                         +fractionno3*signature_N(iv_nutr_NO3_tra_N(is))*age_N(iv_nutr_NO3_age_tra_N(is))) &
                        -ulvebenthmortsed*c(iv_ulv_benth_age_tra_N(is))  &
                         -ulveresuspazote*signature_N(iv_ulv_benth_tra_N(is))*age_N(iv_ulv_benth_age_tra_N(is)) &
                     +vitessechuteulve*c(iv_ulv_sus_age_tra_N(is)))*ibbenth 
#endif
#endif

   ! Evolution de l azote marque du microzooplancton (micromoles/L N)
   ! ------------------------------------------------------------------  
      dc(iv_zoo_micr_tra_N(is))=assimilmicrozoo*c(iv_zoo_micr_N)*(broumicrozoonano*signature_N(iv_phyto_nano_tra_N(is))  &
                                                                      +broumicrozoodiat*signature_N(iv_phyto_diat_tra_N(is))  &
                                                                     + broumicrozoodet*signature_N(iv_detr_tra_N(is)))        &
                                   -(excretionmicrozoo+txmortmicrozoo)*c(iv_zoo_micr_tra_N(is))   &
                                    - broumesozoomicrozoo*c(iv_zoo_meso_N)*signature_N(iv_zoo_micr_tra_N(is))

#ifdef key_phaeocystis
      dc(iv_zoo_micr_tra_N(is))=dc(iv_zoo_micr_tra_N(is)) +  &
                          assimilmicrozoo*c(iv_zoo_micr_N)*broumicrozoophaeocell*signature_N(iv_phyto_phaeocystis_cell_tra_N(is))
#endif
#ifdef key_psnz
      dc(iv_zoo_micr_tra_N(is))=dc(iv_zoo_micr_tra_N(is)) + &
                          assimilmicrozoo*c(iv_zoo_micr_N)*broumicrozoopsnz*signature_N(iv_phyto_psnz_tra_N(is))
#endif

#ifdef key_age_tracer
      dc(iv_zoo_micr_age_tra_N(is))=c(iv_zoo_micr_tra_N(is)) +assimilmicrozoo*c(iv_zoo_micr_N)* &
                       (broumicrozoonano*signature_N(iv_phyto_nano_tra_N(is))*age_N(iv_phyto_nano_age_tra_N(is))   &
                        +broumicrozoodiat*signature_N(iv_phyto_diat_tra_N(is))*age_N(iv_phyto_diat_age_tra_N(is))  &
                        +broumicrozoodet*signature_N(iv_detr_tra_N(is))*age_N(iv_detr_age_tra_N(is)))   &
                       -(excretionmicrozoo+txmortmicrozoo)*c(iv_zoo_micr_age_tra_N(is))  &
                       - broumesozoomicrozoo*c(iv_zoo_meso_N)*signature_N(iv_zoo_micr_tra_N(is))*age_N(iv_zoo_micr_age_tra_N(is))
#ifdef key_phaeocystis
       dc(iv_zoo_micr_age_tra_N(is))=dc(iv_zoo_micr_age_tra_N(is)) &
                        + assimilmicrozoo*c(iv_zoo_micr_N)*broumicrozoophaeocell  &
                          *signature_N(iv_phyto_phaeocystis_cell_tra_N(is))*age_N(iv_phyto_phaeocystis_cell_age_tra_N(is))
#endif
#ifdef key_psnz
       dc(iv_zoo_micr_age_tra_N(is))=dc(iv_zoo_micr_age_tra_N(is))  &
                   + assimilmicrozoo*c(iv_zoo_micr_N)*broumicrozoopsnz &
                          *signature_N(iv_phyto_psnz_tra_N(is))*age_N(iv_phyto_psnz_age_tra_N(is))
#endif
#endif

   ! Evolution de l azote marque du mesozooplancton (micromoles/L N)
   ! -----------------------------------------------------------------
       dc(iv_zoo_meso_tra_N(is))=assimilmesozoo*c(iv_zoo_meso_N)*(broumesozoodiat*signature_N(iv_phyto_diat_tra_N(is))  &
                                                                  +broumesozoodino*signature_N(iv_phyto_dino_tra_N(is))  &
                                                                  +broumesozoomicrozoo*signature_N(iv_zoo_micr_tra_N(is))) &
                                     -(excretionmesozoo+txmortmesozoo)*c(iv_zoo_meso_tra_N(is))
#ifdef key_phaeocystis
       dc(iv_zoo_meso_tra_N(is))=dc(iv_zoo_meso_tra_N(is))+ &
                         assimilmesozoo*c(iv_zoo_meso_N)*broumesozoophaeocolo*signature_N(iv_phyto_phaeocystis_colo_tra_N(is))
#endif
#ifdef key_psnz
       dc(iv_zoo_meso_tra_N(is))=dc(iv_zoo_meso_tra_N(is))+ &
                         assimilmesozoo*c(iv_zoo_meso_N)*broumesozoopsnz*signature_N(iv_phyto_psnz_tra_N(is))
#endif
#ifdef key_karenia
       dc(iv_zoo_meso_tra_N(is))=dc(iv_zoo_meso_tra_N(is))+  &
                         assimilmesozoo*c(iv_zoo_meso_N)*broumesozookarenia*signature_N(iv_phyto_karenia_tra_N(is))
#endif

#ifdef key_age_tracer
       dc(iv_zoo_meso_age_tra_N(is))=c(iv_zoo_meso_tra_N(is)) +assimilmesozoo*c(iv_zoo_meso_N)* &
                        (broumesozoodiat*signature_N(iv_phyto_diat_tra_N(is))*age_N(iv_phyto_diat_age_tra_N(is))   &
                        +broumesozoodino*signature_N(iv_phyto_dino_tra_N(is))*age_N(iv_phyto_dino_age_tra_N(is))  &
                        +broumesozoomicrozoo*signature_N(iv_zoo_micr_tra_N(is))*age_N(iv_zoo_micr_age_tra_N(is)))   &
                         -(excretionmesozoo+txmortmesozoo)*c(iv_zoo_meso_age_tra_N(is))
#ifdef key_phaeocystis
       dc(iv_zoo_meso_age_tra_N(is))=dc(iv_zoo_meso_age_tra_N(is))  &
                             +assimilmesozoo*c(iv_zoo_meso_N)*broumesozoophaeocolo  &
                             *signature_N(iv_phyto_phaeocystis_colo_tra_N(is))*age_N(iv_phyto_phaeocystis_colo_age_tra_N(is))
#endif
#ifdef key_psnz
       dc(iv_zoo_meso_age_tra_N(is))=dc(iv_zoo_meso_age_tra_N(is))   &
                                  +assimilmesozoo*c(iv_zoo_meso_N)*broumesozoopsnz  &
                                  *signature_N(iv_phyto_psnz_tra_N(is))*age_N(iv_phyto_psnz_age_tra_N(is))
#endif
#ifdef key_karenia
       dc(iv_zoo_meso_age_tra_N(is))=dc(iv_zoo_meso_age_tra_N(is))   &
                                     +assimilmesozoo*c(iv_zoo_meso_N)*broumesozookarenia  &
                                      *signature_N(iv_phyto_karenia_tra_N(is))*age_N(iv_phyto_karenia_age_tra_N(is))
#endif
#endif
   
   ! Evolution de l azote detritique marque (micromoles/L N)
   ! ---------------------------------------------------------
       dc(iv_detr_tra_N(is))=diatmorteau*c(iv_phyto_diat_tra_N(is))+dinomorteau*c(iv_phyto_dino_tra_N(is))+ &
                              nanomorteau*c(iv_phyto_nano_tra_N(is))    &           
                             -reminazdeteau*c(iv_detr_tra_N(is))+txmortmesozoo*c(iv_zoo_meso_tra_N(is))  &
                                                                 +txmortmicrozoo*c(iv_zoo_micr_tra_N(is)) &               
                    +(1.0_rsh-assimilmesozoo)*c(iv_zoo_meso_N)*  &
                             (broumesozoodiat*signature_N(iv_phyto_diat_tra_N(is))+  &
                              broumesozoodino*signature_N(iv_phyto_dino_tra_N(is))+   &
                              broumesozoomicrozoo*signature_N(iv_zoo_micr_tra_N(is)))   &
                    +(1.0_rsh-assimilmicrozoo)*c(iv_zoo_micr_N)* &
                              (broumicrozoonano*signature_N(iv_phyto_nano_tra_N(is))+  &
                               broumicrozoodiat*signature_N(iv_phyto_diat_tra_N(is))  &
                               +broumicrozoodet*signature_N(iv_detr_tra_N(is)))-broumicrozoodet*c(iv_zoo_micr_N) &
                                         *signature_N(iv_detr_tra_N(is)) 

#ifdef key_phaeocystis
       dc(iv_detr_tra_N(is))=dc(iv_detr_tra_N(is)) &
                             + (1.0_rsh-assimilmesozoo)*c(iv_zoo_meso_N)*broumesozoophaeocolo  &
                                                    *signature_N(iv_phyto_phaeocystis_colo_tra_N(is))  &
                             + (1.0_rsh-assimilmicrozoo)*c(iv_zoo_micr_N)*broumicrozoophaeocell  &
                                                    *signature_N(iv_phyto_phaeocystis_cell_tra_N(is))  &
                              + (phaeocystislysecolo+phaeocystismortcolo)*c(iv_phyto_phaeocystis_colo_tra_N(is))+ &
                                 phaeocystismortcell*c(iv_phyto_phaeocystis_cell_tra_N(is))
#endif
#ifdef key_psnz
       dc(iv_detr_tra_N(is))=dc(iv_detr_tra_N(is))+ &
                             ((1.0_rsh-assimilmesozoo)*c(iv_zoo_meso_N)*broumesozoopsnz+       &
                             +(1.0_rsh-assimilmicrozoo)*c(iv_zoo_micr_N)*broumicrozoopsnz)  &
                                     *signature_N(iv_phyto_psnz_tra_N(is))+ psnzmorteau*c(iv_phyto_psnz_tra_N(is))
#endif	 
#ifdef key_karenia
       dc(iv_detr_tra_N(is))=dc(iv_detr_tra_N(is))+ &
                              (1.0_rsh-assimilmesozoo)*c(iv_zoo_meso_N)*broumesozookarenia  &
                                     *signature_N(iv_phyto_karenia_tra_N(is))+ kareniamorteau*c(iv_phyto_karenia_tra_N(is))
#endif
#ifdef key_ulvas
       dc(iv_detr_tra_N(is))=dc(iv_detr_tra_N(is))+ulvemorteau*c(iv_ulv_sus_tra_N(is))/0.014_rsh
#endif
#ifdef key_benthos
       dc(iv_detr_tra_N(is))=dc(iv_detr_tra_N(is))+(detresuspazote*signature_N(iv_benth_tra_N(is)) &
                                     -vitessechutedet*c(iv_detr_tra_N(is)))*ibbenth/epn
#endif
#if ! defined key_benthos
       dc(iv_detr_tra_N(is))=dc(iv_detr_tra_N(is))+txfiltbenthij*ibbenth/epn* &
                              (c(iv_phyto_diat_tra_N(is))+c(iv_phyto_dino_tra_N(is))+c(iv_phyto_nano_tra_N(is)))
#ifdef key_phaeocystis
       dc(iv_detr_tra_N(is))=dc(iv_detr_tra_N(is))+txfiltbenthij*ibbenth/epn*c(iv_phyto_phaeocystis_cell_tra_N(is))
#endif
#ifdef key_psnz
       dc(iv_detr_tra_N(is))=dc(iv_detr_tra_N(is))+txfiltbenthij*ibbenth/epn*c(iv_phyto_psnz_tra_N(is))
#endif	 
#ifdef key_karenia
       dc(iv_detr_tra_N(is))=dc(iv_detr_tra_N(is))+txfiltbenthij*ibbenth/epn*c(iv_phyto_karenia_tra_N(is)) 
#endif      
#ifdef key_ulvas
       dc(iv_detr_tra_N(is))=dc(iv_detr_tra_N(is))+ulvebenthmortsed*c(iv_ulv_benth_tra_N(is))*ibbenth/epn/0.014_rsh
#endif
#endif

#ifdef key_age_tracer
       dc(iv_detr_age_tra_N(is))=c(iv_detr_tra_N(is))  &
               +diatmorteau*c(iv_phyto_diat_age_tra_N(is))+dinomorteau*c(iv_phyto_dino_age_tra_N(is)) &
                                                           +nanomorteau*c(iv_phyto_nano_age_tra_N(is))    &           
               -reminazdeteau*c(iv_detr_age_tra_N(is)) &
               + txmortmesozoo*c(iv_zoo_meso_age_tra_N(is))+txmortmicrozoo*c(iv_zoo_micr_age_tra_N(is))       &  
               +(1.0_rsh-assimilmesozoo)*c(iv_zoo_meso_N)*(broumesozoodiat*signature_N(iv_phyto_diat_tra_N(is)) &
                                                            *age_N(iv_phyto_diat_age_tra_N(is))  &
                                                          +broumesozoodino*signature_N(iv_phyto_dino_tra_N(is)) &
                                                            *age_N(iv_phyto_dino_age_tra_N(is))   &
                                                          +broumesozoomicrozoo*signature_N(iv_zoo_micr_tra_N(is)) &
                                                            *age_N(iv_zoo_micr_age_tra_N(is)))  &
               +(1.0_rsh-assimilmicrozoo)*c(iv_zoo_micr_N)*(broumicrozoonano*signature_N(iv_phyto_nano_tra_N(is)) &
                                                            *age_N(iv_phyto_nano_age_tra_N(is))  &
                                                           +broumicrozoodiat*signature_N(iv_phyto_diat_tra_N(is)) &
                                                            *age_N(iv_phyto_diat_age_tra_N(is))  &
                                                           +broumicrozoodet*signature_N(iv_detr_tra_N(is)) &
                                                            *age_N(iv_detr_age_tra_N(is)))              &
               -broumicrozoodet*c(iv_zoo_micr_N)*signature_N(iv_detr_tra_N(is))*age_N(iv_detr_age_tra_N(is))                                                     
#ifdef key_phaeocystis
        dc(iv_detr_age_tra_N(is))=dc(iv_detr_age_tra_N(is))  &
            +(1.0_rsh-assimilmesozoo)*c(iv_zoo_meso_N)*broumesozoophaeocolo &
                        *signature_N(iv_phyto_phaeocystis_colo_tra_N(is))*age_N(iv_phyto_phaeocystis_colo_age_tra_N(is)) &
            +(1.0_rsh-assimilmicrozoo)*c(iv_zoo_micr_N)*broumicrozoophaeocell &
                        *signature_N(iv_phyto_phaeocystis_cell_tra_N(is))*age_N(iv_phyto_phaeocystis_cell_age_tra_N(is)) &
            +(phaeocystislysecolo+phaeocystismortcolo)*c(iv_phyto_phaeocystis_colo_age_tra_N(is))+  &
              phaeocystismortcell*c(iv_phyto_phaeocystis_cell_age_tra_N(is))
#endif
#ifdef key_psnz
        dc(iv_detr_age_tra_N(is))=dc(iv_detr_age_tra_N(is))  &
           +((1.0_rsh-assimilmesozoo)*c(iv_zoo_meso_N)*broumesozoopsnz+       &
           +(1.0_rsh-assimilmicrozoo)*c(iv_zoo_micr_N)*broumicrozoopsnz)   &
                          *signature_N(iv_phyto_psnz_tra_N(is))*age_N(iv_phyto_psnz_age_tra_N(is))       &
           + psnzmorteau*c(iv_phyto_psnz_age_tra_N(is))
#endif	 
#ifdef key_karenia
        dc(iv_detr_age_tra_N(is))=dc(iv_detr_age_tra_N(is))  &
           +(1.0_rsh-assimilmesozoo)*c(iv_zoo_meso_N)*broumesozookarenia  &
                          *signature_N(iv_phyto_karenia_tra_N(is))*age_N(iv_phyto_karenia_age_tra_N(is))  &
           + kareniamorteau*c(iv_phyto_karenia_age_tra_N(is))
#endif
#ifdef key_ulvas
        dc(iv_detr_age_tra_N(is))=dc(iv_detr_age_tra_N(is))+ulvemorteau*c(iv_ulv_sus_age_tra_N(is))/0.014_rsh
#endif

#ifdef key_benthos
        dc(iv_detr_age_tra_N(is))=dc(iv_detr_age_tra_N(is))+  &
                            (detresuspazote*signature_N(iv_benth_tra_N(is))*age_N(iv_benth_age_tra_N(is))  &
                                 -vitessechutedet*c(iv_detr_age_tra_N(is)))*ibbenth/epn
#endif
#if ! defined key_benthos
       dc(iv_detr_age_tra_N(is))=dc(iv_detr_age_tra_N(is)) +txfiltbenthij*ibbenth/epn* &
                           (c(iv_phyto_diat_age_tra_N(is))+c(iv_phyto_dino_age_tra_N(is))+c(iv_phyto_nano_age_tra_N(is)))
#ifdef key_phaeocystis
       dc(iv_detr_age_tra_N(is))=dc(iv_detr_age_tra_N(is))+txfiltbenthij*ibbenth/epn*c(iv_phyto_phaeocystis_cell_age_tra_N(is))
#endif
#ifdef key_psnz
       dc(iv_detr_age_tra_N(is))=dc(iv_detr_age_tra_N(is))+txfiltbenthij*ibbenth/epn*c(iv_phyto_psnz_age_tra_N(is))
#endif	 
#ifdef key_karenia
       dc(iv_detr_age_tra_N(is))=dc(iv_detr_age_tra_N(is))+txfiltbenthij*ibbenth/epn*c(iv_phyto_karenia_age_tra_N(is)) 
#endif      
#ifdef key_ulvas
       dc(iv_detr_age_tra_N(is))=dc(iv_detr_age_tra_N(is))+ulvebenthmortsed*c(iv_ulv_benth_age_tra_N(is))*ibbenth/epn/0.014_rsh
#endif
#endif
#endif     

#ifdef key_benthos
   ! Evolution de l azote organique benthique marque  (mmol.m-2.jour-1)
   ! -------------------------------------------------------------------
   ! modif 2015 : rajout chute des diatomees
       dc(iv_benth_tra_N(is))=ibbenth*(vitessechutedet*c(iv_detr_tra_N(is))+vitessechutediat*c(iv_phyto_diat_tra_N(is))  &
                    -detresuspazote*signature_N(iv_benth_tra_N(is)) &
                    -(reminazdeteau*p_reminbenth+p_burial)*c(iv_benth_tra_N(is))   &
                    +txfiltbenthij*(c(iv_phyto_diat_tra_N(is))+c(iv_phyto_dino_tra_N(is))+c(iv_phyto_nano_tra_N(is))))
       dc(iv_phyto_diat_tra_N(is))=dc(iv_phyto_diat_tra_N(is))-ibbenth*(vitessechutediat*c(iv_phyto_diat_tra_N(is)))/epn

#if defined key_psnz
       dc(iv_benth_tra_N(is))=dc(iv_benth_tra_N(is))+txfiltbenthij*ibbenth*c(iv_phyto_psnz_tra_N(is))
#endif
#if defined key_karenia
       dc(iv_benth_tra_N(is))=dc(iv_benth_tra_N(is))+txfiltbenthij*ibbenth*c(iv_phyto_karenia_tra_N(is))
#endif
#ifdef key_phaeocystis
       dc(iv_benth_tra_N(is))=dc(iv_benth_tra_N(is))+txfiltbenthij*ibbenth*c(iv_phyto_phaeocystis_cell_tra_N(is))
#endif
#ifdef key_ulvas
       dc(iv_benth_tra_N(is))=dc(iv_benth_tra_N(is))+ulvebenthmortsed*c(iv_ulv_benth_tra_N(is))*ibbenth/0.014_rsh
#endif

#ifdef key_age_tracer
       dc(iv_benth_age_tra_N(is))=c(iv_benth_tra_N(is))   &
                     +ibbenth*(vitessechutedet*c(iv_detr_age_tra_N(is))+vitessechutediat*c(iv_phyto_diat_age_tra_N(is))  &
                     -detresuspazote*signature_N(iv_benth_tra_N(is))*age_N(iv_benth_age_tra_N(is)) &
                     -(reminazdeteau*p_reminbenth+p_burial)*c(iv_benth_age_tra_N(is))   &
                     +txfiltbenthij*(c(iv_phyto_diat_age_tra_N(is))+c(iv_phyto_dino_age_tra_N(is))+c(iv_phyto_nano_age_tra_N(is))))
       dc(iv_phyto_diat_age_tra_N(is))=dc(iv_phyto_diat_age_tra_N(is))-ibbenth*(vitessechutediat*c(iv_phyto_diat_age_tra_N(is)))/epn

#if defined key_psnz
       dc(iv_benth_age_tra_N(is))=dc(iv_benth_age_tra_N(is))+txfiltbenthij*ibbenth*c(iv_phyto_psnz_age_tra_N(is))
#endif
#if defined key_karenia
       dc(iv_benth_age_tra_N(is))=dc(iv_benth_age_tra_N(is))+txfiltbenthij*ibbenth*c(iv_phyto_karenia_age_tra_N(is))
#endif
#ifdef key_phaeocystis
       dc(iv_benth_age_tra_N(is))=dc(iv_benth_age_tra_N(is))+txfiltbenthij*ibbenth*c(iv_phyto_phaeocystis_cell_age_tra_N(is))
#endif
#ifdef key_ulvas
       dc(iv_benth_age_tra_N(is))=dc(iv_benth_age_tra_N(is))+ulvebenthmortsed*c(iv_ulv_benth_age_tra_N(is))*ibbenth/0.014_rsh
#endif
#endif     
#endif
   
  ! ++++++++++++++++++++++++++++++++++++++++++++++++
  !   ENREGISTREMENT VARIABLES DIAGNOSTIQUES
  ! ++++++++++++++++++++++++++++++++++++++++++++++++  
    DO ivtra=1,nb_var_tracerN 
       iv_tra=iv_tracer_N(ivtra,is)
       iv_sign=iv_signed_N(ivtra,is)
       id_sign=id_tracer_signN(ivtra,is)
       diag_3d_wat(id_sign,km,im,jm)=0.0_rsh
       IF (c(iv_sign).gt.seuil_N_tracer_diag) diag_3d_wat(id_sign,km,im,jm)=signature_N(iv_tra)
   ENDDO
#ifdef key_age_tracer  
   id_sign=id_sign+2
#else
   id_sign=id_sign+1
#endif
   diag_3d_wat(id_sign,km,im,jm)=c(iv_phyto_diat_tra_N(is))+c(iv_phyto_dino_tra_N(is))+c(iv_phyto_nano_tra_N(is))
   Nphytototal=c(iv_phyto_diat_N)+c(iv_phyto_dino_N)+c(iv_phyto_nano_N)

#ifdef key_karenia
   diag_3d_wat(id_sign,km,im,jm)=diag_3d_wat(id_sign,km,im,jm)+c(iv_phyto_karenia_tra_N(is))
   Nphytototal=Nphytototal+c(iv_phyto_karenia_N)
#endif
#ifdef key_phaeocystis
   diag_3d_wat(id_sign,km,im,jm)=diag_3d_wat(id_sign,km,im,jm)+ &
                                  c(iv_phyto_phaeocystis_colo_tra_N(is))+c(iv_phyto_phaeocystis_cell_tra_N(is))
   Nphytototal=Nphytototal+c(iv_phyto_phaeocystis_colo_N)+c(iv_phyto_phaeocystis_cell_N)
#endif
#ifdef key_psnz
   diag_3d_wat(id_sign,km,im,jm)=diag_3d_wat(id_sign,km,im,jm)+c(iv_phyto_psnz_tra_N(is))
   Nphytototal=Nphytototal+c(iv_phyto_psnz_N)
#endif
   phytototal_tra_N=diag_3d_wat(id_sign,km,im,jm)
   IF (Nphytototal.gt.seuil_N_tracer_diag) THEN
     diag_3d_wat(id_sign,km,im,jm)=diag_3d_wat(id_sign,km,im,jm)/(Nphytototal)
   ELSE
     diag_3d_wat(id_sign,km,im,jm)=0.0_rsh
   ENDIF
   
#ifdef key_age_tracer
   age_max=(t-tdeb_tracerN)/86400.0_rlg
   DO ivtra=1,nb_var_tracerN 
       iv_tra=iv_tracer_N(ivtra,is)
       iv_sign=iv_signed_N(ivtra,is)
       id_sign=id_tracer_ageN(ivtra,is)
       ivage=iv_age_N(ivtra,is)
       !IF (signature_N(iv_tra) .GT. seuil_N_age_tracer_phytot) THEN
       IF (age_N(ivage)==0.0_rsh) THEN
          diag_3d_wat(id_sign,km,im,jm)=-1.0_rsh
       ELSE IF (age_N(ivage) > age_max) THEN
          diag_3d_wat(id_sign,km,im,jm)=-1.0_rsh
       ELSE
          diag_3d_wat(id_sign,km,im,jm)=age_N(ivage)
       ENDIF
   ENDDO  
   id_sign=id_sign+2
   diag_3d_wat(id_sign,km,im,jm)=c(iv_phyto_diat_age_tra_N(is))+c(iv_phyto_dino_age_tra_N(is))+c(iv_phyto_nano_age_tra_N(is))
 
#ifdef key_karenia
   diag_3d_wat(id_sign,km,im,jm)=diag_3d_wat(id_sign,km,im,jm)+c(iv_phyto_karenia_age_tra_N(is))
#endif
#ifdef key_phaeocystis
   diag_3d_wat(id_sign,km,im,jm)=diag_3d_wat(id_sign,km,im,jm)+  &
                                   c(iv_phyto_phaeocystis_colo_age_tra_N(is))+c(iv_phyto_phaeocystis_cell_age_tra_N(is))
#endif
#ifdef key_psnz
   diag_3d_wat(id_sign,km,im,jm)=diag_3d_wat(id_sign,km,im,jm)+c(iv_phyto_psnz_age_tra_N(is))
#endif
   !if (phytototal_tra_N.gt.1.e-4_rsh)  THEN
   IF (diag_3d_wat(id_sign-1,km,im,jm) > seuil_N_age_tracer_phytot) THEN
      diag_3d_wat(id_sign,km,im,jm)=diag_3d_wat(id_sign,km,im,jm)/phytototal_tra_N  
   ELSE
      diag_3d_wat(id_sign,km,im,jm)= -1.0_rsh  
   ENDIF
#endif

   ENDDO
         
         
   END SUBROUTINE  incellwat_nitrogentracer
#endif
   !!======================================================================
#if defined key_P_tracer
  SUBROUTINE incellwat_phosphoretracer(km,im,jm,xe,c,dc,  &
             adsorpeau,desorpeau )
 
   !&E---------------------------------------------------------------------
   !&E                 ***  ROUTINE incellwat_phosphoretracer  ***
   !&E
   !&E ** Purpose : Tracage dans l ecosysteme du phosphore emis par une source
   !&E
   !&E ** Description :
   !&E
   !&E ** Called by :  incellwat_nut4phy3zoo2
   !&E
   !&E ** External calls :
   !&E
   !&E ** Reference :
   !&E
   !&E ** History :
   !&E       !  2010-03    (A. Menesguen ) Original code
   !&E       !  ???????    (  )  evolutions
   !&E
   !&E---------------------------------------------------------------------
   !! * Modules used

   USE parameters, ONLY : nb_var_tracerP
   USE comsubstance, ONLY : attenuation,extinction,alumplafond,name_var
   USE bioloinit, ONLY : tdeb_tracerP
        
   !! * Arguments
   INTEGER, INTENT(in)                       :: km,im,jm      ! ocean spatial-step index
   REAL(KIND=rsh),INTENT(in)                 :: xe            ! ssh
   REAL(KIND=rsh),DIMENSION(:),INTENT(in)    :: c
   REAL(KIND=rsh),DIMENSION(:),INTENT(inout) :: dc
   REAL(KIND=rsh),INTENT(in)                 :: adsorpeau,desorpeau
                                                    
            
   !! * Local declarations
   INTEGER                                   :: is,ivtra,iv_tra,iv_sign,id_sign,ivage
   REAL(KIND=rlg),DIMENSION(nv_state)        :: signature_P,age_P 
   REAL(KIND=rlg)                            :: age_max 
   REAL(KIND=rsh)                            :: Pphytototal,phytototal_tra_P
   REAL (KIND=rsh), PARAMETER                :: seuil_N_tracer=1.e-6_rsh,seuil_N_age_tracer=0.01_rsh
   REAL (KIND=rsh), PARAMETER                :: seuil_N_tracer_diag=5.e-4_rsh,seuil_N_age_tracer_phytot=0.02_rsh 
   REAL (KIND=rsh)                           :: seuil_P_tracer,seuil_P_age_tracer,seuil_P_tracer_diag,seuil_P_age_tracer_phytot

   seuil_P_tracer=seuil_N_tracer/p_phyto_NPratio
   seuil_P_age_tracer=seuil_N_age_tracer/p_phyto_NPratio
   seuil_P_tracer_diag=seuil_N_tracer_diag/p_phyto_NPratio*0.5_rsh
   seuil_P_age_tracer_phytot=seuil_N_age_tracer_phytot

   !!REAL(kind=rsh)  ,PARAMETER                :: epsil=0.0000001_rsh
   !!----------------------------------------------------------------------
   !! * Executable part

   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
   ! saisir le code apres cette limite
   ! =================================
   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

   ! Calcul de la fraction de traceur dans les variables phophorees  (s.u)
   ! ------------------------------------------------------------
   DO is=1,nb_source_tracerP
      DO ivtra=1,nb_var_tracerP 
        iv_tra=iv_tracer_P(ivtra,is)
        signature_P(iv_tra)=0.0_rsh
        iv_sign=iv_signed_P(ivtra,is)
        IF (c(iv_sign).gt.seuil_P_tracer) signature_P(iv_tra)=c(iv_tra)/c(iv_sign)
        IF (signature_P(iv_tra).gt.100.0_rsh) print*,'im=',im,'jm=',jm,'km=',km, &
                     'signature_P',TRIM(ADJUSTL(ADJUSTR(name_var(isubs_tracer_P(ivtra,is))))),signature_P(iv_tra)

#ifdef key_age_tracer
   ! Calcul des ages du traceur dans les variables phosphorees  (jours)
   ! ----------------------------------------------------------------
        ivage=iv_age_P(ivtra,is)
        age_P(ivage)=0.0_rsh
       ! IF (c(iv_tra).gt.1.e-6_rsh) age_P(ivage)=c(ivage)c(iv_tra)
        IF (signature_P(iv_tra) .GT. seuil_P_age_tracer) age_P(ivage)=c(ivage)/c(iv_tra)
#endif
      ENDDO
   
       
   ! Evolution de variables traceurs marques (micromoles/L P)
   ! -------------------------------------------------
   ! Evolution du phosphate marque dissous
      dc(iv_nutr_PO4_tra_P(is))=desorpeau*c(iv_nutr_Pads_tra_P(is))            &
                     -adsorpeau*c(iv_nutr_PO4_tra_P(is))             &
                     -rappaz*(rationdiat*c(iv_phyto_diat_N)+rationdino*c(iv_phyto_dino_N)+  &
                              rationnano*c(iv_phyto_nano_N))*signature_P(iv_nutr_PO4_tra_P(is)) &
                     +excretionmesozoo*c(iv_zoo_meso_tra_P(is))+excretionmicrozoo*c(iv_zoo_micr_tra_P(is))    &
                     +reminpdeteau*c(iv_detr_tra_P(is))
 
#ifdef key_karenia
      dc(iv_nutr_PO4_tra_P(is))=dc(iv_nutr_PO4_tra_P(is))- &
                     rationkarenia*c(iv_phyto_karenia_C)*signature_P(iv_nutr_PO4_tra_P(is))/(p_phyto_NPratio*p_phyto_CNratio)
#endif
#ifdef key_phaeocystis
      dc(iv_nutr_PO4_tra_P(is))=dc(iv_nutr_PO4_tra_P(is))-(rationphaeocystiscolo*c(iv_phyto_phaeocystis_colo_N)    &
                    +rationphaeocystiscell*c(iv_phyto_phaeocystis_cell_N))*signature_P(iv_nutr_PO4_tra_P(is))*rappaz
#endif
#ifdef key_psnz
      dc(iv_nutr_PO4_tra_P(is))=dc(iv_nutr_PO4_tra_P(is))-rationpsnz*c(iv_phyto_psnz_N)*signature_P(iv_nutr_PO4_tra_P(is))*rappaz
#endif
#ifdef key_benthos
      dc(iv_nutr_PO4_tra_P(is))=dc(iv_nutr_PO4_tra_P(is))+reminpdeteau*p_reminbenth*c(iv_benth_tra_P(is))*ibbenth/epn
#endif

#ifdef key_age_tracer
      dc(iv_nutr_PO4_age_tra_P(is))=c(iv_nutr_PO4_tra_P(is)) &
                     +desorpeau*c(iv_nutr_Pads_age_tra_P(is))-adsorpeau*c(iv_nutr_PO4_age_tra_P(is))      &
                     -rappaz*(rationdiat*c(iv_phyto_diat_N)+rationdino*c(iv_phyto_dino_N)+rationnano*c(iv_phyto_nano_N))  &
                             *signature_P(iv_nutr_PO4_tra_P(is))*age_P(iv_nutr_PO4_age_tra_P(is)) &
                     +excretionmesozoo*c(iv_zoo_meso_age_tra_P(is))+excretionmicrozoo*c(iv_zoo_micr_age_tra_P(is))       &
                     +reminpdeteau*c(iv_detr_age_tra_P(is))
#ifdef key_karenia
      dc(iv_nutr_PO4_age_tra_P(is))=dc(iv_nutr_PO4_age_tra_P(is))-rationkarenia*c(iv_phyto_karenia_C) &
                     *signature_P(iv_nutr_PO4_tra_P(is))*age_P(iv_nutr_PO4_age_tra_P(is))/(p_phyto_NPratio*p_phyto_CNratio)   
#endif
#ifdef key_phaeocystis
      dc(iv_nutr_PO4_age_tra_P(is))=dc(iv_nutr_PO4_age_tra_P(is))-(rationphaeocystiscolo*c(iv_phyto_phaeocystis_colo_N)    &
                       +rationphaeocystiscell*c(iv_phyto_phaeocystis_cell_N))  &
                       *signature_P(iv_nutr_PO4_tra_P(is))*age_P(iv_nutr_PO4_age_tra_P(is))*rappaz
#endif
#ifdef key_psnz
      dc(iv_nutr_PO4_age_tra_P(is))=dc(iv_nutr_PO4_age_tra_P(is))  &
                       -rationpsnz*c(iv_phyto_psnz_N)*signature_P(iv_nutr_PO4_tra_P(is))*age_P(iv_nutr_PO4_age_tra_P(is))*rappaz
#endif
#ifdef key_benthos
      dc(iv_nutr_PO4_age_tra_P(is))=dc(iv_nutr_PO4_age_tra_P(is))+reminpdeteau*p_reminbenth*c(iv_benth_age_tra_P(is))*ibbenth/epn
#endif
#endif
   
   ! Evolution du phosphore marque adsorbe
   ! --------------------------------------
       dc(iv_nutr_Pads_tra_P(is))=adsorpeau*c(iv_nutr_PO4_tra_P(is))-desorpeau*c(iv_nutr_Pads_tra_P(is))

#ifdef key_age_tracer
       dc(iv_nutr_Pads_age_tra_P(is))=adsorpeau*c(iv_nutr_PO4_age_tra_P(is))-desorpeau*c(iv_nutr_Pads_age_tra_P(is))
#endif
   
   ! Evolution du phophore marque via l azote marque des diatomees  (micromoles/L P)
   ! -------------------------------------------------------------
       dc(iv_phyto_diat_tra_P(is))=rationdiat*c(iv_phyto_diat_N)*rappaz*signature_P(iv_nutr_PO4_tra_P(is))  &
                     -(diatmorteau+txfiltbenthij*ibbenth/epn)*c(iv_phyto_diat_tra_P(is))    &
                     -(broumesozoodiat*c(iv_zoo_meso_N)+broumicrozoodiat*c(iv_zoo_micr_N)) &
                          *rappaz*signature_P(iv_phyto_diat_tra_P(is))

#ifdef key_age_tracer
  !     dc(iv_phyto_diat_age_tra_P(is))=c(iv_phyto_diat_age_tra_P(is))  &
       dc(iv_phyto_diat_age_tra_P(is))=c(iv_phyto_diat_tra_P(is))  &
                      +rationdiat*c(iv_phyto_diat_N)*rappaz*signature_P(iv_nutr_PO4_tra_P(is))*age_P(iv_nutr_PO4_age_tra_P(is)) &
                     -(diatmorteau+txfiltbenthij*ibbenth/epn)*c(iv_phyto_diat_age_tra_P(is))    &
                     -(broumesozoodiat*c(iv_zoo_meso_N)+broumicrozoodiat*c(iv_zoo_micr_N))  &
                           *rappaz*signature_P(iv_phyto_diat_tra_P(is))*age_P(iv_phyto_diat_age_tra_P(is))
#endif
   
   ! Evolution du phophore marque via l azote marque des dinoflagelles  (micromoles/L P)
   ! -----------------------------------------------------------------
       dc(iv_phyto_dino_tra_P(is))=rationdino*c(iv_phyto_dino_N)*rappaz*signature_P(iv_nutr_PO4_tra_P(is))  &
                     -(dinomorteau+txfiltbenthij*ibbenth/epn)*c(iv_phyto_dino_tra_P(is))  &
                       -broumesozoodino*c(iv_zoo_meso_N)*signature_P(iv_phyto_dino_tra_P(is))*rappaz

#ifdef key_age_tracer  
       dc(iv_phyto_dino_age_tra_P(is))=c(iv_phyto_dino_tra_P(is))  &
                       +rationdino*c(iv_phyto_dino_N)*rappaz*signature_P(iv_nutr_PO4_tra_P(is))*age_P(iv_nutr_PO4_age_tra_P(is)) &
                       -(dinomorteau+txfiltbenthij*ibbenth/epn)*c(iv_phyto_dino_age_tra_P(is))   &
                       -broumesozoodino*c(iv_zoo_meso_N) &
                             *rappaz*signature_P(iv_phyto_dino_tra_P(is))*age_P(iv_phyto_dino_age_tra_P(is))
#endif
   
   ! Evolution du phophore marque via l azote marque des nanoflagelles  (micromoles/L P)
   ! -----------------------------------------------------------------
       dc(iv_phyto_nano_tra_P(is))=rationnano*c(iv_phyto_nano_N)*rappaz*signature_P(iv_nutr_PO4_tra_P(is))  & 
                   -(nanomorteau+txfiltbenthij*ibbenth/epn)*c(iv_phyto_nano_tra_P(is)) &
                    -broumicrozoonano*c(iv_zoo_micr_N)*rappaz*signature_P(iv_phyto_nano_tra_P(is))

#ifdef key_age_tracer  
       dc(iv_phyto_nano_age_tra_P(is))=c(iv_phyto_nano_tra_P(is))  &
                       +rationnano*c(iv_phyto_nano_N)*rappaz*signature_P(iv_nutr_PO4_tra_P(is))*age_P(iv_nutr_PO4_age_tra_P(is)) &
                        -(nanomorteau+txfiltbenthij*ibbenth/epn)*c(iv_phyto_nano_age_tra_P(is))   &
                        -broumicrozoonano*c(iv_zoo_micr_N)  &
                             *rappaz*signature_P(iv_phyto_nano_tra_P(is))*age_P(iv_phyto_nano_age_tra_P(is))
#endif
      
#ifdef key_karenia

   ! Evolution du phophore marque via l azote marque de Karenia mikimotoi (micromoles/L P)
   ! ---------------------------------------------------------------   
       dc(iv_phyto_karenia_tra_P(is))= uptakeN*c(iv_phyto_karenia_C)*rappaz*signature_P(iv_nutr_PO4_tra_P(is))  &
                           -(kareniamorteau+txfiltbenthij*ibbenth/epn)*c(iv_phyto_karenia_tra_P(is))  &
                            -broumesozookarenia*c(iv_zoo_meso_N)*rappaz*signature_P(iv_phyto_karenia_tra_P(is))
#ifdef key_age_tracer
       dc(iv_phyto_karenia_age_tra_P(is))=c(iv_phyto_karenia_tra_P(is))   &
                      +uptakeN*c(iv_phyto_karenia_C)*rappaz*signature_P(iv_nutr_PO4_tra_P(is))*age_P(iv_nutr_PO4_age_tra_P(is)) &
                      -(kareniamorteau+txfiltbenthij*ibbenth/epn)*c(iv_phyto_karenia_age_tra_P(is))   &
                      -broumesozookarenia*c(iv_zoo_meso_N)  &
                           *rappaz*signature_P(iv_phyto_karenia_tra_P(is))*age_P(iv_phyto_karenia_age_tra_P(is))
#endif
#endif

#ifdef key_phaeocystis

   ! Evolution du phophore marque via l azote marque des colonies de Phaeocystis globosa (micromoles/L P)
   ! ----------------------------------------------------------------------------------
       dc(iv_phyto_phaeocystis_colo_tra_P(is))=rationphaeocystiscolo*c(iv_phyto_phaeocystis_colo_N) &
                                                 *rappaz*signature_P(iv_nutr_PO4_tra_P(is))  & 
                                -(phaeocystismortcolo+phaeocystislysecolo)*c(iv_phyto_phaeocystis_colo_tra_P(is))   &
                                  -broumesozoophaeocolo*c(iv_zoo_meso_N)  &
                                                  *rappaz*signature_P(iv_phyto_phaeocystis_colo_tra_P(is)) &
                                +initcolonie*c(iv_phyto_phaeocystis_cell_tra_P(is))
#ifdef key_age_tracer
       dc(iv_phyto_phaeocystis_colo_age_tra_P(is))=c(iv_phyto_phaeocystis_colo_tra_P(is))  &
                      +rationphaeocystiscolo*c(iv_phyto_phaeocystis_colo_N) &
                                               *rappaz*signature_P(iv_nutr_PO4_tra_P(is))*age_P(iv_nutr_PO4_age_tra_P(is))  & 
                      -(phaeocystismortcolo+phaeocystislysecolo)*c(iv_phyto_phaeocystis_colo_age_tra_P(is))   &
                      -broumesozoophaeocolo*c(iv_zoo_meso_N)*rappaz*signature_P(iv_phyto_phaeocystis_colo_tra_P(is))   &
                         *age_P(iv_phyto_phaeocystis_colo_age_tra_P(is))+initcolonie*c(iv_phyto_phaeocystis_cell_age_tra_P(is))
#endif

   ! Evolution du phophore marque via l azote marque des cellules libres de Phaeocystis globosa (micromoles/L P)
   ! -----------------------------------------------------------------------------------------
       dc(iv_phyto_phaeocystis_cell_tra_P(is))=rationphaeocystiscell*c(iv_phyto_phaeocystis_cell_N) &
                                                             *rappaz*signature_P(iv_nutr_PO4_tra_P(is))    & 
                     -(phaeocystismortcell+txfiltbenthij*ibbenth/epn)*c(iv_phyto_phaeocystis_cell_tra_P(is))   &
                     -broumicrozoophaeocell*c(iv_zoo_micr_N)*rappaz*signature_P(iv_phyto_phaeocystis_cell_tra_P(is)) &
                     -initcolonie*c(iv_phyto_phaeocystis_cell_tra_P(is))
#ifdef key_age_tracer
      dc(iv_phyto_phaeocystis_cell_age_tra_P(is))=c(iv_phyto_phaeocystis_cell_tra_P(is))  &
                      +rationphaeocystiscell*c(iv_phyto_phaeocystis_cell_N) &
                                           *rappaz*signature_P(iv_nutr_PO4_tra_P(is))*age_P(iv_nutr_PO4_age_tra_P(is))    & 
                      -(phaeocystismortcell+txfiltbenthij*ibbenth/epn)*c(iv_phyto_phaeocystis_cell_age_tra_P(is))   &
                      -broumicrozoophaeocell*c(iv_zoo_micr_N)*rappaz*signature_P(iv_phyto_phaeocystis_cell_tra_P(is))    &
                       *age_P(iv_phyto_phaeocystis_cell_age_tra_P(is))-initcolonie*c(iv_phyto_phaeocystis_cell_age_tra_P(is))
#endif
#endif

#ifdef key_psnz

   ! Evolution du phophore marque via l azote marque des Pseudo-Nitzschia (micromoles/L P)
   ! -------------------------------------------------------------------
       dc(iv_phyto_psnz_tra_P(is))=rationpsnz*c(iv_phyto_psnz_N)*rappaz*signature_P(iv_nutr_PO4_tra_P(is))  &
                     -(psnzmorteau+txfiltbenthij*ibbenth/epn)*c(iv_phyto_psnz_tra_P(is))   &
                     -(broumicrozoopsnz*c(iv_zoo_micr_N)+broumesozoopsnz*c(iv_zoo_meso_N)) &
                                  *rappaz*signature_P(iv_phyto_psnz_tra_P(is))
#ifdef key_age_tracer
       dc(iv_phyto_psnz_age_tra_P(is))=c(iv_phyto_psnz_tra_P(is))  &
                       +rationpsnz*c(iv_phyto_psnz_N) &
                          *rappaz*signature_P(iv_nutr_PO4_tra_P(is))*age_P(iv_nutr_PO4_age_tra_P(is))  &
                      -(psnzmorteau+txfiltbenthij*ibbenth/epn)*c(iv_phyto_psnz_age_tra_P(is))  &
                      -(broumicrozoopsnz*c(iv_zoo_micr_N)+broumesozoopsnz*c(iv_zoo_meso_N)) &
                          *rappaz*signature_P(iv_phyto_psnz_tra_P(is))*age_P(iv_phyto_psnz_age_tra_P(is))
#endif
#endif

   ! Evolution du phophore marque via l azote marque du microzooplancton (micromoles/L P)
   ! ------------------------------------------------------------------  
      dc(iv_zoo_micr_tra_P(is))=assimilmicrozoo*c(iv_zoo_micr_N) &
                             *rappaz*(broumicrozoonano*signature_P(iv_phyto_nano_tra_P(is))  &
                                     +broumicrozoodiat*signature_P(iv_phyto_diat_tra_P(is))  &
                                    + broumicrozoodet*signature_P(iv_detr_tra_P(is)))         &
                                   -(excretionmicrozoo+txmortmicrozoo)*c(iv_zoo_micr_tra_P(is))   &
                                  - broumesozoomicrozoo*c(iv_zoo_meso_N)*rappaz*signature_P(iv_zoo_micr_tra_P(is))

#ifdef key_phaeocystis
      dc(iv_zoo_micr_tra_P(is))=dc(iv_zoo_micr_tra_P(is)) + assimilmicrozoo*c(iv_zoo_micr_N) &
                                  *rappaz*broumicrozoophaeocell*signature_P(iv_phyto_phaeocystis_cell_tra_P(is))
#endif
#ifdef key_psnz
      dc(iv_zoo_micr_tra_P(is))=dc(iv_zoo_micr_tra_P(is)) + assimilmicrozoo*c(iv_zoo_micr_N) &
                                  *rappaz*broumicrozoopsnz*signature_P(iv_phyto_psnz_tra_P(is))
#endif

#ifdef key_age_tracer
      dc(iv_zoo_micr_age_tra_P(is))=c(iv_zoo_micr_tra_P(is)) +assimilmicrozoo*c(iv_zoo_micr_N) &
                       *rappaz*(broumicrozoonano*signature_P(iv_phyto_nano_tra_P(is))*age_P(iv_phyto_nano_age_tra_P(is))  &
                               +broumicrozoodiat*signature_P(iv_phyto_diat_tra_P(is))*age_P(iv_phyto_diat_age_tra_P(is))  &
                               +broumicrozoodet*signature_P(iv_detr_tra_P(is))*age_P(iv_detr_age_tra_P(is)))   &
                       -(excretionmicrozoo+txmortmicrozoo)*c(iv_zoo_micr_age_tra_P(is))  &
                       - broumesozoomicrozoo*c(iv_zoo_meso_N)* &
                              rappaz*signature_P(iv_zoo_micr_tra_P(is))*age_P(iv_zoo_micr_age_tra_P(is))
#ifdef key_phaeocystis
       dc(iv_zoo_micr_age_tra_P(is))=dc(iv_zoo_micr_age_tra_P(is)) + assimilmicrozoo*c(iv_zoo_micr_N)  &
                   *rappaz*broumicrozoophaeocell*signature_P(iv_phyto_phaeocystis_cell_tra_P(is)) &
                                   *age_P(iv_phyto_phaeocystis_cell_age_tra_P(is))
#endif
#ifdef key_psnz
       dc(iv_zoo_micr_age_tra_P(is))=dc(iv_zoo_micr_age_tra_P(is))+ assimilmicrozoo*c(iv_zoo_micr_N)  &
                   *rappaz*broumicrozoopsnz*signature_P(iv_phyto_psnz_tra_P(is))*age_P(iv_phyto_psnz_age_tra_P(is))
#endif
#endif

   ! Evolution du phophore marque via l azote marque du mesozooplancton (micromoles/L P)
   ! -----------------------------------------------------------------
       dc(iv_zoo_meso_tra_P(is))=assimilmesozoo*c(iv_zoo_meso_N) &
                   *rappaz*(broumesozoodiat*signature_P(iv_phyto_diat_tra_P(is))  &
                           +broumesozoodino*signature_P(iv_phyto_dino_tra_P(is))  &
                           +broumesozoomicrozoo*signature_P(iv_zoo_micr_tra_P(is)))   &
                          -(excretionmesozoo+txmortmesozoo)*c(iv_zoo_meso_tra_P(is))
#ifdef key_phaeocystis
       dc(iv_zoo_meso_tra_P(is))=dc(iv_zoo_meso_tra_P(is)) +assimilmesozoo*c(iv_zoo_meso_N) &
                   *rappaz*broumesozoophaeocolo*signature_P(iv_phyto_phaeocystis_colo_tra_P(is))
#endif
#ifdef key_psnz
       dc(iv_zoo_meso_tra_P(is))=dc(iv_zoo_meso_tra_P(is))+assimilmesozoo*c(iv_zoo_meso_N) &
                   *rappaz*broumesozoopsnz*signature_P(iv_phyto_psnz_tra_P(is))
#endif
#ifdef key_karenia
       dc(iv_zoo_meso_tra_P(is))=dc(iv_zoo_meso_tra_P(is))+assimilmesozoo*c(iv_zoo_meso_N) &
                   *rappaz*broumesozookarenia*signature_P(iv_phyto_karenia_tra_P(is))
#endif

#ifdef key_age_tracer
       dc(iv_zoo_meso_age_tra_P(is))=c(iv_zoo_meso_tra_P(is)) +assimilmesozoo*c(iv_zoo_meso_N) &
                   *rappaz*(broumesozoodiat*signature_P(iv_phyto_diat_tra_P(is))*age_P(iv_phyto_diat_age_tra_P(is))   &
                           +broumesozoodino*signature_P(iv_phyto_dino_tra_P(is))*age_P(iv_phyto_dino_age_tra_P(is))  &
                           +broumesozoomicrozoo*signature_P(iv_zoo_micr_tra_P(is))*age_P(iv_zoo_micr_age_tra_P(is)))   &
                           -(excretionmesozoo+txmortmesozoo)*c(iv_zoo_meso_age_tra_P(is))
#ifdef key_phaeocystis
       dc(iv_zoo_meso_age_tra_P(is))=dc(iv_zoo_meso_age_tra_P(is)) +assimilmesozoo*c(iv_zoo_meso_N) &
                   *rappaz*broumesozoophaeocolo*signature_P(iv_phyto_phaeocystis_colo_tra_P(is)) &
                            *age_P(iv_phyto_phaeocystis_colo_age_tra_P(is))
#endif
#ifdef key_psnz
       dc(iv_zoo_meso_age_tra_P(is))=dc(iv_zoo_meso_age_tra_P(is)) +assimilmesozoo*c(iv_zoo_meso_N)  &
                   *rappaz*broumesozoopsnz*signature_P(iv_phyto_psnz_tra_P(is))*age_P(iv_phyto_psnz_age_tra_P(is))
#endif
#ifdef key_karenia
       dc(iv_zoo_meso_age_tra_P(is))=dc(iv_zoo_meso_age_tra_P(is)) +assimilmesozoo*c(iv_zoo_meso_N)   &
                   *rappaz*broumesozookarenia*signature_P(iv_phyto_karenia_tra_P(is))*age_P(iv_phyto_karenia_age_tra_P(is))
#endif
#endif
   
   ! Evolution du phosphore detritique marque (micromoles/L P)
   ! ---------------------------------------------------------
         dc(iv_detr_tra_P(is))=diatmorteau*c(iv_phyto_diat_tra_P(is))                       &
                -broumicrozoodet*c(iv_zoo_micr_N)*signature_P(iv_detr_tra_P(is))*rNC*rappaz          &
                 -reminpdeteau*c(iv_detr_tra_P(is))                                                   &
                +(dinomorteau*c(iv_phyto_dino_tra_P(is))+nanomorteau*c(iv_phyto_nano_tra_P(is)))      &
                +((txmortmesozoo+(1.0_rsh-assimilmesozoo)*rationmesozoo)*c(iv_zoo_meso_N)*  &
                     (broumesozoodiat*signature_P(iv_phyto_diat_tra_P(is)) &
                     +broumesozoodino*signature_P(iv_phyto_dino_tra_P(is))  &
                     +broumesozoomicrozoo*signature_P(iv_zoo_micr_tra_P(is)))    &
                 +(txmortmicrozoo+(1.0_rsh-assimilmicrozoo)*rationmicrozoo)*c(iv_zoo_micr_N)* &
                     (broumicrozoonano*signature_P(iv_phyto_nano_tra_P(is)) &
                     +broumicrozoodiat*signature_P(iv_phyto_diat_tra_P(is)) &
                     +broumicrozoodet*signature_P(iv_detr_tra_P(is))))*rNC*rappaz
                                                     
#ifdef key_phaeocystis
       dc(iv_detr_tra_P(is))=dc(iv_detr_tra_P(is))+ (1.0_rsh-assimilmesozoo)*c(iv_zoo_meso_N) &
               *rappaz*broumesozoophaeocolo*signature_P(iv_phyto_phaeocystis_colo_tra_P(is))  &
                                                  + (1.0_rsh-assimilmicrozoo)*c(iv_zoo_micr_N)  &
                *rappaz*broumicrozoophaeocell*signature_P(iv_phyto_phaeocystis_cell_tra_P(is))  &
                   + (phaeocystislysecolo+phaeocystismortcolo)*c(iv_phyto_phaeocystis_colo_tra_P(is))+ &
                      phaeocystismortcell*c(iv_phyto_phaeocystis_cell_tra_P(is))
#endif
#ifdef key_psnz
       dc(iv_detr_tra_P(is))=dc(iv_detr_tra_P(is))+((1.0_rsh-assimilmesozoo)*c(iv_zoo_meso_N)*rappaz*broumesozoopsnz+       &
                                                   +(1.0_rsh-assimilmicrozoo)*c(iv_zoo_micr_N)*rappaz*broumicrozoopsnz)  &
                              *signature_P(iv_phyto_psnz_tra_P(is))+ psnzmorteau*c(iv_phyto_psnz_tra_P(is))
#endif	 
#ifdef key_karenia
       dc(iv_detr_tra_P(is))=dc(iv_detr_tra_P(is))+(1.0_rsh-assimilmesozoo)*c(iv_zoo_meso_N) &
                              *rappaz*broumesozookarenia*signature_P(iv_phyto_karenia_tra_P(is))       &
                              + kareniamorteau*c(iv_phyto_karenia_tra_P(is))
#endif
#ifdef key_benthos
       dc(iv_detr_tra_P(is))=dc(iv_detr_tra_P(is))-(-detresusppho*signature_P(iv_benth_tra_P(is))  &
                               +vitessechutedet*c(iv_detr_tra_P(is)))/epn
#endif
#if ! defined key_benthos
       dc(iv_detr_tra_P(is))=dc(iv_detr_tra_P(is))+  &
                        txfiltbenthij*ibbenth/epn*(c(iv_phyto_diat_tra_P(is))+c(iv_phyto_dino_tra_P(is))+c(iv_phyto_nano_tra_P(is)))
#ifdef key_phaeocystis
       dc(iv_detr_tra_P(is))=dc(iv_detr_tra_P(is))+ &
                        txfiltbenthij*ibbenth/epn*c(iv_phyto_phaeocystis_cell_tra_P(is))
#endif
#ifdef key_psnz
       dc(iv_detr_tra_P(is))=dc(iv_detr_tra_P(is))+txfiltbenthij*ibbenth/epn*c(iv_phyto_psnz_tra_P(is))
#endif	 
#ifdef key_karenia
       dc(iv_detr_tra_P(is))=dc(iv_detr_tra_P(is))+txfiltbenthij*ibbenth/epn*c(iv_phyto_karenia_tra_P(is)) 
#endif      
#endif

#ifdef key_age_tracer
        dc(iv_detr_age_tra_P(is))=c(iv_detr_tra_P(is))  &
               +diatmorteau*c(iv_phyto_diat_age_tra_P(is))    &
                -broumicrozoodet*c(iv_zoo_micr_N)*signature_P(iv_detr_tra_P(is))*age_P(iv_detr_age_tra_P(is))*rNC*rappaz   &
                -reminpdeteau*c(iv_detr_age_tra_P(is))                                                   &
                +(dinomorteau*c(iv_phyto_dino_age_tra_P(is))+nanomorteau*c(iv_phyto_nano_age_tra_P(is)))      &
                 +((txmortmesozoo+(1.0_rsh-assimilmesozoo)*rationmesozoo)*c(iv_zoo_meso_N)*  &
                      (broumesozoodiat*signature_P(iv_phyto_diat_tra_P(is))*age_P(iv_phyto_diat_age_tra_P(is))  &
                      +broumesozoodino*signature_P(iv_phyto_dino_tra_P(is))*age_P(iv_phyto_dino_age_tra_P(is))   &
                      +broumesozoomicrozoo*signature_P(iv_zoo_micr_tra_P(is))*age_P(iv_zoo_micr_age_tra_P(is)))  &   
                 +(txmortmicrozoo+(1.0_rsh-assimilmicrozoo)*rationmicrozoo)*c(iv_zoo_micr_N)*  &
                      (broumicrozoonano*signature_P(iv_phyto_nano_tra_P(is))*age_P(iv_phyto_nano_age_tra_P(is))  &
                      +broumicrozoodiat*signature_P(iv_phyto_diat_tra_P(is))*age_P(iv_phyto_diat_age_tra_P(is))  &
                      +broumicrozoodet*signature_P(iv_detr_tra_P(is))*age_P(iv_detr_age_tra_P(is)))) &
                       *rNC*rappaz
                                 
#ifdef key_phaeocystis
        dc(iv_detr_age_tra_P(is))=dc(iv_detr_age_tra_P(is))   &
           +(1.0_rsh-assimilmesozoo)*c(iv_zoo_meso_N)*rappaz &
                  *broumesozoophaeocolo*signature_P(iv_phyto_phaeocystis_colo_tra_P(is)) &
                            *age_P(iv_phyto_phaeocystis_colo_age_tra_P(is))  &
            +(1.0_rsh-assimilmicrozoo)*c(iv_zoo_micr_N)*rappaz*broumicrozoophaeocell  &
                  *signature_P(iv_phyto_phaeocystis_cell_tra_P(is))*age_P(iv_phyto_phaeocystis_cell_age_tra_P(is))  & 
            + (phaeocystislysecolo+phaeocystismortcolo)*c(iv_phyto_phaeocystis_colo_age_tra_P(is))+ &
               phaeocystismortcell*c(iv_phyto_phaeocystis_cell_age_tra_P(is))
#endif
#ifdef key_psnz
        dc(iv_detr_age_tra_P(is))=dc(iv_detr_age_tra_P(is))  &
           +((1.0_rsh-assimilmesozoo)*c(iv_zoo_meso_N)*rappaz*broumesozoopsnz+       &
           +(1.0_rsh-assimilmicrozoo)*c(iv_zoo_micr_N)*rappaz*broumicrozoopsnz)  &
                   *signature_P(iv_phyto_psnz_tra_P(is))*age_P(iv_phyto_psnz_age_tra_P(is))       &
           + psnzmorteau*c(iv_phyto_psnz_age_tra_P(is))
#endif	 
#ifdef key_karenia
        dc(iv_detr_age_tra_P(is))=dc(iv_detr_age_tra_P(is))  &
           +(1.0_rsh-assimilmesozoo)*c(iv_zoo_meso_N)*rappaz*broumesozookarenia &
                    *signature_P(iv_phyto_karenia_tra_P(is))*age_P(iv_phyto_karenia_age_tra_P(is))  &
           + kareniamorteau*c(iv_phyto_karenia_age_tra_P(is))
#endif
#ifdef key_benthos
       dc(iv_detr_age_tra_P(is))=dc(iv_detr_age_tra_P(is))-  &
             (-detresusppho*signature_P(iv_benth_tra_P(is))*age_P(iv_benth_age_tra_P(is))  &
               +vitessechutedet*c(iv_detr_age_tra_P(is)))/epn
#endif
#if ! defined key_benthos
       dc(iv_detr_age_tra_P(is))=dc(iv_detr_age_tra_P(is)) +txfiltbenthij*ibbenth/epn* &
            (c(iv_phyto_diat_age_tra_P(is))+c(iv_phyto_dino_age_tra_P(is))+c(iv_phyto_nano_age_tra_P(is)))
#ifdef key_phaeocystis
       dc(iv_detr_age_tra_P(is))=dc(iv_detr_age_tra_P(is))+txfiltbenthij*ibbenth/epn*c(iv_phyto_phaeocystis_cell_age_tra_P(is))
#endif
#ifdef key_psnz
       dc(iv_detr_age_tra_P(is))=dc(iv_detr_age_tra_P(is))+txfiltbenthij*ibbenth/epn*c(iv_phyto_psnz_age_tra_P(is))
#endif	 
#ifdef key_karenia
       dc(iv_detr_age_tra_P(is))=dc(iv_detr_age_tra_P(is))+txfiltbenthij*ibbenth/epn*c(iv_phyto_karenia_age_tra_P(is)) 
#endif      
#endif
#endif     

#ifdef key_benthos
   ! Evolution du phosphore organique benthique marque  (mmol.m-2.jour-1)
   ! -------------------------------------------------------------------
       dc(iv_benth_tra_P(is))=(-detresusppho*signature_P(iv_benth_tra_P(is))   &
                    +vitessechutedet*c(iv_detr_tra_P(is))+vitessechutediat*c(iv_phyto_diat_tra_P(is))) &
                    -(reminpdeteau*p_reminbenth+p_burial)*c(iv_benth_tra_P(is))  &
                    +txfiltbenthij*(c(iv_phyto_diat_tra_P(is))+c(iv_phyto_dino_tra_P(is))+c(iv_phyto_nano_tra_P(is)))

#if defined key_psnz
       dc(iv_benth_tra_P(is))=dc(iv_benth_tra_P(is))+txfiltbenthij*ibbenth*c(iv_phyto_psnz_tra_P(is))
#endif
#if defined key_karenia
       dc(iv_benth_tra_P(is))=dc(iv_benth_tra_P(is))+txfiltbenthij*ibbenth*c(iv_phyto_karenia_tra_P(is))
#endif
#ifdef key_phaeocystis
       dc(iv_benth_tra_P(is))=dc(iv_benth_tra_P(is))+txfiltbenthij*ibbenth*c(iv_phyto_phaeocystis_cell_tra_P(is))
#endif

#ifdef key_age_tracer
       dc(iv_benth_age_tra_P(is))=c(iv_benth_tra_P(is))+ &
                     (-detresusppho*signature_P(iv_benth_tra_P(is))*age_P(iv_benth_age_tra_P(is))  &
                       +vitessechutedet*c(iv_detr_age_tra_P(is))+vitessechutediat*c(iv_phyto_diat_age_tra_P(is))) &
                     -(reminpdeteau*p_reminbenth+p_burial)*c(iv_benth_age_tra_P(is))  &
                    +txfiltbenthij*(c(iv_phyto_diat_age_tra_P(is))+c(iv_phyto_dino_age_tra_P(is))+c(iv_phyto_nano_age_tra_P(is)))
#if defined key_psnz
       dc(iv_benth_age_tra_P(is))=dc(iv_benth_age_tra_P(is))+txfiltbenthij*ibbenth*c(iv_phyto_psnz_age_tra_P(is))
#endif
#if defined key_karenia
       dc(iv_benth_age_tra_P(is))=dc(iv_benth_age_tra_P(is))+txfiltbenthij*ibbenth*c(iv_phyto_karenia_age_tra_P(is))
#endif
#ifdef key_phaeocystis
       dc(iv_benth_age_tra_P(is))=dc(iv_benth_age_tra_P(is))+txfiltbenthij*ibbenth*c(iv_phyto_phaeocystis_cell_age_tra_P(is))
#endif
#ifdef key_ulvas
       dc(iv_benth_age_tra_P(is))=dc(iv_benth_age_tra_P(is))+ulvebenthmortsed*c(iv_ulv_benth_age_tra_P(is))*ibbenth/0.014_rsh
#endif
#endif     
#endif
   
  ! ++++++++++++++++++++++++++++++++++++++++++++++++
  !   ENREGISTREMENT VARIABLES DIAGNOSTIQUES
  ! ++++++++++++++++++++++++++++++++++++++++++++++++  
    DO ivtra=1,nb_var_tracerP 
       iv_tra=iv_tracer_P(ivtra,is)
       iv_sign=iv_signed_P(ivtra,is)
       id_sign=id_tracer_signP(ivtra,is)
       diag_3d_wat(id_sign,km,im,jm)=0.0_rsh
       IF (c(iv_sign).gt.seuil_P_tracer_diag) diag_3d_wat(id_sign,km,im,jm)=signature_P(iv_tra)
   ENDDO
#ifdef key_age_tracer  
   id_sign=id_sign+2
#else
   id_sign=id_sign+1
#endif
   diag_3d_wat(id_sign,km,im,jm)=c(iv_phyto_diat_tra_P(is))+c(iv_phyto_dino_tra_P(is))+c(iv_phyto_nano_tra_P(is))
   Pphytototal=(c(iv_phyto_diat_N)+c(iv_phyto_dino_N)+c(iv_phyto_nano_N))*rappaz

#ifdef key_karenia
   diag_3d_wat(id_sign,km,im,jm)=diag_3d_wat(id_sign,km,im,jm)+c(iv_phyto_karenia_tra_P(is))
   Pphytototal=Pphytototal+c(iv_phyto_karenia_N)*rappaz
#endif
#ifdef key_phaeocystis
   diag_3d_wat(id_sign,km,im,jm)=diag_3d_wat(id_sign,km,im,jm) &
                  +c(iv_phyto_phaeocystis_colo_tra_P(is))+c(iv_phyto_phaeocystis_cell_tra_P(is))
   Pphytototal=Pphytototal+(c(iv_phyto_phaeocystis_colo_N)+c(iv_phyto_phaeocystis_cell_N))*rappaz
#endif
#ifdef key_psnz
   diag_3d_wat(id_sign,km,im,jm)=diag_3d_wat(id_sign,km,im,jm)+c(iv_phyto_psnz_tra_P(is))
   Pphytototal=Pphytototal+c(iv_phyto_psnz_N)*rappaz
#endif
   phytototal_tra_P=diag_3d_wat(id_sign,km,im,jm)
   IF (Pphytototal.gt.seuil_P_tracer_diag) THEN
     diag_3d_wat(id_sign,km,im,jm)=diag_3d_wat(id_sign,km,im,jm)/(Pphytototal)
   ELSE
     diag_3d_wat(id_sign,km,im,jm)=0.0_rsh
   ENDIF
   
#ifdef key_age_tracer
   age_max=(t-tdeb_tracerP)/86400.0_rlg
   DO ivtra=1,nb_var_tracerP 
       iv_tra=iv_tracer_P(ivtra,is)
       iv_sign=iv_signed_P(ivtra,is)
       id_sign=id_tracer_ageP(ivtra,is)
       ivage=iv_age_P(ivtra,is)
       !IF (signature_P(iv_tra) .GT. 0.02_rsh) THEN
       IF (age_P(ivage)==0.0_rsh) THEN
          diag_3d_wat(id_sign,km,im,jm)=-1.0_rsh
       ELSE IF (age_P(ivage) > age_max) THEN
          diag_3d_wat(id_sign,km,im,jm)=-1.0_rsh
       ELSE
          diag_3d_wat(id_sign,km,im,jm)=age_P(ivage)
       ENDIF
   ENDDO  
   id_sign=id_sign+2
   diag_3d_wat(id_sign,km,im,jm)=c(iv_phyto_diat_age_tra_P(is))+c(iv_phyto_dino_age_tra_P(is))+c(iv_phyto_nano_age_tra_P(is))
 
#ifdef key_karenia
   diag_3d_wat(id_sign,km,im,jm)=diag_3d_wat(id_sign,km,im,jm)+c(iv_phyto_karenia_age_tra_P(is))
#endif
#ifdef key_phaeocystis
   diag_3d_wat(id_sign,km,im,jm)=diag_3d_wat(id_sign,km,im,jm) &
                        +c(iv_phyto_phaeocystis_colo_age_tra_P(is))+c(iv_phyto_phaeocystis_cell_age_tra_P(is))
#endif
#ifdef key_psnz
   diag_3d_wat(id_sign,km,im,jm)=diag_3d_wat(id_sign,km,im,jm)+c(iv_phyto_psnz_age_tra_P(is))
#endif
   !if (phytototal_tra_P.gt.1.e-4_rsh)  THEN
   IF (diag_3d_wat(id_sign-1,km,im,jm) > seuil_P_age_tracer_phytot) THEN
      diag_3d_wat(id_sign,km,im,jm)=diag_3d_wat(id_sign,km,im,jm)/phytototal_tra_P  
   ELSE
      diag_3d_wat(id_sign,km,im,jm)= -1.0_rsh  
   ENDIF
#endif

   ENDDO
         
         
   END SUBROUTINE  incellwat_phosphoretracer
#endif
!!!===========================================================
  SUBROUTINE biolo_settling(km,im,jm,c)

   !&E---------------------------------------------------------------------
   !&E
   !&E ** Purpose : estimate settling velocity for biologic variable (detrital..)
   !&E
   !&E ** Description :
   !&E
   !&E ** Called by :  incellwat_nut4phy3zoo2
   !&E
   !&E ** External calls :
   !&E
   !&E ** Reference :
   !&E
   !&E ** History :
   !&E       !  2010-03    B. Thouvenin issued fro biolodynzwat
   !&E
   !&E---------------------------------------------------------------------
   USE parameters,ONLY    : obc_width,imin,jmin,imax,jmax
   USE obccombine, ONLY : l_obc_south, l_obc_north, l_obc_west, l_obc_east
   USE comsubstance, ONLY : nvp
   USE comvars2d,    ONLY : jjulien
#ifdef key_parsub_newdt
   ! rajout pour calcul de ndt_part en fonction du temps, calcule en fonction de ws
   USE comsubstance, ONLY : imud1
#endif
#if defined key_N_tracer 
   USE parameters, ONLY : nb_var_tracerN 
#endif
#if defined key_P_tracer 
   USE parameters, ONLY : nb_var_tracerP 
#endif

   !! * Arguments
   INTEGER, INTENT(in)                       :: km,im,jm      ! ocean spatial-step index
   REAL(KIND=rsh),DIMENSION(:),INTENT(in)    :: c

   !! * Local declarations
   INTEGER                                   :: ivp
   REAL(KIND=rsh)                            :: modulationsedpardenseau,rdet,wchutedet,foncsinus
   REAL(KIND=rsh)                            :: phytodetritus,zoodetritus,effetchutedia
#if defined key_N_tracer || defined key_P_tracer
   INTEGER                                   :: is,ivtra,iv_tra,iv_sign,ivage
#endif

     IF(l_SNeffect_settle) THEN

       ! Diatomees et dinoflagellees
       !=============================
         effetchutedia=MAX(0.0_rsh,effetselnutdiat)**0.2_rsh
         ws3(km,iv_phyto_diat_N,im,jm)=(ws_free_min(iv_phyto_diat_N)*effetchutedia+      &
                                  ws_free_max(iv_phyto_diat_N)*(1.0_rsh-effetchutedia))
     ENDIF
       modulationsedpardenseau=1.0_rsh
#ifdef key_physadaptation
         ! Modulation par la profondeur (grosses diats cotieres, petites oceaniques)
         ws3(km,iv_phyto_diat_N,im,jm)=ws3(km,iv_phyto_diat_N,im,jm)*  &
                           (0.3+0.7*min(1.0_rsh,(5000.0_rsh-h0(im,jm))/4900.0_rsh))

         ! Modulation de la vitesse de chute du materiel particulaire en 
         ! fonction de la densite de l eau de mer
         ! -------------------------------------------------------------
         ! la loi de Stokes permet de calculer la vitesse limite de chute dans une eau a T,S
         ! en fonction de la vitesse de chute connue dans une eau a Tref,Sref par:
         ! v(T,S)=v(Tref,Sref) * [1 + (1 - ro(T,S)/ro(Tref,Sref))/(roparticule-ro(Tref,Sref)]
         ! roparticule=masse volumique de la particule (=1.05 kg.m-3 pour le phytoplancton)
         ! ro(Tref,Sref)=1.026 kg.m-3 pour l eau de mer a 15 degres C et 35 pour mille
         ! density of pure water at temperature temper
         ! row = 999.842594_rlg + (  6.793952d-02 + ( - 9.095290d-03 +                &
         !         (1.001685d-04 - 1.120083d-06*temper + 6.536332d-09*temper*temper)*temper )*temper  )*temper
         ! density of sea water at salinity sali and temperature temper
         !rost = row + sali * (   0.824493_rlg + (  -4.0899d-03 + ( 7.6438d-05 +                   &
         !           (-8.2467d-07+5.3875d-09*temper)*temper )*temper)*temper) +             &
         !           sali**1.5_rlg * ( -5.72466d-03 + (1.0227d-04-1.6546d-06*temper)*temper) +  &
         !           sali*sali*4.8314d-04
         ! modulationsedpardenseau=1.0_rsh+(1.0_rsh-(rost/ro3515))/(1.05_rsh-ro3515)

         !ws3(km,iv_phyto_diat_N,im,jm)=ws3(km,iv_phyto_diat_N,im,jm)*modulationsedpardenseau
         !!ws3(km,iv_phyto_dino_N,im,jm)=ws3(km,iv_phyto_dino_N,im,jm)*modulationsedpardenseau

#endif
         IF (modulationsedpardenseau .ne.1.0_rsh) THEN

#ifdef key_psnz
            ws3(km,iv_phyto_psnz_N,im,jm)=ws3(km,iv_phyto_psnz_N,im,jm)*modulationsedpardenseau
            ws3(km,iv_phyto_psnz_Si,im,jm)=ws3(km,iv_phyto_psnz_N,im,jm)
#endif	
#ifdef key_karenia	
            ws3(km,iv_phyto_karenia_N,im,jm)=ws3(km,iv_phyto_karenia_N,im,jm)*modulationsedpardenseau
            ws3(km,iv_phyto_karenia_C,im,jm)=ws3(km,iv_phyto_karenia_N,im,jm)
           !   ws3(km,iv_phyto_karenia_P,im,jm)=ws3(km,iv_phyto_karenia_N,im,jm)	
#endif	
#ifdef key_phaeocystis
            ws3(km,iv_phyto_phaeocystis_colo_N,im,jm)=ws3(km,iv_phyto_phaeocystis_colo_N,im,jm)*modulationsedpardenseau
            ws3(km,iv_phyto_phaeocystis_mucus,im,jm)=ws3(km,iv_phyto_phaeocystis_colo_N,im,jm)
#endif

         ENDIF  ! fin if modulationsedpardenseau different de 1
#ifdef key_phaeocystis
            ws3(km,iv_phyto_phaeocystis_colo_N,im,jm)=(0.0085_rsh/3600.0_rsh)*(1+5*(1-effetselnutphaeocystiscolo))
            ws3(km,iv_phyto_phaeocystis_mucus,im,jm)=ws3(km,iv_phyto_phaeocystis_colo_N,im,jm)
#endif
         ! Materiel detritique
         !======================
         ! modulation en fonction du mesozooplancton
         IF(l_phyzoodeteffect_settle .and. c(iv_zoo_meso_N)>0.0_rsh) THEN
           ! PHYTODETRITUS
            phytodetritus=diatmorteau*c(iv_phyto_diat_N)  &
                     +dinomorteau*c(iv_phyto_dino_N)  &
                     +nanomorteau*c(iv_phyto_nano_N)  &
           +(rationmicrozoo*(1.0_rsh-assimilmicrozoo)+txmortmicrozoo)*c(iv_zoo_micr_N)

#ifdef key_psnz
            phytodetritus=phytodetritus+psnzmorteau*c(iv_phyto_psnz_N)
#endif
#ifdef key_karenia
            phytodetritus=phytodetritus+kareniamorteau*c(iv_phyto_karenia_N)
#endif
#ifdef key_phaeocystis
            phytodetritus=phytodetritus+(phaeocystismortcolo+phaeocystislysecolo)*c(iv_phyto_phaeocystis_colo_N) &
                         +c(iv_phyto_phaeocystis_cell_N)*phaeocystismortcell
#endif

 
            ! ZOODETRITUS
                zoodetritus=(rationmesozoo*(1.0_rsh-assimilmesozoo)+txmortmesozoo)*c(iv_zoo_meso_N)!+   &
               !   +(rationmicrozoo*(1.0_rsh-assimilmicrozoo)+txmortmicrozoo)*c(iv_zoo_micr_N)
            IF (zoodetritus > 0.0_rsh) THEN
               rdet=phytodetritus/(zoodetritus+epsilon)       
     
               !si la MOP  est majoritairement composee de phytoplancton
               IF (rdet >= 10.0_rsh) THEN
                  wchutedet=p_detphy_wsed
               !si la MOP est majoritairement composee de zoopk
               ELSE IF (rdet < 0.1_rsh) THEN
                  wchutedet=p_detzoo_wsed
               !si la MOP est d origine mixte
               ELSE
                  wchutedet=p_detzoo_wsed*(1.0_rsh/(rdet+1.0_rsh))+          &
                          p_detphy_wsed*(1.0_rsh-(1.0_rsh/(rdet+1.0_rsh)))
               ENDIF
            ELSE
               wchutedet=p_detphy_wsed
            ENDIF
         ELSE
            foncsinus=(1.0_rsh+SIN(2.0_rsh*3.14159_rsh/365.0_rsh*(jjulien-125)))/2.0_rsh
            wchutedet=p_detphy_wsed*(1.0_rsh+0.0_rsh*foncsinus)
         ENDIF

#ifdef key_physadaptation
          ! Modulation par la profondeur (grosses particules cotieres, petites oceaniques)
          wchutedet=p_detphy_wsed+(wchutedet-p_detphy_wsed)*min(1.0_rsh,(5000.0_rsh-h0(im,jm))/4900.0_rsh)
          ! Modulation si besoin par densite de l eau (commente actuellement)
          wchutedet=wchutedet*modulationsedpardenseau
#endif
          ws3(km,iv_detr_N,im,jm)=wchutedet
          ws3(km,iv_detr_Si,im,jm)=wchutedet
          ws3(km,iv_detr_P,im,jm)=wchutedet

#if defined key_N_tracer
          DO is=1,nb_source_tracerN
            DO ivtra=1,nb_var_tracerN 
             iv_tra=iv_tracer_N(ivtra,is)
             IF(iv_tra <= nvp) THEN
                iv_sign=iv_signed_N(ivtra,is)
                ws3(km,iv_tra,im,jm)=ws3(km,iv_sign,im,jm)
#ifdef key_age_tracer
                ivage=iv_age_N(ivtra,is)
                ws3(km,ivage,im,jm)=ws3(km,iv_sign,im,jm)
#endif
             ENDIF
            ENDDO
          ENDDO
#endif
#if defined key_P_tracer
          DO is=1,nb_source_tracerP
            DO ivtra=1,nb_var_tracerP 
             iv_tra=iv_tracer_P(ivtra,is)
             IF(iv_tra <= nvp) THEN
                iv_sign=iv_signed_P(ivtra,is)
                ws3(km,iv_tra,im,jm)=ws3(km,iv_sign,im,jm)
#ifdef key_age_tracer
                ivage=iv_age_P(ivtra,is)
                ws3(km,ivage,im,jm)=ws3(km,iv_sign,im,jm)
#endif
             ENDIF
            ENDDO
          ENDDO
#endif
  
      ! bornage de la vitesse de chute des variables particulaires en chaque maille
      ! mise a zero aux limites ouvertes
      ! ---------------------------------------------------------------------------
          DO ivp=1,nvp
            ws3(km,ivp,im,jm)=sign(MIN(0.95_rlg*epn/dtbio,REAL(ABS(ws3(km,ivp,im,jm)),rlg)),ws3(km,ivp,im,jm))
          END DO
#ifdef key_parsub_newdt   
          DO ivp=imud1,nvp
                IF (ws3(km,ivp,im,jm)>ws3max_bio(ivp)) ws3max_bio(ivp)=ws3(km,ivp,im,jm)
          ENDDO
#endif 

   END SUBROUTINE  biolo_settling  

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

#ifdef key_zostera

  SUBROUTINE incellwat_zostera(km,im,jm,xe,c,dc)

   !&E-------------------------------------------------------------------
   !&E                 ***  ROUTINE incellwat_zostera  ***
   !&E
   !&E ** Purpose : Calcul des variables concernant les herbiers de zosteres
   !&E              
   !&E
   !&E ** Description :
   !&E
   !&E ** Called by :  incellwat_nut4phy3zoo2
   !&E
   !&E ** External calls :
   !&E
   !&E ** Reference :
   !&E
   !&E ** History :
   !&E       !  2013-09    (M. Plus)
   !&E       !
   !&E
   !&E---------------------------------------------------------------------
   !! * Modules used
   USE comsubstance, ONLY : alumplafond,attenuation
   USE comvars2d,    ONLY : jjulien
   USE cometemp,     ONLY : ventvent  
   USE parameters,   ONLY : pi

   !! * Arguments
   INTEGER, INTENT( in ) ::   km,im,jm      ! ocean spatial-step index
   REAL(KIND=rsh),             INTENT(in) :: xe     !ssh
   REAL(KIND=rsh),DIMENSION(:),INTENT(in) :: c
   REAL(KIND=rsh),DIMENSION(:),INTENT(inout) :: dc

   !! * Local declarations
   

   ! processus lies aux zosteres 
   ! ---------------------------
   REAL(KIND=rsh) :: LAI,Qcan,alumfond,vitvent
   REAL(KIND=rsh) :: effetchaleurzprod,effetchaleurzrespf,effetchaleurzrespr,effetchaleurzmort
   REAL(KIND=rsh) :: effetchaleurzrecr,effet_vent
   REAL(KIND=rsh) :: LNquota,RNquota,LNsat,RNsat,limabsLnh4,limabsLno3,limabsRnh4
   REAL(KIND=rsh) :: limprodLN,limprodLP,limnutrecr,limRN,limRP
   REAL(KIND=rsh) :: LPquota,RPquota,lPsat,RPsat,limabsLpo4,limabsRpo4
   REAL(KIND=rsh) :: effetlumzost,Net_Prod_zost,Root_growth,Leaf_growth,Kzost
   REAL(KIND=rsh) :: Labs_nh4,Labs_no3,Rabs_nh4,Labs_po4,Rabs_po4
   REAL(KIND=rsh) :: deltasat_N,deltasat_P,trans_N_acro,trans_N_basi,trans_P_acro,trans_P_basi
   REAL(KIND=rsh) :: LNrecla,LPrecla,RNrecla,RPrecla
   REAL(KIND=rsh) :: Root_mort,Leaf_mort
   REAL(KIND=rsh) :: revolangle,declinangle,dureej,limdureej,limselfshad,limRB,Recruit_rate
   REAL(KIND=rsh) :: flowering_rate,SNquota,SPquota,Seed_mort,limLBgerm,effetchaleurgerm,Germin_rate
    

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

   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
   ! saisir le code apres cette limite
   ! =================================
   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

   !+++++++++++++++++++++++++++++
   ! Calculs communs
   !+++++++++++++++++++++++++++++
   ! quota en N et P des graines
   ! ---------------------------
   SNquota = 0.5_rsh*(p_zost_LNquotamax-p_zost_LNquotamin)
   SPquota = 0.5_rsh*(p_zost_LPquotamax-p_zost_LPquotamin) 
 
   IF (ibbenth.eq.1) THEN
 
     IF(c(iv_zost_LB).gt.1.e-10 .and. c(iv_zost_RB).gt.1e-10) THEN

       ! Effets de la temperature sur les zosteres (sd)
       ! ----------------------------------------------
       effetchaleurzprod = exp(p_zost_T_prod*temper)
       effetchaleurzrespf = exp(p_zost_T_respf*temper)
       effetchaleurzrespr = exp(p_zost_T_respr*temper)
       effetchaleurzmort = exp(p_zost_T_mort*(temper-20.0_rsh))
       effetchaleurzrecr = exp(p_zost_T_recr*(temper-5.0_rsh))

       ! Effet de la lumiere ("big leaf" model, Tchamitchian 1993)
       ! ---------------------------------------------------------
       LAI = p_zost_klai*c(iv_zost_LB)
       Qcan = p_parradratio*alumplafond(km,im,jm)
!      effetlumzost = tanh(Qcan*(1-exp(-p_zost_leafabscoef*LAI))/p_zost_Ik)
       effetlumzost = tanh(Qcan/p_zost_Ik)
     
       alumfond = Qcan*exp(-p_zost_leafabscoef*LAI)

       ! Effet des sels nutritifs sur l absorption (sd)
       ! ----------------------------------------------
       LNquota = c(iv_zost_LN)/c(iv_zost_LB)
       LNsat = MAX((LNquota - p_zost_LNquotamin)/(p_zost_LNquotamax - p_zost_LNquotamin),0.0_rsh)
       IF(LNsat.lt.0.99_rsh .AND. c(iv_nutr_NO3).gt.0.5_rsh) THEN 
          limabsLno3 = c(iv_nutr_NO3)/(c(iv_nutr_NO3)+p_zost_KNO3L)*(1-LNsat)
        ELSE
          limabsLno3 = 0.0_rsh 
        ENDIF
        IF(LNsat.lt.0.99_rsh .AND. c(iv_nutr_NH4).gt.0.1_rsh) THEN 
          limabsLnh4 = c(iv_nutr_NH4)/(c(iv_nutr_NH4)+p_zost_KNH4L)*(1-LNsat)
        ELSE
          limabsLnh4 = 0.0_rsh 
        ENDIF
        LPquota = c(iv_zost_LP)/c(iv_zost_LB)
        LPsat = MAX((LPquota - p_zost_LPquotamin)/(p_zost_LPquotamax - p_zost_LPquotamin),0.0_rsh)
        IF(LPsat.lt.0.99_rsh .AND. c(iv_nutr_PO4).gt.0.01_rsh) THEN
          limabsLpo4 = c(iv_nutr_PO4)/(c(iv_nutr_PO4)+p_zost_KPL)*(1-LPsat)
        ELSE
          limabsLpo4 = 0.0_rsh
        ENDIF      
        RNquota = c(iv_zost_RN)/c(iv_zost_RB)
        RNsat = MAX((RNquota - p_zost_RNquotamin)/(p_zost_RNquotamax - p_zost_RNquotamin),0.0_rsh)
        RPquota = c(iv_zost_RP)/c(iv_zost_RB)
        RPsat = MAX((RPquota - p_zost_RPquotamin)/(p_zost_RPquotamax - p_zost_RPquotamin),0.0_rsh)
        IF(RNsat.lt.0.99_rsh .AND. c(iv_benth_NH4).gt.1.0_rsh) THEN 
          limabsRnh4 = c(iv_benth_NH4)/(c(iv_benth_NH4)+p_zost_KNH4R)*(1-RNsat)**p_zost_delta1
        ELSE
          limabsRnh4 = 0.0_rsh
        ENDIF
        IF(RPsat.lt.0.99_rsh .AND. c(iv_benth_PO4).gt.0.1_rsh) THEN
          limabsRpo4 = c(iv_benth_PO4)/(c(iv_benth_PO4)+p_zost_KPR)*(1-RPsat)**p_zost_delta1
        ELSE
          limabsRpo4 = 0.0_rsh
        ENDIF

        ! Effet des quotas en N et P sur la production (sd)
        ! -------------------------------------------------
        limprodLN = LNsat**p_zost_delta2
        limprodLP = LPsat**p_zost_delta2

        ! Photosynthese (gO2/mmolC/j) et respiration (gO2/mmolC/j)
        ! ----------------------------------------------------------
        Gross_Prod_zost = p_zost_maxprod0*effetchaleurzprod*effetlumzost*MIN(limprodLN,limprodLP)

        Leaf_Resp_zost = p_zost_respf0*effetchaleurzrespf
        Root_Resp_zost = p_zost_respr0*effetchaleurzrespr

        ! Croissance des feuilles, Leaf_growth, et des rhizomes, Root_growth (j-1)
        ! --------------------------------------------------------
        Net_Prod_zost = Gross_Prod_zost - (Leaf_Resp_zost + Root_Resp_zost)
        Net_Prod_zost = Net_Prod_zost*1000/(32*p_zost_qphotos)   ! transformation de g02/mmolC/j en mmolC/mmolC/j
        Kzost = p_zost_K
        IF(Net_Prod_zost.gt.0.0_rsh) THEN
          Root_growth = Net_Prod_zost*Kzost
          Leaf_growth = Net_Prod_zost - Root_growth
        ELSE
          Root_growth = 0.0_rsh
          Leaf_growth = 0.0_rsh
        ENDIF

        ! Absorption des sels nutritifs (molN/molC/j)
        ! -------------------------------------------
        Labs_nh4 = p_zost_LNnh4maxabs*limabsLnh4
        Labs_no3 = p_zost_LNno3maxabs*limabsLno3
        Labs_po4 = p_zost_LPmaxabs*limabsLpo4*effetlumzost
      
        Rabs_nh4 = p_zost_RNmaxabs*limabsRnh4
        Rabs_po4 = p_zost_RPmaxabs*limabsRpo4
 
        ! transfert de N et P dans la plante (molN ou P/molC/j). Positif sens acropetal
        ! -----------------------------------------------------------------------------
        deltasat_N = RNsat - LNsat
        IF(deltasat_N .gt. 0._rsh .and. LNsat.lt.0.95_rsh) THEN 
          trans_N_acro = p_zost_transfrate*deltasat_N*c(iv_zost_RN)
          trans_N_basi = 0.0_rsh
        ELSE IF(deltasat_N .lt. 0._rsh .and. RNsat.lt.0.95_rsh) THEN
          trans_N_basi = p_zost_transfrate*ABS(deltasat_N)*c(iv_zost_LN)
          trans_N_acro = 0.0_rsh
        ELSE      
          trans_N_acro = 0.0_rsh
          trans_N_basi = 0.0_rsh
        end IF  
         
        deltasat_P = RPsat - LPsat
        IF(deltasat_P .gt. 0._rsh .and. LPsat.lt.0.95_rsh) THEN 
          trans_P_acro = p_zost_transfrate*deltasat_P*c(iv_zost_RP)
          trans_P_basi = 0.0_rsh
        ELSE IF(deltasat_P .lt. 0._rsh .and. RPsat.lt.0.95_rsh) THEN
          trans_P_basi = p_zost_transfrate*ABS(deltasat_P)*c(iv_zost_LP)
          trans_P_acro = 0.0_rsh
        ELSE
          trans_P_acro = 0.0_rsh
          trans_P_basi = 0.0_rsh
        end IF  

        ! conservation de N et P (molN ou P/molC/j) liee au processus de senescence
        ! -------------------------------------------------------------------------
        LNrecla = MAX(p_zost_reclamax*(1-(LNsat)**2),0.0_rsh)
        RNrecla = MAX(p_zost_reclamax*(1-(RNsat)**2),0.0_rsh)
        LPrecla = MAX(p_zost_reclamax*(1-(LPsat)**2),0.0_rsh)
        RPrecla = MAX(p_zost_reclamax*(1-(RPsat)**2),0.0_rsh)
 
        ! Mortalite des feuilles et des rhizomes (j-1)
        ! --------------------------------------------
        IF(ventvent(im,jm).gt.6.0_rsh) THEN
          effet_vent = (ventvent(im,jm)-6)/10*exp(-1.2*d)*exp(0.1*LAI)
        ELSE 
          effet_vent = 0.0_rsh
        ENDIF
        Leaf_mort = p_zost_mort*effetchaleurzmort
        IF(c(iv_zost_LB).gt.1.e-7) THEN
          Root_mort = Leaf_mort*p_zost_K
        ELSE
          Root_mort = Leaf_mort*10.0_rsh
        ENDIF
      
        ! Recrutement de nouveaux pieds par reproduction vegetative (j-1) 
        ! ---------------------------------------------------------------
        limselfshad = alumfond/(alumfond+p_zost_KREC1)
        IF(c(iv_zost_RB).gt.10.0_rsh) THEN
          limRB = c(iv_zost_RB)/(c(iv_zost_RB)+p_zost_KREC2)
        ELSE
          limRB = 0.0_rsh
        ENDIF
        limRN = RNsat**p_zost_delta2
        limRP = RPsat**p_zost_delta2
        limnutrecr = MIN(limRN,limRP)
        Recruit_rate = p_zost_RECRmax*effetchaleurzrecr*MIN(limselfshad,limRB,limnutrecr)

        ! Effort de reproduction sexuee (s.d.) et production de graines (mmolC/pied) 
        ! --------------------------------------------------------------------------
        IF(c(iv_zost_LB).gt.200.0_rsh) THEN
          revolangle = 0.2163108_rsh+2*atan(0.9671396_rsh*tan(0.0086_rsh*(jjulien-186))) !Forsythe et al. (1995)
          declinangle = asin(0.39795_rsh*cos(revolangle))
          dureej = 24-24/pi*acos((sin(0.833_rsh*pi/180)+sin(44.6667_rsh*pi/180)*sin(declinangle)) &
                 /(cos(44.6667_rsh*pi/180)*cos(declinangle)))
          limdureej = MAX(dureej-14,0.0_rsh)/1.57_rsh
          flowering_rate = p_zost_ERSmax*limdureej*effetchaleurzprod
        ELSE
          flowering_rate = 0.0_rsh
        ENDIF

        ! tests sur quelques variables
        ! ----------------------------
!        IF(LNquota.lt.p_zost_LNquotamin .OR. LNquota.gt.p_zost_LNquotamax) THEN
!          print*,'Attention LNquota sort des bornes !!!! en',im,jm,', LNquota =',LNquota
!          print*,'Labs =',(Labs_nh4 + Labs_no3)*c(iv_zost_LB)
!          print*,'Recruit_rate =',Recruit_rate*p_zost_SB1*c(iv_zost_D)*c(iv_zost_RN)/c(iv_zost_RB)
!          print*,'trans_N_acro, trans_N_basi =',trans_N_acro,trans_N_basi
!          print*,'LNrecla =',LNrecla
!          print*,'deltasat_N, RNsat, LNsat =',deltasat_N,RNsat,LNsat
!          print*,'-(Leaf_mort+effet_vent) =',-(Leaf_mort+effet_vent)*c(iv_zost_LN)
!          print*,'Germin_rate=',0.5_rsh*Germin_rate*c(iv_zost_benth_seed)*epnsed*SNquota 
           IF(LNquota.lt.0.005_rsh .OR. LNquota.gt.0.15_rsh) THEN
             print*,'Attention LNquota sort des bornes !!!! en',im,jm,', LNquota =',LNquota
             stop
           ENDIF
!        ENDIF
!        IF(RNquota.lt.p_zost_RNquotamin .OR. RNquota.gt.p_zost_RNquotamax) THEN
!          print*,'Attention RNquota sort des bornes !!!! en ',im,jm,', RNquota = ',RNquota
!          print*,'limabsRnh4 =',limabsRnh4
!          print*,'Recruit_rate =',Recruit_rate*p_zost_SB1*c(iv_zost_D)*c(iv_zost_RN)/c(iv_zost_RB)
!          print*,'trans_N_acro, trans_N_basi =',trans_N_acro,trans_N_basi
!          print*,'RNrecla =',RNrecla
!          print*,'deltasat_N, RNsat, LNsat =',deltasat_N,RNsat,LNsat
!          print*,'-Root_mort =',-Root_mort*c(iv_zost_RN)
!          print*,'Germin_rate=',0.5_rsh*Germin_rate*c(iv_zost_benth_seed)*epnsed*SNquota
!          print*,'LB=',c(iv_zost_LB),'RB=',c(iv_zost_RB)
!          print*,'LN=',c(iv_zost_LN),'RN=',c(iv_zost_RN)
          IF(RNquota.lt.0.01_rsh .OR. RNquota.gt.0.135_rsh) THEN
            print*,'Attention RNquota sort des bornes !!!! en ',im,jm,', RNquota = ',RNquota
            stop
          ENDIF
!        ENDIF
!        IF(LPquota.lt.p_zost_LPquotamin .OR. LPquota.gt.p_zost_LPquotamax) THEN
!          print*,'Attention LPquota sort des bornes !!!! en ',im,jm,', LPquota = ',LPquota
!          print*,'LPsat, limabsLpo4 =',LPsat,limabsLpo4
          IF(LPquota.lt.0.0005_rsh .OR. LPquota.gt.0.009_rsh) THEN
            print*,'Attention LPquota sort des bornes !!!! en ',im,jm,', LPquota = ',LPquota
            stop
          ENDIF
!        ENDIF
!        IF(RPquota.lt.p_zost_RPquotamin .OR. RPquota.gt.p_zost_RPquotamax) THEN
!          print*,'Attention RPquota sort des bornes !!!! en ',im,jm,' RPquota = ',RPquota
!          print*,'RP :'
!          print*,'Rabs, Recruit_rate =',Rabs_po4*c(iv_zost_RB),-Recruit_rate*p_zost_SB1*c(iv_zost_D)*RPquota
!          print*,'transacro,transbasi,RPrecla =',-trans_P_acro,trans_P_basi,RPrecla
!          print*,'Root_mort =',-(1-RPrecla)*Root_mort*c(iv_zost_RP)
!          print*,'RB :'
!          print*,'Root_growth, Recruit_rate, Root_mort =',Root_growth*c(iv_zost_LB),  &
!                 -Recruit_rate*p_zost_SB1*c(iv_zost_D),-Root_mort*c(iv_zost_RB)
          IF(RPquota.lt.0.0005_rsh .OR. RPquota.gt.0.009_rsh) THEN
            print*,'Attention RPquota sort des bornes !!!! en ',im,jm,' RPquota = ',RPquota
            stop
          ENDIF
!        ENDIF

     ELSE
          RNquota = 0.0_rsh
          RPquota = 0.0_rsh
          Gross_Prod_zost = 0.0_rsh         
          Leaf_Resp_zost = 0.0_rsh 
          Root_Resp_zost = 0.0_rsh 
          Root_growth = 0.0_rsh
          Leaf_growth = 0.0_rsh
          Labs_nh4 = 0.0_rsh
          Labs_no3 = 0.0_rsh
          Labs_po4 = 0.0_rsh
          Rabs_nh4 = 0.0_rsh
          Rabs_po4 = 0.0_rsh
          trans_N_acro = 0.0_rsh
          trans_N_basi = 0.0_rsh
          trans_P_acro = 0.0_rsh
          trans_P_basi = 0.0_rsh
          LNrecla =  0.0_rsh
          RNrecla =  0.0_rsh
          LPrecla =  0.0_rsh
          RPrecla =  0.0_rsh
          effet_vent = 0.0_rsh
          Leaf_mort = 0.0_rsh
          Root_mort = 0.0_rsh
          Recruit_rate = 0.0_rsh
          flowering_rate = 0.0_rsh
          
     END IF     ! fin test presence zosteres
     
     IF(c(iv_zost_benth_seed).gt.0.0_rsh) THEN

       ! Mortalite des graines du sediment (j-1)
       ! ---------------------------------------
       IF((p_zost_Smort*c(iv_zost_benth_seed))*dtbio/86400.0_rsh.lt.c(iv_zost_benth_seed)) THEN
          Seed_mort = p_zost_Smort
       ELSE
          Seed_mort = 86400.0_rsh/dtbio
       ENDIF

       ! Recrutement de nouveaux pieds par germination (j-1)
       ! ---------------------------------------------------
       LAI = p_zost_klai*c(iv_zost_LB)
       Qcan = p_parradratio*alumplafond(km,im,jm)
       alumfond = Qcan*exp(-p_zost_leafabscoef*LAI)
       IF(c(iv_zost_benth_seed).gt.p_zost_SB0 .and. alumfond.gt.150) THEN
         IF(c(iv_zost_LB) .le. p_zost_KGERM) THEN
           limLBgerm = 1-(c(iv_zost_LB)/p_zost_KGERM)**2
         ELSE
           limLBgerm = 0._rsh
         end IF
         effetchaleurgerm = exp(p_zost_T_prod*temper) 
         Germin_rate = p_zost_GERmax*limLBgerm*effetchaleurgerm
       ELSE
         Germin_rate = 0.0_rsh
       ENDIF
     ELSE
         Germin_rate = 0.0_rsh
     ENDIF      ! fin test sur presence de graines benthiques

     IF(c(iv_zost_seed).gt.0.0_rsh) THEN

       ! Mortalite des graines en suspension (j-1)
       ! -----------------------------------------
       IF((p_zost_Smort*c(iv_zost_seed))*dtbio/86400.0_rsh.lt.c(iv_zost_seed)) THEN
         Seed_mort = p_zost_Smort
       ELSE
         Seed_mort = 86400.0_rsh/dtbio
       ENDIF
     ELSE
         Seed_mort = 0.0_rsh
     ENDIF


     !++++++++++++++++++++++++++++++++++++
     ! Processus lies aux zosteres 
     !++++++++++++++++++++++++++++++++++++
    
     ! Evolution du nitrate dissous (mmolN/m3/j)
     ! -----------------------------------------
      dc(iv_nutr_NO3) = dc(iv_nutr_NO3) - Labs_no3*c(iv_zost_LB)/epn                                    

     ! Evolution de l ammonium (mmol/m3/j)
     ! -----------------------------------
      dc(iv_nutr_NH4) = dc(iv_nutr_NH4) - Labs_nh4*c(iv_zost_LB)/epn + reminazdeteau/10.0_rsh*c(iv_detr_zost_N)      
 
     ! Evolution du phosphore dissous (mmol/m3/j)
     ! ------------------------------------------   
      dc(iv_nutr_PO4) = dc(iv_nutr_PO4) - Labs_po4*c(iv_zost_LB)/epn + reminpdeteau/10.0_rsh*c(iv_detr_zost_P)      

     ! Evolution du phosphore dissous benthique (mmol/m3/j)
     ! ------------------------------------------------------   
      dc(iv_benth_PO4) = - Rabs_po4*c(iv_zost_RB)/epnsed

     ! Evolution de l ammonium benthique (mmol/m3/j)
     ! -----------------------------------------------
      dc(iv_benth_NH4) = - Rabs_nh4*c(iv_zost_RB)/epnsed

     ! Evolution des feuilles de zosteres (mmolC/m2/j)
     ! -----------------------------------------------
      dc(iv_zost_LB) = Leaf_growth*c(iv_zost_LB) + Recruit_rate*p_zost_SB1*c(iv_zost_D) - (Leaf_mort+effet_vent)*c(iv_zost_LB) &
                      + 0.5_rsh*Germin_rate*c(iv_zost_benth_seed)
!      dc(iv_zost_LB) = 0._rsh
 
     ! Evolution des rhizomes et racines de zosteres (mmolC/m2/j) 
     ! ----------------------------------------------------------
      dc(iv_zost_RB) = Root_growth*c(iv_zost_LB) - Recruit_rate*p_zost_SB1*c(iv_zost_D) - Root_mort*c(iv_zost_RB)  &
                       + 0.5_rsh*Germin_rate*c(iv_zost_benth_seed)
!      dc(iv_zost_RB) = 0._rsh
 
     ! Evolution de la densite de pieds de zosteres (/m2/j)
     ! ----------------------------------------------------
      dc(iv_zost_D) = (Recruit_rate - (Leaf_mort+effet_vent))*c(iv_zost_D)                                                &
                      + Germin_rate*c(iv_zost_benth_seed)*epnsed/p_zost_SB0
!       dc(iv_zost_D) = 0._rsh
 
     ! Evolution du pool de N des feuilles de zosteres (mmolN/m2/j)
     ! ------------------------------------------------------------
      dc(iv_zost_LN) = (Labs_nh4 + Labs_no3)*c(iv_zost_LB)                                                 &
                       + Recruit_rate*p_zost_SB1*c(iv_zost_D)*RNquota                                             &
                       + trans_N_acro - trans_N_basi - ((1-LNrecla)*Leaf_mort+effet_vent)*c(iv_zost_LN)           &
                       + 0.5_rsh*Germin_rate*c(iv_zost_benth_seed)*SNquota 

     ! Evolution du pool de P des feuilles de zosteres (mmolP/m2/j)
     ! ------------------------------------------------------------
      dc(iv_zost_LP) = Labs_po4*c(iv_zost_LB) + Recruit_rate*p_zost_SB1*c(iv_zost_D)*RPquota                      &
                       + trans_P_acro - trans_P_basi - ((1-LPrecla)*Leaf_mort+effet_vent)*c(iv_zost_LP)           &
                       + 0.5_rsh*Germin_rate*c(iv_zost_benth_seed)*SPquota 

     ! Evolution du pool de N des rhizomes de zosteres (mmolN/m2/j)
     ! -----------------------------------------------------------
      dc(iv_zost_RN) = Rabs_nh4*c(iv_zost_RB) - Recruit_rate*p_zost_SB1*c(iv_zost_D)*RNquota                      &
                       - trans_N_acro + trans_N_basi - (1-RNrecla)*Root_mort*c(iv_zost_RN)                        &
                       + 0.5_rsh*Germin_rate*c(iv_zost_benth_seed)*SNquota

     ! Evolution du pool de P des rhizomes de zosteres (mmolP/m2/j)
     ! ------------------------------------------------------------
      dc(iv_zost_RP) = Rabs_po4*c(iv_zost_RB) - Recruit_rate*p_zost_SB1*c(iv_zost_D)*RPquota                      &
                       - trans_P_acro + trans_P_basi - (1-RPrecla)*Root_mort*c(iv_zost_RP)                        &
                       + 0.5_rsh*Germin_rate*c(iv_zost_benth_seed)*SPquota

     ! Evolution de l azote detritique peu labile dans le sediment mmolN/m2/j
     ! ----------------------------------------------------------------------
      dc(iv_zost_benth_N) = (1-RNrecla)*Root_mort*c(iv_zost_RN) + Seed_mort*c(iv_zost_benth_seed)*SNquota

     ! Evolution du phosphore detritique peu labile dans le sediment mmolP/m2/j
     ! ------------------------------------------------------------------------
      dc(iv_zost_benth_P) = (1-RPrecla)*Root_mort*c(iv_zost_RP) + Seed_mort*c(iv_zost_benth_seed)*SPquota

     ! Evolution des pousses de zosteres derivantes exprimee en mmolN/m3/j
     ! -------------------------------------------------------------------
      dc(iv_detr_zost_N) = (1-flowering_rate)*((1-LNrecla)*Leaf_mort+effet_vent)*c(iv_zost_LN)/epn  &
                          + Seed_mort*c(iv_zost_seed)*SNquota &
                          - reminazdeteau/10.0_rsh*c(iv_detr_zost_N)      

     ! Evolution des pousses de zosteres derivantes exprimee en mmolP/m3/j
     ! -------------------------------------------------------------------
      dc(iv_detr_zost_P) = (1-flowering_rate)*((1-LPrecla)*Leaf_mort+effet_vent)*c(iv_zost_LP)/epn &
                          + Seed_mort*c(iv_zost_seed)*SPquota &
                          - reminpdeteau/10.0_rsh*c(iv_detr_zost_P)

     ! Evolution des graines derivantes (mmolC/m3/j)
     ! ---------------------------------------------
      dc(iv_zost_seed) = flowering_rate*(Leaf_mort+effet_vent)*c(iv_zost_LB)/epn - Seed_mort*c(iv_zost_seed)

     ! Evolution des graines du sediment (mmolC/m2/j)
     ! ----------------------------------------------
      dc(iv_zost_benth_seed) = -Seed_mort*c(iv_zost_benth_seed) - Germin_rate*c(iv_zost_benth_seed)

     ! Production cumulee des zosteres (gC/m2/j)
     ! -----------------------------------------
     ! dc(iv_zost_pp) = MAX(Net_Prod_zost,0.0_rsh)*c(iv_zost_LB)*12.0_rsh/1000.0_rsh  
    
     ! Pompage de N cumule des feuilles de zosteres (gN/m2/j)
     ! -------------------------------------------------------
     ! dc(iv_zost_LNuptake) = (Labs_nh4 + Labs_no3)*c(iv_zost_LB)*14.0_rsh/1000.0_rsh 
 
     ! Pompage de P cumule des feuilles de zosteres (gP/m2/j)
     ! ------------------------------------------------------
     ! dc(iv_zost_LPuptake) = Labs_po4*c(iv_zost_LB)*31.0_rsh/1000.0_rsh

     ! Pompage de N cumule des racines de zosteres (gN/m2/j)
     ! -------------------------------------------------------
     ! dc(iv_zost_RNuptake) = Rabs_nh4*c(iv_zost_RB)*14.0_rsh/1000.0_rsh  
 
     ! Pompage de P cumule des racines de zosteres (gP/m2/j)
     ! ------------------------------------------------------
     ! dc(iv_zost_RPuptake) = Rabs_po4*c(iv_zost_RB)*31.0_rsh/1000.0_rsh

   ELSE    ! ibbenth = 0

     IF(c(iv_zost_seed).gt.0.0_rsh) THEN

     ! Mortalite des graines en suspension (j-1)
     ! -----------------------------------------
      IF((p_zost_Smort*c(iv_zost_seed))*dtbio/86400.0_rsh.lt.c(iv_zost_seed)) THEN
        Seed_mort = p_zost_Smort
      ELSE
        Seed_mort = 86400.0_rsh/dtbio
      ENDIF
     ELSE
        Seed_mort = 0.0_rsh
     ENDIF

     ! Evolution des pousses de zosteres derivantes exprimee en mmolN/m3/j
     ! -------------------------------------------------------------------
      dc(iv_detr_zost_N) = Seed_mort*c(iv_zost_seed)*SNquota - reminazdeteau/10.0_rsh*c(iv_detr_zost_N)

     ! Evolution des pousses de zosteres derivantes exprimee en mmolP/m3/j
     ! -------------------------------------------------------------------
      dc(iv_detr_zost_P) = Seed_mort*c(iv_zost_seed)*SPquota - reminpdeteau/10.0_rsh*c(iv_detr_zost_P)

     ! Evolution des graines derivantes (mmolC/m3/j)
     ! ---------------------------------------------
      dc(iv_zost_seed) = - Seed_mort*c(iv_zost_seed) 

     ! Evolution de l ammonium (mmol/m3/j)
     ! -----------------------------------
      dc(iv_nutr_NH4) = dc(iv_nutr_NH4) + reminazdeteau/10.0_rsh*c(iv_detr_zost_N)      
 
     ! Evolution du phosphore dissous (mmol/m3/j)
     ! ------------------------------------------   
      dc(iv_nutr_PO4) = dc(iv_nutr_PO4) + reminpdeteau/10.0_rsh*c(iv_detr_zost_P)      

   END IF  ! fin test sur la maille de fond

!   IF (im.eq.85 .and. jm.eq.161 .and. ibbenth.eq.1) THEN
!     print*,'h0+xe =',h0(im,jm)+xe
!     print*,'epn =',epn
!     print*,'Labs_nh4*c(iv_zost_LB)/epn =',Labs_nh4*c(iv_zost_LB)/epn
!     print*,'Labs_no3*c(iv_zost_LB)/epn =',Labs_no3*c(iv_zost_LB)/epn
!     print*,'Eabs_no3*c(iv_zost_EB)/p_phyto_CNratio/epn =',Eabs_no3*c(iv_zost_EB)/p_phyto_CNratio/epn
!     print*,'Rabs_nh4*c(iv_zost_RB)/epn =',Rabs_nh4*c(iv_zost_RB)/epn
!     print*,'minsed_Nrefrac*c(iv_zost_detRN) =',minsed_Nrefrac*c(iv_zost_detRN)
!     print*,'EM*c(iv_zost_EB)/p_phyto_CNratio/epn =',EM*c(iv_zost_EB)/p_phyto_CNratio/epn
!     print*,'Eabs_nh4*c(iv_zost_EB)/p_phyto_CNratio/epn =',Eabs_nh4*c(iv_zost_EB)/p_phyto_CNratio/epn
!     print*,'Recruit_rate*p_zost_SB1*c(iv_zost_D)*c(iv_zost_RN)/c(iv_zost_RB) =', &
!             Recruit_rate*p_zost_SB1*c(iv_zost_D)*c(iv_zost_RN)/c(iv_zost_RB)
!     print*,'trans_N_acro =',trans_N_acro
!     print*,'trans_N_basi =',trans_N_basi
!     print*,'Root_mort*c(iv_zost_RN) =',Root_mort*c(iv_zost_RN)
!     print*,'Leaf_mort*c(iv_zost_LN)/epn =',Leaf_mort*c(iv_zost_LN)/epn
!     print*,'min_Nrefrac*c(iv_zost_detLN) =',min_Nrefrac*c(iv_zost_detLN)
!     print*,'*******************************'
!   ENDIF


    ! ++++++++++++++++++++++++++++++++++++++++++++++++
    !   ENREGISTREMENT VARIABLES DIAGNOSTIQUES
    ! ++++++++++++++++++++++++++++++++++++++++++++++++
   IF (ibbenth.eq.1) THEN
     IF (c(iv_zost_LB).gt.1.e-10 .AND. c(iv_zost_RB).gt.1.e-10 .or. c(iv_zost_benth_seed).gt.p_zost_SB0) THEN
!       diag_3d_wat(irk_diag(id_zost_LBDW),km,im,jm)=c(iv_zost_LB)*12/1000/0.37_rsh
!       diag_3d_wat(irk_diag(id_zost_RBDW),km,im,jm)=c(iv_zost_RB)*12/1000/0.34_rsh
       diag_3d_wat(irk_diag(id_zost_Qcan),km,im,jm)=Qcan
       diag_3d_wat(irk_diag(id_zost_LAI),km,im,jm)=LAI
       diag_3d_wat(irk_diag(id_zost_limlum),km,im,jm)=effetlumzost
       diag_3d_wat(irk_diag(id_zost_limprodLN),km,im,jm)=limprodLN
       diag_3d_wat(irk_diag(id_zost_limprodLP),km,im,jm)=limprodLP
       diag_3d_wat(irk_diag(id_zost_limRN),km,im,jm)=limRN
       diag_3d_wat(irk_diag(id_zost_limRP),km,im,jm)=limRP
!       diag_3d_wat(irk_diag(id_zost_effetchaleurzprod),km,im,jm)=effetchaleurzprod
!       diag_3d_wat(irk_diag(id_zost_effetchaleurzrespf),km,im,jm)=effetchaleurzrespf
!       diag_3d_wat(irk_diag(id_zost_effetchaleurzrespr),km,im,jm)=effetchaleurzrespr
!       diag_3d_wat(irk_diag(id_zost_limabsLnh4),km,im,jm)=limabsLnh4
!       diag_3d_wat(irk_diag(id_zost_limabsLno3),km,im,jm)=limabsLno3
!       diag_3d_wat(irk_diag(id_zost_limabsLpo4),km,im,jm)=limabsLpo4
!       diag_3d_wat(irk_diag(id_zost_limabsRnh4),km,im,jm)=limabsRnh4
!       diag_3d_wat(irk_diag(id_zost_limabsRpo4),km,im,jm)=limabsRpo4
       diag_3d_wat(irk_diag(id_zost_limselfshad),km,im,jm)=limselfshad
       diag_3d_wat(irk_diag(id_zost_limRB),km,im,jm)=limRB
!       diag_3d_wat(irk_diag(id_zost_effetvent),km,im,jm)=effet_vent  
!       diag_3d_wat(irk_diag(id_zost_Germin_rate),km,im,jm)=Germin_rate
!       diag_3d_wat(irk_diag(id_zost_ERS),km,im,jm)=flowering_rate
       diag_2d(irk_diag(id_zost_prod),im,jm)=MAX(Net_Prod_zost,0.0_rsh)*c(iv_zost_LB)*12.0_rsh/1000.0_rsh
     END IF
   END IF

  END SUBROUTINE incellwat_zostera
#endif
   !!======================================================================
#if defined key_oyster_DEB 

 SUBROUTINE incellwat_oysterDEB(km,im,jm,xe,c,dc)

   !&E---------------------------------------------------------------------
   !&E                 ***  ROUTINE incellwat_modelDEB  ***
   !&E
   !&E ** Purpose : Calcul des variations dues à la croissance des filtreurs
   !&E              selon le modèle DEB
   !&E
   !&E ** Description :
   !&E
   !&E ** Called by :
   !&E
   !&E ** External calls :
   !&E
   !&E ** Reference :
   !&E
   !&E ** History :
   !&E       !          (S. Pouvreau, K. Grangere) Original code
   !&E       
   !&E       
   !&E
   !&E---------------------------------------------------------------------
   !! * Modules used
   USE comsubstance, ONLY : attenuation,extinction,alumplafond,nbhuitre
   !USE comsubstance, ONLY : couvmicrophyto,chlorofondmoy,tempfondmax
   USE comsubstance,  ONLY : hautable,cmes_3dmgl
   USE comvars2d,    ONLY : hm,dx,dy,cdate
   

 
   !! * Arguments
   INTEGER, INTENT( in ) ::   km,im,jm      ! ocean spatial-step index
   REAL(KIND=rsh),             INTENT(in) :: xe     !ssh
   REAL(KIND=rsh),DIMENSION(:),INTENT(in) :: c
   REAL(KIND=rsh),DIMENSION(:),INTENT(inout) :: dc

   
   !! * Local declarations

   ! indices de boucles
   ! ------------------
   INTEGER :: iv,k,toto
   !REAL(KIND=rlg)                            :: tjour
   
   ! variables temperature, salinite
   ! -------------------------------
   REAL(KIND=rsh) :: facttemp,tempref

   ! variables huitre
   ! ---------------
   REAL(KIND=rsh) :: chloro,NRJ_reserves
   REAL(KIND=rsh) :: NRJ_structures,NRJ_gonades,nbhuitres,pa,pc,pg
   REAL(KIND=rsh) :: amaig,pr,ponte,lyse,DWres,DWstruct,DWgon,DWtot
   REAL(KIND=rsh) :: Lgtot,ER,FRpop,PFpop,Fpop,surfmailles,pxpop,MES
   REAL(KIND=rsh) :: k_chlvble,cohnbmoule,pm,pj,txing,txfilt,ChlC,vol
   REAL(KIND=rsh) :: TA,TAL,TAH,TL,TH,Tseuil_ponte,Eg,Em,Kappa,Vp,kR,shape
   REAL(KIND=rsh) :: pxm0,ae,pm0,filtration,Tempcorr,pxm,pam,fchl
   REAL(KIND=rsh) :: energ,ERlim,k_chl,seuil,pam_max,muE
   REAL(KIND=rsh) :: untier,deuxtier,FR,PF,Feces
   REAL(KIND=rsh) :: THresp,THing 
   REAL(KIND=rsh) :: lysemax,amaigmax 

   REAL(KIND=rsh) :: dtt,px
 
   REAL(KIND=rlg)        :: tool_datosec
   !!----------------------------------------------------------------------
   !! * Executable part

   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
   ! saisir le code apres cette limite
   ! =================================
   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! Parametres des entrees
! -----------------------
!  espece=espece consideree
!  chloro=concentration en chlorophylle dans l eau (microg/l)
!  temp=temperature de l eau (degrC)
!  NRJ_reserves=Quantitee d energie des reserves (variable d etat Joules)
!  NRJ_structures=Quantitee d energie des structures (variable d etat Joules)
!  NRJ_gonades=Quantitee d energie des gonades (variable d etat Joules)
!  nbhuitre,epn, 
!
! Parametres des sorties
! ----------------------
!  pa=taux d assimilation (J j-1)
!  pc=flux cataboliques (J j-1)
!  pg=flux vers la croissance (J j-1)
!  amaig=taux d ammaigrissement (J j-1)
!  pr=taux de croissance des goandes (J j-1)
!  ponte=flux vers la ponte (J j-1)
!  lyse=lyse des gonades (J j-1)
!  DWres=poids sec des reserves
!  DWstruct=poids sec des structures
!  DWgon=poids sec des gonades
!  DWtot=poids sec total
   
         TA = p_oysDEB_TA
         TAL = p_oysDEB_TAL
         TAH = p_oysDEB_TAH
         TL = p_oysDEB_TL
         THing = p_oysDEB_THing
         THresp = p_oysDEB_THresp
         Tseuil_ponte = p_oysDEB_Tseuilponte
         Eg = p_oysDEB_Eg
         Em = p_oysDEB_Em
         Kappa = p_oysDEB_Kappa
         Vp = p_oysDEB_Vp
         kR = p_oysDEB_kR
         shape = p_oysDEB_shape
         pxm0 = p_oysDEB_pxm0
         pam_max= p_oysDEB_pammax
         ae= p_oysDEB_ae
         pm0= p_oysDEB_pm0
         ERlim= p_oysDEB_ERlim
         k_chl= p_oysDEB_kchl
         muE= p_oysDEB_muE
         tempref=20.

        !!SR utilisation du C comme unite de nourriture
!        k_chl=150
!  Utilisation d une relation entre k_chl et chloro moyenne fond (Desclaux et al. 2014)
!         k_chl=104.091*chlorofondmoy(im,jm)+52.26
!         k_chl=0.89*(104.091*chlorofondmoy(im,jm)+52.26)+0.09*(74.42*tempfondmax(im,jm)-1084.54)


   !+++++++++++++++++++++++++++++
   ! Calculs communs
   !+++++++++++++++++++++++++++++

IF((nbhuitre(im,jm).ne.0.0).and.(d.gt.hautable(im,jm))) then
!      if((nbhuitre(im,jm).ne.0.0).and.(ibbenth.eq.1)) then

   !tjour=jjulien+iheure/24.0_rlg+iminu/1440.0_rlg+isec/86400.0_rlg
    
   untier=1.0_rsh/3.0_rsh
   deuxtier=2.0_rsh/3.0_rsh
   surfmailles=dx(im,jm)*dy(im,jm)

!calcul de la chlorophylle  
   chloro=diag_3d_wat(irk_diag(id_totalchl),km,im,jm)/fact_phyto_ChlNratio
   MES=cmes_3dmgl(km,im,jm)/1000_rsh

! Calcul du rapport Chloro/carbone

!!SR        ChlC=0.003+0.0154*exp(0.05*c(nbvar-1))*(exp(-0.059*            &
!!       (((alumplafond(km,im,jm)/1951000)*86400)/(extinction(km,im,jm)  &
!!       *epn))*(1-exp(-(extinction(km,im,jm)*epn)))))*effetselnutdiat

   ChlC=0.003+0.0154*exp(0.05*temper)*(exp(-0.059*            &
            (((alumplafond(km,im,jm)/1951000)*86400)/(extinction(km,im,jm)  &
            *epn))*(1-exp(-(extinction(km,im,jm)*epn)))))*effetselnutdiat
     
     !!SR utilisation du C comme unite de nourriture
   chloro=chloro/ChlC
      
!!SR    NRJ_reservesH=c(iv_oysdeb_res)
!!    NRJ_structuresH=c(iv_oysdeb_str)
!!    NRJ_gonadesH=c(iv_oysdeb_gon)
   
   NRJ_reserves=max(0.,c(iv_oysdeb_res))
   NRJ_structures=max(0.,c(iv_oysdeb_str))
   NRJ_gonades=max(0.,c(iv_oysdeb_gon))

   !if(ibbenth.ne.0) then
   !SR verification de transfert
   ! print*,'DEB1',im,jm,c(iv_oysdeb_res),c(iv_oysdeb_str),c(iv_oysdeb_gon)
   !endif

   ! Maximum surface ingestion rate {Pxm}
   !! Correction temperature avec formulation Y. Bourles 2009 : ingestion
   !!SR       pxm = pxm0 * exp(TA*((1./(273+20))-(1./(273+temp))))/   &
   !!SR       (1+exp(TAL*(1/(273+temp)-1/TL))+exp(TAH*(1/THing-1/     &
   !!SR       (273+temp))))    
   facttemp=exp(TA*((1./(273+tempref))-(1./(273+temper))))   &
       *(1+exp(TAL*(1/(273+tempref)-1/TL))+exp(TAH*(1/THing-1/     &
       (273+tempref))))                                            &
       /(1+exp(TAL*(1/(273+temper)-1/TL))+exp(TAH*(1/THing-1/     &
       (273+temper))))

   pxm = pxm0 * facttemp

!       pxm = pxm0 * exp(TA*((1./(273+20))-(1./(273+temper))))/   &
!       (1+exp(TAL*(1/(273+temper)-1/TL))+exp(TAH*(1/THing-1/     &
!       (273+temper))))
    ! Maximum surface assimilation rate {Pam}
   pam = ae * pxm

   ! Reponse fonctionnelle

   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
   ! xk variable avec MES
   ! ATTENTION MES en g par litre!!!!!!!!!
   !!       if(espece.eq.'huitrecreuse') then
   !           k_chlvble=k_chl*(1+(MES/0.06))
   k_chl=k_chl*(1+(MES/0.06))
   !!       endif
   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

   ! forcage par chla mesuree - k_chl=coef de demi saturation
   fchl = chloro/(chloro+k_chl) 
       
   vol=(NRJ_structures/Eg)+epsilon

   ! Assimilation rate Pa

   pa = pam * fchl * (vol**deuxtier)       
   !
   ! Volume cost of maintenance [Pm]
   !! Correction temperature avec formulation Y. Bourles 2009 : respiration
   !!SR        pm = pm0 * exp(TA*((1./(273+20))-(1./(273+temp))))/   &
   !!       (1+exp(TAL*(1/(273+temp)-1/TL))+exp(TAH*(1/THresp-1/   &
   !!       (273+temp))))

   facttemp=exp(TA*((1./(273+tempref))-(1./(273+temper))))   &
       *(1+exp(TAL*(1/(273+tempref)-1/TL))+exp(TAH*(1/THresp-1/     &
       (273+tempref))))                                            &
       /(1+exp(TAL*(1/(273+temper)-1/TL))+exp(TAH*(1/THresp-1/     &
       (273+temper))))

   pm = pm0 * facttemp
!        pm = pm0 * exp(TA*((1./(273+20))-(1./(273+temper))))/   &
!       (1+exp(TAL*(1/(273+temper)-1/TL))+exp(TAH*(1/THresp-1/   &
!       (273+temper))))
     
!  Catabolic flux Pc
   pc = ((Eg/Em)*pam*(vol**(-untier)) + pm)   &
           /((Kappa/vol)+(Eg/(NRJ_reserves+epsilon)))
      
!   Flux vers la croissance
   pg = Kappa*pc - pm*vol
   IF (pg .le. 0) THEN
      pg=0.
   ENDIF
        
!   Maturite et reproduction
   pj = min((Vp*((1-Kappa)/Kappa)*pm),(vol*((1-Kappa)/Kappa)*pm))
   IF (vol .gt. Vp) THEN
! Maintenance developpement
! Developpement - repro
      pr=(1-Kappa) * pc - pj
   ELSE
      pr = 0.
   ENDIF
   IF(pr.lt.0.) THEN
      IF (NRJ_gonades .le. 0.) THEN
            pr=0.
      ELSE
            pr=-min(-pr,NRJ_gonades/dtbio*86400.)
      ENDIF
   ENDIF
       
!  amaigrissement
   seuil = (vol**untier)*pm/(Kappa*pam)
   energ = (NRJ_reserves/vol)/Em
!       if ((energ .le. seuil) .and. (NRJ_gonades .eq. 0.)) then
   IF ((energ .le. seuil) .and. (NRJ_gonades .le. 0.)) THEN
           amaig = -Kappa*pc + pm*vol
           amaigmax=max(0.,NRJ_structures/dtbio*86400.)
           amaig=min(amaig, amaigmax)
   ELSE
      amaig = 0.0_rsh
      amaigmax = 0.0_rsh
   ENDIF
       
!  lyse
!       if (energ .le. seuil) then
   IF ((energ .le. seuil).and. (NRJ_gonades.gt.0.)) THEN
      lyse =  ((pm*vol)-Kappa*pc)/kR
      lysemax=max(0.,NRJ_gonades/dtbio*86400.)
      lyse = min(lyse,lysemax)
   ELSE
      lyse = 0.0_rsh
      lysemax = 0.0_rsh
   ENDIF
!
!   variables etats poids sec
   DWres = NRJ_reserves/muE
   DWstruct = 0.15*vol
   DWgon = kR*NRJ_gonades/muE
   DWtot = DWres + DWstruct + DWgon
   Lgtot=vol**untier/shape

!  sauv taux filt
   txfilt=pxm * (vol**deuxtier)/k_chl/24           &
   !SR uptake  /((4.189*11.4)/ChlC/1000.)/(DWtot+epsilon)
          /((4.189*11.4)/1000.)/(DWtot+epsilon)
   txing=pxm * (vol**deuxtier)/(chloro+k_chl)/24   &
   !SR uptake  /((4.189*11.4)/ChlC/1000.)/(DWtot+epsilon)  
          /((4.189*11.4)/1000.)/(DWtot+epsilon) 

!   ponte - huitre - ER=rapport gonado-somatique (%)
   ER = 100.*(kR*NRJ_gonades/muE)/(DWtot+epsilon)
   !!SR        if ((ER .gt. ERlim) .and. (temp .gt. Tseuil_ponte)) then
   IF ((ER .gt. ERlim) .and. (temper .gt. Tseuil_ponte)) THEN
   !!SR	  ponte=NRJ_gonades/dtt*86400.
      ponte=NRJ_gonades/dtbio*86400.
   ELSE
      ponte=0.0_rsh
   ENDIF

!!!! pour huitre creuse

!  Filtration population
   FR= pxm * (chloro/k_chl)*(vol**deuxtier)
   FRpop=FR*nbhuitre(im,jm)/1000/epn/surfmailles/p_phyto_ChlNratio/((4.189*11.4)/ChlC/1000.)        

!  pseudo-feces
   PF=FR- pxm * fchl * (vol**deuxtier)
   PFpop=PF*nbhuitre(im,jm)/1000./surfmailles/p_phyto_ChlNratio/((4.189*11.4)/ChlC/1000.)

! ingestion 
!!       px=filtration * pxm * fchl * (vol**deuxtier)
   px= pxm * fchl * (vol**deuxtier)
   pxpop=px*nbhuitre(im,jm)/1000./epn/surfmailles/p_phyto_ChlNratio/2./((4.189*11.4)/ChlC/1000.)
 !!      print*, 'toto ',px,pxpop,nbhuitre,epn,surfmailles
 
!  Feces
   Feces= pxm * fchl * (vol**deuxtier)-pa
   Fpop=Feces*nbhuitre(im,jm)/1000./surfmailles/p_phyto_ChlNratio/((4.189*11.4)/ChlC/1000.)

    !!SR!!       if (im==75.and.jm==25) print*,'FRpop, PFpop, Fpop', FRpop, PFpop, Fpop


!!!!!EVOLUTION DES VARIABLES D'ETAT
!!!=====================================

  !!SR       if ((nbhui1(im,jm).ne.0.0_rsh).and.(d.gt.0.5_rsh)) then
  !!     if ((nbhuitre.ne.0.0_rsh).and.(d.gt.0.5_rsh)) then
  !!   if ((nbhuitre(im,jm).ne.0.0_rsh).and.(d.gt.0.5_rsh)) then

!  Evolution de l'energie des reserves
   dc(iv_oysdeb_res)=(pa-pc)*ibbenth
!	  write(*,*)'dc(iv_oysdeb_res)=',im,jm,dc(iv_oysdeb_res)

!  Evolution de l'energie des structures
   dc(iv_oysdeb_str)=(pg-amaig)*ibbenth
!	  write(*,*)'dc(iv_oysdeb_str)=',im,jm,dc(iv_oysdeb_str)

!  Evolution de l'energie des gonades
   dc(iv_oysdeb_gon)=(pr-ponte-lyse)*ibbenth
!	  if((NRJ_gonades.le.0).and.(dc(iv_oysdeb_gon).lt.0)) dc(iv_oysdeb_gon)=0.
!	  if((NRJ_gonades.gt.0).and.(dc(iv_oysdeb_gon).lt.0)) then
!	     dc(iv_oysdeb_gon)=-min(-dc(iv_oysdeb_gon),NRJ_gonades/dtbio*86400.)
!	  endif
!	  write(*,*)'dc(iv_oysdeb_gon)=',im,jm,dc(iv_oysdeb_gon)
        !  if(ibbenth.ne.0) print*,'DCGNOADES',dc(iv_oysdeb_gon), pr,ponte, lyse,c(iv_oysdeb_gon),c(iv_oysdeb_res),c(iv_oysdeb_str)
!
 !!!!!!VARIABLES DIAGNOSTIQUES
 !!!=====================================
     
   diag_2d(irk_diag(id_oysDEB_FRpop),im,jm)= FRpop*ibbenth !FILTRATION HUITRE
   diag_2d(irk_diag(id_oysDEB_PFpop),im,jm)= (PFpop/epn)*ibbenth !PSEUDOFECES HUITRE
   diag_2d(irk_diag(id_oysDEB_Fpop),im,jm)= (Fpop/epn)*ibbenth !FECES HUITRE
   diag_2d(irk_diag(id_oysDEB_DWtot),im,jm)= DWtot*ibbenth ! poids sec total HUITRE
   diag_2d(irk_diag(id_oysDEB_kchlvble),im,jm)= k_chl*ibbenth !coefficient de demi-saturation chloro variable
!   diag_2d(irk_diag(id_oysDEB_kchlvble),km,im,jm)= k_chlvble*ibbenth !coefficient de demi-saturation chloro variable
   diag_2d(irk_diag(id_oysDEB_ER),im,jm)= ER*ibbenth  !rapport GONADO-SOMATIQUE HUITRE
   diag_2d(irk_diag(id_oysDEB_filtrate),im,jm)= txfilt*ibbenth  !taux de filtration HUITRE
   diag_2d(irk_diag(id_oysDEB_Wtot),im,jm)= (DWtot/0.09/0.2)*ibbenth ! poids total
   diag_2d(irk_diag(id_oysDEB_Istress),im,jm)= ((vol*pm+pj)/(pa+epsilon))*ibbenth !INDICE DE STRESS
   diag_2d(irk_diag(id_oysDEB_Lgtot),im,jm)= Lgtot*ibbenth  !Longueur totale HUITRE
   diag_2d(irk_diag(id_oysDEB_ChlC),im,jm)= ChlC  !rapport carbone/chloro
   diag_2d(irk_diag(id_oysDEB_nbhuit),im,jm)= nbhuitre(im,jm)  !nombre d'huitre


 !+++++++++++++++++++++++++++++++++++++++++++++++
 ! EQUATIONS D EVOLUTION  ! concentration en jour-1
 !+++++++++++++++++++++++++++++++++++++++++++++++
                   
   ! Evolution de l azote des diatomees
   ! ----------------------------------
   dc(iv_phyto_diat_N)=dc(iv_phyto_diat_N)   &
                   -FRpop*ibbenth*c(iv_phyto_diat_N)/(c(iv_phyto_diat_N)+c(iv_phyto_dino_N)+c(iv_phyto_nano_N)+1e-10)

!!!!prise ne compte d'une production microphytobenthique
!!if (d.gt.1.5_rsh.and.d.lt.2.0_rsh.and.ibbenth==1.and.jm.ge.33.and.couvmicrophyto(im,jm)==1) then
!!dc(iv_phyto_diat_N)=dc(iv_phyto_diat_N)+350.0_rsh*ibbenth
!!endif
!!if (d.gt.1.5_rsh.and.d.lt.2.0_rsh.and.ibbenth==1.and.jm.lt.33.and.couvmicrophyto(im,jm)==1) then
!!dc(iv_phyto_diat_N)=dc(iv_phyto_diat_N)+200.0_rsh*ibbenth
!!endif
!!!if (d.gt.1.5_rsh.and.d.lt.2.0_rsh.and.ibbenth==1.and.jm.lt.32.and.im.lt.57.and.couvchloro(im,jm)==1) then
!!if (d.gt.1.5_rsh.and.d.lt.2.0_rsh.and.ibbenth==1.and.jm.lt.24.and.im.lt.118.and.couvmicrophyto(im,jm).gt.0.0_rsh) then
!!dc(iv_phyto_diat_N)=dc(iv_phyto_diat_N)+10.0_rsh*ibbenth
!!endif

   
   ! Evolution de l azote des dinoflagelles
   ! --------------------------------------
   dc(iv_phyto_dino_N)=dc(iv_phyto_dino_N)   &
                    -FRpop*ibbenth*c(iv_phyto_dino_N)/(c(iv_phyto_diat_N)+c(iv_phyto_dino_N)+c(iv_phyto_nano_N)+1e-10)

   
   ! Evolution de l azote detritique benthique
   ! --------------------------------------
    !dc(iv_detr_N)=dc(iv_detr_N)+(egestotNhui/epn-consoNdet2)*ibbenth
!!    dc(iv_detr_N)=dc(iv_detr_N)+(PFpop+Fpop)   !&  !!!!SR
   dc(iv_benth_N)=dc(iv_benth_N)+(PFpop+Fpop)*ibbenth
!!    attention aux unites!!!!!
!!              -reminazdeteau*0.1*c(iv_detr_N)


   ! Evolution du phosphore detritique benthique
   ! ---------------------------------
    !dc(iv_detr_P)=dc(iv_detr_P)+(egestotPhui/epn-consoPdet2)*ibbenth 
!!   dc(iv_detr_P)=dc(iv_detr_P)+(PFpop+Fpop)/16.0_rsh
   dc(iv_benth_P)=dc(iv_benth_P)+(PFpop+Fpop)/16.0_rsh*ibbenth
    !!!!SR
!!    attention aux unites!!!!!
   ! Evolution de la silice detritique benthique
   dc(iv_benth_Si)=dc(iv_benth_Si)     &
                +rapsiaz*FRpop*ibbenth*c(iv_phyto_diat_N)/(c(iv_phyto_diat_N)+c(iv_phyto_dino_N)+c(iv_phyto_nano_N)+1e-10)*epn


   ! Evolution de l azote du nano_pico_phytoplancton  (micromolN.l-1)
   ! -----------------------------------------------------------------
   dc(iv_phyto_nano_N)=dc(iv_phyto_nano_N)  &
                    -FRpop*ibbenth*c(iv_phyto_nano_N)/(c(iv_phyto_diat_N)+c(iv_phyto_dino_N)+c(iv_phyto_nano_N)+1e-10)
    
    ! Evolution de l ammonium
   ! ----------------------------------------------------------------- 
   !! excrethuit=1./1000.*24.*PDS*nbhuitre/volmaille
    
    !   dc(11)=reminazdeteau*c(7)-fractionnh4*(rationdiat*c(5)+
    !  $  rationdino*c(6))-xnitrifeau*c(11)+
    ! $  excretionzoo*(c(12)/12.)*(bioparam(58)/bioparam(59))
    ! $  +fluxbenthN(im,jm)*ibbenth/epn
    ! $  +reminazdeteau*0.1*c(16)*ibbenth/epn
!c     $  +reminazdeteau*c(16)*ibbenth/epn
!     &  +(excretmoul+excrethuit+excretcrep)*ibbenth

ELSE
   dc(iv_oysdeb_res)=0.0_rsh
   dc(iv_oysdeb_str)=0.0_rsh
   dc(iv_oysdeb_gon)=0.0_rsh

ENDIF

  END SUBROUTINE incellwat_oysterDEB
#endif

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#if defined key_oyster_SFG
 SUBROUTINE incellwat_oysterSFG(km,im,jm,xe,c,dc)
   !&E---------------------------------------------------------------------
   !&E                 ***  ROUTINE incellwat_oyster  ***
   !&E
   !&E ** Purpose : Calcul des variations dues a la croissance de l'huître
   !&E              creuse
   !&E              
   !&E
   !&E ** Description :
   !&E
   !&E ** Called by :
   !&E
   !&E ** External calls :
   !&E
   !&E ** Reference :
   !&E
   !&E ** History :
   !&E       !          (L. Barillé) Original code
   !&E       
   !&E       
   !&E
   !&E---------------------------------------------------------------------
   !! * Modules used
   USE comsubstance, ONLY : extinction,alumplafond,nbhuitre
   USE comvars2d,    ONLY : h0,t,jjulien,imois,iheure,iminu,isec,ian,ijour,hm,dx,dy
   USE toolgeom,     ONLY : f_dzu
   USE comsubstance, ONLY : tpostpontecoq,tpostpontegam
   USE comsubstance, ONLY : cmes_3dmgl

   !! * Arguments
   INTEGER, INTENT( in )                  ::   km,im,jm      ! ocean spatial-step index
   REAL(KIND=rsh),             INTENT(in) :: xe     !ssh
   REAL(KIND=rsh),DIMENSION(:),INTENT(in) :: c
   REAL(KIND=rsh),DIMENSION(:),INTENT(inout) :: dc

   !! * Local declarations
   REAL(KIND=rlg)                            :: tjour
   ! variables huitre
   ! ---------------
   REAL(KIND=rsh) :: colmat,effettemper,filtmes,filt,filt1,filt2
   REAL(KIND=rsh) :: cphyto,cdetri,retention,consochla,consodet,consoi
   REAL(KIND=rsh) :: consochla2,consodet2,consoNdet2,consoPdet2,volmaille
   REAL(KIND=rsh) :: val1,PFi,cingesi,susp,repsom,susp0,a,b
   REAL(KIND=rsh) :: cingestot,pseudet,ORGAFRING
   REAL(KIND=rsh) :: ER,BILAN,MAXSOMA,BILANSOM,BILANREP,EAT,pseudi
   REAL(KIND=rsh) :: psfchla2,psfdet2,psfNdet2,psfPdet2,egestotNhui,egestotPhui
   REAL(KIND=rsh) :: cmop,consorg,pseuorg,EAorg,ABSorg,fecesorg,ABSorg1
   REAL(KIND=rsh) :: ORGCOQUILLE,GAINSOMA,GAINREPROD,GAINCOQUILLE,PONTE,GAINSOMA2,GAINREPROD2
   REAL(KIND=rsh) :: BILANCOQ,BILANSOMA,RESP1,RESP,PForg,COQGAM,CINGESORG
   INTEGER        :: GAMETO,REPOSGAMETE,REPOSCOQUILLE,SEUILPONTE

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


   tjour=jjulien+iheure/24.0_rlg+iminu/1440.0_rlg+isec/86400.0_rlg

! Filtration - filt2 (L.h-1.ind-1):
! Fonction du poids de l'individu, de la temperature et des MES (effet colmatage)

   IF(nbhuitre(im,jm).ne.0) THEN
      volmaille=epn*dx(im,jm)*dy(im,jm)

      ! susp=c(iv_spim)*1000.0_rsh 
      susp=cmes_3dmgl(km,im,jm)
      colmat=min(0.0_rsh,(p_oys_colmat_thr-susp))

      effettemper=p_oys_paramfiltr*(temper-p_oys_tempopt_filtr)**2
      IF (susp > p_oys_sestfiltr_thr) THEN
            filtmes=-p_oys_kfilt*susp+p_oys_yfilt
      ELSE
            filtmes=p_oys_stdfiltr
      ENDIF
      filt=filtmes-effettemper
      IF (filt < 0.0_rsh) THEN
          filt=0.0_rsh
      ENDIF
        
      filt1=filt * c(iv_oys_so)**p_oys_allfiltr
      filt2=filt1*exp(p_oys_colmparam*colmat)   !!!*p_oys_subratio

      IF(d <= 0.6_rsh) THEN
          filt2=0.0_rsh
      ENDIF

      diag_2d(irk_diag(id_oys_filt),im,jm)=filt2*ibbenth

!!          concentration en chlorophylle  en µg/L
!          cphyto=(c(iv_phyto_diat_N)+c(iv_phyto_dino_N)+c(iv_phyto_nano_N))*p_phyto_ChlNratio
!         cphyto=(abs(cphyto)+cphyto)*0.5
! Essai avec la valeur de chlorophylle calculee precedemment
! mis en commentaire par Benedicte car cela semble faux
!      cphyto=id_totalchl !!!!
       cphyto=diag_3d_wat(irk_diag(id_totalchl),km,im,jm)  !! ATTENTION c est exprime en chlorophylle

!! c(iv_detr_N) en umolN/L --> µmol de carbone --> cdetri en mg/L

      cdetri=(c(iv_detr_N)/16+c(iv_detr_P))*106.0_rsh*12.0_rsh/1000.0_rsh/p_oys_CtoDWratio
      cdetri=(abs(cdetri)+cdetri)*0.5
      IF (susp <= p_oys_retmin_thr) THEN
              retention=-p_oys_kreten*susp+p_oys_yreten
      ELSE
              retention=p_oys_retmin
      ENDIF


!! concentration en MOP  en mg/L          
      IF(imois .GE. 1 .AND. imois .LT. 6) THEN
        !!     cmop=(0.088_rsh*cphyto+0.52_rsh)*1.2_rsh
             cmop=(0.088_rsh*cphyto+0.52_rsh)*1.1_rsh
      ENDIF
        
      IF(imois .GE. 6 .AND. imois <= 12) THEN
        !!     cmop=(0.088_rsh*cphyto+0.52_rsh)*1.2_rsh
             cmop=(0.088_rsh*cphyto+0.52_rsh)*1.1_rsh
      ENDIF
              

!! Consommation phyto - en ugChla.h-1.ind-1          =umolNdiat.h-1.ind-1 :
 !         consochla=filt2*cphyto 

!!! Consommation MOP - en mg.h-1
      consorg=filt2*cmop

        
!! Consommation detritique et inorganique en mg.h-1.ind-1
      consodet=filt2*cdetri*retention
      consoi=filt2*susp*retention
        

!!ce qui est consomme disparait du systeme --> cf dc(iv_phyto_diat_N) et dc(iv_detr_N)
!! consochla en umolNdiat.h-1.ind-1 --> consochla2 en j-1

      consochla2=filt2*nbhuitre(im,jm)*24.0_rsh/1000.0_rsh/volmaille

!! consodet en mg.h-1.ind-1 --> consodet2 en mg.j-1
      consodet2=consodet*nbhuitre(im,jm)*24
        
!! consoNdet2 et consoPdet2 en µmol.l-1.jour-1           
      consoNdet2=consodet2*p_oys_CtoDWratio /12.0_rsh*16.0_rsh/106.0_rsh/volmaille
      consoPdet2=consodet2*p_oys_CtoDWratio /12.0_rsh/106.0_rsh/volmaille           

!! Efficacite de selection de la Chla, du detritique et de l'inorganique
      val1=min(0.0_rsh,(p_oys_prodpseufec_thr-susp))


      PForg=p_oys_prodpseufeco_lev*(1.0_rsh-exp(p_oys_pseufeco_exp*val1))

      PFi=p_oys_prodpseufeci_lev*(1.0_rsh-exp(p_oys_pseufeci_exp*val1))
        

      IF(PForg > 1.0_rsh)  THEN
          PForg=1.0_rsh
      ENDIF
      IF(PForg < 0.0_rsh)  THEN
          PForg=0.0_rsh
      ENDIF
      IF(PFi > 1.0_rsh)  THEN
          PFi=1.0_rsh
      ENDIF
      IF(PFi < 0.0_rsh)  THEN
          PFi=0.0_rsh
      ENDIF


!!Ingestion individuelle de la Chla, du detrique et de l'inorganique

      cingesorg=(1.0_rsh-PForg)*consorg
      cingesi=(1.0_rsh-PFi)*consoi
      cingestot=cingesorg+cingesi

!! Production de PF :
!! pseuchla en ugChla.ind-1.h-1 = umolNdiat.h-1.ind-1
!! pseudet en mg.ind-1.h-1

      pseuorg=max(0.0_rsh,consorg-cingesorg)
      pseudi=max(0.0_rsh,consoi-cingesi)

        
!! Absorption de la partie ingeree et production de feces :
!!feceschla en ugChla.ind-1.h-1 = umolNdiat.h-1.ind-1
!!fecesdet en mg.ind-1.h-1
 !!! ORGAFRING entre 0 et 100
!print*,'cingesorg cingestot',cingesorg,cingestot       
      ORGAFRING=((cingesorg)/(cingestot+epsilon))*100
      diag_2d(irk_diag(id_oys_orgafring),im,jm)=ORGAFRING*ibbenth
        
!!! EAorg entre 0 et 1
      EAorg=p_oys_absmaxmop*(1.0_rsh-exp(-p_oys_absdet*ORGAFRING))

      IF(EAorg < 0.0_rsh) THEN
          EAorg=0.0_rsh
      ENDIF
      IF(EAorg > 1.0_rsh) THEN
          EAorg=1.0_rsh
      ENDIF
        
!!!Energie absorbée

      ABSorg1=(EAorg*cingesorg/1000.0_rsh)!!*p_oys_subratio

        !!!énergie totale absorbée en g MOP.jour-1   
      ABSorg=ABSorg1*24.0_rsh!!!*p_oys_subratio
        
      diag_2d(irk_diag(id_oys_absorg),im,jm)=ABSorg*ibbenth
        
!!!!production de feces en mg MOP.h-1.ind-1
!!! note Benedicte : dans la doc de Morgan (rapport Gerricao, il y a ici un rapport 1000 comme pour ABSorg ??????????????????????????????
      fecesorg=((1.0_rsh-EAorg)*cingesorg)!!*p_oys_subratio
        
!! Egestion totale de N detritique :
!! pseuorg et fecesorg en mg.ind-1.h-1 --> psfdet2 en mmolNdet.j-1.m-2

      psfdet2=(pseuorg+fecesorg)*nbhuitre(im,jm)*24.0_rsh
        
      psfNdet2=psfdet2*p_oys_CtoDWratio /12.0_rsh*16.0_rsh/106.0_rsh/(dx(im,jm)*dy(im,jm))
      psfPdet2=psfdet2*p_oys_CtoDWratio /12.0_rsh/106.0_rsh/(dx(im,jm)*dy(im,jm))
        
      egestotNhui=psfNdet2
      egestotPhui=psfPdet2


!!!!!!RESPIRATION!!!!!!!!!!

!! Reformulation de la loi de Bougrier en g de MOP.jour-1

      RESP1=(0.2_rsh*exp(0.1_rsh*temper))*(c(iv_oys_so)**p_oys_allres)*0.7_rsh/1000.0_rsh!!*p_oys_subratio/1000.0_rsh
      RESP=RESP1*24.0_rsh!!!*p_oys_subratio

      diag_2d(irk_diag(id_oys_resp),im,jm)=RESP*ibbenth

!!!!!!!!!!!!!!!!!!
!!!!!!REPARTITION DE L'ENERGIE ET CROISSANCE!!!!!!!
!!initialisation de REPOSCOQUILLE ET REPOSGAMETE
      IF (tpostpontecoq(im,jm)==1.0_rlg) THEN
          REPOSCOQUILLE=0
      ENDIF
      IF (tpostpontegam(im,jm)==1.0_rlg) THEN
          REPOSGAMETE=0
      ENDIF
!!!!!!!!!!!!!!!!!!

!!!!!pas en période post-ponte
      IF (tpostpontecoq(im,jm) < 0.0_rlg) THEN
         REPOSCOQUILLE=0
      ENDIF
      IF (tpostpontegam(im,jm) < 0.0_rlg) THEN
         REPOSGAMETE=0
      ENDIF
!!!!!!!!!!!!!!!!!!!!!!!!!!!!

!!!!!periode post-ponte de 15 jours durant laquelle la vitellogenese est impossible
!!!!!ARRET post-ponte de la croissance coquillere pendant 7 jours

      IF (tpostpontegam(im,jm) > 0.0_rlg .AND. (tjour-tpostpontegam(im,jm)) <= 15.0_rlg) THEN
          REPOSGAMETE=1
      ENDIF
      IF (tpostpontecoq(im,jm) > 0.0_rlg .AND. (tjour-tpostpontecoq(im,jm)) <= 7.0_rlg) THEN
          REPOSCOQUILLE=1
      ENDIF
!!!!!!!!!!!!!!!

      IF (tpostpontecoq(im,jm) > 0.0_rlg .AND. (tjour-tpostpontecoq(im,jm)) > 7.0_rlg) THEN
          REPOSCOQUILLE=0
          tpostpontecoq(im,jm)=-1.0_rlg
      ENDIF

      IF (tpostpontegam(im,jm) > 0.0_rlg .AND. (tjour-tpostpontegam(im,jm)) > 15.0_rlg) THEN
         REPOSGAMETE=0
          tpostpontegam(im,jm)=-1.0_rlg
      ENDIF

      repsom=c(iv_oys_go)/(c(iv_oys_so)+epsilon)

!!!GAMETO=2 période de vitellogenèse
!!!GAMETO=1 hors période de vitellogenèse
      IF(temper > 8.0_rsh .AND. repsom < 0.6_rsh .AND. REPOSGAMETE==0) THEN
         GAMETO=2
      ELSE
         GAMETO=1
      ENDIF

!!!DECLENCHEMENT DE LA PONTE
      IF(temper > 19_rsh .AND. repsom > 0.35_rsh .AND. REPOSGAMETE==0) THEN
         SEUILPONTE=1
         tpostpontecoq(im,jm)=tjour
         tpostpontegam(im,jm)=tjour
      ELSE
         SEUILPONTE=0
      ENDIF

      IF (ibbenth==1) THEN
         diag_2d(irk_diag(id_oys_tcoq),im,jm)=tpostpontecoq(im,jm)
         diag_2d(irk_diag(id_oys_tgam),im,jm)=tpostpontegam(im,jm)
      ENDIF

!!!PONTE
      IF (SEUILPONTE==1) THEN
         PONTE=(0.6_rsh*c(iv_oys_go)*3600.0_rsh*24.0_rsh)/dtbio
      ELSE
         PONTE=0.0_rsh
      ENDIF

      IF (ibbenth==1) THEN
         diag_2d(irk_diag(id_oys_ponte),im,jm)=diag_2d(irk_diag(id_oys_ponte),im,jm)+PONTE*dtbio/(3600.0_rsh*24.0_rsh)
      ENDIF

!!!REPARTITION ENERGIE!!!

!!! COQUILLE
      IF (REPOSCOQUILLE == 1) THEN
        COQGAM=0.0_rsh
      ELSE
        COQGAM=1/GAMETO
      ENDIF

      IF ((ABSORG-RESP) > 0.0_rsh) THEN
        ORGCOQUILLE=(0.05_rsh*ABSORG)*COQGAM
      ELSE
        ORGCOQUILLE=0.0_rsh
      ENDIF

      GAINCOQUILLE=ORGCOQUILLE*100.0_rsh

      dc(iv_oys_co)=GAINCOQUILLE*ibbenth

!!!!!!!!!!!!
!!!SOMA

      BILANCOQ=ABSORG-ORGCOQUILLE

      IF (c(iv_oys_so) < 1.5_rsh) THEN
        MAXSOMA=0.0293_rsh*c(iv_oys_so)
      ELSE
        MAXSOMA=0.044_rsh
      ENDIF
      BILANSOMA=min(MAXSOMA,BILANCOQ)

      IF (GAMETO==2 .OR. repsom < 0.2_rsh) THEN
        GAINSOMA=BILANSOMA-RESP
      ELSE IF (GAMETO==1) THEN
        GAINSOMA=BILANSOMA
      ENDIF


!!!!!!!!!!!!
!!!REPROD
      IF (GAMETO==2 .OR. repsom < 0.2_rsh) THEN
        GAINREPROD=BILANCOQ-BILANSOMA
      ELSE IF (GAMETO==1) THEN
        GAINREPROD=BILANCOQ-(BILANSOMA+RESP)
      ENDIF

      dc(iv_oys_so)=GAINSOMA*ibbenth
      dc(iv_oys_go)=(GAINREPROD-PONTE)*ibbenth

!!!!!!!!!!!!
      diag_2d(irk_diag(id_oys_gaincoq),im,jm)=GAINCOQUILLE*ibbenth
      diag_2d(irk_diag(id_oys_gainsoma),im,jm)=GAINSOMA*ibbenth
      diag_2d(irk_diag(id_oys_gainrepr),im,jm)=GAINREPROD*ibbenth
      diag_2d(irk_diag(id_oys_bilansoma),im,jm)=BILANSOMA*ibbenth
      diag_2d(irk_diag(id_oys_bilancoq),im,jm)=BILANCOQ*ibbenth

      diag_2d(irk_diag(id_oys_gameto),im,jm)=GAMETO
      diag_2d(irk_diag(id_oys_seuilponte),im,jm)=SEUILPONTE
      diag_2d(irk_diag(id_oys_reposcoq),im,jm)=REPOSCOQUILLE
      diag_2d(irk_diag(id_oys_reposgam),im,jm)=REPOSGAMETE



      !+++++++++++++++++++++++++++++++++++++++++++++++
      ! EQUATIONS D EVOLUTION  ! concentration en jour-1
      !+++++++++++++++++++++++++++++++++++++++++++++++

      ! Evolution de l azote des diatomees
      ! ----------------------------------
      dc(iv_phyto_diat_N)=dc(iv_phyto_diat_N)-consochla2*c(iv_phyto_diat_N)*ibbenth


      ! Evolution de l azote des dinoflagelles
      ! --------------------------------------
      dc(iv_phyto_dino_N)=dc(iv_phyto_dino_N)-consochla2*c(iv_phyto_dino_N)*ibbenth
      
      ! Evolution de l azote detritique
      ! --------------------------------------
      dc(iv_detr_N)=dc(iv_detr_N)+(egestotNhui/epn-consoNdet2)*ibbenth

      ! Evolution du phosphore detritique
      ! ---------------------------------
      dc(iv_detr_P)=dc(iv_detr_P)+(egestotPhui/epn-consoPdet2)*ibbenth
             
      ! Evolution de l'azote du nano_pico_phytoplancton  (micromolN.l-1)
      ! -----------------------------------------------------------------
      dc(iv_phyto_nano_N)=dc(iv_phyto_nano_N)-consochla2*c(iv_phyto_nano_N)*ibbenth


   ENDIF

  END SUBROUTINE incellwat_oysterSFG

   !!======================================================================
#endif


#endif
 END MODULE
