#include atoms_red
#include HETCHEM.spc
#include HETCHEM.eqn

#include ../boxmox/wrapper

#LOOKATALL

#INLINE F90_GLOBAL

  ! global variables used by special rate constants of this mechanism

  ! air/water concentration (molecules/cm3)
  REAL(KIND=dp)      :: c_m

#ENDINLINE

#INLINE F90_RCONST

  c_m = C(ind_M)

#ENDINLINE

#INLINE F90_RATES

REAL(KIND=dp) FUNCTION SFC_REACTION(TEMP, SAD, MW, GAMMA)

  REAL(KIND=dp), INTENT(IN)  :: TEMP, & ! temperature [K]
                                SAD, &  ! aerosol surface area [m2/m3]
                                MW, &   ! molecular weight [kg/mol]
                                GAMMA   ! uptake coeff. [-]

  REAL(KIND=dp)              :: OMEGA

  ! mean molecular velocity (m/s)
  OMEGA = 1.455e2 * SQRT(TEMP / (MW * 1e3))

  ! first order uptake, Fuchs and Sutugin, 1971
  ! dCg = 1/4 * gamma * |v_mol| * A
  SFC_REACTION = 0.25 * GAMMA * OMEGA * SAD

END FUNCTION SFC_REACTION

REAL(kind=dp) FUNCTION JPL_TROE( k0_300K, n, kinf_300K, m, base, temp, cair )

!------------------------------------------------------------
!	... dummy arguments
!------------------------------------------------------------
    REAL(kind=dp), INTENT(IN) :: base      ! base exponent
    REAL(kind=dp), INTENT(IN) :: temp      ! temperature [K]
    REAL(kind=dp), INTENT(IN) :: cair      ! air concentration [molecules/cm3]
    REAL(kind=dp), INTENT(IN) :: k0_300K   ! low pressure limit at 300 K
    REAL(kind=dp), INTENT(IN) :: n         ! exponent for low pressure limit
    REAL(kind=dp), INTENT(IN) :: kinf_300K ! high pressure limit at 300 K
    REAL(kind=dp), INTENT(IN) :: m         ! exponent for high pressure limit

!------------------------------------------------------------
!	... local variables
!------------------------------------------------------------
    REAL(kind=dp)  :: zt_help, k0_T, kinf_T, k_ratio

    zt_help = 300._dp/temp
    k0_T    = k0_300K   * zt_help**(n) * cair ! k_0   at current T
    kinf_T  = kinf_300K * zt_help**(m)        ! k_inf at current T
    k_ratio = k0_T/kinf_T

    JPL_TROE = k0_T/(1._dp + k_ratio)*base**(1._dp/(1._dp + LOG10(k_ratio)**2))

END FUNCTION JPL_TROE

  REAL(KIND=dp) FUNCTION usr_N2O5_M( temp, c_m )

    REAL(KIND=dp), INTENT(IN) :: temp
    REAL(KIND=dp), INTENT(IN) :: c_m

    usr_N2O5_M = TROEE(3.333e26_dp, 10900._dp, 2.2e-30_dp, 4.4_dp, &
                       1.4e-12_dp , .7_dp , TEMP, C_M ) /c_m

END FUNCTION usr_N2O5_M

#ENDINLINE
