LCOV - code coverage report
Current view: top level - chemistry/mozart - mo_chm_diags.F90 (source / functions) Hit Total Coverage
Test: coverage.info Lines: 376 533 70.5 %
Date: 2025-03-13 19:18:33 Functions: 3 3 100.0 %

          Line data    Source code
       1             : module mo_chm_diags
       2             : 
       3             :   use shr_kind_mod, only : r8 => shr_kind_r8
       4             :   use chem_mods,    only : gas_pcnst
       5             :   use mo_tracname,  only : solsym
       6             :   use chem_mods,    only : rxntot, nfs, gas_pcnst, indexm, adv_mass
       7             :   use ppgrid,       only : pver
       8             :   use mo_constants, only : rgrav, rearth
       9             :   use mo_chem_utls, only : get_rxt_ndx, get_spc_ndx
      10             :   use cam_history,  only : fieldname_len
      11             :   use mo_jeuv,      only : neuv
      12             :   use gas_wetdep_opts,only : gas_wetdep_method
      13             :   use mo_drydep,    only : has_drydep
      14             : 
      15             :   implicit none
      16             :   private
      17             : 
      18             :   public :: chm_diags_inti
      19             :   public :: chm_diags
      20             :   public :: het_diags
      21             :   public :: chm_prod_ndep_flx
      22             : 
      23             :   integer :: id_n,id_no,id_no2,id_no3,id_n2o5,id_hno3,id_ho2no2,id_clono2,id_brono2
      24             :   integer :: id_isopfdn, id_isopfdnc, id_terpfdn !these are dinitrates
      25             :   integer :: id_cl,id_clo,id_hocl,id_cl2,id_cl2o2,id_oclo,id_hcl,id_brcl
      26             :   integer :: id_ccl4,id_cfc11,id_cfc113,id_ch3ccl3,id_cfc12,id_ch3cl,id_hcfc22,id_cf3br,id_cf2clbr
      27             :   integer :: id_cfc114,id_cfc115,id_hcfc141b,id_hcfc142b,id_h1202,id_h2402,id_ch2br2,id_chbr3
      28             :   integer :: id_hf,id_f,id_cof2,id_cofcl,id_ch3br
      29             :   integer :: id_br,id_bro,id_hbr,id_hobr,id_ch4,id_h2o,id_h2
      30             :   integer :: id_o,id_o2,id_h, id_h2o2, id_n2o
      31             :   integer :: id_co2,id_o3,id_oh,id_ho2,id_so4_a1,id_so4_a2,id_so4_a3
      32             :   integer :: id_num_a2,id_num_a3,id_dst_a3,id_ncl_a3
      33             :   integer :: id_ndep,id_nhdep
      34             : 
      35             :   integer, parameter :: NJEUV = neuv
      36             :   integer :: rid_jeuv(NJEUV), rid_jno_i, rid_jno
      37             : 
      38             :   logical :: has_jeuvs, has_jno_i, has_jno
      39             : 
      40             :   integer :: nox_species(3),  noy_species(56)
      41             :   integer :: clox_species(6), cloy_species(9), tcly_species(21)
      42             :   integer :: brox_species(4), broy_species(6), tbry_species(13)
      43             :   integer :: foy_species(4),  tfy_species(16)
      44             :   integer :: hox_species(4)
      45             :   integer :: toth_species(3)
      46             :   integer :: sox_species(3)
      47             :   integer :: nhx_species(2)
      48             :   integer :: aer_species(gas_pcnst)
      49             : 
      50             :   character(len=fieldname_len) :: dtchem_name(gas_pcnst)
      51             :   character(len=fieldname_len) :: depvel_name(gas_pcnst)
      52             :   character(len=fieldname_len) :: depflx_name(gas_pcnst)
      53             :   character(len=fieldname_len) :: wetdep_name(gas_pcnst)
      54             :   character(len=fieldname_len) :: wtrate_name(gas_pcnst)
      55             : 
      56             :   real(r8), parameter :: N_molwgt = 14.00674_r8
      57             :   real(r8), parameter :: S_molwgt = 32.066_r8
      58             : 
      59             :   logical, protected :: chm_prod_ndep_flx =.false.
      60             : 
      61             : contains
      62             : 
      63       92088 :   subroutine chm_diags_inti
      64             :     !--------------------------------------------------------------------
      65             :     !   ... initialize utility routine
      66             :     !--------------------------------------------------------------------
      67             : 
      68             :     use cam_history,  only : addfld, add_default, horiz_only
      69             :     use constituents, only : cnst_get_ind, cnst_longname
      70             :     use phys_control, only : phys_getopts
      71             :     use species_sums_diags, only : species_sums_init
      72             : 
      73             :     integer :: j, k, m, n
      74             :     character(len=16) :: jname, spc_name, attr
      75             :     character(len=2)  :: jchar
      76             :     character(len=2)  :: unit_basename  ! Units 'kg' or '1'
      77             : 
      78             :     integer :: id_pan, id_onit, id_mpan, id_isopno3, id_onitr, id_nh4no3
      79             :     integer :: id_so2, id_so4, id_h2so4
      80             :     integer :: id_nh3, id_nh4
      81             :     integer :: id_honitr
      82             :     integer :: id_alknit
      83             :     integer :: id_isopnita
      84             :     integer :: id_isopnitb
      85             :     integer :: id_isopnooh
      86             :     integer :: id_nc4ch2oh
      87             :     integer :: id_nc4cho
      88             :     integer :: id_noa
      89             :     integer :: id_nterpooh
      90             :     integer :: id_pbznit
      91             :     integer :: id_terpnit
      92             :     integer :: id_dst01, id_dst02, id_dst03, id_dst04, id_sslt01, id_sslt02, id_sslt03, id_sslt04
      93             :     integer :: id_soa,  id_oc1, id_oc2, id_cb1, id_cb2
      94             :     integer :: id_soam,id_soai,id_soat,id_soab,id_soax
      95             :     integer :: id_bry, id_cly
      96             :     integer :: id_isopn2b, id_isopn3b, id_isopn1d, id_isopn4d, id_isopnbno3
      97             :     integer :: id_isopfnp, id_isopnoohb, id_isopnoohd, id_inheb, id_inhed
      98             :     integer :: id_no3ch2cho, id_macrn, id_mvkn, id_isopfnc, id_terpns
      99             :     integer :: id_terpnt, id_terpnt1, id_terpns1, id_terpnpt, id_terpnps
     100             :     integer :: id_terpnpt1, id_terpnps1, id_sqtn, id_terphfn
     101             :     integer :: id_terpapan, id_terpa2pan, id_terpa3pan
     102             : 
     103             :     logical :: history_aerosol      ! Output the MAM aerosol tendencies
     104             :     logical :: history_chemistry
     105             :     logical :: history_cesm_forcing
     106             :     logical :: history_scwaccm_forcing
     107             :     logical :: history_chemspecies_srf ! output the chemistry constituents species in the surface layer
     108             :     logical :: history_dust
     109             :     integer :: bulkaero_species(20)
     110             : 
     111             :     !-----------------------------------------------------------------------
     112             : 
     113             :     call phys_getopts( history_aerosol_out = history_aerosol, &
     114             :                        history_chemistry_out = history_chemistry, &
     115             :                        history_chemspecies_srf_out = history_chemspecies_srf, &
     116             :                        history_cesm_forcing_out = history_cesm_forcing, &
     117             :                        history_scwaccm_forcing_out = history_scwaccm_forcing, &
     118        2304 :                        history_dust_out = history_dust )
     119             : 
     120        2304 :     id_bry     = get_spc_ndx( 'BRY' )
     121        2304 :     id_cly     = get_spc_ndx( 'CLY' )
     122             : 
     123        2304 :     id_n       = get_spc_ndx( 'N' )
     124        2304 :     id_no      = get_spc_ndx( 'NO' )
     125        2304 :     id_no2     = get_spc_ndx( 'NO2' )
     126        2304 :     id_no3     = get_spc_ndx( 'NO3' )
     127        2304 :     id_n2o5    = get_spc_ndx( 'N2O5' )
     128        2304 :     id_n2o     = get_spc_ndx( 'N2O' )
     129        2304 :     id_hno3    = get_spc_ndx( 'HNO3' )
     130        2304 :     id_ho2no2  = get_spc_ndx( 'HO2NO2' )
     131        2304 :     id_clono2  = get_spc_ndx( 'CLONO2' )
     132        2304 :     id_brono2  = get_spc_ndx( 'BRONO2' )
     133        2304 :     id_cl      = get_spc_ndx( 'CL' )
     134        2304 :     id_clo     = get_spc_ndx( 'CLO' )
     135        2304 :     id_hocl    = get_spc_ndx( 'HOCL' )
     136        2304 :     id_cl2     = get_spc_ndx( 'CL2' )
     137        2304 :     id_cl2o2   = get_spc_ndx( 'CL2O2' )
     138        2304 :     id_oclo    = get_spc_ndx( 'OCLO' )
     139        2304 :     id_hcl     = get_spc_ndx( 'HCL' )
     140        2304 :     id_brcl    = get_spc_ndx( 'BRCL' )
     141             : 
     142        2304 :     id_co2     = get_spc_ndx( 'CO2' )
     143        2304 :     id_o3      = get_spc_ndx( 'O3' )
     144        2304 :     id_oh      = get_spc_ndx( 'OH' )
     145        2304 :     id_ho2     = get_spc_ndx( 'HO2' )
     146        2304 :     id_h2o2    = get_spc_ndx( 'H2O2' )
     147        2304 :     id_so4_a1  = get_spc_ndx( 'so4_a1' )
     148        2304 :     id_so4_a2  = get_spc_ndx( 'so4_a2' )
     149        2304 :     id_so4_a3  = get_spc_ndx( 'so4_a3' )
     150        2304 :     id_num_a2  = get_spc_ndx( 'num_a2' )
     151        2304 :     id_num_a3  = get_spc_ndx( 'num_a3' )
     152        2304 :     id_dst_a3  = get_spc_ndx( 'dst_a3' )
     153        2304 :     id_ncl_a3  = get_spc_ndx( 'ncl_a3' )
     154             : 
     155        2304 :     id_f       = get_spc_ndx( 'F' )
     156        2304 :     id_hf      = get_spc_ndx( 'HF' )
     157        2304 :     id_cofcl   = get_spc_ndx( 'COFCL' )
     158        2304 :     id_cof2    = get_spc_ndx( 'COF2' )
     159             : 
     160        2304 :     id_ccl4    = get_spc_ndx( 'CCL4' )
     161        2304 :     id_cfc11   = get_spc_ndx( 'CFC11' )
     162             : 
     163        2304 :     id_cfc113  = get_spc_ndx( 'CFC113' )
     164        2304 :     id_cfc114  = get_spc_ndx( 'CFC114' )
     165        2304 :     id_cfc115  = get_spc_ndx( 'CFC115' )
     166             : 
     167        2304 :     id_ch3ccl3 = get_spc_ndx( 'CH3CCL3' )
     168        2304 :     id_cfc12   = get_spc_ndx( 'CFC12' )
     169        2304 :     id_ch3cl   = get_spc_ndx( 'CH3CL' )
     170             : 
     171        2304 :     id_hcfc22  = get_spc_ndx( 'HCFC22' )
     172        2304 :     id_hcfc141b= get_spc_ndx( 'HCFC141B' )
     173        2304 :     id_hcfc142b= get_spc_ndx( 'HCFC142B' )
     174             : 
     175        2304 :     id_cf2clbr = get_spc_ndx( 'CF2CLBR' )
     176        2304 :     id_cf3br   = get_spc_ndx( 'CF3BR' )
     177        2304 :     id_ch3br   = get_spc_ndx( 'CH3BR' )
     178        2304 :     id_h1202   = get_spc_ndx( 'H1202' )
     179        2304 :     id_h2402   = get_spc_ndx( 'H2402' )
     180        2304 :     id_ch2br2  = get_spc_ndx( 'CH2BR2' )
     181        2304 :     id_chbr3   = get_spc_ndx( 'CHBR3' )
     182             : 
     183        2304 :     id_br      = get_spc_ndx( 'BR' )
     184        2304 :     id_bro     = get_spc_ndx( 'BRO' )
     185        2304 :     id_hbr     = get_spc_ndx( 'HBR' )
     186        2304 :     id_hobr    = get_spc_ndx( 'HOBR' )
     187        2304 :     id_ch4     = get_spc_ndx( 'CH4' )
     188        2304 :     id_h2o     = get_spc_ndx( 'H2O' )
     189        2304 :     id_h2      = get_spc_ndx( 'H2' )
     190        2304 :     id_o       = get_spc_ndx( 'O' )
     191        2304 :     id_o2      = get_spc_ndx( 'O2' )
     192        2304 :     id_h       = get_spc_ndx( 'H' )
     193             : 
     194        2304 :     id_pan     = get_spc_ndx( 'PAN' )
     195        2304 :     id_onit    = get_spc_ndx( 'ONIT' )
     196        2304 :     id_mpan    = get_spc_ndx( 'MPAN' )
     197        2304 :     id_isopno3 = get_spc_ndx( 'ISOPNO3' )
     198        2304 :     id_onitr   = get_spc_ndx( 'ONITR' )
     199        2304 :     id_nh4no3  = get_spc_ndx( 'NH4NO3' )
     200             : 
     201        2304 :     id_honitr    = get_spc_ndx( 'HONITR' )
     202        2304 :     id_alknit    = get_spc_ndx( 'ALKNIT' )
     203        2304 :     id_isopnita  = get_spc_ndx( 'ISOPNITA' )
     204        2304 :     id_isopnitb  = get_spc_ndx( 'ISOPNITB' )
     205        2304 :     id_isopnooh  = get_spc_ndx( 'ISOPNOOH' )
     206        2304 :     id_nc4ch2oh  = get_spc_ndx( 'NC4CH2OH' )
     207        2304 :     id_nc4cho    = get_spc_ndx( 'NC4CHO' )
     208        2304 :     id_noa       = get_spc_ndx( 'NOA' )
     209        2304 :     id_nterpooh  = get_spc_ndx( 'NTERPOOH' )
     210        2304 :     id_pbznit    = get_spc_ndx( 'PBZNIT' )
     211        2304 :     id_terpnit   = get_spc_ndx( 'TERPNIT' )
     212        2304 :     id_ndep      = get_spc_ndx( 'NDEP' )
     213        2304 :     id_nhdep     = get_spc_ndx( 'NHDEP' )
     214             : 
     215        2304 :     id_so2     = get_spc_ndx( 'SO2' )
     216        2304 :     id_so4     = get_spc_ndx( 'SO4' )
     217        2304 :     id_h2so4   = get_spc_ndx( 'H2SO4' )
     218             : 
     219        2304 :     id_nh3     = get_spc_ndx( 'NH3' )
     220        2304 :     id_nh4     = get_spc_ndx( 'NH4' )
     221        2304 :     id_nh4no3  = get_spc_ndx( 'NH4NO3' )
     222             : 
     223        2304 :     id_isopn2b   = get_spc_ndx( 'ISOPN2B' )
     224        2304 :     id_isopn3b   = get_spc_ndx( 'ISOPN3B' )
     225        2304 :     id_isopn1d   = get_spc_ndx( 'ISOPN1D' )
     226        2304 :     id_isopn4d   = get_spc_ndx( 'ISOPN4D' )
     227        2304 :     id_isopnbno3 = get_spc_ndx('ISOPNBNO3' )
     228        2304 :     id_isopfdn   = get_spc_ndx( 'ISOPFDN' )
     229        2304 :     id_isopfdnc  = get_spc_ndx( 'ISOPFDNC')
     230        2304 :     id_terpfdn   = get_spc_ndx( 'TERPFDN' )
     231        2304 :     id_isopfnp   = get_spc_ndx( 'ISOPFNP' )
     232        2304 :     id_isopnoohb = get_spc_ndx( 'ISOPNOOHB' )
     233        2304 :     id_isopnoohd = get_spc_ndx( 'ISOPNOOHD' )
     234        2304 :     id_inheb     = get_spc_ndx( 'INHEB' )
     235        2304 :     id_inhed     = get_spc_ndx( 'INHED' )
     236        2304 :     id_no3ch2cho = get_spc_ndx( 'NO3CH2CHO' )
     237        2304 :     id_macrn     = get_spc_ndx( 'MACRN' )
     238        2304 :     id_mvkn      = get_spc_ndx( 'MVKN' )
     239        2304 :     id_isopfnc   = get_spc_ndx( 'ISOPFNC' )
     240        2304 :     id_terpns    = get_spc_ndx( 'TERPNS' )
     241        2304 :     id_terpnt    = get_spc_ndx( 'TERPNT' )
     242        2304 :     id_terpnt1   = get_spc_ndx( 'TERPNT1' )
     243        2304 :     id_terpns1   = get_spc_ndx( 'TERPNS1' )
     244        2304 :     id_terpnpt   = get_spc_ndx( 'TERPNPT' )
     245        2304 :     id_terpnps   = get_spc_ndx( 'TERPNPS' )
     246        2304 :     id_terpnpt1  = get_spc_ndx( 'TERPNPT1' )
     247        2304 :     id_terpnps1  = get_spc_ndx( 'TERPNPS1' )
     248        2304 :     id_sqtn      = get_spc_ndx( 'SQTN' )
     249        2304 :     id_terphfn   = get_spc_ndx( 'TERPHFN' )
     250        2304 :     id_terpapan  = get_spc_ndx( 'TERPAPAN' )
     251        2304 :     id_terpa2pan = get_spc_ndx( 'TERPA2PAN' )
     252        2304 :     id_terpa3pan = get_spc_ndx( 'TERPA3PAN' )
     253             : 
     254        2304 :     id_dst01   = get_spc_ndx( 'DST01' )
     255        2304 :     id_dst02   = get_spc_ndx( 'DST02' )
     256        2304 :     id_dst03   = get_spc_ndx( 'DST03' )
     257        2304 :     id_dst04   = get_spc_ndx( 'DST04' )
     258        2304 :     id_sslt01  = get_spc_ndx( 'SSLT01' )
     259        2304 :     id_sslt02  = get_spc_ndx( 'SSLT02' )
     260        2304 :     id_sslt03  = get_spc_ndx( 'SSLT03' )
     261        2304 :     id_sslt04  = get_spc_ndx( 'SSLT04' )
     262        2304 :     id_soa     = get_spc_ndx( 'SOA' )
     263        2304 :     id_so4     = get_spc_ndx( 'SO4' )
     264        2304 :     id_oc1     = get_spc_ndx( 'OC1' )
     265        2304 :     id_oc2     = get_spc_ndx( 'OC2' )
     266        2304 :     id_cb1     = get_spc_ndx( 'CB1' )
     267        2304 :     id_cb2     = get_spc_ndx( 'CB2' )
     268             : 
     269        2304 :     rid_jno   = get_rxt_ndx( 'jno' )
     270        2304 :     rid_jno_i = get_rxt_ndx( 'jno_i' )
     271             : 
     272        2304 :     id_soam = get_spc_ndx( 'SOAM' )
     273        2304 :     id_soai = get_spc_ndx( 'SOAI' )
     274        2304 :     id_soat = get_spc_ndx( 'SOAT' )
     275        2304 :     id_soab = get_spc_ndx( 'SOAB' )
     276        2304 :     id_soax = get_spc_ndx( 'SOAX' )
     277             : 
     278             : 
     279             : !... NOY species
     280        9216 :     nox_species = (/ id_n, id_no, id_no2 /)
     281             :     noy_species = (/ id_n, id_no, id_no2, id_no3, id_n2o5, id_hno3, id_ho2no2, id_clono2, &
     282             :                      id_brono2, id_pan, id_onit, id_mpan, id_isopno3, id_onitr, id_nh4no3, &
     283             :                      id_honitr, id_alknit, id_isopnita, id_isopnitb, id_isopnooh, id_nc4ch2oh, &
     284             :                      id_nc4cho, id_noa, id_nterpooh, id_pbznit, id_terpnit, &
     285             :                      id_isopn2b, id_isopn3b, id_isopn1d, id_isopn4d, id_isopnbno3, &
     286             :                      id_isopfdn, id_isopfdnc, id_terpfdn, &
     287             :                      id_isopfnp, id_isopnoohb, id_isopnoohd, id_inheb, id_inhed, &
     288             :                      id_no3ch2cho, id_macrn, id_mvkn, id_isopfnc, id_terpns, &
     289             :                      id_terpnt, id_terpnt1, id_terpns1, id_terpnpt, id_terpnps, &
     290             :                      id_terpnpt1, id_terpnps1, id_sqtn, id_terphfn, &
     291      131328 :                      id_terpapan, id_terpa2pan, id_terpa3pan /)
     292             : !... HOX species
     293       11520 :     hox_species = (/ id_h, id_oh, id_ho2, id_h2o2 /)
     294             : 
     295             : !... CLOY species
     296       16128 :     clox_species = (/ id_cl, id_clo, id_hocl, id_cl2, id_cl2o2, id_oclo /)
     297       23040 :     cloy_species = (/ id_cl, id_clo, id_hocl, id_cl2, id_cl2o2, id_oclo, id_hcl, id_clono2, id_brcl /)
     298             :     tcly_species = (/ id_cl, id_clo, id_hocl, id_cl2, id_cl2o2, id_oclo, id_hcl, id_clono2, id_brcl, &
     299             :                       id_ccl4, id_cfc11, id_cfc113, id_cfc114, id_cfc115, id_ch3ccl3, id_cfc12, id_ch3cl, &
     300       50688 :                       id_hcfc22, id_hcfc141b, id_hcfc142b, id_cf2clbr /)
     301             : 
     302             : !... FOY species
     303       11520 :     foy_species = (/ id_F, id_hf, id_cofcl, id_cof2 /)
     304             :     tfy_species = (/ id_f, id_hf, id_cofcl, id_cof2, id_cfc11, id_cfc12, id_cfc113, id_cfc114, id_cfc115, &
     305       39168 :                      id_hcfc22, id_hcfc141b, id_hcfc142b, id_cf2clbr, id_cf3br, id_h1202, id_h2402 /)
     306             : 
     307             : !... BROY species
     308       11520 :     brox_species = (/ id_br, id_bro, id_brcl, id_hobr /)
     309       16128 :     broy_species = (/ id_br, id_bro, id_hbr, id_brono2, id_brcl, id_hobr /)
     310             :     tbry_species = (/ id_br, id_bro, id_hbr, id_brono2, id_brcl, id_hobr, id_cf2clbr, id_cf3br, id_ch3br, id_h1202, &
     311       32256 :                       id_h2402, id_ch2br2, id_chbr3 /)
     312             : 
     313        9216 :     sox_species = (/ id_so2, id_so4, id_h2so4 /)
     314        6912 :     nhx_species = (/ id_nh3, id_nh4 /)
     315       48384 :     bulkaero_species(:) = -1
     316             :     bulkaero_species(1:20) = (/ id_dst01, id_dst02, id_dst03, id_dst04, &
     317             :                                 id_sslt01, id_sslt02, id_sslt03, id_sslt04, &
     318             :                                 id_soa, id_so4, id_oc1, id_oc2, id_cb1, id_cb2, id_nh4no3, &
     319       48384 :                                 id_soam,id_soai,id_soat,id_soab,id_soax /)
     320             : 
     321       73728 :     aer_species(:) = -1
     322        2304 :     n = 1
     323       73728 :     do m = 1,gas_pcnst
     324     1499904 :        k=0
     325     1499904 :        if ( any(bulkaero_species(:)==m) ) k=1
     326       71424 :        if ( k==0 ) k = index(trim(solsym(m)), '_a')
     327       71424 :        if ( k==0 ) k = index(trim(solsym(m)), '_c')
     328       73728 :        if ( k>0 ) then ! must be aerosol species
     329       43776 :           aer_species(n) = m
     330       43776 :           n = n+1
     331             :        endif
     332             :     enddo
     333             : 
     334        9216 :     toth_species = (/ id_ch4, id_h2o, id_h2 /)
     335             : 
     336      138240 :     chm_prod_ndep_flx = any(noy_species>0) .or. any(nhx_species>0)
     337             : 
     338        4608 :     call addfld( 'NOX',     (/ 'lev' /), 'A', 'mol/mol', 'nox (N+NO+NO2)' )
     339             :     call addfld( 'NOY',     (/ 'lev' /), 'A', 'mol/mol', &
     340        4608 :                  'noy = total nitrogen (N+NO+NO2+NO3+2N2O5+HNO3+HO2NO2+ORGNOY+NH4NO3)' )
     341        2304 :     call addfld( 'NOY_SRF', horiz_only,  'A', 'mol/mol', 'surface noy volume mixing ratio' )
     342        4608 :     call addfld( 'HOX',     (/ 'lev' /), 'A', 'mol/mol', 'HOx (H+OH+HO2+2H2O2)' )
     343             : 
     344        4608 :     call addfld( 'BROX',    (/ 'lev' /), 'A', 'mol/mol', 'brox (Br+BrO+BRCl+HOBr)' )
     345        4608 :     call addfld( 'BROY',    (/ 'lev' /), 'A', 'mol/mol', 'total inorganic bromine (Br+BrO+HOBr+BrONO2+HBr+BrCl)' )
     346        4608 :     call addfld( 'TBRY',    (/ 'lev' /), 'A', 'mol/mol', 'total Br (ORG+INORG) volume mixing ratio' )
     347             : 
     348        4608 :     call addfld( 'CLOX',    (/ 'lev' /), 'A', 'mol/mol', 'clox (Cl+CLO+HOCl+2Cl2+2Cl2O2+OClO)' )
     349        4608 :     call addfld( 'CLOY',    (/ 'lev' /), 'A', 'mol/mol', 'total inorganic chlorine (Cl+ClO+2Cl2+2Cl2O2+OClO+HOCl+ClONO2+HCl+BrCl)' )
     350        4608 :     call addfld( 'TCLY',    (/ 'lev' /), 'A', 'mol/mol', 'total Cl (ORG+INORG) volume mixing ratio' )
     351             : 
     352        4608 :     call addfld( 'FOY',     (/ 'lev' /), 'A', 'mol/mol', 'total inorganic fluorine (F+HF+COFCL+2COF2)' )
     353        4608 :     call addfld( 'TFY',     (/ 'lev' /), 'A', 'mol/mol', 'total F (ORG+INORG) volume mixing ratio' )
     354             : 
     355        4608 :     call addfld( 'TOTH',    (/ 'lev' /), 'A', 'mol/mol', 'total H2 volume mixing ratio' )
     356             : 
     357        4608 :     call addfld( 'NOY_mmr', (/ 'lev' /), 'A', 'kg/kg', 'NOy mass mixing ratio' )
     358        4608 :     call addfld( 'SOX_mmr', (/ 'lev' /), 'A', 'kg/kg', 'SOx mass mixing ratio' )
     359        4608 :     call addfld( 'NHX_mmr', (/ 'lev' /), 'A', 'kg/kg', 'NHx mass mixing ratio' )
     360             : 
     361       62208 :     do j = 1,NJEUV
     362       59904 :        write( jchar, '(I2)' ) j
     363       59904 :        jname = 'jeuv_'//trim(adjustl(jchar))
     364       62208 :        rid_jeuv(j) = get_rxt_ndx( trim(jname) )
     365             :     enddo
     366             : 
     367        2304 :     has_jeuvs = all( rid_jeuv(:) > 0 )
     368        2304 :     has_jno_i = rid_jno_i>0
     369        2304 :     has_jno   = rid_jno>0
     370             : 
     371        2304 :     if ( has_jeuvs ) then
     372           0 :        call addfld( 'PION_EUV', (/ 'lev' /), 'I', '/cm^3/s', 'total euv ionization rate' )
     373           0 :        call addfld( 'PEUV1',    (/ 'lev' /), 'I', '/cm^3/s', '(j1+j2+j3)*o' )
     374           0 :        call addfld( 'PEUV1e',   (/ 'lev' /), 'I', '/cm^3/s', '(j14+j15+j16)*o' )
     375           0 :        call addfld( 'PEUV2',    (/ 'lev' /), 'I', '/cm^3/s', 'j4*n' )
     376           0 :        call addfld( 'PEUV3',    (/ 'lev' /), 'I', '/cm^3/s', '(j5+j7+j8+j9)*o2' )
     377           0 :        call addfld( 'PEUV3e',   (/ 'lev' /), 'I', '/cm^3/s', '(j17+j19+j20+j21)*o2' )
     378           0 :        call addfld( 'PEUV4',    (/ 'lev' /), 'I', '/cm^3/s', '(j10+j11)*n2' )
     379           0 :        call addfld( 'PEUV4e',   (/ 'lev' /), 'I', '/cm^3/s', '(j22+j23)*n2' )
     380           0 :        call addfld( 'PEUVN2D',  (/ 'lev' /), 'I', '/cm^3/s', '(j11+j13)*n2' )
     381           0 :        call addfld( 'PEUVN2De', (/ 'lev' /), 'I', '/cm^3/s', '(j23+j25)*n2' )
     382             :     endif
     383        2304 :     if ( has_jno ) then
     384           0 :        call addfld( 'PJNO', (/ 'lev' /), 'I', '/cm^3/s', 'jno*no' )
     385             :     endif
     386        2304 :     if ( has_jno_i ) then
     387           0 :        call addfld( 'PJNO_I', (/ 'lev' /), 'I', '/cm^3/s', 'jno_i*no' )
     388             :     endif
     389             : !
     390             : ! CCMI
     391             : !
     392             :     call addfld( 'DO3CHM_TRP', horiz_only, 'A', 'kg/s', 'integrated net tendency from chem in troposphere',            &
     393        2304 :          flag_xyfill=.True. )
     394             :     call addfld( 'DO3CHM_LMS', horiz_only, 'A', 'kg/s', 'integrated net tendency from chem in lowermost stratosphere', &
     395        2304 :          flag_xyfill=.True. )
     396             : !
     397       73728 :     do m = 1,gas_pcnst
     398             : 
     399       71424 :        spc_name = trim(solsym(m))
     400             : 
     401       71424 :        call cnst_get_ind(spc_name, n, abort=.false. )
     402       71424 :        if ( n > 0 ) then
     403       69120 :           attr = cnst_longname(n)
     404        2304 :        elseif ( trim(spc_name) == 'H2O' ) then
     405        2304 :           attr = 'water vapor'
     406             :        else
     407           0 :           attr = spc_name
     408             :        endif
     409             : 
     410       71424 :        dtchem_name(m) = 'D'//trim(spc_name)//'CHM'
     411      142848 :        call addfld( dtchem_name(m), (/ 'lev' /), 'A', 'kg/s',    'net tendency from chem' )
     412             : 
     413       71424 :        depvel_name(m) = 'DV_'//trim(spc_name)
     414       71424 :        depflx_name(m) = 'DF_'//trim(spc_name)
     415       71424 :        if (has_drydep(spc_name)) then
     416             :           call addfld( depvel_name(m), horiz_only,  'A', 'cm/s',    'deposition velocity ' )
     417             :           call addfld( depflx_name(m), horiz_only,  'A', 'kg/m2/s', 'dry deposition flux ' )
     418       11520 :           if (history_chemistry) then
     419       11520 :              call add_default( depflx_name(m), 1, ' ' )
     420             :           endif
     421             :        endif
     422             : 
     423       71424 :        if (gas_wetdep_method=='MOZ') then
     424           0 :           wetdep_name(m) = 'WD_'//trim(spc_name)
     425           0 :           wtrate_name(m) = 'WDR_'//trim(spc_name)
     426             : 
     427           0 :           call addfld( wetdep_name(m), horiz_only,  'A', 'kg/s', spc_name//' wet deposition' )
     428           0 :           call addfld( wtrate_name(m), (/ 'lev' /), 'A',   '/s', spc_name//' wet deposition rate' )
     429             :        endif
     430             : 
     431       71424 :        if (spc_name(1:3) == 'num') then
     432        9216 :           unit_basename = ' 1'
     433             :        else
     434       62208 :           unit_basename = 'kg'
     435             :        endif
     436             : 
     437     1322496 :        if ( any( aer_species == m ) ) then
     438       87552 :           call addfld( spc_name,   (/ 'lev' /), 'A', unit_basename//'/kg ', trim(attr)//' concentration')
     439       43776 :           call addfld( trim(spc_name)//'_SRF', horiz_only, 'A', unit_basename//'/kg', trim(attr)//" in bottom layer")
     440             :        else
     441       55296 :           call addfld( spc_name, (/ 'lev' /), 'A', 'mol/mol', trim(attr)//' concentration')
     442       27648 :           call addfld( trim(spc_name)//'_SRF', horiz_only, 'A', 'mol/mol', trim(attr)//" in bottom layer")
     443             :        endif
     444             : 
     445       71424 :        if ((m /= id_cly) .and. (m /= id_bry)) then
     446       71424 :           if (history_aerosol.or.history_chemistry) then
     447       71424 :              call add_default( spc_name, 1, ' ' )
     448             :           endif
     449       71424 :           if (history_chemspecies_srf) then
     450       71424 :              call add_default( trim(spc_name)//'_SRF', 1, ' ' )
     451             :           endif
     452             :        endif
     453             : 
     454       71424 :        if ( history_cesm_forcing ) then
     455           0 :           if (m==id_o3)  call add_default( spc_name, 1, ' ')
     456           0 :           if (m==id_oh)  call add_default( spc_name, 1, ' ')
     457           0 :           if (m==id_no3) call add_default( spc_name, 1, ' ')
     458           0 :           if (m==id_ho2) call add_default( spc_name, 1, ' ')
     459             : 
     460           0 :           if (m==id_o3)     call add_default( spc_name, 8, ' ')
     461           0 :           if (m==id_so4_a1) call add_default( spc_name, 8, ' ')
     462           0 :           if (m==id_so4_a2) call add_default( spc_name, 8, ' ')
     463           0 :           if (m==id_so4_a3) call add_default( spc_name, 8, ' ')
     464             : 
     465           0 :           if (m==id_num_a2) call add_default( spc_name, 8, ' ')
     466           0 :           if (m==id_num_a3) call add_default( spc_name, 8, ' ')
     467           0 :           if (m==id_dst_a3) call add_default( spc_name, 8, ' ')
     468           0 :           if (m==id_ncl_a3) call add_default( spc_name, 8, ' ')
     469             : 
     470             :        endif
     471       71424 :        if ( history_scwaccm_forcing ) then
     472           0 :           if (m==id_co2) call add_default( spc_name, 8, ' ')
     473           0 :           if (m==id_h)   call add_default( spc_name, 8, ' ')
     474           0 :           if (m==id_no)  call add_default( spc_name, 8, ' ')
     475           0 :           if (m==id_o)   call add_default( spc_name, 8, ' ')
     476           0 :           if (m==id_o2)  call add_default( spc_name, 8, ' ')
     477           0 :           if (m==id_o3)  call add_default( spc_name, 8, ' ')
     478           0 :           if (m==id_h2o)    call add_default( spc_name, 1, ' ')
     479           0 :           if (m==id_ch4 )   call add_default( spc_name, 1, ' ')
     480           0 :           if (m==id_n2o )   call add_default( spc_name, 1, ' ')
     481           0 :           if (m==id_cfc11 ) call add_default( spc_name, 1, ' ')
     482           0 :           if (m==id_cfc12 ) call add_default( spc_name, 1, ' ')
     483             :        endif
     484             : 
     485       73728 :        if (history_dust .and. (index(spc_name,'dst_') > 0))  call add_default( spc_name, 1, ' ')
     486             : 
     487             :     enddo
     488             : 
     489        4608 :     call addfld( 'MASS', (/ 'lev' /), 'A', 'kg', 'mass of grid box' )
     490        2304 :     call addfld( 'AREA', horiz_only,  'A', 'm2', 'area of grid box' )
     491             : 
     492        2304 :     call addfld( 'dry_deposition_NOy_as_N', horiz_only, 'I', 'kg/m2/s', 'NOy dry deposition flux ' )
     493        2304 :     call addfld( 'DF_SOX', horiz_only, 'I', 'kg/m2/s', 'SOx dry deposition flux ' )
     494        2304 :     call addfld( 'dry_deposition_NHx_as_N', horiz_only, 'I', 'kg/m2/s', 'NHx dry deposition flux ' )
     495        2304 :     if (gas_wetdep_method=='NEU') then
     496        2304 :        call addfld( 'wet_deposition_NOy_as_N', horiz_only, 'A', 'kg/m2/s', 'NOy wet deposition' )
     497        2304 :        call addfld( 'wet_deposition_NHx_as_N', horiz_only, 'A', 'kg/m2/s', 'NHx wet deposition' )
     498           0 :     elseif (gas_wetdep_method=='MOZ') then
     499           0 :        call addfld( 'wet_deposition_NOy_as_N', horiz_only, 'A', 'kg/s', 'NOy wet deposition' )
     500           0 :        call addfld( 'WD_SOX', horiz_only, 'A', 'kg/s', 'SOx wet deposition' )
     501           0 :        call addfld( 'wet_deposition_NHx_as_N', horiz_only, 'A', 'kg/s', 'NHx wet deposition' )
     502             :     endif
     503        2304 :     if ( history_cesm_forcing ) then
     504           0 :        call add_default('dry_deposition_NOy_as_N', 1, ' ')
     505           0 :        call add_default('dry_deposition_NHx_as_N', 1, ' ')
     506           0 :        call add_default('wet_deposition_NOy_as_N', 1, ' ')
     507           0 :        call add_default('wet_deposition_NHx_as_N', 1, ' ')
     508             :     endif
     509             : 
     510        2304 :     call species_sums_init()
     511             : 
     512        2304 :   end subroutine chm_diags_inti
     513             : 
     514      179568 :   subroutine chm_diags( lchnk, ncol, vmr, mmr, rxt_rates, invariants, depvel, depflx, mmr_tend, pdel, pmid, ltrop, &
     515       89784 :                         wetdepflx, nhx_nitrogen_flx, noy_nitrogen_flx )
     516             :     !--------------------------------------------------------------------
     517             :     !   ... utility routine to output chemistry diagnostic variables
     518             :     !--------------------------------------------------------------------
     519             : 
     520        2304 :     use cam_history,  only : outfld
     521             :     use phys_grid,    only : get_area_all_p
     522             :     use species_sums_diags, only : species_sums_output
     523             : !
     524             : ! CCMI
     525             : !
     526             :     use cam_history_support, only : fillvalue
     527             : 
     528             :     !--------------------------------------------------------------------
     529             :     !   ... dummy arguments
     530             :     !--------------------------------------------------------------------
     531             :     integer,  intent(in)  :: lchnk
     532             :     integer,  intent(in)  :: ncol
     533             :     real(r8), intent(in)  :: vmr(ncol,pver,gas_pcnst)
     534             :     real(r8), intent(in)  :: mmr(ncol,pver,gas_pcnst)
     535             :     real(r8), intent(in)  :: rxt_rates(ncol,pver,rxntot)
     536             :     real(r8), intent(in)  :: invariants(ncol,pver,max(1,nfs))
     537             :     real(r8), intent(in)  :: depvel(ncol, gas_pcnst)
     538             :     real(r8), intent(in)  :: depflx(ncol, gas_pcnst)
     539             :     real(r8), intent(in)  :: mmr_tend(ncol,pver,gas_pcnst)
     540             :     real(r8), intent(in)  :: pdel(ncol,pver)
     541             :     real(r8), intent(in)  :: pmid(ncol,pver)
     542             :     integer,  intent(in)  :: ltrop(ncol)
     543             :     real(r8), intent(in)  :: wetdepflx(ncol, gas_pcnst)
     544             :     real(r8), intent(out) :: nhx_nitrogen_flx(ncol) ! kgN/m2/sec
     545             :     real(r8), intent(out) :: noy_nitrogen_flx(ncol) ! kgN/m2/sec
     546             : 
     547             :     !--------------------------------------------------------------------
     548             :     !   ... local variables
     549             :     !--------------------------------------------------------------------
     550             :     integer     :: i, k, m
     551      179568 :     real(r8)    :: wrk(ncol,pver)
     552             :     !      real(r8)    :: tmp(ncol,pver)
     553             :     !      real(r8)    :: m(ncol,pver)
     554      179568 :     real(r8)    :: un2(ncol)
     555             : 
     556      179568 :     real(r8), dimension(ncol,pver) :: vmr_nox, vmr_noy, vmr_clox, vmr_cloy, vmr_tcly, vmr_brox, vmr_broy, vmr_toth
     557      179568 :     real(r8), dimension(ncol,pver) :: vmr_tbry, vmr_foy, vmr_tfy
     558      179568 :     real(r8), dimension(ncol,pver) :: mmr_noy, mmr_sox, mmr_nhx, net_chem
     559      179568 :     real(r8), dimension(ncol)      :: df_noy, df_sox, df_nhx, do3chm_trp, do3chm_lms
     560      179568 :     real(r8), dimension(ncol)      :: wd_noy, wd_nhx
     561      179568 :     real(r8), dimension(ncol,pver) :: vmr_hox
     562             : 
     563       89784 :     real(r8) :: area(ncol), mass(ncol,pver)
     564             :     real(r8) :: wgt
     565             : 
     566             :     !--------------------------------------------------------------------
     567             :     !   ... "diagnostic" groups
     568             :     !--------------------------------------------------------------------
     569   139513896 :     vmr_nox(:ncol,:) = 0._r8
     570   139513896 :     vmr_noy(:ncol,:) = 0._r8
     571   139513896 :     vmr_hox(:ncol,:) = 0._r8
     572   139513896 :     vmr_clox(:ncol,:) = 0._r8
     573   139513896 :     vmr_cloy(:ncol,:) = 0._r8
     574   139513896 :     vmr_tcly(:ncol,:) = 0._r8
     575   139513896 :     vmr_brox(:ncol,:) = 0._r8
     576   139513896 :     vmr_broy(:ncol,:) = 0._r8
     577   139513896 :     vmr_tbry(:ncol,:) = 0._r8
     578   139513896 :     vmr_foy(:ncol,:)  = 0._r8
     579   139513896 :     vmr_tfy(:ncol,:)  = 0._r8
     580   139513896 :     vmr_toth(:ncol,:) = 0._r8
     581   139513896 :     mmr_noy(:ncol,:) = 0._r8
     582   139513896 :     mmr_sox(:ncol,:) = 0._r8
     583   139513896 :     mmr_nhx(:ncol,:) = 0._r8
     584     1499184 :     df_noy(:ncol) = 0._r8
     585     1499184 :     df_sox(:ncol) = 0._r8
     586     1499184 :     df_nhx(:ncol) = 0._r8
     587             : 
     588     1499184 :     wd_noy(:ncol) = 0._r8
     589     1499184 :     wd_nhx(:ncol) = 0._r8
     590             : 
     591       89784 :     call get_area_all_p(lchnk, ncol, area)
     592     1499184 :     area = area * rearth**2
     593             : 
     594     8439696 :     do k = 1,pver
     595   139513896 :        mass(:ncol,k) = pdel(:ncol,k) * area(:ncol) * rgrav
     596             :     enddo
     597             : 
     598       89784 :     call outfld( 'AREA', area(:ncol),   ncol, lchnk )
     599       89784 :     call outfld( 'MASS', mass(:ncol,:), ncol, lchnk )
     600             : 
     601     2873088 :     do m = 1,gas_pcnst
     602             : 
     603             :  !...FOY (counting Fluorines, not chlorines or bromines)
     604             :        if ( m == id_cfc12 .or. m == id_hcfc22 .or. m == id_cf2clbr .or. m == id_h1202 .or. m == id_hcfc142b &
     605     2783304 :             .or. m == id_cof2 ) then
     606             :           wgt = 2._r8
     607     2693520 :        elseif ( m == id_cfc113 .or. m == id_cf3br ) then
     608             :           wgt = 3._r8
     609     2693520 :        elseif ( m == id_cfc114 .or. m == id_h2402 ) then
     610             :           wgt = 4._r8
     611     2693520 :        elseif ( m == id_cfc115 ) then
     612             :           wgt = 5._r8
     613             :        else
     614     2693520 :           wgt = 1._r8
     615             :        endif
     616    13916520 :        if ( any( foy_species == m ) ) then
     617           0 :           vmr_foy(:ncol,:) = vmr_foy(:ncol,:) +  wgt * vmr(:ncol,:,m)
     618             :        endif
     619    45251136 :        if ( any( tfy_species == m ) ) then
     620   279027792 :           vmr_tfy(:ncol,:) = vmr_tfy(:ncol,:) +  wgt * vmr(:ncol,:,m)
     621             :        endif
     622             : 
     623             : !... counting chlorine and bromines, etc... (and total H2 species)
     624     2783304 :        if ( m == id_ch4 .or. m == id_n2o5 .or. m == id_cfc12 .or. m == id_cl2 .or. m == id_cl2o2 .or. m==id_h2o2  ) then
     625             :           wgt = 2._r8
     626     2513952 :        elseif (m == id_cfc114 .or. m == id_hcfc141b .or. m == id_h1202 .or. m == id_h2402 .or. m == id_ch2br2 ) then
     627             :           wgt = 2._r8
     628     2513952 :        elseif (m == id_isopfdn .or. m == id_isopfdnc .or. m == id_terpfdn ) then
     629             :           wgt = 2._r8
     630     2513952 :        elseif ( m == id_cfc11 .or. m == id_cfc113 .or. m == id_ch3ccl3 .or. m == id_chbr3 ) then
     631             :           wgt = 3._r8
     632     2424168 :        elseif ( m == id_ccl4 ) then
     633             :           wgt = 4._r8
     634             :        else
     635     2424168 :           wgt = 1._r8
     636             :        endif
     637             : !...NOY
     638    11133216 :        if ( any( nox_species == m ) ) then
     639           0 :           vmr_nox(:ncol,:) = vmr_nox(:ncol,:) +  wgt * vmr(:ncol,:,m)
     640             :        endif
     641   158648328 :        if ( any( noy_species == m ) ) then
     642           0 :           vmr_noy(:ncol,:) = vmr_noy(:ncol,:) +  wgt * vmr(:ncol,:,m)
     643             :        endif
     644             : !...NOY, SOX, NHX
     645   158648328 :        if ( any( noy_species == m ) ) then
     646           0 :           mmr_noy(:ncol,:) = mmr_noy(:ncol,:) +  wgt * mmr(:ncol,:,m)
     647             :        endif
     648    10774080 :        if ( any( sox_species == m ) ) then
     649   279027792 :           mmr_sox(:ncol,:) = mmr_sox(:ncol,:) +  wgt * mmr(:ncol,:,m)
     650             :        endif
     651     8349912 :        if ( any( nhx_species == m ) ) then
     652           0 :           mmr_nhx(:ncol,:) = mmr_nhx(:ncol,:) +  wgt * mmr(:ncol,:,m)
     653             :        endif
     654             : !...CLOY
     655    19483128 :        if ( any( clox_species == m ) ) then
     656           0 :           vmr_clox(:ncol,:) = vmr_clox(:ncol,:) +  wgt * vmr(:ncol,:,m)
     657             :        endif
     658    27833040 :        if ( any( cloy_species == m ) ) then
     659           0 :           vmr_cloy(:ncol,:) = vmr_cloy(:ncol,:) +  wgt * vmr(:ncol,:,m)
     660             :        endif
     661    59706360 :        if ( any( tcly_species == m ) ) then
     662   279027792 :           vmr_tcly(:ncol,:) = vmr_tcly(:ncol,:) +  wgt * vmr(:ncol,:,m)
     663             :        endif
     664             : !...BROY
     665    13916520 :        if ( any( brox_species == m ) ) then
     666           0 :           vmr_brox(:ncol,:) = vmr_brox(:ncol,:) +  wgt * vmr(:ncol,:,m)
     667             :        endif
     668    19483128 :        if ( any( broy_species == m ) ) then
     669           0 :           vmr_broy(:ncol,:) = vmr_broy(:ncol,:) +  wgt * vmr(:ncol,:,m)
     670             :        endif
     671    38966256 :        if ( any( tbry_species == m ) ) then
     672           0 :           vmr_tbry(:ncol,:) = vmr_tbry(:ncol,:) +  wgt * vmr(:ncol,:,m)
     673             :        endif
     674             : !...HOY
     675    10684296 :        if ( any ( toth_species == m ) ) then
     676   279027792 :           vmr_toth(:ncol,:) = vmr_toth(:ncol,:) +  wgt * vmr(:ncol,:,m)
     677             :        endif
     678             : !...HOx
     679    13826736 :        if ( any( hox_species == m ) ) then
     680   139513896 :           vmr_hox(:ncol,:) = vmr_hox(:ncol,:) +  wgt * vmr(:ncol,:,m)
     681             :        endif
     682             : 
     683    51536016 :        if ( any( aer_species == m ) ) then
     684     1705896 :           call outfld( solsym(m), mmr(:ncol,:,m), ncol ,lchnk )
     685     1705896 :           call outfld( trim(solsym(m))//'_SRF', mmr(:ncol,pver,m), ncol ,lchnk )
     686             :        else
     687     1077408 :           call outfld( solsym(m), vmr(:ncol,:,m), ncol ,lchnk )
     688     1077408 :           call outfld( trim(solsym(m))//'_SRF', vmr(:ncol,pver,m), ncol ,lchnk )
     689             :        endif
     690             : 
     691     2783304 :        if (has_drydep(solsym(m))) then
     692      448920 :           call outfld( depvel_name(m), depvel(:ncol,m), ncol ,lchnk )
     693      448920 :           call outfld( depflx_name(m), depflx(:ncol,m), ncol ,lchnk )
     694             :        endif
     695             : 
     696   158648328 :        if ( any( noy_species == m ) ) then
     697           0 :           df_noy(:ncol) = df_noy(:ncol) +  wgt * depflx(:ncol,m)*N_molwgt/adv_mass(m)
     698             :        endif
     699    10774080 :        if ( any( sox_species == m ) ) then
     700     2998368 :           df_sox(:ncol) = df_sox(:ncol) +  wgt * depflx(:ncol,m)*S_molwgt/adv_mass(m)
     701             :        endif
     702     8349912 :        if ( any( nhx_species == m ) ) then
     703           0 :           df_nhx(:ncol) = df_nhx(:ncol) +  wgt * depflx(:ncol,m)*N_molwgt/adv_mass(m)
     704             :        endif
     705             : 
     706   158648328 :        if ( any( noy_species == m ) ) then
     707           0 :           wd_noy(:ncol) = wd_noy(:ncol) +  wgt * wetdepflx(:ncol,m)*N_molwgt/adv_mass(m)
     708             :        endif
     709     8349912 :        if ( any( nhx_species == m ) ) then
     710           0 :           wd_nhx(:ncol) = wd_nhx(:ncol) +  wgt * wetdepflx(:ncol,m)*N_molwgt/adv_mass(m)
     711             :        endif
     712             : !
     713             : ! add contribution from non-conservation tracers
     714             : !
     715     2783304 :        if ( id_ndep == m ) then
     716           0 :           wd_noy(:ncol) = wd_noy(:ncol) +  wgt * wetdepflx(:ncol,m)*N_molwgt/adv_mass(m)
     717             :        end if
     718     2783304 :        if ( id_nhdep == m ) then
     719           0 :           wd_nhx(:ncol) = wd_nhx(:ncol) +  wgt * wetdepflx(:ncol,m)*N_molwgt/adv_mass(m)
     720             :        end if
     721             : 
     722   261630576 :        do k=1,pver
     723  4324930776 :           do i=1,ncol
     724  4322147472 :              net_chem(i,k) = mmr_tend(i,k,m) * mass(i,k)
     725             :           end do
     726             :        end do
     727             :        call outfld( dtchem_name(m), net_chem(:ncol,:), ncol, lchnk )
     728             : !
     729             : ! CCMI
     730             : !
     731     2873088 :        if ( trim(dtchem_name(m)) == 'DO3CHM' ) then
     732           0 :           do3chm_trp(:) = 0._r8
     733           0 :           do i=1,ncol
     734           0 :              do k=ltrop(i),pver
     735           0 :                 do3chm_trp(i) = do3chm_trp(i) + net_chem(i,k)
     736             :              end do
     737             :           end do
     738           0 :           where ( do3chm_trp == 0._r8 )
     739             :              do3chm_trp = fillvalue
     740             :           end where
     741           0 :           call outfld('DO3CHM_TRP',do3chm_trp(:ncol), ncol, lchnk )
     742           0 :           do3chm_lms(:) = 0._r8
     743           0 :           do i=1,ncol
     744           0 :              do k=1,pver
     745           0 :                 if ( pmid(i,k) > 100.e2_r8 .and. k < ltrop(i) ) then
     746           0 :                    do3chm_lms(i) = do3chm_lms(i) + net_chem(i,k)
     747             :                 end if
     748             :              end do
     749             :           end do
     750           0 :           where ( do3chm_lms == 0._r8 )
     751             :              do3chm_lms = fillvalue
     752             :           end where
     753           0 :           call outfld('DO3CHM_LMS',do3chm_lms(:ncol), ncol, lchnk )
     754             :        end if
     755             : !
     756             :     enddo
     757             : 
     758             : 
     759       89784 :     call outfld( 'NOX',  vmr_nox  (:ncol,:), ncol, lchnk )
     760       89784 :     call outfld( 'NOY',  vmr_noy  (:ncol,:), ncol, lchnk )
     761       89784 :     call outfld( 'HOX',  vmr_hox  (:ncol,:), ncol, lchnk )
     762       89784 :     call outfld( 'NOY_SRF',  vmr_noy(:ncol,pver),  ncol, lchnk )
     763       89784 :     call outfld( 'CLOX', vmr_clox (:ncol,:), ncol, lchnk )
     764       89784 :     call outfld( 'CLOY', vmr_cloy (:ncol,:), ncol, lchnk )
     765       89784 :     call outfld( 'BROX', vmr_brox (:ncol,:), ncol, lchnk )
     766       89784 :     call outfld( 'BROY', vmr_broy (:ncol,:), ncol, lchnk )
     767       89784 :     call outfld( 'TCLY', vmr_tcly (:ncol,:), ncol, lchnk )
     768       89784 :     call outfld( 'TBRY', vmr_tbry (:ncol,:), ncol, lchnk )
     769       89784 :     call outfld( 'FOY',  vmr_foy  (:ncol,:), ncol, lchnk )
     770       89784 :     call outfld( 'TFY',  vmr_tfy  (:ncol,:), ncol, lchnk )
     771       89784 :     call outfld( 'TOTH', vmr_toth (:ncol,:), ncol, lchnk )
     772             : 
     773       89784 :     call outfld( 'NOY_mmr', mmr_noy(:ncol,:), ncol ,lchnk )
     774       89784 :     call outfld( 'SOX_mmr', mmr_sox(:ncol,:), ncol ,lchnk )
     775       89784 :     call outfld( 'NHX_mmr', mmr_nhx(:ncol,:), ncol ,lchnk )
     776       89784 :     call outfld( 'dry_deposition_NOy_as_N', df_noy(:ncol), ncol ,lchnk )
     777       89784 :     call outfld( 'DF_SOX', df_sox(:ncol), ncol ,lchnk )
     778       89784 :     call outfld( 'dry_deposition_NHx_as_N', df_nhx(:ncol), ncol ,lchnk )
     779       89784 :     if (gas_wetdep_method=='NEU') then
     780     1499184 :       wd_noy(:ncol) = -wd_noy(:ncol) ! downward is possitive
     781     1499184 :       wd_nhx(:ncol) = -wd_nhx(:ncol)
     782       89784 :       call outfld( 'wet_deposition_NOy_as_N', wd_noy(:ncol), ncol, lchnk )
     783       89784 :       call outfld( 'wet_deposition_NHx_as_N', wd_nhx(:ncol), ncol, lchnk )
     784             :     end if
     785             : 
     786     1499184 :     nhx_nitrogen_flx = df_nhx + wd_nhx
     787     1499184 :     noy_nitrogen_flx = df_noy + wd_noy
     788             : 
     789             :     !--------------------------------------------------------------------
     790             :     !   ... euv ion production
     791             :     !--------------------------------------------------------------------
     792             : 
     793       89784 :     jeuvs: if ( has_jeuvs ) then
     794           0 :        do k = 1,pver
     795           0 :           un2(:)   = 1._r8 - (vmr(:,k,id_o) + vmr(:,k,id_o2) + vmr(:,k,id_h))
     796           0 :           wrk(:,k) = vmr(:,k,id_o)*(rxt_rates(:,k,rid_jeuv(1)) + rxt_rates(:,k,rid_jeuv(2)) &
     797           0 :                + rxt_rates(:,k,rid_jeuv(3)) + rxt_rates(:,k,rid_jeuv(14)) &
     798           0 :                + rxt_rates(:,k,rid_jeuv(15)) + rxt_rates(:,k,rid_jeuv(16))) &
     799           0 :                + vmr(:,k,id_n)*rxt_rates(:,k,rid_jeuv(4)) &
     800           0 :                + vmr(:,k,id_o2)*(rxt_rates(:,k,rid_jeuv(5)) + rxt_rates(:,k,rid_jeuv(7)) &
     801           0 :                + rxt_rates(:,k,rid_jeuv(8)) + rxt_rates(:,k,rid_jeuv(9)) &
     802           0 :                + rxt_rates(:,k,rid_jeuv(17)) + rxt_rates(:,k,rid_jeuv(19)) &
     803           0 :                + rxt_rates(:,k,rid_jeuv(20)) + rxt_rates(:,k,rid_jeuv(21))) &
     804           0 :                + un2(:)*(rxt_rates(:,k,rid_jeuv(6)) + rxt_rates(:,k,rid_jeuv(10)) &
     805           0 :                + rxt_rates(:,k,rid_jeuv(11)) + rxt_rates(:,k,rid_jeuv(18)) &
     806           0 :                + rxt_rates(:,k,rid_jeuv(22)) + rxt_rates(:,k,rid_jeuv(23)))
     807           0 :           wrk(:,k) = wrk(:,k) * invariants(:,k,indexm)
     808             :        end do
     809           0 :        call outfld( 'PION_EUV', wrk, ncol, lchnk )
     810             : 
     811           0 :        do k = 1,pver
     812           0 :           wrk(:,k) = vmr(:,k,id_o)*(rxt_rates(:,k,rid_jeuv(1)) + rxt_rates(:,k,rid_jeuv(2)) &
     813           0 :                + rxt_rates(:,k,rid_jeuv(3)))
     814           0 :           wrk(:,k) = wrk(:,k) * invariants(:,k,indexm)
     815             :        end do
     816           0 :        call outfld( 'PEUV1', wrk, ncol, lchnk )
     817           0 :        do k = 1,pver
     818           0 :           wrk(:,k) = vmr(:,k,id_o)*(rxt_rates(:,k,rid_jeuv(14)) + rxt_rates(:,k,rid_jeuv(15)) &
     819           0 :                + rxt_rates(:,k,rid_jeuv(16)))
     820           0 :           wrk(:,k) = wrk(:,k) * invariants(:,k,indexm)
     821             :        end do
     822           0 :        call outfld( 'PEUV1e', wrk, ncol, lchnk )
     823           0 :        do k = 1,pver
     824           0 :           wrk(:,k) = vmr(:,k,id_n)*rxt_rates(:,k,rid_jeuv(4))
     825           0 :           wrk(:,k) = wrk(:,k) * invariants(:,k,indexm)
     826             :        end do
     827           0 :        call outfld( 'PEUV2', wrk, ncol, lchnk )
     828           0 :        do k = 1,pver
     829           0 :           wrk(:,k) = vmr(:,k,id_o2)*(rxt_rates(:,k,rid_jeuv(5)) + rxt_rates(:,k,rid_jeuv(7)) &
     830           0 :                + rxt_rates(:,k,rid_jeuv(8)) + rxt_rates(:,k,rid_jeuv(9)))
     831           0 :           wrk(:,k) = wrk(:,k) * invariants(:,k,indexm)
     832             :        end do
     833           0 :        call outfld( 'PEUV3', wrk, ncol, lchnk )
     834           0 :        do k = 1,pver
     835           0 :           wrk(:,k) = vmr(:,k,id_o2)*(rxt_rates(:,k,rid_jeuv(17)) + rxt_rates(:,k,rid_jeuv(19)) &
     836           0 :                + rxt_rates(:,k,rid_jeuv(20)) + rxt_rates(:,k,rid_jeuv(21)))
     837           0 :           wrk(:,k) = wrk(:,k) * invariants(:,k,indexm)
     838             :        end do
     839           0 :        call outfld( 'PEUV3e', wrk, ncol, lchnk )
     840           0 :        do k = 1,pver
     841           0 :           un2(:)   = 1._r8 - (vmr(:,k,id_o) + vmr(:,k,id_o2) + vmr(:,k,id_h))
     842           0 :           wrk(:,k) = un2(:)*(rxt_rates(:,k,rid_jeuv(6)) + rxt_rates(:,k,rid_jeuv(10)) + rxt_rates(:,k,rid_jeuv(11)))
     843           0 :           wrk(:,k) = wrk(:,k) * invariants(:,k,indexm)
     844             :        end do
     845           0 :        call outfld( 'PEUV4', wrk, ncol, lchnk )
     846           0 :        do k = 1,pver
     847           0 :           un2(:)   = 1._r8 - (vmr(:,k,id_o) + vmr(:,k,id_o2) + vmr(:,k,id_h))
     848           0 :           wrk(:,k) = un2(:)*(rxt_rates(:,k,rid_jeuv(18)) + rxt_rates(:,k,rid_jeuv(22)) + rxt_rates(:,k,rid_jeuv(23)))
     849           0 :           wrk(:,k) = wrk(:,k) * invariants(:,k,indexm)
     850             :        end do
     851           0 :        call outfld( 'PEUV4e', wrk, ncol, lchnk )
     852           0 :        do k = 1,pver
     853           0 :           un2(:)   = 1._r8 - (vmr(:,k,id_o) + vmr(:,k,id_o2) + vmr(:,k,id_h))
     854           0 :           wrk(:,k) = un2(:)*(rxt_rates(:,k,rid_jeuv(11)) + rxt_rates(:,k,rid_jeuv(13)))
     855           0 :           wrk(:,k) = wrk(:,k) * invariants(:,k,indexm)
     856             :        end do
     857           0 :        call outfld( 'PEUVN2D', wrk, ncol, lchnk )
     858           0 :        do k = 1,pver
     859           0 :           un2(:)   = 1._r8 - (vmr(:,k,id_o) + vmr(:,k,id_o2) + vmr(:,k,id_h))
     860           0 :           wrk(:,k) = un2(:)*(rxt_rates(:,k,rid_jeuv(23)) + rxt_rates(:,k,rid_jeuv(25)))
     861           0 :           wrk(:,k) = wrk(:,k) * invariants(:,k,indexm)
     862             :        end do
     863           0 :        call outfld( 'PEUVN2De', wrk, ncol, lchnk )
     864             :     endif jeuvs
     865             : 
     866       89784 :     if ( has_jno_i ) then
     867           0 :        do k = 1,pver
     868           0 :           wrk(:,k) = vmr(:,k,id_no)*rxt_rates(:,k,rid_jno_i)
     869           0 :           wrk(:,k) = wrk(:,k) * invariants(:,k,indexm)
     870             :        end do
     871           0 :        call outfld( 'PJNO_I', wrk, ncol, lchnk )
     872             :     endif
     873       89784 :     if ( has_jno ) then
     874           0 :        do k = 1,pver
     875           0 :           wrk(:,k) = vmr(:,k,id_no)*rxt_rates(:,k,rid_jno)
     876           0 :           wrk(:,k) = wrk(:,k) * invariants(:,k,indexm)
     877             :        end do
     878           0 :        call outfld( 'PJNO', wrk, ncol, lchnk )
     879             :     endif
     880             : 
     881       89784 :     call species_sums_output(vmr, mmr, ncol, lchnk)
     882             : 
     883       89784 :   end subroutine chm_diags
     884             : 
     885       89784 :   subroutine het_diags( het_rates, mmr, pdel, lchnk, ncol )
     886             : 
     887       89784 :     use cam_history,  only : outfld
     888             :     use phys_grid,    only : get_wght_all_p
     889             : 
     890             :     integer,  intent(in)  :: lchnk
     891             :     integer,  intent(in)  :: ncol
     892             :     real(r8), intent(in)  :: het_rates(ncol,pver,max(1,gas_pcnst))
     893             :     real(r8), intent(in)  :: mmr(ncol,pver,gas_pcnst)
     894             :     real(r8), intent(in)  :: pdel(ncol,pver)
     895             : 
     896      179568 :     real(r8), dimension(ncol) :: noy_wk, sox_wk, nhx_wk, wrk_wd
     897             :     integer :: m, k
     898       89784 :     real(r8) :: wght(ncol)
     899             :     !
     900             :     ! output integrated wet deposition field
     901             :     !
     902     1499184 :     noy_wk(:) = 0._r8
     903     1499184 :     sox_wk(:) = 0._r8
     904     1499184 :     nhx_wk(:) = 0._r8
     905             : 
     906       89784 :     call get_wght_all_p(lchnk, ncol, wght)
     907             : 
     908     2873088 :     do m = 1,gas_pcnst
     909             :        !
     910             :        ! compute vertical integral
     911             :        !
     912    46474704 :        wrk_wd(:ncol) = 0._r8
     913   261630576 :        do k = 1,pver
     914  4324930776 :           wrk_wd(:ncol) = wrk_wd(:ncol) + het_rates(:ncol,k,m) * mmr(:ncol,k,m) * pdel(:ncol,k)
     915             :        end do
     916             :        !
     917    46474704 :        wrk_wd(:ncol) = wrk_wd(:ncol) * rgrav * wght(:ncol) * rearth**2
     918             :        !
     919     2873088 :        if (gas_wetdep_method=='MOZ') then
     920           0 :           call outfld( wetdep_name(m), wrk_wd(:ncol),               ncol, lchnk )
     921           0 :           call outfld( wtrate_name(m), het_rates(:ncol,:,m), ncol, lchnk )
     922             : 
     923           0 :           if ( any(noy_species == m ) ) then
     924           0 :              noy_wk(:ncol) = noy_wk(:ncol) + wrk_wd(:ncol)*N_molwgt/adv_mass(m)
     925             :           endif
     926           0 :           if ( m == id_n2o5 ) then  ! 2 NOy molecules in N2O5
     927           0 :              noy_wk(:ncol) = noy_wk(:ncol) + wrk_wd(:ncol)*N_molwgt/adv_mass(m)
     928             :           endif
     929           0 :           if ( any(sox_species == m ) ) then
     930           0 :              sox_wk(:ncol) = sox_wk(:ncol) + wrk_wd(:ncol)*S_molwgt/adv_mass(m)
     931             :           endif
     932           0 :           if ( any(nhx_species == m ) ) then
     933           0 :              nhx_wk(:ncol) = nhx_wk(:ncol) + wrk_wd(:ncol)*N_molwgt/adv_mass(m)
     934             :           endif
     935             :        endif
     936             :     end do
     937       89784 :     if (gas_wetdep_method=='MOZ') then
     938           0 :        call outfld( 'wet_deposition_NOy_as_N', noy_wk(:ncol), ncol, lchnk )
     939           0 :        call outfld( 'WD_SOX', sox_wk(:ncol), ncol, lchnk )
     940           0 :        call outfld( 'wet_deposition_NHx_as_N', nhx_wk(:ncol), ncol, lchnk )
     941             :     endif
     942             : 
     943       89784 :   end subroutine het_diags
     944             : 
     945             : end module mo_chm_diags

Generated by: LCOV version 1.14