    subroutine chem_driver ( grid , config_flags &
,moist,moist_bxs,moist_bxe,moist_bys,moist_bye,moist_btxs,moist_btxe,moist_btys,moist_btye,dfi_moist,dfi_moist_bxs,dfi_moist_bxe, &
dfi_moist_bys,dfi_moist_bye,dfi_moist_btxs,dfi_moist_btxe,dfi_moist_btys,dfi_moist_btye,scalar,scalar_bxs,scalar_bxe,scalar_bys, &
scalar_bye,scalar_btxs,scalar_btxe,scalar_btys,scalar_btye,dfi_scalar,dfi_scalar_bxs,dfi_scalar_bxe,dfi_scalar_bys, &
dfi_scalar_bye,dfi_scalar_btxs,dfi_scalar_btxe,dfi_scalar_btys,dfi_scalar_btye,aerod,ozmixm,aerosolc_1,aerosolc_2,fdda3d,fdda2d, &
advh_t,advz_t,emis_ant,eghg_bio,emis_dust,emis_seas,emis_vol,ebu,ebu_in,emis_aircraft,ext_coef,bscat_coef,asym_par,conv_ct, &
chem_ct,vmix_ct,advh_ct,advz_ct,dvel,vprm_in,wet_in,chem,chem_bxs,chem_bxe,chem_bys,chem_bye,chem_btxs,chem_btxe,chem_btys, &
chem_btye,tracer,tracer_bxs,tracer_bxe,tracer_bys,tracer_bye,tracer_btxs,tracer_btxe,tracer_btys,tracer_btye,nba_mij,nba_rij &
                 )
  USE module_domain , only : domain
  USE module_configure
  USE module_driver_constants
  USE module_machine
  USE module_tiles
  USE module_dm
  USE module_model_constants
  USE module_state_description
  USE module_data_radm2
  USE module_data_sorgam
  USE module_radm
  USE module_dep_simple
  USE module_bioemi_simple
  USE module_phot_mad
  USE module_ftuv_driver, only : ftuv_timestep_init
  USE module_aerosols_sorgam
  USE module_chem_utilities
  USE module_gocart_so2so4
  USE module_aer_opt_out,only: aer_opt_out
  USE module_ctrans_grell
  USE module_data_soa_vbs, only: ldrog_vbs
  USE module_chem_cup, only: chem_cup_driver
  USE module_dry_dep_driver
  USE module_emissions_driver
  USE module_input_tracer, only: set_tracer
  USE module_wetscav_driver, only: wetscav_driver
  USE module_wetdep_ls, only:wetdep_ls
  USE module_input_chem_data, only: last_chem_time, &
                                     get_last_gas,mozcart_lbc_set
  USE module_upper_bc_driver, only: upper_bc_driver
  USE module_tropopause, only: tropopause_driver
  USE modal_aero_data, only: ntot_amode_cam_mam => ntot_amode
  USE module_cam_support, only: gas_pcnst => gas_pcnst_modal_aero,gas_pcnst_pos => gas_pcnst_modal_aero_pos, &
       pcnst =>pcnst_runtime, numgas_mam, cam_mam_aerosols
  USE module_cu_camzm_driver, only: zm_conv_tend_2
  USE module_cam_mam_gas_wetdep_driver, only: cam_mam_gas_wetdep_driver
  IMPLICIT NONE
  interface
     SUBROUTINE sum_pm_driver ( config_flags, &
          alt, chem, h2oaj, h2oai, &
          pm2_5_dry, pm2_5_water, pm2_5_dry_ec, pm10, &
          hoa_a01, hoa_a02, hoa_a03, hoa_a04, &
          hoa_a05, hoa_a06, hoa_a07, hoa_a08, &
          bboa_a01, bboa_a02, bboa_a03, bboa_a04, &
          bboa_a05, bboa_a06, bboa_a07, bboa_a08, &
          soa_a01, soa_a02, soa_a03, soa_a04, &
          soa_a05, soa_a06, soa_a07, soa_a08, &
          bbsoa_a01, bbsoa_a02, bbsoa_a03, bbsoa_a04, &
          bbsoa_a05, bbsoa_a06, bbsoa_a07, bbsoa_a08, &
          hsoa_a01, hsoa_a02, hsoa_a03, hsoa_a04, &
          hsoa_a05, hsoa_a06, hsoa_a07, hsoa_a08, &
          biog_a01, biog_a02, biog_a03, biog_a04, &
          biog_a05, biog_a06, biog_a07, biog_a08, &
          asmpsoa_a01, asmpsoa_a02, asmpsoa_a03, asmpsoa_a04, &
          arosoa_a01, arosoa_a02, arosoa_a03, arosoa_a04, &
          arosoa_a05, arosoa_a06, arosoa_a07, arosoa_a08, &
          totoa_a01, totoa_a02, totoa_a03, totoa_a04, &
          totoa_a05, totoa_a06, totoa_a07, totoa_a08, &
          hsoa_c, hsoa_o, bbsoa_c, bbsoa_o, &
          biog_v1, biog_v2, biog_v3, biog_v4, &
          ant_v1, ant_v2, ant_v3, ant_v4, &
          smpa_v1, smpbb_v1, &
          hoa_cw01, hoa_cw02, hoa_cw03, hoa_cw04, &
          hoa_cw05, hoa_cw06, hoa_cw07, hoa_cw08, &
          bboa_cw01, bboa_cw02, bboa_cw03, bboa_cw04, &
          bboa_cw05, bboa_cw06, bboa_cw07, bboa_cw08, &
          soa_cw01, soa_cw02, soa_cw03, soa_cw04, &
          soa_cw05, soa_cw06, soa_cw07, soa_cw08, &
          bbsoa_cw01, bbsoa_cw02, bbsoa_cw03, bbsoa_cw04, &
          bbsoa_cw05, bbsoa_cw06, bbsoa_cw07, bbsoa_cw08, &
          biog_cw01, biog_cw02, biog_cw03, biog_cw04, &
          biog_cw05, biog_cw06, biog_cw07, biog_cw08, &
          hsoa_cw01, hsoa_cw02, hsoa_cw03, hsoa_cw04, &
          hsoa_cw05, hsoa_cw06, hsoa_cw07, hsoa_cw08, &
          arosoa_cw01, arosoa_cw02, arosoa_cw03, arosoa_cw04, &
          arosoa_cw05, arosoa_cw06, arosoa_cw07, arosoa_cw08, &
          totoa_cw01, totoa_cw02, totoa_cw03, totoa_cw04, &
          totoa_cw05, totoa_cw06, totoa_cw07, totoa_cw08, &
          hsoa_cw_c, hsoa_cw_o, bbsoa_cw_c, bbsoa_cw_o, &
          biog_cw_v1, &
          ant_cw_v1, &
          ids,ide, jds,jde, kds,kde, &
          ims,ime, jms,jme, kms,kme, &
          its,ite, jts,jte, kts,kte )
       USE module_configure
       USE module_aerosols_sorgam, only: sum_pm_sorgam
       USE module_mosaic_driver, only: sum_pm_mosaic,sum_pm_mosaic_vbs2,sum_pm_mosaic_vbs0,sum_vbs9,sum_vbs2,sum_vbs0
       USE module_gocart_aerosols, only: sum_pm_gocart
       USE module_aerosols_soa_vbs, only: sum_pm_soa_vbs
       IMPLICIT NONE
       INTEGER, INTENT(IN ) :: &
            ids,ide, jds,jde, kds,kde, &
            ims,ime, jms,jme, kms,kme, &
            its,ite, jts,jte, kts,kte
       REAL, DIMENSION( ims:ime, kms:kme, jms:jme, num_chem ), &
            INTENT(IN ) :: chem
       REAL, DIMENSION( ims:ime, kms:kme, jms:jme ), &
            INTENT(IN ) :: alt
       REAL, DIMENSION( ims:ime, kms:kme, jms:jme ), &
            OPTIONAL, &
            INTENT(IN ) :: h2oaj,h2oai
       REAL, DIMENSION( ims:ime, kms:kme, jms:jme ), &
         OPTIONAL, &
         INTENT(OUT) :: pm2_5_dry,pm2_5_water,pm2_5_dry_ec,pm10, &
             hoa_a01, hoa_a02, hoa_a03, hoa_a04, &
             hoa_a05, hoa_a06, hoa_a07, hoa_a08, &
             bboa_a01, bboa_a02, bboa_a03, bboa_a04, &
             bboa_a05, bboa_a06, bboa_a07, bboa_a08, &
             soa_a01, soa_a02, soa_a03, soa_a04, &
             soa_a05, soa_a06, soa_a07, soa_a08, &
             bbsoa_a01, bbsoa_a02, bbsoa_a03, bbsoa_a04, &
             bbsoa_a05, bbsoa_a06, bbsoa_a07, bbsoa_a08, &
             hsoa_a01, hsoa_a02, hsoa_a03, hsoa_a04, &
             hsoa_a05, hsoa_a06, hsoa_a07, hsoa_a08, &
             biog_a01, biog_a02, biog_a03, biog_a04, &
             biog_a05, biog_a06, biog_a07, biog_a08, &
             arosoa_a01, arosoa_a02, arosoa_a03, arosoa_a04, &
             arosoa_a05, arosoa_a06, arosoa_a07, arosoa_a08, &
             totoa_a01, totoa_a02, totoa_a03, totoa_a04, &
             totoa_a05, totoa_a06, totoa_a07, totoa_a08, &
             hsoa_c, hsoa_o, bbsoa_c, bbsoa_o, &
             biog_v1, biog_v2, biog_v3, biog_v4, &
             ant_v1, ant_v2, ant_v3, ant_v4, &
             smpa_v1, &
             smpbb_v1, &
             asmpsoa_a01, asmpsoa_a02, asmpsoa_a03, asmpsoa_a04, &
             hoa_cw01, hoa_cw02, hoa_cw03, hoa_cw04, &
             hoa_cw05, hoa_cw06, hoa_cw07, hoa_cw08, &
             bboa_cw01, bboa_cw02, bboa_cw03, bboa_cw04, &
             bboa_cw05, bboa_cw06, bboa_cw07, bboa_cw08, &
             soa_cw01, soa_cw02, soa_cw03, soa_cw04, &
             soa_cw05, soa_cw06, soa_cw07, soa_cw08, &
             bbsoa_cw01, bbsoa_cw02, bbsoa_cw03, bbsoa_cw04, &
             bbsoa_cw05, bbsoa_cw06, bbsoa_cw07, bbsoa_cw08, &
             biog_cw01, biog_cw02, biog_cw03, biog_cw04, &
             biog_cw05, biog_cw06, biog_cw07, biog_cw08, &
             hsoa_cw01, hsoa_cw02, hsoa_cw03, hsoa_cw04, &
             hsoa_cw05, hsoa_cw06, hsoa_cw07, hsoa_cw08, &
             arosoa_cw01, arosoa_cw02, arosoa_cw03, arosoa_cw04, &
             arosoa_cw05, arosoa_cw06, arosoa_cw07, arosoa_cw08, &
             totoa_cw01, totoa_cw02, totoa_cw03, totoa_cw04, &
             totoa_cw05, totoa_cw06, totoa_cw07, totoa_cw08, &
             hsoa_cw_c, hsoa_cw_o, bbsoa_cw_c, bbsoa_cw_o, &
             biog_cw_v1, &
             ant_cw_v1
       TYPE(grid_config_rec_type), INTENT(IN ) :: config_flags
     end SUBROUTINE sum_pm_driver
  end interface
   TYPE(domain) , TARGET :: grid
real ,DIMENSION(grid%sm31:grid%em31,grid%sm32:grid%em32,grid%sm33:grid%em33,num_moist) :: moist
real ,DIMENSION(grid%sm33:grid%em33,grid%sm32:grid%em32,grid%spec_bdy_width,num_moist) :: moist_bxs
real ,DIMENSION(grid%sm33:grid%em33,grid%sm32:grid%em32,grid%spec_bdy_width,num_moist) :: moist_bxe
real ,DIMENSION(grid%sm31:grid%em31,grid%sm32:grid%em32,grid%spec_bdy_width,num_moist) :: moist_bys
real ,DIMENSION(grid%sm31:grid%em31,grid%sm32:grid%em32,grid%spec_bdy_width,num_moist) :: moist_bye
real ,DIMENSION(grid%sm33:grid%em33,grid%sm32:grid%em32,grid%spec_bdy_width,num_moist) :: moist_btxs
real ,DIMENSION(grid%sm33:grid%em33,grid%sm32:grid%em32,grid%spec_bdy_width,num_moist) :: moist_btxe
real ,DIMENSION(grid%sm31:grid%em31,grid%sm32:grid%em32,grid%spec_bdy_width,num_moist) :: moist_btys
real ,DIMENSION(grid%sm31:grid%em31,grid%sm32:grid%em32,grid%spec_bdy_width,num_moist) :: moist_btye
real ,DIMENSION(grid%sm31:grid%em31,grid%sm32:grid%em32,grid%sm33:grid%em33,num_dfi_moist) :: dfi_moist
real ,DIMENSION(grid%sm33:grid%em33,grid%sm32:grid%em32,grid%spec_bdy_width,num_dfi_moist) :: dfi_moist_bxs
real ,DIMENSION(grid%sm33:grid%em33,grid%sm32:grid%em32,grid%spec_bdy_width,num_dfi_moist) :: dfi_moist_bxe
real ,DIMENSION(grid%sm31:grid%em31,grid%sm32:grid%em32,grid%spec_bdy_width,num_dfi_moist) :: dfi_moist_bys
real ,DIMENSION(grid%sm31:grid%em31,grid%sm32:grid%em32,grid%spec_bdy_width,num_dfi_moist) :: dfi_moist_bye
real ,DIMENSION(grid%sm33:grid%em33,grid%sm32:grid%em32,grid%spec_bdy_width,num_dfi_moist) :: dfi_moist_btxs
real ,DIMENSION(grid%sm33:grid%em33,grid%sm32:grid%em32,grid%spec_bdy_width,num_dfi_moist) :: dfi_moist_btxe
real ,DIMENSION(grid%sm31:grid%em31,grid%sm32:grid%em32,grid%spec_bdy_width,num_dfi_moist) :: dfi_moist_btys
real ,DIMENSION(grid%sm31:grid%em31,grid%sm32:grid%em32,grid%spec_bdy_width,num_dfi_moist) :: dfi_moist_btye
real ,DIMENSION(grid%sm31:grid%em31,grid%sm32:grid%em32,grid%sm33:grid%em33,num_scalar) :: scalar
real ,DIMENSION(grid%sm33:grid%em33,grid%sm32:grid%em32,grid%spec_bdy_width,num_scalar) :: scalar_bxs
real ,DIMENSION(grid%sm33:grid%em33,grid%sm32:grid%em32,grid%spec_bdy_width,num_scalar) :: scalar_bxe
real ,DIMENSION(grid%sm31:grid%em31,grid%sm32:grid%em32,grid%spec_bdy_width,num_scalar) :: scalar_bys
real ,DIMENSION(grid%sm31:grid%em31,grid%sm32:grid%em32,grid%spec_bdy_width,num_scalar) :: scalar_bye
real ,DIMENSION(grid%sm33:grid%em33,grid%sm32:grid%em32,grid%spec_bdy_width,num_scalar) :: scalar_btxs
real ,DIMENSION(grid%sm33:grid%em33,grid%sm32:grid%em32,grid%spec_bdy_width,num_scalar) :: scalar_btxe
real ,DIMENSION(grid%sm31:grid%em31,grid%sm32:grid%em32,grid%spec_bdy_width,num_scalar) :: scalar_btys
real ,DIMENSION(grid%sm31:grid%em31,grid%sm32:grid%em32,grid%spec_bdy_width,num_scalar) :: scalar_btye
real ,DIMENSION(grid%sm31:grid%em31,grid%sm32:grid%em32,grid%sm33:grid%em33,num_dfi_scalar) :: dfi_scalar
real ,DIMENSION(grid%sm33:grid%em33,grid%sm32:grid%em32,grid%spec_bdy_width,num_dfi_scalar) :: dfi_scalar_bxs
real ,DIMENSION(grid%sm33:grid%em33,grid%sm32:grid%em32,grid%spec_bdy_width,num_dfi_scalar) :: dfi_scalar_bxe
real ,DIMENSION(grid%sm31:grid%em31,grid%sm32:grid%em32,grid%spec_bdy_width,num_dfi_scalar) :: dfi_scalar_bys
real ,DIMENSION(grid%sm31:grid%em31,grid%sm32:grid%em32,grid%spec_bdy_width,num_dfi_scalar) :: dfi_scalar_bye
real ,DIMENSION(grid%sm33:grid%em33,grid%sm32:grid%em32,grid%spec_bdy_width,num_dfi_scalar) :: dfi_scalar_btxs
real ,DIMENSION(grid%sm33:grid%em33,grid%sm32:grid%em32,grid%spec_bdy_width,num_dfi_scalar) :: dfi_scalar_btxe
real ,DIMENSION(grid%sm31:grid%em31,grid%sm32:grid%em32,grid%spec_bdy_width,num_dfi_scalar) :: dfi_scalar_btys
real ,DIMENSION(grid%sm31:grid%em31,grid%sm32:grid%em32,grid%spec_bdy_width,num_dfi_scalar) :: dfi_scalar_btye
real ,DIMENSION(grid%sm31:grid%em31,grid%sm32:grid%em32,grid%sm33:grid%em33,num_aerod) :: aerod
real ,DIMENSION(grid%sm31:grid%em31,1:grid%levsiz,grid%sm33:grid%em33,num_ozmixm) :: ozmixm
real ,DIMENSION(grid%sm31:grid%em31,1:grid%paerlev,grid%sm33:grid%em33,num_aerosolc) :: aerosolc_1
real ,DIMENSION(grid%sm31:grid%em31,1:grid%paerlev,grid%sm33:grid%em33,num_aerosolc) :: aerosolc_2
real ,DIMENSION(grid%sm31:grid%em31,grid%sm32:grid%em32,grid%sm33:grid%em33,num_fdda3d) :: fdda3d
real ,DIMENSION(grid%sm31:grid%em31,1:1,grid%sm33:grid%em33,num_fdda2d) :: fdda2d
real ,DIMENSION(grid%sm31:grid%em31,grid%sm32:grid%em32,grid%sm33:grid%em33,num_advh_t) :: advh_t
real ,DIMENSION(grid%sm31:grid%em31,grid%sm32:grid%em32,grid%sm33:grid%em33,num_advz_t) :: advz_t
real ,DIMENSION(grid%sm31:grid%em31,1:grid%kemit,grid%sm33:grid%em33,num_emis_ant) :: emis_ant
real ,DIMENSION(grid%sm31:grid%em31,1:1,grid%sm33:grid%em33,num_eghg_bio) :: eghg_bio
real ,DIMENSION(grid%sm31:grid%em31,1:grid%kfuture,grid%sm33:grid%em33,num_emis_dust) :: emis_dust
real ,DIMENSION(grid%sm31:grid%em31,1:grid%kfuture,grid%sm33:grid%em33,num_emis_seas) :: emis_seas
real ,DIMENSION(grid%sm31:grid%em31,grid%sm32:grid%em32,grid%sm33:grid%em33,num_emis_vol) :: emis_vol
real ,DIMENSION(grid%sm31:grid%em31,grid%sm32:grid%em32,grid%sm33:grid%em33,num_ebu) :: ebu
real ,DIMENSION(grid%sm31:grid%em31,1:grid%kfire,grid%sm33:grid%em33,num_ebu_in) :: ebu_in
real ,DIMENSION(grid%sm31:grid%em31,1:grid%kemit_aircraft,grid%sm33:grid%em33,num_emis_aircraft) :: emis_aircraft
real ,DIMENSION(grid%sm31:grid%em31,grid%sm32:grid%em32,grid%sm33:grid%em33,num_ext_coef) :: ext_coef
real ,DIMENSION(grid%sm31:grid%em31,grid%sm32:grid%em32,grid%sm33:grid%em33,num_bscat_coef) :: bscat_coef
real ,DIMENSION(grid%sm31:grid%em31,grid%sm32:grid%em32,grid%sm33:grid%em33,num_asym_par) :: asym_par
real ,DIMENSION(grid%sm31:grid%em31,grid%sm32:grid%em32,grid%sm33:grid%em33,num_conv_ct) :: conv_ct
real ,DIMENSION(grid%sm31:grid%em31,grid%sm32:grid%em32,grid%sm33:grid%em33,num_chem_ct) :: chem_ct
real ,DIMENSION(grid%sm31:grid%em31,grid%sm32:grid%em32,grid%sm33:grid%em33,num_vmix_ct) :: vmix_ct
real ,DIMENSION(grid%sm31:grid%em31,grid%sm32:grid%em32,grid%sm33:grid%em33,num_advh_ct) :: advh_ct
real ,DIMENSION(grid%sm31:grid%em31,grid%sm32:grid%em32,grid%sm33:grid%em33,num_advz_ct) :: advz_ct
real ,DIMENSION(grid%sm31:grid%em31,1:grid%kdvel,grid%sm33:grid%em33,num_dvel) :: dvel
real ,DIMENSION(grid%sm31:grid%em31,1:8,grid%sm33:grid%em33,num_vprm_in) :: vprm_in
real ,DIMENSION(grid%sm31:grid%em31,1:1,grid%sm33:grid%em33,num_wet_in) :: wet_in
real ,DIMENSION(grid%sm31:grid%em31,grid%sm32:grid%em32,grid%sm33:grid%em33,num_chem) :: chem
real ,DIMENSION(grid%sm33:grid%em33,grid%sm32:grid%em32,grid%spec_bdy_width,num_chem) :: chem_bxs
real ,DIMENSION(grid%sm33:grid%em33,grid%sm32:grid%em32,grid%spec_bdy_width,num_chem) :: chem_bxe
real ,DIMENSION(grid%sm31:grid%em31,grid%sm32:grid%em32,grid%spec_bdy_width,num_chem) :: chem_bys
real ,DIMENSION(grid%sm31:grid%em31,grid%sm32:grid%em32,grid%spec_bdy_width,num_chem) :: chem_bye
real ,DIMENSION(grid%sm33:grid%em33,grid%sm32:grid%em32,grid%spec_bdy_width,num_chem) :: chem_btxs
real ,DIMENSION(grid%sm33:grid%em33,grid%sm32:grid%em32,grid%spec_bdy_width,num_chem) :: chem_btxe
real ,DIMENSION(grid%sm31:grid%em31,grid%sm32:grid%em32,grid%spec_bdy_width,num_chem) :: chem_btys
real ,DIMENSION(grid%sm31:grid%em31,grid%sm32:grid%em32,grid%spec_bdy_width,num_chem) :: chem_btye
real ,DIMENSION(grid%sm31:grid%em31,grid%sm32:grid%em32,grid%sm33:grid%em33,num_tracer) :: tracer
real ,DIMENSION(grid%sm33:grid%em33,grid%sm32:grid%em32,grid%spec_bdy_width,num_tracer) :: tracer_bxs
real ,DIMENSION(grid%sm33:grid%em33,grid%sm32:grid%em32,grid%spec_bdy_width,num_tracer) :: tracer_bxe
real ,DIMENSION(grid%sm31:grid%em31,grid%sm32:grid%em32,grid%spec_bdy_width,num_tracer) :: tracer_bys
real ,DIMENSION(grid%sm31:grid%em31,grid%sm32:grid%em32,grid%spec_bdy_width,num_tracer) :: tracer_bye
real ,DIMENSION(grid%sm33:grid%em33,grid%sm32:grid%em32,grid%spec_bdy_width,num_tracer) :: tracer_btxs
real ,DIMENSION(grid%sm33:grid%em33,grid%sm32:grid%em32,grid%spec_bdy_width,num_tracer) :: tracer_btxe
real ,DIMENSION(grid%sm31:grid%em31,grid%sm32:grid%em32,grid%spec_bdy_width,num_tracer) :: tracer_btys
real ,DIMENSION(grid%sm31:grid%em31,grid%sm32:grid%em32,grid%spec_bdy_width,num_tracer) :: tracer_btye
real ,DIMENSION(grid%sm31:grid%em31,grid%sm32:grid%em32,grid%sm33:grid%em33,num_nba_mij) :: nba_mij
real ,DIMENSION(grid%sm31:grid%em31,grid%sm32:grid%em32,grid%sm33:grid%em33,num_nba_rij) :: nba_rij
   TYPE(grid_config_rec_type), INTENT(IN ) :: config_flags
   INTEGER :: ids,ide, jds,jde, kds,kde, &
                                  ims,ime, jms,jme, kms,kme, &
                                  ips,ipe, jps,jpe, kps,kpe, &
                                  its,ite, jts,jte, kts,kte
   INTEGER :: stepave,i,j,k,l,numgas,nv,n, nr,ktau,k_start,k_end,idf,jdf,kdf
   INTEGER :: ijulian
   INTEGER :: bc_switch, so4_switch
      real, dimension(grid%sm31:grid%em31,grid%sm32:grid%em32,grid%sm33:grid%em33) ::vcsulf_old,vcso2_old,vch2o2_old
      real, dimension(grid%sm31:grid%em31,grid%sm32:grid%em32,grid%sm33:grid%em33,ldrog) ::vdrog3
      real, dimension(grid%sm31:grid%em31,grid%sm32:grid%em32,grid%sm33:grid%em33,ldrog_vbs) ::vdrog3_vbs
      real, dimension(grid%sm31:grid%em31,grid%sm32:grid%em32,grid%sm33:grid%em33) ::n2o5_het
      REAL,DIMENSION(grid%sm31:grid%em31,grid%sm32:grid%em32,grid%sm33:grid%em33) :: &
                                                              p_phy,u_phy,v_phy &
                                                             ,t_phy,dz8w,t8w,p8w &
                                                             ,rho,rri,z_at_w,vvel,zmid,rh
      REAL,DIMENSION(grid%sm31:grid%em31,grid%sm33:grid%em33) :: pbl_h
      REAL,DIMENSION(grid%sm31:grid%em31,grid%sm33:grid%em33, 5) :: seasin,dustin
      REAL,DIMENSION(grid%sm32:grid%em32-1) :: QL,TL
      REAL,DIMENSION(grid%sm31:grid%em31,grid%sm33:grid%em33) :: REXNSFC,FACTRS &
                                        ,TOT,TSFC
      REAL,DIMENSION(grid%sm31:grid%em31,grid%sm32:grid%em32,grid%sm33:grid%em33,num_chem_ct) :: chem_old
      INTEGER,DIMENSION(num_chem_ct) :: chem_ct_indices
      TYPE(WRFU_TimeInterval) :: tmpTimeInterval
      REAL(KIND=8) :: curr_secs
      REAL(KIND=8) :: real_time_r8
      LOGICAL :: adapt_step_flag, do_chemstep, do_photstep
      LOGICAL :: do_radeffectstep
      REAL :: DAYI,DPL,FICE,FRAIN,HOUR,PLYR &
     & ,QI,QR,QW,RADT,TIMES,WC,TDUM,WMSK,RWMSK
      INTEGER :: ij
      INTEGER :: im , num_3d_m , ic , num_3d_c, num_3d_s
      INTEGER :: ijds, ijde
      INTEGER :: ksubt
      REAL :: chem_minval, dtstepc
      REAL, DIMENSION(grid%sm31:grid%em31, grid%sm32:grid%em32, grid%sm33:grid%em33, numgas_mam) :: gas_aqfrac
      REAL, DIMENSION( grid%sm31:grid%em31, grid%sm32:grid%em32, grid%sm33:grid%em33, ntot_amode_cam_mam ) :: &
         wetdens_ap
      REAL, DIMENSION( grid%sm31:grid%em31, grid%sm32:grid%em32, grid%sm33:grid%em33 ) :: &
         del_h2so4_gasprod
      REAL, DIMENSION( grid%sm31:grid%em31, grid%sm32:grid%em32, grid%sm33:grid%em33,gas_pcnst_pos) :: dvmrdt_sv13d,dvmrcwdt_sv13d
      LOGICAL :: haveaer
      CHARACTER (LEN=1000) :: msg
      CHARACTER (LEN=256) :: current_date_char
      integer :: current_month
      INTRINSIC max, min
  adapt_step_flag = .TRUE.
  ktau = grid%itimestep
  tmpTimeInterval = domain_get_time_since_sim_start(grid)
  curr_secs = real_time_r8(tmpTimeInterval)
  ijulian=ifix(grid%julian)
  do_photstep = .false.
  IF ( ktau==1 ) then
     do_photstep = .true.
  ELSE IF ( adapt_step_flag ) THEN
     IF ( (grid%photdt<=0) .or. &
          ( curr_secs+real(grid%dt,8)+0.01 >= &
          ( INT( curr_secs/real(grid%photdt*60.,8)+1,8 )*real(grid%photdt*60.,8) ) ) &
          ) then
        do_photstep = .true.
     ENDIF
  ELSE IF ( (MOD(ktau,grid%stepphot)==0) .or. (grid%stepphot==1) ) THEN
     do_photstep = .true.
  ENDIF
  do_radeffectstep = .false.
  IF ( ktau==1 ) then
     do_radeffectstep = .true.
  ELSE IF ( adapt_step_flag ) THEN
     IF ( (grid%radeffectdt<=0) .or. &
          ( curr_secs+real(grid%dt,8)+0.01 >= &
          ( INT( curr_secs/real(grid%radeffectdt*60.,8)+1,8 )*real(grid%radeffectdt*60.,8)) ) &
          ) then
        do_radeffectstep = .true.
     ENDIF
  ELSE IF ( (MOD(ktau,grid%stepradeffect)==0) .or. (grid%stepradeffect==1) ) THEN
     do_radeffectstep = .true.
  ENDIF
  if( ktau==1 ) then
     dtstepc = grid%dt
  else
     tmpTimeInterval = domain_get_current_time(grid) - last_chem_time(grid%id)
     dtstepc = real(real_time_r8(tmpTimeInterval),4)
  end if
  if( ktau==1 ) then
     grid%conv_ct(:,:,:,:) = 0.
     grid%chem_ct(:,:,:,:) = 0.
     grid%vmix_ct(:,:,:,:) = 0.
  endif
  if(config_flags%chemdiag == USECHEMDIAG)then
      chem_ct_indices(p_chem_co) = p_co
      chem_ct_indices(p_chem_o3) = p_o3
      chem_ct_indices(p_chem_no) = p_no
      chem_ct_indices(p_chem_no2) = p_no2
      chem_ct_indices(p_chem_hno3) = p_hno3
      chem_ct_indices(p_chem_iso) = p_iso
      chem_ct_indices(p_chem_ho) = p_ho
      chem_ct_indices(p_chem_ho2) = p_ho2
  endif
  do_chemstep = .false.
  IF ( ktau==1 ) then
     do_chemstep = .true.
     grid%ktauc = 1
  ELSE IF ( adapt_step_flag ) THEN
     IF ( (grid%chemdt<=0) .or. &
          ( curr_secs+real(grid%dt,8)+0.01 >= &
          ( INT( curr_secs/real(grid%chemdt*60.,8)+1,8 )*real(grid%chemdt*60.,8) ) ) &
          ) then
        do_chemstep = .true.
        grid%ktauc = grid%ktauc+1
        last_chem_time(grid%id) = domain_get_current_time( grid )
        call WRFU_TimeGet( last_chem_time(grid%id), &
                           YY = grid%last_chem_time_year, &
                           MM = grid%last_chem_time_month, &
                           DD = grid%last_chem_time_day, &
                           H = grid%last_chem_time_hour, &
                           M = grid%last_chem_time_minute, &
                           S = grid%last_chem_time_second )
     ENDIF
  ELSE IF ( (MOD(ktau,grid%stepchem)==0) .or. (grid%stepchem==1) ) THEN
     do_chemstep = .true.
     grid%ktauc=max(ktau/grid%stepchem,1)
  ENDIF
  CALL get_ijk_from_grid ( grid , &
                            ids, ide, jds, jde, kds, kde, &
                            ims, ime, jms, jme, kms, kme, &
                            ips, ipe, jps, jpe, kps, kpe )
  CALL domain_clock_get( grid, current_timestr=current_date_char )
  read(current_date_char(6:7),FMT='(I2)') current_month
  seasin(:,:,:)=0.
  dustin(:,:,:)=0.
  if(config_flags%cu_diag == 0 ) grid%raincv_b(:,:) = grid%raincv(:,:)
  num_3d_m = num_moist
  num_3d_c = num_chem
  num_3d_s = num_scalar
  numgas = get_last_gas(config_flags%chem_opt)
  CALL set_tiles ( grid , ids , ide , jds , jde , ips , ipe , jps , jpe )
  k_start = kps
  k_end = kpe
  ijds = min(ids, jds)
  ijde = max(ide, jde)
   chem_minval = epsilc
   chem_select: SELECT CASE(config_flags%chem_opt)
     CASE (RADM2)
       CALL wrf_debug(15,'calling radm2 from chem_driver')
       haveaer = .false.
     CASE (RADM2_KPP)
       CALL wrf_debug(15,'calling radm2_kpp from chem_driver')
       haveaer = .false.
     CASE (CRIMECH_KPP)
       CALL wrf_debug(15,'calling crimech_kpp from chem_driver')
       haveaer = .false.
     CASE (RADM2SORG)
       CALL wrf_debug(15,'calling radm2sorg aerosols driver from chem_driver')
       haveaer = .true.
     CASE (RADM2SORG_KPP)
       CALL wrf_debug(15,'calling radm2sorg aerosols driver from chem_driver')
       haveaer = .false.
     CASE (RADM2SORG_AQ)
       CALL wrf_debug(15,'calling radm2sorg_aq aerosols driver from chem_driver')
       haveaer = .true.
     CASE (RACMSORG_AQ)
       CALL wrf_debug(15,'calling racmsorg_aq aerosols driver from chem_driver')
       haveaer = .true.
     CASE (RADM2SORG_AQCHEM)
       CALL wrf_debug(15,'calling radm2sorg_aqchem aerosols driver from chem_driver')
       haveaer = .true.
     CASE (RACMSORG_AQCHEM_KPP)
       CALL wrf_debug(15,'calling racmsorg_aqchem_kpp aerosols driver from chem_driver')
       haveaer = .true.
     CASE (RACM_ESRLSORG_AQCHEM_KPP)
       CALL wrf_debug(15,'calling racm_esrlsorg_aqchem_kpp aerosols driver from chem_driver')
       haveaer = .true.
     CASE (RACM_KPP)
       CALL wrf_debug(15,'calling racm_kpp from chem_driver')
     CASE (RACMPM_KPP)
       CALL wrf_debug(15,'calling racmpm_kpp from chem_driver')
       haveaer = .false.
     CASE (RACM_MIM_KPP)
       CALL wrf_debug(15,'calling racm_mim_kpp from chem_driver')
       haveaer = .false.
     CASE (RACM_ESRLSORG_KPP)
       CALL wrf_debug(15,'calling racmsorgesrl_kpp aerosols driver from chem_driver')
       haveaer = .false.
     CASE (RACMSORG_KPP)
       CALL wrf_debug(15,'calling racmsorg_kpp aerosols driver from chem_driver')
       haveaer = .false.
     CASE (RACM_SOA_VBS_KPP)
       CALL wrf_debug(15,'calling racm_soa_vbs_kpp aerosols driver from chem_driver')
       haveaer = .false.
     CASE (GOCART_SIMPLE)
       CALL wrf_debug(15,'calling only gocart aerosols driver from chem_driver')
       haveaer = .false.
     CASE (GOCARTRACM_KPP)
       CALL wrf_debug(15,'calling gocart and racm driver from chem_driver')
       haveaer = .false.
     CASE (GOCARTRADM2_KPP)
       CALL wrf_debug(15,'calling gocart and radmkpp driver from chem_driver')
       haveaer = .false.
     CASE (GOCARTRADM2)
       CALL wrf_debug(15,'calling gocart and radm driver from chem_driver')
       haveaer = .false.
     CASE (SAPRC99_KPP)
       CALL wrf_debug(15,'calling saprc99_kpp from chem_driver')
       haveaer = .false.
     CASE (CBMZ_MOSAIC_4BIN_VBS2_KPP)
       CALL wrf_debug(15,'calling cbmz_mosaic_4bin_vbs2_kpp from chem_driver')
     CASE (SAPRC99_MOSAIC_4BIN_VBS9_KPP)
       CALL wrf_debug(15,'calling saprc99_mosaic_4bin_vbs9_kpp from chem_driver')
       haveaer = .false.
       haveaer = .false.
     CASE (SAPRC99_MOSAIC_4BIN_VBS2_KPP)
       CALL wrf_debug(15,'calling saprc99_mosaic_4bin_vbs2_kpp from chem_driver')
       haveaer = .false.
     CASE (MOZART_MOSAIC_4BIN_VBS0_KPP)
       CALL wrf_debug(15,'calling mozart_mosaic_4bin_vbs0_kpp from chem_driver')
       haveaer = .true.
     CASE (SAPRC99_MOSAIC_8BIN_VBS2_AQ_KPP)
       CALL wrf_debug(15,'calling saprc99_mosaic_8bin_vbs2_aq_kpp from chem_driver')
       haveaer = .false.
    CASE (SAPRC99_MOSAIC_8BIN_VBS2_KPP)
       CALL wrf_debug(15,'calling saprc99_mosaic_8bin_vbs2_kpp from chem_driver')
       haveaer = .false.
     CASE (CBMZSORG)
       CALL wrf_debug(15,'calling cbmzsorg aerosols from chem_driver')
       haveaer = .true.
     CASE (CBMZSORG_AQ)
       CALL wrf_debug(15,'calling cbmzsorg_aq aerosols from chem_driver')
       haveaer = .true.
     CASE (CBMZ)
       CALL wrf_debug(15,'calling cbmz from chem_driver')
       haveaer = .false.
     CASE (CBMZ_BB)
       CALL wrf_debug(15,'calling cbmz_bb from chem_driver')
       haveaer = .false.
     CASE (CBMZ_BB_KPP)
       CALL wrf_debug(15,'calling cbmz_bb_kpp from chem_driver')
     CASE (CBMZ_SORGAM_KPP)
       CALL wrf_debug(15,'calling cbmz_sorgam_kpp from chem_driver')
       haveaer = .false.
     CASE (CBMZ_MOSAIC_KPP)
       CALL wrf_debug(15,'calling cbmz_mosaic_kpp from chem_driver')
       haveaer = .false.
     CASE (CBMZ_MOSAIC_8BIN_VBS9_KPP)
       CALL wrf_debug(15,'calling cbmz_8bin_vbs9_kpp from chem_driver')
       haveaer = .false.
     CASE (CBMZ_MOSAIC_4BIN_VBS9_KPP)
       CALL wrf_debug(15,'calling cbmz_4bin_vbs9_kpp from chem_driver')
       haveaer = .false.
     CASE (CBMZ_MOSAIC_4BIN)
       CALL wrf_debug(15,'calling cbmz_mosaic_4bin aerosols driver from chem_driver')
       haveaer = .true.
     CASE (CBMZ_MOSAIC_8BIN)
       CALL wrf_debug(15,'calling cbmz_mosaic_8bin aerosols driver from chem_driver')
       haveaer = .true.
     CASE (CBMZ_MOSAIC_4BIN_AQ)
       CALL wrf_debug(15,'calling cbmz_mosaic_4bin_aq aerosols driver from chem_driver')
       haveaer = .true.
     CASE (CBMZ_MOSAIC_8BIN_AQ)
       CALL wrf_debug(15,'calling cbmz_mosaic_8bin_aq aerosols driver from chem_driver')
       haveaer = .true.
     CASE (CBMZ_MOSAIC_DMS_4BIN)
       CALL wrf_debug(15,'calling cbmz_mosaic_dms_4bin aerosols driver from chem_driver')
       haveaer = .true.
     CASE (CBMZ_MOSAIC_DMS_8BIN)
       CALL wrf_debug(15,'calling cbmz_mosaic_dms_8bin aerosols driver from chem_driver')
       haveaer = .true.
     CASE (CBMZ_MOSAIC_DMS_4BIN_AQ)
       CALL wrf_debug(15,'calling cbmz_mosaic_dms_4bin_aq aerosols driver from chem_driver')
       haveaer = .true.
     CASE (CBMZ_MOSAIC_DMS_8BIN_AQ)
       CALL wrf_debug(15,'calling cbmz_mosaic_dms_8bin_aq aerosols driver from chem_driver')
       haveaer = .true.
     CASE (CRI_MOSAIC_8BIN_AQ_KPP)
       CALL wrf_debug(15,'calling cri_mosaic_8bin_aq_kpp aerosols driver from chem_driver')
       haveaer = .true.
     CASE (CRI_MOSAIC_4BIN_AQ_KPP)
       CALL wrf_debug(15,'calling cri_mosaic_4bin_aq_kpp aerosols driver from chem_driver')
       haveaer = .true.
     CASE (MOZART_KPP)
       CALL wrf_debug(15,'calling mozart driver from chem_driver')
     CASE (MOZCART_KPP)
       CALL wrf_debug(15,'calling mozcart driver from chem_driver')
    CASE (CHEM_TRACER,CHEM_TRACE2)
       CALL wrf_debug(15,'tracer mode: only doing emissions and dry dep in chem_driver')
    CASE (CHEM_VOLC)
       CALL wrf_debug(15,'Full Volcanic Ash mode: doing emissions (SO2 + ASH), settling, and subgrid transport in chem_driver')
    CASE (CHEM_VOLC_4BIN)
       CALL wrf_debug(15,'4bin Volcanic Ash mode: doing emissions (ASH), settling, and subgrid transport in chem_driver')
    CASE (CHEM_VASH)
       CALL wrf_debug(15,'Volcanic Ash mode: only doing emissions, settling, and subgrid transport in chem_driver')
    CASE (DUST)
       CALL wrf_debug(15,'Dust only mode: only doing emissions, settling, and subgrid transport chem_driver')
    CASE (CO2_TRACER,GHG_TRACER)
      CALL wrf_debug(15,'Greenhouse gas mode: fluxes and transport of GHG')
    CASE DEFAULT
       if(config_flags%tracer_opt > 0 )then
       CALL wrf_debug(15,'only doing tracer transport in chem_driver')
       else
       CALL wrf_debug(15,'calling chem_opt=? from chem_driver')
       endif
   END SELECT chem_select
   tracer_select: SELECT CASE(config_flags%tracer_opt)
    CASE (TRACER_SMOKE)
       CALL wrf_debug(15,'tracer mode: 1 tracer for fires')
    CASE (TRACER_TEST1)
       CALL wrf_debug(15,'tracer mode: 8 tracers')
    CASE (TRACER_TEST2)
       CALL wrf_debug(15,'tracer mode: 8 tracers')
    CASE (TRACER_TEST3)
       CALL wrf_debug(15,'tracer mode: 10 tracers')
     CASE DEFAULT
       CALL wrf_debug(15,'calling chem_opt=? from chem_driver')
   END SELECT tracer_select
   if ((config_flags%chem_opt == CBMZ_CAM_MAM3_NOAQ) .or. &
       (config_flags%chem_opt == CBMZ_CAM_MAM3_AQ ) .or. &
       (config_flags%chem_opt == CBMZ_CAM_MAM7_NOAQ) .or. &
       (config_flags%chem_opt == CBMZ_CAM_MAM7_AQ )) then
      grid%dgnum4d(:,:,:,:) = 0.0
      grid%dgnumwet4d(:,:,:,:) = 0.0
      wetdens_ap(:,:,:,:) = 0.0
      if(numgas_mam < numgas) then
         write(msg,*)'CHEM_DRIVER - NUMGAS_MAM is should be equal to numgas (check chemics_init.F), numgas_mam=',numgas_mam,' and numgas=',numgas
         call wrf_error_fatal3("<stdin>",773,&
msg )
      endif
      if(.NOT.cam_mam_aerosols) then
         write(msg,*)'CHEM_DRIVER - cam_mam_aerosol should be TRUE (check module_physics_init.F), module_cam_mam_aerosol=',cam_mam_aerosols
         call wrf_error_fatal3("<stdin>",779,&
msg)
      endif
   end if
      do nv=1,num_chem
         do j=jps,jpe
            do k=kps,kpe
               do i=ips,ipe
                  chem(i,k,j,nv)=max(chem(i,k,j,nv),chem_minval)
               enddo
            enddo
         enddo
      enddo
      select case (config_flags%chem_opt)
      case (RADM2SORG, RADM2SORG_AQ, RADM2SORG_AQCHEM, RADM2SORG_KPP, &
            RACM_ESRLSORG_KPP,RACMSORG_AQ,RACMSORG_KPP, RACMSORG_AQCHEM_KPP, RACM_ESRLSORG_AQCHEM_KPP, RACM_SOA_VBS_KPP)
         do j=jps,jpe
            do k=kps,kpe
               do i=ips,ipe
                  if(chem(i,k,j,p_nu0).lt.1.e07) then
                     chem(i,k,j,p_nu0)=1.e7
                  endif
               enddo
            enddo
         enddo
      case (CBMZ_MOSAIC_4BIN_VBS2_KPP, SAPRC99_MOSAIC_4BIN_VBS2_KPP,SAPRC99_KPP,SAPRC99_MOSAIC_4BIN_VBS9_KPP, &
           SAPRC99_MOSAIC_8BIN_VBS2_AQ_KPP,SAPRC99_MOSAIC_8BIN_VBS2_KPP)
         CALL wrf_debug ( 15 , ' fixing ch4 conc using co conc' )
         do j=jps,jpe
            do k=kps,kpe
               do i=ips,ipe
                  chem(i,k,j,p_ch4)=1.893
               enddo
            enddo
         enddo
      end select
      vdrog3=0.
      do j=jps,min(jde-1,jpe)
         do k=kps,kpe
            do i=ips,min(ide-1,ipe)
              vvel(i,k,j)=grid%w_2(i,k,j)
              zmid(i,k,j)=grid%z(i,k,j)
            enddo
         enddo
      enddo
      do j=jps,min(jde-1,jpe)
         do k=kps,min(kde-1,kpe)
            do i=ips,min(ide-1,ipe)
              rri(i,k,j)=grid%alt(i,k,j)
            enddo
         enddo
      enddo
      do j=jps,min(jde-1,jpe)
         do i=ips,min(ide-1,ipe)
            pbl_h(i,j)=grid%pblh(i,j)
         enddo
      enddo
      if( config_flags%chem_opt == MOZART_KPP .or. &
          config_flags%chem_opt == MOZCART_KPP .or. &
          config_flags%chem_opt == MOZART_MOSAIC_4BIN_VBS0_KPP) then
        if( config_flags%phot_opt == FTUV ) then
          CALL ftuv_timestep_init( grid%id, grid%julday )
        endif
      endif
!$OMP PARALLEL DO &
!$OMP PRIVATE ( ij, its, ite, jts, jte )
   chem_tile_loop_1: DO ij = 1 , grid%num_tiles
       its = grid%i_start(ij)
       ite = min(grid%i_end(ij),ide-1)
       jts = grid%j_start(ij)
       jte = min(grid%j_end(ij),jde-1)
       kts=k_start
       kte=min(k_end,kde-1)
         CALL wrf_debug ( 15 , ' call chem_prep' )
         CALL chem_prep ( config_flags, &
                         grid%u_2, grid%v_2, grid%p, grid%pb, &
                         grid%alt,grid%ph_2, grid%phb, grid%t_2, &
                         moist, num_3d_m, rho, &
                         p_phy, u_phy, v_phy, &
                         p8w, t_phy, t8w, grid%z, z_at_w, &
                         dz8w, rh, grid%fnm, grid%fnp, &
                         ids, ide, jds, jde, kds, kde, &
                         ims, ime, jms, jme, kms, kme, &
                         its,ite,jts,jte, &
                         k_start, k_end )
    if(config_flags%emiss_inpt_opt > 0 .or. config_flags%dust_opt > 0)then
      call wrf_debug(15,'calling emissions driver')
      call emissions_driver(grid%id,ktau,grid%dt,grid%DX, &
              adapt_step_flag, curr_secs, &
              grid%plumerisefire_frq,grid%stepfirepl, &
              grid%bioemdt,grid%stepbioe, &
              config_flags, &
              grid%gmt,ijulian,rri,t_phy,moist,p8w,t8w,u_phy,v_phy,vvel, &
              grid%e_bio,p_phy,chem,rho,dz8w,grid%ne_area,emis_ant,emis_vol,grid%tsk, &
              grid%erod,g,emis_seas,emis_dust,tracer, &
              ebu , ebu_in,grid%mean_fct_agtf,grid%mean_fct_agef,grid%mean_fct_agsv, &
              grid%mean_fct_aggr,grid%firesize_agtf, &
              grid%firesize_agef,grid%firesize_agsv,grid%firesize_aggr, &
              grid%u10,grid%v10,grid%ivgtyp,grid%isltyp,grid%gsw,grid%vegfra,grid%rmol, &
              grid%ust,grid%znt,grid%dms_0,grid%erup_beg,grid%erup_end, &
              grid%xland,grid%xlat,grid%xlong, &
              z_at_w,zmid,grid%smois,dustin,seasin, &
              grid%sebio_iso,grid%sebio_oli,grid%sebio_api,grid%sebio_lim, &
              grid%sebio_xyl,grid%sebio_hc3,grid%sebio_ete,grid%sebio_olt, &
              grid%sebio_ket,grid%sebio_ald,grid%sebio_hcho,grid%sebio_eth, &
              grid%sebio_ora2,grid%sebio_co,grid%sebio_nr, &
              grid%sebio_sesq,grid%sebio_mbo, &
              grid%noag_grow,grid%noag_nongrow,grid%nononag,grid%slai, &
              grid%ebio_iso,grid%ebio_oli,grid%ebio_api,grid%ebio_lim,grid%ebio_xyl, &
              grid%ebio_hc3,grid%ebio_ete,grid%ebio_olt,grid%ebio_ket,grid%ebio_ald, &
              grid%ebio_hcho,grid%ebio_eth,grid%ebio_ora2,grid%ebio_co,grid%ebio_nr, &
              grid%ebio_no,grid%ebio_sesq,grid%ebio_mbo, &
              grid%ebio_c10h16,grid%ebio_tol,grid%ebio_bigalk, &
              grid%ebio_ch3oh,grid%ebio_acet,grid%ebio_nh3,grid%ebio_no2, &
              grid%ebio_c2h5oh,grid%ebio_ch3cooh,grid%ebio_mek,grid%ebio_bigene, &
              grid%ebio_c2h6,grid%ebio_c2h4,grid%ebio_c3h6,grid%ebio_c3h8,grid%ebio_so2, &
              grid%ebio_dms, &
              grid%ebio_alk3, grid%ebio_alk4, grid%ebio_alk5, grid%ebio_ole1, grid%ebio_ole2, &
              grid%ebio_aro1, grid%ebio_aro2, grid%ebio_ccho, grid%ebio_meoh, &
              grid%ebio_ethene, grid%ebio_hcooh, grid%ebio_terp, grid%ebio_bald, &
              grid%ebio_cco_oh, grid%ebio_rco_oh, &
              grid%clayfrac,grid%sandfrac,grid%dust_alpha,grid%dust_gamma,grid%dust_smtune,&
              grid%snowh,grid%zs, &
              grid%ebio_c5h8,grid%ebio_apinene,grid%ebio_bpinene,grid%ebio_toluene, &
              grid%ebio_ch3cho,grid%ebio_ch3co2h,grid%ebio_tbut2ene, &
              grid%ebio_c2h5cho,grid%ebio_nc4h10, &
              grid%T2,grid%swdown, &
              grid%nmegan,grid%EFmegan, &
              grid%msebio_isop, &
              grid%mlai, &
              grid%pftp_bt, grid%pftp_nt, grid%pftp_sb, grid%pftp_hb, &
              grid%mtsa, &
              grid%mswdown, &
              grid%mebio_isop,grid%mebio_apin,grid%mebio_bpin, grid%mebio_bcar, &
              grid%mebio_acet,grid%mebio_mbo,grid%mebio_no, &
              current_month, &
              grid%ht, grid%refl_10cm, grid%ic_flashrate, grid%cg_flashrate, &
              grid%cldfra_cup, grid%htop, &
              emis_aircraft, &
              vprm_in,grid%rad_vprm,grid%lambda_vprm, &
              grid%alpha_vprm,grid%resp_vprm,grid%xtime, &
              grid%TSLB, wet_in,grid%RAINC,grid%RAINNC, &
              grid%potevp,grid%SFCEVP,grid%LU_INDEX, &
              grid%biomt_par,grid%emit_par,grid%ebio_co2oce, &
              eghg_bio, &
              ids,ide, jds,jde, kds,kde, &
              ims,ime, jms,jme, kms,kme, &
              its,ite,jts,jte,kts,kte)
              if( config_flags%chem_opt == MOZART_KPP .or. &
                  config_flags%chem_opt == MOZCART_KPP .or. &
                  config_flags%chem_opt == MOZART_MOSAIC_4BIN_VBS0_KPP ) then
                 call mozcart_lbc_set( chem, num_chem, grid%id, &
                                       ims, ime, jms, jme, kms, kme, &
                                       its, ite, jts, jte, kts )
              end if
     endif
      if( do_photstep .and. &
           config_flags%chem_opt /= CHEM_TRACER .and. &
           config_flags%chem_opt /= CHEM_VASH .and. &
           config_flags%chem_opt /= CHEM_VOLC .and. &
           config_flags%chem_opt /= CHEM_VOLC_4BIN .and. &
           config_flags%chem_opt /= DUST .and. &
           config_flags%chem_opt /= CHEM_TRACE2 .and. &
           config_flags%chem_opt /= CO2_TRACER .and. &
           config_flags%chem_opt /= GHG_TRACER ) then
         call wrf_debug(15,'calling optical driver')
         IF ( do_radeffectstep ) THEN
         CALL wrf_debug(1,'chem_driver, calling optical properties for the radiative effect calculations')
         so4_switch=1
         bc_switch=0
         call optical_driver (grid%id,curr_secs,grid%dt,config_flags,haveaer,&
              chem,dz8w,rri,rh,&
              grid%h2oai,grid%h2oaj,&
              grid%tauaer1_no_bc,grid%tauaer2_no_bc,grid%tauaer3_no_bc,grid%tauaer4_no_bc,&
              grid%extaer1,grid%extaer2,grid%extaer3,grid%extaer4,&
              grid%gaer1_no_bc,grid%gaer2_no_bc,grid%gaer3_no_bc,grid%gaer4_no_bc,&
              grid%waer1_no_bc,grid%waer2_no_bc,grid%waer3_no_bc,grid%waer4_no_bc,&
              grid%bscoef1,grid%bscoef2,grid%bscoef3,grid%bscoef4,&
              grid%l2aer,grid%l3aer,grid%l4aer,grid%l5aer,grid%l6aer,grid%l7aer,&
              grid%totoa_a01,grid%totoa_a02,grid%totoa_a03,grid%totoa_a04,&
              grid%totoa_a05,grid%totoa_a06,grid%totoa_a07,grid%totoa_a08,&
              grid%extaerlw1,grid%extaerlw2,grid%extaerlw3,grid%extaerlw4,grid%extaerlw5,&
              grid%extaerlw6,grid%extaerlw7,grid%extaerlw8,grid%extaerlw9,grid%extaerlw10,&
              grid%extaerlw11,grid%extaerlw12,grid%extaerlw13,grid%extaerlw14,grid%extaerlw15,&
              grid%extaerlw16, &
              grid%tauaerlw1,grid%tauaerlw2,grid%tauaerlw3,grid%tauaerlw4,grid%tauaerlw5,&
              grid%tauaerlw6,grid%tauaerlw7,grid%tauaerlw8,grid%tauaerlw9,grid%tauaerlw10,&
              grid%tauaerlw11,grid%tauaerlw12,grid%tauaerlw13,grid%tauaerlw14,grid%tauaerlw15,&
              grid%tauaerlw16, &
              bc_switch, so4_switch, &
              ids,ide, jds,jde, kds,kde,&
              ims,ime, jms,jme, kms,kme,&
              its,ite, jts,jte, kts,kte)
         so4_switch=0
         bc_switch=1
         call optical_driver (grid%id,curr_secs,grid%dt,config_flags,haveaer,&
              chem,dz8w,rri,rh,&
              grid%h2oai,grid%h2oaj,&
              grid%tauaer1_no_so4,grid%tauaer2_no_so4,grid%tauaer3_no_so4,grid%tauaer4_no_so4,&
              grid%extaer1,grid%extaer2,grid%extaer3,grid%extaer4,&
              grid%gaer1_no_so4,grid%gaer2_no_so4,grid%gaer3_no_so4,grid%gaer4_no_so4,&
              grid%waer1_no_so4,grid%waer2_no_so4,grid%waer3_no_so4,grid%waer4_no_so4,&
              grid%bscoef1,grid%bscoef2,grid%bscoef3,grid%bscoef4,&
              grid%l2aer,grid%l3aer,grid%l4aer,grid%l5aer,grid%l6aer,grid%l7aer,&
              grid%totoa_a01,grid%totoa_a02,grid%totoa_a03,grid%totoa_a04,&
              grid%totoa_a05,grid%totoa_a06,grid%totoa_a07,grid%totoa_a08,&
              grid%extaerlw1,grid%extaerlw2,grid%extaerlw3,grid%extaerlw4,grid%extaerlw5,&
              grid%extaerlw6,grid%extaerlw7,grid%extaerlw8,grid%extaerlw9,grid%extaerlw10,&
              grid%extaerlw11,grid%extaerlw12,grid%extaerlw13,grid%extaerlw14,grid%extaerlw15,&
              grid%extaerlw16, &
              grid%tauaerlw1,grid%tauaerlw2,grid%tauaerlw3,grid%tauaerlw4,grid%tauaerlw5,&
              grid%tauaerlw6,grid%tauaerlw7,grid%tauaerlw8,grid%tauaerlw9,grid%tauaerlw10,&
              grid%tauaerlw11,grid%tauaerlw12,grid%tauaerlw13,grid%tauaerlw14,grid%tauaerlw15,&
              grid%tauaerlw16, &
              bc_switch, so4_switch, &
              ids,ide, jds,jde, kds,kde,&
              ims,ime, jms,jme, kms,kme,&
              its,ite, jts,jte, kts,kte)
         endif
         so4_switch=1
         bc_switch=1
         call optical_driver (grid%id,curr_secs,grid%dt,config_flags,haveaer, &
              chem,dz8w,rri,rh, &
              grid%h2oai,grid%h2oaj, &
              grid%tauaer1,grid%tauaer2,grid%tauaer3,grid%tauaer4, &
              grid%extaer1,grid%extaer2,grid%extaer3,grid%extaer4, &
              grid%gaer1,grid%gaer2,grid%gaer3,grid%gaer4, &
              grid%waer1,grid%waer2,grid%waer3,grid%waer4, &
              grid%bscoef1,grid%bscoef2,grid%bscoef3,grid%bscoef4, &
              grid%l2aer,grid%l3aer,grid%l4aer,grid%l5aer,grid%l6aer,grid%l7aer, &
              grid%totoa_a01,grid%totoa_a02,grid%totoa_a03,grid%totoa_a04, &
              grid%totoa_a05,grid%totoa_a06,grid%totoa_a07,grid%totoa_a08, &
              grid%extaerlw1,grid%extaerlw2,grid%extaerlw3,grid%extaerlw4,grid%extaerlw5, &
              grid%extaerlw6,grid%extaerlw7,grid%extaerlw8,grid%extaerlw9,grid%extaerlw10, &
              grid%extaerlw11,grid%extaerlw12,grid%extaerlw13,grid%extaerlw14,grid%extaerlw15, &
              grid%extaerlw16, &
              grid%tauaerlw1,grid%tauaerlw2,grid%tauaerlw3,grid%tauaerlw4,grid%tauaerlw5, &
              grid%tauaerlw6,grid%tauaerlw7,grid%tauaerlw8,grid%tauaerlw9,grid%tauaerlw10, &
              grid%tauaerlw11,grid%tauaerlw12,grid%tauaerlw13,grid%tauaerlw14,grid%tauaerlw15, &
              grid%tauaerlw16, &
              bc_switch, so4_switch,&
              ids,ide, jds,jde, kds,kde, &
              ims,ime, jms,jme, kms,kme, &
              its,ite, jts,jte, kts,kte)
      endif
      if( do_photstep .and. &
           config_flags%chem_opt /= CHEM_TRACER .and. &
           config_flags%chem_opt /= CHEM_VASH .and. &
           config_flags%chem_opt /= CHEM_VOLC .and. &
           config_flags%chem_opt /= CHEM_VOLC_4BIN .and. &
           config_flags%chem_opt /= DUST .and. &
           config_flags%chem_opt /= CHEM_TRACE2 .and. &
           config_flags%chem_opt /= CO2_TRACER .and. &
           config_flags%chem_opt /= GHG_TRACER ) then
         call wrf_debug(15,'calling photolysis driver')
         call photolysis_driver (grid%id,curr_secs,ktau,grid%dt, &
              config_flags,haveaer, &
              grid%gmt,ijulian,t_phy,moist,grid%aerwrf,p8w,t8w,p_phy, &
              chem,rho,dz8w,grid%xlat,grid%xlong, &
              z_at_w, &
              grid%gd_cloud_b,grid%gd_cloud2_b, &
              grid%ph_macr,grid%ph_o31d,grid%ph_o33p,grid%ph_no2,grid%ph_no3o2, &
              grid%ph_no3o,grid%ph_hno2,grid%ph_hno3,grid%ph_hno4,grid%ph_h2o2, &
              grid%ph_ch2or,grid%ph_ch2om,grid%ph_ch3cho,grid%ph_ch3coch3, &
              grid%ph_ch3coc2h5,grid%ph_hcocho,grid%ph_ch3cocho, &
              grid%ph_hcochest,grid%ph_ch3o2h,grid%ph_ch3coo2h,grid%ph_ch3ono2, &
              grid%ph_hcochob,grid%ph_n2o5,grid%ph_o2,grid%ph_n2o, &
              grid%ph_pan,grid%ph_mpan,grid%ph_acetol,grid%ph_gly, &
              grid%ph_open,grid%ph_mek,grid%ph_etooh,grid%ph_prooh,grid%ph_pooh, &
              grid%ph_acetp,grid%ph_xooh,grid%ph_isooh,grid%ph_alkooh, &
              grid%ph_mekooh,grid%ph_tolooh,grid%ph_terpooh,grid%ph_mvk, &
              grid%ph_glyald,grid%ph_hyac, &
              config_flags%track_tuv_lev, &
              config_flags%track_rad_num, &
              config_flags%track_tuv_num, &
              grid%radfld,grid%adjcoe,grid%phrate, &
              grid%track_wc,grid%track_zref, &
              grid%snowh, grid%snowc, grid%xice, grid%LU_INDEX, &
              grid%tauaer1,grid%tauaer2,grid%tauaer3,grid%tauaer4, &
              grid%gaer1,grid%gaer2,grid%gaer3,grid%gaer4, &
              grid%waer1,grid%waer2,grid%waer3,grid%waer4, &
              grid%bscoef1,grid%bscoef2,grid%bscoef3,grid%bscoef4, &
              grid%l2aer,grid%l3aer,grid%l4aer,grid%l5aer,grid%l6aer,grid%l7aer, &
              grid%pm2_5_dry,grid%pm2_5_water,grid%uvrad,grid%ivgtyp, &
              ids,ide, jds,jde, kds,kde, &
              ims,ime, jms,jme, kms,kme, &
              its,ite,jts,jte,kts,kte)
      endif
   DO nv=PARAM_FIRST_SCALAR,num_chem_ct
     chem_old(its:ite,kts:kte,jts:jte,nv) = chem(its:ite,kts:kte,jts:jte,chem_ct_indices(nv))
   ENDDO
      if (config_flags%vertmix_onoff>0) then
         if (ktau.gt.2) then
            call wrf_debug(15,'calling dry_deposition_driver')
            call dry_dep_driver(grid%id,curr_secs,ktau,grid%dt,config_flags, &
                 grid%gmt,ijulian,t_phy,moist,scalar,p8w,t8w,vvel, &
                 rri,p_phy,chem,tracer,rho,dz8w,rh,grid%exch_h,grid%hfx,grid%dx, &
                 grid%cldfra, grid%cldfra_old,grid%raincv_b,seasin,dustin, &
          grid%ccn1, grid%ccn2, grid%ccn3, grid%ccn4, grid%ccn5, grid%ccn6, &
                 grid%qndropsource,grid%ivgtyp,grid%tsk,grid%gsw,grid%vegfra,pbl_h, &
                 grid%rmol,grid%ust,grid%znt,grid%xlat,grid%xlong, &
                 zmid,z_at_w,grid%xland,grid%ash_fall, &
                 grid%h2oaj,grid%h2oai,grid%nu3,grid%ac3,grid%cor3,grid%asulf, &
                 grid%ahno3,grid%anh3,grid%cvaro1,grid%cvaro2,grid%cvalk1,grid%cvole1,&
                 grid%cvapi1,grid%cvapi2,grid%cvlim1,grid%cvlim2,grid%dep_vel_o3, &
                 emis_ant,ebu_in, &
                 config_flags%sf_urban_physics,numgas,current_month,dvel,grid%snowh, &
                 grid%is_CAMMGMP_used, &
                 grid%xice, grid%dry_dep_bc, &
                 grid%dep_vel,grid%num_vert_mix, &
                 ids,ide, jds,jde, kds,kde, &
                 ims,ime, jms,jme, kms,kme, &
                 its,ite,jts,jte,kts,kte)
            if( config_flags%chem_opt == MOZART_KPP .or. &
                config_flags%chem_opt == MOZCART_KPP .or. &
                config_flags%chem_opt == MOZART_MOSAIC_4BIN_VBS0_KPP ) then
               call mozcart_lbc_set( chem, num_chem, grid%id, &
                                     ims, ime, jms, jme, kms, kme, &
                                     its, ite, jts, jte, kts )
            end if
         end if
   DO nv=PARAM_FIRST_SCALAR,num_chem_ct
      grid%vmix_ct(its:ite,kts:kte,jts:jte,nv) = grid%vmix_ct(its:ite,kts:kte,jts:jte,nv) + &
                                                        (chem(its:ite,kts:kte,jts:jte,chem_ct_indices(nv)) - &
                                                     chem_old(its:ite,kts:kte,jts:jte,nv))
   ENDDO
      end if
     if( config_flags%cu_physics>0 .and. config_flags%chem_conv_tr>0 &
          .and. config_flags%cu_physics/=kfcupscheme ) then
        call wrf_debug(15,'calling conv transport for chemical species')
        if(config_flags%chem_opt >0 )then
        DO nv=PARAM_FIRST_SCALAR,num_chem_ct
           chem_old(its:ite,kts:kte,jts:jte,nv) = chem(its:ite,kts:kte,jts:jte,chem_ct_indices(nv))
        ENDDO
        call grelldrvct(grid%DT,ktau,grid%DX, &
             rho,grid%RAINCV_B,chem, &
             U_phy,V_phy,t_phy,moist,dz8w, &
             p_phy,XLV,CP,G,r_v, &
             z_at_w,grid%cu_co_ten, &
             grid%wd_no3_cu,grid%wd_so4_cu, &
             grid%k22_shallow,grid%kbcon_shallow,grid%ktop_shallow,grid%xmb_shallow, &
             config_flags%ishallow,num_moist,numgas,num_chem,config_flags%chem_opt,0, &
             config_flags%conv_tr_wetscav,config_flags%conv_tr_aqchem, &
             ids,ide, jds,jde, kds,kde, &
             ims,ime, jms,jme, kms,kme, &
             its,ite,jts,jte,kts,k_end)
             if( config_flags%chem_opt == MOZART_KPP .or. &
                 config_flags%chem_opt == MOZCART_KPP .or. &
                 config_flags%chem_opt == MOZART_MOSAIC_4BIN_VBS0_KPP ) then
                     call mozcart_lbc_set( chem, num_chem, grid%id, &
                                 ims, ime, jms, jme, kms, kme, &
                                 its, ite, jts, jte, kts )
             end if
        DO nv=PARAM_FIRST_SCALAR,num_chem_ct
          grid%conv_ct(its:ite,kts:kte,jts:jte,nv) = grid%conv_ct(its:ite,kts:kte,jts:jte,nv) + &
                                                            (chem(its:ite,kts:kte,jts:jte,chem_ct_indices(nv)) - &
                                                         chem_old(its:ite,kts:kte,jts:jte,nv))
        ENDDO
        endif
        if (config_flags%tracer_opt > 0)then
        call wrf_debug(15,'calling conv transport for tracers')
        call grelldrvct(grid%DT,ktau,grid%DX, &
             rho,grid%RAINCV_B,tracer, &
             U_phy,V_phy,t_phy,moist,dz8w, &
             p_phy,XLV,CP,G,r_v, &
             z_at_w, grid%cu_co_ten, &
             grid%wd_no3_cu,grid%wd_so4_cu, &
             grid%k22_shallow,grid%kbcon_shallow,grid%ktop_shallow,grid%xmb_shallow, &
             config_flags%ishallow,num_moist,0,num_tracer,0,config_flags%tracer_opt, &
             config_flags%conv_tr_wetscav,config_flags%conv_tr_aqchem, &
             ids,ide, jds,jde, kds,kde, &
             ims,ime, jms,jme, kms,kme, &
             its,ite,jts,jte,kts,k_end)
          end if
     end if
     n2o5_het(its:ite,kts:kte,jts:jte)=0.
     call wrf_debug(15,'calling calc_het_n2o5')
     if( do_chemstep .and. &
          config_flags%chem_opt /= CHEM_TRACER .and. &
          config_flags%chem_opt /= CHEM_VASH .and. &
          config_flags%chem_opt /= CHEM_VOLC .and. &
          config_flags%chem_opt /= CHEM_VOLC_4BIN .and. &
          config_flags%chem_opt /= DUST .and. &
          config_flags%chem_opt /= CHEM_TRACE2 .and. &
          config_flags%chem_opt /= CO2_TRACER .and. &
          config_flags%chem_opt /= GHG_TRACER ) then
   DO nv=PARAM_FIRST_SCALAR,num_chem_ct
      chem_old(its:ite,kts:kte,jts:jte,nv) = chem(its:ite,kts:kte,jts:jte,chem_ct_indices(nv))
   ENDDO
        if ( cam_mam_aerosols ) &
           del_h2so4_gasprod(:,:,:) = chem(:,:,:,p_sulf)
        if(config_flags%gaschem_onoff>0)then
          call mechanism_driver(grid%id,curr_secs,ktau,grid%dt,grid%ktauc,dtstepc,config_flags, &
              grid%gmt,ijulian,t_phy,moist,p8w,t8w,grid%gd_cldfr, &
              p_phy,chem,rho,dz8w,grid%dx,g, &
              zmid,z_at_w,grid%xlat,grid%xlong, &
              vdrog3,vcsulf_old,vcso2_old,vch2o2_old,grid%ttday,grid%tcosz, &
              grid%ph_macr,grid%ph_o31d,grid%ph_o33p,grid%ph_no2,grid%ph_no3o2, &
              grid%ph_no3o,grid%ph_hno2,grid%ph_hno3,grid%ph_hno4,grid%ph_h2o2, &
              grid%ph_ch2or,grid%ph_ch2om,grid%ph_ch3cho,grid%ph_ch3coch3, &
              grid%ph_ch3coc2h5,grid%ph_hcocho,grid%ph_ch3cocho,grid%ph_hcochest, &
              grid%ph_ch3o2h,grid%ph_ch3coo2h,grid%ph_ch3ono2,grid%ph_hcochob, &
              grid%ph_n2o5,grid%ph_o2,grid%backg_oh,grid%backg_h2o2,grid%backg_no3, &
              grid%addt,grid%addx,grid%addc,grid%etep, &
              grid%oltp,grid%olip,grid%cslp,grid%limp,grid%hc5p,grid%hc8p,grid%tolp, &
              grid%xylp,grid%apip,grid%isop,grid%hc3p,grid%ethp,grid%o3p,grid%tco3, &
              grid%mo2,grid%o1d,grid%olnn,grid%rpho,grid%xo2, &
              grid%ketp,grid%olnd, &
              ids,ide, jds,jde, kds,kde, &
              ims,ime, jms,jme, kms,kme, &
              its,ite,jts,jte,kts,kte )
         if( config_flags%chem_opt == CBMZ_MOSAIC_4BIN_VBS2_KPP .or. &
             config_flags%chem_opt == SAPRC99_MOSAIC_4BIN_VBS2_KPP .or. &
            config_flags%chem_opt ==SAPRC99_MOSAIC_8BIN_VBS2_AQ_KPP.or. &
             config_flags%chem_opt ==SAPRC99_MOSAIC_8BIN_VBS2_KPP ) then
          do k=kts,kte
           do i=its,ite
            do j=jts,jte
              chem(i,k,j,p_psd1)=0.0
              chem(i,k,j,p_psd2)=0.0
            enddo
           enddo
          enddo
         endif
   CALL wrf_debug(15,'calling kpp_mechanism_driver')
CALL kpp_mechanism_driver (chem, &
   grid%id,dtstepc,config_flags, &
   p_phy,t_phy,rho, &
   moist, &
   vdrog3, ldrog, vdrog3_vbs, ldrog_vbs, &
             grid%addt, grid%addx, grid%addc, grid%etep, &
             grid%oltp, grid%olip, grid%cslp, grid%limp, &
             grid%hc5p, grid%hc8p, grid%tolp, grid%xylp, &
             grid%apip, grid%isop, grid%hc3p, grid%ethp, &
             grid%o3p, grid%tco3, grid%mo2, grid%o1d, &
             grid%olnn, grid%olnd, grid%rpho, grid%xo2, &
             grid%ketp, grid%xno2, grid%ol2p, grid%oln, &
             grid%macp, grid%hocoo, grid%bzno2_o, grid%bz_o, &
             grid%tbu_o, &
             grid%ph_o31d, grid%ph_o33p, grid%ph_no2, grid%ph_no3o2, &
             grid%ph_no3o, grid%ph_hno2, grid%ph_hno3, grid%ph_hno4, &
             grid%ph_h2o2, grid%ph_ch2or, grid%ph_ch2om, grid%ph_ch3cho, &
             grid%ph_ch3coch3, grid%ph_ch3coc2h5, grid%ph_hcocho, grid%ph_ch3cocho, &
             grid%ph_hcochest, grid%ph_ch3o2h, grid%ph_ch3coo2h, grid%ph_ch3ono2, &
             grid%ph_hcochob, grid%ph_macr, grid%ph_n2o5, grid%ph_o2, &
             grid%ph_pan, grid%ph_acet, grid%ph_mglo, grid%ph_hno4_2, &
             grid%ph_n2o, grid%ph_pooh, grid%ph_mpan, grid%ph_mvk, &
             grid%ph_etooh, grid%ph_prooh, grid%ph_onitr, grid%ph_acetol, &
             grid%ph_glyald, grid%ph_hyac, grid%ph_mek, grid%ph_open, &
             grid%ph_gly, grid%ph_acetp, grid%ph_xooh, grid%ph_isooh, &
             grid%ph_alkooh, grid%ph_mekooh, grid%ph_tolooh, grid%ph_terpooh, &
   ids,ide, jds,jde, kds,kde, &
   ims,ime, jms,jme, kms,kme, &
   its,ite,jts,jte,kts,kte)
          if( config_flags%chem_opt == MOZART_KPP .or. &
              config_flags%chem_opt == MOZCART_KPP .or. &
              config_flags%chem_opt == MOZART_MOSAIC_4BIN_VBS0_KPP ) then
             call mozcart_lbc_set( chem, num_chem, grid%id, &
                                   ims, ime, jms, jme, kms, kme, &
                                    its, ite, jts, jte, kts )
          end if
    if(config_flags%chem_opt == 301 ) then
       chem(its:ite,kts:kte,jts:jte,p_sulf)=vcsulf_old(its:ite,kts:kte,jts:jte)
       chem(its:ite,kts:kte,jts:jte,p_so2)=vcso2_old(its:ite,kts:kte,jts:jte)
   endif
   IF(config_flags%conv_tr_aqchem == 0 ) THEN
      so2so4_selecta: SELECT CASE(config_flags%chem_opt)
      CASE (RADM2SORG,RADM2SORG_KPP,RACMSORG_KPP,RACM_SOA_VBS_KPP)
         CALL wrf_debug(15,'gocart so2-so4 conversion')
         CALL so2so4(0,chem,p_so2,p_sulf,p_h2o2,p_QC,T_PHY,MOIST, &
              grid%gd_cloud_b, grid%gd_cldfr, &
              NUM_CHEM,NUM_MOIST, &
              ids,ide, jds,jde, kds,kde, &
              ims,ime, jms,jme, kms,kme, &
              its,ite, jts,jte, kts,kte )
      CASE DEFAULT
         CALL wrf_debug(15,'no gocart so2-so4 conversion')
      END SELECT so2so4_selecta
   else IF(config_flags%conv_tr_aqchem == 1 ) THEN
      so2so4_selectb: SELECT CASE(config_flags%chem_opt)
      CASE (RADM2SORG,RADM2SORG_KPP,RACMSORG_KPP,RACM_SOA_VBS_KPP)
         CALL wrf_debug(15,'gocart so2-so4 conversion')
         CALL so2so4(1,chem,p_so2,p_sulf,p_h2o2,p_QC,T_PHY,MOIST, &
              grid%gd_cloud_b, grid%gd_cldfr, &
              NUM_CHEM,NUM_MOIST, &
              ids,ide, jds,jde, kds,kde, &
              ims,ime, jms,jme, kms,kme, &
              its,ite, jts,jte, kts,kte )
      CASE DEFAULT
         CALL wrf_debug(15,'no gocart so2-so4 conversion')
      END SELECT so2so4_selectb
   ENDIF
        endif
   DO nv=PARAM_FIRST_SCALAR,num_chem_ct
      grid%chem_ct(its:ite,kts:kte,jts:jte,nv) = grid%chem_ct(its:ite,kts:kte,jts:jte,nv) + &
                                                        (chem(its:ite,kts:kte,jts:jte,chem_ct_indices(nv)) - &
                                                     chem_old(its:ite,kts:kte,jts:jte,nv))
   ENDDO
if ( cam_mam_aerosols ) &
           del_h2so4_gasprod(:,:,:) = chem(:,:,:,p_sulf) - del_h2so4_gasprod(:,:,:)
        if ( (config_flags%cldchem_onoff > 0) .or. &
             (config_flags%wetscav_onoff > 0) ) then
            gas_aqfrac(its:ite,kts:kte,jts:jte,:) = 0.0
        end if
        if (((config_flags%chem_opt == CBMZ_CAM_MAM3_NOAQ) .or. &
             (config_flags%chem_opt == CBMZ_CAM_MAM3_AQ ) .or. &
             (config_flags%chem_opt == CBMZ_CAM_MAM7_NOAQ) .or. &
             (config_flags%chem_opt == CBMZ_CAM_MAM7_AQ )).and. &
             (config_flags%cu_physics == CAMZMSCHEME)) then
           call cam_mam_gas_wetdep_driver( &
                chem, &
                dtstepc, config_flags, grid%ht,grid%XLAT, &
                grid%nevapr3d, grid%rprdsh, &
                grid%rprddp3d, grid%prain3d, grid%z, &
                p_phy, t_phy, grid%alt, moist, scalar, &
                ids,ide, jds,jde, kds,kde, &
                ims,ime, jms,jme, kms,kme, &
                its,ite, jts,jte, kts,kte )
        endif
        if( config_flags%chem_conv_tr>0 .and. &
             config_flags%cu_physics==kfcupscheme ) then
           call chem_cup_driver( &
                grid%id, ktau, grid%ktauc, grid%dt, dtstepc, config_flags, &
                t_phy, p_phy, rho, rri, dz8w, zmid, z_at_w, &
                moist, grid%cldfra, grid%ph_no2, &
                chem, grid%chem_cupflag, &
                grid%cupflag, grid%shall, grid%tcloud_cup, grid%nca, grid%wact_cup, &
                grid%cldfra_cup, grid%updfra_cup, grid%qc_ic_cup, grid%qc_iu_cup, &
                grid%mfup_cup, grid%mfup_ent_cup, grid%mfdn_cup, grid%mfdn_ent_cup, &
                grid%fcvt_qc_to_pr_cup, grid%fcvt_qc_to_qi_cup, grid%fcvt_qi_to_pr_cup, &
                grid%co_a_ic_cup, grid%hno3_a_ic_cup, &
                grid%so4_a_1to4_ic_cup, grid%so4_cw_1to4_ic_cup, &
                grid%nh4_a_1to4_ic_cup, grid%nh4_cw_1to4_ic_cup, &
                grid%no3_a_1to4_ic_cup, grid%no3_cw_1to4_ic_cup, &
                grid%oa_a_1to4_ic_cup, grid%oa_cw_1to4_ic_cup, &
                grid%oin_a_1to4_ic_cup, grid%oin_cw_1to4_ic_cup, &
                grid%bc_a_1to4_ic_cup, grid%bc_cw_1to4_ic_cup, &
                grid%na_a_1to4_ic_cup, grid%na_cw_1to4_ic_cup, &
                grid%cl_a_1to4_ic_cup, grid%cl_cw_1to4_ic_cup, &
                grid%water_1to4_ic_cup, &
                grid%so4_a_5to6_ic_cup, grid%so4_cw_5to6_ic_cup, &
                grid%nh4_a_5to6_ic_cup, grid%nh4_cw_5to6_ic_cup, &
                grid%no3_a_5to6_ic_cup, grid%no3_cw_5to6_ic_cup, &
                grid%oa_a_5to6_ic_cup, grid%oa_cw_5to6_ic_cup, &
                grid%oin_a_5to6_ic_cup, grid%oin_cw_5to6_ic_cup, &
                grid%bc_a_5to6_ic_cup, grid%bc_cw_5to6_ic_cup, &
                grid%na_a_5to6_ic_cup, grid%na_cw_5to6_ic_cup, &
                grid%cl_a_5to6_ic_cup, grid%cl_cw_5to6_ic_cup, &
                grid%water_5to6_ic_cup, &
                grid%wet_dep_bc, &
                ids,ide, jds,jde, kds,kde, &
                ims,ime, jms,jme, kms,kme, &
                its,ite, jts,jte, kts,kte )
        else
           grid%chem_cupflag = 0
        endif
        if (config_flags%cldchem_onoff > 0) then
        call cloudchem_driver( &
               grid%id, ktau, grid%ktauc, grid%dt, dtstepc, config_flags, &
               t_phy, p_phy, rho, rri, dz8w, &
               p8w,grid%prain3d,scalar,grid%dvmrdt_sv13d,grid%dvmrcwdt_sv13d, grid%f_ice_phy, &
               grid%f_rain_phy,grid%cldfrai, grid%cldfral, &
               moist, grid%cldfra, grid%cldfra_mp_all, grid%ph_no2, &
               chem, gas_aqfrac, numgas_mam,grid%is_CAMMGMP_used, &
               ids,ide, jds,jde, kds,kde, &
               ims,ime, jms,jme, kms,kme, &
               its,ite, jts,jte, kts,kte )
       endif
 if(config_flags%aerchem_onoff>0)then
        call aerosols_driver (grid%id,curr_secs,ktau,grid%dt,grid%ktauc, &
             config_flags,dtstepc,grid%dx, &
              rri,t_phy,moist,grid%aerwrf,p8w,t8w, &
              p_phy,chem,rho,dz8w, rh, &
              zmid,z_at_w,pbl_h,grid%cldfra,grid%cldfra_mp_all,grid%vbs_nbin, &
              grid%h2oaj,grid%h2oai,grid%nu3,grid%ac3,grid%cor3,grid%asulf, &
              grid%ahno3,grid%anh3,grid%cvaro1,grid%cvaro2,grid%cvalk1,grid%cvole1, &
              grid%cvapi1,grid%cvapi2,grid%cvlim1,grid%cvlim2,vcsulf_old, &
              vdrog3,vdrog3_vbs,grid%br_rto,grid%dgnum4d,grid%dgnumwet4d,wetdens_ap, &
              del_h2so4_gasprod,grid%dvmrdt_sv13d,grid%dvmrcwdt_sv13d, &
              grid%is_CAMMGMP_used, &
              ids,ide, jds,jde, kds,kde, &
              ims,ime, jms,jme, kms,kme, &
              its,ite,jts,jte,kts,kte )
       endif
 if (config_flags%wetscav_onoff > 0) then
        call wetscav_driver (grid%id,ktau,grid%dt,grid%ktauc,config_flags,dtstepc, &
              rri,t_phy,moist,p8w,t8w, &
              grid%dx, grid%dy, &
              p_phy,chem,rho,grid%cldfra,grid%cldfra2, &
              grid%rainprod,grid%evapprod,grid%hno3_col_mdel, &
              grid%qlsink,grid%precr,grid%preci,grid%precs,grid%precg, &
              grid%cldfra_cup, grid%precr_cup, grid%preci_cup, &
              gas_aqfrac, numgas_mam,dz8w, &
              grid%h2oaj,grid%h2oai,grid%nu3,grid%ac3,grid%cor3, &
              grid%asulf,grid%ahno3,grid%anh3,grid%cvaro1,grid%cvaro2, &
              grid%cvalk1,grid%cvole1,grid%cvapi1,grid%cvapi2, &
              grid%cvlim1,grid%cvlim2, &
              grid%wd_no3_sc,grid%wd_so4_sc, &
              grid%qv_b4mp, grid%qc_b4mp, grid%qi_b4mp, grid%qs_b4mp, &
              grid%p_hyd,scalar,grid%dgnum4d,grid%dgnumwet4d,grid%dlf,grid%dlf2, &
              grid%qme3d,grid%prain3d,grid%nevapr3d,grid%rate1ord_cw2pr_st3d, &
              grid%shfrc3d,grid%cmfmc,grid%cmfmc2,grid%evapcsh,grid%icwmrsh, &
              grid%rprdsh,grid%evapcdp3d,grid%icwmrdp3d,grid%rprddp3d,grid%fracis3d, &
              grid%f_ice_phy,grid%f_rain_phy,grid%cldfrai,grid%cldfral, &
              grid%cldfra_mp_all,grid%is_CAMMGMP_used, &
              grid%wet_dep_bc, &
              ids,ide, jds,jde, kds,kde, &
              ims,ime, jms,jme, kms,kme, &
              its,ite, jts,jte, kts,kte)
       endif
       if (((config_flags%chem_opt == CBMZ_CAM_MAM3_NOAQ) .or. &
            (config_flags%chem_opt == CBMZ_CAM_MAM3_AQ ) .or. &
            (config_flags%chem_opt == CBMZ_CAM_MAM7_NOAQ) .or. &
            (config_flags%chem_opt == CBMZ_CAM_MAM7_AQ )).and. &
            (config_flags%cu_physics == CAMZMSCHEME)) then
          call zm_conv_tend_2(grid%itimestep, grid%dt, p8w, grid%fracis3d, grid%dp3d, &
               grid%du3d, grid%ed3d, grid%eu3d, grid%md3d, grid%mu3d, grid%dsubcld2d, &
               grid%ideep2d, grid%jt2d, grid%maxg2d, grid%lengath2d, moist, scalar, chem,&
               ids,ide, jds,jde, kds,kde, &
               ims,ime, jms,jme, kms,kme, &
               its,ite, jts,jte, kts,kte)
       endif
end if
        if(config_flags%chem_opt == CHEM_VOLC)then
          CALL wrf_debug(15,'gocart so2-so4 conversion')
          CALL so2so4(0,chem,p_so2,p_sulf,p_h2o2,p_QC,T_PHY,MOIST, &
         grid%gd_cloud_b, grid%gd_cldfr, &
         NUM_CHEM,NUM_MOIST, &
         ids,ide, jds,jde, kds,kde, &
         ims,ime, jms,jme, kms,kme, &
         its,ite, jts,jte, kts,kte )
        endif
        if(config_flags%wetscav_onoff<0)then
           call wrf_debug(15,'calculate LS wet deposition')
           call wetdep_ls(grid%dt,chem,grid%rainncv,moist,rho,num_moist, &
                num_chem,numgas,dz8w,vvel,grid%chem_opt, &
                ids,ide, jds,jde, kds,kde, &
                ims,ime, jms,jme, kms,kme, &
                its,ite, jts,jte, kts,kte )
         endif
      call sum_pm_driver( config_flags, &
        rri, chem, grid%h2oaj, grid%h2oai, &
        grid%pm2_5_dry, grid%pm2_5_water, grid%pm2_5_dry_ec, grid%pm10, &
        grid%hoa_a01, grid%hoa_a02, grid%hoa_a03, grid%hoa_a04, &
        grid%hoa_a05, grid%hoa_a06, grid%hoa_a07, grid%hoa_a08, &
        grid%bboa_a01, grid%bboa_a02, grid%bboa_a03, grid%bboa_a04, &
        grid%bboa_a05, grid%bboa_a06, grid%bboa_a07, grid%bboa_a08, &
        grid%soa_a01, grid%soa_a02, grid%soa_a03, grid%soa_a04, &
        grid%soa_a05, grid%soa_a06, grid%soa_a07, grid%soa_a08, &
        grid%bbsoa_a01, grid%bbsoa_a02, grid%bbsoa_a03, grid%bbsoa_a04, &
        grid%bbsoa_a05, grid%bbsoa_a06, grid%bbsoa_a07, grid%bbsoa_a08, &
        grid%hsoa_a01, grid%hsoa_a02, grid%hsoa_a03, grid%hsoa_a04, &
        grid%hsoa_a05, grid%hsoa_a06, grid%hsoa_a07, grid%hsoa_a08, &
        grid%biog_a01, grid%biog_a02, grid%biog_a03, grid%biog_a04, &
        grid%biog_a05, grid%biog_a06, grid%biog_a07, grid%biog_a08, &
        grid%asmpsoa_a01, grid%asmpsoa_a02, grid%asmpsoa_a03, grid%asmpsoa_a04, &
        grid%arosoa_a01, grid%arosoa_a02, grid%arosoa_a03, grid%arosoa_a04, &
        grid%arosoa_a05, grid%arosoa_a06, grid%arosoa_a07, grid%arosoa_a08, &
        grid%totoa_a01, grid%totoa_a02, grid%totoa_a03, grid%totoa_a04, &
        grid%totoa_a05, grid%totoa_a06, grid%totoa_a07, grid%totoa_a08, &
        grid%hsoa_c, grid%hsoa_o, grid%bbsoa_c, grid%bbsoa_o, &
        grid%biog_v1, grid%biog_v2, grid%biog_v3, grid%biog_v4, &
        grid%ant_v1, grid%ant_v2, grid%ant_v3, grid%ant_v4, &
        grid%smpa_v1, grid%smpbb_v1, &
        grid%hoa_cw01, grid%hoa_cw02, grid%hoa_cw03, grid%hoa_cw04, &
        grid%hoa_cw05, grid%hoa_cw06, grid%hoa_cw07, grid%hoa_cw08, &
        grid%bboa_cw01, grid%bboa_cw02, grid%bboa_cw03, grid%bboa_cw04, &
        grid%bboa_cw05, grid%bboa_cw06, grid%bboa_cw07, grid%bboa_cw08, &
        grid%soa_cw01, grid%soa_cw02, grid%soa_cw03, grid%soa_cw04, &
        grid%soa_cw05, grid%soa_cw06, grid%soa_cw07, grid%soa_cw08, &
        grid%bbsoa_cw01, grid%bbsoa_cw02, grid%bbsoa_cw03, grid%bbsoa_cw04, &
        grid%bbsoa_cw05, grid%bbsoa_cw06, grid%bbsoa_cw07, grid%bbsoa_cw08, &
        grid%biog_cw01, grid%biog_cw02, grid%biog_cw03, grid%biog_cw04, &
        grid%biog_cw05, grid%biog_cw06, grid%biog_cw07, grid%biog_cw08, &
        grid%hsoa_cw01, grid%hsoa_cw02, grid%hsoa_cw03, grid%hsoa_cw04, &
        grid%hsoa_cw05, grid%hsoa_cw06, grid%hsoa_cw07, grid%hsoa_cw08, &
        grid%arosoa_cw01, grid%arosoa_cw02, grid%arosoa_cw03, grid%arosoa_cw04, &
        grid%arosoa_cw05, grid%arosoa_cw06, grid%arosoa_cw07, grid%arosoa_cw08, &
        grid%totoa_cw01, grid%totoa_cw02, grid%totoa_cw03, grid%totoa_cw04, &
        grid%totoa_cw05, grid%totoa_cw06, grid%totoa_cw07, grid%totoa_cw08, &
        grid%hsoa_cw_c, grid%hsoa_cw_o, grid%bbsoa_cw_c, grid%bbsoa_cw_o, &
        grid%biog_cw_v1, &
        grid%ant_cw_v1, &
        ids,ide, jds,jde, kds,kde, &
        ims,ime, jms,jme, kms,kme, &
        its,ite, jts,jte, kts,kte )
      do nv=1,num_chem
         do j=jts,jte
            do i=its,ite
                  chem(i,k_end,j,nv)=chem(i,kte,j,nv)
            enddo
         enddo
      enddo
      call wrf_debug(15,'done tileloop in chem_driver')
   if( grid%OPT_PARS_OUT == 1) then
      call wrf_debug(15,'calculate optical output stuff')
    call aer_opt_out(TAUAER300=grid%tauaer1, TAUAER400=grid%tauaer2 &
     & ,TAUAER600=grid%tauaer3, TAUAER999=grid%tauaer4 &
     & ,GAER300=grid%gaer1, GAER400=grid%gaer2, GAER600=grid%gaer3, GAER999=grid%gaer4 &
     & ,WAER300=grid%waer1, WAER400=grid%waer2, WAER600=grid%waer3, WAER999=grid%waer4 &
              ,ext_coeff=grid%ext_coef,bscat_coeff=grid%bscat_coef,asym_par=grid%asym_par &
              ,num_ext_coef=num_ext_coef,num_bscat_coef=num_bscat_coef,num_asym_par=num_asym_par &
     & ,dz8w=dz8w &
     & ,IDS=ids,IDE=ide, JDS=jds,JDE=jde, KDS=kds,KDE=kde &
     & ,IMS=ims,IME=ime, JMS=jms,JME=jme, KMS=kms,KME=kme &
     & ,its=its,ite=ite,jts=jts,jte=jte,kts=kts, kte=kte)
   endif
   tracer2: SELECT CASE(config_flags%tracer_opt)
    CASE (TRACER_TEST1, TRACER_TEST2, TRACER_TEST3)
       CALL wrf_debug(15,'tracer mode: reset some tracers')
       call set_tracer(grid%dt,ktau,pbl_h,tracer,t_phy, &
                        config_flags%tracer_opt,num_tracer, &
                       zmid,grid%ht,ids,ide, jds,jde, kds,kde, &
                               ims,ime, jms,jme, kms,kme, &
                               its,ite, jts,jte, kts,kte )
   END SELECT tracer2
    if( config_flags%have_bcs_upper )then
       call wrf_debug(15,'set upper boundary condition')
       call tropopause_driver( grid%id, grid%dt, current_date_char, &
                               t_phy, p_phy, p8w, zmid, z_at_w, &
                               grid%tropo_lev, grid%tropo_p, grid%tropo_z, &
                               ids, ide, jds, jde, kds, kde, &
                               ims, ime, jms, jme, kms, kme, &
                               its, ite, jts, jte, kts, kte )
       call upper_bc_driver ( grid%id, grid%dt, current_date_char, &
                               chem, p_phy, p8w, grid%tropo_lev, &
                               ids,ide, jds,jde, kds,kde, &
                               ims,ime, jms,jme, kms,kme, &
                               its,ite, jts,jte, kts,kte )
    endif
   END DO chem_tile_loop_1
    END subroutine chem_driver


	subroutine ad_cal(inunit,outshort,outunit,ifile,file$,
     $            ical_no,signumber,
     $		ref_volt,equiv_db,equiv_press,dcoffset,
     $          sample_rate,ierr)
c
c file$ passed in as 80 characters - BMS Aug 23 2004
c corrected call to read_it - wrong number of arguments - BMS July 8 2004
c read ref_volt and equiv_db from open_mat_file - BMS Nov 18 2002
c return sample rate (read from Matlab file, if nowhere else) - BMS Aug 26 2002
c Also to open the Matlab file for reborn booth version- BMS Aug 21 2002
c program to calibrate the system for adloud
c                                             BMS June 26 1990
c change calling parameters of read_ad_header      Feb 12 1992
c Add BOOMFILE option (already in PSF) - Dec 2 1993

c	INPUT
c             inunit = logical unit for input data
c            outshort = logical unit for shortform output data
c            outunit = logical unit for longform output data
c	       ifile = 1 for A/D (one file for cal & signals)
c	               2 for D/A (separate files)
c	               3 for WSMR data

c	OUTPUT
c	       file$ = file name (for A/D file, this may be usefull)
c	   signumber = number of signals in file (not including cals.)
c	     ical_no = aquisition number in A/D file for cal_tone (iskip)
c	    ref_volt = reference voltage for calibration level
c	    equiv_db = pressure level equivalent (in dB) to ref_volt
c	 equiv_press = pressure level equivalent (in Pascals) to ref_volt
c           dcoffset = D.C. offset for cal. tone
c	        ierr = error flag (o is good)

c the READ routines read into the standard PLAYBOOM arrays
	include 'sigpair_big.inc'

	integer inunit,signumber,outunit,outshort
	logical lseq,ltype,lme

	character*80 file$,name$

c reference pressure in Pascals (which is what SUBF7X works in)
	real pzero
	data pzero /20.0e-6/

	real sample_rate

	ierr = 0

	if (ifile .eq. 7 .or. ifile .eq. 8) then
	   ref_volt = 1.002
	   equiv_db = 94.0
	else if (ifile .ne. 1) then
	   print *,' '
	   print *,' Enter the reference voltage and equivalent dB level'
	   print *,' or enter zeros to use a cal. tone file'
	   accept *,ref_volt,equiv_db
	   print *,' '
	   if (ref_volt .eq. 0.0) then
 100	      print *,' Enter file name holding the cal. tone'
	      read (*,'(a)') file$
	      slevel = 1.
	      cal_fac = 1.
	      iwhich = 0
	      call read_it(inunit,file$,slevel,cal_fac,iwhich,
     1		signal,isignal,number,srate,adjust,isize_sigpair,ierr)
	      if (ierr .ne. 0) then
	         print *,' ******* Error reading cal. signal *******'
	         print *,' Try another name'
	         go to 100
	      endif
	      call sub_ref(outunit,signal,number,srate,ref_volt,equiv_db,
     $				dcoffset,ierr)
	   endif
	else
c it was all in one file but I can't see how to handle that now.
 300	   print *,' Enter Matlab file name holding the data'
	   read (*,'(a)') file$
	   iclose = 0
	   call open_mat_file(sample_rate,ref_volt,equiv_db,file$,ierr)
	print *,sample_rate
	print *,ref_volt
	print *,equiv_db

c	   call read_ad_header(file$,inunit,outshort,outunit,
c     @				iclose,lseq,ltype,lme,signumber,ierr)
	   if (ierr .ne. 0) go to 300
	   print *,' '
c	   print *,' Enter the aquisition number for the cal. tone'
c	   print *,' or zero to enter the reference level'
c	   accept *,ical_no
c	   print *,' '
c	   if (ical_no .eq. 0) then
c	      print *,' Enter the reference voltage and equivalent dB level'
c	      accept *,ref_volt,equiv_db
	      ical_no=-1
c	   else
c
c we've only just opened the file so we skip from the start to the
c required aquisition (iskip = ical_no)
c	      call read_ad(inunit,outunit,0,ical_no,number,srate,name$,ierr)
c	      call sub_ref(outunit,signal,number,srate,ref_volt,equiv_db,
c     $				dcoffset,ierr)
c	   endif
	endif

c ref_volt is equivalent to equiv_db.
c What's that in Pascals?
c 0 dB = pzero pascals
	equiv_press = pzero * 10.**(equiv_db/20.)

	print *,' '
	print *, ref_volt,equiv_db,equiv_press

	return
	end