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

Generated by: LCOV version 1.14