1 MODULE module_cam_support
2 !------------------------------------------------------------------------
3 ! This module contains global scope variables and routines shared by
4 ! multiple CAM physics routines. As much as possible, the codes is copied
5 ! verbatim from the corresponding CAM modules noted below.
7 ! Author: William.Gustafson@pnl.gov, Nov 2009
8 !------------------------------------------------------------------------
9 use module_state_description, only: param_num_moist
17 integer(SHR_KIND_IN),parameter,private :: R8 = SHR_KIND_R8 ! rename for local readability only
19 ! From spmd_utils in CAM...
20 logical, parameter :: masterproc = .TRUE.
21 logical, parameter :: iam = .FALSE.
23 ! From ppgrid in CAM...
24 integer, parameter :: pcols = 1 !Always have a chunk size of 1 in WRF
25 integer :: pver !Number of model level middles in CAM speak
26 integer :: pverp !Number of model level interfaces in CAM speak
28 ! From constituents in CAM...
29 integer, parameter :: pcnst = param_num_moist !Number of tracer constituents for CAM q array
30 !In WRF this is currently setup to only handle
31 !the moist array, and then even in a half-handed way.
32 !We allocate the max possible size, but loops need to
33 !be over a smaller number.
34 !Scalar and chem need to eventually be handled too.
36 ! 2010-06-16 rce - about pcnst ...
37 ! in CAM with modal aerosols, pcnst = 5 (water vapor + cloud water/ice mass/number) +
38 ! number of trace gas and aerosol species
39 ! if we want to do things similarly in wrfchem, then we should have pcnst = 5 + num_chem,
40 ! which means that pcnst is set at runtime,
41 ! which means that any saved arrays (i.e. module data) need to be allocated
42 ! OR, we could use a bunch of CPP directives to produce the appropriate constant value
44 ! for now (temporarily), the following will be used in modal aerosol routines
45 ! its appropriate value must be set in an initialization routine,
46 ! and the initial -999888777 should cause code to crash if it gets used
47 ! before being set correctly
49 !Balwinder.Singh@pnnl.gov: pcnst is now defined dynamically in module_physics_init.F. pcnst_runtime
50 !is referenced by pcnst for getting the runtime (dynamic) value of pcnst. TO accomplish this,
51 !all 'module level' or 'saved' arrays are declared 'allocatable' in CAM specific modules. The
52 !allocatable arrays are allocated in the 'initialization' call of the respective module. If a module
53 !doesn't have an 'initialization' subroutine then allocatable arrays are allocated in module_physics_init.F.
54 !Allocatable CAM arrays which are NOT currently used by WRF are not allocated
56 integer :: pcnst_runtime = -999888777 !Number of tracer constituents in CAM q array
58 !For assisting decoupled microphysics (MP) CAM MAM simulations (simulations, where MAM package is coupled with
59 !radiation but decoupled with MP- i.e. MP runs with 'prescribed' aerosols) 'pcnst_mp' is defined.'pcnst_mp' will
60 !only be used in the CAMMGMP driver and its supporting modules (ndrop and microp_aero)
61 integer :: pcnst_mp = -999888777
63 integer :: gas_pcnst_modal_aero = -999888777 !Number of tracer constituents in CAM q array
65 !BSINGH - In simulations where no MAM chem package (501, 502,503 or 504) is used,
66 ! following integer(gas_pcnst_modal_aero_pos) is used to specify array dimensions,
67 ! so it has to have a positive value. It will assume a positive value in chemistry
68 ! initializations accordling to the chem package specified in the namelist
69 integer :: gas_pcnst_modal_aero_pos = -999888777 !Number of tracer constituents in CAM q array
71 ! excluding water vapor, cloud water, cloud ice, droplet number, ice number
73 integer :: pcnst_non_chem_modal_aero = -999888777 !Number of non-chemistry (i.e., moisture) species in CAM q array
76 character(len=750) :: iulog !In CAM this is a file handle. In WRF, this is a string
77 !that can be used to send messages via wrf_message, etc.
79 !From cam_pio_utils.F90
80 integer, parameter, public :: phys_decomp=100
82 ! From cam_pio_utils (used in camuwpbl_driver module)...
83 integer, parameter :: fieldname_len = 16 ! max chars for field name
85 !From chem_mods (dummy value for now)
86 integer, parameter :: nfs = -999888777 !Balwinder.Singh@pnnl.gov: NFS is not used for any meaningful computations for now
88 !From cam_history_support.F90
89 real(r8), parameter, public :: fillvalue = 1.e36_r8 ! fill value for netcdf fields
92 !For module_cam_mam_gas_wetdep_driver.F
93 !BSINGH - We are going to operate on only 6 gases (following MOSAIC -
94 !module_mosaic_wetscav.F). MOSAIC actually operates upon 7 gases but MAM
95 !doesn't have msa, therefore MAM will operate on only 6 gases
97 !so2,h2o2,h2so4,hno3,hcl,nh3 (msa not included)
99 integer, public, parameter :: gas_wetdep_cnt = 6
100 character(len=3), public, parameter :: gas_wetdep_method = 'MOZ'
101 !BSINGH - Following list should be all UPPER CASE and 'sulf' should be replaced with 'H2SO4'
102 character(len=5), public, parameter :: gas_wetdep_list(1:gas_wetdep_cnt) = (/'SO2 ','H2O2 ','H2SO4','HNO3 ','HCL ','NH3 '/) !Upper Case
104 !BSINGH:01/31/2013 - numgas_mam is being used for specifying a variable dimension in che_driver
105 !This variable is *UPDATED* in chemics_init.F, where it is assigned a new value based
106 !on number of gases being used in the simulation
107 integer :: numgas_mam = 1
109 !BSINGH:02/01/2013 - Define cam_mam_aerosol to know if the simulation is a mam simulation or not
110 ! This variable is updated in module_physics_init.F
111 logical :: cam_mam_aerosols = .FALSE.
114 !------------------------------------------------------------------------
116 !------------------------------------------------------------------------
117 subroutine lower_case( txt_in, txt_lc )
119 ! converts a character string (txt_in) to lowercase (txt_lc)
123 character(len=*), intent(in) :: txt_in
124 character(len=*), intent(out) :: txt_lc
127 integer, parameter :: iachar_lowera = iachar('a')
128 integer, parameter :: iachar_uppera = iachar('A')
129 integer, parameter :: iachar_upperz = iachar('Z')
132 do i = 1, len( trim(txt_lc) )
133 j = iachar( txt_lc(i:i) )
134 if (j < iachar_uppera) cycle
135 if (j > iachar_upperz) cycle
136 txt_lc(i:i) = achar( j + iachar_lowera - iachar_uppera )
140 end subroutine lower_case
143 !------------------------------------------------------------------------
144 SUBROUTINE endrun(msg)
145 ! Pass through routine to wrf_error_fatal that mimics endrun in module
148 ! Replaces endrun in abortutils module in CAM.
150 ! Author: William.Gustafson@pnl.gov, Nov 2009
151 ! Modified : Balwinder.Singh@pnl.gov - Argument made optional
152 !------------------------------------------------------------------------
155 ! Argument of the subroutine is made optional to accomodate endrun calls with no argument
156 character(len=*), intent(in), optional :: msg
158 if(present(msg)) then
159 call wrf_error_fatal(msg)
161 ! The error message is written to iulog before the endrun call
162 call wrf_error_fatal(iulog)
165 END SUBROUTINE endrun
169 !------------------------------------------------------------------------
170 SUBROUTINE t_stopf(event)
171 ! Stub to accomodate stop time calls of CAM
173 ! Replaces t_stopf in perf_mod module in CAM.
175 ! Author: Balwinder.Singh@pnl.gov
176 !------------------------------------------------------------------------
177 character(len=*), intent(in) :: event
179 END SUBROUTINE t_stopf
183 !------------------------------------------------------------------------
184 SUBROUTINE t_startf(event)
185 ! Stub to accomodate start time calls of CAM
187 ! Replaces t_startf in perf_mod module in CAM.
189 ! Author: Balwinder.Singh@pnl.gov
190 !------------------------------------------------------------------------
192 character(len=*), intent(in) :: event
194 END SUBROUTINE t_startf
198 !------------------------------------------------------------------------
199 SUBROUTINE outfld( fname, field, idim, c)
200 ! Stub to accomodate outfld calls of CAM
202 ! Replaces outfld in cam_history module in CAM.
204 ! Author: Balwinder.Singh@pnl.gov
205 !------------------------------------------------------------------------
206 character(len=*), intent(in) :: fname
207 integer, intent(in) :: idim
208 integer, intent(in) :: c
209 real(r8), intent(in) :: field(idim,*)
211 END SUBROUTINE outfld
215 !------------------------------------------------------------------------
216 SUBROUTINE addfld(fname, units, numlev, avgflag, long_name, &
217 decomp_type, flag_xyfill, flag_isccplev, sampling_seq)
218 ! Stub to accomodate addfld calls of CAM
220 ! Replaces addfld in cam_history module in CAM.
222 ! Author: Balwinder.Singh@pnl.gov
223 !------------------------------------------------------------------------
224 character(len=*), intent(in) :: fname
225 character(len=*), intent(in) :: units
226 character(len=1), intent(in) :: avgflag
227 character(len=*), intent(in) :: long_name
229 integer, intent(in) :: numlev
230 integer, intent(in) :: decomp_type
232 logical, intent(in), optional :: flag_xyfill
233 logical, intent(in), optional :: flag_isccplev
234 character(len=*), intent(in), optional :: sampling_seq
236 END SUBROUTINE ADDFLD
240 !------------------------------------------------------------------------
241 SUBROUTINE ADD_DEFAULT (name, tindex, flag)
243 ! Stub to accomodate add_default calls of CAM
244 ! Relaces add_default in cam_history module of CAM
246 ! Author: Balwinder.Singh@pnl.gov
247 !-----------------------------------------------------------------------
248 character(len=*), intent(in) :: name ! field name
249 character(len=1), intent(in) :: flag ! averaging flag
251 integer, intent(in) :: tindex ! history tape index
253 END SUBROUTINE ADD_DEFAULT
255 END MODULE module_cam_support