LCOV - code coverage report
Current view: top level - chemistry/mozart - mo_chm_diags.F90 (source / functions) Hit Total Coverage
Test: coverage.info Lines: 480 533 90.1 %
Date: 2025-03-14 01:26:08 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       22656 :   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         768 :                        history_dust_out = history_dust )
     119             : 
     120         768 :     id_bry     = get_spc_ndx( 'BRY' )
     121         768 :     id_cly     = get_spc_ndx( 'CLY' )
     122             : 
     123         768 :     id_n       = get_spc_ndx( 'N' )
     124         768 :     id_no      = get_spc_ndx( 'NO' )
     125         768 :     id_no2     = get_spc_ndx( 'NO2' )
     126         768 :     id_no3     = get_spc_ndx( 'NO3' )
     127         768 :     id_n2o5    = get_spc_ndx( 'N2O5' )
     128         768 :     id_n2o     = get_spc_ndx( 'N2O' )
     129         768 :     id_hno3    = get_spc_ndx( 'HNO3' )
     130         768 :     id_ho2no2  = get_spc_ndx( 'HO2NO2' )
     131         768 :     id_clono2  = get_spc_ndx( 'CLONO2' )
     132         768 :     id_brono2  = get_spc_ndx( 'BRONO2' )
     133         768 :     id_cl      = get_spc_ndx( 'CL' )
     134         768 :     id_clo     = get_spc_ndx( 'CLO' )
     135         768 :     id_hocl    = get_spc_ndx( 'HOCL' )
     136         768 :     id_cl2     = get_spc_ndx( 'CL2' )
     137         768 :     id_cl2o2   = get_spc_ndx( 'CL2O2' )
     138         768 :     id_oclo    = get_spc_ndx( 'OCLO' )
     139         768 :     id_hcl     = get_spc_ndx( 'HCL' )
     140         768 :     id_brcl    = get_spc_ndx( 'BRCL' )
     141             : 
     142         768 :     id_co2     = get_spc_ndx( 'CO2' )
     143         768 :     id_o3      = get_spc_ndx( 'O3' )
     144         768 :     id_oh      = get_spc_ndx( 'OH' )
     145         768 :     id_ho2     = get_spc_ndx( 'HO2' )
     146         768 :     id_h2o2    = get_spc_ndx( 'H2O2' )
     147         768 :     id_so4_a1  = get_spc_ndx( 'so4_a1' )
     148         768 :     id_so4_a2  = get_spc_ndx( 'so4_a2' )
     149         768 :     id_so4_a3  = get_spc_ndx( 'so4_a3' )
     150         768 :     id_num_a2  = get_spc_ndx( 'num_a2' )
     151         768 :     id_num_a3  = get_spc_ndx( 'num_a3' )
     152         768 :     id_dst_a3  = get_spc_ndx( 'dst_a3' )
     153         768 :     id_ncl_a3  = get_spc_ndx( 'ncl_a3' )
     154             : 
     155         768 :     id_f       = get_spc_ndx( 'F' )
     156         768 :     id_hf      = get_spc_ndx( 'HF' )
     157         768 :     id_cofcl   = get_spc_ndx( 'COFCL' )
     158         768 :     id_cof2    = get_spc_ndx( 'COF2' )
     159             : 
     160         768 :     id_ccl4    = get_spc_ndx( 'CCL4' )
     161         768 :     id_cfc11   = get_spc_ndx( 'CFC11' )
     162             : 
     163         768 :     id_cfc113  = get_spc_ndx( 'CFC113' )
     164         768 :     id_cfc114  = get_spc_ndx( 'CFC114' )
     165         768 :     id_cfc115  = get_spc_ndx( 'CFC115' )
     166             : 
     167         768 :     id_ch3ccl3 = get_spc_ndx( 'CH3CCL3' )
     168         768 :     id_cfc12   = get_spc_ndx( 'CFC12' )
     169         768 :     id_ch3cl   = get_spc_ndx( 'CH3CL' )
     170             : 
     171         768 :     id_hcfc22  = get_spc_ndx( 'HCFC22' )
     172         768 :     id_hcfc141b= get_spc_ndx( 'HCFC141B' )
     173         768 :     id_hcfc142b= get_spc_ndx( 'HCFC142B' )
     174             : 
     175         768 :     id_cf2clbr = get_spc_ndx( 'CF2CLBR' )
     176         768 :     id_cf3br   = get_spc_ndx( 'CF3BR' )
     177         768 :     id_ch3br   = get_spc_ndx( 'CH3BR' )
     178         768 :     id_h1202   = get_spc_ndx( 'H1202' )
     179         768 :     id_h2402   = get_spc_ndx( 'H2402' )
     180         768 :     id_ch2br2  = get_spc_ndx( 'CH2BR2' )
     181         768 :     id_chbr3   = get_spc_ndx( 'CHBR3' )
     182             : 
     183         768 :     id_br      = get_spc_ndx( 'BR' )
     184         768 :     id_bro     = get_spc_ndx( 'BRO' )
     185         768 :     id_hbr     = get_spc_ndx( 'HBR' )
     186         768 :     id_hobr    = get_spc_ndx( 'HOBR' )
     187         768 :     id_ch4     = get_spc_ndx( 'CH4' )
     188         768 :     id_h2o     = get_spc_ndx( 'H2O' )
     189         768 :     id_h2      = get_spc_ndx( 'H2' )
     190         768 :     id_o       = get_spc_ndx( 'O' )
     191         768 :     id_o2      = get_spc_ndx( 'O2' )
     192         768 :     id_h       = get_spc_ndx( 'H' )
     193             : 
     194         768 :     id_pan     = get_spc_ndx( 'PAN' )
     195         768 :     id_onit    = get_spc_ndx( 'ONIT' )
     196         768 :     id_mpan    = get_spc_ndx( 'MPAN' )
     197         768 :     id_isopno3 = get_spc_ndx( 'ISOPNO3' )
     198         768 :     id_onitr   = get_spc_ndx( 'ONITR' )
     199         768 :     id_nh4no3  = get_spc_ndx( 'NH4NO3' )
     200             : 
     201         768 :     id_honitr    = get_spc_ndx( 'HONITR' )
     202         768 :     id_alknit    = get_spc_ndx( 'ALKNIT' )
     203         768 :     id_isopnita  = get_spc_ndx( 'ISOPNITA' )
     204         768 :     id_isopnitb  = get_spc_ndx( 'ISOPNITB' )
     205         768 :     id_isopnooh  = get_spc_ndx( 'ISOPNOOH' )
     206         768 :     id_nc4ch2oh  = get_spc_ndx( 'NC4CH2OH' )
     207         768 :     id_nc4cho    = get_spc_ndx( 'NC4CHO' )
     208         768 :     id_noa       = get_spc_ndx( 'NOA' )
     209         768 :     id_nterpooh  = get_spc_ndx( 'NTERPOOH' )
     210         768 :     id_pbznit    = get_spc_ndx( 'PBZNIT' )
     211         768 :     id_terpnit   = get_spc_ndx( 'TERPNIT' )
     212         768 :     id_ndep      = get_spc_ndx( 'NDEP' )
     213         768 :     id_nhdep     = get_spc_ndx( 'NHDEP' )
     214             : 
     215         768 :     id_so2     = get_spc_ndx( 'SO2' )
     216         768 :     id_so4     = get_spc_ndx( 'SO4' )
     217         768 :     id_h2so4   = get_spc_ndx( 'H2SO4' )
     218             : 
     219         768 :     id_nh3     = get_spc_ndx( 'NH3' )
     220         768 :     id_nh4     = get_spc_ndx( 'NH4' )
     221         768 :     id_nh4no3  = get_spc_ndx( 'NH4NO3' )
     222             : 
     223         768 :     id_isopn2b   = get_spc_ndx( 'ISOPN2B' )
     224         768 :     id_isopn3b   = get_spc_ndx( 'ISOPN3B' )
     225         768 :     id_isopn1d   = get_spc_ndx( 'ISOPN1D' )
     226         768 :     id_isopn4d   = get_spc_ndx( 'ISOPN4D' )
     227         768 :     id_isopnbno3 = get_spc_ndx('ISOPNBNO3' )
     228         768 :     id_isopfdn   = get_spc_ndx( 'ISOPFDN' )
     229         768 :     id_isopfdnc  = get_spc_ndx( 'ISOPFDNC')
     230         768 :     id_terpfdn   = get_spc_ndx( 'TERPFDN' )
     231         768 :     id_isopfnp   = get_spc_ndx( 'ISOPFNP' )
     232         768 :     id_isopnoohb = get_spc_ndx( 'ISOPNOOHB' )
     233         768 :     id_isopnoohd = get_spc_ndx( 'ISOPNOOHD' )
     234         768 :     id_inheb     = get_spc_ndx( 'INHEB' )
     235         768 :     id_inhed     = get_spc_ndx( 'INHED' )
     236         768 :     id_no3ch2cho = get_spc_ndx( 'NO3CH2CHO' )
     237         768 :     id_macrn     = get_spc_ndx( 'MACRN' )
     238         768 :     id_mvkn      = get_spc_ndx( 'MVKN' )
     239         768 :     id_isopfnc   = get_spc_ndx( 'ISOPFNC' )
     240         768 :     id_terpns    = get_spc_ndx( 'TERPNS' )
     241         768 :     id_terpnt    = get_spc_ndx( 'TERPNT' )
     242         768 :     id_terpnt1   = get_spc_ndx( 'TERPNT1' )
     243         768 :     id_terpns1   = get_spc_ndx( 'TERPNS1' )
     244         768 :     id_terpnpt   = get_spc_ndx( 'TERPNPT' )
     245         768 :     id_terpnps   = get_spc_ndx( 'TERPNPS' )
     246         768 :     id_terpnpt1  = get_spc_ndx( 'TERPNPT1' )
     247         768 :     id_terpnps1  = get_spc_ndx( 'TERPNPS1' )
     248         768 :     id_sqtn      = get_spc_ndx( 'SQTN' )
     249         768 :     id_terphfn   = get_spc_ndx( 'TERPHFN' )
     250         768 :     id_terpapan  = get_spc_ndx( 'TERPAPAN' )
     251         768 :     id_terpa2pan = get_spc_ndx( 'TERPA2PAN' )
     252         768 :     id_terpa3pan = get_spc_ndx( 'TERPA3PAN' )
     253             : 
     254         768 :     id_dst01   = get_spc_ndx( 'DST01' )
     255         768 :     id_dst02   = get_spc_ndx( 'DST02' )
     256         768 :     id_dst03   = get_spc_ndx( 'DST03' )
     257         768 :     id_dst04   = get_spc_ndx( 'DST04' )
     258         768 :     id_sslt01  = get_spc_ndx( 'SSLT01' )
     259         768 :     id_sslt02  = get_spc_ndx( 'SSLT02' )
     260         768 :     id_sslt03  = get_spc_ndx( 'SSLT03' )
     261         768 :     id_sslt04  = get_spc_ndx( 'SSLT04' )
     262         768 :     id_soa     = get_spc_ndx( 'SOA' )
     263         768 :     id_so4     = get_spc_ndx( 'SO4' )
     264         768 :     id_oc1     = get_spc_ndx( 'OC1' )
     265         768 :     id_oc2     = get_spc_ndx( 'OC2' )
     266         768 :     id_cb1     = get_spc_ndx( 'CB1' )
     267         768 :     id_cb2     = get_spc_ndx( 'CB2' )
     268             : 
     269         768 :     rid_jno   = get_rxt_ndx( 'jno' )
     270         768 :     rid_jno_i = get_rxt_ndx( 'jno_i' )
     271             : 
     272         768 :     id_soam = get_spc_ndx( 'SOAM' )
     273         768 :     id_soai = get_spc_ndx( 'SOAI' )
     274         768 :     id_soat = get_spc_ndx( 'SOAT' )
     275         768 :     id_soab = get_spc_ndx( 'SOAB' )
     276         768 :     id_soax = get_spc_ndx( 'SOAX' )
     277             : 
     278             : 
     279             : !... NOY species
     280        3072 :     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       43776 :                      id_terpapan, id_terpa2pan, id_terpa3pan /)
     292             : !... HOX species
     293        3840 :     hox_species = (/ id_h, id_oh, id_ho2, id_h2o2 /)
     294             : 
     295             : !... CLOY species
     296        5376 :     clox_species = (/ id_cl, id_clo, id_hocl, id_cl2, id_cl2o2, id_oclo /)
     297        7680 :     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       16896 :                       id_hcfc22, id_hcfc141b, id_hcfc142b, id_cf2clbr /)
     301             : 
     302             : !... FOY species
     303        3840 :     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       13056 :                      id_hcfc22, id_hcfc141b, id_hcfc142b, id_cf2clbr, id_cf3br, id_h1202, id_h2402 /)
     306             : 
     307             : !... BROY species
     308        3840 :     brox_species = (/ id_br, id_bro, id_brcl, id_hobr /)
     309        5376 :     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       10752 :                       id_h2402, id_ch2br2, id_chbr3 /)
     312             : 
     313        3072 :     sox_species = (/ id_so2, id_so4, id_h2so4 /)
     314        2304 :     nhx_species = (/ id_nh3, id_nh4 /)
     315       16128 :     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       16128 :                                 id_soam,id_soai,id_soat,id_soab,id_soax /)
     320             : 
     321      107520 :     aer_species(:) = -1
     322         768 :     n = 1
     323      107520 :     do m = 1,gas_pcnst
     324     2241792 :        k=0
     325     2241792 :        if ( any(bulkaero_species(:)==m) ) k=1
     326      106752 :        if ( k==0 ) k = index(trim(solsym(m)), '_a')
     327      106752 :        if ( k==0 ) k = index(trim(solsym(m)), '_c')
     328      107520 :        if ( k>0 ) then ! must be aerosol species
     329       16128 :           aer_species(n) = m
     330       16128 :           n = n+1
     331             :        endif
     332             :     enddo
     333             : 
     334        3072 :     toth_species = (/ id_ch4, id_h2o, id_h2 /)
     335             : 
     336        3072 :     chm_prod_ndep_flx = any(noy_species>0) .or. any(nhx_species>0)
     337             : 
     338        1536 :     call addfld( 'NOX',     (/ 'lev' /), 'A', 'mol/mol', 'nox (N+NO+NO2)' )
     339             :     call addfld( 'NOY',     (/ 'lev' /), 'A', 'mol/mol', &
     340        1536 :                  'noy = total nitrogen (N+NO+NO2+NO3+2N2O5+HNO3+HO2NO2+ORGNOY+NH4NO3)' )
     341         768 :     call addfld( 'NOY_SRF', horiz_only,  'A', 'mol/mol', 'surface noy volume mixing ratio' )
     342        1536 :     call addfld( 'HOX',     (/ 'lev' /), 'A', 'mol/mol', 'HOx (H+OH+HO2+2H2O2)' )
     343             : 
     344        1536 :     call addfld( 'BROX',    (/ 'lev' /), 'A', 'mol/mol', 'brox (Br+BrO+BRCl+HOBr)' )
     345        1536 :     call addfld( 'BROY',    (/ 'lev' /), 'A', 'mol/mol', 'total inorganic bromine (Br+BrO+HOBr+BrONO2+HBr+BrCl)' )
     346        1536 :     call addfld( 'TBRY',    (/ 'lev' /), 'A', 'mol/mol', 'total Br (ORG+INORG) volume mixing ratio' )
     347             : 
     348        1536 :     call addfld( 'CLOX',    (/ 'lev' /), 'A', 'mol/mol', 'clox (Cl+CLO+HOCl+2Cl2+2Cl2O2+OClO)' )
     349        1536 :     call addfld( 'CLOY',    (/ 'lev' /), 'A', 'mol/mol', 'total inorganic chlorine (Cl+ClO+2Cl2+2Cl2O2+OClO+HOCl+ClONO2+HCl+BrCl)' )
     350        1536 :     call addfld( 'TCLY',    (/ 'lev' /), 'A', 'mol/mol', 'total Cl (ORG+INORG) volume mixing ratio' )
     351             : 
     352        1536 :     call addfld( 'FOY',     (/ 'lev' /), 'A', 'mol/mol', 'total inorganic fluorine (F+HF+COFCL+2COF2)' )
     353        1536 :     call addfld( 'TFY',     (/ 'lev' /), 'A', 'mol/mol', 'total F (ORG+INORG) volume mixing ratio' )
     354             : 
     355        1536 :     call addfld( 'TOTH',    (/ 'lev' /), 'A', 'mol/mol', 'total H2 volume mixing ratio' )
     356             : 
     357        1536 :     call addfld( 'NOY_mmr', (/ 'lev' /), 'A', 'kg/kg', 'NOy mass mixing ratio' )
     358        1536 :     call addfld( 'SOX_mmr', (/ 'lev' /), 'A', 'kg/kg', 'SOx mass mixing ratio' )
     359        1536 :     call addfld( 'NHX_mmr', (/ 'lev' /), 'A', 'kg/kg', 'NHx mass mixing ratio' )
     360             : 
     361       20736 :     do j = 1,NJEUV
     362       19968 :        write( jchar, '(I2)' ) j
     363       19968 :        jname = 'jeuv_'//trim(adjustl(jchar))
     364       20736 :        rid_jeuv(j) = get_rxt_ndx( trim(jname) )
     365             :     enddo
     366             : 
     367       20736 :     has_jeuvs = all( rid_jeuv(:) > 0 )
     368         768 :     has_jno_i = rid_jno_i>0
     369         768 :     has_jno   = rid_jno>0
     370             : 
     371         768 :     if ( has_jeuvs ) then
     372        1536 :        call addfld( 'PION_EUV', (/ 'lev' /), 'I', '/cm^3/s', 'total euv ionization rate' )
     373        1536 :        call addfld( 'PEUV1',    (/ 'lev' /), 'I', '/cm^3/s', '(j1+j2+j3)*o' )
     374        1536 :        call addfld( 'PEUV1e',   (/ 'lev' /), 'I', '/cm^3/s', '(j14+j15+j16)*o' )
     375        1536 :        call addfld( 'PEUV2',    (/ 'lev' /), 'I', '/cm^3/s', 'j4*n' )
     376        1536 :        call addfld( 'PEUV3',    (/ 'lev' /), 'I', '/cm^3/s', '(j5+j7+j8+j9)*o2' )
     377        1536 :        call addfld( 'PEUV3e',   (/ 'lev' /), 'I', '/cm^3/s', '(j17+j19+j20+j21)*o2' )
     378        1536 :        call addfld( 'PEUV4',    (/ 'lev' /), 'I', '/cm^3/s', '(j10+j11)*n2' )
     379        1536 :        call addfld( 'PEUV4e',   (/ 'lev' /), 'I', '/cm^3/s', '(j22+j23)*n2' )
     380        1536 :        call addfld( 'PEUVN2D',  (/ 'lev' /), 'I', '/cm^3/s', '(j11+j13)*n2' )
     381        1536 :        call addfld( 'PEUVN2De', (/ 'lev' /), 'I', '/cm^3/s', '(j23+j25)*n2' )
     382             :     endif
     383         768 :     if ( has_jno ) then
     384        1536 :        call addfld( 'PJNO', (/ 'lev' /), 'I', '/cm^3/s', 'jno*no' )
     385             :     endif
     386         768 :     if ( has_jno_i ) then
     387        1536 :        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         768 :          flag_xyfill=.True. )
     394             :     call addfld( 'DO3CHM_LMS', horiz_only, 'A', 'kg/s', 'integrated net tendency from chem in lowermost stratosphere', &
     395         768 :          flag_xyfill=.True. )
     396             : !
     397      107520 :     do m = 1,gas_pcnst
     398             : 
     399      106752 :        spc_name = trim(solsym(m))
     400             : 
     401      106752 :        call cnst_get_ind(spc_name, n, abort=.false. )
     402      106752 :        if ( n > 0 ) then
     403       68352 :           attr = cnst_longname(n)
     404       38400 :        elseif ( trim(spc_name) == 'H2O' ) then
     405         768 :           attr = 'water vapor'
     406             :        else
     407       37632 :           attr = spc_name
     408             :        endif
     409             : 
     410      106752 :        dtchem_name(m) = 'D'//trim(spc_name)//'CHM'
     411      213504 :        call addfld( dtchem_name(m), (/ 'lev' /), 'A', 'kg/s',    'net tendency from chem' )
     412             : 
     413      106752 :        depvel_name(m) = 'DV_'//trim(spc_name)
     414      106752 :        depflx_name(m) = 'DF_'//trim(spc_name)
     415      106752 :        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       10752 :           if (history_chemistry) then
     419       10752 :              call add_default( depflx_name(m), 1, ' ' )
     420             :           endif
     421             :        endif
     422             : 
     423      106752 :        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      106752 :        if (spc_name(1:3) == 'num') then
     432        3840 :           unit_basename = ' 1'
     433             :        else
     434      102912 :           unit_basename = 'kg'
     435             :        endif
     436             : 
     437    12864768 :        if ( any( aer_species == m ) ) then
     438       32256 :           call addfld( spc_name,   (/ 'lev' /), 'A', unit_basename//'/kg ', trim(attr)//' concentration')
     439       16128 :           call addfld( trim(spc_name)//'_SRF', horiz_only, 'A', unit_basename//'/kg', trim(attr)//" in bottom layer")
     440             :        else
     441      181248 :           call addfld( spc_name, (/ 'lev' /), 'A', 'mol/mol', trim(attr)//' concentration')
     442       90624 :           call addfld( trim(spc_name)//'_SRF', horiz_only, 'A', 'mol/mol', trim(attr)//" in bottom layer")
     443             :        endif
     444             : 
     445      106752 :        if ((m /= id_cly) .and. (m /= id_bry)) then
     446      105216 :           if (history_aerosol.or.history_chemistry) then
     447      105216 :              call add_default( spc_name, 1, ' ' )
     448             :           endif
     449      105216 :           if (history_chemspecies_srf) then
     450      105216 :              call add_default( trim(spc_name)//'_SRF', 1, ' ' )
     451             :           endif
     452             :        endif
     453             : 
     454      106752 :        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      106752 :        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      107520 :        if (history_dust .and. (index(spc_name,'dst_') > 0))  call add_default( spc_name, 1, ' ')
     486             : 
     487             :     enddo
     488             : 
     489        1536 :     call addfld( 'MASS', (/ 'lev' /), 'A', 'kg', 'mass of grid box' )
     490         768 :     call addfld( 'AREA', horiz_only,  'A', 'm2', 'area of grid box' )
     491             : 
     492         768 :     call addfld( 'dry_deposition_NOy_as_N', horiz_only, 'I', 'kg/m2/s', 'NOy dry deposition flux ' )
     493         768 :     call addfld( 'DF_SOX', horiz_only, 'I', 'kg/m2/s', 'SOx dry deposition flux ' )
     494         768 :     call addfld( 'dry_deposition_NHx_as_N', horiz_only, 'I', 'kg/m2/s', 'NHx dry deposition flux ' )
     495         768 :     if (gas_wetdep_method=='NEU') then
     496         768 :        call addfld( 'wet_deposition_NOy_as_N', horiz_only, 'A', 'kg/m2/s', 'NOy wet deposition' )
     497         768 :        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         768 :     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         768 :     call species_sums_init()
     511             : 
     512         768 :   end subroutine chm_diags_inti
     513             : 
     514       43776 :   subroutine chm_diags( lchnk, ncol, vmr, mmr, rxt_rates, invariants, depvel, depflx, mmr_tend, pdel, pmid, ltrop, &
     515       21888 :                         wetdepflx, nhx_nitrogen_flx, noy_nitrogen_flx )
     516             :     !--------------------------------------------------------------------
     517             :     !   ... utility routine to output chemistry diagnostic variables
     518             :     !--------------------------------------------------------------------
     519             : 
     520         768 :     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       43776 :     real(r8)    :: wrk(ncol,pver)
     552             :     !      real(r8)    :: tmp(ncol,pver)
     553             :     !      real(r8)    :: m(ncol,pver)
     554       43776 :     real(r8)    :: un2(ncol)
     555             : 
     556       43776 :     real(r8), dimension(ncol,pver) :: vmr_nox, vmr_noy, vmr_clox, vmr_cloy, vmr_tcly, vmr_brox, vmr_broy, vmr_toth
     557       43776 :     real(r8), dimension(ncol,pver) :: vmr_tbry, vmr_foy, vmr_tfy
     558       43776 :     real(r8), dimension(ncol,pver) :: mmr_noy, mmr_sox, mmr_nhx, net_chem
     559       43776 :     real(r8), dimension(ncol)      :: df_noy, df_sox, df_nhx, do3chm_trp, do3chm_lms
     560       43776 :     real(r8), dimension(ncol)      :: wd_noy, wd_nhx
     561       43776 :     real(r8), dimension(ncol,pver) :: vmr_hox
     562             : 
     563       21888 :     real(r8) :: area(ncol), mass(ncol,pver)
     564             :     real(r8) :: wgt
     565             : 
     566             :     !--------------------------------------------------------------------
     567             :     !   ... "diagnostic" groups
     568             :     !--------------------------------------------------------------------
     569    37012608 :     vmr_nox(:ncol,:) = 0._r8
     570    37012608 :     vmr_noy(:ncol,:) = 0._r8
     571    37012608 :     vmr_hox(:ncol,:) = 0._r8
     572    37012608 :     vmr_clox(:ncol,:) = 0._r8
     573    37012608 :     vmr_cloy(:ncol,:) = 0._r8
     574    37012608 :     vmr_tcly(:ncol,:) = 0._r8
     575    37012608 :     vmr_brox(:ncol,:) = 0._r8
     576    37012608 :     vmr_broy(:ncol,:) = 0._r8
     577    37012608 :     vmr_tbry(:ncol,:) = 0._r8
     578    37012608 :     vmr_foy(:ncol,:)  = 0._r8
     579    37012608 :     vmr_tfy(:ncol,:)  = 0._r8
     580    37012608 :     vmr_toth(:ncol,:) = 0._r8
     581    37012608 :     mmr_noy(:ncol,:) = 0._r8
     582    37012608 :     mmr_sox(:ncol,:) = 0._r8
     583    37012608 :     mmr_nhx(:ncol,:) = 0._r8
     584      284544 :     df_noy(:ncol) = 0._r8
     585      284544 :     df_sox(:ncol) = 0._r8
     586      284544 :     df_nhx(:ncol) = 0._r8
     587             : 
     588      284544 :     wd_noy(:ncol) = 0._r8
     589      284544 :     wd_nhx(:ncol) = 0._r8
     590             : 
     591       21888 :     call get_area_all_p(lchnk, ncol, area)
     592      284544 :     area = area * rearth**2
     593             : 
     594     2867328 :     do k = 1,pver
     595    37012608 :        mass(:ncol,k) = pdel(:ncol,k) * area(:ncol) * rgrav
     596             :     enddo
     597             : 
     598       21888 :     call outfld( 'AREA', area(:ncol),   ncol, lchnk )
     599       21888 :     call outfld( 'MASS', mass(:ncol,:), ncol, lchnk )
     600             : 
     601     3064320 :     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     3042432 :             .or. m == id_cof2 ) then
     606             :           wgt = 2._r8
     607     2932992 :        elseif ( m == id_cfc113 .or. m == id_cf3br ) then
     608             :           wgt = 3._r8
     609     2889216 :        elseif ( m == id_cfc114 .or. m == id_h2402 ) then
     610             :           wgt = 4._r8
     611     2845440 :        elseif ( m == id_cfc115 ) then
     612             :           wgt = 5._r8
     613             :        else
     614     2823552 :           wgt = 1._r8
     615             :        endif
     616    14993280 :        if ( any( foy_species == m ) ) then
     617   148050432 :           vmr_foy(:ncol,:) = vmr_foy(:ncol,:) +  wgt * vmr(:ncol,:,m)
     618             :        endif
     619    48788352 :        if ( any( tfy_species == m ) ) then
     620   555189120 :           vmr_tfy(:ncol,:) = vmr_tfy(:ncol,:) +  wgt * vmr(:ncol,:,m)
     621             :        endif
     622             : 
     623             : !... counting chlorine and bromines, etc... (and total H2 species)
     624     3042432 :        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     2911104 :        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     2823552 :        elseif (m == id_isopfdn .or. m == id_isopfdnc .or. m == id_terpfdn ) then
     629             :           wgt = 2._r8
     630     2823552 :        elseif ( m == id_cfc11 .or. m == id_cfc113 .or. m == id_ch3ccl3 .or. m == id_chbr3 ) then
     631             :           wgt = 3._r8
     632     2736000 :        elseif ( m == id_ccl4 ) then
     633             :           wgt = 4._r8
     634             :        else
     635     2714112 :           wgt = 1._r8
     636             :        endif
     637             : !...NOY
     638    12038400 :        if ( any( nox_species == m ) ) then
     639   111037824 :           vmr_nox(:ncol,:) = vmr_nox(:ncol,:) +  wgt * vmr(:ncol,:,m)
     640             :        endif
     641   163175040 :        if ( any( noy_species == m ) ) then
     642   333113472 :           vmr_noy(:ncol,:) = vmr_noy(:ncol,:) +  wgt * vmr(:ncol,:,m)
     643             :        endif
     644             : !...NOY, SOX, NHX
     645   163175040 :        if ( any( noy_species == m ) ) then
     646   333113472 :           mmr_noy(:ncol,:) = mmr_noy(:ncol,:) +  wgt * mmr(:ncol,:,m)
     647             :        endif
     648    12082176 :        if ( any( sox_species == m ) ) then
     649    74025216 :           mmr_sox(:ncol,:) = mmr_sox(:ncol,:) +  wgt * mmr(:ncol,:,m)
     650             :        endif
     651     9127296 :        if ( any( nhx_species == m ) ) then
     652           0 :           mmr_nhx(:ncol,:) = mmr_nhx(:ncol,:) +  wgt * mmr(:ncol,:,m)
     653             :        endif
     654             : !...CLOY
     655    20837376 :        if ( any( clox_species == m ) ) then
     656   222075648 :           vmr_clox(:ncol,:) = vmr_clox(:ncol,:) +  wgt * vmr(:ncol,:,m)
     657             :        endif
     658    29439360 :        if ( any( cloy_species == m ) ) then
     659   333113472 :           vmr_cloy(:ncol,:) = vmr_cloy(:ncol,:) +  wgt * vmr(:ncol,:,m)
     660             :        endif
     661    61877376 :        if ( any( tcly_species == m ) ) then
     662   777264768 :           vmr_tcly(:ncol,:) = vmr_tcly(:ncol,:) +  wgt * vmr(:ncol,:,m)
     663             :        endif
     664             : !...BROY
     665    14993280 :        if ( any( brox_species == m ) ) then
     666   148050432 :           vmr_brox(:ncol,:) = vmr_brox(:ncol,:) +  wgt * vmr(:ncol,:,m)
     667             :        endif
     668    20837376 :        if ( any( broy_species == m ) ) then
     669   222075648 :           vmr_broy(:ncol,:) = vmr_broy(:ncol,:) +  wgt * vmr(:ncol,:,m)
     670             :        endif
     671    40689792 :        if ( any( tbry_species == m ) ) then
     672   444151296 :           vmr_tbry(:ncol,:) = vmr_tbry(:ncol,:) +  wgt * vmr(:ncol,:,m)
     673             :        endif
     674             : !...HOY
     675    12038400 :        if ( any ( toth_species == m ) ) then
     676   111037824 :           vmr_toth(:ncol,:) = vmr_toth(:ncol,:) +  wgt * vmr(:ncol,:,m)
     677             :        endif
     678             : !...HOx
     679    14993280 :        if ( any( hox_species == m ) ) then
     680   148050432 :           vmr_hox(:ncol,:) = vmr_hox(:ncol,:) +  wgt * vmr(:ncol,:,m)
     681             :        endif
     682             : 
     683   366645888 :        if ( any( aer_species == m ) ) then
     684      459648 :           call outfld( solsym(m), mmr(:ncol,:,m), ncol ,lchnk )
     685      459648 :           call outfld( trim(solsym(m))//'_SRF', mmr(:ncol,pver,m), ncol ,lchnk )
     686             :        else
     687     2582784 :           call outfld( solsym(m), vmr(:ncol,:,m), ncol ,lchnk )
     688     2582784 :           call outfld( trim(solsym(m))//'_SRF', vmr(:ncol,pver,m), ncol ,lchnk )
     689             :        endif
     690             : 
     691     3042432 :        if (has_drydep(solsym(m))) then
     692      306432 :           call outfld( depvel_name(m), depvel(:ncol,m), ncol ,lchnk )
     693      306432 :           call outfld( depflx_name(m), depflx(:ncol,m), ncol ,lchnk )
     694             :        endif
     695             : 
     696   163175040 :        if ( any( noy_species == m ) ) then
     697     2560896 :           df_noy(:ncol) = df_noy(:ncol) +  wgt * depflx(:ncol,m)*N_molwgt/adv_mass(m)
     698             :        endif
     699    12082176 :        if ( any( sox_species == m ) ) then
     700      569088 :           df_sox(:ncol) = df_sox(:ncol) +  wgt * depflx(:ncol,m)*S_molwgt/adv_mass(m)
     701             :        endif
     702     9127296 :        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   163175040 :        if ( any( noy_species == m ) ) then
     707     2560896 :           wd_noy(:ncol) = wd_noy(:ncol) +  wgt * wetdepflx(:ncol,m)*N_molwgt/adv_mass(m)
     708             :        endif
     709     9127296 :        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     3042432 :        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     3042432 :        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   398558592 :        do k=1,pver
     723  5144752512 :           do i=1,ncol
     724  5141710080 :              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     3064320 :        if ( trim(dtchem_name(m)) == 'DO3CHM' ) then
     732      284544 :           do3chm_trp(:) = 0._r8
     733      284544 :           do i=1,ncol
     734     5084429 :              do k=ltrop(i),pver
     735     5062541 :                 do3chm_trp(i) = do3chm_trp(i) + net_chem(i,k)
     736             :              end do
     737             :           end do
     738      284544 :           where ( do3chm_trp == 0._r8 )
     739             :              do3chm_trp = fillvalue
     740             :           end where
     741       21888 :           call outfld('DO3CHM_TRP',do3chm_trp(:ncol), ncol, lchnk )
     742      284544 :           do3chm_lms(:) = 0._r8
     743      284544 :           do i=1,ncol
     744    34429824 :              do k=1,pver
     745    34407936 :                 if ( pmid(i,k) > 100.e2_r8 .and. k < ltrop(i) ) then
     746      982647 :                    do3chm_lms(i) = do3chm_lms(i) + net_chem(i,k)
     747             :                 end if
     748             :              end do
     749             :           end do
     750      284544 :           where ( do3chm_lms == 0._r8 )
     751             :              do3chm_lms = fillvalue
     752             :           end where
     753       21888 :           call outfld('DO3CHM_LMS',do3chm_lms(:ncol), ncol, lchnk )
     754             :        end if
     755             : !
     756             :     enddo
     757             : 
     758             : 
     759       21888 :     call outfld( 'NOX',  vmr_nox  (:ncol,:), ncol, lchnk )
     760       21888 :     call outfld( 'NOY',  vmr_noy  (:ncol,:), ncol, lchnk )
     761       21888 :     call outfld( 'HOX',  vmr_hox  (:ncol,:), ncol, lchnk )
     762       21888 :     call outfld( 'NOY_SRF',  vmr_noy(:ncol,pver),  ncol, lchnk )
     763       21888 :     call outfld( 'CLOX', vmr_clox (:ncol,:), ncol, lchnk )
     764       21888 :     call outfld( 'CLOY', vmr_cloy (:ncol,:), ncol, lchnk )
     765       21888 :     call outfld( 'BROX', vmr_brox (:ncol,:), ncol, lchnk )
     766       21888 :     call outfld( 'BROY', vmr_broy (:ncol,:), ncol, lchnk )
     767       21888 :     call outfld( 'TCLY', vmr_tcly (:ncol,:), ncol, lchnk )
     768       21888 :     call outfld( 'TBRY', vmr_tbry (:ncol,:), ncol, lchnk )
     769       21888 :     call outfld( 'FOY',  vmr_foy  (:ncol,:), ncol, lchnk )
     770       21888 :     call outfld( 'TFY',  vmr_tfy  (:ncol,:), ncol, lchnk )
     771       21888 :     call outfld( 'TOTH', vmr_toth (:ncol,:), ncol, lchnk )
     772             : 
     773       21888 :     call outfld( 'NOY_mmr', mmr_noy(:ncol,:), ncol ,lchnk )
     774       21888 :     call outfld( 'SOX_mmr', mmr_sox(:ncol,:), ncol ,lchnk )
     775       21888 :     call outfld( 'NHX_mmr', mmr_nhx(:ncol,:), ncol ,lchnk )
     776       21888 :     call outfld( 'dry_deposition_NOy_as_N', df_noy(:ncol), ncol ,lchnk )
     777       21888 :     call outfld( 'DF_SOX', df_sox(:ncol), ncol ,lchnk )
     778       21888 :     call outfld( 'dry_deposition_NHx_as_N', df_nhx(:ncol), ncol ,lchnk )
     779       21888 :     if (gas_wetdep_method=='NEU') then
     780      284544 :       wd_noy(:ncol) = -wd_noy(:ncol) ! downward is possitive
     781      284544 :       wd_nhx(:ncol) = -wd_nhx(:ncol)
     782       21888 :       call outfld( 'wet_deposition_NOy_as_N', wd_noy(:ncol), ncol, lchnk )
     783       21888 :       call outfld( 'wet_deposition_NHx_as_N', wd_nhx(:ncol), ncol, lchnk )
     784             :     end if
     785             : 
     786      284544 :     nhx_nitrogen_flx = df_nhx + wd_nhx
     787      284544 :     noy_nitrogen_flx = df_noy + wd_noy
     788             : 
     789             :     !--------------------------------------------------------------------
     790             :     !   ... euv ion production
     791             :     !--------------------------------------------------------------------
     792             : 
     793       21888 :     jeuvs: if ( has_jeuvs ) then
     794     2867328 :        do k = 1,pver
     795    36990720 :           un2(:)   = 1._r8 - (vmr(:,k,id_o) + vmr(:,k,id_o2) + vmr(:,k,id_h))
     796     5690880 :           wrk(:,k) = vmr(:,k,id_o)*(rxt_rates(:,k,rid_jeuv(1)) + rxt_rates(:,k,rid_jeuv(2)) &
     797     5690880 :                + rxt_rates(:,k,rid_jeuv(3)) + rxt_rates(:,k,rid_jeuv(14)) &
     798     5690880 :                + rxt_rates(:,k,rid_jeuv(15)) + rxt_rates(:,k,rid_jeuv(16))) &
     799     5690880 :                + vmr(:,k,id_n)*rxt_rates(:,k,rid_jeuv(4)) &
     800     5690880 :                + vmr(:,k,id_o2)*(rxt_rates(:,k,rid_jeuv(5)) + rxt_rates(:,k,rid_jeuv(7)) &
     801     5690880 :                + rxt_rates(:,k,rid_jeuv(8)) + rxt_rates(:,k,rid_jeuv(9)) &
     802     5690880 :                + rxt_rates(:,k,rid_jeuv(17)) + rxt_rates(:,k,rid_jeuv(19)) &
     803     5690880 :                + rxt_rates(:,k,rid_jeuv(20)) + rxt_rates(:,k,rid_jeuv(21))) &
     804     5690880 :                + un2(:)*(rxt_rates(:,k,rid_jeuv(6)) + rxt_rates(:,k,rid_jeuv(10)) &
     805     5690880 :                + rxt_rates(:,k,rid_jeuv(11)) + rxt_rates(:,k,rid_jeuv(18)) &
     806    93899520 :                + rxt_rates(:,k,rid_jeuv(22)) + rxt_rates(:,k,rid_jeuv(23)))
     807    37012608 :           wrk(:,k) = wrk(:,k) * invariants(:,k,indexm)
     808             :        end do
     809       21888 :        call outfld( 'PION_EUV', wrk, ncol, lchnk )
     810             : 
     811     2867328 :        do k = 1,pver
     812    11381760 :           wrk(:,k) = vmr(:,k,id_o)*(rxt_rates(:,k,rid_jeuv(1)) + rxt_rates(:,k,rid_jeuv(2)) &
     813    48372480 :                + rxt_rates(:,k,rid_jeuv(3)))
     814    37012608 :           wrk(:,k) = wrk(:,k) * invariants(:,k,indexm)
     815             :        end do
     816       21888 :        call outfld( 'PEUV1', wrk, ncol, lchnk )
     817     2867328 :        do k = 1,pver
     818    11381760 :           wrk(:,k) = vmr(:,k,id_o)*(rxt_rates(:,k,rid_jeuv(14)) + rxt_rates(:,k,rid_jeuv(15)) &
     819    48372480 :                + rxt_rates(:,k,rid_jeuv(16)))
     820    37012608 :           wrk(:,k) = wrk(:,k) * invariants(:,k,indexm)
     821             :        end do
     822       21888 :        call outfld( 'PEUV1e', wrk, ncol, lchnk )
     823     2867328 :        do k = 1,pver
     824    36990720 :           wrk(:,k) = vmr(:,k,id_n)*rxt_rates(:,k,rid_jeuv(4))
     825    37012608 :           wrk(:,k) = wrk(:,k) * invariants(:,k,indexm)
     826             :        end do
     827       21888 :        call outfld( 'PEUV2', wrk, ncol, lchnk )
     828     2867328 :        do k = 1,pver
     829    11381760 :           wrk(:,k) = vmr(:,k,id_o2)*(rxt_rates(:,k,rid_jeuv(5)) + rxt_rates(:,k,rid_jeuv(7)) &
     830    48372480 :                + rxt_rates(:,k,rid_jeuv(8)) + rxt_rates(:,k,rid_jeuv(9)))
     831    37012608 :           wrk(:,k) = wrk(:,k) * invariants(:,k,indexm)
     832             :        end do
     833       21888 :        call outfld( 'PEUV3', wrk, ncol, lchnk )
     834     2867328 :        do k = 1,pver
     835    11381760 :           wrk(:,k) = vmr(:,k,id_o2)*(rxt_rates(:,k,rid_jeuv(17)) + rxt_rates(:,k,rid_jeuv(19)) &
     836    48372480 :                + rxt_rates(:,k,rid_jeuv(20)) + rxt_rates(:,k,rid_jeuv(21)))
     837    37012608 :           wrk(:,k) = wrk(:,k) * invariants(:,k,indexm)
     838             :        end do
     839       21888 :        call outfld( 'PEUV3e', wrk, ncol, lchnk )
     840     2867328 :        do k = 1,pver
     841    36990720 :           un2(:)   = 1._r8 - (vmr(:,k,id_o) + vmr(:,k,id_o2) + vmr(:,k,id_h))
     842    36990720 :           wrk(:,k) = un2(:)*(rxt_rates(:,k,rid_jeuv(6)) + rxt_rates(:,k,rid_jeuv(10)) + rxt_rates(:,k,rid_jeuv(11)))
     843    37012608 :           wrk(:,k) = wrk(:,k) * invariants(:,k,indexm)
     844             :        end do
     845       21888 :        call outfld( 'PEUV4', wrk, ncol, lchnk )
     846     2867328 :        do k = 1,pver
     847    36990720 :           un2(:)   = 1._r8 - (vmr(:,k,id_o) + vmr(:,k,id_o2) + vmr(:,k,id_h))
     848    36990720 :           wrk(:,k) = un2(:)*(rxt_rates(:,k,rid_jeuv(18)) + rxt_rates(:,k,rid_jeuv(22)) + rxt_rates(:,k,rid_jeuv(23)))
     849    37012608 :           wrk(:,k) = wrk(:,k) * invariants(:,k,indexm)
     850             :        end do
     851       21888 :        call outfld( 'PEUV4e', wrk, ncol, lchnk )
     852     2867328 :        do k = 1,pver
     853    36990720 :           un2(:)   = 1._r8 - (vmr(:,k,id_o) + vmr(:,k,id_o2) + vmr(:,k,id_h))
     854    36990720 :           wrk(:,k) = un2(:)*(rxt_rates(:,k,rid_jeuv(11)) + rxt_rates(:,k,rid_jeuv(13)))
     855    37012608 :           wrk(:,k) = wrk(:,k) * invariants(:,k,indexm)
     856             :        end do
     857       21888 :        call outfld( 'PEUVN2D', wrk, ncol, lchnk )
     858     2867328 :        do k = 1,pver
     859    36990720 :           un2(:)   = 1._r8 - (vmr(:,k,id_o) + vmr(:,k,id_o2) + vmr(:,k,id_h))
     860    36990720 :           wrk(:,k) = un2(:)*(rxt_rates(:,k,rid_jeuv(23)) + rxt_rates(:,k,rid_jeuv(25)))
     861    37012608 :           wrk(:,k) = wrk(:,k) * invariants(:,k,indexm)
     862             :        end do
     863       21888 :        call outfld( 'PEUVN2De', wrk, ncol, lchnk )
     864             :     endif jeuvs
     865             : 
     866       21888 :     if ( has_jno_i ) then
     867     2867328 :        do k = 1,pver
     868    36990720 :           wrk(:,k) = vmr(:,k,id_no)*rxt_rates(:,k,rid_jno_i)
     869    37012608 :           wrk(:,k) = wrk(:,k) * invariants(:,k,indexm)
     870             :        end do
     871       21888 :        call outfld( 'PJNO_I', wrk, ncol, lchnk )
     872             :     endif
     873       21888 :     if ( has_jno ) then
     874     2867328 :        do k = 1,pver
     875    36990720 :           wrk(:,k) = vmr(:,k,id_no)*rxt_rates(:,k,rid_jno)
     876    37012608 :           wrk(:,k) = wrk(:,k) * invariants(:,k,indexm)
     877             :        end do
     878       21888 :        call outfld( 'PJNO', wrk, ncol, lchnk )
     879             :     endif
     880             : 
     881       21888 :     call species_sums_output(vmr, mmr, ncol, lchnk)
     882             : 
     883       21888 :   end subroutine chm_diags
     884             : 
     885       21888 :   subroutine het_diags( het_rates, mmr, pdel, lchnk, ncol )
     886             : 
     887       21888 :     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       43776 :     real(r8), dimension(ncol) :: noy_wk, sox_wk, nhx_wk, wrk_wd
     897             :     integer :: m, k
     898       21888 :     real(r8) :: wght(ncol)
     899             :     !
     900             :     ! output integrated wet deposition field
     901             :     !
     902      284544 :     noy_wk(:) = 0._r8
     903      284544 :     sox_wk(:) = 0._r8
     904      284544 :     nhx_wk(:) = 0._r8
     905             : 
     906       21888 :     call get_wght_all_p(lchnk, ncol, wght)
     907             : 
     908     3064320 :     do m = 1,gas_pcnst
     909             :        !
     910             :        ! compute vertical integral
     911             :        !
     912    39551616 :        wrk_wd(:ncol) = 0._r8
     913   398558592 :        do k = 1,pver
     914  5144752512 :           wrk_wd(:ncol) = wrk_wd(:ncol) + het_rates(:ncol,k,m) * mmr(:ncol,k,m) * pdel(:ncol,k)
     915             :        end do
     916             :        !
     917    39551616 :        wrk_wd(:ncol) = wrk_wd(:ncol) * rgrav * wght(:ncol) * rearth**2
     918             :        !
     919     3064320 :        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       21888 :     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       21888 :   end subroutine het_diags
     944             : 
     945             : end module mo_chm_diags

Generated by: LCOV version 1.14