      subroutine soachem(iout,tempk,press,dthr,rk,
     &                   avgox,cprec,dcprec,cCG,cNV,yfac,
     &                   nfam,avgsen,sen_prec,sen_CG,sen_NV,lddm)
c
c----CAMx v7.40 260801
c
c-----------------------------------------------------------------------
c   Description:
c     This routine solves the oxidation reactions for SOA precursors
c     assuming first-order decay and constant oxidant concentrations
c
c      Copyright Ramboll
c
c     Input arguments:
c        iout     standard output file unit
c        tempk    cell temperature [K]
c        press    cell pressure [mb]
c        dthr     time duration to be integrated [hr]
c        rk       gas-phase rate constants [ppm-n hr-1]
c        avgox    average oxidant concentrations [ppm]
c                 1 - O; 2 - OH; 3 - O3; 4 - NO3; 5 - NO; 6 - HO2
c        cprec    precursor concentrations [ppm]
c                 1 - BNZA; 2 - HPAR; 3 - TOLA; 4  - XYLA; 5 - IVOA; 6 - IVC1
c                 7 - IVC2; 8 - SVOA; 9 - ISP ; 10 - TRP ; 11 - APN; 12 - SQT
c                13 - FVC1
c        cCG      CG species concentrations [ppm]
c                 1 - ACG2; 2 - ACG1; 3 - BCG2; 4 - BCG1
c        cNV      NV products concentration [ppm]
c                 1 - CGA (anthro); 2 - CGB (bio)
c        yfac     weighted yield factors
c        nfam     number of sensitivity families
c        avgsen   average sensitivities of oxidants [ppm]
c        sen_prec sensitivities of precursors [ppm]
c        sen_CG   sensitivities of CGs [ppm]
c        sen_NV   sensitivities of NVs [ppm]
c        lddm     logical flag for DDM sensitivities
c
c     Output arguments:
c        cprec    precursor concentrations [ppm]
c        dcprec   change in precursor concentrations [ppm]
c        cCG      CG species concentrations [ppm]
c        cNV      NV products concentration [ppm]
c        yfac     3 weighted yields, fh, fn for each precursor
c        sen_prec sensitivities of precursors [ppm]
c        sen_CG   sensitivities of CGs [ppm]
c        sen_NV   sensitivities of NVs [ppm]
c
c-----------------------------------------------------------------------
c   LOG:
c-----------------------------------------------------------------------
c
c     03/22/06  --bkoo--  Original development
c     06/20/06  --bkoo--  2-product model for isoprene
c     08/23/13  --bkoo--  Added code for DDM-PM
c     03/18/14  --bkoo--  Revised for benzene SOA
c     08/25/16  --bkoo--  Updated for new SOAP (SOAP2 begins)
c     04/22/19  --gy----  Updated hi/low NOx rate constants
c     04/05/24  --cemery-- Added SVOA (SOAP3 begins)
c     05/16/24  --lhuang-- Differentiate SOA yields from TERP and
c                          add SOA yields from APIN 
c     05/23/24  --gy----  Use rate constats from the gas-phase mechanism
c                         except IVOA & SVOA rate constants are local and
c                         RO2 rate constants are local and follow MCM
c     04/26/25 --gwilson-- Add SOAP precursor species IVC1, IVC2, HPAR
c     03/31/26  --gy----  Add FVC1 precursor from fire emissions
c
c-----------------------------------------------------------------------
c
      implicit none
      include 'soap.inc'
      include 'soap3.inc'
      include 'chmdat.inc'
c
c     soap.inc passes pointers iksoap() to access rate constants rk()
c            1 - BNZA + OH; 2 - TOLA + OH;   3 - XYLA + OH 
c            4 - ISP + OH ;  5 - ISP + O3;   6 - ISP + NO3
c            7 - TRP + OH ;  8 - TRP + O3;   9 - TRP + NO3
c           10 - SQT + OH ; 11 - SQT + O3;  12 - SQT + NO3
c           13 - APN + OH ; 14 - APN + O3;  15 - APN + NO3
c           16 - HPAR + OH; 17 - FVC1 + OH; 18 - FVC1 + O3
c           19 - FVC1 + NO3
c
      integer :: iout
      real    :: tempk,press,dthr
      real    :: avgox(NOXID),cprec(NPREC_S),cCG(NSOAP),cNV(NNVOL)
      real    :: dcprec(NPREC_S)
      real    :: yfac(5,NPREC_S)

      real    :: rk(*)

      real, parameter    :: eps = 1.e-12
c
c======================== DDM Begin =======================
c
      integer :: nfam,ifam
      real    :: avgsen(nfam,NOXID)
      real    :: sen_prec(nfam,NPREC)
      real    :: sen_CG(nfam,NCG)
      real    :: sen_NV(nfam,NNV)
      real    :: srh(nfam)
      real    :: ssumk,srk1(NOXID),sdprec
      logical :: lddm, luse_sqt, luse_apin, luse_hpar, luse_fvc1
c
c======================== DDM End =======================
c
c     [1/ppm-hr] = [cm3/molecule-sec]*3600*(6.022e23*1.e-12/8.314)*(P[Pa]/T[K])
      real, parameter  :: s2h = 3600.0 ! seconds per hour
      real, parameter  :: cf0 = 2.608e14 ! 3600*(6.022e23*1.e-12/8.314)
      real, parameter  :: rkivoa = 1.34E-11 ! OH + IVOA rate constant
      real, parameter  :: rkivc1 = 1.34E-11 ! OH + IVC1 rate constant
      real, parameter  :: rkivc2 = 1.34E-11 ! OH + IVC2 rate constant
      real, parameter  :: rksvoa = 1.6E-11  ! OH + SVOA rate constant
      real    :: cfac
      real    :: rk1(NOXID), rh, rl, ra, fh, fl, fn, sumk, dprec, cfrac
      real    :: dfac
      integer :: i, j, k
c 
c----Entry Point
c
      yfac(:,:) = 0.0
      dcprec = 0.0
c
c----check status of SQT, APIN and HPAR
c
      luse_sqt  = .FALSE.
      luse_apin = .FALSE.
      luse_hpar = .FALSE.
      luse_fvc1 = .FALSE.
      if(iksoap(10) .GT. 0) luse_sqt  = .TRUE.
      if(iksoap(13) .GT. 0) luse_apin = .TRUE.
      if(iksoap(16) .GT. 0) luse_hpar = .TRUE.
      if(iksoap(17) .GT. 0) luse_fvc1 = .TRUE.
c
c-----Conversion factor for 2nd-order rate constants from cms to ppm-hr
c
      cfac = cf0 * (press*100./tempk) ! [1/ppm-hr] = cfac * [cm3/molecule-sec]
c
c-----Re-set NV product concentrations to zero
c
      cNV = 0.0
c
c-----NOx-dependent pathways for HPAR, if active
c
      if( luse_hpar ) then
         rh = 2.70e-12*exp(360.0/tempk)*cfac * avgox(IOX_NO )   ! HPAR RO2 + NO rate (hr-1)
         rl = 2.39e-12*exp(1300.0/tempk)*cfac * avgox(IOX_HO2)  ! HPAR RO2 + HO2 rate (hr-1)
         ra = 2.20e+08*exp(-6200.0/tempk)*s2h                   ! HPAR RO autoxidation rate (hr-1)
         fh = (rh / (rh + rl)) * (rh / (rh + ra + rl))
         fl = 1.0 - fh
         yfac(1,ISOAP_HPAR) = y_h(1,ISOAP_HPAR)*fh + y_l(1,ISOAP_HPAR)*fl
         yfac(2,ISOAP_HPAR) = y_h(2,ISOAP_HPAR)*fh + y_l(2,ISOAP_HPAR)*fl
         yfac(3,ISOAP_HPAR) = y_h(3,ISOAP_HPAR)*fh + y_l(3,ISOAP_HPAR)*fl
         yfac(4,ISOAP_HPAR) = fh
c
c======================== DDM Begin =======================
c
         if ( lddm ) then
           do ifam = 1, nfam
             sen_NV(ifam,:) = 0.0 ! <- cNV reset
             srh(ifam) = (fl*rh - fh*rl) / (rh + rl)
           enddo
         endif
c
c======================== DDM End =======================
c
         rk1(IOX_OH ) = rk(iksoap(16)) * avgox(IOX_OH ) ! HPAR + OH rate (hr-1)
         cfrac = 1. - exp(-rk1(IOX_OH )*dthr)
         dprec = cprec(ISOAP_HPAR) * cfrac
         dcprec(ISOAP_HPAR) = -dprec
         if (dprec.gt.eps) then
           cprec(ISOAP_HPAR) = cprec(ISOAP_HPAR) - dprec
           cCG(ICG_ACG2) = cCG(ICG_ACG2) + dprec * yfac(1,ISOAP_HPAR)
           cCG(ICG_ACG1) = cCG(ICG_ACG1) + dprec * yfac(2,ISOAP_HPAR)
           cNV(INV_ANTH) = cNV(INV_ANTH) + dprec * yfac(3,ISOAP_HPAR)
c
c======================== DDM Begin =======================
c
           if ( lddm ) then
             do ifam = 1, nfam
               srk1(IOX_OH) = rk(iksoap(16)) * avgsen(ifam,IOX_OH)
               sdprec = sen_prec(ifam,ISOAP_HPAR) * cfrac
     &             + cprec(ISOAP_HPAR) * dthr * srk1(IOX_OH) ! because cprec has been updated
               sen_prec(ifam,ISOAP_HPAR) = sen_prec(ifam,ISOAP_HPAR) - sdprec
               sen_CG(ifam,1) = sen_CG(ifam,1) + sdprec * yfac(1,ISOAP_HPAR)
     &                                      + dprec *
     &            ( y_h(1,ISOAP_HPAR)*srh(ifam) - y_l(1,ISOAP_HPAR)*srh(ifam) )
               sen_CG(ifam,2) = sen_CG(ifam,2) + sdprec * yfac(2,ISOAP_HPAR)
     &                                      + dprec *
     &            ( y_h(2,ISOAP_HPAR)*srh(ifam) - y_l(2,ISOAP_HPAR)*srh(ifam) )
                 sen_NV(ifam,1) = sen_NV(ifam,1) + sdprec * yfac(3,ISOAP_HPAR)
     &                                      + dprec *
     &            ( y_h(3,ISOAP_HPAR)*srh(ifam) - y_l(3,ISOAP_HPAR)*srh(ifam) )
             enddo
c
c======================== DDM End =======================
c
           endif
         endif
      endif   ! end check of luse_hpar
c
c-----NOx-dependent pathways for aromatics
c
      rh = 2.70e-12*exp(360.0/tempk)*cfac * avgox(IOX_NO )   ! aromatic RO2 + NO rate (hr-1)
      rl = 2.39e-12*exp(1300.0/tempk)*cfac * avgox(IOX_HO2)  ! aromatic RO2 + HO2 rate (hr-1)
      fh = rh / (rh + rl)
      fl = 1.0 - fh

      yfac(1,ISOAP_BNZA) = y_h(1,ISOAP_BNZA)*fh + y_l(1,ISOAP_BNZA)*fl
      yfac(2,ISOAP_BNZA) = y_h(2,ISOAP_BNZA)*fh + y_l(2,ISOAP_BNZA)*fl
      yfac(3,ISOAP_BNZA) = y_h(3,ISOAP_BNZA)*fh + y_l(3,ISOAP_BNZA)*fl
      yfac(4,ISOAP_BNZA) = fh

      yfac(1,ISOAP_TOLA) = y_h(1,ISOAP_TOLA)*fh + y_l(1,ISOAP_TOLA)*fl
      yfac(2,ISOAP_TOLA) = y_h(2,ISOAP_TOLA)*fh + y_l(2,ISOAP_TOLA)*fl
      yfac(3,ISOAP_TOLA) = y_h(3,ISOAP_TOLA)*fh + y_l(3,ISOAP_TOLA)*fl
      yfac(4,ISOAP_TOLA) = fh

      yfac(1,ISOAP_XYLA) = y_h(1,ISOAP_XYLA)*fh + y_l(1,ISOAP_XYLA)*fl
      yfac(2,ISOAP_XYLA) = y_h(2,ISOAP_XYLA)*fh + y_l(2,ISOAP_XYLA)*fl
      yfac(3,ISOAP_XYLA) = y_h(3,ISOAP_XYLA)*fh + y_l(3,ISOAP_XYLA)*fl
      yfac(4,ISOAP_XYLA) = fh
c
c======================== DDM Begin =======================
c
      if ( lddm ) then
        do ifam = 1, nfam
          sen_NV(ifam,:) = 0.0 ! <- cNV reset
          srh(ifam) = (fl*rh - fh*rl) / (rh + rl)
        enddo
      endif
c
c======================== DDM End =======================
c
c     BNZA

      rk1(IOX_OH ) = rk(iksoap(1)) * avgox(IOX_OH ) ! BNZA + OH rate (hr-1)
      cfrac = 1. - exp(-rk1(IOX_OH )*dthr)
      dprec = cprec(ISOAP_BNZA) * cfrac
      dcprec(ISOAP_BNZA) = -dprec
      if (dprec.gt.eps) then
        cprec(ISOAP_BNZA) = cprec(ISOAP_BNZA) - dprec
        cCG(ICG_ACG2) = cCG(ICG_ACG2) + dprec * yfac(1,ISOAP_BNZA)
        cCG(ICG_ACG1) = cCG(ICG_ACG1) + dprec * yfac(2,ISOAP_BNZA)
        cNV(INV_ANTH) = cNV(INV_ANTH) + dprec * yfac(3,ISOAP_BNZA)
c
c======================== DDM Begin =======================
c
        if ( lddm ) then
          do ifam = 1, nfam
            srk1(IOX_OH) = rk(iksoap(1)) * avgsen(ifam,IOX_OH)
            sdprec = sen_prec(ifam,ISOAP_BNZA) * cfrac
     &             + cprec(ISOAP_BNZA) * dthr * srk1(IOX_OH) ! because cprec has been updated
            sen_prec(ifam,ISOAP_BNZA) = sen_prec(ifam,ISOAP_BNZA) - sdprec
            sen_CG(ifam,1) = sen_CG(ifam,1) + sdprec * yfac(1,ISOAP_BNZA)
     &                                      + dprec *
     &            ( y_h(1,ISOAP_BNZA)*srh(ifam) - y_l(1,ISOAP_BNZA)*srh(ifam) )
            sen_CG(ifam,2) = sen_CG(ifam,2) + sdprec * yfac(2,ISOAP_BNZA)
     &                                      + dprec *
     &            ( y_h(2,ISOAP_BNZA)*srh(ifam) - y_l(2,ISOAP_BNZA)*srh(ifam) )
            sen_NV(ifam,1) = sen_NV(ifam,1) + sdprec * yfac(3,ISOAP_BNZA)
     &                                      + dprec *
     &            ( y_h(3,ISOAP_BNZA)*srh(ifam) - y_l(3,ISOAP_BNZA)*srh(ifam) )
          enddo
        endif
c
c======================== DDM End =======================
c
      endif
 
c     TOLA

      rk1(IOX_OH ) = rk(iksoap(2)) * avgox(IOX_OH ) ! TOLA + OH rate (hr-1)
      cfrac = 1. - exp(-rk1(IOX_OH )*dthr)
      dprec = cprec(ISOAP_TOLA) * cfrac
      dcprec(ISOAP_TOLA) = -dprec
      if (dprec.gt.eps) then
        cprec(ISOAP_TOLA) = cprec(ISOAP_TOLA) - dprec
        cCG(ICG_ACG2) = cCG(ICG_ACG2) + dprec * yfac(1,ISOAP_TOLA)
        cCG(ICG_ACG1) = cCG(ICG_ACG1) + dprec * yfac(2,ISOAP_TOLA)
        cNV(INV_ANTH) = cNV(INV_ANTH) + dprec * yfac(3,ISOAP_TOLA)
c
c======================== DDM Begin =======================
c
        if ( lddm ) then
          do ifam = 1, nfam
            srk1(IOX_OH) = rk(iksoap(2)) * avgsen(ifam,IOX_OH)
            sdprec = sen_prec(ifam,ISOAP_TOLA) * cfrac
     &             + cprec(ISOAP_TOLA) * dthr * srk1(IOX_OH) ! because cprec has been updated
            sen_prec(ifam,ISOAP_TOLA) = sen_prec(ifam,ISOAP_TOLA) - sdprec
            sen_CG(ifam,1) = sen_CG(ifam,1) + sdprec * yfac(1,ISOAP_TOLA)
     &                                      + dprec *
     &            ( y_h(1,ISOAP_TOLA)*srh(ifam) - y_l(1,ISOAP_TOLA)*srh(ifam) )
            sen_CG(ifam,2) = sen_CG(ifam,2) + sdprec * yfac(2,ISOAP_TOLA)
     &                                      + dprec *
     &            ( y_h(2,ISOAP_TOLA)*srh(ifam) - y_l(2,ISOAP_TOLA)*srh(ifam) )
            sen_NV(ifam,1) = sen_NV(ifam,1) + sdprec * yfac(3,ISOAP_TOLA)
     &                                      + dprec *
     &            ( y_h(3,ISOAP_TOLA)*srh(ifam) - y_l(3,ISOAP_TOLA)*srh(ifam) )
          enddo
        endif
c
c======================== DDM End =======================
c
      endif

c     XYLA

      rk1(IOX_OH ) = rk(iksoap(3)) * avgox(IOX_OH ) ! XYLA + OH rate (hr-1)
      cfrac = 1. - exp(-rk1(IOX_OH )*dthr)
      dprec = cprec(ISOAP_XYLA) * cfrac
      dcprec(ISOAP_XYLA) = -dprec
      if (dprec.gt.eps) then
        cprec(ISOAP_XYLA) = cprec(ISOAP_XYLA) - dprec
        cCG(ICG_ACG2) = cCG(ICG_ACG2) + dprec * yfac(1,ISOAP_XYLA)
        cCG(ICG_ACG1) = cCG(ICG_ACG1) + dprec * yfac(2,ISOAP_XYLA)
        cNV(INV_ANTH) = cNV(INV_ANTH) + dprec * yfac(3,ISOAP_XYLA)
c
c======================== DDM Begin =======================
c
        if ( lddm ) then
          do ifam = 1, nfam
            srk1(IOX_OH) = rk(iksoap(3)) * avgsen(ifam,IOX_OH)
            sdprec = sen_prec(ifam,ISOAP_XYLA) * cfrac
     &             + cprec(ISOAP_XYLA) * dthr * srk1(IOX_OH) ! because cprec has been updated
            sen_prec(ifam,ISOAP_XYLA) = sen_prec(ifam,ISOAP_XYLA) - sdprec
            sen_CG(ifam,1) = sen_CG(ifam,1) + sdprec * yfac(1,ISOAP_XYLA)
     &                                      + dprec *
     &            ( y_h(1,ISOAP_XYLA)*srh(ifam) - y_l(1,ISOAP_XYLA)*srh(ifam) )
            sen_CG(ifam,2) = sen_CG(ifam,2) + sdprec * yfac(2,ISOAP_XYLA)
     &                                      + dprec *
     &            ( y_h(2,ISOAP_XYLA)*srh(ifam) - y_l(2,ISOAP_XYLA)*srh(ifam) )
            sen_NV(ifam,1) = sen_NV(ifam,1) + sdprec * yfac(3,ISOAP_XYLA)
     &                                      + dprec *
     &            ( y_h(3,ISOAP_XYLA)*srh(ifam) - y_l(3,ISOAP_XYLA)*srh(ifam) )
          enddo
        endif
c
c======================== DDM End =======================
c
      endif
c
c-----NOx-dependent pathways for ISOP
c
      rk1(IOX_OH ) = rk(iksoap(4)) * avgox(IOX_OH ) ! ISP + OH rate (hr-1)
      rk1(IOX_O3 ) = rk(iksoap(5)) * avgox(IOX_O3 ) ! ISP + O3 rate (hr-1)
      rk1(IOX_NO3) = rk(iksoap(6)) * avgox(IOX_NO3) ! ISP + NO3 rate (hr-1)
      sumk = rk1(IOX_OH ) + rk1(IOX_O3 ) + rk1(IOX_NO3)

      rh = 2.70e-12*exp(360.0/tempk)*cfac * avgox(IOX_NO )  ! isoprene RO2 + NO rate (hr-1)
      rl = 1.93e-12*exp(1300.0/tempk)*cfac * avgox(IOX_HO2) ! isoprene RO2 + HO2 rate (hr-1)

      fn = rk1(IOX_NO3) / sumk
      fh = (1.0 - fn) * rh / (rh + rl)
      fl = 1.0 - fh - fn

      yfac(1,ISOAP_ISP) = y_h(1,ISOAP_ISP)*fh + y_l(1,ISOAP_ISP)*fl + y_n(1,ISOAP_ISP)*fn
      yfac(2,ISOAP_ISP) = y_h(2,ISOAP_ISP)*fh + y_l(2,ISOAP_ISP)*fl + y_n(2,ISOAP_ISP)*fn
      yfac(3,ISOAP_ISP) = y_h(3,ISOAP_ISP)*fh + y_l(3,ISOAP_ISP)*fl + y_n(3,ISOAP_ISP)*fn
      yfac(4,ISOAP_ISP) = fh
      yfac(5,ISOAP_ISP) = fn

      cfrac = 1. - exp(-sumk*dthr)
      dprec = cprec(ISOAP_ISP) * cfrac
      dcprec(ISOAP_ISP) = -dprec
      if (dprec.gt.eps) then
        cprec(ISOAP_ISP) = cprec(ISOAP_ISP) - dprec
        cCG(ICG_BCG2) = cCG(ICG_BCG2) + dprec * yfac(1,ISOAP_ISP)
        cCG(ICG_BCG1) = cCG(ICG_BCG1) + dprec * yfac(2,ISOAP_ISP)
        cNV(INV_BIO) = cNV(INV_BIO) + dprec * yfac(3,ISOAP_ISP)
c
c======================== DDM Begin =======================
c
        if ( lddm ) then
          do ifam = 1, nfam
            srh(ifam) = (fl*rh - fh*rl) / (rh + rl)
            ssumk = rk(iksoap(4)) * avgsen(ifam,IOX_OH)
     &            + rk(iksoap(5)) * avgsen(ifam,IOX_O3)
     &            + rk(iksoap(6)) * avgsen(ifam,IOX_NO3)
            sdprec = sen_prec(ifam,ISOAP_ISP) * cfrac
     &             + cprec(ISOAP_ISP) * dthr * ssumk ! because cprec has been updated
            sen_prec(ifam,ISOAP_ISP) = sen_prec(ifam,ISOAP_ISP) - sdprec

            sen_CG(ifam,3) = sen_CG(ifam,3) + sdprec * yfac(1,ISOAP_ISP)
     &                                      + dprec * (1.0 - fn) *
     &             ( y_h(1,ISOAP_ISP)*srh(ifam) - y_l(1,ISOAP_ISP)*srh(ifam) )
     &                                      + dprec * fn * y_n(1,ISOAP_ISP)

            sen_CG(ifam,4) = sen_CG(ifam,4) + sdprec * yfac(2,ISOAP_ISP)
     &                                      + dprec * (1.0 - fn) *
     &             ( y_h(2,ISOAP_ISP)*srh(ifam) - y_l(2,ISOAP_ISP)*srh(ifam) )
     &                                      + dprec * fn * y_n(2,ISOAP_ISP)

            sen_NV(ifam,2) = sen_NV(ifam,2) + sdprec * yfac(3,ISOAP_ISP)
     &                                      + dprec * (1.0 - fn) *
     &             ( y_h(3,ISOAP_ISP)*srh(ifam) - y_l(3,ISOAP_ISP)*srh(ifam) )
     &                                      + dprec * fn * y_n(3,ISOAP_ISP)
          enddo
        endif
c
c======================== DDM End =======================
c
      endif
c
c-----NOx-dependent pathways for TERP (lumped monoterpenes)
c
      rk1(IOX_OH ) = rk(iksoap(7)) * avgox(IOX_OH ) ! TRP + OH rate (hr-1)
      rk1(IOX_O3 ) = rk(iksoap(8)) * avgox(IOX_O3 ) ! TRP + O3 rate (hr-1)
      rk1(IOX_NO3) = rk(iksoap(9)) * avgox(IOX_NO3) ! TRP + NO3 rate (hr-1)
      sumk = rk1(IOX_OH ) + rk1(IOX_O3 ) + rk1(IOX_NO3)

      rh = 2.70e-12*exp(360.0/tempk)*cfac * avgox(IOX_NO )  ! terpene RO2 + NO rate (hr-1)
      rl = 2.60e-12*exp(1300.0/tempk)*cfac * avgox(IOX_HO2) ! terpene RO2 + HO2 rate (hr-1)

      fn = rk1(IOX_NO3) / sumk
      fh = (1.0 - fn) * rh / (rh + rl)
      fl = 1.0 - fh - fn

      yfac(1,ISOAP_TRP) = y_h(1,ISOAP_TRP)*fh + y_l(1,ISOAP_TRP)*fl + y_n(1,ISOAP_TRP)*fn
      yfac(2,ISOAP_TRP) = y_h(2,ISOAP_TRP)*fh + y_l(2,ISOAP_TRP)*fl + y_n(2,ISOAP_TRP)*fn
      yfac(3,ISOAP_TRP) = y_h(3,ISOAP_TRP)*fh + y_l(3,ISOAP_TRP)*fl + y_n(3,ISOAP_TRP)*fn
      yfac(4,ISOAP_TRP) = fh
      yfac(5,ISOAP_TRP) = fn

      cfrac = 1. - exp(-sumk*dthr)
      dprec = cprec(ISOAP_TRP) * cfrac
      dcprec(ISOAP_TRP) = -dprec
      if (dprec.gt.eps) then
        cprec(ISOAP_TRP) = cprec(ISOAP_TRP) - dprec
        cCG(ICG_BCG2) = cCG(ICG_BCG2) + dprec * yfac(1,ISOAP_TRP)
        cCG(ICG_BCG1) = cCG(ICG_BCG1) + dprec * yfac(2,ISOAP_TRP)
        cNV(INV_BIO) = cNV(INV_BIO) + dprec * yfac(3,ISOAP_TRP)
c
c======================== DDM Begin =======================
c
        if ( lddm ) then
          do ifam = 1, nfam
            srh(ifam) = (fl*rh - fh*rl) / (rh + rl)
            ssumk = rk(iksoap(7)) * avgsen(ifam,IOX_OH)
     &            + rk(iksoap(8)) * avgsen(ifam,IOX_O3)
     &            + rk(iksoap(9)) * avgsen(ifam,IOX_NO3)
            sdprec = sen_prec(ifam,ISOAP_TRP) * cfrac
     &             + cprec(ISOAP_TRP) * dthr * ssumk ! because cprec has been updated
            sen_prec(ifam,ISOAP_TRP) = sen_prec(ifam,ISOAP_TRP) - sdprec

            sen_CG(ifam,3) = sen_CG(ifam,3) + sdprec * yfac(1,ISOAP_TRP)
     &                                      + dprec * (1.0 - fn) *
     &             ( y_h(1,ISOAP_TRP)*srh(ifam) - y_l(1,ISOAP_TRP)*srh(ifam) )
     &                                      + dprec * fn * y_n(1,ISOAP_TRP)

            sen_CG(ifam,4) = sen_CG(ifam,4) + sdprec * yfac(2,ISOAP_TRP)
     &                                      + dprec * (1.0 - fn) *
     &             ( y_h(2,ISOAP_TRP)*srh(ifam) - y_l(2,ISOAP_TRP)*srh(ifam) )
     &                                      + dprec * fn * y_n(2,ISOAP_TRP)

            sen_NV(ifam,2) = sen_NV(ifam,2) + sdprec * yfac(3,ISOAP_TRP)
     &                                      + dprec * (1.0 - fn) *
     &             ( y_h(3,ISOAP_TRP)*srh(ifam) - y_l(3,ISOAP_TRP)*srh(ifam) )
     &                                      + dprec * fn * y_n(3,ISOAP_TRP)
          enddo
        endif
c
c======================== DDM End =======================
c
      endif
c
c-----NOx-dependent pathways for APIN (a-pinene), if active
c
      if( luse_apin ) then

        rk1(IOX_OH ) = rk(iksoap(13)) * avgox(IOX_OH ) ! APN + OH rate (hr-1)
        rk1(IOX_O3 ) = rk(iksoap(14)) * avgox(IOX_O3 ) ! APN + O3 rate (hr-1)
        rk1(IOX_NO3) = rk(iksoap(15)) * avgox(IOX_NO3) ! APN + NO3 rate (hr-1)
        sumk = rk1(IOX_OH ) + rk1(IOX_O3 ) + rk1(IOX_NO3)

        rh = 2.70e-12*exp(360.0/tempk)*cfac * avgox(IOX_NO )  ! a-pinene RO2 + NO rate (hr-1)
        rl = 2.60e-12*exp(1300.0/tempk)*cfac * avgox(IOX_HO2) ! a-pinene RO2 + HO2 rate (hr-1)

        fn = rk1(IOX_NO3) / sumk
        fh = (1.0 - fn) * rh / (rh + rl)
        fl = 1.0 - fh - fn

        yfac(1,ISOAP_APN) = y_h(1,ISOAP_APN)*fh + y_l(1,ISOAP_APN)*fl + y_n(1,ISOAP_APN)*fn
        yfac(2,ISOAP_APN) = y_h(2,ISOAP_APN)*fh + y_l(2,ISOAP_APN)*fl + y_n(2,ISOAP_APN)*fn
        yfac(3,ISOAP_APN) = y_h(3,ISOAP_APN)*fh + y_l(3,ISOAP_APN)*fl + y_n(3,ISOAP_APN)*fn
        yfac(4,ISOAP_APN) = fh
        yfac(5,ISOAP_APN) = fn

        cfrac = 1. - exp(-sumk*dthr)
        dprec = cprec(ISOAP_APN) * cfrac
        dcprec(ISOAP_APN) = -dprec
        if (dprec.gt.eps) then
          cprec(ISOAP_APN) = cprec(ISOAP_APN) - dprec
          cCG(ICG_BCG2) = cCG(ICG_BCG2) + dprec * yfac(1,ISOAP_APN)
          cCG(ICG_BCG1) = cCG(ICG_BCG1) + dprec * yfac(2,ISOAP_APN)
          cNV(INV_BIO) = cNV(INV_BIO) + dprec * yfac(3,ISOAP_APN)
c
c======================== DDM Begin =======================
c
          if ( lddm ) then
            do ifam = 1, nfam
              srh(ifam) = (fl*rh - fh*rl) / (rh + rl)
              ssumk = rk(iksoap(13)) * avgsen(ifam,IOX_OH)
     &              + rk(iksoap(14)) * avgsen(ifam,IOX_O3)
     &              + rk(iksoap(15)) * avgsen(ifam,IOX_NO3)
              sdprec = sen_prec(ifam,ISOAP_APN) * cfrac
     &               + cprec(ISOAP_APN) * dthr * ssumk ! because cprec has been updated
              sen_prec(ifam,ISOAP_APN) = sen_prec(ifam,ISOAP_APN) - sdprec

              sen_CG(ifam,3) = sen_CG(ifam,3) + sdprec * yfac(1,ISOAP_APN)
     &                                        + dprec * (1.0 - fn) *
     &               ( y_h(1,ISOAP_APN)*srh(ifam) - y_l(1,ISOAP_APN)*srh(ifam) )
     &                                        + dprec * fn * y_n(1,ISOAP_APN)

              sen_CG(ifam,4) = sen_CG(ifam,4) + sdprec * yfac(2,ISOAP_APN)
     &                                        + dprec * (1.0 - fn) *
     &               ( y_h(2,ISOAP_APN)*srh(ifam) - y_l(2,ISOAP_APN)*srh(ifam) )
     &                                        + dprec * fn * y_n(2,ISOAP_APN)

              sen_NV(ifam,2) = sen_NV(ifam,2) + sdprec * yfac(3,ISOAP_APN)
     &                                        + dprec * (1.0 - fn) *
     &               ( y_h(3,ISOAP_APN)*srh(ifam) - y_l(3,ISOAP_APN)*srh(ifam) )
     &                                        + dprec * fn * y_n(3,ISOAP_APN)
            enddo
          endif
c
c======================== DDM End =======================
c
        endif
      endif  ! end check of luse_apin
c
c-----NOx-dependent pathways for SQT (lumped sesquiterpenes)
c
c     use local rate constants if unavailable from gas-phase mechanism
c
      if( luse_sqt ) then
        rk1(IOX_OH ) = rk(iksoap(10)) * avgox(IOX_OH ) ! SQT + OH rate (hr-1)
        rk1(IOX_O3 ) = rk(iksoap(11)) * avgox(IOX_O3 ) ! SQT + O3 rate (hr-1)
        rk1(IOX_NO3) = rk(iksoap(12)) * avgox(IOX_NO3) ! SQT + NO3 rate (hr-1)
      else
        rk1(IOX_OH ) = 1.97e-10*cfac * avgox(IOX_OH ) ! MCM v3.2 b-caryophyllene
        rk1(IOX_O3 ) = 1.20e-14*cfac * avgox(IOX_O3 ) ! MCM v3.2 b-caryophyllene
        rk1(IOX_NO3) = 1.90e-11*cfac * avgox(IOX_NO3) ! MCM v3.2 b-caryophyllene
      endif
      sumk = rk1(IOX_OH ) + rk1(IOX_O3 ) + rk1(IOX_NO3)

      rh = 2.70e-12*exp(360.0/tempk)*cfac * avgox(IOX_NO )  ! sesquiterpene RO2 + NO rate (hr-1)
      rl = 2.75e-12*exp(1300.0/tempk)*cfac * avgox(IOX_HO2) ! sesquiterpene RO2 + HO2 rate (hr-1)

      fn = rk1(IOX_NO3) / sumk
      fh = (1.0 - fn) * rh / (rh + rl)
      fl = 1.0 - fh - fn

      yfac(1,ISOAP_SQT) = y_h(1,ISOAP_SQT)*fh + y_l(1,ISOAP_SQT)*fl + y_n(1,ISOAP_SQT)*fn
      yfac(2,ISOAP_SQT) = y_h(2,ISOAP_SQT)*fh + y_l(2,ISOAP_SQT)*fl + y_n(2,ISOAP_SQT)*fn
      yfac(3,ISOAP_SQT) = y_h(3,ISOAP_SQT)*fh + y_l(3,ISOAP_SQT)*fl + y_n(3,ISOAP_SQT)*fn
      yfac(4,ISOAP_SQT) = fh
      yfac(5,ISOAP_SQT) = fn

      cfrac = 1. - exp(-sumk*dthr)
      dprec = cprec(ISOAP_SQT) * cfrac
      dcprec(ISOAP_SQT) = -dprec
      if (dprec.gt.eps) then
        cprec(ISOAP_SQT) = cprec(ISOAP_SQT) - dprec
        cCG(ICG_BCG2) = cCG(ICG_BCG2) + dprec * yfac(1,ISOAP_SQT)
        cCG(ICG_BCG1) = cCG(ICG_BCG1) + dprec * yfac(2,ISOAP_SQT)
        cNV(INV_BIO) = cNV(INV_BIO) + dprec * yfac(3,ISOAP_SQT)
c
c======================== DDM Begin =======================
c
        if ( lddm ) then
          do ifam = 1, nfam
            srh(ifam) = (fl*rh - fh*rl) / (rh + rl)
c
            ssumk = rk(iksoap(10)) * avgsen(ifam,IOX_OH)
     &            + rk(iksoap(11)) * avgsen(ifam,IOX_O3)
     &            + rk(iksoap(12)) * avgsen(ifam,IOX_NO3)
            sdprec = sen_prec(ifam,ISOAP_SQT) * cfrac
     &             + cprec(ISOAP_SQT) * dthr * ssumk ! because cprec has been updated
            sen_prec(ifam,ISOAP_SQT) = sen_prec(ifam,ISOAP_SQT) - sdprec
            sen_CG(ifam,3) = sen_CG(ifam,3) + sdprec * yfac(1,ISOAP_SQT)
     &                                      + dprec * (1.0 - fn) *
     &             ( y_h(1,ISOAP_SQT)*srh(ifam) - y_l(1,ISOAP_SQT)*srh(ifam) )
     &                                      + dprec * fn * y_n(1,ISOAP_SQT)

            sen_CG(ifam,4) = sen_CG(ifam,4) + sdprec * yfac(2,ISOAP_SQT)
     &                                      + dprec * (1.0 - fn) *
     &             ( y_h(2,ISOAP_SQT)*srh(ifam) - y_l(2,ISOAP_SQT)*srh(ifam) )
     &                                      + dprec * fn * y_n(2,ISOAP_SQT)

            sen_NV(ifam,2) = sen_NV(ifam,2) + sdprec * yfac(3,ISOAP_SQT)
     &                                      + dprec * (1.0 - fn) *
     &             ( y_h(3,ISOAP_SQT)*srh(ifam) - y_l(3,ISOAP_SQT)*srh(ifam) )
     &                                      + dprec * fn * y_n(3,ISOAP_SQT)
          enddo
        endif
c
c======================== DDM End =======================
c
      endif
c
c-----NOx-dependent pathways for IVOA, IVC1, IVC2 and SVOA
c
      rh = 2.70e-12*exp(360.0/tempk)*cfac * avgox(IOX_NO )  ! IVOA RO2 + NO rate (hr-1)
      rl = 2.75e-12*exp(1300.0/tempk)*cfac * avgox(IOX_HO2) ! IVOA RO2 + HO2 rate (hr-1)
      fh = rh / (rh + rl)
      fl = 1.0 - fh

      yfac(1,ISOAP_IVOA) = y_h(1,ISOAP_IVOA)*fh + y_l(1,ISOAP_IVOA)*fl
      yfac(2,ISOAP_IVOA) = y_h(2,ISOAP_IVOA)*fh + y_l(2,ISOAP_IVOA)*fl
      yfac(3,ISOAP_IVOA) = y_h(3,ISOAP_IVOA)*fh + y_l(3,ISOAP_IVOA)*fl
      yfac(4,ISOAP_IVOA) = fh
c
      yfac(1,ISOAP_IVC1) = y_h(1,ISOAP_IVC1)*fh + y_l(1,ISOAP_IVC1)*fl
      yfac(2,ISOAP_IVC1) = y_h(2,ISOAP_IVC1)*fh + y_l(2,ISOAP_IVC1)*fl
      yfac(3,ISOAP_IVC1) = y_h(3,ISOAP_IVC1)*fh + y_l(3,ISOAP_IVC1)*fl
      yfac(4,ISOAP_IVC1) = fh
c
      yfac(1,ISOAP_IVC2) = y_h(1,ISOAP_IVC2)*fh + y_l(1,ISOAP_IVC2)*fl
      yfac(2,ISOAP_IVC2) = y_h(2,ISOAP_IVC2)*fh + y_l(2,ISOAP_IVC2)*fl
      yfac(3,ISOAP_IVC2) = y_h(3,ISOAP_IVC2)*fh + y_l(3,ISOAP_IVC2)*fl
      yfac(4,ISOAP_IVC2) = fh
c
      yfac(1,ISOAP_SVOA) = y_h(1,ISOAP_SVOA)*fh + y_l(1,ISOAP_SVOA)*fl
      yfac(2,ISOAP_SVOA) = y_h(2,ISOAP_SVOA)*fh + y_l(2,ISOAP_SVOA)*fl
      yfac(3,ISOAP_SVOA) = y_h(3,ISOAP_SVOA)*fh + y_l(3,ISOAP_SVOA)*fl
      yfac(4,ISOAP_SVOA) = fh
c
c======================== DDM Begin =======================
c
      if ( lddm ) then
        do ifam = 1, nfam
          srh(ifam) = (fl*rh - fh*rl) / (rh + rl)
        enddo
      endif
c
c======================== DDM End =======================
c
      rk1(IOX_OH ) = rkivoa * cfac * avgox(IOX_OH ) ! IVOA + OH rate (hr-1)
      cfrac = 1. - exp(-rk1(IOX_OH )*dthr)

      dprec = cprec(ISOAP_IVOA) * cfrac
      dcprec(ISOAP_IVOA) = -dprec
      if (dprec.gt.eps) then
        cprec(ISOAP_IVOA) = cprec(ISOAP_IVOA) - dprec
        cCG(ICG_ACG2) = cCG(ICG_ACG2) + dprec * yfac(1,ISOAP_IVOA)
        cCG(ICG_ACG1) = cCG(ICG_ACG1) + dprec * yfac(2,ISOAP_IVOA)
        cNV(INV_ANTH) = cNV(INV_ANTH) + dprec * yfac(3,ISOAP_IVOA)
c
c======================== DDM Begin =======================
c
        if ( lddm ) then
          do ifam = 1, nfam
            srk1(IOX_OH) = rkivoa * cfac * avgsen(ifam,IOX_OH)
            sdprec = sen_prec(ifam,ISOAP_IVOA) * cfrac
     &             + cprec(ISOAP_IVOA) * dthr * srk1(IOX_OH) ! because cprec has been updated
            sen_prec(ifam,ISOAP_IVOA) = sen_prec(ifam,ISOAP_IVOA) - sdprec
            sen_CG(ifam,1) = sen_CG(ifam,1) + sdprec * yfac(1,ISOAP_IVOA)
     &                                      + dprec *
     &            ( y_h(1,ISOAP_IVOA)*srh(ifam) - y_l(1,ISOAP_IVOA)*srh(ifam) )
            sen_CG(ifam,2) = sen_CG(ifam,2) + sdprec * yfac(2,ISOAP_IVOA)
     &                                      + dprec *
     &            ( y_h(2,ISOAP_IVOA)*srh(ifam) - y_l(2,ISOAP_IVOA)*srh(ifam) )
            sen_NV(ifam,1) = sen_NV(ifam,1) + sdprec * yfac(3,ISOAP_IVOA)
     &                                      + dprec *
     &            ( y_h(3,ISOAP_IVOA)*srh(ifam) - y_l(3,ISOAP_IVOA)*srh(ifam) )
          enddo
        endif
c
c======================== DDM End =======================
c
      endif

      dprec = cprec(ISOAP_IVC1) * cfrac
      dcprec(ISOAP_IVC1) = -dprec
      if (dprec.gt.eps) then
        cprec(ISOAP_IVC1) = cprec(ISOAP_IVC1) - dprec
        cCG(ICG_ACG2) = cCG(ICG_ACG2) + dprec * yfac(1,ISOAP_IVC1)
        cCG(ICG_ACG1) = cCG(ICG_ACG1) + dprec * yfac(2,ISOAP_IVC1)
        cNV(INV_ANTH) = cNV(INV_ANTH) + dprec * yfac(3,ISOAP_IVC1)
c
c======================== DDM Begin =======================
c
        if ( lddm ) then
          do ifam = 1, nfam
            srk1(IOX_OH) = rkivc1 * cfac * avgsen(ifam,IOX_OH)
            sdprec = sen_prec(ifam,ISOAP_IVC1) * cfrac
     &             + cprec(ISOAP_IVC1) * dthr * srk1(IOX_OH) ! because cprec has been updated
            sen_prec(ifam,ISOAP_IVC1) = sen_prec(ifam,ISOAP_IVC1) - sdprec
            sen_CG(ifam,1) = sen_CG(ifam,1) + sdprec * yfac(1,ISOAP_IVC1)
     &                                      + dprec *
     &            ( y_h(1,ISOAP_IVC1)*srh(ifam) - y_l(1,ISOAP_IVC1)*srh(ifam) )
            sen_CG(ifam,2) = sen_CG(ifam,2) + sdprec * yfac(2,ISOAP_IVC1)
     &                                      + dprec *
     &            ( y_h(2,ISOAP_IVC1)*srh(ifam) - y_l(2,ISOAP_IVC1)*srh(ifam) )
            sen_NV(ifam,1) = sen_NV(ifam,1) + sdprec * yfac(3,ISOAP_IVC1)
     &                                      + dprec *
     &            ( y_h(3,ISOAP_IVC1)*srh(ifam) - y_l(3,ISOAP_IVC1)*srh(ifam) )
          enddo
        endif
c
c======================== DDM End =======================
c
      endif

      dprec = cprec(ISOAP_IVC2) * cfrac
      dcprec(ISOAP_IVC2) = -dprec
      if (dprec.gt.eps) then
        cprec(ISOAP_IVC2) = cprec(ISOAP_IVC2) - dprec
        cCG(ICG_ACG2) = cCG(ICG_ACG2) + dprec * yfac(1,ISOAP_IVC2)
        cCG(ICG_ACG1) = cCG(ICG_ACG1) + dprec * yfac(2,ISOAP_IVC2)
        cNV(INV_ANTH) = cNV(INV_ANTH) + dprec * yfac(3,ISOAP_IVC2)
c
c======================== DDM Begin =======================
c
        if ( lddm ) then
          do ifam = 1, nfam
            srk1(IOX_OH) = rkivc2 * cfac * avgsen(ifam,IOX_OH)
            sdprec = sen_prec(ifam,ISOAP_IVC2) * cfrac
     &             + cprec(ISOAP_IVC2) * dthr * srk1(IOX_OH) ! because cprec has been updated
            sen_prec(ifam,ISOAP_IVC2) = sen_prec(ifam,ISOAP_IVC2) - sdprec
            sen_CG(ifam,1) = sen_CG(ifam,1) + sdprec * yfac(1,ISOAP_IVC2)
     &                                      + dprec *
     &            ( y_h(1,ISOAP_IVC2)*srh(ifam) - y_l(1,ISOAP_IVC2)*srh(ifam) )
            sen_CG(ifam,2) = sen_CG(ifam,2) + sdprec * yfac(2,ISOAP_IVC2)
     &                                      + dprec *
     &            ( y_h(2,ISOAP_IVC2)*srh(ifam) - y_l(2,ISOAP_IVC2)*srh(ifam) )
            sen_NV(ifam,1) = sen_NV(ifam,1) + sdprec * yfac(3,ISOAP_IVC2)
     &                                      + dprec *
     &            ( y_h(3,ISOAP_IVC2)*srh(ifam) - y_l(3,ISOAP_IVC2)*srh(ifam) )
          enddo
        endif
c
c======================== DDM End =======================
c
      endif

      rk1(IOX_OH ) = rksvoa * cfac * avgox(IOX_OH ) ! SVOA + OH rate (hr-1)
      cfrac = 1. - exp(-rk1(IOX_OH )*dthr)

      dprec = cprec(ISOAP_SVOA) * cfrac
      dcprec(ISOAP_SVOA) = -dprec
      if (dprec.gt.eps) then
        cprec(ISOAP_SVOA) = cprec(ISOAP_SVOA) - dprec
        cCG(ICG_ACG2) = cCG(ICG_ACG2) + dprec * yfac(1,ISOAP_SVOA)
        cCG(ICG_ACG1) = cCG(ICG_ACG1) + dprec * yfac(2,ISOAP_SVOA)
        cNV(INV_ANTH) = cNV(INV_ANTH) + dprec * yfac(3,ISOAP_SVOA)
c
c======================== DDM Begin =======================
c
        if ( lddm ) then
          do ifam = 1, nfam
            srk1(IOX_OH) = rksvoa * cfac * avgsen(ifam,IOX_OH)
            sdprec = sen_prec(ifam,ISOAP_SVOA) * cfrac
     &             + cprec(ISOAP_SVOA) * dthr * srk1(IOX_OH) ! because cprec has been updated
            sen_prec(ifam,ISOAP_SVOA) = sen_prec(ifam,ISOAP_SVOA) - sdprec
            sen_CG(ifam,1) = sen_CG(ifam,1) + sdprec * yfac(1,ISOAP_SVOA)
     &                                      + dprec *
     &            ( y_h(1,ISOAP_SVOA)*srh(ifam) - y_l(1,ISOAP_SVOA)*srh(ifam) )
            sen_CG(ifam,2) = sen_CG(ifam,2) + sdprec * yfac(2,ISOAP_SVOA)
     &                                      + dprec *
     &            ( y_h(2,ISOAP_SVOA)*srh(ifam) - y_l(2,ISOAP_SVOA)*srh(ifam) )
            sen_NV(ifam,1) = sen_NV(ifam,1) + sdprec * yfac(3,ISOAP_SVOA)
     &                                      + dprec *
     &            ( y_h(3,ISOAP_SVOA)*srh(ifam) - y_l(3,ISOAP_SVOA)*srh(ifam) )
          enddo
        endif
c
c======================== DDM End =======================
c
      endif
c
c-----NOx-dependent pathways for FVC1 (wildfire VOC) if active
c
      if( luse_fvc1 ) then

        rk1(IOX_OH ) = rk(iksoap(17)) * avgox(IOX_OH ) ! FVC1 + OH rate (hr-1)
        rk1(IOX_O3 ) = rk(iksoap(18)) * avgox(IOX_O3 ) ! FVC1 + O3 rate (hr-1)
        rk1(IOX_NO3) = rk(iksoap(19)) * avgox(IOX_NO3) ! FVC1 + NO3 rate (hr-1)
        sumk = rk1(IOX_OH ) + rk1(IOX_O3 ) + rk1(IOX_NO3)

        rh = 2.70e-12*exp(360.0/tempk)*cfac * avgox(IOX_NO )  ! FVC1 RO2 + NO rate (hr-1)
        rl = 2.47e-12*exp(1300.0/tempk)*cfac * avgox(IOX_HO2) ! FVC1 RO2 + HO2 rate (hr-1) (guaiacol)

        fn = rk1(IOX_NO3) / sumk
        fh = (1.0 - fn) * rh / (rh + rl)
        fl = 1.0 - fh - fn

        yfac(1,ISOAP_FVC1) = y_h(1,ISOAP_FVC1)*fh + y_l(1,ISOAP_FVC1)*fl + y_n(1,ISOAP_FVC1)*fn
        yfac(2,ISOAP_FVC1) = y_h(2,ISOAP_FVC1)*fh + y_l(2,ISOAP_FVC1)*fl + y_n(2,ISOAP_FVC1)*fn
        yfac(3,ISOAP_FVC1) = y_h(3,ISOAP_FVC1)*fh + y_l(3,ISOAP_FVC1)*fl + y_n(3,ISOAP_FVC1)*fn
        yfac(4,ISOAP_FVC1) = fh
        yfac(5,ISOAP_FVC1) = fn

        cfrac = 1. - exp(-sumk*dthr)
        dprec = cprec(ISOAP_FVC1) * cfrac
        dcprec(ISOAP_FVC1) = -dprec
        if (dprec.gt.eps) then
          cprec(ISOAP_FVC1) = cprec(ISOAP_FVC1) - dprec
          cCG(ICG_BCG2) = cCG(ICG_BCG2) + dprec * yfac(1,ISOAP_FVC1)
          cCG(ICG_BCG1) = cCG(ICG_BCG1) + dprec * yfac(2,ISOAP_FVC1)
          cNV(INV_BIO) = cNV(INV_BIO) + dprec * yfac(3,ISOAP_FVC1)
c
c======================== DDM Begin =======================
c
          if ( lddm ) then
            do ifam = 1, nfam
              srh(ifam) = (fl*rh - fh*rl) / (rh + rl)
              ssumk = rk(iksoap(17)) * avgsen(ifam,IOX_OH)
     &              + rk(iksoap(18)) * avgsen(ifam,IOX_O3)
     &              + rk(iksoap(19)) * avgsen(ifam,IOX_NO3)
              sdprec = sen_prec(ifam,ISOAP_FVC1) * cfrac
     &               + cprec(ISOAP_FVC1) * dthr * ssumk ! because cprec has been updated
              sen_prec(ifam,ISOAP_FVC1) = sen_prec(ifam,ISOAP_FVC1) - sdprec

              sen_CG(ifam,3) = sen_CG(ifam,3) + sdprec * yfac(1,ISOAP_FVC1)
     &                                        + dprec * (1.0 - fn) *
     &               ( y_h(1,ISOAP_FVC1)*srh(ifam) - y_l(1,ISOAP_FVC1)*srh(ifam) )
     &                                        + dprec * fn * y_n(1,ISOAP_FVC1)

              sen_CG(ifam,4) = sen_CG(ifam,4) + sdprec * yfac(2,ISOAP_FVC1)
     &                                        + dprec * (1.0 - fn) *
     &               ( y_h(2,ISOAP_FVC1)*srh(ifam) - y_l(2,ISOAP_FVC1)*srh(ifam) )
     &                                        + dprec * fn * y_n(2,ISOAP_FVC1)

              sen_NV(ifam,2) = sen_NV(ifam,2) + sdprec * yfac(3,ISOAP_FVC1)
     &                                        + dprec * (1.0 - fn) *
     &               ( y_h(3,ISOAP_FVC1)*srh(ifam) - y_l(3,ISOAP_FVC1)*srh(ifam) )
     &                                        + dprec * fn * y_n(3,ISOAP_FVC1)
            enddo
          endif
c
c======================== DDM End =======================
c
        endif
      endif  ! end check of luse_fvc1
c












c
      return
      end

