PageRenderTime 42ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/wrfv2_fire/dyn_nmm/module_si_io_nmm.F

http://github.com/jbeezley/wrf-fire
FORTRAN Legacy | 3107 lines | 2044 code | 419 blank | 644 comment | 65 complexity | 0cb16b601e95d14369c5ac03cb4466f9 MD5 | raw file
Possible License(s): AGPL-1.0
  1. MODULE module_si_io_nmm
  2. USE module_optional_input
  3. IMPLICIT NONE
  4. !! FROM MODULE_KINDS
  5. ! The numerical data types defined in this module are:
  6. ! i_byte - specification kind for byte (1-byte) integer variable
  7. ! i_short - specification kind for short (2-byte) integer variable
  8. ! i_long - specification kind for long (4-byte) integer variable
  9. ! i_llong - specification kind for double long (8-byte) integer variable
  10. ! r_single - specification kind for single precision (4-byte) real variable
  11. ! r_double - specification kind for double precision (8-byte) real variable
  12. ! r_quad - specification kind for quad precision (16-byte) real variable
  13. !
  14. ! i_kind - generic specification kind for default integer
  15. ! r_kind - generic specification kind for default floating point
  16. !
  17. !
  18. ! Integer type definitions below
  19. ! Integer types
  20. integer, parameter, public :: i_byte = selected_int_kind(1) ! byte integer
  21. integer, parameter, public :: i_short = selected_int_kind(4) ! short integer
  22. integer, parameter, public :: i_long = selected_int_kind(8) ! long integer
  23. integer, parameter, private :: llong_t = selected_int_kind(16) ! llong integer
  24. integer, parameter, public :: i_llong = max( llong_t, i_long )
  25. ! Expected 8-bit byte sizes of the integer kinds
  26. integer, parameter, public :: num_bytes_for_i_byte = 1
  27. integer, parameter, public :: num_bytes_for_i_short = 2
  28. integer, parameter, public :: num_bytes_for_i_long = 4
  29. integer, parameter, public :: num_bytes_for_i_llong = 8
  30. ! Define arrays for default definition
  31. integer, parameter, private :: num_i_kinds = 4
  32. integer, parameter, dimension( num_i_kinds ), private :: integer_types = (/ &
  33. i_byte, i_short, i_long, i_llong /)
  34. integer, parameter, dimension( num_i_kinds ), private :: integer_byte_sizes = (/ &
  35. num_bytes_for_i_byte, num_bytes_for_i_short, &
  36. num_bytes_for_i_long, num_bytes_for_i_llong /)
  37. ! Default values
  38. ! **** CHANGE THE FOLLOWING TO CHANGE THE DEFAULT INTEGER TYPE KIND ***
  39. integer, parameter, private :: default_integer = 2 ! 1=byte,
  40. ! 2=short,
  41. ! 3=long,
  42. ! 4=llong
  43. integer, parameter, public :: i_kind = integer_types( default_integer )
  44. integer, parameter, public :: num_bytes_for_i_kind = &
  45. integer_byte_sizes( default_integer )
  46. ! Real definitions below
  47. ! Real types
  48. integer, parameter, public :: r_single = selected_real_kind(6) ! single precision
  49. integer, parameter, public :: r_double = selected_real_kind(15) ! double precision
  50. integer, parameter, private :: quad_t = selected_real_kind(20) ! quad precision
  51. integer, parameter, public :: r_quad = max( quad_t, r_double )
  52. ! Expected 8-bit byte sizes of the real kinds
  53. integer, parameter, public :: num_bytes_for_r_single = 4
  54. integer, parameter, public :: num_bytes_for_r_double = 8
  55. integer, parameter, public :: num_bytes_for_r_quad = 16
  56. ! Define arrays for default definition
  57. integer, parameter, private :: num_r_kinds = 3
  58. integer, parameter, dimension( num_r_kinds ), private :: real_kinds = (/ &
  59. r_single, r_double, r_quad /)
  60. integer, parameter, dimension( num_r_kinds ), private :: real_byte_sizes = (/ &
  61. num_bytes_for_r_single, num_bytes_for_r_double, &
  62. num_bytes_for_r_quad /)
  63. ! Default values
  64. ! **** CHANGE THE FOLLOWING TO CHANGE THE DEFAULT REAL TYPE KIND ***
  65. integer, parameter, private :: default_real = 2 ! 1=single,
  66. ! 2=double,
  67. !! END FROM MODULE_KINDS
  68. ! Input 3D meteorological fields.
  69. REAL , DIMENSION(:,:,:) , ALLOCATABLE :: u_input , v_input , &
  70. q_input , t_input
  71. ! Input 3D LSM fields.
  72. REAL , DIMENSION(:,:,:) , ALLOCATABLE :: landuse_frac_input , &
  73. soil_top_cat_input , &
  74. soil_bot_cat_input
  75. REAL, ALLOCATABLE:: htm_in(:,:,:),vtm_in(:,:,:)
  76. ! Input 2D surface fields.
  77. REAL , DIMENSION(:,:) , ALLOCATABLE,save :: soilt010_input , soilt040_input , &
  78. soilt100_input , soilt200_input , &
  79. soilm010_input , soilm040_input , &
  80. soilm100_input , soilm200_input , &
  81. psfc_in,pmsl
  82. REAL , DIMENSION(:,:) , ALLOCATABLE :: lat_wind, lon_wind
  83. REAL , DIMENSION(:) , ALLOCATABLE :: DETA_in, AETA_in, ETAX_in
  84. REAL , DIMENSION(:) , ALLOCATABLE :: DETA1_in, AETA1_in, ETA1_in
  85. REAL , DIMENSION(:) , ALLOCATABLE :: DETA2_in, AETA2_in, ETA2_in, DFL_in
  86. REAL , DIMENSION(:,:,:), ALLOCATABLE,save :: st_inputx , sm_inputx, sw_inputx
  87. ! Local input arrays
  88. REAL,DIMENSION(:,:),ALLOCATABLE :: dum2d
  89. INTEGER,DIMENSION(:,:),ALLOCATABLE :: idum2d
  90. REAL,DIMENSION(:,:,:),ALLOCATABLE :: dum3d
  91. LOGICAL , SAVE :: first_time_in = .TRUE.
  92. INTEGER :: flag_soilt010 , flag_soilt100 , flag_soilt200 , &
  93. flag_soilm010 , flag_soilm100 , flag_soilm200
  94. ! Some constants to allow simple dimensions in the defined types
  95. ! given below.
  96. INTEGER, PARAMETER :: var_maxdims = 5
  97. INTEGER, PARAMETER :: max_staggers_xy_new = 4
  98. INTEGER, PARAMETER :: max_staggers_xy_old = 3
  99. INTEGER, PARAMETER :: max_staggers_z = 2
  100. INTEGER, PARAMETER :: max_standard_lats = 4
  101. INTEGER, PARAMETER :: max_standard_lons = 4
  102. INTEGER, PARAMETER :: max_fg_variables = 200
  103. INTEGER, PARAMETER :: max_vertical_levels = 2000
  104. ! This module defines the items needed for the WRF metadata
  105. ! which is broken up into three levels:
  106. ! Global metadata: Those things which apply to the
  107. ! entire simulation that are
  108. ! independent of time, domain, or
  109. ! variable
  110. !
  111. ! Domain metadata: Those things which apply to
  112. ! a single domain (this may
  113. ! or may not be time dependent)
  114. !
  115. ! Variable metadata: Those things which apply to
  116. ! a specific variable at a
  117. ! specific time
  118. !
  119. ! The variable names and definitions can be
  120. ! found in the wrf_metadata spec, which is still
  121. ! a living document as coding goes on. The names
  122. ! may not match exactly, but you should be able
  123. ! to figure things out.
  124. !
  125. TYPE wrf_var_metadata
  126. CHARACTER (LEN=8) :: name
  127. CHARACTER (LEN=16) :: units
  128. CHARACTER (LEN=80) :: description
  129. INTEGER :: domain_id
  130. INTEGER :: ndim
  131. INTEGER :: dim_val (var_maxdims)
  132. CHARACTER(LEN=4) :: dim_desc (var_maxdims)
  133. INTEGER :: start_index(var_maxdims)
  134. INTEGER :: stop_index(var_maxdims)
  135. INTEGER :: h_stagger_index
  136. INTEGER :: v_stagger_index
  137. CHARACTER(LEN=8) :: array_order
  138. CHARACTER(LEN=4) :: field_type
  139. CHARACTER(LEN=8) :: field_source_prog
  140. CHARACTER(LEN=80) :: source_desc
  141. CHARACTER(LEN=8) :: field_time_type
  142. INTEGER :: vt_date_start
  143. REAL :: vt_time_start
  144. INTEGER :: vt_date_stop
  145. REAL :: vt_time_stop
  146. END TYPE wrf_var_metadata
  147. TYPE(wrf_var_metadata) :: var_meta , var_info
  148. TYPE wrf_domain_metadata
  149. INTEGER :: id
  150. INTEGER :: parent_id
  151. CHARACTER(LEN=8) :: dyn_init_src
  152. CHARACTER(LEN=8) :: static_init_src
  153. INTEGER :: vt_date
  154. REAL :: vt_time
  155. INTEGER :: origin_parent_x
  156. INTEGER :: origin_parent_y
  157. INTEGER :: ratio_to_parent
  158. REAL :: delta_x
  159. REAL :: delta_y
  160. REAL :: top_level
  161. INTEGER :: origin_parent_z
  162. REAL :: corner_lats_new(4,max_staggers_xy_new)
  163. REAL :: corner_lons_new(4,max_staggers_xy_new)
  164. REAL :: corner_lats_old(4,max_staggers_xy_old)
  165. REAL :: corner_lons_old(4,max_staggers_xy_old)
  166. INTEGER :: xdim
  167. INTEGER :: ydim
  168. INTEGER :: zdim
  169. END TYPE wrf_domain_metadata
  170. TYPE(wrf_domain_metadata) :: dom_meta
  171. TYPE wrf_global_metadata
  172. CHARACTER(LEN=80) :: simulation_name
  173. CHARACTER(LEN=80) :: user_desc
  174. INTEGER :: si_version
  175. INTEGER :: analysis_version
  176. INTEGER :: wrf_version
  177. INTEGER :: post_version
  178. CHARACTER(LEN=32) :: map_projection
  179. REAL :: moad_known_lat
  180. REAL :: moad_known_lon
  181. CHARACTER(LEN=8) :: moad_known_loc
  182. REAL :: moad_stand_lats(max_standard_lats)
  183. REAL :: moad_stand_lons(max_standard_lons)
  184. REAL :: moad_delta_x
  185. REAL :: moad_delta_y
  186. CHARACTER(LEN=4) :: horiz_stagger_type
  187. INTEGER :: num_stagger_xy
  188. REAL :: stagger_dir_x_new(max_staggers_xy_new)
  189. REAL :: stagger_dir_y_new(max_staggers_xy_new)
  190. REAL :: stagger_dir_x_old(max_staggers_xy_old)
  191. REAL :: stagger_dir_y_old(max_staggers_xy_old)
  192. INTEGER :: num_stagger_z
  193. REAL :: stagger_dir_z(max_staggers_z)
  194. CHARACTER(LEN=8) :: vertical_coord
  195. INTEGER :: num_domains
  196. INTEGER :: init_date
  197. REAL :: init_time
  198. INTEGER :: end_date
  199. REAL :: end_time
  200. CHARACTER(LEN=4) :: lu_source
  201. INTEGER :: lu_water
  202. INTEGER :: lu_ice
  203. END TYPE wrf_global_metadata
  204. TYPE(wrf_global_metadata) :: global_meta
  205. CONTAINS
  206. SUBROUTINE read_si ( grid, file_date_string )
  207. USE module_soil_pre
  208. USE module_domain
  209. IMPLICIT NONE
  210. TYPE(domain) , INTENT(INOUT) :: grid
  211. CHARACTER (LEN=19) , INTENT(IN) :: file_date_string
  212. INTEGER :: ids,ide,jds,jde,kds,kde &
  213. ,ims,ime,jms,jme,kms,kme &
  214. ,its,ite,jts,jte,kts,kte
  215. INTEGER :: i , j , k , loop, IMAX, JMAX
  216. REAL :: dummy
  217. CHARACTER (LEN= 8) :: dummy_char
  218. CHARACTER (LEN=256) :: dummy_char_256
  219. INTEGER :: ok , map_proj , ok_open
  220. REAL :: pt
  221. INTEGER :: num_veg_cat , num_soil_top_cat , num_soil_bot_cat
  222. SELECT CASE ( model_data_order )
  223. CASE ( DATA_ORDER_ZXY )
  224. kds = grid%sd31 ; kde = grid%ed31 ;
  225. ids = grid%sd32 ; ide = grid%ed32 ;
  226. jds = grid%sd33 ; jde = grid%ed33 ;
  227. kms = grid%sm31 ; kme = grid%em31 ;
  228. ims = grid%sm32 ; ime = grid%em32 ;
  229. jms = grid%sm33 ; jme = grid%em33 ;
  230. kts = grid%sp31 ; kte = grid%ep31 ; ! tile is entire patch
  231. its = grid%sp32 ; ite = grid%ep32 ; ! tile is entire patch
  232. jts = grid%sp33 ; jte = grid%ep33 ; ! tile is entire patch
  233. CASE ( DATA_ORDER_XYZ )
  234. ids = grid%sd31 ; ide = grid%ed31 ;
  235. jds = grid%sd32 ; jde = grid%ed32 ;
  236. kds = grid%sd33 ; kde = grid%ed33 ;
  237. ims = grid%sm31 ; ime = grid%em31 ;
  238. jms = grid%sm32 ; jme = grid%em32 ;
  239. kms = grid%sm33 ; kme = grid%em33 ;
  240. its = grid%sp31 ; ite = grid%ep31 ; ! tile is entire patch
  241. jts = grid%sp32 ; jte = grid%ep32 ; ! tile is entire patch
  242. kts = grid%sp33 ; kte = grid%ep33 ; ! tile is entire patch
  243. CASE ( DATA_ORDER_XZY )
  244. ids = grid%sd31 ; ide = grid%ed31 ;
  245. kds = grid%sd32 ; kde = grid%ed32 ;
  246. jds = grid%sd33 ; jde = grid%ed33 ;
  247. ims = grid%sm31 ; ime = grid%em31 ;
  248. kms = grid%sm32 ; kme = grid%em32 ;
  249. jms = grid%sm33 ; jme = grid%em33 ;
  250. its = grid%sp31 ; ite = grid%ep31 ; ! tile is entire patch
  251. kts = grid%sp32 ; kte = grid%ep32 ; ! tile is entire patch
  252. jts = grid%sp33 ; jte = grid%ep33 ; ! tile is entire patch
  253. END SELECT
  254. ! Initialize what soil temperature and moisture is available.
  255. ! write(0,*) 'dum3d I allocs: ', ids,ide-1
  256. ! write(0,*) 'dum3d J allocs: ', jds,jde-1
  257. ! write(0,*) 'dum3d K allocs: ', kds,kde-1
  258. flag_st000010 = 0
  259. flag_st010040 = 0
  260. flag_st040100 = 0
  261. flag_st100200 = 0
  262. flag_sm000010 = 0
  263. flag_sm010040 = 0
  264. flag_sm040100 = 0
  265. flag_sm100200 = 0
  266. flag_st010200 = 0
  267. flag_sm010200 = 0
  268. flag_soilt010 = 0
  269. flag_soilt040 = 0
  270. flag_soilt100 = 0
  271. flag_soilt200 = 0
  272. flag_soilm010 = 0
  273. flag_soilm040 = 0
  274. flag_soilm100 = 0
  275. flag_soilm200 = 0
  276. flag_sst = 0
  277. flag_toposoil = 0
  278. ! How many soil levels have we found? Well, right now, none.
  279. num_st_levels_input = 0
  280. num_sm_levels_input = 0
  281. st_levels_input = -1
  282. sm_levels_input = -1
  283. ! Get the space for the data if this is the first time here.
  284. write(6,*) 'enter read_si...first_time_in:: ', first_time_in
  285. IF ( first_time_in ) THEN
  286. CLOSE(12)
  287. OPEN ( FILE = 'real_input_nm.global.metadata' , &
  288. UNIT = 12 , &
  289. STATUS = 'OLD' , &
  290. ACCESS = 'SEQUENTIAL' , &
  291. FORM = 'UNFORMATTED' , &
  292. IOSTAT = ok_open )
  293. IF ( ok_open .NE. 0 ) THEN
  294. PRINT '(A)','You asked for WRF SI data, but no real_input_nm.global.metadata file exists.'
  295. STOP 'No_real_input_nm.global.metadata_exists'
  296. END IF
  297. READ(12) global_meta%simulation_name, global_meta%user_desc, &
  298. global_meta%si_version, global_meta%analysis_version, &
  299. global_meta%wrf_version, global_meta%post_version
  300. REWIND (12)
  301. IF ( global_meta%si_version .EQ. 1 ) THEN
  302. READ(12) global_meta%simulation_name, global_meta%user_desc, &
  303. global_meta%si_version, global_meta%analysis_version, &
  304. global_meta%wrf_version, global_meta%post_version, &
  305. global_meta%map_projection, global_meta%moad_known_lat, &
  306. global_meta%moad_known_lon, global_meta%moad_known_loc, &
  307. global_meta%moad_stand_lats, global_meta%moad_stand_lons, &
  308. global_meta%moad_delta_x, global_meta%moad_delta_y, &
  309. global_meta%horiz_stagger_type, global_meta%num_stagger_xy, &
  310. global_meta%stagger_dir_x_old, global_meta%stagger_dir_y_old, &
  311. global_meta%num_stagger_z, global_meta%stagger_dir_z, &
  312. global_meta%vertical_coord, global_meta%num_domains, &
  313. global_meta%init_date, global_meta%init_time, &
  314. global_meta%end_date, global_meta%end_time
  315. ELSE IF ( global_meta%si_version .EQ. 2 ) THEN
  316. READ(12) global_meta%simulation_name, global_meta%user_desc, &
  317. global_meta%si_version, global_meta%analysis_version, &
  318. global_meta%wrf_version, global_meta%post_version, &
  319. global_meta%map_projection, global_meta%moad_known_lat, &
  320. global_meta%moad_known_lon, global_meta%moad_known_loc, &
  321. global_meta%moad_stand_lats, global_meta%moad_stand_lons, &
  322. global_meta%moad_delta_x, global_meta%moad_delta_y, &
  323. global_meta%horiz_stagger_type, global_meta%num_stagger_xy, &
  324. global_meta%stagger_dir_x_new, global_meta%stagger_dir_y_new, &
  325. global_meta%num_stagger_z, global_meta%stagger_dir_z, &
  326. global_meta%vertical_coord, global_meta%num_domains, &
  327. global_meta%init_date, global_meta%init_time, &
  328. global_meta%end_date, global_meta%end_time , &
  329. global_meta%lu_source, global_meta%lu_water, global_meta%lu_ice
  330. END IF
  331. CLOSE (12)
  332. print *,'GLOBAL METADATA'
  333. print *,'global_meta%simulation_name', global_meta%simulation_name
  334. print *,'global_meta%user_desc', global_meta%user_desc
  335. print *,'global_meta%user_desc', global_meta%user_desc
  336. print *,'global_meta%si_version', global_meta%si_version
  337. print *,'global_meta%analysis_version', global_meta%analysis_version
  338. print *,'global_meta%wrf_version', global_meta%wrf_version
  339. print *,'global_meta%post_version', global_meta%post_version
  340. print *,'global_meta%map_projection', global_meta%map_projection
  341. print *,'global_meta%moad_known_lat', global_meta%moad_known_lat
  342. print *,'global_meta%moad_known_lon', global_meta%moad_known_lon
  343. print *,'global_meta%moad_known_loc', global_meta%moad_known_loc
  344. print *,'global_meta%moad_stand_lats', global_meta%moad_stand_lats
  345. print *,'global_meta%moad_stand_lons', global_meta%moad_stand_lons
  346. print *,'global_meta%moad_delta_x', global_meta%moad_delta_x
  347. print *,'global_meta%moad_delta_y', global_meta%moad_delta_y
  348. print *,'global_meta%horiz_stagger_type', global_meta%horiz_stagger_type
  349. print *,'global_meta%num_stagger_xy', global_meta%num_stagger_xy
  350. IF ( global_meta%si_version .EQ. 1 ) THEN
  351. print *,'global_meta%stagger_dir_x', global_meta%stagger_dir_x_old
  352. print *,'global_meta%stagger_dir_y', global_meta%stagger_dir_y_old
  353. ELSE IF ( global_meta%si_version .EQ. 2 ) THEN
  354. print *,'global_meta%stagger_dir_x', global_meta%stagger_dir_x_new
  355. print *,'global_meta%stagger_dir_y', global_meta%stagger_dir_y_new
  356. END IF
  357. print *,'global_meta%num_stagger_z', global_meta%num_stagger_z
  358. print *,'global_meta%stagger_dir_z', global_meta%stagger_dir_z
  359. print *,'global_meta%vertical_coord', global_meta%vertical_coord
  360. print *,'global_meta%num_domains', global_meta%num_domains
  361. print *,'global_meta%init_date', global_meta%init_date
  362. print *,'global_meta%init_time', global_meta%init_time
  363. print *,'global_meta%end_date', global_meta%end_date
  364. print *,'global_meta%end_time', global_meta%end_time
  365. IF ( global_meta%si_version .EQ. 2 ) THEN
  366. print *,'global_meta%lu_source', global_meta%lu_source
  367. print *,'global_meta%lu_water', global_meta%lu_water
  368. print *,'global_meta%lu_ice', global_meta%lu_ice
  369. END IF
  370. print *,' '
  371. ! 1D - this is the definition of the vertical coordinate.
  372. IF (.NOT. ALLOCATED (DETA_in)) ALLOCATE(DETA_in(kds:kde-1))
  373. IF (.NOT. ALLOCATED (AETA_in)) ALLOCATE(AETA_in(kds:kde-1))
  374. IF (.NOT. ALLOCATED (ETAX_in)) ALLOCATE(ETAX_in(kds:kde))
  375. IF (.NOT. ALLOCATED (DETA1_in)) ALLOCATE(DETA1_in(kds:kde-1))
  376. IF (.NOT. ALLOCATED (AETA1_in)) ALLOCATE(AETA1_in(kds:kde-1))
  377. IF (.NOT. ALLOCATED (ETA1_in)) ALLOCATE(ETA1_in(kds:kde))
  378. IF (.NOT. ALLOCATED (DETA2_in)) ALLOCATE(DETA2_in(kds:kde-1))
  379. IF (.NOT. ALLOCATED (AETA2_in)) ALLOCATE(AETA2_in(kds:kde-1))
  380. IF (.NOT. ALLOCATED (ETA2_in)) ALLOCATE(ETA2_in(kds:kde))
  381. IF (.NOT. ALLOCATED (DFL_in)) ALLOCATE(DFL_in(kds:kde))
  382. ! 3D met
  383. IF (.NOT. ALLOCATED (u_input) ) ALLOCATE ( u_input(its:ite,jts:jte,kts:kte) )
  384. IF (.NOT. ALLOCATED (v_input) ) ALLOCATE ( v_input(its:ite,jts:jte,kts:kte) )
  385. IF (.NOT. ALLOCATED (q_input) ) ALLOCATE ( q_input(its:ite,jts:jte,kts:kte) )
  386. IF (.NOT. ALLOCATED (t_input) ) ALLOCATE ( t_input(its:ite,jts:jte,kts:kte) )
  387. IF (.NOT. ALLOCATED (htm_in) ) ALLOCATE ( htm_in(its:ite,jts:jte,kts:kte) )
  388. IF (.NOT. ALLOCATED (vtm_in) ) ALLOCATE ( vtm_in(its:ite,jts:jte,kts:kte) )
  389. ! 2D pressure fields
  390. IF (.NOT. ALLOCATED (pmsl) ) ALLOCATE ( pmsl(its:ite,jts:jte) )
  391. IF (.NOT. ALLOCATED (psfc_in) ) ALLOCATE ( psfc_in(its:ite,jts:jte) )
  392. ! 2D - for LSM, these are computed from the categorical precentage values.
  393. ! 2D - for LSM, the various soil temperature and moisture levels that are available.
  394. IF (.NOT. ALLOCATED (st_inputx)) ALLOCATE (st_inputx(its:ite,jts:jte,num_st_levels_alloc))
  395. IF (.NOT. ALLOCATED (sm_inputx)) ALLOCATE (sm_inputx(its:ite,jts:jte,num_st_levels_alloc))
  396. IF (.NOT. ALLOCATED (sw_inputx)) ALLOCATE (sw_inputx(its:ite,jts:jte,num_st_levels_alloc))
  397. IF (.NOT. ALLOCATED (soilt010_input) ) ALLOCATE ( soilt010_input(its:ite,jts:jte) )
  398. IF (.NOT. ALLOCATED (soilt040_input) ) ALLOCATE ( soilt040_input(its:ite,jts:jte) )
  399. IF (.NOT. ALLOCATED (soilt100_input) ) ALLOCATE ( soilt100_input(its:ite,jts:jte) )
  400. IF (.NOT. ALLOCATED (soilt200_input) ) ALLOCATE ( soilt200_input(its:ite,jts:jte) )
  401. IF (.NOT. ALLOCATED (soilm010_input) ) ALLOCATE ( soilm010_input(its:ite,jts:jte) )
  402. IF (.NOT. ALLOCATED (soilm040_input) ) ALLOCATE ( soilm040_input(its:ite,jts:jte) )
  403. IF (.NOT. ALLOCATED (soilm100_input) ) ALLOCATE ( soilm100_input(its:ite,jts:jte) )
  404. IF (.NOT. ALLOCATED (soilm200_input) ) ALLOCATE ( soilm200_input(its:ite,jts:jte) )
  405. IF (.NOT. ALLOCATED (lat_wind) ) ALLOCATE (lat_wind(its:ite,jts:jte))
  406. IF (.NOT. ALLOCATED (lon_wind) ) ALLOCATE (lon_wind(its:ite,jts:jte))
  407. ! Local arrays
  408. IF (.NOT. ALLOCATED (dum2d) ) ALLOCATE (dum2d(IDS:IDE-1,JDS:JDE-1))
  409. IF (.NOT. ALLOCATED (idum2d) ) ALLOCATE (idum2d(IDS:IDE-1,JDS:JDE-1))
  410. IF (.NOT. ALLOCATED (dum3d) ) ALLOCATE (dum3d(IDS:IDE-1,JDS:JDE-1,KDS:KDE-1))
  411. END IF
  412. CLOSE(13)
  413. write(6,*) 'file_date_string: ', file_date_string
  414. write(6,*) 'opening real_input_nm.d01.'//file_date_string//' as unit 13'
  415. OPEN ( FILE = 'real_input_nm.d01.'//file_date_string , &
  416. UNIT = 13 , &
  417. STATUS = 'OLD' , &
  418. ACCESS = 'SEQUENTIAL' , &
  419. FORM = 'UNFORMATTED' )
  420. IF ( global_meta%si_version .EQ. 1 ) THEN
  421. READ (13) dom_meta%id,dom_meta%parent_id,dom_meta%dyn_init_src,&
  422. dom_meta%static_init_src, dom_meta%vt_date, dom_meta%vt_time, &
  423. dom_meta%origin_parent_x, dom_meta%origin_parent_y, &
  424. dom_meta%ratio_to_parent, dom_meta%delta_x, dom_meta%delta_y, &
  425. dom_meta%top_level, dom_meta%origin_parent_z, &
  426. dom_meta%corner_lats_old, dom_meta%corner_lons_old, dom_meta%xdim, &
  427. dom_meta%ydim, dom_meta%zdim
  428. ELSE IF ( global_meta%si_version .EQ. 2 ) THEN
  429. READ (13) dom_meta%id,dom_meta%parent_id,dom_meta%dyn_init_src,&
  430. dom_meta%static_init_src, dom_meta%vt_date, dom_meta%vt_time, &
  431. dom_meta%origin_parent_x, dom_meta%origin_parent_y, &
  432. dom_meta%ratio_to_parent, dom_meta%delta_x, dom_meta%delta_y, &
  433. dom_meta%top_level, dom_meta%origin_parent_z, &
  434. dom_meta%corner_lats_new, dom_meta%corner_lons_new, dom_meta%xdim, &
  435. dom_meta%ydim, dom_meta%zdim
  436. END IF
  437. print *,'DOMAIN METADATA'
  438. print *,'dom_meta%id=', dom_meta%id
  439. print *,'dom_meta%parent_id=', dom_meta%parent_id
  440. print *,'dom_meta%dyn_init_src=', dom_meta%dyn_init_src
  441. print *,'dom_meta%static_init_src=', dom_meta%static_init_src
  442. print *,'dom_meta%vt_date=', dom_meta%vt_date
  443. print *,'dom_meta%vt_time=', dom_meta%vt_time
  444. print *,'dom_meta%origin_parent_x=', dom_meta%origin_parent_x
  445. print *,'dom_meta%origin_parent_y=', dom_meta%origin_parent_y
  446. print *,'dom_meta%ratio_to_parent=', dom_meta%ratio_to_parent
  447. print *,'dom_meta%delta_x=', dom_meta%delta_x
  448. print *,'dom_meta%delta_y=', dom_meta%delta_y
  449. print *,'dom_meta%top_level=', dom_meta%top_level
  450. print *,'dom_meta%origin_parent_z=', dom_meta%origin_parent_z
  451. IF ( global_meta%si_version .EQ. 1 ) THEN
  452. print *,'dom_meta%corner_lats=', dom_meta%corner_lats_old
  453. print *,'dom_meta%corner_lons=', dom_meta%corner_lons_old
  454. ELSE IF ( global_meta%si_version .EQ. 2 ) THEN
  455. print *,'dom_meta%corner_lats=', dom_meta%corner_lats_new
  456. print *,'dom_meta%corner_lons=', dom_meta%corner_lons_new
  457. END IF
  458. print *,'dom_meta%xdim=', dom_meta%xdim
  459. print *,'dom_meta%ydim=', dom_meta%ydim
  460. print *,'dom_meta%zdim=', dom_meta%zdim
  461. print *,' '
  462. ! A simple domain size test.
  463. !! relax constraint, as model namelist has +1 for i and j, while
  464. !! si data has true dimensions
  465. IF ( abs(dom_meta%xdim - (ide-1)) .gt. 1 &
  466. .OR. abs(dom_meta%ydim - (jde-1)) .gt. 1 &
  467. .OR. abs(dom_meta%zdim - (kde-1)) .gt. 1) THEN
  468. PRINT '(A)','Namelist does not match the input data.'
  469. PRINT '(A,3I5,A)','Namelist dimensions =',ide-1,jde-1,kde-1,'.'
  470. PRINT '(A,3I5,A)','Input data dimensions =',dom_meta%xdim,dom_meta%ydim,dom_meta%zdim,'.'
  471. STOP 'Wrong_data_size'
  472. END IF
  473. ! How about the grid distance? Is it the same as in the namelist?
  474. IF ( global_meta%si_version .EQ. 1 ) THEN
  475. CALL nl_set_cen_lat ( grid%id , ( dom_meta%corner_lats_old(1,1) + dom_meta%corner_lats_old(2,1) + &
  476. dom_meta%corner_lats_old(3,1) + dom_meta%corner_lats_old(4,1) ) * 0.25 )
  477. ELSE IF ( ( global_meta%si_version .EQ. 2 ) .AND. ( global_meta%moad_known_loc(1:6) .EQ. 'CENTER' ) ) THEN
  478. CALL nl_set_cen_lat ( grid%id , global_meta%moad_known_lat )
  479. ELSE IF ( global_meta%si_version .EQ. 2 ) THEN
  480. CALL nl_set_cen_lat ( grid%id , ( dom_meta%corner_lats_new(1,1) + dom_meta%corner_lats_new(2,1) + &
  481. dom_meta%corner_lats_new(3,1) + dom_meta%corner_lats_new(4,1) ) * 0.25 )
  482. END IF
  483. !!! might be trouble here
  484. CALL nl_set_cen_lon ( grid%id , global_meta%moad_stand_lons(1) )
  485. !!!!!
  486. write(6,*) 'set_cen_lat... global_meta%moad_stand_lats(1): ', global_meta%moad_stand_lats(1)
  487. CALL nl_set_cen_lat ( grid%id , global_meta%moad_stand_lats(1) )
  488. !!!!!
  489. CALL nl_set_truelat1 ( grid%id , global_meta%moad_stand_lats(1) )
  490. CALL nl_set_truelat2 ( grid%id , global_meta%moad_stand_lats(2) )
  491. pt = dom_meta%top_level
  492. IF ( global_meta%map_projection(1:17) .EQ. 'LAMBERT CONFORMAL' ) THEN
  493. map_proj = 1
  494. ELSE IF ( global_meta%map_projection(1:19) .EQ. 'POLAR STEREOGRAPHIC' ) THEN
  495. map_proj = 2
  496. ELSE IF ( global_meta%map_projection(1: 8) .EQ. 'MERCATOR' ) THEN
  497. map_proj = 3
  498. ELSE IF ( global_meta%map_projection(1:14) .EQ. 'ROTATED LATLON' ) THEN
  499. map_proj = 203 !?
  500. ELSE
  501. PRINT '(A,A,A)','Undefined map projection: ',TRIM(global_meta%map_projection(1:20)),'.'
  502. STOP 'Undefined_map_proj_si'
  503. END IF
  504. CALL nl_set_map_proj ( grid%id , map_proj )
  505. ! write(0,*) 'global_meta%si_version: ', global_meta%si_version
  506. ! write(0,*) 'global_meta%lu_source: ', global_meta%lu_source
  507. ! write(0,*) 'global_meta%lu_water: ', global_meta%lu_water
  508. IF ( global_meta%si_version .EQ. 1 ) THEN
  509. CALL nl_set_mminlu (grid%id, 'USGS' )
  510. CALL nl_set_iswater (grid%id, 16 )
  511. ELSE IF ( global_meta%si_version .EQ. 2 ) THEN
  512. CALL nl_set_mminlu ( grid%id, global_meta%lu_source )
  513. CALL nl_set_iswater (grid%id, global_meta%lu_water )
  514. CALL nl_set_isice (grid%id, global_meta%lu_ice )
  515. END IF
  516. CALL nl_set_gmt (grid%id, dom_meta%vt_time / 3600. )
  517. CALL nl_set_julyr (grid%id, dom_meta%vt_date / 1000 )
  518. CALL nl_set_julday (grid%id, dom_meta%vt_date - ( dom_meta%vt_date / 1000 ) * 1000 )
  519. write(6,*) 'start reading from unit 13'
  520. read_all_the_data : DO
  521. READ (13,IOSTAT=OK) var_info%name, var_info%units, &
  522. var_info%description, var_info%domain_id, var_info%ndim, &
  523. var_info%dim_val, var_info%dim_desc, var_info%start_index, &
  524. var_info%stop_index, var_info%h_stagger_index, var_info%v_stagger_index,&
  525. var_info%array_order, var_info%field_type, var_info%field_source_prog, &
  526. var_info%source_desc, var_info%field_time_type, var_info%vt_date_start, &
  527. var_info%vt_time_start, var_info%vt_date_stop, var_info%vt_time_stop
  528. IF ( OK .NE. 0 ) THEN
  529. PRINT '(A,A,A)','End of file found for real_input_nm.d01.',file_date_string,'.'
  530. EXIT read_all_the_data
  531. END IF
  532. ! print *,'VARIABLE METADATA'
  533. PRINT '(A,A)','var_info%name=', var_info%name
  534. ! print *,'var_info%units=', var_info%units
  535. ! print *,'var_info%description=', var_info%description
  536. ! print *,'var_info%domain_id=', var_info%domain_id
  537. ! print *,'var_info%ndim=', var_info%ndim
  538. ! print *,'var_info%dim_val=', var_info%dim_val
  539. ! print *,'var_info%dim_desc=', var_info%dim_desc
  540. ! print *,'var_info%start_index=', var_info%start_index
  541. ! print *,'var_info%stop_index=', var_info%stop_index
  542. ! print *,'var_info%h_stagger_index=', var_info%h_stagger_index
  543. ! print *,'var_info%v_stagger_index=', var_info%v_stagger_index
  544. ! print *,'var_info%array_order=', var_info%array_order
  545. ! print *,'var_info%field_type=', var_info%field_type
  546. ! print *,'var_info%field_source_prog=', var_info%field_source_prog
  547. ! print *,'var_info%source_desc=', var_info%source_desc
  548. ! print *,'var_info%field_time_type=', var_info%field_time_type
  549. ! print *,'var_info%vt_date_start=', var_info%vt_date_start
  550. ! print *,'var_info%vt_time_start=', var_info%vt_time_start
  551. ! print *,'var_info%vt_date_stop=', var_info%vt_date_stop
  552. ! print *,'var_info%vt_time_stop=', var_info%vt_time_stop
  553. JMAX=min(JDE-1,JTE)
  554. IMAX=min(IDE-1,ITE)
  555. ! 3D meteorological fields.
  556. ! write(0,*)' read_si var_info%name=',var_info%name(1:8)
  557. IF ( var_info%name(1:8) .EQ. 'T ' ) THEN
  558. READ (13) dum3d
  559. do k=kts,kte-1
  560. do j=jts,JMAX
  561. do i=its,IMAX
  562. t_input(i,j,k)=dum3d(i,j,k)
  563. enddo
  564. enddo
  565. enddo
  566. ELSE IF ( var_info%name(1:8) .EQ. 'U ' ) THEN
  567. READ (13) dum3d
  568. do k=kts,kte-1
  569. do j=jts,JMAX
  570. do i=its,IMAX
  571. u_input(i,j,k)=dum3d(i,j,k)
  572. enddo
  573. enddo
  574. enddo
  575. ELSE IF ( var_info%name(1:8) .EQ. 'V ' ) THEN
  576. READ (13) dum3d
  577. do k=kts,kte-1
  578. do j=jts,JMAX
  579. do i=its,IMAX
  580. v_input(i,j,k)=dum3d(i,j,k)
  581. enddo
  582. enddo
  583. enddo
  584. ELSE IF ( var_info%name(1:8) .EQ. 'Q ' ) THEN
  585. READ (13) dum3d
  586. do k=kts,kte-1
  587. do j=jts,JMAX
  588. do i=its,IMAX
  589. q_input(i,j,k)=dum3d(i,j,k)
  590. enddo
  591. enddo
  592. enddo
  593. ! 3D LSM fields. Don't know the 3rd dimension until we read it in.
  594. ELSE IF ( var_info%name(1:8) .EQ. 'LANDUSEF' ) THEN
  595. IF ( ( first_time_in ) .AND. ( .NOT. ALLOCATED ( landuse_frac_input) ) ) THEN
  596. ALLOCATE (landuse_frac_input(its:ite,jts:jte,var_info%dim_val(3)) )
  597. END IF
  598. READ (13) (((dum3d(i,j,k),i=ids,ide-1),j=jds,jde-1),k=1,var_info%dim_val(3))
  599. do k=1,var_info%dim_val(3)
  600. do j=jts,JMAX
  601. do i=its,IMAX
  602. landuse_frac_input(i,j,k)=dum3d(i,j,k)
  603. enddo
  604. enddo
  605. enddo
  606. ELSE IF ( var_info%name(1:8) .EQ. 'SOILCTOP' ) THEN
  607. IF ( ( first_time_in ) .AND. ( .NOT. ALLOCATED ( soil_top_cat_input) ) ) THEN
  608. ALLOCATE (soil_top_cat_input(its:ite,jts:jte,var_info%dim_val(3)) )
  609. END IF
  610. READ (13) (((dum3d(i,j,k),i=ids,ide-1),j=jds,jde-1),k=1,var_info%dim_val(3))
  611. do k=1,var_info%dim_val(3)
  612. do j=jts,JMAX
  613. do i=its,IMAX
  614. soil_top_cat_input(i,j,k)=dum3d(i,j,k)
  615. enddo
  616. enddo
  617. enddo
  618. ELSE IF ( var_info%name(1:8) .EQ. 'SOILCBOT' ) THEN
  619. IF ( ( first_time_in ) .AND. ( .NOT. ALLOCATED ( soil_bot_cat_input) ) ) THEN
  620. ALLOCATE (soil_bot_cat_input(its:ite,jts:jte,var_info%dim_val(3)) )
  621. END IF
  622. READ (13) (((dum3d(i,j,k),i=ids,ide-1),j=jds,jde-1),k=1,var_info%dim_val(3))
  623. do k=1,var_info%dim_val(3)
  624. do j=jts,JMAX
  625. do i=its,IMAX
  626. soil_bot_cat_input(i,j,k)=dum3d(i,j,k)
  627. enddo
  628. enddo
  629. enddo
  630. ! 2D dry pressure minus ptop.
  631. ELSE IF ( var_info%name(1:8) .EQ. 'PD ' ) THEN
  632. READ (13) dum2d
  633. do j=jts,JMAX
  634. do i=its,IMAX
  635. grid%pd(i,j)=dum2d(i,j)
  636. enddo
  637. enddo
  638. ELSE IF ( var_info%name(1:8) .EQ. 'PSFC ' ) THEN
  639. READ (13) dum2d
  640. do j=jts,JMAX
  641. do i=its,IMAX
  642. psfc_in(i,j)=dum2d(i,j)
  643. enddo
  644. enddo
  645. ELSE IF ( var_info%name(1:8) .EQ. 'PMSL ' ) THEN
  646. READ (13) dum2d
  647. do j=jts,JMAX
  648. do i=its,IMAX
  649. pmsl(i,j)=dum2d(i,j)
  650. enddo
  651. enddo
  652. ELSE IF ( var_info%name(1:8) .EQ. 'PDTOP ' ) THEN
  653. READ (13) grid%pdtop
  654. ELSE IF ( var_info%name(1:8) .EQ. 'PT ' ) THEN
  655. READ (13) grid%pt
  656. ! 2D surface fields.
  657. ELSE IF ( var_info%name(1:8) .eq. 'GLAT ' ) THEN
  658. READ (13) dum2d
  659. do j=jts,JMAX
  660. do i=its,IMAX
  661. grid%glat(i,j)=dum2d(i,j)
  662. enddo
  663. enddo
  664. ELSE IF ( var_info%name(1:8) .eq. 'GLON ' ) THEN
  665. READ (13) dum2d
  666. do j=jts,JMAX
  667. do i=its,IMAX
  668. grid%glon(i,j)=dum2d(i,j)
  669. enddo
  670. enddo
  671. ELSE IF ( var_info%name(1:8) .eq. 'LAT_V ' ) THEN
  672. READ (13) dum2d
  673. do j=jts,JMAX
  674. do i=its,IMAX
  675. lat_wind(i,j)=dum2d(i,j)
  676. enddo
  677. enddo
  678. ELSE IF ( var_info%name(1:8) .eq. 'LON_V ' ) THEN
  679. READ (13) dum2d
  680. do j=jts,JMAX
  681. do i=its,IMAX
  682. lon_wind(i,j)=dum2d(i,j)
  683. enddo
  684. enddo
  685. ELSE IF ( var_info%name(1:8) .EQ. 'ST000010' ) THEN
  686. READ (13) dum2d
  687. do j=jts,JMAX
  688. do i=its,IMAX
  689. grid%st000010(i,j)=dum2d(i,j)
  690. enddo
  691. enddo
  692. flag_st000010 = 1
  693. num_st_levels_input = num_st_levels_input + 1
  694. st_levels_input(num_st_levels_input) = char2int2(var_info%name(3:8))
  695. do j=jts,JMAX
  696. do i=its,IMAX
  697. st_inputx(I,J,num_st_levels_input + 1) = grid%st000010(i,j)
  698. enddo
  699. enddo
  700. ELSE IF ( var_info%name(1:8) .EQ. 'ST010040' ) THEN
  701. READ (13) dum2d
  702. do j=jts,JMAX
  703. do i=its,IMAX
  704. grid%st010040(i,j)=dum2d(i,j)
  705. enddo
  706. enddo
  707. flag_st010040 = 1
  708. num_st_levels_input = num_st_levels_input + 1
  709. st_levels_input(num_st_levels_input) = char2int2(var_info%name(3:8))
  710. do j=jts,JMAX
  711. do i=its,IMAX
  712. st_inputx(I,J,num_st_levels_input + 1) = grid%st010040(i,j)
  713. enddo
  714. enddo
  715. ELSE IF ( var_info%name(1:8) .EQ. 'ST040100' ) THEN
  716. READ (13) dum2d
  717. do j=jts,JMAX
  718. do i=its,IMAX
  719. grid%st040100(i,j)=dum2d(i,j)
  720. enddo
  721. enddo
  722. flag_st040100 = 1
  723. num_st_levels_input = num_st_levels_input + 1
  724. st_levels_input(num_st_levels_input) = char2int2(var_info%name(3:8))
  725. do j=jts,JMAX
  726. do i=its,IMAX
  727. st_inputx(I,J,num_st_levels_input + 1) = grid%st040100(i,j)
  728. enddo
  729. enddo
  730. ELSE IF ( var_info%name(1:8) .EQ. 'ST100200' ) THEN
  731. READ (13) dum2d
  732. do j=jts,JMAX
  733. do i=its,IMAX
  734. grid%st100200(i,j)=dum2d(i,j)
  735. enddo
  736. enddo
  737. flag_st100200 = 1
  738. num_st_levels_input = num_st_levels_input + 1
  739. st_levels_input(num_st_levels_input) = char2int2(var_info%name(3:8))
  740. do j=jts,JMAX
  741. do i=its,IMAX
  742. st_inputx(I,J,num_st_levels_input + 1) = grid%st100200(i,j)
  743. enddo
  744. enddo
  745. ELSE IF ( var_info%name(1:8) .EQ. 'ST010200' ) THEN
  746. READ (13) dum2d
  747. do j=jts,JMAX
  748. do i=its,IMAX
  749. grid%st010200(i,j)=dum2d(i,j)
  750. enddo
  751. enddo
  752. flag_st010200 = 1
  753. num_st_levels_input = num_st_levels_input + 1
  754. st_levels_input(num_st_levels_input) = char2int2(var_info%name(3:8))
  755. do j=jts,JMAX
  756. do i=its,IMAX
  757. st_inputx(I,J,num_st_levels_input + 1) = grid%st010200(i,j)
  758. enddo
  759. enddo
  760. ELSE IF ( var_info%name(1:8) .EQ. 'SM000010' ) THEN
  761. READ (13) dum2d
  762. do j=jts,JMAX
  763. do i=its,IMAX
  764. grid%sm000010(i,j)=dum2d(i,j)
  765. enddo
  766. enddo
  767. flag_sm000010 = 1
  768. num_sm_levels_input = num_sm_levels_input + 1
  769. sm_levels_input(num_sm_levels_input) = char2int2(var_info%name(3:8))
  770. do j=jts,JMAX
  771. do i=its,IMAX
  772. sm_inputx(I,J,num_sm_levels_input + 1) = grid%sm000010(i,j)
  773. enddo
  774. enddo
  775. ELSE IF ( var_info%name(1:8) .EQ. 'SM010040' ) THEN
  776. READ (13) dum2d
  777. do j=jts,JMAX
  778. do i=its,IMAX
  779. grid%sm010040(i,j)=dum2d(i,j)
  780. enddo
  781. enddo
  782. flag_sm010040 = 1
  783. num_sm_levels_input = num_sm_levels_input + 1
  784. sm_levels_input(num_sm_levels_input) = char2int2(var_info%name(3:8))
  785. do j=jts,JMAX
  786. do i=its,IMAX
  787. sm_inputx(I,J,num_sm_levels_input + 1) = grid%sm010040(i,j)
  788. enddo
  789. enddo
  790. ELSE IF ( var_info%name(1:8) .EQ. 'SM040100' ) THEN
  791. READ (13) dum2d
  792. do j=jts,JMAX
  793. do i=its,IMAX
  794. grid%sm040100(i,j)=dum2d(i,j)
  795. enddo
  796. enddo
  797. flag_sm040100 = 1
  798. num_sm_levels_input = num_sm_levels_input + 1
  799. sm_levels_input(num_sm_levels_input) = char2int2(var_info%name(3:8))
  800. do j=jts,JMAX
  801. do i=its,IMAX
  802. sm_inputx(I,J,num_sm_levels_input + 1) = grid%sm040100(i,j)
  803. enddo
  804. enddo
  805. ELSE IF ( var_info%name(1:8) .EQ. 'SM100200' ) THEN
  806. READ (13) dum2d
  807. do j=jts,JMAX
  808. do i=its,IMAX
  809. grid%sm100200(i,j)=dum2d(i,j)
  810. enddo
  811. enddo
  812. flag_sm100200 = 1
  813. num_sm_levels_input = num_sm_levels_input + 1
  814. sm_levels_input(num_sm_levels_input) = char2int2(var_info%name(3:8))
  815. do j=jts,JMAX
  816. do i=its,IMAX
  817. sm_inputx(I,J,num_sm_levels_input + 1) = grid%sm100200(i,j)
  818. enddo
  819. enddo
  820. ELSE IF ( var_info%name(1:8) .EQ. 'SM010200' ) THEN
  821. READ (13) dum2d
  822. do j=jts,JMAX
  823. do i=its,IMAX
  824. grid%sm010200(i,j)=dum2d(i,j)
  825. enddo
  826. enddo
  827. flag_sm010200 = 1
  828. num_sm_levels_input = num_sm_levels_input + 1
  829. sm_levels_input(num_sm_levels_input) = char2int2(var_info%name(3:8))
  830. do j=jts,JMAX
  831. do i=its,IMAX
  832. sm_inputx(I,J,num_sm_levels_input + 1) = grid%sm010200(i,j)
  833. enddo
  834. enddo
  835. ELSE IF ( var_info%name(1:8) .EQ. 'SOILT010' ) THEN
  836. READ (13) dum2d
  837. do j=jts,JMAX
  838. do i=its,IMAX
  839. soilt010_input(i,j)=dum2d(i,j)
  840. enddo
  841. enddo
  842. flag_soilt010 = 1
  843. num_st_levels_input = num_st_levels_input + 1
  844. st_levels_input(num_st_levels_input) = char2int1(var_info%name(6:8))
  845. !mp st_inputx(:,:,num_st_levels_input + 1) = soilt010_input
  846. do j=jts,JMAX
  847. do i=its,IMAX
  848. st_inputx(I,J,num_st_levels_input + 1) = soilt010_input(I,J)
  849. enddo
  850. enddo
  851. write(6,*) 'num_st_levels_input=',num_st_levels_input
  852. ELSE IF ( var_info%name(1:8) .EQ. 'SOILT040' ) THEN
  853. READ (13) dum2d
  854. do j=jts,JMAX
  855. do i=its,IMAX
  856. soilt040_input(i,j)=dum2d(i,j)
  857. enddo
  858. enddo
  859. flag_soilt040 = 1
  860. num_st_levels_input = num_st_levels_input + 1
  861. st_levels_input(num_st_levels_input) = char2int1(var_info%name(6:8))
  862. !mp st_inputx(:,:,num_st_levels_input + 1) = soilt040_input
  863. do j=jts,JMAX
  864. do i=its,IMAX
  865. st_inputx(I,J,num_st_levels_input + 1) = soilt040_input(I,J)
  866. enddo
  867. enddo
  868. write(6,*) 'num_st_levels_input=',num_st_levels_input
  869. ELSE IF ( var_info%name(1:8) .EQ. 'SOILT100' ) THEN
  870. READ (13) dum2d
  871. do j=jts,JMAX
  872. do i=its,IMAX
  873. soilt100_input(i,j)=dum2d(i,j)
  874. enddo
  875. enddo
  876. flag_soilt100 = 1
  877. num_st_levels_input = num_st_levels_input + 1
  878. st_levels_input(num_st_levels_input) = char2int1(var_info%name(6:8))
  879. !mp st_inputx(:,:,num_st_levels_input + 1) = soilt100_input
  880. do j=jts,JMAX
  881. do i=its,IMAX
  882. st_inputx(I,J,num_st_levels_input + 1) = soilt100_input(I,J)
  883. enddo
  884. enddo
  885. write(6,*) 'num_st_levels_input=',num_st_levels_input
  886. ELSE IF ( var_info%name(1:8) .EQ. 'SOILT200' ) THEN
  887. READ (13) dum2d
  888. do j=jts,JMAX
  889. do i=its,IMAX
  890. soilt200_input(i,j)=dum2d(i,j)
  891. enddo
  892. enddo
  893. flag_soilt200 = 1
  894. num_st_levels_input = num_st_levels_input + 1
  895. st_levels_input(num_st_levels_input) = char2int1(var_info%name(6:8))
  896. !mp st_inputx(:,:,num_st_levels_input + 1) = soilt200_input
  897. do j=jts,JMAX
  898. do i=its,IMAX
  899. st_inputx(I,J,num_st_levels_input + 1) = soilt200_input(I,J)
  900. enddo
  901. enddo
  902. write(6,*) 'num_st_levels_input=',num_st_levels_input
  903. ELSE IF ( var_info%name(1:8) .EQ. 'SOILM010' ) THEN
  904. READ (13) dum2d
  905. do j=jts,JMAX
  906. do i=its,IMAX
  907. soilm010_input(i,j)=dum2d(i,j)
  908. enddo
  909. enddo
  910. flag_soilm010 = 1
  911. num_sm_levels_input = num_sm_levels_input + 1
  912. sm_levels_input(num_sm_levels_input) = char2int1(var_info%name(6:8))
  913. !mp sm_inputx(:,:,num_sm_levels_input + 1) = soilm010_input
  914. do j=jts,JMAX
  915. do i=its,IMAX
  916. sm_inputx(I,J,num_sm_levels_input + 1) = soilm010_input(I,J)
  917. enddo
  918. enddo
  919. ELSE IF ( var_info%name(1:8) .EQ. 'SOILM040' ) THEN
  920. READ (13) dum2d
  921. do j=jts,JMAX
  922. do i=its,IMAX
  923. soilm040_input(i,j)=dum2d(i,j)
  924. enddo
  925. enddo
  926. flag_soilm040 = 1
  927. num_sm_levels_input = num_sm_levels_input + 1
  928. sm_levels_input(num_sm_levels_input) = char2int1(var_info%name(6:8))
  929. !mp sm_inputx(:,:,num_sm_levels_input + 1) = soilm040_input
  930. do j=jts,JMAX
  931. do i=its,IMAX
  932. sm_inputx(I,J,num_sm_levels_input + 1) = soilm040_input(I,J)
  933. enddo
  934. enddo
  935. ELSE IF ( var_info%name(1:8) .EQ. 'SOILM100' ) THEN
  936. READ (13) dum2d
  937. do j=jts,JMAX
  938. do i=its,IMAX
  939. soilm100_input(i,j)=dum2d(i,j)
  940. enddo
  941. enddo
  942. flag_soilm100 = 1
  943. num_sm_levels_input = num_sm_levels_input + 1
  944. sm_levels_input(num_sm_levels_input) = char2int1(var_info%name(6:8))
  945. !mp sm_inputx(:,:,num_sm_levels_input + 1) = soilm100_input
  946. do j=jts,JMAX
  947. do i=its,IMAX
  948. sm_inputx(I,J,num_sm_levels_input + 1) = soilm100_input(I,J)
  949. enddo
  950. enddo
  951. ELSE IF ( var_info%name(1:8) .EQ. 'SOILM200' ) THEN
  952. READ (13) dum2d
  953. do j=jts,JMAX
  954. do i=its,IMAX
  955. soilm200_input(i,j)=dum2d(i,j)
  956. enddo
  957. enddo
  958. flag_soilm200 = 1
  959. num_sm_levels_input = num_sm_levels_input + 1
  960. sm_levels_input(num_sm_levels_input) = char2int1(var_info%name(6:8))
  961. !mp sm_inputx(:,:,num_sm_levels_input + 1) = soilm200_input
  962. do j=jts,JMAX
  963. do i=its,IMAX
  964. sm_inputx(I,J,num_sm_levels_input + 1) = soilm200_input(I,J)
  965. enddo
  966. enddo
  967. ELSE IF ( var_info%name(1:8) .EQ. 'SEAICE ' ) THEN
  968. READ (13) dum2d
  969. do j=jts,JMAX
  970. do i=its,IMAX
  971. grid%xice(i,j)=dum2d(i,j)
  972. enddo
  973. enddo
  974. ELSE IF ( var_info%name(1:8) .EQ. 'WEASD ' ) THEN
  975. READ (13) dum2d
  976. do j=jts,JMAX
  977. do i=its,IMAX
  978. grid%weasd(i,j)=dum2d(i,j)
  979. enddo
  980. enddo
  981. ELSE IF ( var_info%name(1:8) .EQ. 'CANWAT ' ) THEN
  982. READ (13) dum2d
  983. do j=jts,JMAX
  984. do i=its,IMAX
  985. grid%canwat(i,j)=dum2d(i,j)
  986. enddo
  987. enddo
  988. ELSE IF ( var_info%name(1:8) .EQ. 'LANDMASK' ) THEN
  989. READ (13) dum2d
  990. do j=jts,JMAX
  991. do i=its,IMAX
  992. grid%landmask(i,j)=dum2d(i,j)
  993. enddo
  994. enddo
  995. ELSE IF ( var_info%name(1:8) .EQ. 'SKINTEMP' ) THEN
  996. READ (13) dum2d
  997. do j=jts,JMAX
  998. do i=its,IMAX
  999. grid%nmm_tsk(i,j)=dum2d(i,j)
  1000. enddo
  1001. enddo
  1002. ELSE IF ( var_info%name(1:8) .EQ. 'TGROUND ' ) THEN
  1003. READ (13) dum2d
  1004. do j=jts,JMAX
  1005. do i=its,IMAX
  1006. grid%tg(i,j)=dum2d(i,j)
  1007. enddo
  1008. enddo
  1009. ELSE IF ( var_info%name(1:8) .EQ. 'SOILTB ' ) THEN
  1010. READ (13) dum2d
  1011. do j=jts,JMAX
  1012. do i=its,IMAX
  1013. grid%soiltb(i,j)=dum2d(i,j)
  1014. enddo
  1015. enddo
  1016. ELSE IF ( var_info%name(1:8) .EQ. 'SST ' ) THEN
  1017. READ (13) dum2d
  1018. do j=jts,JMAX
  1019. do i=its,IMAX
  1020. grid%sst(i,j)=dum2d(i,j)
  1021. enddo
  1022. enddo
  1023. flag_sst = 1
  1024. ELSE IF ( var_info%name(1:8) .EQ. 'GREENFRC' ) THEN
  1025. READ (13) dum2d
  1026. do j=jts,JMAX
  1027. do i=its,IMAX
  1028. grid%vegfrc(i,j)=dum2d(i,j)
  1029. enddo
  1030. enddo
  1031. ELSE IF ( var_info%name(1:8) .EQ. 'ISLOPE ' ) THEN
  1032. READ (13) dum2d
  1033. do j=jts,JMAX
  1034. do i=its,IMAX
  1035. grid%islope(i,j)=nint(dum2d(i,j))
  1036. enddo
  1037. enddo
  1038. ELSE IF ( var_info%name(1:8) .EQ. 'GREENMAX' ) THEN
  1039. READ (13) dum2d
  1040. do j=jts,JMAX
  1041. do i=its,IMAX
  1042. grid%greenmax(i,j)=dum2d(i,j)
  1043. enddo
  1044. enddo
  1045. ELSE IF ( var_info%name(1:8) .EQ. 'GREENMIN' ) THEN
  1046. READ (13) dum2d
  1047. do j=jts,JMAX
  1048. do i=its,IMAX
  1049. grid%greenmin(i,j)=dum2d(i,j)
  1050. enddo
  1051. enddo
  1052. ELSE IF ( var_info%name(1:8) .EQ. 'FIS ' ) THEN
  1053. READ (13) dum2d
  1054. do j=jts,JMAX
  1055. do i=its,IMAX
  1056. grid%fis(i,j)=dum2d(i,j)
  1057. enddo
  1058. enddo
  1059. ELSE IF ( var_info%name(1:8) .EQ. 'Z0 ' ) THEN
  1060. ! ELSE IF ( var_info%name(1:8) .EQ. 'STDEV ' ) THEN
  1061. READ (13) dum2d
  1062. do j=jts,JMAX
  1063. do i=its,IMAX
  1064. grid%z0(i,j)=dum2d(i,j)
  1065. enddo
  1066. enddo
  1067. ELSE IF ( var_info%name(1:8) .EQ. 'CMC ' ) THEN
  1068. READ (13) dum2d
  1069. do j=jts,JMAX
  1070. do i=its,IMAX
  1071. grid%cmc(i,j)=dum2d(i,j)
  1072. enddo
  1073. enddo
  1074. ELSE IF ( var_info%name(1:8) .EQ. 'HTM ' ) THEN
  1075. READ (13) dum3d
  1076. do k=kts,kte-1
  1077. do j=jts,JMAX
  1078. do i=its,IMAX
  1079. htm_in(i,j,k)=dum3d(i,j,k)
  1080. enddo
  1081. enddo
  1082. enddo
  1083. ELSE IF ( var_info%name(1:8) .EQ. 'VTM ' ) THEN
  1084. READ (13) dum3d
  1085. do k=kts,kte-1
  1086. do j=jts,JMAX
  1087. do i=its,IMAX
  1088. vtm_in(i,j,k)=dum3d(i,j,k)
  1089. enddo
  1090. enddo
  1091. enddo
  1092. ELSE IF ( var_info%name(1:8) .EQ. 'SM ' ) THEN
  1093. READ (13) dum2d
  1094. do j=jts,JMAX
  1095. do i=its,IMAX
  1096. grid%sm(i,j)=dum2d(i,j)
  1097. enddo
  1098. enddo
  1099. ELSE IF ( var_info%name(1:8) .EQ. 'ALBASE ' ) THEN
  1100. READ (13) dum2d
  1101. do j=jts,JMAX
  1102. do i=its,IMAX
  1103. grid%albase(i,j)=dum2d(i,j)
  1104. enddo
  1105. enddo
  1106. ELSE IF ( var_info%name(1:8) .EQ. 'MXSNAL ' ) THEN
  1107. READ (13) dum2d
  1108. do j=jts,JMAX
  1109. do i=its,IMAX
  1110. grid%mxsnal(i,j)=dum2d(i,j)
  1111. enddo
  1112. enddo
  1113. ! 1D vertical coordinate.
  1114. ELSE IF ( var_info%name(1:8) .EQ. 'DETA ' ) THEN
  1115. READ(13) DETA_in
  1116. ELSE IF ( var_info%name(1:8) .EQ. 'DETA1 ' ) THEN
  1117. READ(13) DETA1_in
  1118. ELSE IF ( var_info%name(1:8) .EQ. 'DETA2 ' ) THEN
  1119. READ(13) DETA2_in
  1120. ELSE IF ( var_info%name(1:8) .EQ. 'ETAX ' ) THEN
  1121. READ(13) ETAX_in
  1122. ELSE IF ( var_info%name(1:8) .EQ. 'ETA1 ' ) THEN
  1123. READ(13) ETA1_in
  1124. ELSE IF ( var_info%name(1:8) .EQ. 'ETA2 ' ) THEN
  1125. READ(13) ETA2_in
  1126. ELSE IF ( var_info%name(1:8) .EQ. 'AETA ' ) THEN
  1127. READ(13) AETA_in
  1128. ELSE IF ( var_info%name(1:8) .EQ. 'AETA1 ' ) THEN
  1129. READ(13) AETA1_in
  1130. ELSE IF ( var_info%name(1:8) .EQ. 'AETA2 ' ) THEN
  1131. READ(13) AETA2_in
  1132. ELSE IF ( var_info%name(1:8) .EQ. 'DFL ' ) THEN
  1133. READ(13) DFL_in
  1134. ! ELSE IF ( var_info%name(1:8) .EQ. 'ETAPHALF' ) THEN
  1135. ! READ (13) etahalf
  1136. ! ELSE IF ( var_info%name(1:8) .EQ. 'ETAPFULL' ) THEN
  1137. ! READ (13) etafull
  1138. ! wrong input data.
  1139. ELSE IF ( var_info%name(1:8) .EQ. 'ZETAFULL' ) THEN
  1140. PRINT '(A)','Oops, you put in the height data.'
  1141. STOP 'this_is_mass_not_height'
  1142. ! Stuff that we do not want or need is just skipped over.
  1143. ELSE
  1144. print *,'------------------> skipping ', var_info%name(1:8)
  1145. READ (13) dummy
  1146. END IF
  1147. END DO read_all_the_data
  1148. CLOSE (13)
  1149. first_time_in = .FALSE.
  1150. !new
  1151. sw_inputx=0.
  1152. !new
  1153. do k=kts,kte-1
  1154. do j=jts,JMAX
  1155. do i=its,IMAX
  1156. grid%U(I,J,K)=U_input(I,J,K)
  1157. grid%V(I,J,K)=V_input(I,J,K)
  1158. grid%T(I,J,K)=T_input(I,J,K)
  1159. grid%Q(I,J,K)=Q_input(I,J,K)
  1160. enddo
  1161. enddo
  1162. enddo
  1163. ! write(0,*) 'size sw_input: ', size(sw_input,dim=1),size(sw_input,dim=2),size(sw_input,dim=3)
  1164. ! write(0,*) 'size sw_inputx: ', size(sw_inputx,dim=1),size(sw_inputx,dim=2),size(sw_inputx,dim=3)
  1165. sw_input=0.
  1166. ! write(0,*) 'maxval st_inputx(1): ', maxval(st_input(:,:,1))
  1167. ! write(0,*) 'maxval st_inputx(2): ', maxval(st_input(:,:,2))
  1168. ! write(0,*) 'maxval st_inputx(3): ', maxval(st_input(:,:,3))
  1169. ! write(0,*) 'maxval st_inputx(4): ', maxval(st_input(:,:,4))
  1170. do J=JTS,min(JDE-1,JTE)
  1171. do K=1,num_st_levels_alloc
  1172. do I=ITS,min(IDE-1,ITE)
  1173. st_input(I,K,J)=st_inputx(I,J,K)
  1174. sm_input(I,K,J)=sm_inputx(I,J,K)
  1175. sw_input(I,K,J)=sw_inputx(I,J,K)
  1176. enddo
  1177. enddo
  1178. enddo
  1179. ! write(0,*) 'maxval st_input(1): ', maxval(st_input(:,1,:))
  1180. ! write(0,*) 'maxval st_input(2): ', maxval(st_input(:,2,:))
  1181. ! write(0,*) 'maxval st_input(3): ', maxval(st_input(:,3,:))
  1182. ! write(0,*) 'maxval st_input(4): ', maxval(st_input(:,4,:))
  1183. num_veg_cat = SIZE ( grid%landusef , DIM=2 )
  1184. num_soil_top_cat = SIZE ( grid%soilctop , DIM=2 )
  1185. num_soil_bot_cat = SIZE ( grid%soilcbot , DIM=2 )
  1186. do J=JTS,min(JDE-1,JTE)
  1187. do K=1,num_soil_top_cat
  1188. do I=ITS,min(IDE-1,ITE)
  1189. grid%SOILCTOP(I,K,J)=soil_top_cat_input(I,J,K)
  1190. grid%SOILCTOP_gc(I,J,K)=soil_top_cat_input(I,J,K)
  1191. enddo
  1192. enddo
  1193. enddo
  1194. do J=JTS,min(JDE-1,JTE)
  1195. do K=1,num_soil_bot_cat
  1196. do I=ITS,min(IDE-1,ITE)
  1197. grid%SOILCBOT(I,K,J)=soil_bot_cat_input(I,J,K)
  1198. grid%SOILCBOT_gc(I,J,K)=soil_bot_cat_input(I,J,K)
  1199. enddo
  1200. enddo
  1201. enddo
  1202. do J=JTS,min(JDE-1,JTE)
  1203. do K=1,num_veg_cat
  1204. do I=ITS,min(IDE-1,ITE)
  1205. grid%LANDUSEF(I,K,J)=landuse_frac_input(I,J,K)
  1206. grid%LANDUSEF_gc(I,J,K)=landuse_frac_input(I,J,K)
  1207. enddo
  1208. enddo
  1209. enddo
  1210. do K=KDS,KDE
  1211. grid%ETAX(K)=ETAX_in(KDE-K+1)
  1212. grid%ETA1(K)=ETA1_in(KDE-K+1)
  1213. grid%ETA2(K)=ETA2_in(KDE-K+1)
  1214. grid%DFL(K)=DFL_in(KDE-K+1)
  1215. enddo
  1216. do K=KDS,KDE-1
  1217. grid%DETA(K)=DETA_in(KDE-K)
  1218. grid%DETA1(K)=DETA1_in(KDE-K)
  1219. grid%DETA2(K)=DETA2_in(KDE-K)
  1220. grid%AETA(K)=AETA_in(KDE-K)
  1221. grid%AETA1(K)=AETA1_in(KDE-K)
  1222. grid%AETA2(K)=AETA2_in(KDE-K)
  1223. enddo
  1224. END SUBROUTINE read_si
  1225. ! ------------------------------------------------------------
  1226. ! ------------------------------------------------------------
  1227. ! ------------------------------------------------------------
  1228. ! ------------------------------------------------------------
  1229. ! ------------------------------------------------------------
  1230. ! ------------------------------------------------------------
  1231. SUBROUTINE read_wps ( grid, filename, file_date_string, num_metgrid_levels )
  1232. USE module_soil_pre
  1233. USE module_domain
  1234. IMPLICIT NONE
  1235. TYPE(domain) , INTENT(INOUT) :: grid
  1236. CHARACTER (LEN=19) , INTENT(IN) :: file_date_string
  1237. CHARACTER (LEN=19) :: VarName
  1238. CHARACTER (LEN=150) :: chartemp
  1239. CHARACTER (LEN=256) :: mminlu_loc, message
  1240. CHARACTER (*) , INTENT(IN) :: filename
  1241. INTEGER :: ids,ide,jds,jde,kds,kde &
  1242. ,ims,ime,jms,jme,kms,kme &
  1243. ,its,ite,jts,jte,kts,kte
  1244. INTEGER :: i , j , k , loop, IMAX, JMAX
  1245. INTEGER :: DATAHANDLE, num_metgrid_levels
  1246. INTEGER :: Sysdepinfo, Status, N
  1247. INTEGER :: istatus,ioutcount,iret,index,ierr
  1248. integer :: nrecs,iunit, L,hor_size
  1249. !!
  1250. character*132, allocatable,save :: datestr_all(:)
  1251. character*132, allocatable,save :: varname_all(:)
  1252. integer, allocatable,save :: domainend_all(:,:)
  1253. integer, allocatable,save :: start_block(:)
  1254. integer, allocatable,save :: end_block(:)
  1255. integer, allocatable,save :: start_byte(:)
  1256. integer, allocatable,save :: end_byte(:)
  1257. integer(kind=i_llong), allocatable,save :: file_offset(:)
  1258. !!
  1259. REAL :: dummy,tmp,garb
  1260. REAL, ALLOCATABLE,save :: dumdata(:,:,:)
  1261. CHARACTER (LEN= 8) :: dummy_char
  1262. INTEGER :: ok , map_proj , ok_open, igarb
  1263. REAL :: pt
  1264. INTEGER :: num_veg_cat , num_soil_top_cat , num_soil_bot_cat
  1265. #if defined(DM_PARALLEL) && !defined(STUBMPI)
  1266. INCLUDE "mpif.h"
  1267. SELECT CASE ( model_data_order )
  1268. CASE ( DATA_ORDER_ZXY )
  1269. kds = grid%sd31 ; kde = grid%ed31 ;
  1270. ids = grid%sd32 ; ide = grid%ed32 ;
  1271. jds = grid%sd33 ; jde = grid%ed33 ;
  1272. kms = grid%sm31 ; kme = grid%em31 ;
  1273. ims = grid%sm32 ; ime = grid%em32 ;
  1274. jms = grid%sm33 ; jme = grid%em33 ;
  1275. kts = grid%sp31 ; kte = grid%ep31 ; ! tile is entire patch
  1276. its = grid%sp32 ; ite = grid%ep32 ; ! tile is entire patch
  1277. jts = grid%sp33 ; jte = grid%ep33 ; ! tile is entire patch
  1278. CASE ( DATA_ORDER_XYZ )
  1279. ids = grid%sd31 ; ide = grid%ed31 ;
  1280. jds = grid%sd32 ; jde = grid%ed32 ;
  1281. kds = grid%sd33 ; kde = grid%ed33 ;
  1282. ims = grid%sm31 ; ime = grid%em31 ;
  1283. jms = grid%sm32 ; jme = grid%em32 ;
  1284. kms = grid%sm33 ; kme = grid%em33 ;
  1285. its = grid%sp31 ; ite = grid%ep31 ; ! tile is entire patch
  1286. jts = grid%sp32 ; jte = grid%ep32 ; ! tile is entire patch
  1287. kts = grid%sp33 ; kte = grid%ep33 ; ! tile is entire patch
  1288. CASE ( DATA_ORDER_XZY )
  1289. ids = grid%sd31 ; ide = grid%ed31 ;
  1290. kds = grid%sd32 ; kde = grid%ed32 ;
  1291. jds = grid%sd33 ; jde = grid%ed33 ;
  1292. ims = grid%sm31 ; ime = grid%em31 ;
  1293. kms = grid%sm32 ; kme = grid%em32 ;
  1294. jms = grid%sm33 ; jme = grid%em33 ;
  1295. its = grid%sp31 ; ite = grid%ep31 ; ! tile is entire patch
  1296. kts = grid%sp32 ; kte = grid%ep32 ; ! tile is entire patch
  1297. jts = grid%sp33 ; jte = grid%ep33 ; ! tile is entire patch
  1298. END SELECT
  1299. ! Initialize what soil temperature and moisture is available.
  1300. flag_st000010 = 0
  1301. flag_st010040 = 0
  1302. flag_st040100 = 0
  1303. flag_st100200 = 0
  1304. flag_sm000010 = 0
  1305. flag_sm010040 = 0
  1306. flag_sm040100 = 0
  1307. flag_sm100200 = 0
  1308. flag_st010200 = 0
  1309. flag_sm010200 = 0
  1310. flag_soilt010 = 0
  1311. flag_soilt040 = 0
  1312. flag_soilt100 = 0
  1313. flag_soilt200 = 0
  1314. flag_soilm010 = 0
  1315. flag_soilm040 = 0
  1316. flag_soilm100 = 0
  1317. flag_soilm200 = 0
  1318. flag_sst = 0
  1319. flag_toposoil = 0
  1320. ! How many soil levels have we found? Well, right now, none.
  1321. num_st_levels_input = 0
  1322. num_sm_levels_input = 0
  1323. st_levels_input = -1
  1324. sm_levels_input = -1
  1325. mminlu_loc=''
  1326. mminlu_loc(1:4)='USGS'
  1327. CALL nl_set_mminlu ( grid%id, mminlu_loc)
  1328. CALL nl_set_iswater (grid%id, 16 )
  1329. CALL nl_set_isice (grid%id, 24 )
  1330. CALL nl_set_islake (grid%id, -1)
  1331. ! Get the space for the data if this is the first time here.
  1332. IF (.NOT. ALLOCATED (pmsl) ) ALLOCATE ( pmsl(its:ite,jts:jte) )
  1333. IF (.NOT. ALLOCATED (psfc_in) ) ALLOCATE ( psfc_in(its:ite,jts:jte) )
  1334. IF (.NOT. ALLOCATED (st_inputx)) ALLOCATE (st_inputx(its:ite,jts:jte,num_st_levels_alloc))
  1335. IF (.NOT. ALLOCATED (sm_inputx)) ALLOCATE (sm_inputx(its:ite,jts:jte,num_st_levels_alloc))
  1336. IF (.NOT. ALLOCATED (sw_inputx)) ALLOCATE (sw_inputx(its:ite,jts:jte,num_st_levels_alloc))
  1337. IF (.NOT. ALLOCATED (soilt010_input) ) ALLOCATE ( soilt010_input(its:ite,jts:jte) )
  1338. IF (.NOT. ALLOCATED (soilt040_input) ) ALLOCATE ( soilt040_input(its:ite,jts:jte) )
  1339. IF (.NOT. ALLOCATED (soilt100_input) ) ALLOCATE ( soilt100_input(its:ite,jts:jte) )
  1340. IF (.NOT. ALLOCATED (soilt200_input) ) ALLOCATE ( soilt200_input(its:ite,jts:jte) )
  1341. IF (.NOT. ALLOCATED (soilm010_input) ) ALLOCATE ( soilm010_input(its:ite,jts:jte) )
  1342. IF (.NOT. ALLOCATED (soilm040_input) ) ALLOCATE ( soilm040_input(its:ite,jts:jte) )
  1343. IF (.NOT. ALLOCATED (soilm100_input) ) ALLOCATE ( soilm100_input(its:ite,jts:jte) )
  1344. IF (.NOT. ALLOCATED (soilm200_input) ) ALLOCATE ( soilm200_input(its:ite,jts:jte) )
  1345. ! Local arrays
  1346. !!! MPI IO
  1347. iunit=33
  1348. call count_recs_wrf_binary_file(iunit, trim(fileName), nrecs)
  1349. if (.NOT. ALLOCATED (datestr_all)) allocate (datestr_all(nrecs))
  1350. if (.NOT. ALLOCATED (varname_all)) allocate (varname_all(nrecs))
  1351. if (.NOT. ALLOCATED (domainend_all)) allocate (domainend_all(3,nrecs))
  1352. if (.NOT. ALLOCATED (start_block)) allocate (start_block(nrecs))
  1353. if (.NOT. ALLOCATED (end_block)) allocate (end_block(nrecs))
  1354. if (.NOT. ALLOCATED (start_byte)) allocate (start_byte(nrecs))
  1355. if (.NOT. ALLOCATED (end_byte)) allocate (end_byte(nrecs))
  1356. if (.NOT. ALLOCATED (file_offset)) allocate (file_offset(nrecs))
  1357. call inventory_wrf_binary_file(iunit, trim(filename), nrecs, &
  1358. datestr_all,varname_all,domainend_all, &
  1359. start_block,end_block,start_byte,end_byte,file_offset)
  1360. do N=1,NRECS
  1361. write(message,*) 'N,varname_all(N): ',N, varname_all(N)
  1362. call wrf_debug(100,message)
  1363. enddo
  1364. call mpi_file_open(mpi_comm_world, trim(filename), &
  1365. mpi_mode_rdonly,mpi_info_null, iunit, ierr)
  1366. if (ierr /= 0) then
  1367. call wrf_error_fatal("Error opening file with mpi io")
  1368. end if
  1369. VarName='CEN_LAT'
  1370. call retrieve_index(index,VarName,varname_all,nrecs,iret)
  1371. if (iret /= 0) then
  1372. write(message,*) VarName, ' not found in file'
  1373. call wrf_message(message)
  1374. else
  1375. call mpi_file_read_at(iunit,file_offset(index)+5*4, &
  1376. garb,1,mpi_real4, &
  1377. mpi_status_ignore, ierr)
  1378. if (ierr /= 0) then
  1379. write(message,*) 'Error reading ', VarName,' using MPIIO'
  1380. call wrf_message(message)
  1381. else
  1382. write(message,*) VarName, ' from MPIIO READ= ', garb
  1383. call wrf_message(message)
  1384. CALL nl_set_cen_lat ( grid%id , garb )
  1385. end if
  1386. end if
  1387. VarName='CEN_LON'
  1388. call retrieve_index(index,VarName,varname_all,nrecs,iret)
  1389. call mpi_file_read_at(iunit,file_offset(index)+5*4, &
  1390. garb,1,mpi_real4, &
  1391. mpi_status_ignore, ierr)
  1392. CALL nl_set_cen_lon ( grid%id , garb )
  1393. CALL nl_set_stand_lon ( grid%id , garb )
  1394. VarName='TRUELAT1'
  1395. call retrieve_index(index,VarName,varname_all,nrecs,iret)
  1396. call mpi_file_read_at(iunit,file_offset(index)+5*4, &
  1397. garb,1,mpi_real4, &
  1398. mpi_status_ignore, ierr)
  1399. CALL nl_set_truelat1 ( grid%id , garb )
  1400. VarName='TRUELAT2'
  1401. call retrieve_index(index,VarName,varname_all,nrecs,iret)
  1402. call mpi_file_read_at(iunit,file_offset(index)+5*4, &
  1403. garb,1,mpi_real4, &
  1404. mpi_status_ignore, ierr)
  1405. CALL nl_set_truelat2 ( grid%id , garb )
  1406. VarName='MAP_PROJ'
  1407. call retrieve_index(index,VarName,varname_all,nrecs,iret)
  1408. call mpi_file_read_at(iunit,file_offset(index)+5*4, &
  1409. igarb,1,mpi_integer4, &
  1410. mpi_status_ignore, ierr)
  1411. CALL nl_set_map_proj( grid%id, igarb)
  1412. VarName='FLAG_SNOWH'
  1413. call retrieve_index(index,VarName,varname_all,nrecs,iret)
  1414. call mpi_file_read_at(iunit,file_offset(index)+5*4, &
  1415. igarb,1,mpi_integer4, &
  1416. mpi_status_ignore, ierr)
  1417. write(0,*) 'ierr, igarb for FLAG_SNOWH: ', ierr,igarb
  1418. flag_snowh=igarb
  1419. hor_size=(IDE-IDS)*(JDE-JDS)
  1420. varName='PRES'
  1421. if (.not. allocated(dumdata)) then
  1422. allocate(dumdata(IDS:IDE-1,JDS:JDE-1,num_metgrid_levels))
  1423. endif
  1424. CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
  1425. CALL mpi_file_read_at(iunit,file_offset(index+1), &
  1426. dumdata,hor_size*num_metgrid_levels,mpi_real4, &
  1427. mpi_status_ignore, ierr)
  1428. DO K=1,num_metgrid_levels
  1429. DO J=JTS,min(JTE,JDE-1)
  1430. DO I=ITS,min(ITE,IDE-1)
  1431. grid%p_gc(I,J,K)=dumdata(I,J,K)
  1432. ENDDO
  1433. ENDDO
  1434. ENDDO
  1435. varName='GHT'
  1436. CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
  1437. CALL mpi_file_read_at(iunit,file_offset(index+1), &
  1438. dumdata,hor_size*num_metgrid_levels,mpi_real4, &
  1439. mpi_status_ignore, ierr)
  1440. DO K=1,num_metgrid_levels
  1441. DO J=JTS,min(JTE,JDE-1)
  1442. DO I=ITS,min(ITE,IDE-1)
  1443. grid%ght_gc(I,J,K)=dumdata(I,J,K)
  1444. ENDDO
  1445. ENDDO
  1446. ENDDO
  1447. varName='VEGCAT'
  1448. CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
  1449. CALL mpi_file_read_at(iunit,file_offset(index+1), &
  1450. dumdata,hor_size,mpi_real4, &
  1451. mpi_status_ignore, ierr)
  1452. DO J=JTS,min(JTE,JDE-1)
  1453. DO I=ITS,min(ITE,IDE-1)
  1454. grid%vegcat(I,J)=dumdata(I,J,1)
  1455. ENDDO
  1456. ENDDO
  1457. varName='SOIL_CAT'
  1458. CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
  1459. CALL mpi_file_read_at(iunit,file_offset(index+1), &
  1460. dumdata,hor_size,mpi_real4, &
  1461. mpi_status_ignore, ierr)
  1462. DO J=JTS,min(JTE,JDE-1)
  1463. DO I=ITS,min(ITE,IDE-1)
  1464. grid%input_soil_cat(I,J)=dumdata(I,J,1)
  1465. ENDDO
  1466. ENDDO
  1467. varName='CANWAT'
  1468. CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
  1469. CALL mpi_file_read_at(iunit,file_offset(index+1), &
  1470. dumdata,hor_size,mpi_real4, &
  1471. mpi_status_ignore, ierr)
  1472. DO J=JTS,min(JTE,JDE-1)
  1473. DO I=ITS,min(ITE,IDE-1)
  1474. grid%canwat(I,J)=dumdata(I,J,1)
  1475. ENDDO
  1476. ENDDO
  1477. varName='SNOW'
  1478. CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
  1479. CALL mpi_file_read_at(iunit,file_offset(index+1), &
  1480. dumdata,hor_size,mpi_real4, &
  1481. mpi_status_ignore, ierr)
  1482. DO J=JTS,min(JTE,JDE-1)
  1483. DO I=ITS,min(ITE,IDE-1)
  1484. grid%snow(I,J)=dumdata(I,J,1)
  1485. ENDDO
  1486. ENDDO
  1487. varName='SNOWH'
  1488. CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
  1489. CALL mpi_file_read_at(iunit,file_offset(index+1), &
  1490. dumdata,hor_size,mpi_real4, &
  1491. mpi_status_ignore, ierr)
  1492. DO J=JTS,min(JTE,JDE-1)
  1493. DO I=ITS,min(ITE,IDE-1)
  1494. grid%snowh(I,J)=dumdata(I,J,1)
  1495. ENDDO
  1496. ENDDO
  1497. varName='SKINTEMP'
  1498. CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
  1499. CALL mpi_file_read_at(iunit,file_offset(index+1), &
  1500. dumdata,hor_size,mpi_real4, &
  1501. mpi_status_ignore, ierr)
  1502. DO J=JTS,min(JTE,JDE-1)
  1503. DO I=ITS,min(ITE,IDE-1)
  1504. grid%tsk_gc(I,J)=dumdata(I,J,1)
  1505. ENDDO
  1506. ENDDO
  1507. varName='SOILHGT'
  1508. CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
  1509. CALL mpi_file_read_at(iunit,file_offset(index+1), &
  1510. dumdata,hor_size,mpi_real4, &
  1511. mpi_status_ignore, ierr)
  1512. DO J=JTS,min(JTE,JDE-1)
  1513. DO I=ITS,min(ITE,IDE-1)
  1514. grid%toposoil(I,J)=dumdata(I,J,1)
  1515. ENDDO
  1516. ENDDO
  1517. varName='SEAICE'
  1518. CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
  1519. CALL mpi_file_read_at(iunit,file_offset(index+1), &
  1520. dumdata,hor_size,mpi_real4, &
  1521. mpi_status_ignore, ierr)
  1522. DO J=JTS,min(JTE,JDE-1)
  1523. DO I=ITS,min(ITE,IDE-1)
  1524. grid%xice_gc(I,J)=dumdata(I,J,1)
  1525. ENDDO
  1526. ENDDO
  1527. varName='ST100200'
  1528. CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
  1529. CALL mpi_file_read_at(iunit,file_offset(index+1), &
  1530. dumdata,hor_size,mpi_real4, &
  1531. mpi_status_ignore, ierr)
  1532. DO J=JTS,min(JTE,JDE-1)
  1533. DO I=ITS,min(ITE,IDE-1)
  1534. grid%st100200(I,J)=dumdata(I,J,1)
  1535. ENDDO
  1536. ENDDO
  1537. varName='ST040100'
  1538. CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
  1539. CALL mpi_file_read_at(iunit,file_offset(index+1), &
  1540. dumdata,hor_size,mpi_real4, &
  1541. mpi_status_ignore, ierr)
  1542. DO J=JTS,min(JTE,JDE-1)
  1543. DO I=ITS,min(ITE,IDE-1)
  1544. grid%st040100(I,J)=dumdata(I,J,1)
  1545. ENDDO
  1546. ENDDO
  1547. varName='ST010040'
  1548. CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
  1549. CALL mpi_file_read_at(iunit,file_offset(index+1), &
  1550. dumdata,hor_size,mpi_real4, &
  1551. mpi_status_ignore, ierr)
  1552. DO J=JTS,min(JTE,JDE-1)
  1553. DO I=ITS,min(ITE,IDE-1)
  1554. grid%st010040(I,J)=dumdata(I,J,1)
  1555. ENDDO
  1556. ENDDO
  1557. varName='ST000010'
  1558. CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
  1559. CALL mpi_file_read_at(iunit,file_offset(index+1), &
  1560. dumdata,hor_size,mpi_real4, &
  1561. mpi_status_ignore, ierr)
  1562. DO J=JTS,min(JTE,JDE-1)
  1563. DO I=ITS,min(ITE,IDE-1)
  1564. grid%st000010(I,J)=dumdata(I,J,1)
  1565. ENDDO
  1566. ENDDO
  1567. varName='SM100200'
  1568. CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
  1569. CALL mpi_file_read_at(iunit,file_offset(index+1), &
  1570. dumdata,hor_size,mpi_real4, &
  1571. mpi_status_ignore, ierr)
  1572. DO J=JTS,min(JTE,JDE-1)
  1573. DO I=ITS,min(ITE,IDE-1)
  1574. grid%sm100200(I,J)=dumdata(I,J,1)
  1575. ENDDO
  1576. ENDDO
  1577. varName='SM040100'
  1578. CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
  1579. CALL mpi_file_read_at(iunit,file_offset(index+1), &
  1580. dumdata,hor_size,mpi_real4, &
  1581. mpi_status_ignore, ierr)
  1582. DO J=JTS,min(JTE,JDE-1)
  1583. DO I=ITS,min(ITE,IDE-1)
  1584. grid%sm040100(I,J)=dumdata(I,J,1)
  1585. ENDDO
  1586. ENDDO
  1587. varName='SM010040'
  1588. CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
  1589. CALL mpi_file_read_at(iunit,file_offset(index+1), &
  1590. dumdata,hor_size,mpi_real4, &
  1591. mpi_status_ignore, ierr)
  1592. DO J=JTS,min(JTE,JDE-1)
  1593. DO I=ITS,min(ITE,IDE-1)
  1594. grid%sm010040(I,J)=dumdata(I,J,1)
  1595. ENDDO
  1596. ENDDO
  1597. varName='SM000010'
  1598. CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
  1599. CALL mpi_file_read_at(iunit,file_offset(index+1), &
  1600. dumdata,hor_size,mpi_real4, &
  1601. mpi_status_ignore, ierr)
  1602. DO J=JTS,min(JTE,JDE-1)
  1603. DO I=ITS,min(ITE,IDE-1)
  1604. grid%sm000010(I,J)=dumdata(I,J,1)
  1605. ENDDO
  1606. ENDDO
  1607. varName='PSFC'
  1608. CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
  1609. CALL mpi_file_read_at(iunit,file_offset(index+1), &
  1610. dumdata,hor_size,mpi_real4, &
  1611. mpi_status_ignore, ierr)
  1612. DO J=JTS,min(JTE,JDE-1)
  1613. DO I=ITS,min(ITE,IDE-1)
  1614. grid%psfc(I,J)=dumdata(I,J,1)
  1615. ENDDO
  1616. ENDDO
  1617. varName='RH'
  1618. CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
  1619. CALL mpi_file_read_at(iunit,file_offset(index+1), &
  1620. dumdata,hor_size*num_metgrid_levels,mpi_real4, &
  1621. mpi_status_ignore, ierr)
  1622. DO K=1,num_metgrid_levels
  1623. DO J=JTS,min(JTE,JDE-1)
  1624. DO I=ITS,min(ITE,IDE-1)
  1625. grid%rh_gc(I,J,K)=dumdata(I,J,K)
  1626. ENDDO
  1627. ENDDO
  1628. ENDDO
  1629. varName='VV'
  1630. CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
  1631. CALL mpi_file_read_at(iunit,file_offset(index+1), &
  1632. dumdata,hor_size*num_metgrid_levels,mpi_real4, &
  1633. mpi_status_ignore, ierr)
  1634. DO K=1,num_metgrid_levels
  1635. DO J=JTS,min(JTE,JDE-1)
  1636. DO I=ITS,min(ITE,IDE-1)
  1637. grid%v_gc(I,J,K)=dumdata(I,J,K)
  1638. ENDDO
  1639. ENDDO
  1640. ENDDO
  1641. varName='UU'
  1642. CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
  1643. CALL mpi_file_read_at(iunit,file_offset(index+1), &
  1644. dumdata,hor_size*num_metgrid_levels,mpi_real4, &
  1645. mpi_status_ignore, ierr)
  1646. DO K=1,num_metgrid_levels
  1647. DO J=JTS,min(JTE,JDE-1)
  1648. DO I=ITS,min(ITE,IDE-1)
  1649. grid%u_gc(I,J,K)=dumdata(I,J,K)
  1650. ENDDO
  1651. ENDDO
  1652. ENDDO
  1653. varName='TT'
  1654. CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
  1655. if (IRET .eq. 0) then
  1656. CALL mpi_file_read_at(iunit,file_offset(index+1), &
  1657. dumdata,hor_size*num_metgrid_levels,mpi_real4, &
  1658. mpi_status_ignore, ierr)
  1659. DO K=1,num_metgrid_levels
  1660. DO J=JTS,min(JTE,JDE-1)
  1661. DO I=ITS,min(ITE,IDE-1)
  1662. grid%t_gc(I,J,K)=dumdata(I,J,K)
  1663. ENDDO
  1664. ENDDO
  1665. ENDDO
  1666. endif
  1667. ! varName='RWMR'
  1668. ! CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
  1669. ! if (iret .ne. 0) then
  1670. ! grid%rwmr_gc=0.
  1671. ! grid%snmr_gc=0.
  1672. ! grid%clwmr_gc=0.
  1673. ! grid%cice_gc=0.
  1674. ! grid%rimef_gc=0.
  1675. ! write(0,*) 'skipping cloud reads'
  1676. ! goto 979
  1677. ! endif
  1678. ! CALL mpi_file_read_at(iunit,file_offset(index+1), &
  1679. ! dumdata,hor_size*num_metgrid_levels,mpi_real4, &
  1680. ! mpi_status_ignore, ierr)
  1681. ! DO K=1,num_metgrid_levels
  1682. ! DO J=JTS,min(JTE,JDE-1)
  1683. ! DO I=ITS,min(ITE,IDE-1)
  1684. ! grid%rwmr_gc(I,J,K)=dumdata(I,J,K)
  1685. ! ENDDO
  1686. ! ENDDO
  1687. ! ENDDO
  1688. ! varName='SNMR'
  1689. ! CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
  1690. ! CALL mpi_file_read_at(iunit,file_offset(index+1), &
  1691. ! dumdata,hor_size*num_metgrid_levels,mpi_real4, &
  1692. ! mpi_status_ignore, ierr)
  1693. ! DO K=1,num_metgrid_levels
  1694. ! DO J=JTS,min(JTE,JDE-1)
  1695. ! DO I=ITS,min(ITE,IDE-1)
  1696. ! grid%snmr_gc(I,J,K)=dumdata(I,J,K)
  1697. ! ENDDO
  1698. ! ENDDO
  1699. ! ENDDO
  1700. ! varName='CLWMR'
  1701. ! CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
  1702. ! CALL mpi_file_read_at(iunit,file_offset(index+1), &
  1703. ! dumdata,hor_size*num_metgrid_levels,mpi_real4, &
  1704. ! mpi_status_ignore, ierr)
  1705. ! DO K=1,num_metgrid_levels
  1706. ! DO J=JTS,min(JTE,JDE-1)
  1707. ! DO I=ITS,min(ITE,IDE-1)
  1708. ! grid%clwmr_gc(I,J,K)=dumdata(I,J,K)
  1709. ! ENDDO
  1710. ! ENDDO
  1711. ! ENDDO
  1712. ! varName='CICE'
  1713. ! CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
  1714. ! CALL mpi_file_read_at(iunit,file_offset(index+1), &
  1715. ! dumdata,hor_size*num_metgrid_levels,mpi_real4, &
  1716. ! mpi_status_ignore, ierr)
  1717. ! DO K=1,num_metgrid_levels
  1718. ! DO J=JTS,min(JTE,JDE-1)
  1719. ! DO I=ITS,min(ITE,IDE-1)
  1720. ! grid%cice_gc(I,J,K)=dumdata(I,J,K)
  1721. ! ENDDO
  1722. ! ENDDO
  1723. ! ENDDO
  1724. ! varName='FRIMEF'
  1725. ! CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
  1726. ! CALL mpi_file_read_at(iunit,file_offset(index+1), &
  1727. ! dumdata,hor_size*num_metgrid_levels,mpi_real4, &
  1728. ! mpi_status_ignore, ierr)
  1729. ! DO K=1,num_metgrid_levels
  1730. ! DO J=JTS,min(JTE,JDE-1)
  1731. ! DO I=ITS,min(ITE,IDE-1)
  1732. ! grid%rimef_gc(I,J,K)=dumdata(I,J,K)
  1733. ! ENDDO
  1734. ! ENDDO
  1735. ! ENDDO
  1736. 979 continue
  1737. ! varName='PMSL'
  1738. varName='SLOPECAT'
  1739. CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
  1740. CALL mpi_file_read_at(iunit,file_offset(index+1), &
  1741. dumdata,hor_size,mpi_real4, &
  1742. mpi_status_ignore, ierr)
  1743. DO J=JTS,min(JTE,JDE-1)
  1744. DO I=ITS,min(ITE,IDE-1)
  1745. grid%slopecat(I,J)=dumdata(I,J,1)
  1746. ENDDO
  1747. ENDDO
  1748. varName='SNOALB'
  1749. CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
  1750. CALL mpi_file_read_at(iunit,file_offset(index+1), &
  1751. dumdata,hor_size,mpi_real4, &
  1752. mpi_status_ignore, ierr)
  1753. DO J=JTS,min(JTE,JDE-1)
  1754. DO I=ITS,min(ITE,IDE-1)
  1755. grid%snoalb(I,J)=dumdata(I,J,1)
  1756. ENDDO
  1757. ENDDO
  1758. num_veg_cat = SIZE ( grid%landusef_gc , DIM=3 )
  1759. num_soil_top_cat = SIZE ( grid%soilctop_gc , DIM=3 )
  1760. num_soil_bot_cat = SIZE ( grid%soilcbot_gc , DIM=3 )
  1761. varName='GREENFRAC'
  1762. CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
  1763. CALL mpi_file_read_at(iunit,file_offset(index+1), &
  1764. dumdata,hor_size*12,mpi_real4, &
  1765. mpi_status_ignore, ierr)
  1766. DO K=1,12
  1767. DO J=JTS,min(JTE,JDE-1)
  1768. DO I=ITS,min(ITE,IDE-1)
  1769. grid%greenfrac_gc(I,J,K)=dumdata(I,J,K)
  1770. ENDDO
  1771. ENDDO
  1772. ENDDO
  1773. varName='ALBEDO12M'
  1774. CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
  1775. CALL mpi_file_read_at(iunit,file_offset(index+1), &
  1776. dumdata,hor_size*12,mpi_real4, &
  1777. mpi_status_ignore, ierr)
  1778. DO K=1,12
  1779. DO J=JTS,min(JTE,JDE-1)
  1780. DO I=ITS,min(ITE,IDE-1)
  1781. grid%albedo12m_gc(I,J,K)=dumdata(I,J,K)
  1782. ENDDO
  1783. ENDDO
  1784. ENDDO
  1785. varName='SOILCBOT'
  1786. CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
  1787. CALL mpi_file_read_at(iunit,file_offset(index+1), &
  1788. dumdata,hor_size*num_soil_bot_cat,mpi_real4, &
  1789. mpi_status_ignore, ierr)
  1790. DO K=1,num_soil_bot_cat
  1791. DO J=JTS,min(JTE,JDE-1)
  1792. DO I=ITS,min(ITE,IDE-1)
  1793. grid%soilcbot_gc(I,J,K)=dumdata(I,J,K)
  1794. ENDDO
  1795. ENDDO
  1796. ENDDO
  1797. varName='SOILCAT'
  1798. CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
  1799. CALL mpi_file_read_at(iunit,file_offset(index+1), &
  1800. dumdata,hor_size,mpi_real4, &
  1801. mpi_status_ignore, ierr)
  1802. DO J=JTS,min(JTE,JDE-1)
  1803. DO I=ITS,min(ITE,IDE-1)
  1804. grid%soilcat(I,J)=dumdata(I,J,1)
  1805. ENDDO
  1806. ENDDO
  1807. varName='SOILCTOP'
  1808. CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
  1809. CALL mpi_file_read_at(iunit,file_offset(index+1), &
  1810. dumdata,hor_size*num_soil_top_cat,mpi_real4, &
  1811. mpi_status_ignore, ierr)
  1812. DO K=1,num_soil_top_cat
  1813. DO J=JTS,min(JTE,JDE-1)
  1814. DO I=ITS,min(ITE,IDE-1)
  1815. grid%soilctop_gc(I,J,K)=dumdata(I,J,K)
  1816. ENDDO
  1817. ENDDO
  1818. ENDDO
  1819. varName='SOILTEMP'
  1820. CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
  1821. CALL mpi_file_read_at(iunit,file_offset(index+1), &
  1822. dumdata,hor_size,mpi_real4, &
  1823. mpi_status_ignore, ierr)
  1824. DO J=JTS,min(JTE,JDE-1)
  1825. DO I=ITS,min(ITE,IDE-1)
  1826. grid%tmn_gc(I,J)=dumdata(I,J,1)
  1827. ENDDO
  1828. ENDDO
  1829. varName='HGT_V'
  1830. CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
  1831. CALL mpi_file_read_at(iunit,file_offset(index+1), &
  1832. dumdata,hor_size,mpi_real4, &
  1833. mpi_status_ignore, ierr)
  1834. DO J=JTS,min(JTE,JDE-1)
  1835. DO I=ITS,min(ITE,IDE-1)
  1836. grid%htv_gc(I,J)=dumdata(I,J,1)
  1837. ENDDO
  1838. ENDDO
  1839. varName='HGT_M'
  1840. CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
  1841. CALL mpi_file_read_at(iunit,file_offset(index+1), &
  1842. dumdata,hor_size,mpi_real4, &
  1843. mpi_status_ignore, ierr)
  1844. DO J=JTS,min(JTE,JDE-1)
  1845. DO I=ITS,min(ITE,IDE-1)
  1846. grid%ht_gc(I,J)=dumdata(I,J,1)
  1847. ENDDO
  1848. ENDDO
  1849. varName='LU_INDEX'
  1850. CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
  1851. CALL mpi_file_read_at(iunit,file_offset(index+1), &
  1852. dumdata,hor_size,mpi_real4, &
  1853. mpi_status_ignore, ierr)
  1854. DO J=JTS,min(JTE,JDE-1)
  1855. DO I=ITS,min(ITE,IDE-1)
  1856. grid%lu_index(I,J)=dumdata(I,J,1)
  1857. ENDDO
  1858. ENDDO
  1859. varName='LANDUSEF'
  1860. CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
  1861. CALL mpi_file_read_at(iunit,file_offset(index+1), &
  1862. dumdata,hor_size*num_veg_cat,mpi_real4, &
  1863. mpi_status_ignore, ierr)
  1864. DO K=1,num_veg_cat
  1865. DO J=JTS,min(JTE,JDE-1)
  1866. DO I=ITS,min(ITE,IDE-1)
  1867. grid%landusef_gc(I,J,K)=dumdata(I,J,K)
  1868. ENDDO
  1869. ENDDO
  1870. ENDDO
  1871. varName='LANDMASK'
  1872. CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
  1873. CALL mpi_file_read_at(iunit,file_offset(index+1), &
  1874. dumdata,hor_size,mpi_real4, &
  1875. mpi_status_ignore, ierr)
  1876. DO J=JTS,min(JTE,JDE-1)
  1877. DO I=ITS,min(ITE,IDE-1)
  1878. grid%landmask(I,J)=dumdata(I,J,1)
  1879. ENDDO
  1880. ENDDO
  1881. varName='XLONG_V'
  1882. CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
  1883. CALL mpi_file_read_at(iunit,file_offset(index+1), &
  1884. dumdata,hor_size,mpi_real4, &
  1885. mpi_status_ignore, ierr)
  1886. DO J=JTS,min(JTE,JDE-1)
  1887. DO I=ITS,min(ITE,IDE-1)
  1888. grid%vlon_gc(I,J)=dumdata(I,J,1)
  1889. ENDDO
  1890. ENDDO
  1891. varName='XLAT_V'
  1892. CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
  1893. CALL mpi_file_read_at(iunit,file_offset(index+1), &
  1894. dumdata,hor_size,mpi_real4, &
  1895. mpi_status_ignore, ierr)
  1896. DO J=JTS,min(JTE,JDE-1)
  1897. DO I=ITS,min(ITE,IDE-1)
  1898. grid%vlat_gc(I,J)=dumdata(I,J,1)
  1899. ENDDO
  1900. ENDDO
  1901. varName='XLONG_M'
  1902. CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
  1903. CALL mpi_file_read_at(iunit,file_offset(index+1), &
  1904. dumdata,hor_size,mpi_real4, &
  1905. mpi_status_ignore, ierr)
  1906. DO J=JTS,min(JTE,JDE-1)
  1907. DO I=ITS,min(ITE,IDE-1)
  1908. grid%hlon_gc(I,J)=dumdata(I,J,1)
  1909. ENDDO
  1910. ENDDO
  1911. varName='XLAT_M'
  1912. CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
  1913. CALL mpi_file_read_at(iunit,file_offset(index+1), &
  1914. dumdata,hor_size,mpi_real4, &
  1915. mpi_status_ignore, ierr)
  1916. DO J=JTS,min(JTE,JDE-1)
  1917. DO I=ITS,min(ITE,IDE-1)
  1918. grid%hlat_gc(I,J)=dumdata(I,J,1)
  1919. ENDDO
  1920. ENDDO
  1921. !!! GWD fields
  1922. varName='HSTDV'
  1923. CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
  1924. CALL mpi_file_read_at(iunit,file_offset(index+1), &
  1925. dumdata,hor_size,mpi_real4, &
  1926. mpi_status_ignore, ierr)
  1927. DO J=JTS,min(JTE,JDE-1)
  1928. DO I=ITS,min(ITE,IDE-1)
  1929. grid%hstdv(I,J)=dumdata(I,J,1)
  1930. ENDDO
  1931. ENDDO
  1932. varName='HCNVX'
  1933. CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
  1934. CALL mpi_file_read_at(iunit,file_offset(index+1), &
  1935. dumdata,hor_size,mpi_real4, &
  1936. mpi_status_ignore, ierr)
  1937. DO J=JTS,min(JTE,JDE-1)
  1938. DO I=ITS,min(ITE,IDE-1)
  1939. grid%hcnvx(I,J)=dumdata(I,J,1)
  1940. ENDDO
  1941. ENDDO
  1942. varName='HASYW'
  1943. CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
  1944. CALL mpi_file_read_at(iunit,file_offset(index+1), &
  1945. dumdata,hor_size,mpi_real4, &
  1946. mpi_status_ignore, ierr)
  1947. DO J=JTS,min(JTE,JDE-1)
  1948. DO I=ITS,min(ITE,IDE-1)
  1949. grid%hasyw(I,J)=dumdata(I,J,1)
  1950. ENDDO
  1951. ENDDO
  1952. varName='HASYS'
  1953. CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
  1954. CALL mpi_file_read_at(iunit,file_offset(index+1), &
  1955. dumdata,hor_size,mpi_real4, &
  1956. mpi_status_ignore, ierr)
  1957. DO J=JTS,min(JTE,JDE-1)
  1958. DO I=ITS,min(ITE,IDE-1)
  1959. grid%hasys(I,J)=dumdata(I,J,1)
  1960. ENDDO
  1961. ENDDO
  1962. varName='HASYSW'
  1963. CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
  1964. CALL mpi_file_read_at(iunit,file_offset(index+1), &
  1965. dumdata,hor_size,mpi_real4, &
  1966. mpi_status_ignore, ierr)
  1967. DO J=JTS,min(JTE,JDE-1)
  1968. DO I=ITS,min(ITE,IDE-1)
  1969. grid%hasysw(I,J)=dumdata(I,J,1)
  1970. ENDDO
  1971. ENDDO
  1972. varName='HASYNW'
  1973. CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
  1974. CALL mpi_file_read_at(iunit,file_offset(index+1), &
  1975. dumdata,hor_size,mpi_real4, &
  1976. mpi_status_ignore, ierr)
  1977. DO J=JTS,min(JTE,JDE-1)
  1978. DO I=ITS,min(ITE,IDE-1)
  1979. grid%hasynw(I,J)=dumdata(I,J,1)
  1980. ENDDO
  1981. ENDDO
  1982. varName='HLENW'
  1983. CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
  1984. CALL mpi_file_read_at(iunit,file_offset(index+1), &
  1985. dumdata,hor_size,mpi_real4, &
  1986. mpi_status_ignore, ierr)
  1987. DO J=JTS,min(JTE,JDE-1)
  1988. DO I=ITS,min(ITE,IDE-1)
  1989. grid%hlenw(I,J)=dumdata(I,J,1)
  1990. ENDDO
  1991. ENDDO
  1992. varName='HLENS'
  1993. CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
  1994. CALL mpi_file_read_at(iunit,file_offset(index+1), &
  1995. dumdata,hor_size,mpi_real4, &
  1996. mpi_status_ignore, ierr)
  1997. DO J=JTS,min(JTE,JDE-1)
  1998. DO I=ITS,min(ITE,IDE-1)
  1999. grid%hlens(I,J)=dumdata(I,J,1)
  2000. ENDDO
  2001. ENDDO
  2002. varName='HLENSW'
  2003. CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
  2004. CALL mpi_file_read_at(iunit,file_offset(index+1), &
  2005. dumdata,hor_size,mpi_real4, &
  2006. mpi_status_ignore, ierr)
  2007. DO J=JTS,min(JTE,JDE-1)
  2008. DO I=ITS,min(ITE,IDE-1)
  2009. grid%hlensw(I,J)=dumdata(I,J,1)
  2010. ENDDO
  2011. ENDDO
  2012. varName='HLENNW'
  2013. CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
  2014. CALL mpi_file_read_at(iunit,file_offset(index+1), &
  2015. dumdata,hor_size,mpi_real4, &
  2016. mpi_status_ignore, ierr)
  2017. DO J=JTS,min(JTE,JDE-1)
  2018. DO I=ITS,min(ITE,IDE-1)
  2019. grid%hlennw(I,J)=dumdata(I,J,1)
  2020. ENDDO
  2021. ENDDO
  2022. varName='HANGL'
  2023. CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
  2024. CALL mpi_file_read_at(iunit,file_offset(index+1), &
  2025. dumdata,hor_size,mpi_real4, &
  2026. mpi_status_ignore, ierr)
  2027. DO J=JTS,min(JTE,JDE-1)
  2028. DO I=ITS,min(ITE,IDE-1)
  2029. grid%hangl(I,J)=dumdata(I,J,1)
  2030. ENDDO
  2031. ENDDO
  2032. varName='HANIS'
  2033. CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
  2034. CALL mpi_file_read_at(iunit,file_offset(index+1), &
  2035. dumdata,hor_size,mpi_real4, &
  2036. mpi_status_ignore, ierr)
  2037. DO J=JTS,min(JTE,JDE-1)
  2038. DO I=ITS,min(ITE,IDE-1)
  2039. grid%hanis(I,J)=dumdata(I,J,1)
  2040. ENDDO
  2041. ENDDO
  2042. varName='HSLOP'
  2043. CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
  2044. CALL mpi_file_read_at(iunit,file_offset(index+1), &
  2045. dumdata,hor_size,mpi_real4, &
  2046. mpi_status_ignore, ierr)
  2047. DO J=JTS,min(JTE,JDE-1)
  2048. DO I=ITS,min(ITE,IDE-1)
  2049. grid%hslop(I,J)=dumdata(I,J,1)
  2050. ENDDO
  2051. ENDDO
  2052. varName='HZMAX'
  2053. CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
  2054. CALL mpi_file_read_at(iunit,file_offset(index+1), &
  2055. dumdata,hor_size,mpi_real4, &
  2056. mpi_status_ignore, ierr)
  2057. DO J=JTS,min(JTE,JDE-1)
  2058. DO I=ITS,min(ITE,IDE-1)
  2059. grid%hzmax(I,J)=dumdata(I,J,1)
  2060. ENDDO
  2061. ENDDO
  2062. write(0,*) 'maxval grid%hzmax: ', maxval(grid%hzmax)
  2063. call mpi_file_close(mpi_comm_world, ierr)
  2064. varName='ST000010'
  2065. flag_st000010 = 1
  2066. num_st_levels_input = num_st_levels_input + 1
  2067. st_levels_input(num_st_levels_input) = char2int2(varName(3:8))
  2068. DO J=JTS,min(JTE,JDE-1)
  2069. DO I=ITS,min(ITE,IDE-1)
  2070. st_inputx(I,J,num_st_levels_input + 1) = grid%st000010(i,j)
  2071. ENDDO
  2072. ENDDO
  2073. varName='ST010040'
  2074. flag_st010040 = 1
  2075. num_st_levels_input = num_st_levels_input + 1
  2076. st_levels_input(num_st_levels_input) = char2int2(varName(3:8))
  2077. DO J=JTS,min(JTE,JDE-1)
  2078. DO I=ITS,min(ITE,IDE-1)
  2079. st_inputx(I,J,num_st_levels_input + 1) = grid%st010040(i,j)
  2080. ENDDO
  2081. ENDDO
  2082. varName='ST040100'
  2083. flag_st040100 = 1
  2084. num_st_levels_input = num_st_levels_input + 1
  2085. st_levels_input(num_st_levels_input) = char2int2(varName(3:8))
  2086. DO J=JTS,min(JTE,JDE-1)
  2087. DO I=ITS,min(ITE,IDE-1)
  2088. st_inputx(I,J,num_st_levels_input + 1) = grid%st040100(i,j)
  2089. ENDDO
  2090. ENDDO
  2091. varName='ST100200'
  2092. flag_st100200 = 1
  2093. num_st_levels_input = num_st_levels_input + 1
  2094. st_levels_input(num_st_levels_input) = char2int2(varName(3:8))
  2095. DO J=JTS,min(JTE,JDE-1)
  2096. DO I=ITS,min(ITE,IDE-1)
  2097. st_inputx(I,J,num_st_levels_input + 1) = grid%st100200(i,j)
  2098. ENDDO
  2099. ENDDO
  2100. varName='SM000010'
  2101. flag_sm000010 = 1
  2102. num_sm_levels_input = num_sm_levels_input + 1
  2103. sm_levels_input(num_sm_levels_input) = char2int2(varName(3:8))
  2104. DO J=JTS,min(JTE,JDE-1)
  2105. DO I=ITS,min(ITE,IDE-1)
  2106. sm_inputx(I,J,num_sm_levels_input + 1) = grid%sm000010(i,j)
  2107. ENDDO
  2108. ENDDO
  2109. varName='SM010040'
  2110. flag_sm010040 = 1
  2111. num_sm_levels_input = num_sm_levels_input + 1
  2112. sm_levels_input(num_sm_levels_input) = char2int2(varName(3:8))
  2113. DO J=JTS,min(JTE,JDE-1)
  2114. DO I=ITS,min(ITE,IDE-1)
  2115. sm_inputx(I,J,num_sm_levels_input + 1) = grid%sm010040(i,j)
  2116. ENDDO
  2117. ENDDO
  2118. varName='SM040100'
  2119. flag_sm040100 = 1
  2120. num_sm_levels_input = num_sm_levels_input + 1
  2121. sm_levels_input(num_sm_levels_input) = char2int2(varName(3:8))
  2122. DO J=JTS,min(JTE,JDE-1)
  2123. DO I=ITS,min(ITE,IDE-1)
  2124. sm_inputx(I,J,num_sm_levels_input + 1) = grid%sm040100(i,j)
  2125. ENDDO
  2126. ENDDO
  2127. varName='SM100200'
  2128. flag_sm100200 = 1
  2129. num_sm_levels_input = num_sm_levels_input + 1
  2130. sm_levels_input(num_sm_levels_input) = char2int2(varName(3:8))
  2131. DO J=JTS,min(JTE,JDE-1)
  2132. DO I=ITS,min(ITE,IDE-1)
  2133. sm_inputx(I,J,num_sm_levels_input + 1) = grid%sm100200(i,j)
  2134. ENDDO
  2135. ENDDO
  2136. flag_sst = 1
  2137. !new
  2138. sw_inputx=0.
  2139. !new
  2140. sw_input=0.
  2141. do J=JTS,min(JDE-1,JTE)
  2142. do K=1,num_st_levels_alloc
  2143. do I=ITS,min(IDE-1,ITE)
  2144. st_input(I,K,J)=st_inputx(I,J,K)
  2145. sm_input(I,K,J)=sm_inputx(I,J,K)
  2146. sw_input(I,K,J)=sw_inputx(I,J,K)
  2147. enddo
  2148. enddo
  2149. enddo
  2150. ! DEALLOCATE(pmsl)
  2151. ! DEALLOCATE(psfc_in)
  2152. ! DEALLOCATE(st_inputx)
  2153. ! DEALLOCATE(sm_inputx)
  2154. ! DEALLOCATE(sw_inputx)
  2155. ! DEALLOCATE(soilt010_input)
  2156. ! DEALLOCATE(soilt040_input)
  2157. ! DEALLOCATE(soilt100_input)
  2158. ! DEALLOCATE(soilt200_input)
  2159. ! DEALLOCATE(soilm010_input)
  2160. ! DEALLOCATE(soilm040_input)
  2161. ! DEALLOCATE(soilm100_input)
  2162. ! DEALLOCATE(soilm200_input)
  2163. ! DEALLOCATE(dumdata)
  2164. #endif
  2165. end subroutine read_wps
  2166. ! -------------------------------------------------------------------------
  2167. ! -------------------------------------------------------------------------
  2168. ! -------------------------------------------------------------------------
  2169. ! -------------------------------------------------------------------------
  2170. !!!! MPI-IO pieces
  2171. subroutine retrieve_index(index,string,varname_all,nrecs,iret)
  2172. !$$$ subprogram documentation block
  2173. ! . . . .
  2174. ! subprogram: retrieve_index get record number of desired variable
  2175. ! prgmmr: parrish org: np22 date: 2004-11-29
  2176. !
  2177. ! abstract: by examining previously generated inventory of wrf binary restart file,
  2178. ! find record number that contains the header record for variable
  2179. ! identified by input character variable "string".
  2180. !
  2181. ! program history log:
  2182. ! 2004-11-29 parrish
  2183. !
  2184. ! input argument list:
  2185. ! string - mnemonic for variable desired
  2186. ! varname_all - list of all mnemonics obtained from inventory of file
  2187. ! nrecs - total number of sequential records counted in wrf
  2188. ! binary restart file
  2189. !
  2190. ! output argument list:
  2191. ! index - desired record number
  2192. ! iret - return status, set to 0 if variable was found,
  2193. ! non-zero if not.
  2194. !
  2195. ! attributes:
  2196. ! language: f90
  2197. ! machine: ibm RS/6000 SP
  2198. !
  2199. !$$$
  2200. implicit none
  2201. integer,intent(out)::iret
  2202. integer,intent(in)::nrecs
  2203. integer,intent(out):: index
  2204. character(*), intent(in):: string
  2205. character(132),intent(in)::varname_all(nrecs)
  2206. integer i
  2207. iret=0
  2208. do i=1,nrecs
  2209. if(trim(string) == trim(varname_all(i))) then
  2210. index=i
  2211. return
  2212. end if
  2213. end do
  2214. write(6,*)' problem reading wrf nmm binary file, rec id "',trim(string),'" not found'
  2215. iret=-1
  2216. end subroutine retrieve_index
  2217. subroutine next_buf(in_unit,buf,nextbyte,locbyte,thisblock,lrecl,nreads,lastbuf)
  2218. !$$$ subprogram documentation block
  2219. ! . . . .
  2220. ! subprogram: next_buf bring in next direct access block
  2221. ! prgmmr: parrish org: np22 date: 2004-11-29
  2222. !
  2223. ! abstract: bring in next direct access block when needed, as the file is scanned
  2224. ! from beginning to end during counting and inventory of records.
  2225. ! (subroutines count_recs_wrf_binary_file and inventory_wrf_binary_file)
  2226. !
  2227. ! program history log:
  2228. ! 2004-11-29 parrish
  2229. !
  2230. ! input argument list:
  2231. ! in_unit - fortran unit number where input file is opened through.
  2232. ! nextbyte - byte number from beginning of file that is desired
  2233. ! locbyte - byte number from beginning of last block read for desired byt
  2234. ! lrecl - direct access block length
  2235. ! nreads - number of blocks read before now (for diagnostic information
  2236. ! lastbuf - logical, if true, then no more blocks, so return
  2237. !
  2238. ! output argument list:
  2239. ! buf - output array containing contents of next block
  2240. ! locbyte - byte number from beginning of new block read for desired byte
  2241. ! thisblock - number of new block being read by this routine
  2242. ! nreads - number of blocks read now (for diagnostic information only)
  2243. ! lastbuf - logical, if true, then at end of file.
  2244. !
  2245. ! attributes:
  2246. ! language: f90
  2247. ! machine: ibm RS/6000 SP
  2248. !
  2249. !$$$
  2250. ! use kinds, only: i_byte,i_llong
  2251. implicit none
  2252. integer(i_llong) lrecl
  2253. integer in_unit,nreads
  2254. integer(i_byte) buf(lrecl)
  2255. integer(i_llong) nextbyte,locbyte,thisblock
  2256. logical lastbuf
  2257. integer ierr
  2258. if(lastbuf) return
  2259. ierr=0
  2260. nreads=nreads+1
  2261. ! compute thisblock:
  2262. thisblock = 1_i_llong + (nextbyte-1_i_llong)/lrecl
  2263. locbyte = 1_i_llong+mod(locbyte-1_i_llong,lrecl)
  2264. read(in_unit,rec=thisblock,iostat=ierr)buf
  2265. lastbuf = ierr /= 0
  2266. end subroutine next_buf
  2267. subroutine inventory_wrf_binary_file(in_unit,wrf_ges_filename,nrecs, &
  2268. datestr_all,varname_all,domainend_all, &
  2269. start_block,end_block,start_byte,end_byte,file_offset)
  2270. !$$$ subprogram documentation block
  2271. ! . . . .
  2272. ! subprogram: inventory_wrf_binary_file get contents of wrf binary file
  2273. ! prgmmr: parrish org: np22 date: 2004-11-29
  2274. !
  2275. ! abstract: generate list of contents and map of wrf binary file which can be
  2276. ! used for reading and writing with mpi io routines.
  2277. ! same basic routine as count_recs_wrf_binary_file, except
  2278. ! now wrf unpacking routines are used to decode wrf header
  2279. ! records, and send back lists of variable mnemonics, dates,
  2280. ! grid dimensions, and byte addresses relative to start of
  2281. ! file for each field (this is used by mpi io routines).
  2282. !
  2283. ! program history log:
  2284. ! 2004-11-29 parrish
  2285. !
  2286. !
  2287. ! input argument list:
  2288. ! in_unit - fortran unit number where input file is opened through.
  2289. ! wrf_ges_filename - filename of input wrf binary restart file
  2290. ! nrecs - number of sequential records found on input wrf binary restart file.
  2291. ! (obtained by a previous call to count_recs_wrf_binary_file)
  2292. !
  2293. ! output argument list: (all following dimensioned nrecs)
  2294. ! datestr_all - date character string for each field, where applicable (or else blanks)
  2295. ! varname_all - wrf mnemonic for each variable, where applicable (or blank)
  2296. ! domainend_all - dimensions of each field, where applicable (up to 3 dimensions)
  2297. ! start_block - direct access block number containing 1st byte of record
  2298. ! (after 4 byte record mark)
  2299. ! end_block - direct access block number containing last byte of record
  2300. ! (before 4 byte record mark)
  2301. ! start_byte - relative byte address in direct access block of 1st byte of record
  2302. ! end_byte - relative byte address in direct access block of last byte of record
  2303. ! file_offset - absolute address of byte before 1st byte of record (used by mpi io)
  2304. !
  2305. ! attributes:
  2306. ! language: f90
  2307. ! machine: ibm RS/6000 SP
  2308. !
  2309. !$$$
  2310. ! use kinds, only: r_single,i_byte,i_long,i_llong
  2311. use module_internal_header_util
  2312. implicit none
  2313. integer,intent(in)::in_unit,nrecs
  2314. character(*),intent(in)::wrf_ges_filename
  2315. character(132),intent(out)::datestr_all(nrecs),varname_all(nrecs)
  2316. integer,intent(out)::domainend_all(3,nrecs)
  2317. integer,intent(out)::start_block(nrecs),end_block(nrecs)
  2318. integer,intent(out)::start_byte(nrecs),end_byte(nrecs)
  2319. integer(i_llong),intent(out)::file_offset(nrecs)
  2320. integer irecs
  2321. integer(i_llong) nextbyte,locbyte,thisblock
  2322. integer(i_byte) lenrec4(4)
  2323. integer(i_long) lenrec,lensave
  2324. equivalence (lenrec4(1),lenrec)
  2325. integer(i_byte) missing4(4)
  2326. integer(i_long) missing
  2327. equivalence (missing,missing4(1))
  2328. integer(i_llong),parameter:: lrecl=2**16-1
  2329. integer(i_byte) buf(lrecl)
  2330. integer i,loc_count,nreads
  2331. logical lastbuf
  2332. integer(i_byte) hdrbuf4(2048)
  2333. integer(i_long) hdrbuf(512)
  2334. equivalence(hdrbuf(1),hdrbuf4(1))
  2335. integer,parameter:: int_field = 530
  2336. integer,parameter:: int_dom_ti_char = 220
  2337. integer,parameter:: int_dom_ti_real = 140
  2338. integer,parameter:: int_dom_ti_integer = 180
  2339. integer hdrbufsize
  2340. integer inttypesize
  2341. integer datahandle,count
  2342. character(128) element,dumstr,strdata
  2343. integer loccode
  2344. character(132) blanks
  2345. integer typesize
  2346. integer fieldtype,comm,iocomm
  2347. integer domaindesc
  2348. character(132) memoryorder,stagger,dimnames(3)
  2349. integer domainstart(3),domainend(3)
  2350. integer memorystart(3),memoryend(3)
  2351. integer patchstart(3),patchend(3)
  2352. character(132) datestr,varname
  2353. real(r_single) dummy_field(1)
  2354. ! integer dummy_field
  2355. ! real dummy_field
  2356. integer itypesize
  2357. integer idata(1)
  2358. real rdata(16)
  2359. call wrf_sizeof_integer(itypesize)
  2360. inttypesize=itypesize
  2361. blanks=trim(' ')
  2362. open(in_unit,file=trim(wrf_ges_filename),access='direct',recl=lrecl)
  2363. irecs=0
  2364. missing=-9999
  2365. nextbyte=0_i_llong
  2366. locbyte=lrecl
  2367. nreads=0
  2368. lastbuf=.false.
  2369. do
  2370. ! get length of next record
  2371. do i=1,4
  2372. nextbyte=nextbyte+1_i_llong
  2373. locbyte=locbyte+1_i_llong
  2374. if(locbyte > lrecl .and. lastbuf) go to 900
  2375. if(locbyte > lrecl) call next_buf(in_unit,buf,nextbyte,locbyte,thisblock,lrecl,nreads,lastbuf)
  2376. lenrec4(i)=buf(locbyte)
  2377. end do
  2378. if(lenrec <= 0 .and. lastbuf) go to 900
  2379. if(lenrec <= 0 .and. .not. lastbuf) go to 885
  2380. nextbyte=nextbyte+1_i_llong
  2381. locbyte=locbyte+1_i_llong
  2382. if(locbyte > lrecl .and. lastbuf) go to 900
  2383. if(locbyte > lrecl) call next_buf(in_unit,buf,nextbyte,locbyte,thisblock,lrecl,nreads,lastbuf)
  2384. irecs=irecs+1
  2385. start_block(irecs)=thisblock
  2386. start_byte(irecs)=locbyte
  2387. file_offset(irecs)=nextbyte-1_i_llong
  2388. hdrbuf4(1)=buf(locbyte)
  2389. hdrbuf4(2:4)=missing4(2:4)
  2390. hdrbuf4(5:8)=missing4(1:4)
  2391. datestr_all(irecs)=blanks
  2392. varname_all(irecs)=blanks
  2393. domainend_all(1:3,irecs)=0
  2394. loc_count=1
  2395. do i=2,8
  2396. if(loc_count.ge.lenrec) exit
  2397. loc_count=loc_count+1
  2398. nextbyte=nextbyte+1_i_llong
  2399. locbyte=locbyte+1_i_llong
  2400. if(locbyte > lrecl .and. lastbuf) go to 900
  2401. if(locbyte > lrecl) call next_buf(in_unit,buf,nextbyte,locbyte,thisblock,lrecl,nreads,lastbuf)
  2402. hdrbuf4(i)=buf(locbyte)
  2403. end do
  2404. ! if(lenrec==2048) write(6,*)' irecs,hdrbuf(2),int_dom_ti_char,int_field=', &
  2405. ! irecs,hdrbuf(2),int_dom_ti_char,int_field
  2406. if(lenrec==2048.and.(hdrbuf(2) == int_dom_ti_char .or. hdrbuf(2) == int_field &
  2407. .or. hdrbuf(2) == int_dom_ti_real .or. hdrbuf(2) == int_dom_ti_integer)) then
  2408. ! bring in next full record, so we can unpack datestr, varname, and domainend
  2409. do i=9,lenrec
  2410. loc_count=loc_count+1
  2411. nextbyte=nextbyte+1_i_llong
  2412. locbyte=locbyte+1_i_llong
  2413. if(locbyte > lrecl .and. lastbuf) go to 900
  2414. if(locbyte > lrecl) call next_buf(in_unit,buf,nextbyte,locbyte,thisblock,lrecl,nreads,lastbuf)
  2415. hdrbuf4(i)=buf(locbyte)
  2416. end do
  2417. if(hdrbuf(2) == int_dom_ti_char) then
  2418. call int_get_ti_header_char(hdrbuf,hdrbufsize,inttypesize, &
  2419. datahandle,element,dumstr,strdata,loccode)
  2420. varname_all(irecs)=trim(element)
  2421. datestr_all(irecs)=trim(strdata)
  2422. ! write(6,*)' irecs,varname,datestr = ',irecs,trim(varname_all(irecs)),trim(datestr_all(irecs))
  2423. else if(hdrbuf(2) == int_dom_ti_real) then
  2424. call int_get_ti_header_real(hdrbuf,hdrbufsize,inttypesize,typesize, &
  2425. datahandle,element,rdata,count,loccode)
  2426. varname_all(irecs)=trim(element)
  2427. ! datestr_all(irecs)=trim(strdata)
  2428. ! write(6,*) 'count: ', count
  2429. ! write(6,*)' irecs,varname,datestr = ',irecs,trim(varname_all(irecs)),rdata(1:count)
  2430. else if(hdrbuf(2) == int_dom_ti_integer) then
  2431. call int_get_ti_header_integer(hdrbuf,hdrbufsize,inttypesize,typesize, &
  2432. datahandle,element,idata,count,loccode)
  2433. varname_all(irecs)=trim(element)
  2434. ! datestr_all(irecs)=trim(strdata)
  2435. ! write(6,*)' irecs,varname,datestr = ',irecs,trim(varname_all(irecs)),idata(1:count)
  2436. else
  2437. call int_get_write_field_header(hdrbuf,hdrbufsize,inttypesize,typesize, &
  2438. datahandle,datestr,varname,dummy_field,fieldtype,comm,iocomm, &
  2439. domaindesc,memoryorder,stagger,dimnames, &
  2440. domainstart,domainend,memorystart,memoryend,patchstart,patchend)
  2441. varname_all(irecs)=trim(varname)
  2442. datestr_all(irecs)=trim(datestr)
  2443. domainend_all(1:3,irecs)=domainend(1:3)
  2444. ! write(6,*)' irecs,datestr,domend,varname = ', &
  2445. ! irecs,trim(datestr_all(irecs)),domainend_all(1:3,irecs),trim(varname_all(irecs))
  2446. end if
  2447. end if
  2448. nextbyte=nextbyte-loc_count+lenrec
  2449. locbyte=locbyte-loc_count+lenrec
  2450. if(locbyte > lrecl .and. lastbuf) go to 900
  2451. if(locbyte > lrecl) call next_buf(in_unit,buf,nextbyte,locbyte,thisblock,lrecl,nreads,lastbuf)
  2452. end_block(irecs)=thisblock
  2453. end_byte(irecs)=locbyte
  2454. lensave=lenrec
  2455. do i=1,4
  2456. nextbyte=nextbyte+1_i_llong
  2457. locbyte=locbyte+1_i_llong
  2458. if(locbyte > lrecl .and. lastbuf) go to 900
  2459. if(locbyte > lrecl) call next_buf(in_unit,buf,nextbyte,locbyte,thisblock,lrecl,nreads,lastbuf)
  2460. lenrec4(i)=buf(locbyte)
  2461. end do
  2462. if(lenrec /= lensave) go to 890
  2463. end do
  2464. 880 continue
  2465. write(6,*)' reached impossible place in inventory_wrf_binary_file'
  2466. close(in_unit)
  2467. return
  2468. 885 continue
  2469. write(6,*)' problem in inventory_wrf_binary_file, lenrec has bad value before end of file'
  2470. write(6,*)' lenrec =',lenrec
  2471. close(in_unit)
  2472. return
  2473. 890 continue
  2474. write(6,*)' problem in inventory_wrf_binary_file, beginning and ending rec len words unequal'
  2475. write(6,*)' begining reclen =',lensave
  2476. write(6,*)' ending reclen =',lenrec
  2477. write(6,*)' irecs =',irecs
  2478. write(6,*)' nrecs =',nrecs
  2479. close(in_unit)
  2480. return
  2481. 900 continue
  2482. write(6,*)' normal end of file reached in inventory_wrf_binary_file'
  2483. write(6,*)' nblocks=',thisblock
  2484. write(6,*)' irecs,nrecs=',irecs,nrecs
  2485. write(6,*)' nreads=',nreads
  2486. close(in_unit)
  2487. end subroutine inventory_wrf_binary_file
  2488. SUBROUTINE wrf_sizeof_integer( retval )
  2489. IMPLICIT NONE
  2490. INTEGER retval
  2491. ! 4 is defined by CPP
  2492. retval = 4
  2493. RETURN
  2494. END SUBROUTINE wrf_sizeof_integer
  2495. SUBROUTINE wrf_sizeof_real( retval )
  2496. IMPLICIT NONE
  2497. INTEGER retval
  2498. ! 4 is defined by CPP
  2499. retval = 4
  2500. RETURN
  2501. END SUBROUTINE wrf_sizeof_real
  2502. subroutine count_recs_wrf_binary_file(in_unit,wrf_ges_filename,nrecs)
  2503. !$$$ subprogram documentation block
  2504. ! . . . .
  2505. ! subprogram: count_recs_binary_file count # recs on wrf binary file
  2506. ! prgmmr: parrish org: np22 date: 2004-11-29
  2507. !
  2508. ! abstract: count number of sequential records contained in wrf binary
  2509. ! file. this is done by opening the file in direct access
  2510. ! mode with block length of 2**20, the size of the physical
  2511. ! blocks on ibm "blue" and "white" machines. for optimal
  2512. ! performance, change block length to correspond to the
  2513. ! physical block length of host machine disk space.
  2514. ! records are counted by looking for the 4 byte starting
  2515. ! and ending sequential record markers, which contain the
  2516. ! record size in bytes. only blocks are read which are known
  2517. ! by simple calculation to contain these record markers.
  2518. ! even though this is done on one processor, it is still
  2519. ! very fast, and the time will always scale by the number of
  2520. ! sequential records, not their size. this step and the
  2521. ! following inventory step consistently take less than 0.1 seconds
  2522. ! to complete.
  2523. !
  2524. ! program history log:
  2525. ! 2004-11-29 parrish
  2526. !
  2527. ! input argument list:
  2528. ! in_unit - fortran unit number where input file is opened through.
  2529. ! wrf_ges_filename - filename of input wrf binary restart file
  2530. !
  2531. ! output argument list:
  2532. ! nrecs - number of sequential records found on input wrf binary restart fil
  2533. !
  2534. ! attributes:
  2535. ! language: f90
  2536. ! machine: ibm RS/6000 SP
  2537. !
  2538. !$$$
  2539. ! do an initial read through of a wrf binary file, and get total number of sequential fil
  2540. ! use kinds, only: r_single,i_byte,i_long,i_llong
  2541. implicit none
  2542. integer,intent(in)::in_unit
  2543. character(*),intent(in)::wrf_ges_filename
  2544. integer,intent(out)::nrecs
  2545. integer(i_llong) nextbyte,locbyte,thisblock
  2546. integer(i_byte) lenrec4(4)
  2547. integer(i_long) lenrec,lensave
  2548. equivalence (lenrec4(1),lenrec)
  2549. integer(i_byte) missing4(4)
  2550. integer(i_long) missing
  2551. equivalence (missing,missing4(1))
  2552. integer(i_llong),parameter:: lrecl=2**16-1
  2553. integer(i_byte) buf(lrecl)
  2554. integer i,loc_count,nreads
  2555. logical lastbuf
  2556. open(in_unit,file=trim(wrf_ges_filename),access='direct',recl=lrecl)
  2557. nrecs=0
  2558. missing=-9999
  2559. nextbyte=0_i_llong
  2560. locbyte=lrecl
  2561. nreads=0
  2562. lastbuf=.false.
  2563. do
  2564. ! get length of next record
  2565. do i=1,4
  2566. nextbyte=nextbyte+1_i_llong
  2567. locbyte=locbyte+1_i_llong
  2568. if(locbyte > lrecl .and. lastbuf) go to 900
  2569. if(locbyte > lrecl) call next_buf(in_unit,buf,nextbyte,locbyte,thisblock,lrecl,nreads,lastbuf)
  2570. lenrec4(i)=buf(locbyte)
  2571. end do
  2572. if(lenrec <= 0 .and. lastbuf) go to 900
  2573. if(lenrec <= 0 .and. .not.lastbuf) go to 885
  2574. nextbyte=nextbyte+1_i_llong
  2575. locbyte=locbyte+1_i_llong
  2576. if(locbyte > lrecl .and. lastbuf) go to 900
  2577. if(locbyte > lrecl) call next_buf(in_unit,buf,nextbyte,locbyte,thisblock,lrecl,nreads,lastbuf)
  2578. nrecs=nrecs+1
  2579. loc_count=1
  2580. do i=2,4
  2581. if(loc_count.ge.lenrec) exit
  2582. loc_count=loc_count+1
  2583. nextbyte=nextbyte+1_i_llong
  2584. locbyte=locbyte+1_i_llong
  2585. if(locbyte > lrecl .and. lastbuf) go to 900
  2586. if(locbyte > lrecl) call next_buf(in_unit,buf,nextbyte,locbyte,thisblock,lrecl,nreads,lastbuf)
  2587. end do
  2588. do i=1,4
  2589. if(loc_count.ge.lenrec) exit
  2590. loc_count=loc_count+1
  2591. nextbyte=nextbyte+1_i_llong
  2592. locbyte=locbyte+1_i_llong
  2593. if(locbyte > lrecl .and. lastbuf) go to 900
  2594. if(locbyte > lrecl) call next_buf(in_unit,buf,nextbyte,locbyte,thisblock,lrecl,nreads,lastbuf)
  2595. end do
  2596. nextbyte=nextbyte-loc_count+lenrec
  2597. locbyte=locbyte-loc_count+lenrec
  2598. if(locbyte > lrecl .and. lastbuf) go to 900
  2599. if(locbyte > lrecl) call next_buf(in_unit,buf,nextbyte,locbyte,thisblock,lrecl,nreads,lastbuf)
  2600. lensave=lenrec
  2601. do i=1,4
  2602. nextbyte=nextbyte+1_i_llong
  2603. locbyte=locbyte+1_i_llong
  2604. if(locbyte > lrecl .and. lastbuf) go to 900
  2605. if(locbyte > lrecl) call next_buf(in_unit,buf,nextbyte,locbyte,thisblock,lrecl,nreads,lastbuf)
  2606. lenrec4(i)=buf(locbyte)
  2607. end do
  2608. if(lenrec /= lensave) go to 890
  2609. end do
  2610. 880 continue
  2611. write(6,*)' reached impossible place in count_recs_wrf_binary_file'
  2612. close(in_unit)
  2613. return
  2614. 885 continue
  2615. write(6,*)' problem in count_recs_wrf_binary_file, lenrec has bad value before end of file'
  2616. write(6,*)' lenrec =',lenrec
  2617. close(in_unit)
  2618. return
  2619. 890 continue
  2620. write(6,*)' problem in count_recs_wrf_binary_file, beginning and ending rec len words unequal'
  2621. write(6,*)' begining reclen =',lensave
  2622. write(6,*)' ending reclen =',lenrec
  2623. close(in_unit)
  2624. return
  2625. 900 continue
  2626. write(6,*)' normal end of file reached in count_recs_wrf_binary_file'
  2627. write(6,*)' nblocks=',thisblock
  2628. write(6,*)' nrecs=',nrecs
  2629. write(6,*)' nreads=',nreads
  2630. close(in_unit)
  2631. end subroutine count_recs_wrf_binary_file
  2632. subroutine retrieve_field(in_unit,wrfges,out,start_block,end_block,start_byte,end_byte)
  2633. !$$$ subprogram documentation block
  2634. ! . . . .
  2635. ! subprogram: retrieve_field retrieve field from wrf binary file
  2636. ! prgmmr: parrish org: np22 date: 2004-11-29
  2637. !
  2638. ! abstract: still using direct access, retrieve a field from the wrf binary restart file.
  2639. !
  2640. ! program history log:
  2641. ! 2004-11-29 parrish
  2642. !
  2643. ! input argument list:
  2644. ! in_unit - fortran unit number where input file is opened through.
  2645. ! wrfges - filename of input wrf binary restart file
  2646. ! start_block - direct access block number containing 1st byte of record
  2647. ! (after 4 byte record mark)
  2648. ! end_block - direct access block number containing last byte of record
  2649. ! (before 4 byte record mark)
  2650. ! start_byte - relative byte address in direct access block of 1st byte of record
  2651. ! end_byte - relative byte address in direct access block of last byte of record
  2652. !
  2653. ! output argument list:
  2654. ! out - output buffer where desired field is deposited
  2655. !
  2656. ! attributes:
  2657. ! language: f90
  2658. ! machine: ibm RS/6000 SP
  2659. !
  2660. !$$$
  2661. ! use kinds, only: i_byte,i_kind
  2662. implicit none
  2663. integer(i_kind),intent(in)::in_unit
  2664. character(50),intent(in)::wrfges
  2665. integer(i_kind),intent(in)::start_block,end_block,start_byte,end_byte
  2666. integer(i_byte),intent(out)::out(*)
  2667. integer(i_llong),parameter:: lrecl=2**16-1
  2668. integer(i_byte) buf(lrecl)
  2669. integer(i_kind) i,ii,k
  2670. integer ierr, ibegin, iend
  2671. open(in_unit,file=trim(wrfges),access='direct',recl=lrecl)
  2672. write(6,*)' in retrieve_field, start_block,end_block=',start_block,end_block
  2673. write(6,*)' in retrieve_field, start_byte,end_byte=',start_byte,end_byte
  2674. ii=0
  2675. ierr=0
  2676. do k=start_block,end_block
  2677. read(in_unit,rec=k,iostat=ierr)buf
  2678. ibegin=1 ; iend=lrecl
  2679. if(k == start_block) ibegin=start_byte
  2680. if(k == end_block) iend=end_byte
  2681. do i=ibegin,iend
  2682. ii=ii+1
  2683. out(ii)=buf(i)
  2684. end do
  2685. end do
  2686. close(in_unit)
  2687. end subroutine retrieve_field
  2688. END MODULE module_si_io_nmm