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 :: iproj_type, n_domains, io_form_output, dyn_opt
17 integer, dimension(MAX_DOMAINS) :: parent_grid_ratio, parent_id, ixdim, jydim
18 real :: known_lat, known_lon, stand_lon, truelat1, truelat2, known_x, known_y, &
19 dxkm, dykm, phi, lambda, ref_lat, ref_lon, ref_x, ref_y
20 real, dimension(MAX_DOMAINS) :: parent_ll_x, parent_ll_y, parent_ur_x, parent_ur_y
21 character (len=128) :: geog_data_path, opt_output_from_geogrid_path, opt_geogrid_tbl_path
23 character (len=128), dimension(MAX_DOMAINS) :: geog_data_res
24 character (len=1) :: gridtype
25 logical :: do_tiled_output
26 integer :: debug_level
30 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
31 ! Name: get_grid_params
33 ! Purpose: This subroutine retrieves all parameters regarding the model domains
34 ! to be processed by geogrid.exe. This includes map parameters, domain
35 ! size and location, and nest information.
36 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
37 subroutine get_grid_params()
42 integer :: i, j, max_dom, funit, io_form_geogrid, interval_seconds
43 real :: dx, dy, rparent_gridpts
44 integer, dimension(MAX_DOMAINS) :: i_parent_start, j_parent_start, &
45 s_we, e_we, s_sn, e_sn, &
46 start_year, start_month, start_day, start_hour, start_minute, start_second, &
47 end_year, end_month, end_day, end_hour, end_minute, end_second
48 character (len=128) :: map_proj
49 character (len=128), dimension(MAX_DOMAINS) :: start_date, end_date
50 character (len=3) :: wrf_core
53 namelist /share/ wrf_core, max_dom, start_date, end_date, &
54 start_year, end_year, start_month, end_month, &
55 start_day, end_day, start_hour, end_hour, &
56 start_minute, end_minute, start_second, end_second, &
58 io_form_geogrid, opt_output_from_geogrid_path, debug_level
59 namelist /geogrid/ parent_id, parent_grid_ratio, &
60 i_parent_start, j_parent_start, s_we, e_we, s_sn, e_sn, &
61 map_proj, ref_x, ref_y, ref_lat, ref_lon, &
62 truelat1, truelat2, stand_lon, dx, dy, &
63 geog_data_res, geog_data_path, opt_geogrid_tbl_path
65 ! Set defaults for namelist variables
70 geog_data_path = 'NOT_SPECIFIED'
82 geog_data_res(i) = 'default'
84 parent_grid_ratio(i) = INVALID
101 start_date(i) = '0000-00-00_00:00:00'
102 end_date(i) = '0000-00-00_00:00:00'
104 opt_output_from_geogrid_path = './'
105 opt_geogrid_tbl_path = 'geogrid/'
106 interval_seconds = INVALID
108 ! Read parameters from Fortran namelist
110 inquire(unit=funit, opened=is_used)
111 if (.not. is_used) exit
113 open(funit,file='namelist.wps',status='old',form='formatted',err=1000)
118 ! BUG: More properly handle debug_level in module_debug
119 if (debug_level.gt.100) then
120 call set_debug_level(DEBUG)
122 call set_debug_level(WARN)
125 call mprintf(.true.,LOGFILE,'Using the following namelist variables:')
126 call mprintf(.true.,LOGFILE,'&SHARE')
127 call mprintf(.true.,LOGFILE,' WRF_CORE = %s',s1=wrf_core)
128 call mprintf(.true.,LOGFILE,' MAX_DOM = %i',i1=max_dom)
129 call mprintf(.true.,LOGFILE,' START_YEAR = %i',i1=start_year(1))
131 call mprintf(.true.,LOGFILE,' = %i',i1=start_year(i))
133 call mprintf(.true.,LOGFILE,' START_MONTH = %i',i1=start_month(1))
135 call mprintf(.true.,LOGFILE,' = %i',i1=start_month(i))
137 call mprintf(.true.,LOGFILE,' START_DAY = %i',i1=start_day(1))
139 call mprintf(.true.,LOGFILE,' = %i',i1=start_day(i))
141 call mprintf(.true.,LOGFILE,' START_HOUR = %i',i1=start_hour(1))
143 call mprintf(.true.,LOGFILE,' = %i',i1=start_hour(i))
145 call mprintf(.true.,LOGFILE,' START_MINUTE = %i',i1=start_minute(1))
147 call mprintf(.true.,LOGFILE,' = %i',i1=start_minute(i))
149 call mprintf(.true.,LOGFILE,' START_SECOND = %i',i1=start_second(1))
151 call mprintf(.true.,LOGFILE,' = %i',i1=start_second(i))
153 call mprintf(.true.,LOGFILE,' END_YEAR = %i',i1=end_year(1))
155 call mprintf(.true.,LOGFILE,' = %i',i1=end_year(i))
157 call mprintf(.true.,LOGFILE,' END_MONTH = %i',i1=end_month(1))
159 call mprintf(.true.,LOGFILE,' = %i',i1=end_month(i))
161 call mprintf(.true.,LOGFILE,' END_DAY = %i',i1=end_day(1))
163 call mprintf(.true.,LOGFILE,' = %i',i1=end_day(i))
165 call mprintf(.true.,LOGFILE,' END_HOUR = %i',i1=end_hour(1))
167 call mprintf(.true.,LOGFILE,' = %i',i1=end_hour(i))
169 call mprintf(.true.,LOGFILE,' END_MINUTE = %i',i1=end_minute(1))
171 call mprintf(.true.,LOGFILE,' = %i',i1=end_minute(i))
173 call mprintf(.true.,LOGFILE,' END_SECOND = %i',i1=end_second(1))
175 call mprintf(.true.,LOGFILE,' = %i',i1=end_second(i))
177 call mprintf(.true.,LOGFILE,' START_DATE = %s',s1=start_date(1))
179 call mprintf(.true.,LOGFILE,' = %s',s1=start_date(i))
181 call mprintf(.true.,LOGFILE,' END_DATE = %s',s1=end_date(1))
183 call mprintf(.true.,LOGFILE,' = %s',s1=end_date(i))
185 call mprintf(.true.,LOGFILE,' INTERVAL_SECONDS = %i',i1=interval_seconds)
186 call mprintf(.true.,LOGFILE,' IO_FORM_GEOGRID = %i',i1=io_form_geogrid)
187 call mprintf(.true.,LOGFILE,' OPT_OUTPUT_FROM_GEOGRID_PATH = %s',s1=opt_output_from_geogrid_path)
188 call mprintf(.true.,LOGFILE,' DEBUG_LEVEL = %i',i1=debug_level)
189 call mprintf(.true.,LOGFILE,'/')
191 call mprintf(.true.,LOGFILE,'&GEOGRID')
192 call mprintf(.true.,LOGFILE,' PARENT_ID = %i',i1=parent_id(1))
194 call mprintf(.true.,LOGFILE,' = %i',i1=parent_id(i))
196 call mprintf(.true.,LOGFILE,' PARENT_GRID_RATIO = %i',i1=parent_grid_ratio(1))
198 call mprintf(.true.,LOGFILE,' = %i',i1=parent_grid_ratio(i))
200 call mprintf(.true.,LOGFILE,' I_PARENT_START = %i',i1=i_parent_start(1))
202 call mprintf(.true.,LOGFILE,' = %i',i1=i_parent_start(i))
204 call mprintf(.true.,LOGFILE,' J_PARENT_START = %i',i1=j_parent_start(1))
206 call mprintf(.true.,LOGFILE,' = %i',i1=j_parent_start(i))
208 call mprintf(.true.,LOGFILE,' S_WE = %i',i1=s_we(1))
210 call mprintf(.true.,LOGFILE,' = %i',i1=s_we(i))
212 call mprintf(.true.,LOGFILE,' E_WE = %i',i1=e_we(1))
214 call mprintf(.true.,LOGFILE,' = %i',i1=e_we(i))
216 call mprintf(.true.,LOGFILE,' S_SN = %i',i1=s_sn(1))
218 call mprintf(.true.,LOGFILE,' = %i',i1=s_sn(i))
220 call mprintf(.true.,LOGFILE,' E_SN = %i',i1=e_sn(1))
222 call mprintf(.true.,LOGFILE,' = %i',i1=e_sn(i))
224 call mprintf(.true.,LOGFILE,' GEOG_DATA_RES = %s',s1=geog_data_res(1))
226 call mprintf(.true.,LOGFILE,' = %s',s1=geog_data_res(i))
228 call mprintf(.true.,LOGFILE,' DX = %f',f1=dx)
229 call mprintf(.true.,LOGFILE,' DY = %f',f1=dy)
230 call mprintf(.true.,LOGFILE,' MAP_PROJ = %s',s1=map_proj)
231 call mprintf(.true.,LOGFILE,' REF_LAT = %f',f1=ref_lat)
232 call mprintf(.true.,LOGFILE,' REF_LON = %f',f1=ref_lon)
233 call mprintf(.true.,LOGFILE,' REF_X = %f',f1=ref_x)
234 call mprintf(.true.,LOGFILE,' REF_Y = %f',f1=ref_y)
235 call mprintf(.true.,LOGFILE,' TRUELAT1 = %f',f1=truelat1)
236 call mprintf(.true.,LOGFILE,' TRUELAT2 = %f',f1=truelat2)
237 call mprintf(.true.,LOGFILE,' STAND_LON = %f',f1=stand_lon)
238 call mprintf(.true.,LOGFILE,' GEOG_DATA_PATH = %s',s1=geog_data_path)
239 call mprintf(.true.,LOGFILE,' OPT_GEOGRID_TBL_PATH = %s',s1=opt_geogrid_tbl_path)
240 call mprintf(.true.,LOGFILE,'/')
250 ! Convert wrf_core to uppercase letters
252 if (ichar(wrf_core(i:i)) >= 97) wrf_core(i:i) = char(ichar(wrf_core(i:i))-32)
255 ! Before doing anything else, we must have a valid grid type
257 if (wrf_core == 'ARW') then
260 else if (wrf_core == 'NMM') then
265 ! Next, if this is NMM, we need to subtract 1 from the specified E_WE and E_SN;
266 ! for some reason, these two variables need to be set to 1 larger than they
267 ! really ought to be in the WRF namelist, so, to be consistent, we will do
268 ! the same in the WPS namelist
269 if (gridtype == 'E') then
271 e_we(i) = e_we(i) - 1
272 e_sn(i) = e_sn(i) - 1
276 call mprintf(gridtype /= 'C' .and. gridtype /= 'E', ERROR, &
277 'A valid wrf_core must be specified in the namelist. '// &
278 'Currently, only "ARW" and "NMM" are supported.')
280 call mprintf(max_dom > MAX_DOMAINS, ERROR, &
281 'In namelist, max_dom must be <= %i. To run with more'// &
282 ' than %i domains, increase the MAX_DOMAINS parameter.', &
283 i1=MAX_DOMAINS, i2=MAX_DOMAINS)
285 ! Every domain must have a valid parent id
287 call mprintf(parent_id(i) <= 0 .or. parent_id(i) >= i, ERROR, &
288 'In namelist, the parent_id of domain %i must be in '// &
289 'the range 1 to %i.', i1=i, i2=i-1)
292 ! Check for valid geog_data_path
294 do i=1,len(geog_data_path)
295 geog_data_path(j:j) = geog_data_path(i:i)
296 if (geog_data_path(i:i) /= ' ') j = j + 1
298 if (geog_data_path(1:1) == ' ') then
299 call mprintf(.true.,ERROR,'In namelist, geog_data_path must be specified.')
301 j = len_trim(geog_data_path)
303 call mprintf(.true.,ERROR, &
304 'In namelist, geog_data_path must be strictly less '// &
305 'than 128 characters in length.')
307 if (geog_data_path(j:j) /= '/') then
308 geog_data_path(j+1:j+1) = '/'
312 ! Paths need to end with a /
313 j = len_trim(opt_geogrid_tbl_path)
314 if (opt_geogrid_tbl_path(j:j) /= '/') then
315 opt_geogrid_tbl_path(j+1:j+1) = '/'
318 j = len_trim(opt_output_from_geogrid_path)
319 if (opt_output_from_geogrid_path(j:j) /= '/') then
320 opt_output_from_geogrid_path(j+1:j+1) = '/'
323 ! Handle IOFORM+100 to do tiled IO
324 if (io_form_geogrid > 100) then
325 do_tiled_output = .true.
326 io_form_geogrid = io_form_geogrid - 100
328 do_tiled_output = .false.
331 ! Check for valid io_form_geogrid
334 io_form_geogrid /= BINARY .and. &
337 io_form_geogrid /= NETCDF .and. &
340 io_form_geogrid /= GRIB1 .and. &
343 call mprintf(.true.,WARN,'Valid io_form_geogrid values are:')
345 call mprintf(.true.,WARN,' %i (=BINARY)',i1=BINARY)
348 call mprintf(.true.,WARN,' %i (=NETCDF)',i1=NETCDF)
351 call mprintf(.true.,WARN,' %i (=GRIB1)',i1=GRIB1)
353 call mprintf(.true.,ERROR,'No valid value for io_form_geogrid was specified in the namelist.')
355 io_form_output = io_form_geogrid
357 ! Convert map_proj to uppercase letters
359 if (ichar(map_proj(i:i)) >= 97) map_proj(i:i) = char(ichar(map_proj(i:i))-32)
362 ! Assign parameters to module variables
363 if ((index(map_proj, 'LAMBERT') /= 0) .and. &
364 (len_trim(map_proj) == len('LAMBERT'))) then
367 else if ((index(map_proj, 'MERCATOR') /= 0) .and. &
368 (len_trim(map_proj) == len('MERCATOR'))) then
369 iproj_type = PROJ_MERC
371 else if ((index(map_proj, 'POLAR') /= 0) .and. &
372 (len_trim(map_proj) == len('POLAR'))) then
375 else if ((index(map_proj, 'ROTATED_LL') /= 0) .and. &
376 (len_trim(map_proj) == len('ROTATED_LL'))) then
377 iproj_type = PROJ_ROTLL
380 call mprintf(.true.,ERROR,&
381 'In namelist, invalid map_proj specified. Valid '// &
382 'projections are "lambert", "mercator", "polar", '// &
388 ! For C grid, let ixdim and jydim be the number of mass points in
389 ! each direction; for E grid, we will put the row and column back
390 ! later; maybe this should be changed to be more clear, though.
392 ixdim(i) = e_we(i) - s_we(i) + 1
393 jydim(i) = e_sn(i) - s_sn(i) + 1
396 if (gridtype == 'E') then
397 phi = dykm*real(jydim(1)-1)/2.
398 lambda = dxkm*real(ixdim(1)-1)
401 ! If the user hasn't supplied a known_x and known_y, assume the center of domain 1
402 if (gridtype == 'E' .and. (known_x /= NAN .or. known_y /= NAN)) then
403 call mprintf(.true.,WARN, &
404 'Namelist variables ref_x and ref_y cannot be used for NMM grids.'// &
405 ' (ref_lat, ref_lon) will refer to the center of the coarse grid.')
406 else if (gridtype == 'C') then
407 if (known_x == NAN .and. known_y == NAN) then
408 known_x = ixdim(1) / 2.
409 known_y = jydim(1) / 2.
410 else if (known_x == NAN .or. known_y == NAN) then
411 call mprintf(.true.,ERROR, &
412 'In namelist.wps, neither or both of ref_x, ref_y must be specified.')
416 ! Checks specific to E grid
417 if (gridtype == 'E') then
419 ! E grid supports only the rotated lat/lon projection
420 if (iproj_type /= PROJ_ROTLL) then
421 call mprintf(.true., WARN, &
422 'For the NMM core, projection type must be rotated '// &
423 'lat/lon (map_proj=rotated_ll)')
424 call mprintf(.true.,WARN,'Projection will be set to rotated_ll')
425 iproj_type = PROJ_ROTLL
428 ! In the following check, add back the 1 that we had to subtract above
429 ! for the sake of being consistent with WRF namelist
430 call mprintf(mod(e_sn(1)+1,2) /= 0, ERROR, &
431 'For the NMM core, E_SN must be an even number for grid %i.', i1=1)
434 call mprintf((parent_grid_ratio(i) /= 3 .and. i > 1), ERROR, &
435 'For the NMM core, the parent_grid_ratio must be 3.')
438 ! Check that nests have an acceptable number of grid points in each dimension
440 ! rparent_gridpts = real(ixdim(i)+2)/real(parent_grid_ratio(i))
441 ! if (floor(rparent_gridpts) /= ceiling(rparent_gridpts)) then
442 ! call mprintf(.true.,ERROR,'For nest %i, e_we must be 3n-2 '// &
443 ! 'for some integer n > 1.', &
446 ! rparent_gridpts = real(jydim(i)+2)/real(parent_grid_ratio(i))
447 ! if (floor(rparent_gridpts) /= ceiling(rparent_gridpts)) then
448 ! call mprintf(.true.,ERROR,'For nest %i, e_sn must be 3n-2 '// &
449 ! 'for some odd integer n > 1.', &
454 ! Checks specific to C grid
455 else if (gridtype == 'C') then
457 ! C grid does not support the rotated lat/lon projection
458 call mprintf((iproj_type == PROJ_ROTLL), ERROR, &
459 'Rotated lat/lon projection is not supported for the ARW core. '// &
460 'Valid projecitons are "lambert", "mercator", and "polar".')
462 ! Check that nests have an acceptable number of grid points in each dimension
464 rparent_gridpts = real(ixdim(i)-1)/real(parent_grid_ratio(i))
465 if (floor(rparent_gridpts) /= ceiling(rparent_gridpts)) then
466 call mprintf(.true.,ERROR,'For nest %i, (e_we-s_we+1) must be one greater '// &
467 'than an interger multiple of the parent_grid_ratio of %i.', &
468 i1=i, i2=parent_grid_ratio(i))
470 rparent_gridpts = real(jydim(i)-1)/real(parent_grid_ratio(i))
471 if (floor(rparent_gridpts) /= ceiling(rparent_gridpts)) then
472 call mprintf(.true.,ERROR,'For nest %i, (e_sn-s_sn+1) must be one greater '// &
473 'than an interger multiple of the parent_grid_ratio of %i.', &
474 i1=i, i2=parent_grid_ratio(i))
480 parent_ll_x(i) = real(i_parent_start(i))
481 parent_ll_y(i) = real(j_parent_start(i))
482 parent_ur_x(i) = real(i_parent_start(i))+real(ixdim(i))/real(parent_grid_ratio(i))-1.
483 parent_ur_y(i) = real(j_parent_start(i))+real(jydim(i))/real(parent_grid_ratio(i))-1.
488 1000 call mprintf(.true.,ERROR,'Error opening file namelist.wps')
490 end subroutine get_grid_params
492 end module gridinfo_module