1 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2 ! MODULE GRIDINFO_MODULE
4 ! This module handles (i.e., acquires, stores, and makes available) all data
5 ! describing the model domains to be processed.
6 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
9 use misc_definitions_module
13 integer, parameter :: MAX_DOMAINS = 21
16 integer :: interval_seconds, max_dom, io_form_input, io_form_output, debug_level
17 integer, dimension(MAX_DOMAINS) :: subgrid_ratio_x, subgrid_ratio_y
18 integer :: process_only_bdy
19 character (len=MAX_FILENAME_LEN) :: opt_output_from_geogrid_path, &
20 opt_output_from_metgrid_path, opt_metgrid_tbl_path
21 character (len=128), dimension(MAX_DOMAINS) :: start_date, end_date
22 character (len=MAX_FILENAME_LEN), dimension(MAX_DOMAINS) :: fg_name, constants_name
23 logical :: do_tiled_input, do_tiled_output, nocolons
24 logical, dimension(MAX_DOMAINS) :: grid_is_active
25 character (len=1) :: gridtype
29 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
30 ! Name: get_namelist_params
32 ! Purpose: Read namelist parameters.
33 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
34 subroutine get_namelist_params()
39 integer :: i, io_form_geogrid, io_form_metgrid
40 integer, dimension(MAX_DOMAINS) :: start_year, start_month, start_day, start_hour, start_minute, start_second, &
41 end_year, end_month, end_day, end_hour, end_minute, end_second
42 logical, dimension(MAX_DOMAINS) :: active_grid
45 character (len=3) :: wrf_core
47 namelist /share/ wrf_core, max_dom, start_date, end_date, &
48 start_year, end_year, start_month, end_month, &
49 start_day, end_day, start_hour, end_hour, &
50 start_minute, end_minute, start_second, end_second, &
51 interval_seconds, io_form_geogrid, opt_output_from_geogrid_path, &
52 debug_level, active_grid, nocolons, &
53 subgrid_ratio_x, subgrid_ratio_y
54 namelist /metgrid/ io_form_metgrid, fg_name, constants_name, process_only_bdy, opt_output_from_metgrid_path, &
66 constants_name(i) = '*'
79 start_date(i) = '0000-00-00_00:00:00'
80 end_date(i) = '0000-00-00_00:00:00'
81 active_grid(i) = .true.
82 subgrid_ratio_x(i) = 1
83 subgrid_ratio_y(i) = 1
86 opt_output_from_geogrid_path = './'
87 opt_output_from_metgrid_path = './'
88 opt_metgrid_tbl_path = 'metgrid/'
89 interval_seconds = INVALID
91 ! Read parameters from Fortran namelist
93 inquire(unit=funit, opened=is_used)
94 if (.not. is_used) exit
96 open(funit,file='namelist.wps',status='old',form='formatted',err=1000)
101 ! BUG: Better handle debug_level in module_debug
102 if ( debug_level .gt. 100 ) then
103 call set_debug_level(DEBUG)
105 call set_debug_level(WARN)
108 call mprintf(.true.,LOGFILE,'Using the following namelist variables:')
109 call mprintf(.true.,LOGFILE,'&SHARE')
110 call mprintf(.true.,LOGFILE,' WRF_CORE = %s',s1=wrf_core)
111 call mprintf(.true.,LOGFILE,' MAX_DOM = %i',i1=max_dom)
112 call mprintf(.true.,LOGFILE,' START_YEAR = %i',i1=start_year(1))
114 call mprintf(.true.,LOGFILE,' = %i',i1=start_year(i))
116 call mprintf(.true.,LOGFILE,' START_MONTH = %i',i1=start_month(1))
118 call mprintf(.true.,LOGFILE,' = %i',i1=start_month(i))
120 call mprintf(.true.,LOGFILE,' START_DAY = %i',i1=start_day(1))
122 call mprintf(.true.,LOGFILE,' = %i',i1=start_day(i))
124 call mprintf(.true.,LOGFILE,' START_HOUR = %i',i1=start_hour(1))
126 call mprintf(.true.,LOGFILE,' = %i',i1=start_hour(i))
128 call mprintf(.true.,LOGFILE,' START_MINUTE = %i',i1=start_minute(1))
130 call mprintf(.true.,LOGFILE,' = %i',i1=start_minute(i))
132 call mprintf(.true.,LOGFILE,' START_SECOND = %i',i1=start_second(1))
134 call mprintf(.true.,LOGFILE,' = %i',i1=start_second(i))
136 call mprintf(.true.,LOGFILE,' END_YEAR = %i',i1=end_year(1))
138 call mprintf(.true.,LOGFILE,' = %i',i1=end_year(i))
140 call mprintf(.true.,LOGFILE,' END_MONTH = %i',i1=end_month(1))
142 call mprintf(.true.,LOGFILE,' = %i',i1=end_month(i))
144 call mprintf(.true.,LOGFILE,' END_DAY = %i',i1=end_day(1))
146 call mprintf(.true.,LOGFILE,' = %i',i1=end_day(i))
148 call mprintf(.true.,LOGFILE,' END_HOUR = %i',i1=end_hour(1))
150 call mprintf(.true.,LOGFILE,' = %i',i1=end_hour(i))
152 call mprintf(.true.,LOGFILE,' END_MINUTE = %i',i1=end_minute(1))
154 call mprintf(.true.,LOGFILE,' = %i',i1=end_minute(i))
156 call mprintf(.true.,LOGFILE,' END_SECOND = %i',i1=end_second(1))
158 call mprintf(.true.,LOGFILE,' = %i',i1=end_second(i))
160 call mprintf(.true.,LOGFILE,' START_DATE = %s',s1=start_date(1))
162 call mprintf(.true.,LOGFILE,' = %s',s1=start_date(i))
164 call mprintf(.true.,LOGFILE,' END_DATE = %s',s1=end_date(1))
166 call mprintf(.true.,LOGFILE,' = %s',s1=end_date(i))
168 call mprintf(.true.,LOGFILE,' INTERVAL_SECONDS = %i',i1=interval_seconds)
169 call mprintf(.true.,LOGFILE,' IO_FORM_GEOGRID = %i',i1=io_form_geogrid)
170 call mprintf(.true.,LOGFILE,' OPT_OUTPUT_FROM_GEOGRID_PATH = %s',s1=opt_output_from_geogrid_path)
171 call mprintf(.true.,LOGFILE,' SUBGRID_RATIO_X = %i',i1=subgrid_ratio_x(1))
173 call mprintf(.true.,LOGFILE,' = %i',i1=subgrid_ratio_x(i))
175 call mprintf(.true.,LOGFILE,' SUBGRID_RATIO_Y = %i',i1=subgrid_ratio_y(1))
177 call mprintf(.true.,LOGFILE,' = %i',i1=subgrid_ratio_y(i))
179 call mprintf(.true.,LOGFILE,' DEBUG_LEVEL = %i',i1=debug_level)
180 call mprintf(.true.,LOGFILE,' ACTIVE_GRID = %l',l1=active_grid(1))
182 call mprintf(.true.,LOGFILE,' = %l',l1=active_grid(i))
184 call mprintf(.true.,LOGFILE,' NOCOLONS = %l',l1=nocolons)
185 call mprintf(.true.,LOGFILE,'/')
187 call mprintf(.true.,LOGFILE,'&METGRID')
190 if (fg_name(i) == '*') then
191 call mprintf(.true.,LOGFILE,' FG_NAME = ')
193 call mprintf(.true.,LOGFILE,' FG_NAME = %s',s1=fg_name(i))
196 if (fg_name(i) == '*') exit
197 call mprintf(.true.,LOGFILE,' = %s',s1=fg_name(i))
202 if (constants_name(i) == '*') then
203 call mprintf(.true.,LOGFILE,' CONSTANTS_NAME = ')
205 call mprintf(.true.,LOGFILE,' CONSTANTS_NAME = %s',s1=constants_name(i))
208 if (constants_name(i) == '*') exit
209 call mprintf(.true.,LOGFILE,' = %s',s1=constants_name(i))
212 call mprintf(.true.,LOGFILE,' IO_FORM_METGRID = %i',i1=io_form_metgrid)
213 call mprintf(.true.,LOGFILE,' PROCESS_ONLY_BDY = %i',i1=process_only_bdy)
214 call mprintf(.true.,LOGFILE,' OPT_OUTPUT_FROM_METGRID_PATH = %s',s1=opt_output_from_metgrid_path)
215 call mprintf(.true.,LOGFILE,' OPT_METGRID_TBL_PATH = %s',s1=opt_metgrid_tbl_path)
216 call mprintf(.true.,LOGFILE,'/')
219 ! Convert wrf_core to uppercase letters
221 if (ichar(wrf_core(i:i)) >= ichar('a') .and. ichar(wrf_core(i:i)) <= ichar('z') ) &
222 wrf_core(i:i) = char(ichar(wrf_core(i:i))-ichar('a')+ichar('A'))
225 ! Before doing anything else, we must have a valid grid type
227 if (wrf_core == 'ARW') then
229 else if (wrf_core == 'NMM') then
233 call mprintf(gridtype /= 'C' .and. gridtype /= 'E', ERROR, &
234 'A valid wrf_core must be specified in the namelist. '// &
235 'Currently, only "ARW" and "NMM" are supported.')
237 call mprintf(max_dom > MAX_DOMAINS, ERROR, &
238 'In namelist, max_dom must be <= %i. To run with more'// &
239 ' than %i domains, increase the MAX_DOMAINS parameter.', &
240 i1=MAX_DOMAINS, i2=MAX_DOMAINS)
242 call mprintf(gridtype /= 'C' .and. process_only_bdy /= 0, ERROR, &
243 'The use of process_only_bdy is only currently supported in the "ARW" core. '// &
244 'For "NMM", please set process_only_bdy to 0 in the namelist.')
247 if (io_form_geogrid > 100) then
248 io_form_geogrid = io_form_geogrid - 100
249 do_tiled_input = .true.
251 do_tiled_input = .false.
253 if (io_form_metgrid > 100) then
254 io_form_metgrid = io_form_metgrid - 100
255 do_tiled_output = .true.
257 do_tiled_output = .false.
260 ! Check for valid io_form_geogrid
263 io_form_geogrid /= BINARY .and. &
266 io_form_geogrid /= NETCDF .and. &
269 io_form_geogrid /= GRIB1 .and. &
272 call mprintf(.true.,WARN,'Valid io_form_geogrid values are:')
274 call mprintf(.true.,WARN,' %i (=BINARY)',i1=BINARY)
277 call mprintf(.true.,WARN,' %i (=NETCDF)',i1=NETCDF)
280 call mprintf(.true.,WARN,' %i (=GRIB1)',i1=GRIB1)
282 call mprintf(.true.,ERROR,'No valid value for io_form_geogrid was specified in the namelist.')
284 io_form_input = io_form_geogrid
286 ! Check for valid io_form_metgrid
289 io_form_metgrid /= BINARY .and. &
292 io_form_metgrid /= NETCDF .and. &
295 io_form_metgrid /= GRIB1 .and. &
298 call mprintf(.true.,WARN,'Valid io_form_metgrid values are:')
300 call mprintf(.true.,WARN,' %i (=BINARY)',i1=BINARY)
303 call mprintf(.true.,WARN,' %i (=NETCDF)',i1=NETCDF)
306 call mprintf(.true.,WARN,' %i (=GRIB1)',i1=GRIB1)
308 call mprintf(.true.,ERROR,'No valid value for io_form_metgrid was specified in the namelist.')
310 io_form_output = io_form_metgrid
312 if (start_date(1) == '0000-00-00_00:00:00') then
314 ! Build starting date string
315 write(start_date(i), '(i4.4,a1,i2.2,a1,i2.2,a1,i2.2,a1,i2.2,a1,i2.2)') &
316 start_year(i),'-',start_month(i),'-',start_day(i),'_',start_hour(i),':',start_minute(i),':',start_second(i)
318 ! Build ending date string
319 write(end_date(i), '(i4.4,a1,i2.2,a1,i2.2,a1,i2.2,a1,i2.2,a1,i2.2)') &
320 end_year(i),'-',end_month(i),'-',end_day(i),'_',end_hour(i),':',end_minute(i),':',end_second(i)
325 ! Paths need to end with a /
326 i = len_trim(opt_metgrid_tbl_path)
327 if (opt_metgrid_tbl_path(i:i) /= '/') then
328 opt_metgrid_tbl_path(i+1:i+1) = '/'
331 i = len_trim(opt_output_from_geogrid_path)
332 if (opt_output_from_geogrid_path(i:i) /= '/') then
333 opt_output_from_geogrid_path(i+1:i+1) = '/'
336 i = len_trim(opt_output_from_metgrid_path)
337 if (opt_output_from_metgrid_path(i:i) /= '/') then
338 opt_output_from_metgrid_path(i+1:i+1) = '/'
342 ! Blank strings should be set to flag values
344 if (len_trim(constants_name(i)) == 0) then
345 constants_name(i) = '*'
347 if (len_trim(fg_name(i)) == 0) then
353 grid_is_active(i) = active_grid(i)
358 1000 call mprintf(.true.,ERROR,'Error opening file namelist.wps')
360 end subroutine get_namelist_params
362 end module gridinfo_module