!-----------------------------------------------------------------------
!
      MODULE MODULE_CBM5     
!
!-----------------------------------------------------------------------
!
!***  THE OUTER DRIVER FOR THE CBM05 GAS-PHASE CHEMICAL MECHANISM.
!
!-----------------------------------------------------------------------
! HISTORY LOG:
!
!   2009-11-25  Jorba - Creation of the module.
!
!-----------------------------------------------------------------------
!
      USE MODULE_DM_PARALLEL, ONLY    : MYPE_SHARE
!
      USE CBM5_MODEL
!
      USE CBM5_INITIALIZE, ONLY    : INITIALIZECB5
!
      USE MODULE_BSC_CHEM_DATA
!
!-----------------------------------------------------------------------
!
      IMPLICIT NONE
!
!-----------------------------------------------------------------------
!
      INTEGER :: MYPE
!
!-----------------------------------------------------------------------
!
      CONTAINS
!
!-----------------------------------------------------------------------
!&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
!-----------------------------------------------------------------------
      SUBROUTINE RUN_CBM5(                                              &
                       NTIMESTEP,DT,NPHS,TEMPERATURE                    &
                      ,START_HOUR                                       &
                      ,CHEM,NUM_GAS_TOTAL                               &
               ,P8W,RHO_PHY,WATER,NUM_WATER,P_QV                        &
!               ,ph_no2,ph_o33p,ph_o31d,ph_no3o2,ph_no3o,ph_hno2         &
!               ,ph_h2o2,ph_hno4,ph_hno3,ph_n2o5,ph_ntr,ph_mepx          &
!               ,ph_ch2or,ph_ch2om,ph_ald2,ph_pan,ph_aldx,ph_mgly        &
!               ,ph_ispd                                                 &
               ,JPNL                                                    &
                      ,IDS,IDE,JDS,JDE,LM                               &
                      ,IMS,IME,JMS,JME,KMS,KME                          &
                      ,ITS,ITE,JTS,JTE)
!***********************************************************************
!$$$  SUBPROGRAM DOCUMENTATION BLOCK
!                .      .    .
! SUBPROGRAM:  CBM05_DRIVER  CHEMISTRY OUTER DRIVER
!   PRGRMMR: JORBA           ORG: W/NP22     DATE: 09-11-25
!
! ABSTRACT:
!     CHEM_DRIVER DRIVES THE CHEMISTRY SCHEMES
!
! PROGRAM HISTORY LOG (with changes to called routines) :
!   09-11-25  JORBA      - ORIGINATOR OF THE DRIVER
!
! USAGE: CALL CHEM_DRIVER FROM PHY_RUN
!
! ATTRIBUTES:
!   LANGUAGE: FORTRAN 90
!   MACHINE : 1
!$$$
!-----------------------------------------------------------------------
!
      IMPLICIT NONE
!
!-----------------------------------------------------------------------
!
      INTEGER,INTENT(IN) :: IDS,IDE,JDS,JDE,LM                          &
                           ,IMS,IME,JMS,JME,KMS,KME                     &
                           ,ITS,ITE,JTS,JTE                             &
                           ,NPHS,NTIMESTEP,START_HOUR                   &
                           ,NUM_WATER,P_QV
!
      INTEGER,DIMENSION(ITS:ITE,JTS:JTE),INTENT(IN) :: JPNL
!
      REAL,INTENT(IN) :: DT

      REAL,DIMENSION(ITS:ITE,JTS:JTE,1:LM,1:NUM_WATER),INTENT(IN) :: WATER

!
!      REAL, DIMENSION( ITS:ITE, kms:kme, JTS:JTE ),                 &
!         INTENT(IN) ::                                              &
!                ph_no2,ph_o33p,ph_o31d,ph_no3o2,ph_no3o,ph_hno2     &
!               ,ph_h2o2,ph_hno4,ph_hno3,ph_n2o5,ph_ntr,ph_mepx      &
!               ,ph_ch2or,ph_ch2om,ph_ald2,ph_pan,ph_aldx,ph_mgly    &
!               ,ph_ispd
      INTEGER,INTENT(IN) :: NUM_GAS_TOTAL

      REAL,DIMENSION(ITS:ITE,JTS:JTE,1:LM,NUM_GAS_TOTAL),INTENT(INOUT) ::  CHEM

      REAL,DIMENSION(IMS:IME,JMS:JME,1:LM),INTENT(IN) :: TEMPERATURE

      REAL,DIMENSION(ITS:ITE,1:LM+1,JTS:JTE),INTENT(IN) :: P8W

      REAL,DIMENSION(ITS:ITE,1:LM,JTS:JTE),INTENT(IN) :: RHO_PHY
!
!-----------------------------------------------------------------------
!***
!***  LOCAL VARIABLES
!***
!-----------------------------------------------------------------------
      INTEGER :: NCHEM,IT,JT,KT,KFLIP,KSE,KSS
      REAL :: TCHEM,TSTART,TEND,DTCHEM,DTSOLVER
      REAL(kind=dp) :: T, DVAL(NSPEC)
      REAL(kind=dp) :: RSTATE(20)
      INTEGER :: i
      REAL :: factr
      REAL pcnt

      real avognumkpp
      parameter (avognumkpp = 6.02252e23)       ! molecules/mole

      real, parameter :: eps=0.622
      real pressbox,airdenbox,cair_mlc,h2o,o2,n2,h2,ch4,m,factoraa
!
!-----------------------------------------------------------------------

      MYPE=MYPE_SHARE

      IF(MYPE==0)THEN
        WRITE(0,*) DT, NTIMESTEP
      ENDIF

      KSS=1
      KSE=NUM_GAS_TOTAL

!~~~> Initialization

!!! TEMPORAL
      NCHEM=NPHS
!!!END

      STEPMIN = 0.0d0
      STEPMAX = 0.0d0

      DO i=1,NVAR
        RTOL(i) = 1.0d-4
        ATOL(i) = 1.0d-3
      END DO

        CALL InitializeCB5()

!!!DT meteo integration time step in seconds
!!!DTCHEM chemistry integration time step in seconds (DT)
!!!NCHEM*DT time between chemistry execution
!!!NTIMESTEP*DT start time of chemistry integration (TCHEM)

      TCHEM=START_HOUR*3600.0+DT*NTIMESTEP !Carefull from wrfchem !!!tchem = gmt*3600.0 + dtstep*(ktau-1)
      TCHEM=MOD(TCHEM,86400.0)
      DTCHEM=NCHEM*DT
      TSTART=TCHEM
      TEND=TSTART+DTCHEM
!      DTSOLVER=(TEND-TSTART)/6.
!      DTSOLVER=4*60.
      DTSOLVER = DTCHEM

      IF(MYPE==0)THEN
         WRITE(0,*) 'TIME STEPS:',TSTART, TEND, DTSOLVER
      ENDIF

grid_loop: DO JT = JTS,JTE !JMS,JME
!      DO KT = 1,JPNL ! We are moving up from the bottom in the flipped arrays
!        KFLIP=JPNL+1-KT+(LM-JPNL) ! The flipped index will thus be for the NMMB arrays
      DO IT = ITS,ITE !IMS,IME
      DO KT = 1,JPNL(IT,JT) ! We are moving up from the bottom in the flipped arrays
        KFLIP=JPNL(IT,JT)+1-KT+(LM-JPNL(IT,JT)) ! The flipped index will thus be for the NMMB arrays
!
!-----------------------------------------------------------------------
!***  NOTE:  THE NMMB HAS IJK STORAGE WITH LAYER 1 AT THE TOP.
!***         THE WRF PHYSICS DRIVERS HAVE IKJ STORAGE WITH LAYER 1
!***         AT THE BOTTOM.
!-----------------------------------------------------------------------
!
      !!!!!  C es la concentracio de especies TRACERS... en (molecules/cm3)
!*** CONVERT: TRACERS(ppm) --> czz(mole/cm3)-->C(molecules/cm3)
!!! necessitem p_phy en dynes/cm2; rho_phy i temp!!!


!        tempbox = TEMPERATURE(IT,JT,KFLIP)
!   p_phy = (Pa);  pressbox = (dynes/cm2)
        pressbox = p8w(it,KT,jt)*10.0
!   rho_phy = (kg_air/m3);  airdenbox = (mole_air/cm3)
        airdenbox = rho_phy(it,kt,jt)/28.966e3 !molecular weight of air 28.966 g/mol

        C=0.
!-----------------------------------------------------------------------
!*** FROM cbmz of wrf-chem
!-----------------------------------------------------------------------
!   cair_mlc = (molecules_air/cm3)
        cair_mlc = airdenbox*avognumkpp

!  moist = (kg_h2o/kg_air);  czz = (mole_h2o/cm3);  h2o = (molecules_h2o/cm3)
!       czz(ih2o_z) = (moist(it,kt,jt,p_qv)/eps)*airdenbox
!       if (i_boxtest_units_convert .eq. 10) then
!           czz(ih2o_z) = moist(it,kt,jt,p_qv)*airdenbox
!       end if
!       h2o      = czz(ih2o_z)*avognumkpp
        h2o = (WATER(it,jt,kflip,P_QV)/eps)*airdenbox
        h2o = h2o*avognumkpp

!!       czz(ich4_z) = 1.7e-6*airdenbox           ! ch4 conc. in mol/cc
!!       ch4      = czz(ich4_z)*avognumkpp        ! ch4 conc. in molec/cc
!        ch4      = 1.7e-6*airdenbox*avognumkpp   ! ch4 conc. in molec/cc
!
!        oxygen   = 0.21*cair_mlc                 ! o2 conc. in molec/cc
!        nitrogen = 0.79*cair_mlc                 ! n2 conc. in molec/cc
!        hydrogen = 0.58e-6*cair_mlc              ! h2 conc. in molec/cc
         o2 = 0.2095*cair_mlc                 ! o2 conc. in molec/cc
!         n2 = 0.7808*cair_mlc                 ! n2 conc. in molec/cc
         h2 = 0.56e-6*cair_mlc              ! h2 conc. in molec/ccf
         m  = 1.0*cair_mlc                  ! M  conc. in molec/ccf
         ch4 = 1.85*cair_mlc                ! CH4 conc. in molec/ccf

!
!   chem units = (ppm);  czz units = (mole/cm3);  cbox units = (molecules/cm3)
        factoraa = airdenbox*1.0e-6
        factoraa = factoraa*avognumkpp
!
!------------------------------------------------------------------------
!
!      C(1:NUM_GAS_TOTAL) = MAX(CHEM(IT,JT,KFLIP,KSS:KSE)*factoraa,  &
!                                  1.0E-30*factoraa)
!***TEMPORAL - REMAPING CHEM ARRAY TO FOLLOW KPP INDEXES:******************

      C(ind_NO2) = MAX(CHEM(IT,JT,KFLIP,P_NO2)*factoraa,1.0E-30*factoraa)
      C(ind_NO) = MAX(CHEM(IT,JT,KFLIP,P_NO)*factoraa,1.0E-30*factoraa)
      C(ind_O3) = MAX(CHEM(IT,JT,KFLIP,P_O3)*factoraa,1.0E-30*factoraa)
      C(ind_NO3) = MAX(CHEM(IT,JT,KFLIP,P_NO3)*factoraa,1.0E-30*factoraa)
      C(ind_N2O5) = MAX(CHEM(IT,JT,KFLIP,P_N2O5)*factoraa,1.0E-30*factoraa)
      C(ind_HNO3) = MAX(CHEM(IT,JT,KFLIP,P_HNO3)*factoraa,1.0E-30*factoraa)
      C(ind_HONO) = MAX(CHEM(IT,JT,KFLIP,P_HONO)*factoraa,1.0E-30*factoraa)
      C(ind_PNA) = MAX(CHEM(IT,JT,KFLIP,P_PNA)*factoraa,1.0E-30*factoraa)
      C(ind_H2O2) = MAX(CHEM(IT,JT,KFLIP,P_H2O2)*factoraa,1.0E-30*factoraa)
      C(ind_NTR) = MAX(CHEM(IT,JT,KFLIP,P_NTR)*factoraa,1.0E-30*factoraa)
      C(ind_ROOH) = MAX(CHEM(IT,JT,KFLIP,P_ROOH)*factoraa,1.0E-30*factoraa)
      C(ind_FORM) = MAX(CHEM(IT,JT,KFLIP,P_FORM)*factoraa,1.0E-30*factoraa)
      C(ind_ALD2) = MAX(CHEM(IT,JT,KFLIP,P_ALD2)*factoraa,1.0E-30*factoraa)
      C(ind_ALDX) = MAX(CHEM(IT,JT,KFLIP,P_ALDX)*factoraa,1.0E-30*factoraa)
      C(ind_PAR) = MAX(CHEM(IT,JT,KFLIP,P_PAR)*factoraa,1.0E-30*factoraa)
      C(ind_CO) = MAX(CHEM(IT,JT,KFLIP,P_CO)*factoraa,1.0E-30*factoraa)
      C(ind_MEPX) = MAX(CHEM(IT,JT,KFLIP,P_MEPX)*factoraa,1.0E-30*factoraa)
      C(ind_MEOH) = MAX(CHEM(IT,JT,KFLIP,P_MEOH)*factoraa,1.0E-30*factoraa)
      C(ind_FACD) = MAX(CHEM(IT,JT,KFLIP,P_FACD)*factoraa,1.0E-30*factoraa)
      C(ind_PAN) = MAX(CHEM(IT,JT,KFLIP,P_PAN)*factoraa,1.0E-30*factoraa)
      C(ind_PACD) = MAX(CHEM(IT,JT,KFLIP,P_PACD)*factoraa,1.0E-30*factoraa)
      C(ind_AACD) = MAX(CHEM(IT,JT,KFLIP,P_AACD)*factoraa,1.0E-30*factoraa)
      C(ind_PANX) = MAX(CHEM(IT,JT,KFLIP,P_PANX)*factoraa,1.0E-30*factoraa)
      C(ind_OLE) = MAX(CHEM(IT,JT,KFLIP,P_OLE)*factoraa,1.0E-30*factoraa)
      C(ind_ETH) = MAX(CHEM(IT,JT,KFLIP,P_ETH)*factoraa,1.0E-30*factoraa)
      C(ind_IOLE) = MAX(CHEM(IT,JT,KFLIP,P_IOLE)*factoraa,1.0E-30*factoraa)
      C(ind_TOL) = MAX(CHEM(IT,JT,KFLIP,P_TOL)*factoraa,1.0E-30*factoraa)
      C(ind_CRES) = MAX(CHEM(IT,JT,KFLIP,P_CRES)*factoraa,1.0E-30*factoraa)
      C(ind_OPEN) = MAX(CHEM(IT,JT,KFLIP,P_OPEN)*factoraa,1.0E-30*factoraa)
      C(ind_MGLY) = MAX(CHEM(IT,JT,KFLIP,P_MGLY)*factoraa,1.0E-30*factoraa)
      C(ind_XYL) = MAX(CHEM(IT,JT,KFLIP,P_XYL)*factoraa,1.0E-30*factoraa)
      C(ind_ISOP) = MAX(CHEM(IT,JT,KFLIP,P_ISOP)*factoraa,1.0E-30*factoraa)
      C(ind_ISPD) = MAX(CHEM(IT,JT,KFLIP,P_ISPD)*factoraa,1.0E-30*factoraa)
      C(ind_TERP) = MAX(CHEM(IT,JT,KFLIP,P_TERP)*factoraa,1.0E-30*factoraa)
      C(ind_SO2) = MAX(CHEM(IT,JT,KFLIP,P_SO2)*factoraa,1.0E-30*factoraa)
      C(ind_SULF) = MAX(CHEM(IT,JT,KFLIP,P_SULF)*factoraa,1.0E-30*factoraa)
      C(ind_ETOH) = MAX(CHEM(IT,JT,KFLIP,P_ETOH)*factoraa,1.0E-30*factoraa)
      C(ind_ETHA) = MAX(CHEM(IT,JT,KFLIP,P_ETHA)*factoraa,1.0E-30*factoraa)
!NON-ADVECTED SPECIES
      C(ind_O) = MAX(CHEM(IT,JT,KFLIP,P_O)*factoraa,1.0E-30*factoraa)
      C(ind_O1D) = MAX(CHEM(IT,JT,KFLIP,P_O1D)*factoraa,1.0E-30*factoraa)
      C(ind_OH) = MAX(CHEM(IT,JT,KFLIP,P_OH)*factoraa,1.0E-30*factoraa)
      C(ind_HO2) = MAX(CHEM(IT,JT,KFLIP,P_HO2)*factoraa,1.0E-30*factoraa)
      C(ind_XO2) = MAX(CHEM(IT,JT,KFLIP,P_XO2)*factoraa,1.0E-30*factoraa)
      C(ind_XO2N) = MAX(CHEM(IT,JT,KFLIP,P_XO2N)*factoraa,1.0E-30*factoraa)
      C(ind_MEO2) = MAX(CHEM(IT,JT,KFLIP,P_MEO2)*factoraa,1.0E-30*factoraa)
      C(ind_HCO3) = MAX(CHEM(IT,JT,KFLIP,P_HCO3)*factoraa,1.0E-30*factoraa)
      C(ind_C2O3) = MAX(CHEM(IT,JT,KFLIP,P_C2O3)*factoraa,1.0E-30*factoraa)
      C(ind_CXO3) = MAX(CHEM(IT,JT,KFLIP,P_CXO3)*factoraa,1.0E-30*factoraa)
      C(ind_ROR) = MAX(CHEM(IT,JT,KFLIP,P_ROR)*factoraa,1.0E-30*factoraa)
      C(ind_TO2) = MAX(CHEM(IT,JT,KFLIP,P_TO2)*factoraa,1.0E-30*factoraa)
      C(ind_CRO) = MAX(CHEM(IT,JT,KFLIP,P_CRO)*factoraa,1.0E-30*factoraa)
!      C(ind_CH4) = MAX(CHEM(IT,JT,KFLIP,P_CH4)*factoraa,1.0E-30*factoraa)
!**************************************************************************



      DO T=1,NUM_GAS_TOTAL
      IF(.not.C(T).lt.(1E10*factoraa))then
         print*,'input concentration wrong in CHEM',T, &
         C(T),CHEM(IT,JT,KFLIP,T)
         stop
      endif
      enddo

      CFACTOR = factoraa !conversion factor from ppmv to molec/cm3

      TEMP = TEMPERATURE(IT,JT,KFLIP)

        FIX(1) = h2o !H2O
        FIX(2) = h2    !H2 Init in InitializeCB05, need to be checked
        FIX(3) = o2    !O2 Init in InitializeCB05
!        FIX(4) = n2    !N2 Init in InitializeCB05
        FIX(4) = ch4  !CH4 
        FIX(5) = m    !M  Init in InitializeCB05
        factr=1./60. !convert units from (min-1) to (s-1)
        J_NO2      = ph_no2(IT,KT,JT)*factr
        J_O33P     = ph_o33p(IT,KT,JT)*factr
        J_O31D     = ph_o31d(IT,KT,JT)*factr
        J_NO3O2    = ph_no3o2(IT,KT,JT)*factr
        J_NO3O     = ph_no3o(IT,KT,JT)*factr
        J_HNO2     = ph_hno2(IT,KT,JT)*factr
        J_H2O2     = ph_h2o2(IT,KT,JT)*factr
        J_HNO4     = ph_hno4(IT,KT,JT)*factr !HNO4=HO2NO2   
        J_HNO3     = ph_hno3(IT,KT,JT)*factr
        J_N2O5     = ph_n2o5(IT,KT,JT)*factr
        J_NTR      = ph_ntr(IT,KT,JT)*factr !!!!!
        J_COOH     = ph_mepx(IT,KT,JT)*factr !!!!!
        J_CH2OR    = ph_ch2or(IT,KT,JT)*factr
        J_CH2OM    = ph_ch2om(IT,KT,JT)*factr
        J_CH3CHO   = ph_ald2(IT,KT,JT)*factr !!!CCHO_R_SAPRC99  ????
        J_PAN      = ph_pan(IT,KT,JT)*factr !!!!!
        J_C2CHO    = ph_aldx(IT,KT,JT)*factr !!!!!
        J_MGLY     = ph_mgly(IT,KT,JT)*factr !!!!!
        J_ISPD     = ph_ispd(IT,KT,JT)*factr !!!!!

        CALL Update_RCONSTCB5()

!!!DEBUG
      IF(IT==160.AND.JT==130.AND.KT==1)THEN
!        IF(MYPE==14)THEN
         WRITE(0,*) KT,'preps:',TEMP,pressbox,airdenbox,cair_mlc,h2o,factoraa
         WRITE(0,*) 'CONC:',C
         WRITE(0,*) 'PHOT RATES:',J_NO2,J_O33P,J_O31D,J_NO3O,J_HNO2, &
                     J_H2O2,J_CH2Or,J_CH2Om,J_CH3CHO,J_MGLY

         WRITE(0,*) 'RATE CONSTANT:', RCONST(10)
!        ENDIF
      ENDIF
      IF(IT==160.AND.JT==130.AND.KT==JPNL(IT,JT))THEN
!        IF(MYPE==14)THEN
         WRITE(0,*) KT,'preps:',TEMP,pressbox,airdenbox,cair_mlc,h2o,factoraa
         WRITE(0,*) 'CONC:',C
         WRITE(0,*) 'PHOT RATES:',J_NO2,J_O33P,J_O31D,J_NO3O,J_HNO2, &
                     J_H2O2,J_CH2Or,J_CH2Om,J_CH3CHO,J_MGLY
         WRITE(0,*) 'RATE CONSTANT:', RCONST(10)
!        ENDIF
      ENDIF
!!!DEBUG

!      print *,'Control nans:',IT,JT,KT,J_NO2,ph_no2(IT,KT,JT),RCONST(1)

!#endif

!~~~> Time loop
      T = TSTART
kron: DO WHILE (T < TEND)

        TIME = T
!        CALL GetMass( C, DVAL )
      IF(IT==1.and.JT==1.and.KT==1)THEN
      IF(MYPE==0)THEN
        WRITE(0,991) (T-TSTART)/(TEND-TSTART)*100, T,       &
                   ( TRIM(SPC_NAMES(MONITOR(i))),           &
                     C(MONITOR(i))/CFACTOR, i=1,NMONITOR ), &
                   ( TRIM(SMASS(i)), DVAL(i)/CFACTOR, i=1,NMASS )
      ENDIF
      ENDIF
!        CALL SaveData()
!        CALL Update_SUN()
!        CALL Update_RCONST()

!        IF(J_NO2>0)THEN
!        print *,'J_NO2 dins:',IT,JT,KT,J_NO2,ph_no2(IT,KT,JT),RCONST(1)
!        ENDIF

          CALL INTEGRATECB5( TIN = T, TOUT = T+DTSOLVER, RSTATUS_U = RSTATE, &
          ICNTRL_U = (/ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 /),          &
          RCNTRL_U = (/ 0d0,0d0,0.01d0*DT,0d0,0d0,0d0,0d0,0d0,0d0,0d0,0d0,   &
                        0d0,0d0,0d0,0d0,0d0,0d0,0d0,0d0,0d0 /) )
        T = RSTATE(1)
      END DO kron
!~~~> End Time loop
!!!!DEBUG
      IF(IT==160.AND.JT==130.AND.KT==1)THEN
        IF(MYPE==14)THEN
         WRITE(0,*) KT,'preps:',TEMP,pressbox,airdenbox,cair_mlc,h2o,factoraa
         WRITE(0,*) 'CONC AFTER:',C
         WRITE(0,*) 'PHOT RATES:',J_NO2,J_O33P,J_O31D,J_NO3O,J_HNO2, &
                     J_H2O2,J_CH2Or,J_CH2Om,J_CH3CHO,J_MGLY
        ENDIF
      ENDIF
      IF(IT==160.AND.JT==130.AND.KT==JPNL(IT,JT))THEN
        IF(MYPE==14)THEN
         WRITE(0,*) KT,'preps:',TEMP,pressbox,airdenbox,cair_mlc,h2o,factoraa
         WRITE(0,*) 'CONC AFTER:',C
         WRITE(0,*) 'PHOT RATES:',J_NO2,J_O33P,J_O31D,J_NO3O,J_HNO2, &
                     J_H2O2,J_CH2Or,J_CH2Om,J_CH3CHO,J_MGLY
        ENDIF
      ENDIF
!!!!DEBUG
!  Dump C chemistry results again in TRACERS with flipped index KFLIP
!      CHEM(IT,JT,KFLIP,KSS:KSE)=C(1:NUM_GAS_TOTAL)/factoraa
!****TEMPORAL REMAPING CHEM ARRAY***********************************
      CHEM(IT,JT,KFLIP,P_NO2) = C(ind_NO2)/factoraa 
      CHEM(IT,JT,KFLIP,P_NO) = C(ind_NO)/factoraa 
      CHEM(IT,JT,KFLIP,P_O3) = C(ind_O3)/factoraa 
      CHEM(IT,JT,KFLIP,P_NO3) = C(ind_NO3)/factoraa 
      CHEM(IT,JT,KFLIP,P_N2O5) = C(ind_N2O5)/factoraa 
      CHEM(IT,JT,KFLIP,P_HNO3) = C(ind_HNO3)/factoraa 
      CHEM(IT,JT,KFLIP,P_HONO) = C(ind_HONO)/factoraa 
      CHEM(IT,JT,KFLIP,P_PNA) = C(ind_PNA)/factoraa 
      CHEM(IT,JT,KFLIP,P_H2O2) = C(ind_H2O2)/factoraa 
      CHEM(IT,JT,KFLIP,P_NTR) = C(ind_NTR)/factoraa 
      CHEM(IT,JT,KFLIP,P_ROOH) = C(ind_ROOH)/factoraa 
      CHEM(IT,JT,KFLIP,P_FORM) = C(ind_FORM)/factoraa 
      CHEM(IT,JT,KFLIP,P_ALD2) = C(ind_ALD2)/factoraa 
      CHEM(IT,JT,KFLIP,P_ALDX) = C(ind_ALDX)/factoraa 
      CHEM(IT,JT,KFLIP,P_PAR) = C(ind_PAR)/factoraa 
      CHEM(IT,JT,KFLIP,P_CO) = C(ind_CO)/factoraa 
      CHEM(IT,JT,KFLIP,P_MEPX) = C(ind_MEPX)/factoraa 
      CHEM(IT,JT,KFLIP,P_MEOH) = C(ind_MEOH)/factoraa 
      CHEM(IT,JT,KFLIP,P_FACD) = C(ind_FACD)/factoraa 
      CHEM(IT,JT,KFLIP,P_PAN) = C(ind_PAN)/factoraa 
      CHEM(IT,JT,KFLIP,P_PACD) = C(ind_PACD)/factoraa 
      CHEM(IT,JT,KFLIP,P_AACD) = C(ind_AACD)/factoraa 
      CHEM(IT,JT,KFLIP,P_PANX) = C(ind_PANX)/factoraa 
      CHEM(IT,JT,KFLIP,P_OLE) = C(ind_OLE)/factoraa 
      CHEM(IT,JT,KFLIP,P_ETH) = C(ind_ETH)/factoraa 
      CHEM(IT,JT,KFLIP,P_IOLE) = C(ind_IOLE)/factoraa 
      CHEM(IT,JT,KFLIP,P_TOL) = C(ind_TOL)/factoraa 
      CHEM(IT,JT,KFLIP,P_CRES) = C(ind_CRES)/factoraa 
      CHEM(IT,JT,KFLIP,P_OPEN) = C(ind_OPEN)/factoraa 
      CHEM(IT,JT,KFLIP,P_MGLY) = C(ind_MGLY)/factoraa 
      CHEM(IT,JT,KFLIP,P_XYL) = C(ind_XYL)/factoraa 
      CHEM(IT,JT,KFLIP,P_ISOP) = C(ind_ISOP)/factoraa 
      CHEM(IT,JT,KFLIP,P_ISPD) = C(ind_ISPD)/factoraa 
      CHEM(IT,JT,KFLIP,P_TERP) = C(ind_TERP)/factoraa 
      CHEM(IT,JT,KFLIP,P_SO2) = C(ind_SO2)/factoraa 
      CHEM(IT,JT,KFLIP,P_SULF) = C(ind_SULF)/factoraa 
      CHEM(IT,JT,KFLIP,P_ETOH) = C(ind_ETOH)/factoraa 
      CHEM(IT,JT,KFLIP,P_ETHA) = C(ind_ETHA)/factoraa 
!NON-ADVECTED SPECIES
      CHEM(IT,JT,KFLIP,P_O) = C(ind_O)/factoraa 
      CHEM(IT,JT,KFLIP,P_O1D) = C(ind_O1D)/factoraa 
      CHEM(IT,JT,KFLIP,P_OH) = C(ind_OH)/factoraa 
      CHEM(IT,JT,KFLIP,P_HO2) = C(ind_HO2)/factoraa 
      CHEM(IT,JT,KFLIP,P_XO2) = C(ind_XO2)/factoraa 
      CHEM(IT,JT,KFLIP,P_XO2N) = C(ind_XO2N)/factoraa 
      CHEM(IT,JT,KFLIP,P_MEO2) = C(ind_MEO2)/factoraa 
      CHEM(IT,JT,KFLIP,P_HCO3) = C(ind_HCO3)/factoraa 
      CHEM(IT,JT,KFLIP,P_C2O3) = C(ind_C2O3)/factoraa 
      CHEM(IT,JT,KFLIP,P_CXO3) = C(ind_CXO3)/factoraa 
      CHEM(IT,JT,KFLIP,P_ROR) = C(ind_ROR)/factoraa 
      CHEM(IT,JT,KFLIP,P_TO2) = C(ind_TO2)/factoraa 
      CHEM(IT,JT,KFLIP,P_CRO) = C(ind_CRO)/factoraa 
!      CHEM(IT,JT,KFLIP,P_CH4) = C(ind_CH4)/factoraa 
!*******************************************************************

      ENDDO
      ENDDO
!          WRITE(0,*) 'chem JT:',JT
      ENDDO grid_loop

991   FORMAT(F6.1,'%. T=',E9.3,2X,200(A,'=',E11.4,'; '))

      RETURN
!
!-----------------------------------------------------------------------
!
      END SUBROUTINE RUN_CBM5       
!
!---------------------------------------------------------------------
!XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
!!---------------------------------------------------------------------
!
      END MODULE MODULE_CBM5    
!
!-----------------------------------------------------------------------























