PageRenderTime 44ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/WPS/geogrid/src/gridinfo_module.F

http://github.com/jbeezley/wrf-fire
FORTRAN Legacy | 600 lines | 358 code | 61 blank | 181 comment | 72 complexity | af394b8addea52ed10859da2faec7c16 MD5 | raw file
Possible License(s): AGPL-1.0
  1. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  2. ! MODULE GRIDINFO_MODULE
  3. !
  4. ! This module handles (i.e., acquires, stores, and makes available) all data
  5. ! describing the model domains to be processed.
  6. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  7. module gridinfo_module
  8. use constants_module
  9. use misc_definitions_module
  10. use module_debug
  11. ! Parameters
  12. integer, parameter :: MAX_DOMAINS = 21
  13. ! Variables
  14. integer :: iproj_type, n_domains, io_form_output, dyn_opt
  15. integer, dimension(MAX_DOMAINS) :: parent_grid_ratio, parent_id, ixdim, jydim
  16. integer, dimension(MAX_DOMAINS) :: moad_grid_ratio
  17. integer, dimension(MAX_DOMAINS) :: subgrid_ratio_x, subgrid_ratio_y
  18. real :: known_lat, known_lon, pole_lat, pole_lon, stand_lon, truelat1, truelat2, &
  19. known_x, known_y, dxkm, dykm, phi, lambda, ref_lat, ref_lon, ref_x, ref_y, &
  20. dlatdeg, dlondeg
  21. real, dimension(MAX_DOMAINS) :: parent_ll_x, parent_ll_y, parent_ur_x, parent_ur_y
  22. character (len=MAX_FILENAME_LEN) :: 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. logical, dimension(MAX_DOMAINS) :: grid_is_active
  27. integer :: debug_level
  28. contains
  29. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  30. ! Name: get_grid_params
  31. !
  32. ! Purpose: This subroutine retrieves all parameters regarding the model domains
  33. ! to be processed by geogrid.exe. This includes map parameters, domain
  34. ! size and location, and nest information.
  35. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  36. subroutine get_grid_params()
  37. implicit none
  38. ! Local variables
  39. integer :: i, j, max_dom, funit, io_form_geogrid, interval_seconds
  40. real :: dx, dy, rparent_gridpts
  41. integer, dimension(MAX_DOMAINS) :: i_parent_start, j_parent_start, &
  42. s_we, e_we, s_sn, e_sn, &
  43. start_year, start_month, start_day, start_hour, start_minute, start_second, &
  44. end_year, end_month, end_day, end_hour, end_minute, end_second
  45. character (len=128) :: map_proj
  46. character (len=128), dimension(MAX_DOMAINS) :: start_date, end_date
  47. character (len=3) :: wrf_core
  48. logical :: is_used, nest_outside
  49. logical, dimension(MAX_DOMAINS) :: active_grid
  50. namelist /share/ wrf_core, max_dom, start_date, end_date, &
  51. start_year, end_year, start_month, end_month, &
  52. start_day, end_day, start_hour, end_hour, &
  53. start_minute, end_minute, start_second, end_second, &
  54. interval_seconds, &
  55. io_form_geogrid, opt_output_from_geogrid_path, debug_level, active_grid, &
  56. subgrid_ratio_x, subgrid_ratio_y
  57. namelist /geogrid/ parent_id, parent_grid_ratio, &
  58. i_parent_start, j_parent_start, s_we, e_we, s_sn, e_sn, &
  59. map_proj, ref_x, ref_y, ref_lat, ref_lon, &
  60. pole_lat, pole_lon, truelat1, truelat2, stand_lon, &
  61. dx, dy, geog_data_res, geog_data_path, opt_geogrid_tbl_path
  62. ! Set defaults for namelist variables
  63. debug_level = 0
  64. io_form_geogrid = 2
  65. wrf_core = 'ARW'
  66. max_dom = 1
  67. geog_data_path = 'NOT_SPECIFIED'
  68. ref_x = NAN
  69. ref_y = NAN
  70. ref_lat = NAN
  71. ref_lon = NAN
  72. dx = NAN
  73. dy = NAN
  74. map_proj = 'Lambert'
  75. pole_lat = 90.0
  76. pole_lon = 0.0
  77. truelat1 = NAN
  78. truelat2 = NAN
  79. stand_lon = NAN
  80. do i=1,MAX_DOMAINS
  81. geog_data_res(i) = 'default'
  82. parent_id(i) = 1
  83. parent_grid_ratio(i) = INVALID
  84. moad_grid_ratio(i) = INVALID
  85. s_we(i) = 1
  86. e_we(i) = INVALID
  87. s_sn(i) = 1
  88. e_sn(i) = INVALID
  89. start_year(i) = 0
  90. start_month(i) = 0
  91. start_day(i) = 0
  92. start_hour(i) = 0
  93. start_minute(i) = 0
  94. start_second(i) = 0
  95. end_year(i) = 0
  96. end_month(i) = 0
  97. end_day(i) = 0
  98. end_hour(i) = 0
  99. end_minute(i) = 0
  100. end_second(i) = 0
  101. start_date(i) = '0000-00-00_00:00:00'
  102. end_date(i) = '0000-00-00_00:00:00'
  103. active_grid(i) = .true.
  104. subgrid_ratio_x(i) = 1
  105. subgrid_ratio_y(i) = 1
  106. end do
  107. moad_grid_ratio(1) = 1
  108. opt_output_from_geogrid_path = './'
  109. opt_geogrid_tbl_path = 'geogrid/'
  110. interval_seconds = INVALID
  111. ! Read parameters from Fortran namelist
  112. do funit=10,100
  113. inquire(unit=funit, opened=is_used)
  114. if (.not. is_used) exit
  115. end do
  116. open(funit,file='namelist.wps',status='old',form='formatted',err=1000)
  117. read(funit,share)
  118. read(funit,geogrid)
  119. close(funit)
  120. ! BUG: More properly handle debug_level in module_debug
  121. if (debug_level.gt.100) then
  122. call set_debug_level(DEBUG)
  123. else
  124. call set_debug_level(WARN)
  125. end if
  126. call mprintf(.true.,LOGFILE,'Using the following namelist variables:')
  127. call mprintf(.true.,LOGFILE,'&SHARE')
  128. call mprintf(.true.,LOGFILE,' WRF_CORE = %s',s1=wrf_core)
  129. call mprintf(.true.,LOGFILE,' MAX_DOM = %i',i1=max_dom)
  130. call mprintf(.true.,LOGFILE,' START_YEAR = %i',i1=start_year(1))
  131. do i=2,max_dom
  132. call mprintf(.true.,LOGFILE,' = %i',i1=start_year(i))
  133. end do
  134. call mprintf(.true.,LOGFILE,' START_MONTH = %i',i1=start_month(1))
  135. do i=2,max_dom
  136. call mprintf(.true.,LOGFILE,' = %i',i1=start_month(i))
  137. end do
  138. call mprintf(.true.,LOGFILE,' START_DAY = %i',i1=start_day(1))
  139. do i=2,max_dom
  140. call mprintf(.true.,LOGFILE,' = %i',i1=start_day(i))
  141. end do
  142. call mprintf(.true.,LOGFILE,' START_HOUR = %i',i1=start_hour(1))
  143. do i=2,max_dom
  144. call mprintf(.true.,LOGFILE,' = %i',i1=start_hour(i))
  145. end do
  146. call mprintf(.true.,LOGFILE,' START_MINUTE = %i',i1=start_minute(1))
  147. do i=2,max_dom
  148. call mprintf(.true.,LOGFILE,' = %i',i1=start_minute(i))
  149. end do
  150. call mprintf(.true.,LOGFILE,' START_SECOND = %i',i1=start_second(1))
  151. do i=2,max_dom
  152. call mprintf(.true.,LOGFILE,' = %i',i1=start_second(i))
  153. end do
  154. call mprintf(.true.,LOGFILE,' END_YEAR = %i',i1=end_year(1))
  155. do i=2,max_dom
  156. call mprintf(.true.,LOGFILE,' = %i',i1=end_year(i))
  157. end do
  158. call mprintf(.true.,LOGFILE,' END_MONTH = %i',i1=end_month(1))
  159. do i=2,max_dom
  160. call mprintf(.true.,LOGFILE,' = %i',i1=end_month(i))
  161. end do
  162. call mprintf(.true.,LOGFILE,' END_DAY = %i',i1=end_day(1))
  163. do i=2,max_dom
  164. call mprintf(.true.,LOGFILE,' = %i',i1=end_day(i))
  165. end do
  166. call mprintf(.true.,LOGFILE,' END_HOUR = %i',i1=end_hour(1))
  167. do i=2,max_dom
  168. call mprintf(.true.,LOGFILE,' = %i',i1=end_hour(i))
  169. end do
  170. call mprintf(.true.,LOGFILE,' END_MINUTE = %i',i1=end_minute(1))
  171. do i=2,max_dom
  172. call mprintf(.true.,LOGFILE,' = %i',i1=end_minute(i))
  173. end do
  174. call mprintf(.true.,LOGFILE,' END_SECOND = %i',i1=end_second(1))
  175. do i=2,max_dom
  176. call mprintf(.true.,LOGFILE,' = %i',i1=end_second(i))
  177. end do
  178. call mprintf(.true.,LOGFILE,' START_DATE = %s',s1=start_date(1))
  179. do i=2,max_dom
  180. call mprintf(.true.,LOGFILE,' = %s',s1=start_date(i))
  181. end do
  182. call mprintf(.true.,LOGFILE,' END_DATE = %s',s1=end_date(1))
  183. do i=2,max_dom
  184. call mprintf(.true.,LOGFILE,' = %s',s1=end_date(i))
  185. end do
  186. call mprintf(.true.,LOGFILE,' INTERVAL_SECONDS = %i',i1=interval_seconds)
  187. call mprintf(.true.,LOGFILE,' IO_FORM_GEOGRID = %i',i1=io_form_geogrid)
  188. call mprintf(.true.,LOGFILE,' OPT_OUTPUT_FROM_GEOGRID_PATH = %s',s1=opt_output_from_geogrid_path)
  189. call mprintf(.true.,LOGFILE,' SUBGRID_RATIO_X = %i',i1=subgrid_ratio_x(1))
  190. do i=2,max_dom
  191. call mprintf(.true.,LOGFILE,' = %i',i1=subgrid_ratio_x(i))
  192. enddo
  193. call mprintf(.true.,LOGFILE,' SUBGRID_RATIO_Y = %i',i1=subgrid_ratio_y(1))
  194. do i=2,max_dom
  195. call mprintf(.true.,LOGFILE,' = %i',i1=subgrid_ratio_y(i))
  196. enddo
  197. call mprintf(.true.,LOGFILE,' DEBUG_LEVEL = %i',i1=debug_level)
  198. call mprintf(.true.,LOGFILE,' ACTIVE_GRID = %l',l1=active_grid(1))
  199. do i=2,max_dom
  200. call mprintf(.true.,LOGFILE,' = %l',l1=active_grid(i))
  201. end do
  202. call mprintf(.true.,LOGFILE,'/')
  203. call mprintf(.true.,LOGFILE,'&GEOGRID')
  204. call mprintf(.true.,LOGFILE,' PARENT_ID = %i',i1=parent_id(1))
  205. do i=2,max_dom
  206. call mprintf(.true.,LOGFILE,' = %i',i1=parent_id(i))
  207. end do
  208. call mprintf(.true.,LOGFILE,' PARENT_GRID_RATIO = %i',i1=parent_grid_ratio(1))
  209. do i=2,max_dom
  210. call mprintf(.true.,LOGFILE,' = %i',i1=parent_grid_ratio(i))
  211. end do
  212. call mprintf(.true.,LOGFILE,' I_PARENT_START = %i',i1=i_parent_start(1))
  213. do i=2,max_dom
  214. call mprintf(.true.,LOGFILE,' = %i',i1=i_parent_start(i))
  215. end do
  216. call mprintf(.true.,LOGFILE,' J_PARENT_START = %i',i1=j_parent_start(1))
  217. do i=2,max_dom
  218. call mprintf(.true.,LOGFILE,' = %i',i1=j_parent_start(i))
  219. end do
  220. call mprintf(.true.,LOGFILE,' S_WE = %i',i1=s_we(1))
  221. do i=2,max_dom
  222. call mprintf(.true.,LOGFILE,' = %i',i1=s_we(i))
  223. end do
  224. call mprintf(.true.,LOGFILE,' E_WE = %i',i1=e_we(1))
  225. do i=2,max_dom
  226. call mprintf(.true.,LOGFILE,' = %i',i1=e_we(i))
  227. end do
  228. call mprintf(.true.,LOGFILE,' S_SN = %i',i1=s_sn(1))
  229. do i=2,max_dom
  230. call mprintf(.true.,LOGFILE,' = %i',i1=s_sn(i))
  231. end do
  232. call mprintf(.true.,LOGFILE,' E_SN = %i',i1=e_sn(1))
  233. do i=2,max_dom
  234. call mprintf(.true.,LOGFILE,' = %i',i1=e_sn(i))
  235. end do
  236. call mprintf(.true.,LOGFILE,' GEOG_DATA_RES = %s',s1=geog_data_res(1))
  237. do i=2,max_dom
  238. call mprintf(.true.,LOGFILE,' = %s',s1=geog_data_res(i))
  239. end do
  240. call mprintf(.true.,LOGFILE,' DX = %f',f1=dx)
  241. call mprintf(.true.,LOGFILE,' DY = %f',f1=dy)
  242. call mprintf(.true.,LOGFILE,' MAP_PROJ = %s',s1=map_proj)
  243. call mprintf(.true.,LOGFILE,' POLE_LAT = %f',f1=pole_lat)
  244. call mprintf(.true.,LOGFILE,' POLE_LON = %f',f1=pole_lon)
  245. call mprintf(.true.,LOGFILE,' REF_LAT = %f',f1=ref_lat)
  246. call mprintf(.true.,LOGFILE,' REF_LON = %f',f1=ref_lon)
  247. call mprintf(.true.,LOGFILE,' REF_X = %f',f1=ref_x)
  248. call mprintf(.true.,LOGFILE,' REF_Y = %f',f1=ref_y)
  249. call mprintf(.true.,LOGFILE,' TRUELAT1 = %f',f1=truelat1)
  250. call mprintf(.true.,LOGFILE,' TRUELAT2 = %f',f1=truelat2)
  251. call mprintf(.true.,LOGFILE,' STAND_LON = %f',f1=stand_lon)
  252. call mprintf(.true.,LOGFILE,' GEOG_DATA_PATH = %s',s1=geog_data_path)
  253. call mprintf(.true.,LOGFILE,' OPT_GEOGRID_TBL_PATH = %s',s1=opt_geogrid_tbl_path)
  254. call mprintf(.true.,LOGFILE,'/')
  255. dxkm = dx
  256. dykm = dy
  257. known_lat = ref_lat
  258. known_lon = ref_lon
  259. known_x = ref_x
  260. known_y = ref_y
  261. ! Convert wrf_core to uppercase letters
  262. do i=1,3
  263. if (ichar(wrf_core(i:i)) >= 97) wrf_core(i:i) = char(ichar(wrf_core(i:i))-32)
  264. end do
  265. ! Before doing anything else, we must have a valid grid type
  266. gridtype = ' '
  267. if (wrf_core == 'ARW') then
  268. gridtype = 'C'
  269. dyn_opt = 2
  270. else if (wrf_core == 'NMM') then
  271. gridtype = 'E'
  272. dyn_opt = 4
  273. end if
  274. ! Next, if this is NMM, we need to subtract 1 from the specified E_WE and E_SN;
  275. ! for some reason, these two variables need to be set to 1 larger than they
  276. ! really ought to be in the WRF namelist, so, to be consistent, we will do
  277. ! the same in the WPS namelist
  278. if (gridtype == 'E') then
  279. do i=1,max_dom
  280. e_we(i) = e_we(i) - 1
  281. e_sn(i) = e_sn(i) - 1
  282. end do
  283. end if
  284. call mprintf(gridtype /= 'C' .and. gridtype /= 'E', ERROR, &
  285. 'A valid wrf_core must be specified in the namelist. '// &
  286. 'Currently, only "ARW" and "NMM" are supported.')
  287. call mprintf(max_dom > MAX_DOMAINS, ERROR, &
  288. 'In namelist, max_dom must be <= %i. To run with more'// &
  289. ' than %i domains, increase the MAX_DOMAINS parameter.', &
  290. i1=MAX_DOMAINS, i2=MAX_DOMAINS)
  291. ! Every domain must have a valid parent id
  292. do i=2,max_dom
  293. call mprintf(parent_id(i) <= 0 .or. parent_id(i) >= i, ERROR, &
  294. 'In namelist, the parent_id of domain %i must be in '// &
  295. 'the range 1 to %i.', i1=i, i2=i-1)
  296. end do
  297. ! Check for valid geog_data_path
  298. j=1
  299. do i=1,len(geog_data_path)
  300. geog_data_path(j:j) = geog_data_path(i:i)
  301. if (geog_data_path(i:i) /= ' ') j = j + 1
  302. end do
  303. if (geog_data_path(1:1) == ' ') then
  304. call mprintf(.true.,ERROR,'In namelist, geog_data_path must be specified.')
  305. end if
  306. j = len_trim(geog_data_path)
  307. if (j >= MAX_FILENAME_LEN) then
  308. call mprintf(.true.,ERROR, &
  309. 'In namelist, geog_data_path must be strictly less '// &
  310. 'than 128 characters in length.')
  311. else
  312. if (geog_data_path(j:j) /= '/') then
  313. geog_data_path(j+1:j+1) = '/'
  314. end if
  315. end if
  316. ! Paths need to end with a /
  317. j = len_trim(opt_geogrid_tbl_path)
  318. if (opt_geogrid_tbl_path(j:j) /= '/') then
  319. opt_geogrid_tbl_path(j+1:j+1) = '/'
  320. end if
  321. j = len_trim(opt_output_from_geogrid_path)
  322. if (opt_output_from_geogrid_path(j:j) /= '/') then
  323. opt_output_from_geogrid_path(j+1:j+1) = '/'
  324. end if
  325. ! Handle IOFORM+100 to do tiled IO
  326. if (io_form_geogrid > 100) then
  327. do_tiled_output = .true.
  328. io_form_geogrid = io_form_geogrid - 100
  329. else
  330. do_tiled_output = .false.
  331. end if
  332. ! Check for valid io_form_geogrid
  333. if ( &
  334. #ifdef IO_BINARY
  335. io_form_geogrid /= BINARY .and. &
  336. #endif
  337. #ifdef IO_NETCDF
  338. io_form_geogrid /= NETCDF .and. &
  339. #endif
  340. #ifdef IO_GRIB1
  341. io_form_geogrid /= GRIB1 .and. &
  342. #endif
  343. .true. ) then
  344. call mprintf(.true.,WARN,'Valid io_form_geogrid values are:')
  345. #ifdef IO_BINARY
  346. call mprintf(.true.,WARN,' %i (=BINARY)',i1=BINARY)
  347. #endif
  348. #ifdef IO_NETCDF
  349. call mprintf(.true.,WARN,' %i (=NETCDF)',i1=NETCDF)
  350. #endif
  351. #ifdef IO_GRIB1
  352. call mprintf(.true.,WARN,' %i (=GRIB1)',i1=GRIB1)
  353. #endif
  354. call mprintf(.true.,ERROR,'No valid value for io_form_geogrid was specified in the namelist.')
  355. end if
  356. io_form_output = io_form_geogrid
  357. ! Convert map_proj to uppercase letters
  358. do i=1,len(map_proj)
  359. if (ichar(map_proj(i:i)) >= 97) map_proj(i:i) = char(ichar(map_proj(i:i))-32)
  360. end do
  361. ! Assign parameters to module variables
  362. if ((index(map_proj, 'LAMBERT') /= 0) .and. &
  363. (len_trim(map_proj) == len('LAMBERT'))) then
  364. iproj_type = PROJ_LC
  365. else if ((index(map_proj, 'MERCATOR') /= 0) .and. &
  366. (len_trim(map_proj) == len('MERCATOR'))) then
  367. iproj_type = PROJ_MERC
  368. else if ((index(map_proj, 'POLAR') /= 0) .and. &
  369. (len_trim(map_proj) == len('POLAR'))) then
  370. iproj_type = PROJ_PS
  371. else if ((index(map_proj, 'ROTATED_LL') /= 0) .and. &
  372. (len_trim(map_proj) == len('ROTATED_LL'))) then
  373. iproj_type = PROJ_ROTLL
  374. else if ((index(map_proj, 'LAT-LON') /= 0) .and. &
  375. (len_trim(map_proj) == len('LAT-LON'))) then
  376. iproj_type = PROJ_CASSINI
  377. else
  378. call mprintf(.true.,ERROR,&
  379. 'In namelist, invalid map_proj specified. Valid '// &
  380. 'projections are "lambert", "mercator", "polar", '// &
  381. '"lat-lon", and "rotated_ll".')
  382. end if
  383. ! For Cassini / lat-lon projections
  384. if (iproj_type == PROJ_CASSINI) then
  385. ! If no dx,dy specified, assume global grid
  386. if (dx == NAN .and. dy == NAN) then
  387. dlondeg = 360. / (e_we(1)-s_we(1)) ! Here, we really do not want e_we-s_we+1
  388. dlatdeg = 180. / (e_sn(1)-s_sn(1)) ! Here, we really do not want e_we-s_we+1
  389. known_x = 1.
  390. known_y = 1.
  391. known_lon = stand_lon + dlondeg/2.
  392. known_lat = -90. + dlatdeg/2.
  393. dxkm = EARTH_RADIUS_M * PI * 2.0 / (e_we(1)-s_we(1))
  394. dykm = EARTH_RADIUS_M * PI / (e_sn(1)-s_sn(1))
  395. ! If dx,dy specified, however, assume regional grid
  396. else
  397. dlatdeg = dy
  398. dlondeg = dx
  399. dxkm = dlondeg * EARTH_RADIUS_M * PI * 2.0 / 360.0
  400. dykm = dlatdeg * EARTH_RADIUS_M * PI * 2.0 / 360.0
  401. if (known_lat == NAN .or. known_lon == NAN) then
  402. call mprintf(.true.,ERROR,'For lat-lon projection, if dx/dy are specified, '// &
  403. 'a regional domain is assumed, and a ref_lat,ref_lon must also be specified')
  404. end if
  405. end if
  406. end if
  407. ! Manually set truelat2 = truelat1 if truelat2 not specified for Lambert
  408. if (iproj_type == PROJ_LC .and. truelat2 == NAN) then
  409. call mprintf ((truelat1 == NAN), ERROR, "No TRUELAT1 specified for Lambert conformal projection.")
  410. truelat2 = truelat1
  411. end if
  412. n_domains = max_dom
  413. ! For C grid, let ixdim and jydim be the number of velocity points in
  414. ! each direction; for E grid, we will put the row and column back
  415. ! later; maybe this should be changed to be more clear, though.
  416. do i=1,n_domains
  417. ixdim(i) = e_we(i) - s_we(i) + 1
  418. jydim(i) = e_sn(i) - s_sn(i) + 1
  419. end do
  420. if (gridtype == 'E') then
  421. phi = dykm*real(jydim(1)-1)/2.
  422. lambda = dxkm*real(ixdim(1)-1)
  423. end if
  424. ! If the user hasn't supplied a known_x and known_y, assume the center of domain 1
  425. if (gridtype == 'E' .and. (known_x /= NAN .or. known_y /= NAN)) then
  426. call mprintf(.true.,WARN, &
  427. 'Namelist variables ref_x and ref_y cannot be used for NMM grids.'// &
  428. ' (ref_lat, ref_lon) will refer to the center of the coarse grid.')
  429. else if (gridtype == 'C') then
  430. if (known_x == NAN .and. known_y == NAN) then
  431. known_x = ixdim(1) / 2.
  432. known_y = jydim(1) / 2.
  433. else if (known_x == NAN .or. known_y == NAN) then
  434. call mprintf(.true.,ERROR, &
  435. 'In namelist.wps, neither or both of ref_x, ref_y must be specified.')
  436. end if
  437. end if
  438. ! Checks specific to E grid
  439. if (gridtype == 'E') then
  440. ! E grid supports only the rotated lat/lon projection
  441. if (iproj_type /= PROJ_ROTLL) then
  442. call mprintf(.true., WARN, &
  443. 'For the NMM core, projection type must be rotated '// &
  444. 'lat/lon (map_proj=rotated_ll)')
  445. call mprintf(.true.,WARN,'Projection will be set to rotated_ll')
  446. iproj_type = PROJ_ROTLL
  447. end if
  448. ! In the following check, add back the 1 that we had to subtract above
  449. ! for the sake of being consistent with WRF namelist
  450. call mprintf(mod(e_sn(1)+1,2) /= 0, ERROR, &
  451. 'For the NMM core, E_SN must be an even number for grid %i.', i1=1)
  452. do i=2,n_domains
  453. call mprintf((parent_grid_ratio(i) /= 3), WARN, &
  454. 'For the NMM core, the parent_grid_ratio must be 3 for '// &
  455. 'domain %i. A ratio of 3 will be assumed.', i1=i)
  456. parent_grid_ratio(i) = 3
  457. end do
  458. ! Check that nests have an acceptable number of grid points in each dimension
  459. ! do i=2,n_domains
  460. ! rparent_gridpts = real(ixdim(i)+2)/real(parent_grid_ratio(i))
  461. ! if (floor(rparent_gridpts) /= ceiling(rparent_gridpts)) then
  462. ! call mprintf(.true.,ERROR,'For nest %i, e_we must be 3n-2 '// &
  463. ! 'for some integer n > 1.', &
  464. ! i1=i)
  465. ! end if
  466. ! rparent_gridpts = real(jydim(i)+2)/real(parent_grid_ratio(i))
  467. ! if (floor(rparent_gridpts) /= ceiling(rparent_gridpts)) then
  468. ! call mprintf(.true.,ERROR,'For nest %i, e_sn must be 3n-2 '// &
  469. ! 'for some odd integer n > 1.', &
  470. ! i1=i)
  471. ! end if
  472. ! end do
  473. do i=2,n_domains
  474. parent_ll_x(i) = 1.
  475. parent_ll_y(i) = 1.
  476. end do
  477. ! Checks specific to C grid
  478. else if (gridtype == 'C') then
  479. ! C grid does not support the rotated lat/lon projection
  480. call mprintf((iproj_type == PROJ_ROTLL), ERROR, &
  481. 'Rotated lat/lon projection is not supported for the ARW core. '// &
  482. 'Valid projecitons are "lambert", "mercator", "polar", and "lat-lon".')
  483. ! Check that nests have an acceptable number of grid points in each dimension
  484. do i=2,n_domains
  485. rparent_gridpts = real(ixdim(i)-1)/real(parent_grid_ratio(i))
  486. if (floor(rparent_gridpts) /= ceiling(rparent_gridpts)) then
  487. call mprintf(.true.,ERROR,'For nest %i, (e_we-s_we+1) must be one greater '// &
  488. 'than an interger multiple of the parent_grid_ratio of %i.', &
  489. i1=i, i2=parent_grid_ratio(i))
  490. end if
  491. rparent_gridpts = real(jydim(i)-1)/real(parent_grid_ratio(i))
  492. if (floor(rparent_gridpts) /= ceiling(rparent_gridpts)) then
  493. call mprintf(.true.,ERROR,'For nest %i, (e_sn-s_sn+1) must be one greater '// &
  494. 'than an interger multiple of the parent_grid_ratio of %i.', &
  495. i1=i, i2=parent_grid_ratio(i))
  496. end if
  497. end do
  498. ! Check that a nest does not extend outside of its parent grid
  499. nest_outside = .false.
  500. do i=2,n_domains
  501. if (i_parent_start(i) >= ixdim(parent_id(i))) then
  502. call mprintf(.true.,WARN,'Nest %i cannot have i_parent_start outside of parent domain.',i1=i)
  503. nest_outside = .true.
  504. else if (i_parent_start(i) + (ixdim(i) - 1)/parent_grid_ratio(i) > ixdim(parent_id(i))) then
  505. call mprintf(.true.,WARN,'Nest %i extends beyond its parent grid in the west-east direction.',i1=i)
  506. call mprintf(.true.,WARN,' Maximum allowable e_we for current i/j_parent_start is %i.', &
  507. i1=(ixdim(parent_id(i))-i_parent_start(i))*parent_grid_ratio(i)+1 )
  508. nest_outside = .true.
  509. end if
  510. if (j_parent_start(i) >= jydim(parent_id(i))) then
  511. call mprintf(.true.,WARN,'Nest %i cannot have j_parent_start outside of parent domain.',i1=i)
  512. nest_outside = .true.
  513. else if (j_parent_start(i) + (jydim(i) - 1)/parent_grid_ratio(i) > jydim(parent_id(i))) then
  514. call mprintf(.true.,WARN,'Nest %i extends beyond its parent grid in the south-north direction.',i1=i)
  515. call mprintf(.true.,WARN,' Maximum allowable e_sn for current i/j_parent_start is %i.', &
  516. i1=(jydim(parent_id(i))-j_parent_start(i))*parent_grid_ratio(i)+1 )
  517. nest_outside = .true.
  518. end if
  519. end do
  520. if (nest_outside) then
  521. call mprintf(.true.,ERROR,'One or more nested domains extend beyond their parent domains.')
  522. end if
  523. do i=1,n_domains
  524. parent_ll_x(i) = real(i_parent_start(i))
  525. parent_ll_y(i) = real(j_parent_start(i))
  526. parent_ur_x(i) = real(i_parent_start(i))+real(ixdim(i))/real(parent_grid_ratio(i))-1.
  527. parent_ur_y(i) = real(j_parent_start(i))+real(jydim(i))/real(parent_grid_ratio(i))-1.
  528. grid_is_active(i) = active_grid(i)
  529. end do
  530. end if
  531. ! calculate the grid ratio between each domain and the moad (mother of all domains)
  532. ! i.e. the product of parent_grid_ratio traversing down the nest tree
  533. do i=2,n_domains
  534. moad_grid_ratio(i)=moad_grid_ratio(parent_id(i))*parent_grid_ratio(i)
  535. end do
  536. return
  537. 1000 call mprintf(.true.,ERROR,'Error opening file namelist.wps')
  538. end subroutine get_grid_params
  539. end module gridinfo_module