 MODULE contaradsigz

#if defined key_substance && defined key_contaminant
   !!======================================================================
   !!                   ***  MODULE  contaradsigz  ***
   !! Functions which give correspondance between z and sigma
   !!  and subroutine for computing attenuation of radiation in water column 
   !!  isuued from key_biolo (on biolodynzwat) but useful for contaminant
   !!======================================================================
   !! * Modules used 
   USE parameters,   ONLY : rsh,rlg,kmax,valmanq,limin,limax,ljmin,ljmax, &
                            limaxp2,ljmaxp2,ljminp2,ljmaxm1,liminm2,ljminm2
   USE comvars2d,    ONLY : h0,iscreenlog,ig,id
   IMPLICIT NONE
   PRIVATE

   !! * Accessibility
   PUBLIC radz_reduce

   !! * Interface

   !! * Shared module variables

   !! * Private variables

 CONTAINS

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

  SUBROUTINE radz_reduce(xe)

   !&E---------------------------------------------------------------------
   !&E                 ***  ROUTINE  ***
   !&E
   !&E ** Purpose : Computing attenuation of radiation threw water column
   !&E          useful if one reaction has a cinetic which depends on radiation
   !&E
   !&E ** Description :
   !&E
   !&E ** Called by :
   !&E
   !&E ** External calls :
   !&E
   !&E
   !&E ** Reference :
   !&E
   !&E ** History :
   !&E       !  issued for key_biolo
   !&E       !  2011-11  (V. Garnier) Spatial extension of ssh(liminm2:limaxp2,ljminm2:ljmaxp2)
   !&E
   !&E---------------------------------------------------------------------
   !! * Modules used
   USE cometemp, ONLY : coext
   USE sflxatm,  ONLY : rad
   USE comvars2d,    ONLY : h0
   USE comsubstance, ONLY : extinction,attenuation,alumplafond
   USE toolgeom,     ONLY : f_dzu
   IMPLICIT NONE
   !! * Arguments
   REAL(KIND=rsh),DIMENSION(liminm2:limaxp2,ljminm2:ljmaxp2),INTENT( in )   :: xe

   !! * Local declarations
   REAL(KIND=rsh) :: hz_u,dzu
   INTEGER        :: k,i,j

   DO j=ljminp2,ljmaxm1
     DO i=MAX0(limin,ig(j)+1),MIN0(limax,id(j)-1)
       IF (h0(i,j) /= -valmanq ) THEN
         DO k=1,kmax
!!!!         coext=max(0.154_rsh,extinction(k,i,j))
           dzu=f_dzu(h0(i,j),xe(i,j),k,i,j)
           attenuation(k,i,j)=EXP(-coext*dzu)
         END DO
       
         alumplafond(kmax,i,j)=1.0_rsh
         DO k=kmax-1,1,-1
           alumplafond(k,i,j)=alumplafond(k+1,i,j)*attenuation(k+1,i,j)
         END DO
       END IF
     END DO
   END DO
   
  END SUBROUTINE radz_reduce

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

#endif
 END MODULE
