      subroutine hr_xo7(y0,y1,yh,H2O,M,O2,CH4,H2,ny,rk,r,nr,dt)
      implicit none
c
c----CAMx v7.40 260801
c
c     HR_XO7 solves halogen oxides by EBI iterations
c
c      Copyright Ramboll
c
c     Created by the CMC v7.4
c
c     CB7r3 20March2026 + GLY/MGLY SOA
c
c --- Subroutines Called:
c        none
c
c --- Called by:
c        EBISOLV
c
c --- Argument definitions:
c        y0  - initial Conc for this step (ppm)
c        yh  - current Conc iteration (ppm)
c        y1  - next Conc iteration (ppm)
c        H2O - water vapor Conc (ppm)
c        M   - total gas Conc (ppm)
c        O2  - oxygen Conc (ppm)
c        CH4 - methane Conc (ppm)
c        H2  - hydrogen Conc (ppm)
c        ny  - dimension of y0, y1 and yh
c        rk  - rate constants (ppm-n hr-1)
c        r   - reaction rates (hr-1)
c        nr  - dimension of rk and r
c        dt  - time step (hr)
c
c --- Includes:
      include "camx.prm"
      include "chmdat.inc"
      include "ddmchm.inc"
c
c --- Arguments:
      integer ny, nr
      real y0(ny+1), y1(ny+1), yh(ny+1)
      real rk(nr), r(nr)
      real H2O, M, O2, CH4, H2, dt
c
c --- Local variables:
      real N2
      integer iter, nit
      real TINY
      parameter (TINY = 1.0E-20)
      real gainI, lossI
      real gainIO, lossIO
      real gainOIO, lossOIO
      real r241, r242, r243, r244, r245, r246, r247, r248, r249, r250
      real r251, r252, r253, r255
c
c --- Entry Point
c
      N2 = M - O2
      r241 = r(241)
      r242 = r(242)
      r253 = r(253)
      r255 = r(255)
c
      nit = 2
c
      do iter = 1,nit
c
c --- Update reaction rates that change with iteration of y1
c
      r243 = rk(243)*y1(lI)*yh(lO3)
      r244 = rk(244)*y1(lIO)
      r245 = rk(245)*y1(lIO)*y1(lIO)
      r246 = rk(246)*y1(lIO)*yh(lHO2)
      r247 = rk(247)*y1(lIO)*yh(lNO)
      r248 = rk(248)*y1(lIO)*yh(lNO2)
      r249 = rk(249)*y1(lOIO)
      r250 = rk(250)*y1(lOIO)*yh(lOH)
      r251 = rk(251)*y1(lOIO)*y1(lIO)
      r252 = rk(252)*y1(lOIO)*yh(lNO)
c
c --- Gain and loss terms for the XO species
c
      gainI = 0.0
     &       + ( 2.000)*r241
     &       +          r242
     &       +          r244
     &       + ( 0.400)*r245
     &       +          r247
     &       +          r249
     &       +          r253
     &       +          r255
c
      lossI = 0.0
     &       +          r243
c
      gainIO = 0.0
     &       +          r243
     &       +          r252
c
      lossIO = 0.0
     &       +          r244
     &       + ( 2.000)*r245
     &       +          r246
     &       +          r247
     &       +          r248
     &       +          r251
c
      gainOIO = 0.0
     &       + ( 0.400)*r245
     &       +          r253
c
      lossOIO = 0.0
     &       +          r249
     &       +          r250
     &       +          r251
     &       +          r252
c
c --- EBI solution for the XO species
c
      y1(lI) = MIN(1.0, MAX(TINY,(y0(lI) + gainI*dt)
     &                         / (1.0 + lossI*dt/y1(lI))))
c
      y1(lIO) = MIN(1.0, MAX(TINY,(y0(lIO) + gainIO*dt)
     &                         / (1.0 + lossIO*dt/y1(lIO))))
c
      y1(lOIO) = MIN(1.0, MAX(TINY,(y0(lOIO) + gainOIO*dt)
     &                         / (1.0 + lossOIO*dt/y1(lOIO))))
c
      enddo ! Iterations
c
      return
      end

