!-----------------------------------------------------------------------
!
      MODULE SUAQ_hetchem_uptake
!
!-----------------------------------------------------------------------
!Models-3/CMAQ code adapted for MONARCH
!
!***********************************************************************
!   Portions of Models-3/CMAQ software were developed or based on      *
!   information from various groups: Federal Government employees,     *
!   contractors working on a United States Government contract, and    *
!   non-Federal sources (including research institutions).  These      *
!   research institutions have given the Government permission to      *
!   use, prepare derivative works, and distribute copies of their      *
!   work in Models-3/CMAQ to the public and to permit others to do     *
!   so.  EPA therefore grants similar permissions for use of the       *
!   Models-3/CMAQ software, but users are requested to provide copies  *
!   of derivative works to the Government without restrictions as to   *
!   use by others.  Users are responsible for acquiring their own      *
!   copies of commercial software associated with Models-3/CMAQ and    *
!   for complying with vendor requirements.  Software copyrights by    *
!   the MCNC Environmental Modeling Center are used with their         *
!   permissions subject to the above restrictions.                     *
!***********************************************************************
!-----------------------------------------------------------------------
!
!***  HETEROGENEOUS N2O5 UPTAKE COEFFICIENT CALCULATION
!***  FROM CMAQv5.0
!
!-----------------------------------------------------------------------
! HISTORY LOG:
!
!   2017-04-13  Jorba - Creation of the module.
!-----------------------------------------------------------------------
!
!      PUBLIC :: N2O5PROB,CRHB,IRHX
!
!------------------------------------------------------------------------
!
      CONTAINS
!
!------------------------------------------------------------------------
!
!:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
      REAL FUNCTION N2O5PROB( TEMP, RH, ANH4, ANO3, ASO4, GPARAM )

!  Calculates the N2O5 heterogeneous reaction probability, which is the
!  fraction of collisions between a gaseous N2O5 molecule and a particle
!  surface that leads to nitrate production.  In the literature, this
!  probability is commonly referred to with the Greek letter, GAMMA.  To
!  avoid conflicts with the intrinsic GAMMA function on some compilers,
!  we refer to the reaction probability as N2O5PROB in this function.

!  A variety of parameterizations of N2O5PROB are available in this
!  function.  Users may select among the different parameterizations
!  by changing the input argument, GPARAM.  This argument may take on
!  the following values (see code for further details):
!     1. Constant value of 0.1 based on Dentener & Crutzen (1993)
!     2. Function of particle SO4 and NO3, based on Riemer et al. (2003)
!     3. Function of RH, Temp, and particle composition, based on a
!        combination of parameterizations by Evans & Jacob (2005) and
!        Riemer et al. (2003)
!  If GPARAM matches none of the above values, the default calculation
!  of N2O5PROB is a function of RH, T, particle composition, and phase
!  state, based on the parameterization by Davis et al. (2008).

!  Key Subroutines Called: none

!  Key Functions Called: CRHB, IRHX

!  Revision History:
!    First version was coded in November 2007 by Dr. Prakash Bhave
!    using excerpts of the HETCHEM subroutine, which contained only
!    one option for computing N2O5PROB (i.e., GPARAM = 3).
!
!  PVB 11/03/07 Removed code that sets N2O5PROB to zero when RH < 1%.
!
!  PVB 11/05/07 Corrected GPARAM = 3 option to fix the typographical
!               error in the paper by Evans & Jacob (2005), which was
!               found by Dr. Jerry Davis.
!
!  PVB 04/11/08 Updated formulas for LAM1 & LAM2 based on revised paper
!               by Davis et al. (2008).  Added APNDX flag so users may
!               switch between base parameterization and the alternative
!               discussed in Appendix A by Davis et al.  Set default
!               parameterization to match equations in Appendix A.
!               Reduced all regression coefficients by one decimal place
!               for consistency with revised paper.
!
!  JTK 04/17/08 Moved molar mass to AERO_INFO.f
!
!  SH  12/08/09 Use new Fortran modules (aero_data, met_data) in lieu of
!               CBLK array and AERO_INFO module
!
!  SH  03/10/11 Renamed met_data to aeromet_data
 
! References:
!   1. Dentener, F.J. and P.J. Crutzen, Reaction of N2O5 on tropospheric
!      aerosols: Impact of global distributions of NOx, O3, and OH.
!      J. Geophys. Res., Vol 98, 7149-7163, 1993.
!
!   2. Riemer, N., H. Vogel, B. Vogel, B. Schell, I. Ackermann, C.
!      Kessler, and H. Hass, Impact of the heterogeneous hydrolysis
!      of N2O5 on chemistry of nitrate aerosol formation in the lower
!      troposphere under photosmog conditions.  J. Geophys. Res., Vol
!      108, No D4, 4144, doi:10.1029/2002JD002436, 2003.
!
!   3. Evans, M.J. and D.J. Jacob, Impact of new laboratory studies of
!      N2O5 hydrolysis on global model budgets of tropospheric nitrogen
!      oxides, ozone, and OH.  Geophys. Res. Lett., 32, L09813,
!      doi:10.1029/2005GL022469, 2005.
!
!   4. Davis, J.M., P.V. Bhave, and K.M. Foley, Parameterization of N2O5
!      reaction probabilities on the surface of particles containing
!      ammonium, sulfate, and nitrate.  Atmos. Chem. Phys., 2008, in
!      press.
!
!   5. Mentel, T.F., M. Sohn, and A. Wahner, Nitrate effect in the
!      heterogeneous hydrolysis of dinitrogen pentoxide on aqueous
!      aerosols.  Phys. Chem. Chem. Phys., 1, 5451-5457, 1999.
!-----------------------------------------------------------------------

!      USE AERO_DATA
!      USE AEROMET_DATA   ! Includes CONST.EXT

      IMPLICIT NONE

! *** Arguments
      REAL,    INTENT( IN ) :: TEMP     ! Air temperature [ K ]
      REAL,    INTENT( IN ) :: RH       ! Fractional relative humidity
      REAL,    INTENT( IN ) :: ANH4     ! Total ammonium [ug/m3]
      REAL,    INTENT( IN ) :: ANO3     ! Total nitrate [ug/m3]
      REAL,    INTENT( IN ) :: ASO4     ! Total sulfate [ug/m3]
      INTEGER, INTENT( IN ) :: GPARAM   ! switch to select among
                                        !  parameterizations

! *** Parameters

! *** switch for alternative parameterization of LAM1 & LAM2
!     when APNDX = .TRUE. (default), Eqs A1-A2 are used for reaction
!     probability on aqueous sulfate particles.  Alternatively, set
!     APNDX = .FALSE. to use Eqs 4-5.
      LOGICAL, PARAMETER :: APNDX = .TRUE.

! *** Local Variables

! *** chemical species concentrations [ug/m3]
!      REAL      ANH4      ! i+j mode ammonium
!      REAL      ANO3      ! i+j mode nitrate
!      REAL      ASO4      ! i+j mode sulfate

! *** variables for computing N2O5PROB when GPARAM = 2 or 3
      REAL      FRACSO4   ! aerosol mass ratio of SO4/(SO4+NO3)
      REAL      GAMMA1    ! upper limit of rxn prob
      REAL      GAMMA2    ! lower limit of rxn prob
      REAL      ALPHA     ! RH-dependent parameter to compute GAMMA1
      REAL      BETA      ! TEMP-dependent parameter to compute GAMMA1

! *** variables for default parameterization of N2O5PROB
!      LOGICAL   CRHB      ! function to determine if RH is below CRH
      LOGICAL   CRYSTAL   ! true if ambient RH < CRH, false otherwise
!      LOGICAL   IRHX      ! function to determine whether RH exceeds IRH
      LOGICAL   FROZEN    ! true if ambient RH > IRH, false otherwise
      REAL      NNO3      ! particle-phase nitrate [micromoles/m3]
      REAL      NSO4      ! particle-phase sulfate [micromoles/m3]
      REAL      NNH4      ! particle-phase ammonium [micromoles/m3]
      REAL      NANI      ! particle-phase anions [micromoles/m3]
      REAL      X1        ! mole fraction of ammonium bisulfate
      REAL      X2        ! mole fraction of ammonium sulfate
      REAL      X3        ! mole fraction of ammonium nitrate
      REAL      LAM1      ! logit transformation of N2O5PROB on
      REAL      LAM2      !   aqueous NH4HSO4 [LAM1], aqueous (NH4)2SO4
      REAL      LAM3      !   [LAM2], aqueous NH4NO3 [LAM3], and dry
      REAL      LAMD      !   sulfate-containing particles [LAMD]
      REAL      GAM1      ! reaction probability on aqueous NH4HSO4
      REAL      GAM2      !    "          "      "     "    (NH4)2SO4
      REAL      GAM3      !    "          "      "     "    NH4NO3
      REAL      GAMD      !    "          "      " dry sulfate particles
      REAL      T293,T291 ! temperature threshold variables
      REAL      RH46      ! RH threshold variable

! *** molecular weights
      REAL, PARAMETER :: MW_NH4=18.039  ! [g/mol]
      REAL, PARAMETER :: MW_NO3=62.0049 ! [g/mol]
      REAL, PARAMETER :: MW_SO4=96.06   ! [g/mol]

! *** statement function for inverting the logit transformation given
!     in Eq 7 by Davis et al (2008)
      REAL      LOGITINV  ! statement function
      REAL      XX        ! dummy argument for LOGITINV
      LOGITINV( XX ) = 1.0 / ( 1.0 + EXP( -XX ) )

!-----------------------------------------------------------------------

! *** retrieve particle-phase ammonium, nitrate, and sulfate [ug/m3]
!      ANH4 = aerospc_conc( ANH4_IDX,1 ) + aerospc_conc( ANH4_IDX,2 )
!      ANO3 = aerospc_conc( ANO3_IDX,1 ) + aerospc_conc( ANO3_IDX,2 )
!      ASO4 = aerospc_conc( ASO4_IDX,1 ) + aerospc_conc( ASO4_IDX,2 )

! *** User Option: GPARAM = 1
!     Dentener and Crutzen (1993) recommended a constant value of
!     N2O5PROB = 0.1, which was used in CMAQ prior to ver4.3.  In more
!     recent literature, this value has been recognized as an upper
!     estimate of N2O5PROB so it should not be used for routine
!     simulations.  It is included here only to facilitate sensitivity
!     studies by CMAQ model users.
      IF ( GPARAM .EQ. 1 ) THEN
         N2O5PROB = 0.1
         RETURN
      END IF

! *** User Options: GPARAM = 2 and 3
!     These options both employ Eqs 2 and 3 by Riemer et al (2003), in
!     which N2O5PROB varies according to the particle-phase sulfate and
!     nitrate concentrations.  In both options, the NO3 effect (i.e.,
!     GAMMA1/GAMMA2) is assumed to be a factor of 10 based on Mentel et
!     al (1999) and Riemer et al (2003).
!      - When GPARAM = 2, upper limit of N2O5PROB is fixed at 0.02.
!        This was the default setting in CMAQ ver4.3 through ver4.5.1.
!      - When GPARAM = 3, upper limit of N2O5PROB is a function of
!        ambient TEMP & RH based on the "Sulfate" equation in Table 1
!        by Evans & Jacob (2005).  This was the default setting in CMAQ
!        ver4.6.  After that release, a typographical error was found
!        in the published equation of Evans & Jacob (2005) so this code
!        has been corrected accordingly.
      IF ( GPARAM .EQ. 2 ) THEN

         GAMMA1 = 0.02

      ELSE IF ( GPARAM .EQ. 3 ) THEN

!        In this function, RH is in fractional units whereas the
!        published equation by Evans&Jacob refers to RH as a percentage.
         ALPHA = 2.79E-4 + RH * ( 1.3E-2 + RH * ( -3.43E-2 + 7.52E-2 * RH ) )

!        To fix the typographical error by Evans & Jacob (2005), the
!        sign of BETA has been switched in this code.
         IF ( TEMP .LT. 282.0 ) THEN
            GAMMA1 = 3.0199517 * ALPHA   ! (10.0 ** 0.48) * ALPHA
         ELSE
            BETA  = 0.04 * ( 294.0 - TEMP )
            GAMMA1 = ALPHA * ( 10.0 ** BETA )
         END IF

      END IF

      IF ( ( GPARAM .EQ. 2 ) .OR. ( GPARAM .EQ. 3 ) ) THEN

         IF ( ANO3 .GT. 0.0 ) THEN
            FRACSO4 = ASO4 / ( ASO4 + ANO3 )
         ELSE
            FRACSO4 = 1.0
         END IF

         GAMMA2 = 0.1 * GAMMA1
         N2O5PROB = GAMMA2 + FRACSO4 * ( GAMMA1 - GAMMA2 )
         RETURN

      END IF

! *** Default setting in current version of CMAQ:
!     This code implements the paramaterization given in Eq 15 by Davis
!     et al (2008), in which N2O5PROB is a function of RH, TEMP,
!     particle composition, and phase state.  Note: In this function, RH
!     is in fractional units whereas the published equations refer to RH
!     as a percentage.

! *** Check whether the ambient RH is below the crystallization RH for
!     the given inorganic particle composition.
      NNO3 = ANO3 / MW_NO3 !aerospc_mw( ANO3_IDX )
      NSO4 = ASO4 / MW_SO4 !aerospc_mw( ASO4_IDX )
      NNH4 = ANH4 / MW_NH4 !aerospc_mw( ANH4_IDX )
      CRYSTAL = CRHB( RH, NSO4, NNO3, NNH4, .TRUE. )

! *** Check whether the ambient RH exceeds the RH of ice formation.
      FROZEN = IRHX( TEMP, RH )

! *** Set N2O5PROB to constant value if particles contain ice, based on
!     Eq 14 by Davis et al (2008).
      IF ( FROZEN ) THEN
         N2O5PROB = 0.02                               ! Eq 14

! *** Compute mole-fractional-composition of particles based on Eq 11 by
!     Davis et al (2008).
      ELSE
         NNO3 = ANO3 / MW_NO3 !aerospc_mw( ANO3_IDX )
         NSO4 = ASO4 / MW_SO4 !aerospc_mw( ASO4_IDX )
         NNH4 = ANH4 / MW_NH4 !aerospc_mw( ANH4_IDX )
         NANI = NNO3 + NSO4

         X3 = NNO3 / NANI
         X2 = MAX( 0.0, MIN( 1.0 - X3, NNH4/NANI - 1.0 ) )
         X1 = 1.0 - ( X2 + X3 )

! *** Compute N2O5PROB on pure NH4NO3 particles using Eqs 6 and 8 by
!     Davis et al (2008).
         LAM3 = -8.10774 + 4.902 * RH                  ! Eq 6
         GAM3 = MIN( LOGITINV( LAM3 ), 0.0154 )        ! Eq 8

! *** Compute N2O5PROB on dry particles using Eqs 9, 10, and 13 by
!     Davis et al (2008).
         IF ( CRYSTAL ) THEN
            T293     = MAX( 0.0, TEMP - 293.0 )
            LAMD     = -6.13376 + 3.592 * RH         & ! Eq 9
                      - 0.19688 * T293
            GAMD     = MIN( LOGITINV( LAMD ), 0.0124 ) ! Eq 10
            N2O5PROB = ( X1 + X2 ) * GAMD            & ! Eq 13
                      + X3 * MIN( GAMD, GAM3 )

! *** Compute N2O5PROB on aqeuous particles using Eqs A1, A2, 8, and 12
!     by Davis et al (2008).  When APNDX = .TRUE. (default), Eqs A1-A2
!     are used for reaction probability on aqueous sulfate particles.
!     Switch to .FALSE. if Eqs 4-5 are desired.  See Appendix A by
!     Davis et al. (2008) for a discussion of these options.
         ELSE
            T291 = MAX( 0.0, TEMP - 291.0 )
            IF ( APNDX ) THEN
               RH46 = MIN( 0.0, RH - 0.46 )
               LAM2  = -3.64849 + 9.553 * RH46         ! Eq A2
               LAM1  = LAM2 + 0.97579                & ! Eqs A1 & A2
                      - 0.20427 * T291
            ELSE
               LAM1  = -4.10612 + 2.386 * RH         & ! Eq 4
                      - 0.23771 * T291
               LAM2  = LAM1 - 0.80570                & ! Eqs 4 & 5
                      + 0.10225 * T291
            END IF
            GAM1     = MIN( LOGITINV( LAM1 ), 0.08585 )! Eq 8
            GAM2     = MIN( LOGITINV( LAM2 ), 0.053 )  ! Eq 8
            N2O5PROB = ( X1 * GAM1 )                 & ! Eq 12
                     + ( X2 * GAM2 )                 &
                     + ( X3 * GAM3 )

         END IF

      END IF

      RETURN

      END FUNCTION N2O5PROB

!:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
      LOGICAL FUNCTION CRHB( RH, NSO4, NNO3, NNH4, COMPLETE )

!  Determines whether the ambient RH is below the crystallization relative
!  humidity (CRH).  The output of this logical function is .TRUE. when the
!  ambient RH is below the CRH and .FALSE. otherwise.  The empirical
!  equations developed by Martin et al (2003) are applied to determine the
!  CRH for a given mixture of sulfate, nitrate, and ammonium.  Though those
!  equations are validated only at 293K, they are applied at all ambient
!  temperatures because insufficient data exist to estimate the temperature
!  dependence of the CRH of mixed sulfate-nitrate-ammonium particles.
!  Users can opt to compute either the RH of initial crystal formation
! (i.e., COMPLETE .EQ. .FALSE.) or the RH of compete crystallization (i.e.,
!  COMPLETE .EQ. .TRUE.).

!  References:
!   1. Martin, S.T., J.C. Schlenker, A. Malinowski, H.-M. Hung, and
!      Y. Rudich, Crystallization of atmospheric sulfate-nitrate-
!      ammonium particles.  Geophys. Res. Lett., 30(21), 2102,
!      doi:10.1029/2003GL017930, 2003.

!  Revision History:
!    PVB 11/05/07 Coded the first version.
!    JTK 04/17/08 Moved molar mass to AERO_INFO.f
!    SH  12/08/09 Use aero_data module in lieu of CBLK array

!-----------------------------------------------------------------------

!      USE aero_data

      IMPLICIT NONE

! *** Arguments
      REAL, INTENT( IN )    :: RH        ! fractional relative humidity
      REAL, INTENT( IN )    :: NSO4      ! sulfate concentration [micromoles/m3]
      REAL, INTENT( IN )    :: NNO3      ! nitrate concentration [micromoles/m3]
      REAL, INTENT( IN )    :: NNH4      ! ammonium concentration [micromoles/m3]
      LOGICAL, INTENT( IN ) :: COMPLETE  ! flag deciding which CRH
                                         !  equation to use

! *** Local Variables

! *** chemical species concentrations [micromoles/m3]
!      REAL      NSO4     ! i+j mode sulfate
!      REAL      NNO3     ! i+j mode nitrate
!      REAL      NNH4     ! i+j mode ammonium
      REAL      NCAT     ! i+j mode cations
      REAL      NANI     ! i+j mode anions

! *** cation and anion mole fractions used in CRH equations
      REAL X         ! ammonium/cation mole fraction: NH4/(NH4+H)
      REAL Y         ! sulfate/anion mole fraction:  SO4/(SO4+NO3)

! *** intermediate variables used in CRH equations
      REAL X2, XY, Y2, X2Y, XY2, RDEN

      REAL CRH       ! crystallization RH (fractional units)

!-----------------------------------------------------------------------

! *** Experimental measurements of CRH are lacking below 1% relative
!     humidity.  Under those very dry conditions, we assume that
!     particles will crystallize.  Equations by Martin et al (2003) for
!     internally-mixed sulfate-nitrate-ammonium particles yield maximum
!     CRH values of 35.03% and 34.50% for initial crystal formation and
!     complete crystallization, respectively.  Therefore, the full CRH
!     calculation can be avoided when RH > 35.1%.
      IF ( RH .LE. 0.01 ) THEN
         CRHB = .TRUE.    ! ambient particles are dry
         RETURN
      ELSE IF ( RH .GT. 0.351 ) THEN
         CRHB = .FALSE.   ! ambient RH exceeds CRH
         RETURN
      END IF

! *** calculate total particle-phase composition [micromoles/m3]
!      NNO3 = ( aerospc_conc( ANO3_IDX,1 ) + aerospc_conc( ANO3_IDX,2 ) )
!     &     / aerospc_mw( ANO3_IDX )
!      NSO4 = ( aerospc_conc( ASO4_IDX,1 ) + aerospc_conc( ASO4_IDX,2 ) )
!     &     / aerospc_mw( ASO4_IDX )
!      NNH4 = ( aerospc_conc( ANH4_IDX,1 ) + aerospc_conc( ANH4_IDX,2 ) )
!     &     / aerospc_mw( ANH4_IDX )

! *** calculate total anion and cation concentrations
      NCAT = MAX( NNH4, 2.0 * NSO4 + NNO3 )
      NANI = NNO3 + NSO4

! *** calculate ammonium and sulfate mole fractions
      X = NNH4 / NCAT
      Y = NSO4 / NANI

! *** Experimental data of Martin et al. (2003) show no crystal
!     formation when X < 0.50 or Y < 0.22.  For these particle
!     compositions, the full CRH calculation can be avoided.
!
!     Note: Martin's equation for initial crystal formation returns
!     very large CRH values when X and Y approach zero.  However,
!     those values were verified to be erroneous by personal
!     communication with Dr. Scot Martin on Aug. 30, 2007.
      IF ( ( X .LT. 0.50 ) .OR. ( Y .LT. 0.22 ) ) THEN
         CRHB = .FALSE.   ! ambient RH exceeds CRH
         RETURN
      END IF

! *** store some terms needed to evaluate the CRH equations
      X2   = X * X
      XY   = X * Y
      X2Y  = X2 * Y
      Y2   = Y * Y
      XY2  = X * Y2
      RDEN = 1.0 / ( 25.0 + ( X - 0.7 ) * ( Y - 0.5 ) )

! *** calculate CRH using empirical equations of Martin et al (2003)
      IF ( COMPLETE ) THEN

         CRH = 3143.44 + (63.07 * X) + (0.114 * X2) + (87.97 * Y)  &
             - (125.73 * XY) + (0.586 * X2Y) + (0.95 * Y2)         &
             - (1.384 * XY2) - (79692.5 * RDEN)

      ELSE

         CRH = -697.908 - (15.351 * X) + (0.43 * X2) - (22.11 * Y) &
             + (33.882 * XY) - (1.818 * X2Y) + (0.772 * Y2)        &
             - (1.636 * XY2) + (17707.6 * RDEN)

      END IF

! *** set value of the output variable, CRHB
      IF ( RH .LE. CRH ) THEN
         CRHB = .TRUE.    ! ambient particles are dry
      ELSE
         CRHB = .FALSE.   ! ambient RH exceeds CRH
      END IF

      RETURN

      END FUNCTION CRHB

!:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
      LOGICAL FUNCTION IRHX( TEMP, RH )

!  Determines whether the ambient RH has exceeded the RH of ice formation,
!  based on the Goff-Gratch equations as given by List (1984).

!  References:
!   1. Goff, J.A. and S. Gratch, Low-pressure properties of water from
!      -160 to 212 F, in Transactions of the American Society of Heating
!      and Ventilating Engineers, pp 95-122, New York, 1946.
!   2. List, R.J. (editor), Smithsonian Meteorological Tables, 5th ed.
!      pp. 350, 1984.

!  Revision History:
!   PVB 11/06/07 Coded the first version.
!-----------------------------------------------------------------------

      IMPLICIT NONE

! *** Arguments
      REAL, INTENT( IN ) ::  TEMP        ! Air temperature [ K ]
      REAL, INTENT( IN ) ::  RH          ! Fractional relative humidity

! *** Parameters

! *** The following values are taken from List (1984).  Note that
!     these differ slightly from the original equations published by
!     Goff & Gratch (1946).  We also note that T0 and PST differ
!     slightly from STDTEMP and STDATMPA in the AERO_INFO module.
!     Here, we use 273.16 K and 1013.246 hPa to be consistent with
!     the Goff-Gratch equations as given by List (1984).
      REAL, PARAMETER :: TST = 373.16    ! steam-point temperature, K
      REAL, PARAMETER :: T0  = 273.16    ! ice-point temperature, K
      REAL, PARAMETER :: PST = 1013.246  ! sat vapor pres at TST, hPa
      REAL, PARAMETER :: P0  = 6.1071    ! sat vapor pres at T0, hPa

      REAL, PARAMETER :: LOGPST = 3.0057149     ! LOG10(PST)
      REAL, PARAMETER :: LOGP0  = 0.78583503    ! LOG10(P0)

! *** Local Variables

! *** estimates of IRH using a polynomial approximation
      REAL      EIRH   ! IRH approximated using 2nd order polynomial
      REAL      LIRH   ! lower-bound of IRH
      REAL      UIRH   ! upper-bound of IRH

! *** variables used to compute RH of ice formation
      REAL      TSDT, TDTS, T0DT, TDT0  ! intermediate variables
      REAL      LOGPW  ! log10 of saturation vapor pressure over H2O
      REAL      LOGPI  ! log10 of saturation vapor pressure over ice

      REAL      IRH    ! fractional RH at which ice forms

!-----------------------------------------------------------------------

      IF ( TEMP .LT. T0 ) THEN

! *** To mitigate the computational expense associated with Goff-Gratch
!     equations, use a 2nd order polynomial function to approximate IRH.
!     This approximation, EIRH, matches IRH from the full Goff-Gratch
!     equations within 0.004 over the entire low-temperature range of
!     interest (200 to 275K) and is used for screening purposes.
         EIRH = 1.61299 + TEMP * ( 4.4117437E-5 * TEMP - 1.4293888E-2 )
         LIRH = EIRH - 0.005
         UIRH = EIRH + 0.005

         IF ( RH .GT. UIRH ) THEN
            IRHX = .TRUE.
         ELSE IF ( RH .LT. LIRH ) THEN
            IRHX = .FALSE.
         ELSE

! *** Compute IRH using Goff-Gratch equations as given by List (1984)
            TSDT  = TST / TEMP
            TDTS  = TEMP / TST
            T0DT  = T0 / TEMP
            TDT0  = TEMP / T0
            LOGPW = -7.90298 * ( TSDT - 1.0 )                               &
                  + 5.02808 * LOG10( TSDT )                                 &
                  - 1.3816E-7 * ( 10.0 ** ( 11.344 *  (1.0 - TDTS) ) -1.0 ) &
                  + 8.1328E-3 * ( 10.0 ** ( -3.49149* (TSDT - 1.0) ) -1.0 ) &
                  + LOGPST
            LOGPI = -9.09718 * (T0DT - 1.0)                                 &
                  - 3.56654 * LOG10( T0DT )                                 &
                  + .876793 * (1.0 - TDT0)                                  &
                  + LOGP0
            IRH   = 10.0 ** ( LOGPI - LOGPW )

            IF ( RH .GT. IRH ) THEN
               IRHX = .TRUE.
            ELSE
               IRHX = .FALSE.
            END IF

         END IF
      ELSE
         IRHX = .FALSE.
      END IF

      RETURN

      END FUNCTION IRHX

      END MODULE SUAQ_hetchem_uptake
!
!-----------------------------------------------------------------------

