PageRenderTime 129ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 2ms

/wrfv2_fire/external/io_phdf5/wrf-phdf5.F90

http://github.com/jbeezley/wrf-fire
FORTRAN Modern | 5378 lines | 4323 code | 782 blank | 273 comment | 478 complexity | e5d9ac9f88e1018fcfbca67fdcb8f8d8 MD5 | raw file
Possible License(s): AGPL-1.0
  1. !/***************************************************************************
  2. !* The HDF5 WRF IO module was written by the the HDF Group at NCSA, the *
  3. !* National Center for Supercomputing Applications. *
  4. !* HDF Group *
  5. !* National Center for Supercomputing Applications *
  6. !* University of Illinois at Urbana-Champaign *
  7. !* 605 E. Springfield, Champaign IL 61820 *
  8. !* http://hdf.ncsa.uiuc.edu/ *
  9. !* *
  10. !* Copyright 2004 by the Board of Trustees, University of Illinois, *
  11. !* *
  12. !* Redistribution or use of this IO module, with or without modification, *
  13. !* is permitted for any purpose, including commercial purposes. *
  14. !* *
  15. !* This software is an unsupported prototype. Use at your own risk. *
  16. !* http://hdf.ncsa.uiuc.edu/apps/WRF-ROMS *
  17. !* *
  18. !* This work was funded by the MEAD expedition at the National Center *
  19. !* for Supercomputing Applications, NCSA. For more information see: *
  20. !* http://www.ncsa.uiuc.edu/expeditions/MEAD *
  21. !* *
  22. !* *
  23. !****************************************************************************/
  24. subroutine HDF5IOWRITE(DataHandle,Comm,DateStr,Length,DomainStart,DomainEnd &
  25. ,PatchStart,PatchEnd,MemoryOrder &
  26. ,WrfDType,FieldType,groupID,TimeIndex &
  27. ,DimRank ,DatasetName,XField,Status)
  28. use wrf_phdf5_data
  29. use ext_phdf5_support_routines
  30. use HDF5
  31. implicit none
  32. include 'mpif.h'
  33. include 'wrf_status_codes.h'
  34. integer ,intent(in) :: DataHandle
  35. integer ,intent(inout) :: Comm
  36. character*(*) ,intent(in) :: DateStr
  37. integer,dimension(NVarDims) ,intent(in) :: Length
  38. integer,dimension(NVarDims) ,intent(in) :: DomainStart
  39. integer,dimension(NVarDims) ,intent(in) :: DomainEnd
  40. integer,dimension(NVarDims) ,intent(in) :: PatchStart
  41. integer,dimension(NVarDims) ,intent(in) :: PatchEnd
  42. character*(*) ,intent(in) :: MemoryOrder
  43. integer ,intent(in) :: WrfDType
  44. integer(hid_t) ,intent(in) :: FieldType
  45. integer(hid_t) ,intent(in) :: groupID
  46. integer ,intent(in) :: TimeIndex
  47. integer,dimension(*) ,intent(in) :: DimRank
  48. character (*) ,intent(in) :: DatasetName
  49. integer,dimension(*) ,intent(inout) :: XField
  50. integer ,intent(out) :: Status
  51. integer(hid_t) :: dset_id
  52. integer :: NDim
  53. integer,dimension(NVarDims) :: VStart
  54. integer,dimension(NVarDims) :: VCount
  55. character (3) :: Mem0
  56. character (3) :: UCMem0
  57. type(wrf_phdf5_data_handle) ,pointer :: DH
  58. ! attribute defination
  59. integer(hid_t) :: dimaspace_id ! DimRank dataspace id
  60. integer(hid_t) :: dimattr_id ! DimRank attribute id
  61. integer(hsize_t) ,dimension(1) :: dim_space
  62. INTEGER(HID_T) :: dspace_id ! Raw Data memory Dataspace id
  63. INTEGER(HID_T) :: fspace_id ! Raw Data file Dataspace id
  64. INTEGER(HID_T) :: crp_list ! chunk identifier
  65. integer(hid_t) :: h5_atypeid ! for fieldtype,memorder attribute
  66. integer(hid_t) :: h5_aspaceid ! for fieldtype,memorder
  67. integer(hid_t) :: h5_attrid ! for fieldtype,memorder
  68. integer(hsize_t), dimension(7) :: adata_dims
  69. integer :: routine_atype
  70. integer, dimension(:),allocatable :: dimrank_data
  71. INTEGER(HSIZE_T), dimension(:),allocatable :: dims ! Dataset dimensions
  72. INTEGER(HSIZE_T), dimension(:),allocatable :: sizes ! Dataset dimensions
  73. INTEGER(HSIZE_T), dimension(:),allocatable :: chunk_dims
  74. INTEGER(HSIZE_T), dimension(:),allocatable :: hdf5_maxdims
  75. INTEGER(HSIZE_T), dimension(:),allocatable :: offset
  76. INTEGER(HSIZE_T), dimension(:),allocatable :: count
  77. INTEGER(HSIZE_T), DIMENSION(7) :: dimsfi
  78. integer :: hdf5err
  79. integer :: i,j
  80. integer(size_t) :: dsetsize
  81. ! FOR PARALLEL IO
  82. integer(hid_t) :: xfer_list
  83. logical :: no_par
  84. ! get the handle
  85. call GetDH(DataHandle,DH,Status)
  86. if(Status /= WRF_NO_ERR) then
  87. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  88. call wrf_debug ( WARN , msg)
  89. return
  90. endif
  91. ! get the rank of the dimension
  92. call GetDim(MemoryOrder,NDim,Status)
  93. if(Status /= WRF_NO_ERR) then
  94. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  95. call wrf_debug ( WARN , msg)
  96. return
  97. endif
  98. ! If patch is equal to domain, the parallel is not necessary, sequential is used.
  99. ! In this version, we haven't implemented this yet.
  100. ! We use no_par to check whether we can use compact data storage.
  101. no_par = .TRUE.
  102. do i = 1,NDim
  103. if((PatchStart(i)/=DomainStart(i)).or.(PatchEnd(i)/=DomainEnd(i))) then
  104. no_par = .FALSE.
  105. exit
  106. endif
  107. enddo
  108. ! change the different Memory Order to XYZ for patch and domain
  109. if(MemoryOrder.NE.'0') then
  110. call ExtOrder(MemoryOrder,PatchStart,Status)
  111. call ExtOrder(MemoryOrder,PatchEnd,Status)
  112. call ExtOrder(MemoryOrder,DomainStart,Status)
  113. call ExtOrder(MemoryOrder,DomainEnd,Status)
  114. endif
  115. ! allocating memory for dynamic arrays;
  116. ! since the time step is always 1, we may ignore the fourth
  117. ! dimension time; now keep it to make it consistent with sequential version
  118. allocate(dims(NDim+1))
  119. allocate(count(NDim+1))
  120. allocate(offset(NDim+1))
  121. allocate(sizes(NDim+1))
  122. ! arrange offset, count for each hyperslab
  123. dims(1:NDim) = DomainEnd(1:NDim) - DomainStart(1:NDim) + 1
  124. dims(NDim+1) = 1
  125. count(NDim+1) = 1
  126. count(1:NDim) = Length(1:NDim)
  127. offset(NDim+1) = 0
  128. offset(1:NDim) = PatchStart(1:NDim) - 1
  129. ! allocate the dataspace to write hyperslab data
  130. dimsfi = 0
  131. do i = 1, NDim + 1
  132. dimsfi(i) = count(i)
  133. enddo
  134. ! create the memory space id
  135. call h5screate_simple_f(NDim+1,count,dspace_id,hdf5err,count)
  136. if(hdf5err.lt.0) then
  137. Status = WRF_HDF5_ERR_DATASPACE
  138. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  139. call wrf_debug ( WARN , msg)
  140. deallocate(dims)
  141. deallocate(count)
  142. deallocate(offset)
  143. deallocate(sizes)
  144. return
  145. endif
  146. ! create file space
  147. call h5screate_simple_f(NDim+1,dims,fspace_id,hdf5err,dims)
  148. if(hdf5err.lt.0) then
  149. Status = WRF_HDF5_ERR_DATASPACE
  150. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  151. call wrf_debug ( WARN , msg)
  152. deallocate(dims)
  153. deallocate(count)
  154. deallocate(offset)
  155. deallocate(sizes)
  156. return
  157. endif
  158. ! compact storage when the patch is equal to the whole domain
  159. ! calculate the non-decomposed dataset size
  160. call h5tget_size_f(FieldType,dsetsize,hdf5err)
  161. if(hdf5err.lt.0) then
  162. Status = WRF_HDF5_ERR_DATATYPE
  163. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  164. call wrf_debug ( WARN , msg)
  165. deallocate(dims)
  166. deallocate(count)
  167. deallocate(offset)
  168. deallocate(sizes)
  169. return
  170. endif
  171. do i =1,NDim
  172. dsetsize = dsetsize*dims(i)
  173. enddo
  174. if(no_par.and.(dsetsize.le.CompDsetSize)) then
  175. call h5pcreate_f(H5P_DATASET_CREATE_F,crp_list,hdf5err)
  176. if(hdf5err.lt.0) then
  177. Status = WRF_HDF5_ERR_PROPERTY_LIST
  178. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  179. call wrf_debug ( WARN , msg)
  180. deallocate(dims)
  181. deallocate(count)
  182. deallocate(offset)
  183. deallocate(sizes)
  184. return
  185. endif
  186. call h5pset_layout_f(crp_list,0,hdf5err)
  187. if(hdf5err.lt.0) then
  188. Status = WRF_HDF5_ERR_PROPERTY_LIST
  189. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  190. call wrf_debug ( WARN , msg)
  191. deallocate(dims)
  192. deallocate(count)
  193. deallocate(offset)
  194. deallocate(sizes)
  195. return
  196. endif
  197. call h5dcreate_f(DH%TgroupIDs(TimeIndex),DatasetName,FieldType,fspace_id,dset_id,&
  198. hdf5err,crp_list)
  199. call h5pclose_f(crp_list,hdf5err)
  200. else
  201. call h5dcreate_f(DH%TgroupIDs(TimeIndex),DatasetName,FieldType,fspace_id,dset_id,hdf5err)
  202. endif
  203. if(hdf5err.lt.0) then
  204. Status = WRF_HDF5_ERR_DATASET_CREATE
  205. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  206. call wrf_debug ( WARN , msg)
  207. deallocate(dims)
  208. deallocate(count)
  209. deallocate(offset)
  210. deallocate(sizes)
  211. return
  212. endif
  213. ! select the correct hyperslab for file space id
  214. CALL h5sselect_hyperslab_f(fspace_id, H5S_SELECT_SET_F, offset, count &
  215. ,hdf5err)
  216. if(hdf5err.lt.0) then
  217. Status = WRF_HDF5_ERR_DATASET_GENERAL
  218. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  219. call wrf_debug ( WARN , msg)
  220. deallocate(dims)
  221. deallocate(count)
  222. deallocate(offset)
  223. deallocate(sizes)
  224. return
  225. endif
  226. ! Create property list for collective dataset write
  227. CALL h5pcreate_f(H5P_DATASET_XFER_F, xfer_list, hdf5err)
  228. if(hdf5err.lt.0) then
  229. Status = WRF_HDF5_ERR_PROPERTY_LIST
  230. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  231. call wrf_debug ( WARN , msg)
  232. deallocate(dims)
  233. deallocate(count)
  234. deallocate(offset)
  235. deallocate(sizes)
  236. return
  237. endif
  238. CALL h5pset_dxpl_mpio_f(xfer_list, H5FD_MPIO_COLLECTIVE_F&
  239. ,hdf5err)
  240. if(hdf5err.lt.0) then
  241. Status = WRF_HDF5_ERR_PROPERTY_LIST
  242. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  243. call wrf_debug ( WARN , msg)
  244. deallocate(dims)
  245. deallocate(count)
  246. deallocate(offset)
  247. deallocate(sizes)
  248. return
  249. endif
  250. ! write the data in memory space to file space
  251. CALL h5dwrite_f(dset_id,FieldType,XField,dimsfi,hdf5err,&
  252. mem_space_id =dspace_id,file_space_id =fspace_id, &
  253. xfer_prp = xfer_list)
  254. if(hdf5err.lt.0) then
  255. Status = WRF_HDF5_ERR_DATASET_WRITE
  256. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  257. call wrf_debug ( WARN , msg)
  258. deallocate(dims)
  259. deallocate(count)
  260. deallocate(offset)
  261. deallocate(sizes)
  262. return
  263. endif
  264. CALL h5pclose_f(xfer_list,hdf5err)
  265. if(hdf5err.lt.0) then
  266. Status = WRF_HDF5_ERR_PROPERTY_LIST
  267. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  268. call wrf_debug ( WARN , msg)
  269. deallocate(dims)
  270. deallocate(count)
  271. deallocate(offset)
  272. deallocate(sizes)
  273. return
  274. endif
  275. if(TimeIndex == 1) then
  276. do i =1, MaxVars
  277. if(DH%dsetids(i) == -1) then
  278. DH%dsetids(i) = dset_id
  279. DH%VarNames(i) = DataSetName
  280. exit
  281. endif
  282. enddo
  283. ! Only writing attributes when TimeIndex ==1
  284. call write_hdf5_attributes(DataHandle,MemoryOrder,WrfDType,DimRank,&
  285. NDim,dset_id,Status)
  286. endif
  287. call h5sclose_f(fspace_id,hdf5err)
  288. call h5sclose_f(dspace_id,hdf5err)
  289. if(TimeIndex /= 1) then
  290. call h5dclose_f(dset_id,hdf5err)
  291. endif
  292. if(hdf5err.lt.0) then
  293. Status = WRF_HDF5_ERR_DATASPACE
  294. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  295. call wrf_debug ( WARN , msg)
  296. deallocate(dims)
  297. deallocate(count)
  298. deallocate(offset)
  299. deallocate(sizes)
  300. return
  301. endif
  302. Status = WRF_NO_ERR
  303. return
  304. end subroutine HDF5IOWRITE
  305. subroutine ext_phdf5_ioinit(SysDepInfo, Status)
  306. use wrf_phdf5_data
  307. use HDF5
  308. implicit none
  309. include 'wrf_status_codes.h'
  310. include 'mpif.h'
  311. CHARACTER*(*), INTENT(IN) :: SysDepInfo
  312. integer, intent(out) :: status
  313. integer :: hdf5err
  314. ! set up some variables inside the derived type
  315. WrfDataHandles(1:WrfDataHandleMax)%Free = .true.
  316. ! ?
  317. WrfDataHandles(1:WrfDataHandleMax)%TimesName = 'Times'
  318. WrfDataHandles(1:WrfDataHandleMax)%DimUnlimName = 'Time'
  319. ! set up HDF5 global variables
  320. call h5open_f(hdf5err)
  321. if(hdf5err .lt.0) then
  322. Status = WRF_HDF5_ERR_CLOSE_GENERAL
  323. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  324. call wrf_debug ( WARN , msg)
  325. return
  326. endif
  327. return
  328. end subroutine ext_phdf5_ioinit
  329. subroutine ext_phdf5_ioclose( DataHandle, Status)
  330. use wrf_phdf5_data
  331. use ext_phdf5_support_routines
  332. use hdf5
  333. implicit none
  334. include 'wrf_status_codes.h'
  335. include 'mpif.h'
  336. integer ,intent(in) :: DataHandle
  337. integer ,intent(out) :: Status
  338. type(wrf_phdf5_data_handle),pointer :: DH
  339. integer :: stat
  340. integer :: NVar
  341. integer :: hdferr
  342. integer :: table_length
  343. integer :: i
  344. integer(hid_t) :: dtype_id
  345. integer :: obj_count
  346. integer(hid_t),allocatable,dimension(:) :: obj_ids
  347. character(len=100) :: buf
  348. integer(size_t) :: name_size
  349. call GetDH(DataHandle,DH,Status)
  350. if(Status /= WRF_NO_ERR) then
  351. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', 906
  352. call wrf_debug ( WARN , msg)
  353. return
  354. endif
  355. ! THE FOLLOWING section writes dimscale information to the data set,may be put into a subroutine
  356. ! check the file status, should be either open_for_read or opened_and_committed
  357. if(DH%FileStatus == WRF_FILE_NOT_OPENED) then
  358. Status = WRF_HDF5_ERR_FILE_OPEN
  359. write(msg,*) 'Warning FILE NOT OPENED in ',__FILE__,', line', __LINE__
  360. call wrf_debug ( WARN , msg)
  361. elseif(DH%FileStatus == WRF_FILE_OPENED_NOT_COMMITTED) then
  362. Status = WRF_HDF5_ERR_DRYRUN_CLOSE
  363. write(msg,*) 'Warning TRY TO CLOSE DRYRUN in ',__FILE__,', line', __LINE__
  364. call wrf_debug ( WARN , msg)
  365. elseif(DH%FileStatus == WRF_FILE_OPENED_AND_COMMITTED) then
  366. ! Handle dim. scale
  367. ! STORE "Times" as the first element of the dimensional table
  368. DH%DIMTABLE(1)%dim_name = 'Time'
  369. DH%DIMTABLE(1)%Length = DH%TimeIndex
  370. DH%DIMTABLE(1)%unlimited = 1
  371. do i =1,MaxTabDims
  372. if(DH%DIMTABLE(i)%dim_name== NO_NAME) then
  373. exit
  374. endif
  375. enddo
  376. table_length = i-1
  377. call store_table(DataHandle,table_length,Status)
  378. if(Status.ne.WRF_NO_ERR) then
  379. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  380. call wrf_debug ( WARN , msg)
  381. return
  382. endif
  383. continue
  384. elseif(DH%FileStatus == WRF_FILE_OPENED_FOR_READ) then
  385. ! call h5dclose_f(DH%TimesID,hdferr)
  386. ! if(hdferr.lt.0) then
  387. ! Status = WRF_HDF5_ERR_DATASET_CLOSE
  388. ! write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  389. ! call wrf_debug ( WARN , msg)
  390. ! return
  391. ! endif
  392. continue
  393. else
  394. Status = WRF_HDF5_ERR_BAD_FILE_STATUS
  395. write(msg,*) 'Fatal hdf5err BAD FILE STATUS in ',__FILE__,', line', __LINE__
  396. call wrf_debug ( FATAL , msg)
  397. return
  398. endif
  399. ! close HDF5 APIs
  400. do NVar = 1, MaxVars
  401. if(DH%DsetIDs(NVar) /= -1) then
  402. call h5dclose_f(DH%DsetIDs(NVar),hdferr)
  403. if(hdferr .ne. 0) then
  404. Status = WRF_HDF5_ERR_DATASET_CLOSE
  405. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  406. call wrf_debug ( WARN , msg)
  407. return
  408. endif
  409. endif
  410. enddo
  411. do i = 1, MaxTimes
  412. if(DH%TgroupIDs(i) /= -1) then
  413. call h5gclose_f(DH%TgroupIDs(i),hdferr)
  414. if(hdferr .ne. 0) then
  415. Status = WRF_HDF5_ERR_DATASET_CLOSE
  416. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  417. call wrf_debug ( WARN , msg)
  418. return
  419. endif
  420. endif
  421. enddo
  422. call h5gclose_f(DH%GroupID,hdferr)
  423. if(hdferr .ne. 0) then
  424. Status = WRF_HDF5_ERR_CLOSE_GENERAL
  425. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  426. call wrf_debug ( WARN , msg)
  427. return
  428. endif
  429. call h5gclose_f(DH%DimGroupID,hdferr)
  430. if(hdferr .ne. 0) then
  431. Status = WRF_HDF5_ERR_CLOSE_GENERAL
  432. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  433. call wrf_debug ( WARN , msg)
  434. return
  435. endif
  436. if(Status /= WRF_NO_ERR) then
  437. write(msg,*) 'HDF5 IO CLOSE error in ',__FILE__,', line', __LINE__
  438. call wrf_debug ( WARN , msg)
  439. return
  440. endif
  441. call h5fclose_f(DH%FileID,hdferr)
  442. if(hdferr .ne. 0) then
  443. Status = WRF_HDF5_ERR_CLOSE_GENERAL
  444. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  445. call wrf_debug ( WARN , msg)
  446. return
  447. endif
  448. if(Status /= WRF_NO_ERR) then
  449. write(msg,*) 'HDF5 IO CLOSE error in ',__FILE__,', line', __LINE__
  450. call wrf_debug ( WARN , msg)
  451. return
  452. endif
  453. call free_memory(DataHandle,Status)
  454. if(Status /= WRF_NO_ERR) then
  455. Status = WRF_HDF5_ERR_OTHERS
  456. write(msg,*) 'Warning Status = ',__FILE__,', line', __LINE__
  457. call wrf_debug ( WARN , msg)
  458. return
  459. endif
  460. DH%Free=.true.
  461. return
  462. end subroutine ext_phdf5_ioclose
  463. subroutine ext_phdf5_ioexit(Status)
  464. use wrf_phdf5_data
  465. use ext_phdf5_support_routines
  466. use HDF5
  467. implicit none
  468. include 'wrf_status_codes.h'
  469. include 'mpif.h'
  470. integer ,intent(out) :: Status
  471. integer :: hdf5err
  472. type(wrf_phdf5_data_handle),pointer :: DH
  473. integer :: i
  474. integer :: stat
  475. ! free memories
  476. do i=1,WrfDataHandleMax
  477. if(.not.WrfDataHandles(i)%Free) then
  478. call free_memory(i,Status)
  479. exit
  480. endif
  481. enddo
  482. if(Status /= WRF_NO_ERR) then
  483. write(msg,*) 'free resources error in ',__FILE__,', line', __LINE__
  484. call wrf_debug ( WARN , msg)
  485. return
  486. endif
  487. CALL h5close_f(hdf5err)
  488. if(hdf5err.lt.0) then
  489. Status = WRF_HDF5_ERR_CLOSE_GENERAL
  490. write(msg,*) 'Fatal DEALLOCATION ERROR in ',__FILE__,', line', __LINE__
  491. call wrf_debug ( FATAL , msg)
  492. return
  493. endif
  494. return
  495. end subroutine ext_phdf5_ioexit
  496. !! This routine will set up everything to read HDF5 files
  497. subroutine ext_phdf5_open_for_read(FileName,Comm,iocomm,SysDepInfo,DataHandle,Status)
  498. use wrf_phdf5_data
  499. use ext_phdf5_support_routines
  500. use HDF5
  501. implicit none
  502. include 'mpif.h'
  503. include 'wrf_status_codes.h'
  504. character*(*),intent(in) :: FileName
  505. integer ,intent(in) :: Comm
  506. integer ,intent(in) :: iocomm
  507. character*(*),intent(in) :: SysDepInfo
  508. integer ,intent(out) :: DataHandle
  509. type(wrf_phdf5_data_handle),pointer :: DH
  510. integer ,intent(out) :: Status
  511. integer(hid_t) :: Fileid
  512. integer(hid_t) :: tgroupid
  513. integer(hid_t) :: dsetid
  514. integer(hid_t) :: dspaceid
  515. integer(hid_t) :: dtypeid
  516. integer(hid_t) :: acc_plist
  517. integer :: nmembers
  518. integer :: submembers
  519. integer :: tmembers
  520. integer :: ObjType
  521. character(len= 256) :: ObjName
  522. character(len= 256) :: GroupName
  523. integer :: i,j
  524. integer(hsize_t), dimension(7) :: data_dims
  525. integer(hsize_t), dimension(1) :: h5dims
  526. integer(hsize_t), dimension(1) :: h5maxdims
  527. integer :: StoredDim
  528. integer :: NumVars
  529. integer :: hdf5err
  530. integer :: info,mpi_size,mpi_rank
  531. character(Len = MaxTimeSLen) :: tname
  532. character(Len = 512) :: tgroupname
  533. ! Allocating the data handle
  534. call allocHandle(DataHandle,DH,Comm,Status)
  535. if(Status /= WRF_NO_ERR) then
  536. return
  537. endif
  538. call h5pcreate_f(H5P_FILE_ACCESS_F,acc_plist,hdf5err)
  539. if(hdf5err.lt.0) then
  540. Status = WRF_HDF5_ERR_PROPERTY_LIST
  541. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  542. call wrf_debug ( WARN , msg)
  543. return
  544. endif
  545. info = MPI_INFO_NULL
  546. CALL h5pset_fapl_mpio_f(acc_plist, comm, info, hdf5err)
  547. ! call h5pset_fapl_mpiposix_f(acc_plist,comm,.false.,hdf5err)
  548. if(hdf5err .lt. 0) then
  549. Status = WRF_HDF5_ERR_PROPERTY_LIST
  550. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  551. call wrf_debug ( WARN , msg)
  552. return
  553. endif
  554. !close every objects when closing HDF5 file.
  555. call h5pset_fclose_degree_f(acc_plist,H5F_CLOSE_STRONG_F,hdf5err)
  556. if(hdf5err .lt. 0) then
  557. Status = WRF_HDF5_ERR_PROPERTY_LIST
  558. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  559. call wrf_debug ( WARN , msg)
  560. return
  561. endif
  562. ! Open the file
  563. call h5fopen_f(FileName,H5F_ACC_RDWR_F,Fileid,hdf5err &
  564. ,acc_plist)
  565. if(hdf5err.lt.0) then
  566. Status = WRF_HDF5_ERR_FILE_OPEN
  567. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  568. call wrf_debug ( WARN , msg)
  569. return
  570. endif
  571. call h5pclose_f(acc_plist,hdf5err)
  572. if(hdf5err .lt. 0) then
  573. Status = WRF_HDF5_ERR_PROPERTY_LIST
  574. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  575. call wrf_debug ( WARN , msg)
  576. return
  577. endif
  578. ! Obtain the number of group
  579. DH%FileID = Fileid
  580. call h5gn_members_f(Fileid,"/",nmembers,hdf5err)
  581. if(hdf5err.lt.0) then
  582. Status = WRF_HDF5_ERR_GROUP
  583. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  584. call wrf_debug ( WARN , msg)
  585. return
  586. endif
  587. ! Retrieve group id and dimensional group id, the index must be from 0
  588. do i = 0, nmembers - 1
  589. call h5gget_obj_info_idx_f(Fileid,"/",i,ObjName,ObjType,&
  590. hdf5err)
  591. if(hdf5err.lt.0) then
  592. Status = WRF_HDF5_ERR_GROUP
  593. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  594. call wrf_debug ( WARN , msg)
  595. return
  596. endif
  597. if(ObjName=='DIM_GROUP') then
  598. call h5gopen_f(Fileid,"/DIM_GROUP",DH%DimGroupID,hdf5err)
  599. if(hdf5err.lt.0) then
  600. Status = WRF_HDF5_ERR_GROUP
  601. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  602. call wrf_debug ( WARN , msg)
  603. return
  604. endif
  605. ! For WRF model, the first seven character must be DATASET
  606. else if(ObjName(1:7)=='DATASET')then
  607. GroupName="/"//ObjName
  608. call h5gopen_f(Fileid,GroupName,DH%GroupID,hdf5err)
  609. if(hdf5err.lt.0) then
  610. Status = WRF_HDF5_ERR_GROUP
  611. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  612. call wrf_debug ( WARN , msg)
  613. return
  614. endif
  615. call h5gn_members_f(FileID,GroupName,submembers,Status)
  616. if(hdf5err.lt.0) then
  617. Status = WRF_HDF5_ERR_GROUP
  618. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  619. call wrf_debug ( WARN , msg)
  620. return
  621. endif
  622. do j = 0, submembers -1
  623. call h5gget_obj_info_idx_f(Fileid,GroupName,j,ObjName,ObjType,hdf5err)
  624. if(hdf5err.lt.0) then
  625. Status = WRF_HDF5_ERR_GROUP
  626. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  627. call wrf_debug ( WARN , msg)
  628. return
  629. endif
  630. call numtochar(j+1,tname)
  631. tgroupname = 'TIME_STAMP_'//tname
  632. if(ObjName(1:17)==tgroupname) then
  633. call h5gopen_f(DH%GroupID,tgroupname,tgroupid,hdf5err)
  634. if(hdf5err.lt.0) then
  635. Status = WRF_HDF5_ERR_GROUP
  636. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  637. call wrf_debug ( WARN , msg)
  638. return
  639. endif
  640. call h5gn_members_f(DH%GroupID,tgroupname,tmembers,hdf5err)
  641. if(hdf5err.lt.0) then
  642. Status = WRF_HDF5_ERR_GROUP
  643. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  644. call wrf_debug ( WARN , msg)
  645. return
  646. endif
  647. call h5dopen_f(tgroupid,"Times",dsetid,hdf5err)
  648. if(hdf5err.lt.0) then
  649. Status = WRF_HDF5_ERR_DATASET_OPEN
  650. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  651. call wrf_debug ( WARN , msg)
  652. return
  653. endif
  654. call h5dget_space_f(dsetid,dspaceid,hdf5err)
  655. if(hdf5err.lt.0) then
  656. Status = WRF_HDF5_ERR_DATASPACE
  657. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  658. call wrf_debug ( WARN , msg)
  659. return
  660. endif
  661. call h5sget_simple_extent_ndims_f(dspaceid,StoredDim,hdf5err)
  662. if(hdf5err.lt.0) then
  663. Status = WRF_HDF5_ERR_DATASPACE
  664. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  665. call wrf_debug ( WARN , msg)
  666. return
  667. endif
  668. call h5sget_simple_extent_dims_f(dspaceid,h5dims,h5maxdims,hdf5err)
  669. if(hdf5err.lt.0) then
  670. Status = WRF_HDF5_ERR_DATASPACE
  671. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  672. call wrf_debug ( WARN , msg)
  673. return
  674. endif
  675. data_dims(1) = h5dims(1)
  676. call h5dget_type_f(dsetid,dtypeid,hdf5err)
  677. if(hdf5err.lt.0) then
  678. Status = WRF_HDF5_ERR_DATATYPE
  679. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  680. call wrf_debug ( WARN , msg)
  681. return
  682. endif
  683. call h5dread_f(dsetid,dtypeid,DH%Times(j+1),data_dims,hdf5err)
  684. if(hdf5err.lt.0) then
  685. Status = WRF_HDF5_ERR_DATASET_READ
  686. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  687. call wrf_debug ( WARN , msg)
  688. return
  689. endif
  690. DH%CurrentVariable = 0
  691. DH%CurrentTime = 0
  692. DH%TimeIndex = 0
  693. call h5tclose_f(dtypeid,hdf5err)
  694. call h5sclose_f(dspaceid,hdf5err)
  695. endif
  696. enddo
  697. DH%NumberTimes = submembers
  698. ! the total member of HDF5 dataset.
  699. DH%NumVars = tmembers*submembers
  700. else
  701. Status = WRF_HDF5_ERR_OTHERS
  702. endif
  703. enddo
  704. DH%FileStatus = WRF_FILE_OPENED_FOR_READ
  705. DH%FileName = FileName
  706. ! obtain dimensional scale table
  707. call retrieve_table(DataHandle,Status)
  708. if(Status /= WRF_NO_ERR) then
  709. return
  710. endif
  711. return
  712. end subroutine ext_phdf5_open_for_read
  713. subroutine ext_phdf5_inquire_opened(DataHandle,FileName,FileStatus,Status)
  714. use wrf_phdf5_data
  715. use ext_phdf5_support_routines
  716. use HDF5
  717. implicit none
  718. include 'wrf_status_codes.h'
  719. integer ,intent(in) :: DataHandle
  720. character*(*) ,intent(in) :: FileName
  721. integer ,intent(out) :: FileStatus
  722. integer ,intent(out) :: Status
  723. type(wrf_phdf5_data_handle) ,pointer :: DH
  724. call GetDH(DataHandle,DH,Status)
  725. if(Status /= WRF_NO_ERR) then
  726. FileStatus = WRF_FILE_NOT_OPENED
  727. return
  728. endif
  729. if(FileName /= DH%FileName) then
  730. FileStatus = WRF_FILE_NOT_OPENED
  731. else
  732. FileStatus = DH%FileStatus
  733. endif
  734. Status = WRF_NO_ERR
  735. return
  736. end subroutine ext_phdf5_inquire_opened
  737. subroutine ext_phdf5_inquire_filename(DataHandle,FileName,FileStatus,Status)
  738. use wrf_phdf5_data
  739. use ext_phdf5_support_routines
  740. use HDF5
  741. implicit none
  742. include 'wrf_status_codes.h'
  743. integer ,intent(in) :: DataHandle
  744. character*(*) ,intent(out) :: FileName
  745. integer ,intent(out) :: FileStatus
  746. integer ,intent(out) :: Status
  747. type(wrf_phdf5_data_handle) ,pointer :: DH
  748. ! This line is added to make sure the wrong file will not be opened
  749. FileStatus = WRF_FILE_NOT_OPENED
  750. call GetDH(DataHandle,DH,Status)
  751. if(Status /= WRF_NO_ERR) then
  752. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,',line',__LINE__
  753. call wrf_debug (WARN, msg)
  754. return
  755. endif
  756. FileName = DH%FileName
  757. FileStatus = DH%FileStatus
  758. Status = WRF_NO_ERR
  759. return
  760. end subroutine ext_phdf5_inquire_filename
  761. ! The real routine to read HDF5 files
  762. subroutine ext_phdf5_read_field(DataHandle,DateStr,Var,Field,FieldType,Comm, &
  763. IOComm, DomainDesc, MemoryOrder, Stagger, DimNames, &
  764. DomainStart,DomainEnd,MemoryStart,MemoryEnd, &
  765. PatchStart,PatchEnd,Status)
  766. use wrf_phdf5_data
  767. use ext_phdf5_support_routines
  768. use HDF5
  769. implicit none
  770. include 'wrf_status_codes.h'
  771. integer ,intent(in) :: DataHandle
  772. character*(*) ,intent(in) :: DateStr
  773. character*(*) ,intent(in) :: Var
  774. integer ,intent(out) :: Field(*)
  775. integer ,intent(in) :: FieldType
  776. integer ,intent(inout) :: Comm
  777. integer ,intent(inout) :: IOComm
  778. integer ,intent(in) :: DomainDesc
  779. character*(*) ,intent(in) :: MemoryOrder
  780. character*(*) ,intent(in) :: Stagger ! Dummy for now
  781. character*(*) , dimension (*) ,intent(in) :: DimNames
  782. integer ,dimension(*) ,intent(in) :: DomainStart, DomainEnd
  783. integer ,dimension(*) ,intent(in) :: MemoryStart, MemoryEnd
  784. integer ,dimension(*) ,intent(in) :: PatchStart, PatchEnd
  785. integer ,intent(out) :: Status
  786. type(wrf_phdf5_data_handle) ,pointer :: DH
  787. integer :: NDim
  788. integer(hid_t) :: GroupID
  789. character (VarNameLen) :: VarName
  790. integer ,dimension(NVarDims) :: Length
  791. integer ,dimension(NVarDims) :: StoredStart
  792. integer ,dimension(NVarDims) :: StoredLen
  793. integer, dimension(NVarDims) :: TemDataStart
  794. integer ,dimension(:,:,:,:) ,allocatable :: XField
  795. integer :: NVar
  796. integer :: j
  797. integer :: i1,i2,j1,j2,k1,k2
  798. integer :: x1,x2,y1,y2,z1,z2
  799. integer :: l1,l2,m1,m2,n1,n2
  800. character (VarNameLen) :: Name
  801. integer :: XType
  802. integer :: StoredDim
  803. integer :: NAtts
  804. integer :: Len
  805. integer :: stat
  806. integer :: di
  807. integer :: FType
  808. integer(hsize_t),dimension(7) :: data_dims
  809. integer(hsize_t),dimension(:) ,allocatable :: h5_dims
  810. integer(hsize_t),dimension(:) ,allocatable :: h5_maxdims
  811. integer(hsize_t),dimension(:) ,allocatable :: DataStart
  812. integer(hsize_t),dimension(:) ,allocatable :: Datacount
  813. integer(hid_t) :: tgroupid
  814. integer(hid_t) :: dsetid
  815. integer(hid_t) :: dtype_id
  816. integer(hid_t) :: dmemtype_id
  817. integer(hid_t) :: dspace_id
  818. integer(hid_t) :: memspace_id
  819. integer :: class_type
  820. integer :: TimeIndex
  821. logical :: flag
  822. integer :: hdf5err
  823. character(Len = MaxTimeSLen) :: tname
  824. character(Len = 512) :: tgroupname
  825. ! FOR PARALLEL IO
  826. integer :: mpi_rank
  827. integer(hid_t) :: xfer_list
  828. call GetDH(DataHandle,DH,Status)
  829. if(Status /= WRF_NO_ERR) then
  830. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  831. call wrf_debug ( WARN , msg)
  832. return
  833. endif
  834. if(DH%FileStatus == WRF_FILE_NOT_OPENED) then
  835. Status = WRF_HDF5_ERR_FILE_NOT_OPENED
  836. write(msg,*) 'Warning FILE NOT OPENED in ',__FILE__,', line', __LINE__
  837. call wrf_debug ( WARN , msg)
  838. elseif(DH%FileStatus == WRF_FILE_OPENED_NOT_COMMITTED) then
  839. Status = WRF_HDF5_ERR_DRYRUN_READ
  840. write(msg,*) 'Warning DRYRUN READ in ',__FILE__,', line', __LINE__
  841. call wrf_debug ( WARN , msg)
  842. elseif(DH%FileStatus == WRF_FILE_OPENED_AND_COMMITTED) then
  843. Status = WRF_HDF5_ERR_READ_WONLY_FILE
  844. write(msg,*) 'Warning READ WRITE ONLY FILE in ',__FILE__,', line', __LINE__
  845. call wrf_debug ( WARN , msg)
  846. elseif(DH%FileStatus == WRF_FILE_OPENED_FOR_READ) then
  847. ! obtain TimeIndex
  848. call GetDataTimeIndex('read',DataHandle,DateStr,TimeIndex,Status)
  849. ! obtain the absolute name of the group where the dataset is located
  850. call numtochar(TimeIndex,tname)
  851. tgroupname = 'TIME_STAMP_'//tname
  852. call h5gopen_f(DH%GroupID,tgroupname,tgroupid,hdf5err)
  853. if(hdf5err.lt.0) then
  854. Status = WRF_HDF5_ERR_GROUP
  855. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  856. call wrf_debug ( WARN , msg)
  857. return
  858. endif
  859. call h5dopen_f(tgroupid,Var,dsetid,hdf5err)
  860. if(hdf5err.lt.0) then
  861. Status = WRF_HDF5_ERR_DATASET_OPEN
  862. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  863. call wrf_debug ( WARN , msg)
  864. return
  865. endif
  866. ! Obtain the memory datatype
  867. select case(FieldType)
  868. case (WRF_REAL)
  869. dmemtype_id = H5T_NATIVE_REAL
  870. case (WRF_DOUBLE)
  871. dmemtype_id = H5T_NATIVE_DOUBLE
  872. case (WRF_INTEGER)
  873. dmemtype_id = H5T_NATIVE_INTEGER
  874. case (WRF_LOGICAL)
  875. dmemtype_id = DH%EnumID
  876. case default
  877. Status = WRF_HDF5_ERR_DATA_TYPE_NOTFOUND
  878. write(msg,*) 'Warning BAD Memory Data type in ',__FILE__,',line',__LINE__
  879. call wrf_debug(WARN,msg)
  880. return
  881. end select
  882. ! Obtain the datatype
  883. call h5dget_type_f(dsetid,dtype_id,hdf5err)
  884. if(hdf5err.lt.0) then
  885. Status = WRF_HDF5_ERR_DATATYPE
  886. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  887. call wrf_debug ( WARN , msg)
  888. return
  889. endif
  890. ! double check whether the Fieldtype is the type of the dataset
  891. ! we may do the force coercion between real and double
  892. call h5tget_class_f(dtype_id,class_type,hdf5err)
  893. if(hdf5err.lt.0) then
  894. Status = WRF_HDF5_ERR_DATATYPE
  895. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  896. call wrf_debug ( WARN , msg)
  897. return
  898. endif
  899. if( (FieldType == WRF_REAL .OR. FieldType == WRF_DOUBLE) ) then
  900. if ( class_type /= H5T_FLOAT_F) then
  901. Status = WRF_HDF5_ERR_TYPE_MISMATCH
  902. write(msg,*) 'Warning TYPE MISMATCH in ',__FILE__,', line', __LINE__
  903. call wrf_debug ( WARN , msg)
  904. return
  905. endif
  906. else if(FieldType == WRF_CHARACTER) then
  907. if(class_type /= H5T_STRING_F) then
  908. Status = WRF_HDF5_ERR_TYPE_MISMATCH
  909. write(msg,*) 'Warning TYPE MISMATCH in ',__FILE__,', line', __LINE__
  910. call wrf_debug ( WARN , msg)
  911. return
  912. endif
  913. else if(FieldType == WRF_INTEGER) then
  914. if(class_type /= H5T_INTEGER_F) then
  915. Status = WRF_HDF5_ERR_TYPE_MISMATCH
  916. write(msg,*) 'Warning TYPE MISMATCH in ',__FILE__,', line', __LINE__
  917. call wrf_debug ( WARN , msg)
  918. return
  919. endif
  920. else if(FieldType == WRF_LOGICAL) then
  921. if(class_type /= H5T_ENUM_F) then
  922. Status = WRF_HDF5_ERR_TYPE_MISMATCH
  923. write(msg,*) 'Warning TYPE MISMATCH in ',__FILE__,', line', __LINE__
  924. call wrf_debug ( WARN , msg)
  925. return
  926. endif
  927. call h5tequal_f(dtype_id,DH%EnumID,flag,hdf5err)
  928. if(hdf5err.lt.0) then
  929. Status = WRF_HDF5_ERR_DATASET_OPEN
  930. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  931. call wrf_debug ( WARN , msg)
  932. return
  933. endif
  934. if(flag .EQV. .FALSE.) then
  935. Status = WRF_HDF5_ERR_TYPE_MISMATCH
  936. write(msg,*) 'Warning TYPE MISMATCH in ',__FILE__,', line', __LINE__
  937. call wrf_debug ( WARN , msg)
  938. return
  939. endif
  940. else
  941. Status = WRF_HDF5_ERR_BAD_DATA_TYPE
  942. write(msg,*)'Fatal Non-WRF supported TYPE in ',__FILE__,', line',__LINE__
  943. call wrf_debug(FATAL, msg)
  944. return
  945. endif
  946. ! Obtain the dataspace, check whether the dataspace is within the range
  947. ! transpose the memory order to the disk order
  948. call h5dget_space_f(dsetid,dspace_id,hdf5err)
  949. if(hdf5err.lt.0) then
  950. Status = WRF_HDF5_ERR_DATASPACE
  951. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  952. call wrf_debug ( WARN , msg)
  953. return
  954. endif
  955. call GetDim(MemoryOrder,NDim,Status)
  956. Length(1:NDim) = PatchEnd(1:NDim)-PatchStart(1:NDim)+1
  957. call ExtOrder(MemoryOrder,Length,Status)
  958. ! Obtain the rank of the dimension
  959. call h5sget_simple_extent_ndims_f(dspace_id,StoredDim,hdf5err)
  960. if(hdf5err.lt.0) then
  961. Status = WRF_HDF5_ERR_DATASPACE
  962. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  963. call wrf_debug ( WARN , msg)
  964. return
  965. endif
  966. ! From NetCDF implementation, only do error handling
  967. if((NDim+1) /= StoredDim) then
  968. Status = WRF_HDF5_ERR_BAD_VARIABLE_DIM
  969. write(msg,*) 'Fatal error BAD VARIABLE DIMENSION in ',__FILE__,', line', __LINE__
  970. call wrf_debug ( FATAL , msg)
  971. return
  972. endif
  973. allocate(h5_dims(StoredDim))
  974. allocate(h5_maxdims(StoredDim))
  975. allocate(DataStart(StoredDim))
  976. allocate(DataCount(StoredDim))
  977. call h5sget_simple_extent_dims_f(dspace_id,h5_dims,h5_maxdims,hdf5err)
  978. if(hdf5err.lt.0) then
  979. Status = WRF_HDF5_ERR_DATASPACE
  980. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  981. call wrf_debug ( WARN , msg)
  982. return
  983. endif
  984. ! This part of code needs to be adjusted, currently use NetCDF convention
  985. do j = 1, NDim
  986. if(Length(j) > h5_dims(j)) then
  987. Status = WRF_HDF5_ERR_READ_PAST_EOF
  988. write(msg,*) 'Warning READ PAST EOF in ',__FILE__,', line', __LINE__
  989. call wrf_debug ( WARN , msg)
  990. return
  991. elseif(Length(j) <= 0) then
  992. Status = WRF_HDF5_ERR_ZERO_LENGTH_READ
  993. write(msg,*) 'Warning ZERO LENGTH READ in ',__FILE__,', line', __LINE__
  994. call wrf_debug ( WARN , msg)
  995. return
  996. endif
  997. enddo
  998. ! create memspace_id
  999. data_dims(1:NDim) = Length(1:NDim)
  1000. data_dims(NDim+1) = 1
  1001. call h5screate_simple_f(NDim+1,data_dims,memspace_id,hdf5err)
  1002. if(hdf5err.lt.0) then
  1003. Status = WRF_HDF5_ERR_DATASPACE
  1004. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  1005. call wrf_debug ( WARN , msg)
  1006. return
  1007. endif
  1008. ! DataStart can start from PatchStart.
  1009. TEMDataStart(1:NDim) = PatchStart(1:NDim)-1
  1010. if(MemoryOrder.NE.'0') then
  1011. call ExtOrder(MemoryOrder,TEMDataStart,Status)
  1012. endif
  1013. DataStart(1:NDim) = TEMDataStart(1:NDim)
  1014. DataStart(NDim+1) = 0
  1015. DataCount(1:NDim) = Length(1:NDim)
  1016. DataCount(NDim+1) = 1
  1017. ! transpose the data XField to Field
  1018. call GetIndices(NDim,MemoryStart,MemoryEnd,l1,l2,m1,m2,n1,n2)
  1019. StoredStart = 1
  1020. StoredLen(1:NDim) = Length(1:NDim)
  1021. ! the dimensional information inside the disk may be greater than
  1022. ! the dimension(PatchEnd-PatchStart); here we can speed up
  1023. ! the performance by using hyperslab selection
  1024. call GetIndices(NDim,StoredStart,StoredLen,x1,x2,y1,y2,z1,z2)
  1025. call GetIndices(NDim,PatchStart,PatchEnd,i1,i2,j1,j2,k1,k2)
  1026. ! di is for double type data
  1027. di = 1
  1028. if(FieldType == WRF_DOUBLE) di = 2
  1029. allocate(XField(di,x1:x2,y1:y2,z1:z2), STAT=stat)
  1030. ! use hyperslab to only read this current timestamp
  1031. call h5sselect_hyperslab_f(dspace_id,H5S_SELECT_SET_F, &
  1032. DataStart,DataCount,hdf5err)
  1033. if(hdf5err.lt.0) then
  1034. Status = WRF_HDF5_ERR_DATASET_GENERAL
  1035. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  1036. call wrf_debug ( WARN , msg)
  1037. return
  1038. endif
  1039. ! read the data in this time stamp
  1040. call h5dread_f(dsetid,dmemtype_id,XField,data_dims,hdf5err, &
  1041. memspace_id,dspace_id,H5P_DEFAULT_F)
  1042. if(hdf5err.lt.0) then
  1043. Status = WRF_HDF5_ERR_DATASET_READ
  1044. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  1045. call wrf_debug ( WARN , msg)
  1046. return
  1047. endif
  1048. call transpose_hdf5('read',MemoryOrder,di, Field,l1,l2,m1,m2,n1,n2 &
  1049. ,XField,x1,x2,y1,y2,z1,z2 &
  1050. ,i1,i2,j1,j2,k1,k2 )
  1051. deallocate(XField, STAT=stat)
  1052. if(stat/= 0) then
  1053. Status = WRF_HDF5_ERR_DEALLOCATION
  1054. write(msg,*) 'Fatal DEALLOCATION ERROR in ',__FILE__,', line', __LINE__
  1055. call wrf_debug ( FATAL , msg)
  1056. return
  1057. endif
  1058. call h5dclose_f(dsetid,hdf5err)
  1059. if(hdf5err.lt.0) then
  1060. Status = WRF_HDF5_ERR_DATASET_CLOSE
  1061. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  1062. call wrf_debug ( WARN , msg)
  1063. return
  1064. endif
  1065. deallocate(h5_dims)
  1066. deallocate(h5_maxdims)
  1067. deallocate(DataStart)
  1068. deallocate(DataCount)
  1069. else
  1070. Status = WRF_HDF5_ERR_BAD_FILE_STATUS
  1071. write(msg,*) 'Fatal error BAD FILE STATUS in ',__FILE__,', line', __LINE__
  1072. call wrf_debug ( FATAL , msg)
  1073. endif
  1074. DH%first_operation = .FALSE.
  1075. return
  1076. end subroutine ext_phdf5_read_field
  1077. !! This routine essentially sets up everything to write HDF5 files
  1078. SUBROUTINE ext_phdf5_open_for_write_begin(FileName,Comm,IOComm,SysDepInfo,DataHandle,Status)
  1079. use wrf_phdf5_data
  1080. use HDF5
  1081. use ext_phdf5_support_routines
  1082. implicit none
  1083. include 'mpif.h'
  1084. include 'wrf_status_codes.h'
  1085. character*(*) ,intent(in) :: FileName
  1086. integer ,intent(in) :: Comm
  1087. integer ,intent(in) :: IOComm
  1088. character*(*) ,intent(in) :: SysDepInfo
  1089. integer ,intent(out) :: DataHandle
  1090. integer ,intent(out) :: Status
  1091. type(wrf_phdf5_data_handle),pointer :: DH
  1092. integer(hid_t) :: file5_id
  1093. integer(hid_t) :: g_id
  1094. integer(hid_t) :: gdim_id
  1095. integer :: hdferr
  1096. integer :: i
  1097. integer :: stat
  1098. character (7) :: Buffer
  1099. integer :: VDimIDs(2)
  1100. character(Len = 512) :: groupname
  1101. ! For parallel IO
  1102. integer(hid_t) :: plist_id
  1103. integer :: hdf5_comm,info,mpi_size,mpi_rank
  1104. call allocHandle(DataHandle,DH,Comm,Status)
  1105. if(Status /= WRF_NO_ERR) then
  1106. write(msg,*) 'Fatal ALLOCATION ERROR in ',__FILE__,', line', __LINE__
  1107. call wrf_debug ( FATAL , msg)
  1108. return
  1109. endif
  1110. DH%TimeIndex = 0
  1111. DH%Times = ZeroDate
  1112. CALL h5pcreate_f(H5P_FILE_ACCESS_F, plist_id, hdferr)
  1113. if(hdferr .lt. 0) then
  1114. Status = WRF_HDF5_ERR_PROPERTY_LIST
  1115. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  1116. call wrf_debug ( WARN , msg)
  1117. return
  1118. endif
  1119. info = MPI_INFO_NULL
  1120. CALL h5pset_fapl_mpio_f(plist_id, comm, info, hdferr)
  1121. if(hdferr .lt. 0) then
  1122. Status = WRF_HDF5_ERR_PROPERTY_LIST
  1123. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  1124. call wrf_debug ( WARN , msg)
  1125. return
  1126. endif
  1127. call h5fcreate_f(FileName,H5F_ACC_TRUNC_F,file5_id,hdferr &
  1128. ,access_prp = plist_id)
  1129. if(hdferr .lt. 0) then
  1130. Status = WRF_HDF5_ERR_FILE_CREATE
  1131. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  1132. call wrf_debug ( WARN , msg)
  1133. return
  1134. endif
  1135. call h5pclose_f(plist_id,hdferr)
  1136. if(hdferr .lt. 0) then
  1137. Status = WRF_HDF5_ERR_PROPERTY_LIST
  1138. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  1139. call wrf_debug ( WARN , msg)
  1140. return
  1141. endif
  1142. DH%FileStatus = WRF_FILE_OPENED_NOT_COMMITTED
  1143. DH%FileName = FileName
  1144. ! should add a check to see whether the file opened has been used by previous handles
  1145. DH%VarNames (1:MaxVars) = NO_NAME
  1146. DH%MDVarNames(1:MaxVars) = NO_NAME
  1147. ! group name information is stored at SysDepInfo
  1148. groupname = "/"//SysDepInfo
  1149. ! write(*,*) "groupname ",groupname
  1150. call h5gcreate_f(file5_id,groupname,g_id,hdferr)
  1151. if(hdferr .lt. 0) then
  1152. Status = WRF_HDF5_ERR_GROUP
  1153. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  1154. call wrf_debug ( WARN , msg)
  1155. return
  1156. endif
  1157. ! create dimensional group id
  1158. call h5gcreate_f(file5_id,"/DIM_GROUP",gdim_id,hdferr)
  1159. if(hdferr .lt. 0) then
  1160. Status = WRF_HDF5_ERR_GROUP
  1161. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  1162. call wrf_debug ( WARN , msg)
  1163. return
  1164. endif
  1165. DH%FileID = file5_id
  1166. DH%GroupID = g_id
  1167. DH%DIMGroupID = gdim_id
  1168. return
  1169. end subroutine ext_phdf5_open_for_write_begin
  1170. ! HDF5 doesnot need this stage, basically this routine
  1171. ! just updates the File status.
  1172. SUBROUTINE ext_phdf5_open_for_write_commit(DataHandle, Status)
  1173. use wrf_phdf5_data
  1174. use ext_phdf5_support_routines
  1175. use HDF5
  1176. implicit none
  1177. include 'wrf_status_codes.h'
  1178. integer ,intent(in) :: DataHandle
  1179. integer ,intent(out) :: Status
  1180. type(wrf_phdf5_data_handle),pointer :: DH
  1181. integer(hid_t) :: enum_type
  1182. integer :: i
  1183. integer :: stat
  1184. call GetDH(DataHandle,DH,Status)
  1185. if(Status /= WRF_NO_ERR) then
  1186. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  1187. call wrf_debug ( WARN , msg)
  1188. return
  1189. endif
  1190. DH%FileStatus = WRF_FILE_OPENED_AND_COMMITTED
  1191. DH%first_operation = .TRUE.
  1192. return
  1193. end subroutine ext_phdf5_open_for_write_commit
  1194. ! The real routine to write HDF5 file
  1195. subroutine ext_phdf5_write_field(DataHandle,DateStr,Var,Field,FieldType,&
  1196. Comm,IOComm,DomainDesc,MemoryOrder, &
  1197. Stagger,DimNames,DomainStart,DomainEnd,&
  1198. MemoryStart,MemoryEnd,PatchStart,PatchEnd,&
  1199. Status)
  1200. use wrf_phdf5_data
  1201. use ext_phdf5_support_routines
  1202. USE HDF5 ! This module contains all necessary modules
  1203. implicit none
  1204. include 'wrf_status_codes.h'
  1205. integer ,intent(in) :: DataHandle
  1206. character*(*) ,intent(in) :: DateStr
  1207. character*(*) ,intent(in) :: Var
  1208. integer ,intent(inout) :: Field(*)
  1209. integer ,intent(in) :: FieldType
  1210. integer ,intent(inout) :: Comm
  1211. integer ,intent(inout) :: IOComm
  1212. integer ,intent(in) :: DomainDesc
  1213. character*(*) ,intent(in) :: MemoryOrder
  1214. character*(*) ,intent(in) :: Stagger ! Dummy for now
  1215. character*(*) , dimension (*) ,intent(in) :: DimNames
  1216. integer ,dimension(*) ,intent(in) :: DomainStart, DomainEnd
  1217. integer ,dimension(*) ,intent(in) :: MemoryStart, MemoryEnd
  1218. integer ,dimension(*) ,intent(in) :: PatchStart, PatchEnd
  1219. integer ,intent(out) :: Status
  1220. type(wrf_phdf5_data_handle) ,pointer :: DH
  1221. integer(hid_t) :: GroupID
  1222. integer :: NDim
  1223. character (VarNameLen) :: VarName
  1224. character (3) :: MemO
  1225. character (3) :: UCMemO
  1226. integer(hid_t) :: DsetID
  1227. integer ,dimension(NVarDims) :: Length
  1228. integer ,dimension(NVarDims) :: DomLength
  1229. integer ,dimension(NVarDims+1) :: DimRank
  1230. character(256),dimension(NVarDims) :: RODimNames
  1231. integer ,dimension(NVarDims) :: StoredStart
  1232. integer ,dimension(:,:,:,:),allocatable :: XField
  1233. integer ,dimension(:,:,:,:),allocatable :: BUFFER! for logical field
  1234. integer :: stat
  1235. integer :: NVar
  1236. integer :: i,j,k,m,dim_flag
  1237. integer :: i1,i2,j1,j2,k1,k2
  1238. integer :: x1,x2,y1,y2,z1,z2
  1239. integer :: l1,l2,m1,m2,n1,n2
  1240. integer(hid_t) :: XType
  1241. integer :: di
  1242. character (256) :: NullName
  1243. integer :: TimeIndex
  1244. integer ,dimension(NVarDims+1) :: temprank
  1245. logical :: NotFound
  1246. NullName = char(0)
  1247. dim_flag = 0
  1248. call GetDH(DataHandle,DH,Status)
  1249. if(Status /= WRF_NO_ERR) then
  1250. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  1251. call wrf_debug ( WARN , msg)
  1252. return
  1253. endif
  1254. ! Examine here, Nov. 7th, 2003
  1255. if(DH%FileStatus == WRF_FILE_OPENED_AND_COMMITTED) then
  1256. ! obtain group id and initialize the rank of dimensional attributes
  1257. GroupID = DH%GroupID
  1258. DimRank = -1
  1259. ! get the rank of the dimension based on MemoryOrder string(cleaver from NetCDF)
  1260. call GetDim(MemoryOrder,NDim,Status)
  1261. if(Status /= WRF_NO_ERR) then
  1262. write(msg,*) 'Warning BAD MEMORY ORDER in ',__FILE__,', line', __LINE__
  1263. call wrf_debug ( WARN , msg)
  1264. return
  1265. endif
  1266. ! check whether the DateStr is the correct length
  1267. call DateCheck(DateStr,Status)
  1268. if(Status /= WRF_NO_ERR) then
  1269. write(msg,*) 'Warning DATE STRING ERROR in ',__FILE__,', line', __LINE__
  1270. call wrf_debug ( WARN , msg)
  1271. return
  1272. endif
  1273. ! get the dataset name and dimensional information of the data
  1274. VarName = Var
  1275. Length(1:NDim) = PatchEnd(1:NDim) - PatchStart(1:NDim) + 1
  1276. DomLength(1:NDim) = DomainEnd(1:NDim) - DomainStart(1:NDim) + 1
  1277. ! Transposing the data order and dim. string order, store to RODimNames
  1278. call ExtOrder(MemoryOrder,Length,Status)
  1279. call ExtOrder(MemoryOrder,DomLength,Status)
  1280. if(Status /= WRF_NO_ERR) then
  1281. write(msg,*) 'Warning BAD MEMORY ORDER in ',__FILE__,', line', __LINE__
  1282. call wrf_debug ( WARN , msg)
  1283. return
  1284. endif
  1285. ! Map datatype from WRF to HDF5
  1286. select case (FieldType)
  1287. case (WRF_REAL)
  1288. XType = H5T_NATIVE_REAL
  1289. case (WRF_DOUBLE)
  1290. Xtype = H5T_NATIVE_DOUBLE
  1291. case (WRF_INTEGER)
  1292. XType = H5T_NATIVE_INTEGER
  1293. case (WRF_LOGICAL)
  1294. XType = DH%EnumID
  1295. case default
  1296. Status = WRF_HDF5_ERR_DATA_TYPE_NOTFOUND
  1297. return
  1298. end select
  1299. ! HANDLE with dim. scale
  1300. ! handle dimensional scale data; search and store them in a table.
  1301. ! The table is one dimensional array of compound data type. One member of
  1302. ! the type is HDF5 string, representing the name of the dim(west_east_stag eg.)
  1303. ! Another number is the length of the dimension(west_east_stag = 31)
  1304. ! In this part, we will not store TIME but leave it at the end since the time
  1305. ! index won't be known until the end of the run; since all fields(HDF5 datasets)
  1306. ! have the same timestamp, writing it once should be fine.
  1307. ! 1) create a loop for dimensions
  1308. call GetDataTimeIndex('write',DataHandle,DateStr,TimeIndex,Status)
  1309. if(Status /= WRF_NO_ERR) then
  1310. return
  1311. endif
  1312. if(TimeIndex == 1) then
  1313. ! 2) get the dim. name, the first dim. is reserved for time,
  1314. call ExtOrderStr(MemoryOrder,DimNames,RODimNames,Status)
  1315. if(Status /= WRF_NO_ERR) then
  1316. write(msg,*) 'Warning BAD MEMORY ORDER in ',__FILE__,', line', __LINE__
  1317. call wrf_debug ( WARN , msg)
  1318. return
  1319. endif
  1320. ! 3) get the dim. length
  1321. ! 4) inside the loop, search the table for dimensional name( table module)
  1322. ! IF FOUND, go to the next dimension, return the table dimensional rank
  1323. ! (For example, find west_east_stag in the table, the rank of "west_east_stag"
  1324. ! is 3; so return 3 for the array dimrank.)
  1325. ! in the table; so through the table, we can find the information
  1326. ! such as names, length of this dimension
  1327. ! 4.1) save the rank into an array for attribute
  1328. ! if not found, go to 5)
  1329. ! 4)' the first dimension is reserved for time, so table starts from j = 2
  1330. !
  1331. ! 5) NOT FOUND, inside the loop add the new dimensional information to the
  1332. ! table(table module)
  1333. ! The first dimension of the field is always "time" and "time"
  1334. ! is also the first dimension of the "table".
  1335. k = 2
  1336. DimRank(1) = 1
  1337. do i = 1,NDim
  1338. do j = 2,MaxTabDims
  1339. ! Search for the table and see if we are at the end of the table
  1340. if (DH%DIMTABLE(j)%dim_name == NO_NAME) then
  1341. ! Sometimes the RODimNames is NULLName or ''. If that happens,
  1342. ! we will search the table from the beginning and see
  1343. ! whether the name is FAKEDIM(the default name) and the
  1344. ! current length of the dim. is the same as that of FAKEDIM;
  1345. ! if yes, use this FAKEDIM for the current field dim.
  1346. if(RODimNames(i) ==''.or. RODimNames(i)==NullName) then
  1347. do m = 2,j
  1348. if(DomLength(i)==DH%DIMTABLE(m)%Length.and. &
  1349. DH%DIMTABLE(m)%dim_name(1:7)=='FAKEDIM')then
  1350. DimRank(k) = m
  1351. k = k + 1
  1352. dim_flag = 1
  1353. exit
  1354. endif
  1355. enddo
  1356. ! No FAKEDIM and the same length dim. is found,
  1357. ! Add another dimension "FAKEDIM + j", with the length
  1358. ! as DomLength(i)
  1359. if (dim_flag == 1) then
  1360. dim_flag = 0
  1361. else
  1362. RODimNames(i) = 'FAKEDIM'//achar(j+iachar('0'))
  1363. DH%DIMTABLE(j)%dim_name = RODimNames(i)
  1364. DH%DIMTABLE(j)%length = DomLength(i)
  1365. DimRank(k) = j
  1366. k = k + 1
  1367. endif
  1368. ! no '' or NULLName is found, then assign this RODimNames
  1369. ! to the dim. table.
  1370. else
  1371. DH%DIMTABLE(j)%dim_name = RODimNames(i)
  1372. DH%DIMTABLE(j)%length = DomLength(i)
  1373. DimRank(k) = j
  1374. k = k + 1
  1375. endif
  1376. exit
  1377. ! If we found the current dim. in the table already,save the rank
  1378. else if(DH%DIMTABLE(j)%dim_name == RODimNames(i)) then
  1379. ! remember the rank of dimensional scale
  1380. DimRank(k) = j
  1381. k = k + 1
  1382. exit
  1383. else
  1384. continue
  1385. endif
  1386. enddo
  1387. enddo
  1388. endif ! end of timeindex of 1
  1389. ! 6) create an attribute array called DimRank to store the rank of the attribute.
  1390. ! This will be done in the HDF5IOWRITE routine
  1391. ! 7) before the end of the run, 1) update time, 2) write the table to HDF5.
  1392. ! get the index of l1,.......for writing HDF5 file.
  1393. StoredStart = 1
  1394. call GetIndices(NDim,MemoryStart,MemoryEnd,l1,l2,m1,m2,n1,n2)
  1395. call GetIndices(NDim,StoredStart,Length ,x1,x2,y1,y2,z1,z2)
  1396. call GetIndices(NDim,PatchStart, PatchEnd ,i1,i2,j1,j2,k1,k2)
  1397. di=1
  1398. if(FieldType == WRF_DOUBLE) di = 2
  1399. allocate(XField(di,x1:x2,y1:y2,z1:z2), STAT=stat)
  1400. if(stat/= 0) then
  1401. Status = WRF_ERR_FATAL_ALLOCATION_ERROR
  1402. write(msg,*) 'Fatal ALLOCATION ERROR in ',__FILE__,', line',__LINE__
  1403. call wrf_debug ( FATAL , msg)
  1404. return
  1405. endif
  1406. ! Transpose the real data for tools people
  1407. call Transpose_hdf5('write',MemoryOrder,di, Field,l1,l2,m1,m2,n1,n2 &
  1408. ,XField,x1,x2,y1,y2,z1,z2 &
  1409. ,i1,i2,j1,j2,k1,k2 )
  1410. ! handle with logical data separately,because of not able to
  1411. ! map Fortran Logical type to C type
  1412. if(FieldType .eq. WRF_LOGICAL) then
  1413. allocate(BUFFER(di,x1:x2,y1:y2,z1:z2), STAT=stat)
  1414. do k =z1,z2
  1415. do j = y1,y2
  1416. do i = x1,x2
  1417. do m = 1,di
  1418. if(XField(m,i,j,k)/= 0) then
  1419. BUFFER(m,i,j,k) = 1
  1420. else
  1421. BUFFER(m,i,j,k) = 0
  1422. endif
  1423. enddo
  1424. enddo
  1425. enddo
  1426. enddo
  1427. call HDF5IOWRITE(DataHandle,Comm,DateStr,Length,DomainStart, DomainEnd &
  1428. ,PatchStart,PatchEnd, MemoryOrder &
  1429. ,FieldType,XType,groupID,TimeIndex,DimRank &
  1430. ,Var,BUFFER,Status)
  1431. deallocate(BUFFER,STAT=stat)
  1432. if(stat/=0) then
  1433. Status = WRF_ERR_FATAL_ALLOCATION_ERROR
  1434. write(msg,*) 'Fatal ALLOCATION ERROR in ',__FILE__,', line',__LINE__
  1435. call wrf_debug ( FATAL , msg)
  1436. return
  1437. endif
  1438. else
  1439. call HDF5IOWRITE(DataHandle,Comm,DateStr,Length, DomainStart, DomainEnd &
  1440. ,PatchStart, PatchEnd, MemoryOrder &
  1441. ,FieldType,XType,groupID,TimeIndex,DimRank &
  1442. ,Var,XField,Status)
  1443. endif
  1444. if (Status /= WRF_NO_ERR) then
  1445. return
  1446. endif
  1447. deallocate(XField,STAT=stat)
  1448. if(stat/=0) then
  1449. Status = WRF_ERR_FATAL_ALLOCATION_ERROR
  1450. write(msg,*) 'Fatal ALLOCATION ERROR in ',__FILE__,', line',__LINE__
  1451. call wrf_debug ( FATAL , msg)
  1452. return
  1453. endif
  1454. endif
  1455. DH%first_operation = .FALSE.
  1456. return
  1457. end subroutine ext_phdf5_write_field
  1458. ! set_time routine is only used for open_for_read
  1459. subroutine ext_phdf5_set_time(DataHandle, DateStr, Status)
  1460. use wrf_phdf5_data
  1461. use ext_phdf5_support_routines
  1462. use HDF5
  1463. implicit none
  1464. include 'wrf_status_codes.h'
  1465. integer ,intent(in) :: DataHandle
  1466. character*(*) ,intent(in) :: DateStr
  1467. integer ,intent(out) :: Status
  1468. type(wrf_phdf5_data_handle) ,pointer :: DH
  1469. integer :: i
  1470. ! check whether the Date length is equal to DateStrLen defined at wrf_phdf5_data
  1471. ! sees not enough, leave it for the time being 3/12/2003
  1472. call DateCheck(DateStr,Status)
  1473. if(Status /= WRF_NO_ERR) then
  1474. write(msg,*) 'Warning DATE STRING ERROR in ',__FILE__,', line', __LINE__
  1475. call wrf_debug ( WARN , msg)
  1476. return
  1477. endif
  1478. call GetDH(DataHandle,DH,Status)
  1479. if(Status /= WRF_NO_ERR) then
  1480. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  1481. call wrf_debug ( WARN , msg)
  1482. return
  1483. endif
  1484. if(DH%FileStatus == WRF_FILE_NOT_OPENED) then
  1485. Status = WRF_HDF5_ERR_FILE_NOT_OPENED
  1486. write(msg,*) 'Warning FILE NOT OPENED in ',__FILE__,', line', __LINE__
  1487. call wrf_debug ( WARN , msg)
  1488. elseif(DH%FileStatus == WRF_FILE_OPENED_NOT_COMMITTED) then
  1489. Status = WRF_HDF5_ERR_FILE_NOT_COMMITTED
  1490. write(msg,*) 'Warning FILE NOT COMMITTED in ',__FILE__,', line', __LINE__
  1491. call wrf_debug ( WARN , msg)
  1492. elseif(DH%FileStatus == WRF_FILE_OPENED_AND_COMMITTED) then
  1493. Status = WRF_HDF5_ERR_READ_WONLY_FILE
  1494. write(msg,*) 'Warning READ WRITE ONLY FILE in ',__FILE__,', line', __LINE__
  1495. call wrf_debug ( WARN , msg)
  1496. elseif(DH%FileStatus == WRF_FILE_OPENED_FOR_READ) then
  1497. do i=1,MaxTimes
  1498. if(DH%Times(i)==DateStr) then
  1499. DH%CurrentTime = i
  1500. exit
  1501. endif
  1502. if(i==MaxTimes) then
  1503. Status = WRF_HDF5_ERR_TIME
  1504. return
  1505. endif
  1506. enddo
  1507. DH%CurrentVariable = 0
  1508. Status = WRF_NO_ERR
  1509. else
  1510. Status = WRF_HDF5_ERR_BAD_FILE_STATUS
  1511. write(msg,*) 'FATAL BAD FILE STATUS in ',__FILE__,', line', __LINE__
  1512. call wrf_debug ( FATAL , msg)
  1513. endif
  1514. return
  1515. end subroutine ext_phdf5_set_time
  1516. ! get_next_time routine is only used for open_for_read
  1517. subroutine ext_phdf5_get_next_time(DataHandle, DateStr, Status)
  1518. use wrf_phdf5_data
  1519. use ext_phdf5_support_routines
  1520. use HDF5
  1521. implicit none
  1522. include 'wrf_status_codes.h'
  1523. integer ,intent(in) :: DataHandle
  1524. character*(*) ,intent(out) :: DateStr
  1525. integer ,intent(out) :: Status
  1526. type(wrf_phdf5_data_handle) ,pointer :: DH
  1527. call GetDH(DataHandle,DH,Status)
  1528. if(Status /= WRF_NO_ERR) then
  1529. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  1530. call wrf_debug ( WARN , msg)
  1531. return
  1532. endif
  1533. if(DH%FileStatus == WRF_FILE_NOT_OPENED) then
  1534. Status = WRF_HDF5_ERR_FILE_NOT_OPENED
  1535. write(msg,*) 'Warning FILE NOT OPENED in ',__FILE__,', line', __LINE__
  1536. call wrf_debug ( WARN , msg)
  1537. elseif(DH%FileStatus == WRF_FILE_OPENED_NOT_COMMITTED) then
  1538. Status = WRF_HDF5_ERR_DRYRUN_READ
  1539. write(msg,*) 'Warning DRYRUN READ in ',__FILE__,', line', __LINE__
  1540. call wrf_debug ( WARN , msg)
  1541. elseif(DH%FileStatus == WRF_FILE_OPENED_AND_COMMITTED) then
  1542. Status = WRF_HDF5_ERR_READ_WONLY_FILE
  1543. write(msg,*) 'Warning READ WRITE ONLY FILE in ',__FILE__,', line', __LINE__
  1544. call wrf_debug ( WARN , msg)
  1545. elseif(DH%FileStatus == WRF_FILE_OPENED_FOR_READ) then
  1546. if(DH%CurrentTime >= DH%NumberTimes) then
  1547. Status = WRF_HDF5_ERR_TIME
  1548. write(msg,*) 'Warning READ WRITE ONLY FILE in ',__FILE__,', line', __LINE__
  1549. call wrf_debug ( WARN , msg)
  1550. return
  1551. endif
  1552. DH%CurrentTime = DH%CurrentTime +1
  1553. DateStr = DH%Times(DH%CurrentTime)
  1554. DH%CurrentVariable = 0
  1555. Status = WRF_NO_ERR
  1556. else
  1557. Status = WRF_HDF5_ERR_BAD_FILE_STATUS
  1558. write(msg,*) 'Fatal error BAD FILE STATUS in ',__FILE__,', line', __LINE__
  1559. call wrf_debug ( FATAL , msg)
  1560. endif
  1561. return
  1562. end subroutine ext_phdf5_get_next_time
  1563. ! get_previous_time routine
  1564. subroutine ext_phdf5_get_previous_time(DataHandle, DateStr, Status)
  1565. use wrf_phdf5_data
  1566. use ext_phdf5_support_routines
  1567. use HDF5
  1568. implicit none
  1569. include 'wrf_status_codes.h'
  1570. integer ,intent(in) :: DataHandle
  1571. character*(*) ,intent(out) :: DateStr
  1572. integer ,intent(out) :: Status
  1573. type(wrf_phdf5_data_handle) ,pointer :: DH
  1574. call GetDH(DataHandle,DH,Status)
  1575. if(Status /= WRF_NO_ERR) then
  1576. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  1577. call wrf_debug ( WARN , msg)
  1578. return
  1579. endif
  1580. if(DH%FileStatus == WRF_FILE_NOT_OPENED) then
  1581. Status = WRF_HDF5_ERR_FILE_NOT_OPENED
  1582. write(msg,*) 'Warning FILE NOT OPENED in ',__FILE__,', line', __LINE__
  1583. call wrf_debug ( WARN , msg)
  1584. elseif(DH%FileStatus == WRF_FILE_OPENED_NOT_COMMITTED) then
  1585. Status = WRF_HDF5_ERR_DRYRUN_READ
  1586. write(msg,*) 'Warning DRYRUN READ in ',__FILE__,', line', __LINE__
  1587. call wrf_debug ( WARN , msg)
  1588. elseif(DH%FileStatus == WRF_FILE_OPENED_AND_COMMITTED) then
  1589. Status = WRF_HDF5_ERR_READ_WONLY_FILE
  1590. write(msg,*) 'Warning READ WRITE ONLY FILE in ',__FILE__,', line', __LINE__
  1591. call wrf_debug ( WARN , msg)
  1592. elseif(DH%FileStatus == WRF_FILE_OPENED_FOR_READ) then
  1593. if(DH%CurrentTime.GT.0) then
  1594. DH%CurrentTime = DH%CurrentTime - 1
  1595. endif
  1596. DateStr = DH%Times(DH%CurrentTime)
  1597. DH%CurrentVariable = 0
  1598. Status = WRF_NO_ERR
  1599. else
  1600. Status = WRF_HDF5_ERR_BAD_FILE_STATUS
  1601. write(msg,*) 'Fatal error BAD FILE STATUS in ',__FILE__,', line', __LINE__
  1602. call wrf_debug ( FATAL , msg)
  1603. endif
  1604. return
  1605. end subroutine ext_phdf5_get_previous_time
  1606. subroutine ext_phdf5_get_var_info(DataHandle,Name,NDim,MemoryOrder,Stagger,DomainStart,DomainEnd,WrfType,Status)
  1607. use wrf_phdf5_data
  1608. use ext_phdf5_support_routines
  1609. use HDF5
  1610. implicit none
  1611. include 'wrf_status_codes.h'
  1612. integer ,intent(in) :: DataHandle
  1613. character*(*) ,intent(in) :: Name
  1614. integer ,intent(out) :: NDim
  1615. character*(*) ,intent(out) :: MemoryOrder
  1616. character*(*) ,intent(out) :: Stagger ! Dummy for now
  1617. integer ,dimension(*) ,intent(out) :: DomainStart, DomainEnd
  1618. integer ,intent(out) :: WrfType
  1619. integer ,intent(out) :: Status
  1620. type(wrf_phdf5_data_handle) ,pointer :: DH
  1621. integer :: VarID
  1622. integer ,dimension(NVarDims) :: VDimIDs
  1623. integer :: j
  1624. integer :: hdf5err
  1625. integer :: XType
  1626. character(Len =MaxTimeSLen) :: tname
  1627. character(Len = 512) :: tgroupname
  1628. integer(hid_t) :: tgroupid
  1629. integer(hid_t) :: dsetid
  1630. integer(hid_t) :: dspaceid
  1631. integer :: HDF5_NDim
  1632. integer(hsize_t),dimension(:),allocatable :: h5dims
  1633. integer(hsize_t),dimension(:),allocatable :: h5maxdims
  1634. call GetDH(DataHandle,DH,Status)
  1635. if(Status /= WRF_NO_ERR) then
  1636. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  1637. call wrf_debug ( WARN , TRIM(msg))
  1638. return
  1639. endif
  1640. if(DH%FileStatus == WRF_FILE_NOT_OPENED) then
  1641. Status = WRF_HDF5_ERR_FILE_NOT_OPENED
  1642. write(msg,*) 'Warning FILE NOT OPENED in ',__FILE__,', line', __LINE__
  1643. call wrf_debug ( WARN , TRIM(msg))
  1644. return
  1645. elseif(DH%FileStatus == WRF_FILE_OPENED_NOT_COMMITTED) then
  1646. Status = WRF_HDF5_ERR_DRYRUN_READ
  1647. write(msg,*) 'Warning DRYRUN READ in ',__FILE__,', line', __LINE__
  1648. call wrf_debug ( WARN , TRIM(msg))
  1649. return
  1650. elseif(DH%FileStatus == WRF_FILE_OPENED_AND_COMMITTED) then
  1651. Status = WRF_HDF5_ERR_READ_WONLY_FILE
  1652. write(msg,*) 'Warning READ WRITE ONLY FILE in ',__FILE__,', line', __LINE__
  1653. call wrf_debug ( WARN , TRIM(msg))
  1654. return
  1655. elseif(DH%FileStatus == WRF_FILE_OPENED_FOR_READ) then
  1656. if(Name /= "Times") then
  1657. call numtochar(1,tname)
  1658. tgroupname = 'TIME_STAMP_'//tname
  1659. call h5gopen_f(DH%GroupID,tgroupname,tgroupid,hdf5err)
  1660. if(hdf5err.lt.0) then
  1661. Status = WRF_HDF5_ERR_GROUP
  1662. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  1663. call wrf_debug ( WARN , msg)
  1664. return
  1665. endif
  1666. call h5dopen_f(tgroupid,Name,dsetid,hdf5err)
  1667. if(hdf5err /= 0) then
  1668. STATUS = WRF_HDF5_ERR_DATASET_OPEN
  1669. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  1670. call wrf_debug ( WARN , msg)
  1671. return
  1672. endif
  1673. call h5dget_space_f(dsetid,dspaceid,hdf5err)
  1674. if(hdf5err.lt.0) then
  1675. Status = WRF_HDF5_ERR_DATASPACE
  1676. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  1677. call wrf_debug ( WARN , msg)
  1678. return
  1679. endif
  1680. call h5sget_simple_extent_ndims_f(dspaceid,HDF5_NDim,hdf5err)
  1681. if(hdf5err.lt.0) then
  1682. Status = WRF_HDF5_ERR_DATASPACE
  1683. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  1684. call wrf_debug ( WARN , msg)
  1685. return
  1686. endif
  1687. call ext_phdf5_get_var_ti_char(DataHandle,"MemoryOrder",Name,MemoryOrder,Status)
  1688. if(Status /= WRF_NO_ERR) then
  1689. Status = WRF_HDF5_ERR_ATTRIBUTE_GENERAL
  1690. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  1691. call wrf_debug ( WARN , msg)
  1692. return
  1693. endif
  1694. ! get the rank of the dimension
  1695. call GetDim(MemoryOrder,NDim,Status)
  1696. if(Status /= WRF_NO_ERR) then
  1697. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  1698. call wrf_debug ( WARN , msg)
  1699. return
  1700. endif
  1701. if((NDim+1)/= HDF5_NDim)then
  1702. Status = WRF_HDF5_ERR_DATASPACE
  1703. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  1704. call wrf_debug ( WARN , msg)
  1705. return
  1706. endif
  1707. call ext_phdf5_get_var_ti_char(DataHandle,"Stagger",Name,Stagger,Status)
  1708. if(Status /= WRF_NO_ERR) then
  1709. Status = WRF_HDF5_ERR_ATTRIBUTE_GENERAL
  1710. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  1711. call wrf_debug ( WARN , msg)
  1712. return
  1713. endif
  1714. call ext_phdf5_get_var_ti_integer(DataHandle,"FieldType",Name,WrfType,Status)
  1715. if(Status /= WRF_NO_ERR) then
  1716. Status = WRF_HDF5_ERR_ATTRIBUTE_GENERAL
  1717. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  1718. call wrf_debug ( WARN , msg)
  1719. return
  1720. endif
  1721. ! obtain Domain Start and Domain End.
  1722. allocate(h5dims(NDim+1))
  1723. allocate(h5maxdims(NDim+1))
  1724. call h5sget_simple_extent_dims_f(dspaceid,h5dims,h5maxdims,hdf5err)
  1725. if(hdf5err .lt. 0) then
  1726. Status = WRF_HDF5_ERR_DATASPACE
  1727. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  1728. call wrf_debug ( WARN , msg)
  1729. return
  1730. endif
  1731. do j =1, NDim
  1732. DomainStart(j) = 1
  1733. DomainEnd(j) = h5dims(j)
  1734. enddo
  1735. deallocate(h5dims)
  1736. deallocate(h5maxdims)
  1737. endif
  1738. return
  1739. endif
  1740. return
  1741. end subroutine ext_phdf5_get_var_info
  1742. ! obtain the domain time independent attribute with REAL type
  1743. subroutine ext_phdf5_get_dom_ti_real(DataHandle,Element,Data,Count,OutCount,Status)
  1744. use wrf_phdf5_data
  1745. use ext_phdf5_support_routines
  1746. USE HDF5 ! This module contains all necessary modules
  1747. use get_attrid_routine
  1748. implicit none
  1749. include 'wrf_status_codes.h'
  1750. integer ,intent(in) :: DataHandle
  1751. character*(*) ,intent(in) :: Element
  1752. real ,intent(out) :: Data(*)
  1753. real ,dimension(:),allocatable :: buffer
  1754. integer ,intent(in) :: Count
  1755. integer ,intent(out) :: OutCount
  1756. integer ,intent(out) :: Status
  1757. integer(hid_t) :: h5_atypeid
  1758. integer(hid_t) :: h5_aspaceid
  1759. integer(hid_t) :: h5_attrid
  1760. integer :: rank
  1761. integer(hid_t) :: attr_type
  1762. integer(hsize_t), dimension(7) :: h5_dims
  1763. integer :: hdf5err
  1764. ! Do nothing unless it is time to read time-independent domain metadata.
  1765. IF ( .NOT. phdf5_ok_to_get_dom_ti( DataHandle ) ) THEN
  1766. Status = WRF_NO_ERR
  1767. return
  1768. ENDIF
  1769. attr_type = H5T_NATIVE_REAL
  1770. call get_attrid(DataHandle,Element,h5_attrid,Status)
  1771. if(Status /= WRF_NO_ERR) then
  1772. return
  1773. endif
  1774. call check_type(DataHandle,attr_type,h5_attrid,Status)
  1775. if (Status /= WRF_NO_ERR) then
  1776. return
  1777. endif
  1778. call retrieve_ti_info(DataHandle,h5_attrid,h5_atypeid,&
  1779. Count,OutCount,Status)
  1780. if (Status /= WRF_NO_ERR) then
  1781. return
  1782. endif
  1783. allocate(buffer(OutCount))
  1784. h5_dims(1) = OutCount
  1785. call h5aread_f(h5_attrid,attr_type,buffer,h5_dims,hdf5err)
  1786. if(hdf5err.lt.0) then
  1787. Status = WRF_HDF5_ERR_ATTRIBUTE_READ
  1788. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  1789. call wrf_debug ( WARN , msg)
  1790. deallocate(buffer)
  1791. return
  1792. endif
  1793. data(1:OutCount) = buffer(1:OutCount)
  1794. deallocate(buffer)
  1795. return
  1796. end subroutine ext_phdf5_get_dom_ti_real
  1797. ! obtain the domain time independent attribute with REAL8 type
  1798. subroutine ext_phdf5_get_dom_ti_double(DataHandle,Element,Data,Count,OutCount,Status)
  1799. use wrf_phdf5_data
  1800. use ext_phdf5_support_routines
  1801. USE HDF5 ! This module contains all necessary modules
  1802. use get_attrid_routine
  1803. implicit none
  1804. include 'wrf_status_codes.h'
  1805. integer ,intent(in) :: DataHandle
  1806. character*(*) ,intent(in) :: Element
  1807. real*8 ,intent(out) :: Data(*)
  1808. integer ,intent(in) :: Count
  1809. integer ,intent(out) :: OutCount
  1810. integer ,intent(out) :: Status
  1811. integer(hid_t) :: h5_atypeid
  1812. integer(hid_t) :: h5_aspaceid
  1813. integer(hid_t) :: h5_attrid
  1814. integer :: rank
  1815. integer :: hdf5err
  1816. integer(hid_t) :: attr_type
  1817. integer(hsize_t), dimension(7) :: h5_dims
  1818. ! Do nothing unless it is time to read time-independent domain metadata.
  1819. IF ( .NOT. phdf5_ok_to_get_dom_ti( DataHandle ) ) THEN
  1820. Status = WRF_NO_ERR
  1821. return
  1822. ENDIF
  1823. attr_type = H5T_NATIVE_DOUBLE
  1824. call get_attrid(DataHandle,Element,h5_attrid,Status)
  1825. if(Status /= WRF_NO_ERR) then
  1826. return
  1827. endif
  1828. call check_type(DataHandle,attr_type,h5_attrid,Status)
  1829. if (Status /= WRF_NO_ERR) then
  1830. return
  1831. endif
  1832. call retrieve_ti_info(DataHandle,h5_attrid,h5_atypeid,&
  1833. Count,OutCount,Status)
  1834. if (Status /= WRF_NO_ERR) then
  1835. return
  1836. endif
  1837. h5_dims(1) = OutCount
  1838. call h5aread_f(h5_attrid,attr_type,data,h5_dims,hdf5err)
  1839. if(hdf5err.lt.0) then
  1840. Status = WRF_HDF5_ERR_ATTRIBUTE_READ
  1841. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  1842. call wrf_debug ( WARN , msg)
  1843. return
  1844. endif
  1845. return
  1846. end subroutine ext_phdf5_get_dom_ti_double
  1847. ! obtain the domain time independent attribute with integer type
  1848. subroutine ext_phdf5_get_dom_ti_integer(DataHandle,Element,Data,Count,OutCount,Status)
  1849. use wrf_phdf5_data
  1850. use ext_phdf5_support_routines
  1851. USE HDF5 ! This module contains all necessary modules
  1852. use get_attrid_routine
  1853. implicit none
  1854. include 'wrf_status_codes.h'
  1855. integer ,intent(in) :: DataHandle
  1856. character*(*) ,intent(in) :: Element
  1857. integer ,intent(out) :: Data(*)
  1858. integer ,intent(in) :: Count
  1859. integer ,intent(out) :: OutCount
  1860. integer ,intent(out) :: Status
  1861. integer(hid_t) :: h5_atypeid
  1862. integer(hid_t) :: h5_aspaceid
  1863. integer(hid_t) :: h5_attrid
  1864. integer :: rank
  1865. integer(hid_t) :: attr_type
  1866. integer(hsize_t), dimension(7) :: h5_dims
  1867. integer :: hdf5err
  1868. ! Do nothing unless it is time to read time-independent domain metadata.
  1869. IF ( .NOT. phdf5_ok_to_get_dom_ti( DataHandle ) ) THEN
  1870. Status = WRF_NO_ERR
  1871. return
  1872. ENDIF
  1873. attr_type = H5T_NATIVE_INTEGER
  1874. call get_attrid(DataHandle,Element,h5_attrid,Status)
  1875. if(Status /= WRF_NO_ERR) then
  1876. return
  1877. endif
  1878. call check_type(DataHandle,attr_type,h5_attrid,Status)
  1879. if (Status /= WRF_NO_ERR) then
  1880. return
  1881. endif
  1882. call retrieve_ti_info(DataHandle,h5_attrid,h5_atypeid,&
  1883. Count,OutCount,Status)
  1884. if (Status /= WRF_NO_ERR) then
  1885. return
  1886. endif
  1887. h5_dims(1) = OutCount
  1888. call h5aread_f(h5_attrid,attr_type,Data,h5_dims,Status)
  1889. if(hdf5err.lt.0) then
  1890. Status = WRF_HDF5_ERR_ATTRIBUTE_READ
  1891. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  1892. call wrf_debug ( WARN , msg)
  1893. return
  1894. endif
  1895. return
  1896. end subroutine ext_phdf5_get_dom_ti_integer
  1897. subroutine ext_phdf5_get_dom_ti_logical(DataHandle,Element,Data,Count,OutCount,Status)
  1898. use wrf_phdf5_data
  1899. use ext_phdf5_support_routines
  1900. USE HDF5 ! This module contains all necessary modules
  1901. use get_attrid_routine
  1902. implicit none
  1903. include 'wrf_status_codes.h'
  1904. integer ,intent(in) :: DataHandle
  1905. character*(*) ,intent(in) :: Element
  1906. logical ,intent(out) :: Data(*)
  1907. integer, dimension(:),allocatable :: buffer
  1908. integer ,intent(in) :: Count
  1909. integer ,intent(out) :: OutCount
  1910. integer ,intent(out) :: Status
  1911. integer(hid_t) :: h5_atypeid
  1912. integer(hid_t) :: h5_aspaceid
  1913. integer(hid_t) :: h5_attrid
  1914. integer :: rank
  1915. integer(hid_t) :: attr_type
  1916. type(wrf_phdf5_data_handle),pointer :: DH
  1917. integer(hsize_t), dimension(7) :: h5_dims
  1918. integer :: hdf5err
  1919. call GetDH(DataHandle,DH,Status)
  1920. if(Status /= WRF_NO_ERR) then
  1921. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  1922. call wrf_debug ( WARN , msg)
  1923. return
  1924. endif
  1925. ! Do nothing unless it is time to read time-independent domain metadata.
  1926. IF ( .NOT. phdf5_ok_to_get_dom_ti( DataHandle ) ) THEN
  1927. Status = WRF_NO_ERR
  1928. return
  1929. ENDIF
  1930. attr_type = DH%EnumID
  1931. call get_attrid(DataHandle,Element,h5_attrid,Status)
  1932. if(Status /= WRF_NO_ERR) then
  1933. return
  1934. endif
  1935. call check_type(DataHandle,attr_type,h5_attrid,Status)
  1936. if (status /= WRF_NO_ERR) then
  1937. return
  1938. endif
  1939. call retrieve_ti_info(DataHandle,h5_attrid,h5_atypeid,&
  1940. Count,OutCount,Status)
  1941. if (Status /= WRF_NO_ERR) then
  1942. return
  1943. endif
  1944. h5_dims(1) = OutCount
  1945. allocate(buffer(OutCount))
  1946. call h5aread_f(h5_attrid,attr_type,buffer,h5_dims,hdf5err)
  1947. if(hdf5err.lt.0) then
  1948. Status = WRF_HDF5_ERR_ATTRIBUTE_READ
  1949. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  1950. call wrf_debug ( WARN , msg)
  1951. deallocate(buffer)
  1952. return
  1953. endif
  1954. Data(1:OutCount) = buffer(1:OutCount)==1
  1955. deallocate(buffer)
  1956. return
  1957. end subroutine ext_phdf5_get_dom_ti_logical
  1958. ! obtain the domain time independent attribute with char type
  1959. subroutine ext_phdf5_get_dom_ti_char(DataHandle,Element,Data,Status)
  1960. use wrf_phdf5_data
  1961. use ext_phdf5_support_routines
  1962. USE HDF5 ! This module contains all necessary modules
  1963. use get_attrid_routine
  1964. implicit none
  1965. include 'wrf_status_codes.h'
  1966. integer ,intent(in) :: DataHandle
  1967. character*(*) ,intent(in) :: Element
  1968. character*(*) ,intent(out) :: Data
  1969. integer :: Count
  1970. integer :: OutCount
  1971. integer ,intent(out) :: Status
  1972. integer(hid_t) :: h5_atypeid
  1973. integer(hid_t) :: h5_aspaceid
  1974. integer(hid_t) :: h5_attrid
  1975. integer :: rank
  1976. integer(hid_t) :: attr_type
  1977. integer(hsize_t), dimension(7) :: h5_dims
  1978. integer :: hdf5err
  1979. ! Do nothing unless it is time to read time-independent domain metadata.
  1980. IF ( .NOT. phdf5_ok_to_get_dom_ti( DataHandle ) ) THEN
  1981. Status = WRF_NO_ERR
  1982. return
  1983. ENDIF
  1984. attr_type = H5T_NATIVE_CHARACTER
  1985. call get_attrid(DataHandle,Element,h5_attrid,Status)
  1986. if(Status /= WRF_NO_ERR) then
  1987. return
  1988. endif
  1989. call check_type(DataHandle,attr_type,h5_attrid,Status)
  1990. if (status /= WRF_NO_ERR) then
  1991. return
  1992. endif
  1993. call retrieve_ti_info(DataHandle,h5_attrid,h5_atypeid,&
  1994. Count,OutCount,Status)
  1995. if(Status /= WRF_NO_ERR) then
  1996. return
  1997. endif
  1998. h5_dims(1) = OutCount
  1999. call h5aread_f(h5_attrid,h5_atypeid,data,h5_dims,hdf5err)
  2000. if(hdf5err.lt.0) then
  2001. Status = WRF_HDF5_ERR_ATTRIBUTE_READ
  2002. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  2003. call wrf_debug ( WARN , msg)
  2004. return
  2005. endif
  2006. return
  2007. end subroutine ext_phdf5_get_dom_ti_char
  2008. subroutine ext_phdf5_put_dom_td_real(DataHandle,Element,DateStr,Data,Count,Status)
  2009. integer ,intent(in) :: DataHandle
  2010. character*(*) ,intent(in) :: Element
  2011. character*(*) ,intent(in) :: DateStr
  2012. real ,intent(in) :: Data(*)
  2013. integer ,intent(in) :: Count
  2014. integer ,intent(out) :: Status
  2015. call ext_phdf5_put_var_td_real(DataHandle,Element,DateStr,&
  2016. 'E_X_T_D_O_M_A_I_N_M_E_T_A_DATA_',&
  2017. Data,Count,Status)
  2018. return
  2019. end subroutine ext_phdf5_put_dom_td_real
  2020. subroutine ext_phdf5_put_dom_td_double(DataHandle,Element,DateStr,Data,Count,Status)
  2021. integer ,intent(in) :: DataHandle
  2022. character*(*) ,intent(in) :: Element
  2023. character*(*) ,intent(in) :: DateStr
  2024. real*8 ,intent(in) :: Data(*)
  2025. integer ,intent(in) :: Count
  2026. integer ,intent(out) :: Status
  2027. call ext_phdf5_put_var_td_double(DataHandle,Element,DateStr,&
  2028. 'E_X_T_D_O_M_A_I_N_M_E_T_A_DATA_',&
  2029. Data,Count,Status)
  2030. return
  2031. end subroutine ext_phdf5_put_dom_td_double
  2032. subroutine ext_phdf5_put_dom_td_logical(DataHandle,Element,DateStr,Data,Count,Status)
  2033. integer ,intent(in) :: DataHandle
  2034. character*(*) ,intent(in) :: Element
  2035. character*(*) ,intent(in) :: DateStr
  2036. logical ,intent(in) :: Data(*)
  2037. integer ,intent(in) :: Count
  2038. integer ,intent(out) :: Status
  2039. call ext_phdf5_put_var_td_logical(DataHandle,Element,DateStr,&
  2040. 'E_X_T_D_O_M_A_I_N_M_E_T_A_DATA_',&
  2041. Data,Count,Status)
  2042. return
  2043. end subroutine ext_phdf5_put_dom_td_logical
  2044. subroutine ext_phdf5_put_dom_td_integer(DataHandle,Element,DateStr,Data,Count,Status)
  2045. integer ,intent(in) :: DataHandle
  2046. character*(*) ,intent(in) :: Element
  2047. character*(*) ,intent(in) :: DateStr
  2048. integer ,intent(in) :: Data(*)
  2049. integer ,intent(in) :: Count
  2050. integer ,intent(out) :: Status
  2051. call ext_phdf5_put_var_td_integer(DataHandle,Element,DateStr,&
  2052. 'E_X_T_D_O_M_A_I_N_M_E_T_A_DATA_',&
  2053. Data,Count,Status)
  2054. return
  2055. end subroutine ext_phdf5_put_dom_td_integer
  2056. subroutine ext_phdf5_put_dom_td_char(DataHandle,Element,DateStr,Data,Status)
  2057. integer ,intent(in) :: DataHandle
  2058. character*(*) ,intent(in) :: Element
  2059. character*(*) ,intent(in) :: DateStr
  2060. character*(*) ,intent(in) :: Data
  2061. integer ,intent(out) :: Status
  2062. call ext_phdf5_put_var_td_char(DataHandle,Element,DateStr,&
  2063. 'E_X_T_D_O_M_A_I_N_M_E_T_A_DATA_',&
  2064. Data,Status)
  2065. return
  2066. end subroutine ext_phdf5_put_dom_td_char
  2067. subroutine ext_phdf5_get_dom_td_real(DataHandle,Element,DateStr,Data,Count,OutCount,Status)
  2068. integer ,intent(in) :: DataHandle
  2069. character*(*) ,intent(in) :: Element
  2070. character*(*) ,intent(in) :: DateStr
  2071. real ,intent(out) :: Data(*)
  2072. integer ,intent(in) :: Count
  2073. integer ,intent(out) :: OutCount
  2074. integer ,intent(out) :: Status
  2075. call ext_phdf5_get_var_td_real(DataHandle,Element,DateStr,&
  2076. 'E_X_T_D_O_M_A_I_N_M_E_T_A_DATA_',Data,Count,OutCount,Status)
  2077. return
  2078. end subroutine ext_phdf5_get_dom_td_real
  2079. subroutine ext_phdf5_get_dom_td_double(DataHandle,Element,DateStr,Data,Count,OutCount,Status)
  2080. integer ,intent(in) :: DataHandle
  2081. character*(*) ,intent(in) :: Element
  2082. character*(*) ,intent(in) :: DateStr
  2083. real*8 ,intent(out) :: Data(*)
  2084. integer ,intent(in) :: Count
  2085. integer ,intent(out) :: OutCount
  2086. integer ,intent(out) :: Status
  2087. call ext_phdf5_get_var_td_double(DataHandle,Element,DateStr,&
  2088. 'E_X_T_D_O_M_A_I_N_M_E_T_A_DATA_',Data,Count,OutCount,Status)
  2089. return
  2090. end subroutine ext_phdf5_get_dom_td_double
  2091. subroutine ext_phdf5_get_dom_td_integer(DataHandle,Element,DateStr,Data,Count,OutCount,Status)
  2092. integer ,intent(in) :: DataHandle
  2093. character*(*) ,intent(in) :: Element
  2094. character*(*) ,intent(in) :: DateStr
  2095. integer ,intent(out) :: Data(*)
  2096. integer ,intent(in) :: Count
  2097. integer ,intent(out) :: OutCount
  2098. integer ,intent(out) :: Status
  2099. call ext_phdf5_get_var_td_integer(DataHandle,Element,DateStr,&
  2100. 'E_X_T_D_O_M_A_I_N_M_E_T_A_DATA_',Data,Count,OutCount,Status)
  2101. return
  2102. end subroutine ext_phdf5_get_dom_td_integer
  2103. subroutine ext_phdf5_get_dom_td_logical(DataHandle,Element,DateStr,Data,Count,OutCount,Status)
  2104. integer ,intent(in) :: DataHandle
  2105. character*(*) ,intent(in) :: Element
  2106. character*(*) ,intent(in) :: DateStr
  2107. logical ,intent(out) :: Data(*)
  2108. integer ,intent(in) :: Count
  2109. integer ,intent(out) :: OutCount
  2110. integer ,intent(out) :: Status
  2111. call ext_phdf5_get_var_td_logical(DataHandle,Element,DateStr,&
  2112. 'E_X_T_D_O_M_A_I_N_M_E_T_A_DATA_',Data,Count,OutCount,Status)
  2113. return
  2114. end subroutine ext_phdf5_get_dom_td_logical
  2115. subroutine ext_phdf5_get_dom_td_char(DataHandle,Element,DateStr,Data,Status)
  2116. integer ,intent(in) :: DataHandle
  2117. character*(*) ,intent(in) :: Element
  2118. character*(*) ,intent(in) :: DateStr
  2119. character*(*) ,intent(out) :: Data
  2120. integer ,intent(out) :: Status
  2121. call ext_phdf5_get_var_td_char(DataHandle,Element,DateStr,&
  2122. 'E_X_T_D_O_M_A_I_N_M_E_T_A_DATA_',Data,Status)
  2123. return
  2124. end subroutine ext_phdf5_get_dom_td_char
  2125. subroutine ext_phdf5_put_var_td_real(DataHandle,Element,DateStr,Var,Data,Count,Status)
  2126. use wrf_phdf5_data
  2127. use ext_phdf5_support_routines
  2128. USE HDF5 ! This module contains all necessary modules
  2129. implicit none
  2130. include 'wrf_status_codes.h'
  2131. integer ,intent(in) :: DataHandle
  2132. character*(*) ,intent(in) :: Element
  2133. character*(*) ,intent(in) :: DateStr
  2134. character*(*) ,intent(in) :: Var
  2135. character(len = 256) :: DataSetName
  2136. real ,intent(in) :: Data(*)
  2137. integer ,intent(in) :: Count
  2138. integer ,intent(out) :: Status
  2139. type(wrf_phdf5_data_handle),pointer :: DH
  2140. integer :: TimeIndex
  2141. integer(hid_t) :: dset_id
  2142. integer(hid_t) :: dspaceid
  2143. integer(hid_t) :: fspaceid
  2144. integer(hid_t) :: tgroupid
  2145. integer(hsize_t),dimension(1) :: dims
  2146. integer :: hdf5err
  2147. integer :: i
  2148. call GetDH(DataHandle,DH,Status)
  2149. if(Status /= WRF_NO_ERR) then
  2150. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  2151. call wrf_debug ( WARN , msg)
  2152. return
  2153. endif
  2154. ! check whether the DateStr is the correct length
  2155. call DateCheck(DateStr,Status)
  2156. if(Status /= WRF_NO_ERR) then
  2157. write(msg,*) 'Warning DATE STRING ERROR in ',__FILE__,', line', __LINE__
  2158. call wrf_debug ( WARN , msg)
  2159. return
  2160. endif
  2161. if(DH%FileStatus == WRF_FILE_OPENED_AND_COMMITTED) then
  2162. dims(1) = Count
  2163. ! Get the time index
  2164. call GetAttrTimeIndex('write',DataHandle,DateStr,TimeIndex,Status)
  2165. if(Status /= WRF_NO_ERR) then
  2166. return
  2167. endif
  2168. ! Set up dataspace,property list
  2169. call GetName(Element,Var,DataSetName,Status)
  2170. if(Status /= WRF_NO_ERR) then
  2171. return
  2172. endif
  2173. call setup_wrtd_dataset(DataHandle,DataSetName,H5T_NATIVE_REAL,Count,&
  2174. dset_id,dspaceid,fspaceid,tgroupid,TimeIndex,Status)
  2175. if(Status /= WRF_NO_ERR) then
  2176. return
  2177. endif
  2178. call h5dwrite_f(dset_id,H5T_NATIVE_REAL,Data,dims,hdf5err,dspaceid,&
  2179. fspaceid)
  2180. if(hdf5err.lt.0) then
  2181. Status = WRF_HDF5_ERR_DATASET_WRITE
  2182. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  2183. call wrf_debug ( WARN , msg)
  2184. return
  2185. endif
  2186. call h5dclose_f(dset_id,hdf5err)
  2187. call h5sclose_f(dspaceid,hdf5err)
  2188. call h5sclose_f(fspaceid,hdf5err)
  2189. ! call h5gclose_f(tgroupid,hdf5err)
  2190. endif
  2191. return
  2192. end subroutine ext_phdf5_put_var_td_real
  2193. subroutine ext_phdf5_put_var_td_double(DataHandle,Element,DateStr,Var,Data,Count,Status)
  2194. use wrf_phdf5_data
  2195. use ext_phdf5_support_routines
  2196. USE HDF5 ! This module contains all necessary modules
  2197. implicit none
  2198. include 'wrf_status_codes.h'
  2199. integer ,intent(in) :: DataHandle
  2200. character*(*) ,intent(in) :: Element
  2201. character*(*) ,intent(in) :: DateStr
  2202. character*(*) ,intent(in) :: Var
  2203. character(len = 256) :: DataSetName
  2204. real*8 ,intent(in) :: Data(*)
  2205. integer ,intent(in) :: Count
  2206. integer ,intent(out) :: Status
  2207. type(wrf_phdf5_data_handle),pointer :: DH
  2208. integer :: TimeIndex
  2209. integer(hid_t) :: dset_id
  2210. integer(hid_t) :: dspaceid
  2211. integer(hid_t) :: fspaceid
  2212. integer(hid_t) :: tgroupid
  2213. integer(hsize_t),dimension(1) :: dims
  2214. integer :: hdf5err
  2215. integer :: i
  2216. call GetDH(DataHandle,DH,Status)
  2217. if(Status /= WRF_NO_ERR) then
  2218. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  2219. call wrf_debug ( WARN , msg)
  2220. return
  2221. endif
  2222. ! check whether the DateStr is the correct length
  2223. call DateCheck(DateStr,Status)
  2224. if(Status /= WRF_NO_ERR) then
  2225. write(msg,*) 'Warning DATE STRING ERROR in ',__FILE__,', line', __LINE__
  2226. call wrf_debug ( WARN , msg)
  2227. return
  2228. endif
  2229. if(DH%FileStatus == WRF_FILE_OPENED_AND_COMMITTED) then
  2230. dims(1) = Count
  2231. ! Get the time index
  2232. call GetAttrTimeIndex('write',DataHandle,DateStr,TimeIndex,Status)
  2233. if(Status /= WRF_NO_ERR) then
  2234. return
  2235. endif
  2236. ! Set up dataspace,property list
  2237. call GetName(Element,Var,DataSetName,Status)
  2238. call setup_wrtd_dataset(DataHandle,DataSetName,H5T_NATIVE_DOUBLE,Count,&
  2239. dset_id,dspaceid,fspaceid,tgroupid,TimeIndex,Status)
  2240. if(Status /= WRF_NO_ERR) then
  2241. return
  2242. endif
  2243. call h5dwrite_f(dset_id,H5T_NATIVE_DOUBLE,Data,dims,hdf5err,dspaceid,&
  2244. fspaceid)
  2245. if(hdf5err.lt.0) then
  2246. Status = WRF_HDF5_ERR_DATASET_WRITE
  2247. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  2248. call wrf_debug ( WARN , msg)
  2249. return
  2250. endif
  2251. call h5dclose_f(dset_id,hdf5err)
  2252. call h5sclose_f(dspaceid,hdf5err)
  2253. call h5sclose_f(fspaceid,hdf5err)
  2254. ! call h5gclose_f(tgroupid,hdf5err)
  2255. endif
  2256. return
  2257. end subroutine ext_phdf5_put_var_td_double
  2258. subroutine ext_phdf5_put_var_td_integer(DataHandle,Element,DateStr,Var,Data,Count,Status)
  2259. use wrf_phdf5_data
  2260. use ext_phdf5_support_routines
  2261. USE HDF5 ! This module contains all necessary modules
  2262. implicit none
  2263. include 'wrf_status_codes.h'
  2264. integer ,intent(in) :: DataHandle
  2265. character*(*) ,intent(in) :: Element
  2266. character*(*) ,intent(in) :: DateStr
  2267. character*(*) ,intent(in) :: Var
  2268. character(len = 256) :: DataSetName
  2269. integer ,intent(in) :: Data(*)
  2270. integer ,intent(in) :: Count
  2271. integer ,intent(out) :: Status
  2272. type(wrf_phdf5_data_handle),pointer :: DH
  2273. integer :: TimeIndex
  2274. integer(hid_t) :: dset_id
  2275. integer(hid_t) :: dspaceid
  2276. integer(hid_t) :: fspaceid
  2277. integer(hid_t) :: tgroupid
  2278. integer(hsize_t),dimension(1) :: dims
  2279. integer :: hdf5err
  2280. integer :: i
  2281. call GetDH(DataHandle,DH,Status)
  2282. if(Status /= WRF_NO_ERR) then
  2283. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  2284. call wrf_debug ( WARN , msg)
  2285. return
  2286. endif
  2287. ! check whether the DateStr is the correct length
  2288. call DateCheck(DateStr,Status)
  2289. if(Status /= WRF_NO_ERR) then
  2290. write(msg,*) 'Warning DATE STRING ERROR in ',__FILE__,', line', __LINE__
  2291. call wrf_debug ( WARN , msg)
  2292. return
  2293. endif
  2294. if(DH%FileStatus == WRF_FILE_OPENED_AND_COMMITTED) then
  2295. dims(1) = Count
  2296. ! Get the time index
  2297. call GetAttrTimeIndex('write',DataHandle,DateStr,TimeIndex,Status)
  2298. if(Status /= WRF_NO_ERR) then
  2299. return
  2300. endif
  2301. ! Set up dataspace,property list
  2302. call GetName(Element,Var,DataSetName,Status)
  2303. call setup_wrtd_dataset(DataHandle,DataSetName,H5T_NATIVE_INTEGER, &
  2304. Count,dset_id,dspaceid,fspaceid,tgroupid, &
  2305. TimeIndex, Status)
  2306. if(Status /= WRF_NO_ERR) then
  2307. return
  2308. endif
  2309. call h5dwrite_f(dset_id,H5T_NATIVE_INTEGER,Data,dims,hdf5err,dspaceid,&
  2310. fspaceid)
  2311. if(hdf5err.lt.0) then
  2312. Status = WRF_HDF5_ERR_DATASET_WRITE
  2313. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  2314. call wrf_debug ( WARN , msg)
  2315. return
  2316. endif
  2317. call h5dclose_f(dset_id,hdf5err)
  2318. call h5sclose_f(dspaceid,hdf5err)
  2319. call h5sclose_f(fspaceid,hdf5err)
  2320. ! call h5gclose_f(tgroupid,hdf5err)
  2321. endif
  2322. return
  2323. end subroutine ext_phdf5_put_var_td_integer
  2324. subroutine ext_phdf5_put_var_td_logical(DataHandle,Element,DateStr,Var,Data,Count,Status)
  2325. use wrf_phdf5_data
  2326. use ext_phdf5_support_routines
  2327. USE HDF5 ! This module contains all necessary modules
  2328. implicit none
  2329. include 'wrf_status_codes.h'
  2330. integer ,intent(in) :: DataHandle
  2331. character*(*) ,intent(in) :: Element
  2332. character*(*) ,intent(in) :: DateStr
  2333. character*(*) ,intent(in) :: Var
  2334. character(len = 256) :: DataSetName
  2335. logical ,intent(in) :: Data(*)
  2336. integer ,dimension(:),allocatable :: Buffer
  2337. integer ,intent(in) :: Count
  2338. integer ,intent(out) :: Status
  2339. type(wrf_phdf5_data_handle),pointer :: DH
  2340. integer :: TimeIndex
  2341. integer(hid_t) :: dset_id
  2342. integer(hid_t) :: dspaceid
  2343. integer(hid_t) :: fspaceid
  2344. integer(hid_t) :: tgroupid
  2345. integer(hsize_t),dimension(1) :: dims
  2346. integer :: hdf5err
  2347. integer :: i
  2348. call GetDH(DataHandle,DH,Status)
  2349. if(Status /= WRF_NO_ERR) then
  2350. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  2351. call wrf_debug ( WARN , msg)
  2352. return
  2353. endif
  2354. ! check whether the DateStr is the correct length
  2355. call DateCheck(DateStr,Status)
  2356. if(Status /= WRF_NO_ERR) then
  2357. write(msg,*) 'Warning DATE STRING ERROR in ',__FILE__,', line', __LINE__
  2358. call wrf_debug ( WARN , msg)
  2359. return
  2360. endif
  2361. if(DH%FileStatus == WRF_FILE_OPENED_AND_COMMITTED) then
  2362. allocate(buffer(count))
  2363. do i = 1, count
  2364. if(data(i).EQV..TRUE.) then
  2365. buffer(i) = 1
  2366. else
  2367. buffer(i) = 0
  2368. endif
  2369. enddo
  2370. dims(1) = Count
  2371. ! Get the time index
  2372. call GetAttrTimeIndex('write',DataHandle,DateStr,TimeIndex,Status)
  2373. if(Status /= WRF_NO_ERR) then
  2374. return
  2375. endif
  2376. ! Set up dataspace,property list
  2377. call GetName(Element,Var,DataSetName,Status)
  2378. call setup_wrtd_dataset(DataHandle,DataSetName,DH%EnumID, &
  2379. Count,dset_id,dspaceid, &
  2380. fspaceid,tgroupid,TimeIndex,Status)
  2381. if(Status /= WRF_NO_ERR) then
  2382. return
  2383. endif
  2384. call h5dwrite_f(dset_id,DH%EnumID,Buffer,dims,hdf5err,dspaceid,&
  2385. fspaceid)
  2386. if(hdf5err.lt.0) then
  2387. Status = WRF_HDF5_ERR_DATASET_WRITE
  2388. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  2389. call wrf_debug ( WARN , msg)
  2390. return
  2391. endif
  2392. call h5dclose_f(dset_id,hdf5err)
  2393. call h5sclose_f(dspaceid,hdf5err)
  2394. call h5sclose_f(fspaceid,hdf5err)
  2395. ! call h5gclose_f(tgroupid,hdf5err)
  2396. deallocate(Buffer)
  2397. endif
  2398. return
  2399. end subroutine ext_phdf5_put_var_td_logical
  2400. subroutine ext_phdf5_put_var_td_char(DataHandle,Element,DateStr,Var,Data,Status)
  2401. use wrf_phdf5_data
  2402. use ext_phdf5_support_routines
  2403. USE HDF5 ! This module contains all necessary modules
  2404. implicit none
  2405. include 'wrf_status_codes.h'
  2406. integer ,intent(in) :: DataHandle
  2407. character*(*) ,intent(in) :: Element
  2408. character*(*) ,intent(in) :: DateStr
  2409. character*(*) ,intent(in) :: Var
  2410. character(len = 256) :: DataSetName
  2411. character*(*) ,intent(in) :: Data
  2412. integer ,intent(out) :: Status
  2413. type(wrf_phdf5_data_handle),pointer :: DH
  2414. integer :: TimeIndex
  2415. integer(hid_t) :: dset_id
  2416. integer(hid_t) :: dspaceid
  2417. integer(hid_t) :: fspaceid
  2418. integer(hid_t) :: tgroupid
  2419. integer(hsize_t),dimension(1) :: dims
  2420. integer :: hdf5err
  2421. integer :: i
  2422. integer :: str_id
  2423. integer :: str_len
  2424. integer :: count
  2425. call GetDH(DataHandle,DH,Status)
  2426. if(Status /= WRF_NO_ERR) then
  2427. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  2428. call wrf_debug ( WARN , msg)
  2429. return
  2430. endif
  2431. ! check whether the DateStr is the correct length
  2432. call DateCheck(DateStr,Status)
  2433. if(Status /= WRF_NO_ERR) then
  2434. write(msg,*) 'Warning DATE STRING ERROR in ',__FILE__,', line', __LINE__
  2435. call wrf_debug ( WARN , msg)
  2436. return
  2437. endif
  2438. if(DH%FileStatus == WRF_FILE_OPENED_AND_COMMITTED) then
  2439. dims(1) = 1
  2440. ! Get the time index
  2441. call GetAttrTimeIndex('write',DataHandle,DateStr,TimeIndex,Status)
  2442. if(Status /= WRF_NO_ERR) then
  2443. return
  2444. endif
  2445. ! make str id
  2446. str_len = len_trim(Data)
  2447. call make_strid(str_len,str_id,Status)
  2448. if(Status /= WRF_NO_ERR) then
  2449. return
  2450. endif
  2451. ! assign count of the string to 1
  2452. count = 1
  2453. ! Set up dataspace,property list
  2454. call GetName(Element,Var,DataSetName,Status)
  2455. if(Status /= WRF_NO_ERR) then
  2456. return
  2457. endif
  2458. call setup_wrtd_dataset(DataHandle,DataSetName,str_id, &
  2459. count,dset_id,dspaceid, &
  2460. fspaceid,tgroupid,TimeIndex,Status)
  2461. if(Status /= WRF_NO_ERR) then
  2462. return
  2463. endif
  2464. call h5dwrite_f(dset_id,str_id,Data,dims,hdf5err,dspaceid,&
  2465. fspaceid)
  2466. if(hdf5err.lt.0) then
  2467. Status = WRF_HDF5_ERR_DATASET_WRITE
  2468. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  2469. call wrf_debug ( WARN , msg)
  2470. return
  2471. endif
  2472. ! close the string id
  2473. call h5tclose_f(str_id,hdf5err)
  2474. if(hdf5err.lt.0) then
  2475. Status = WRF_HDF5_ERR_DATATYPE
  2476. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  2477. call wrf_debug ( WARN , msg)
  2478. return
  2479. endif
  2480. call h5dclose_f(dset_id,hdf5err)
  2481. call h5sclose_f(dspaceid,hdf5err)
  2482. call h5sclose_f(fspaceid,hdf5err)
  2483. ! call h5gclose_f(tgroupid,hdf5err)
  2484. endif
  2485. return
  2486. end subroutine ext_phdf5_put_var_td_char
  2487. subroutine ext_phdf5_get_var_td_real(DataHandle,Element,DateStr,Var,Data,Count,OutCount,Status)
  2488. use wrf_phdf5_data
  2489. use ext_phdf5_support_routines
  2490. USE HDF5 ! This module contains all necessary modules
  2491. implicit none
  2492. include 'wrf_status_codes.h'
  2493. integer ,intent(in) :: DataHandle
  2494. character*(*) ,intent(in) :: Element
  2495. character*(*) ,intent(in) :: DateStr
  2496. character*(*) ,intent(in) :: Var
  2497. character(len =256) :: DataSetName
  2498. real ,intent(out) :: Data(*)
  2499. integer ,intent(in) :: Count
  2500. integer ,intent(out) :: OutCount
  2501. integer ,intent(out) :: Status
  2502. type(wrf_phdf5_data_handle),pointer :: DH
  2503. integer :: TimeIndex
  2504. integer(hid_t) :: dset_id
  2505. integer(hid_t) :: dspaceid
  2506. integer(hid_t) :: memspaceid
  2507. integer(hid_t) :: tgroupid
  2508. integer(hsize_t),dimension(7) :: data_dims
  2509. integer :: hdf5err
  2510. call GetDH(DataHandle,DH,Status)
  2511. if(Status /= WRF_NO_ERR) then
  2512. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  2513. call wrf_debug ( WARN , msg)
  2514. return
  2515. endif
  2516. ! check whether the DateStr is the correct length
  2517. call DateCheck(DateStr,Status)
  2518. if(Status /= WRF_NO_ERR) then
  2519. write(msg,*) 'Warning DATE STRING ERROR in ',__FILE__,', line', __LINE__
  2520. call wrf_debug ( WARN , msg)
  2521. return
  2522. endif
  2523. if(DH%FileStatus == WRF_FILE_OPENED_FOR_READ) then
  2524. ! get the time-dependent attribute name
  2525. call GetName(Element,Var,DataSetName,Status)
  2526. ! get time index of the time-dependent attribute
  2527. call GetAttrTimeIndex('read',DataHandle,DateStr,TimeIndex,Status)
  2528. if(Status /= WRF_NO_ERR) then
  2529. return
  2530. endif
  2531. ! For parallel, find the group and obtain the attribute.
  2532. ! set up for reading the time-dependent attribute
  2533. call setup_rdtd_dataset(DataHandle,DataSetName,H5T_NATIVE_REAL,TimeIndex,&
  2534. Count,OutCount,dset_id,memspaceid,dspaceid,tgroupid,&
  2535. Status)
  2536. if(Status /= WRF_NO_ERR) then
  2537. return
  2538. endif
  2539. data_dims(1) = OutCount
  2540. ! read the dataset
  2541. call h5dread_f(dset_id,H5T_NATIVE_REAL,data,data_dims,hdf5err, &
  2542. memspaceid,dspaceid,H5P_DEFAULT_F)
  2543. if(hdf5err.lt.0) then
  2544. Status = WRF_HDF5_ERR_DATASET_READ
  2545. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  2546. call wrf_debug ( WARN , msg)
  2547. return
  2548. endif
  2549. call h5sclose_f(memspaceid,hdf5err)
  2550. call h5sclose_f(dspaceid,hdf5err)
  2551. call h5dclose_f(dset_id,hdf5err)
  2552. call h5gclose_f(tgroupid,hdf5err)
  2553. endif
  2554. end subroutine ext_phdf5_get_var_td_real
  2555. subroutine ext_phdf5_get_var_td_double(DataHandle,Element,DateStr,Var,Data,&
  2556. Count,OutCount,Status)
  2557. use wrf_phdf5_data
  2558. use ext_phdf5_support_routines
  2559. USE HDF5 ! This module contains all necessary modules
  2560. implicit none
  2561. include 'wrf_status_codes.h'
  2562. integer ,intent(in) :: DataHandle
  2563. character*(*) ,intent(in) :: Element
  2564. character*(*) ,intent(in) :: DateStr
  2565. character*(*) ,intent(in) :: Var
  2566. character(len =256) :: DataSetName
  2567. real*8 ,intent(out) :: Data(*)
  2568. integer ,intent(in) :: Count
  2569. integer ,intent(out) :: OutCount
  2570. integer ,intent(out) :: Status
  2571. type(wrf_phdf5_data_handle),pointer :: DH
  2572. integer :: TimeIndex
  2573. integer(hid_t) :: dset_id
  2574. integer(hid_t) :: dspaceid
  2575. integer(hid_t) :: memspaceid
  2576. integer(hid_t) :: tgroupid
  2577. integer(hsize_t),dimension(7) :: data_dims
  2578. integer :: hdf5err
  2579. call GetDH(DataHandle,DH,Status)
  2580. if(Status /= WRF_NO_ERR) then
  2581. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  2582. call wrf_debug ( WARN , msg)
  2583. return
  2584. endif
  2585. ! check whether the DateStr is the correct length
  2586. call DateCheck(DateStr,Status)
  2587. if(Status /= WRF_NO_ERR) then
  2588. write(msg,*) 'Warning DATE STRING ERROR in ',__FILE__,', line', __LINE__
  2589. call wrf_debug ( WARN , msg)
  2590. return
  2591. endif
  2592. if(DH%FileStatus == WRF_FILE_OPENED_FOR_READ) then
  2593. ! get the time-dependent attribute name
  2594. call GetName(Element,Var,DataSetName,Status)
  2595. ! get time index of the time-dependent attribute
  2596. call GetAttrTimeIndex('read',DataHandle,DateStr,TimeIndex,Status)
  2597. if(Status /= WRF_NO_ERR) then
  2598. return
  2599. endif
  2600. ! set up for reading the time-dependent attribute
  2601. call setup_rdtd_dataset(DataHandle,DataSetName,H5T_NATIVE_DOUBLE,TimeIndex,&
  2602. Count,OutCount,dset_id,memspaceid,dspaceid,tgroupid,&
  2603. Status)
  2604. if(Status /= WRF_NO_ERR) then
  2605. return
  2606. endif
  2607. data_dims(1) = OutCount
  2608. ! read the dataset
  2609. call h5dread_f(dset_id,H5T_NATIVE_DOUBLE,data,data_dims,hdf5err, &
  2610. memspaceid,dspaceid,H5P_DEFAULT_F)
  2611. if(hdf5err.lt.0) then
  2612. Status = WRF_HDF5_ERR_DATASET_READ
  2613. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  2614. call wrf_debug ( WARN , msg)
  2615. return
  2616. endif
  2617. call h5sclose_f(memspaceid,hdf5err)
  2618. call h5sclose_f(dspaceid,hdf5err)
  2619. call h5dclose_f(dset_id,hdf5err)
  2620. call h5gclose_f(tgroupid,hdf5err)
  2621. endif
  2622. end subroutine ext_phdf5_get_var_td_double
  2623. subroutine ext_phdf5_get_var_td_integer(DataHandle,Element,DateStr,Var,Data,&
  2624. Count,OutCount,Status)
  2625. use wrf_phdf5_data
  2626. use ext_phdf5_support_routines
  2627. USE HDF5 ! This module contains all necessary modules
  2628. implicit none
  2629. include 'wrf_status_codes.h'
  2630. integer ,intent(in) :: DataHandle
  2631. character*(*) ,intent(in) :: Element
  2632. character*(*) ,intent(in) :: DateStr
  2633. character*(*) ,intent(in) :: Var
  2634. character(len =256) :: DataSetName
  2635. integer ,intent(out) :: Data(*)
  2636. integer ,intent(in) :: Count
  2637. INTEGER ,intent(out) :: OutCount
  2638. integer ,intent(out) :: Status
  2639. type(wrf_phdf5_data_handle),pointer :: DH
  2640. integer :: TimeIndex
  2641. integer(hid_t) :: dset_id
  2642. integer(hid_t) :: dspaceid
  2643. integer(hid_t) :: memspaceid
  2644. integer(hid_t) :: tgroupid
  2645. integer(hsize_t),dimension(7) :: data_dims
  2646. integer :: hdf5err
  2647. call GetDH(DataHandle,DH,Status)
  2648. if(Status /= WRF_NO_ERR) then
  2649. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  2650. call wrf_debug ( WARN , msg)
  2651. return
  2652. endif
  2653. ! check whether the DateStr is the correct length
  2654. call DateCheck(DateStr,Status)
  2655. if(Status /= WRF_NO_ERR) then
  2656. write(msg,*) 'Warning DATE STRING ERROR in ',__FILE__,', line', __LINE__
  2657. call wrf_debug ( WARN , msg)
  2658. return
  2659. endif
  2660. if(DH%FileStatus == WRF_FILE_OPENED_FOR_READ) then
  2661. ! get the time-dependent attribute name
  2662. call GetName(Element,Var,DataSetName,Status)
  2663. ! get time index of the time-dependent attribute
  2664. call GetAttrTimeIndex('read',DataHandle,DateStr,TimeIndex,Status)
  2665. if(Status /= WRF_NO_ERR) then
  2666. return
  2667. endif
  2668. ! set up for reading the time-dependent attribute
  2669. call setup_rdtd_dataset(DataHandle,DataSetName,H5T_NATIVE_INTEGER,TimeIndex,&
  2670. Count,OutCount,dset_id,memspaceid,dspaceid,tgroupid,&
  2671. Status)
  2672. if(Status /= WRF_NO_ERR) then
  2673. return
  2674. endif
  2675. data_dims(1) = OutCount
  2676. ! read the dataset
  2677. call h5dread_f(dset_id,H5T_NATIVE_INTEGER,data,data_dims,hdf5err, &
  2678. memspaceid,dspaceid,H5P_DEFAULT_F)
  2679. if(hdf5err.lt.0) then
  2680. Status = WRF_HDF5_ERR_DATASET_READ
  2681. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  2682. call wrf_debug ( WARN , msg)
  2683. return
  2684. endif
  2685. call h5sclose_f(memspaceid,hdf5err)
  2686. call h5sclose_f(dspaceid,hdf5err)
  2687. call h5dclose_f(dset_id,hdf5err)
  2688. call h5gclose_f(tgroupid,hdf5err)
  2689. endif
  2690. end subroutine ext_phdf5_get_var_td_integer
  2691. subroutine ext_phdf5_get_var_td_logical(DataHandle,Element,DateStr,Var,Data,&
  2692. Count,OutCount,Status)
  2693. use wrf_phdf5_data
  2694. use ext_phdf5_support_routines
  2695. USE HDF5 ! This module contains all necessary modules
  2696. implicit none
  2697. include 'wrf_status_codes.h'
  2698. integer ,intent(in) :: DataHandle
  2699. character*(*) ,intent(in) :: Element
  2700. character*(*) ,intent(in) :: DateStr
  2701. character*(*) ,intent(in) :: Var
  2702. character(len =256) :: DataSetName
  2703. logical ,intent(out) :: Data(*)
  2704. integer, dimension(:),allocatable :: Buffer
  2705. integer ,intent(in) :: Count
  2706. integer ,intent(out) :: OutCount
  2707. integer ,intent(out) :: Status
  2708. type(wrf_phdf5_data_handle),pointer :: DH
  2709. integer :: TimeIndex
  2710. integer(hid_t) :: dset_id
  2711. integer(hid_t) :: dspaceid
  2712. integer(hid_t) :: memspaceid
  2713. integer(hid_t) :: tgroupid
  2714. integer(hsize_t),dimension(7) :: data_dims
  2715. integer :: hdf5err
  2716. call GetDH(DataHandle,DH,Status)
  2717. if(Status /= WRF_NO_ERR) then
  2718. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  2719. call wrf_debug ( WARN , msg)
  2720. return
  2721. endif
  2722. ! check whether the DateStr is the correct length
  2723. call DateCheck(DateStr,Status)
  2724. if(Status /= WRF_NO_ERR) then
  2725. write(msg,*) 'Warning DATE STRING ERROR in ',__FILE__,', line', __LINE__
  2726. call wrf_debug ( WARN , msg)
  2727. return
  2728. endif
  2729. if(DH%FileStatus == WRF_FILE_OPENED_FOR_READ) then
  2730. ! get the time-dependent attribute name
  2731. call GetName(Element,Var,DataSetName,Status)
  2732. ! get time index of the time-dependent attribute
  2733. call GetAttrTimeIndex('read',DataHandle,DateStr,TimeIndex,Status)
  2734. if(Status /= WRF_NO_ERR) then
  2735. return
  2736. endif
  2737. ! set up for reading the time-dependent attribute
  2738. call setup_rdtd_dataset(DataHandle,DataSetName,DH%EnumID,TimeIndex,&
  2739. Count,OutCount,dset_id,memspaceid,dspaceid,&
  2740. tgroupid,Status)
  2741. if(Status /= WRF_NO_ERR) then
  2742. return
  2743. endif
  2744. data_dims(1) = OutCount
  2745. ! read the dataset
  2746. allocate(Buffer(OutCount))
  2747. call h5dread_f(dset_id,DH%EnumID,buffer,data_dims,hdf5err, &
  2748. memspaceid,dspaceid,H5P_DEFAULT_F)
  2749. if(hdf5err.lt.0) then
  2750. Status = WRF_HDF5_ERR_DATASET_READ
  2751. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  2752. call wrf_debug ( WARN , msg)
  2753. return
  2754. endif
  2755. data(1:OutCount) = buffer(1:OutCount) == 1
  2756. deallocate(buffer)
  2757. call h5sclose_f(memspaceid,hdf5err)
  2758. call h5sclose_f(dspaceid,hdf5err)
  2759. call h5dclose_f(dset_id,hdf5err)
  2760. call h5gclose_f(tgroupid,hdf5err)
  2761. endif
  2762. end subroutine ext_phdf5_get_var_td_logical
  2763. subroutine ext_phdf5_get_var_td_char(DataHandle,Element,DateStr,Var,Data,Status)
  2764. use wrf_phdf5_data
  2765. use ext_phdf5_support_routines
  2766. USE HDF5 ! This module contains all necessary modules
  2767. implicit none
  2768. include 'wrf_status_codes.h'
  2769. integer ,intent(in) :: DataHandle
  2770. character*(*) ,intent(in) :: Element
  2771. character*(*) ,intent(in) :: DateStr
  2772. character*(*) ,intent(in) :: Var
  2773. character(len =256) :: DataSetName
  2774. character*(*) ,intent(out) :: Data
  2775. integer :: Count
  2776. integer :: OutCount
  2777. integer ,intent(out) :: Status
  2778. type(wrf_phdf5_data_handle),pointer :: DH
  2779. integer :: TimeIndex
  2780. integer(hid_t) :: dset_id
  2781. integer(hid_t) :: dspaceid
  2782. integer(hid_t) :: memspaceid
  2783. integer(hid_t) :: tgroupid
  2784. integer(hsize_t),dimension(7) :: data_dims
  2785. integer :: hdf5err
  2786. integer(hid_t) :: str_id
  2787. call GetDH(DataHandle,DH,Status)
  2788. if(Status /= WRF_NO_ERR) then
  2789. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  2790. call wrf_debug ( WARN , msg)
  2791. return
  2792. endif
  2793. ! check whether the DateStr is the correct length
  2794. call DateCheck(DateStr,Status)
  2795. if(Status /= WRF_NO_ERR) then
  2796. write(msg,*) 'Warning DATE STRING ERROR in ',__FILE__,', line', __LINE__
  2797. call wrf_debug ( WARN , msg)
  2798. return
  2799. endif
  2800. if(DH%FileStatus == WRF_FILE_OPENED_FOR_READ) then
  2801. ! get the time-dependent attribute name
  2802. call GetName(Element,Var,DataSetName,Status)
  2803. ! get time index of the time-dependent attribute
  2804. call GetAttrTimeIndex('read',DataHandle,DateStr,TimeIndex,Status)
  2805. if(Status /= WRF_NO_ERR) then
  2806. return
  2807. endif
  2808. ! set up for reading the time-dependent attribute
  2809. str_id = H5T_NATIVE_CHARACTER
  2810. Count = 1
  2811. call setup_rdtd_dataset(DataHandle,DataSetName,str_id,TimeIndex,&
  2812. Count,OutCount,dset_id,memspaceid,dspaceid,&
  2813. tgroupid,Status)
  2814. if(Status /= WRF_NO_ERR) then
  2815. return
  2816. endif
  2817. data_dims(1) = Count
  2818. ! read the dataset
  2819. call h5dread_f(dset_id,str_id,data,data_dims,hdf5err, &
  2820. memspaceid,dspaceid,H5P_DEFAULT_F)
  2821. if(hdf5err.lt.0) then
  2822. Status = WRF_HDF5_ERR_DATASET_READ
  2823. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  2824. call wrf_debug ( WARN , msg)
  2825. return
  2826. endif
  2827. call h5sclose_f(memspaceid,hdf5err)
  2828. call h5sclose_f(dspaceid,hdf5err)
  2829. call h5dclose_f(dset_id,hdf5err)
  2830. call h5gclose_f(tgroupid,hdf5err)
  2831. endif
  2832. end subroutine ext_phdf5_get_var_td_char
  2833. ! obtain the variable time independent attribute with REAL type
  2834. subroutine ext_phdf5_get_var_ti_real(DataHandle,Element,Var,Data,Count,OutCount,Status)
  2835. use wrf_phdf5_data
  2836. use ext_phdf5_support_routines
  2837. USE HDF5 ! This module contains all necessary modules
  2838. use get_attrid_routine
  2839. implicit none
  2840. include 'wrf_status_codes.h'
  2841. integer ,intent(in) :: DataHandle
  2842. character*(*) ,intent(in) :: Element
  2843. character*(*) ,intent(in) :: Var
  2844. real ,intent(out) :: Data(*)
  2845. integer ,intent(in) :: Count
  2846. integer ,intent(out) :: OutCount
  2847. integer ,intent(out) :: Status
  2848. integer(hid_t) :: h5_atypeid
  2849. integer(hid_t) :: h5_aspaceid
  2850. integer(hid_t) :: h5_attrid
  2851. integer(hid_t) :: attr_type
  2852. integer(hsize_t), dimension(7) :: h5_dims
  2853. integer :: hdf5err
  2854. attr_type = H5T_NATIVE_REAL
  2855. call get_attrid(DataHandle,Element,h5_attrid,Status,Var)
  2856. if(Status /= WRF_NO_ERR) then
  2857. return
  2858. endif
  2859. call check_type(DataHandle,attr_type,h5_attrid,Status)
  2860. if (status /= WRF_NO_ERR) then
  2861. return
  2862. endif
  2863. call retrieve_ti_info(DataHandle,h5_attrid,h5_atypeid,&
  2864. Count,OutCount,Status)
  2865. if(Status /= WRF_NO_ERR) then
  2866. return
  2867. endif
  2868. h5_dims(1) = OutCount
  2869. call h5aread_f(h5_attrid,attr_type,data,h5_dims,hdf5err)
  2870. if(hdf5err.lt.0) then
  2871. Status = WRF_HDF5_ERR_ATTRIBUTE_READ
  2872. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  2873. call wrf_debug ( WARN , msg)
  2874. return
  2875. endif
  2876. return
  2877. end subroutine ext_phdf5_get_var_ti_real
  2878. ! obtain the variable time independent attribute with REAL8 type
  2879. subroutine ext_phdf5_get_var_ti_double(DataHandle,Element,Var,Data,Count,OutCount,Status)
  2880. use wrf_phdf5_data
  2881. use ext_phdf5_support_routines
  2882. USE HDF5 ! This module contains all necessary modules
  2883. use get_attrid_routine
  2884. implicit none
  2885. include 'wrf_status_codes.h'
  2886. integer ,intent(in) :: DataHandle
  2887. character*(*) ,intent(in) :: Element
  2888. character*(*) ,intent(in) :: Var
  2889. real*8 ,intent(out) :: Data(*)
  2890. integer ,intent(in) :: Count
  2891. integer ,intent(out) :: OutCount
  2892. integer ,intent(out) :: Status
  2893. integer(hid_t) :: h5_atypeid
  2894. integer(hid_t) :: h5_aspaceid
  2895. integer(hid_t) :: h5_attrid
  2896. integer(hid_t) :: attr_type
  2897. integer(hsize_t), dimension(7) :: h5_dims
  2898. integer :: hdf5err
  2899. attr_type = H5T_NATIVE_DOUBLE
  2900. call get_attrid(DataHandle,Element,h5_attrid,Status,Var)
  2901. if(Status /= WRF_NO_ERR) then
  2902. return
  2903. endif
  2904. call check_type(DataHandle,attr_type,h5_attrid,Status)
  2905. if (status /= WRF_NO_ERR) then
  2906. return
  2907. endif
  2908. call retrieve_ti_info(DataHandle,h5_attrid,h5_atypeid,&
  2909. Count,OutCount,Status)
  2910. if(Status /= WRF_NO_ERR) then
  2911. return
  2912. endif
  2913. h5_dims(1) = OutCount
  2914. call h5aread_f(h5_attrid,attr_type,data,h5_dims,hdf5err)
  2915. if(hdf5err.lt.0) then
  2916. Status = WRF_HDF5_ERR_ATTRIBUTE_READ
  2917. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  2918. call wrf_debug ( WARN , msg)
  2919. return
  2920. endif
  2921. end subroutine ext_phdf5_get_var_ti_double
  2922. ! obtain the variable time independent attribute with integer type
  2923. subroutine ext_phdf5_get_var_ti_integer(DataHandle,Element,Var,Data,Count,OutCount,Status)
  2924. use wrf_phdf5_data
  2925. use ext_phdf5_support_routines
  2926. USE HDF5 ! This module contains all necessary modules
  2927. use get_attrid_routine
  2928. implicit none
  2929. include 'wrf_status_codes.h'
  2930. integer ,intent(in) :: DataHandle
  2931. character*(*) ,intent(in) :: Element
  2932. character*(*) ,intent(in) :: Var
  2933. integer ,intent(out) :: Data(*)
  2934. integer ,intent(in) :: Count
  2935. integer ,intent(out) :: OutCount
  2936. integer ,intent(out) :: Status
  2937. integer(hid_t) :: h5_atypeid
  2938. integer(hid_t) :: h5_aspaceid
  2939. integer(hid_t) :: h5_attrid
  2940. integer(hid_t) :: attr_type
  2941. integer(hsize_t), dimension(7) :: h5_dims
  2942. integer :: hdf5err
  2943. attr_type = H5T_NATIVE_INTEGER
  2944. call get_attrid(DataHandle,Element,h5_attrid,Status,Var)
  2945. if (status /= WRF_NO_ERR) then
  2946. return
  2947. endif
  2948. call check_type(DataHandle,attr_type,h5_attrid,Status)
  2949. if (status /= WRF_NO_ERR) then
  2950. return
  2951. endif
  2952. call retrieve_ti_info(DataHandle,h5_attrid,h5_atypeid,&
  2953. Count,OutCount,Status)
  2954. if (status /= WRF_NO_ERR) then
  2955. return
  2956. endif
  2957. h5_dims(1) = OutCount
  2958. call h5aread_f(h5_attrid,attr_type,data,h5_dims,hdf5err)
  2959. if(hdf5err.lt.0) then
  2960. Status = WRF_HDF5_ERR_ATTRIBUTE_READ
  2961. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  2962. call wrf_debug ( WARN , msg)
  2963. return
  2964. endif
  2965. return
  2966. end subroutine ext_phdf5_get_var_ti_integer
  2967. ! obtain the variable time independent attribute with logical type
  2968. subroutine ext_phdf5_get_var_ti_logical(DataHandle,Element,Var,Data,Count,OutCount,Status)
  2969. use wrf_phdf5_data
  2970. use ext_phdf5_support_routines
  2971. USE HDF5 ! This module contains all necessary modules
  2972. use get_attrid_routine
  2973. implicit none
  2974. include 'wrf_status_codes.h'
  2975. integer ,intent(in) :: DataHandle
  2976. character*(*) ,intent(in) :: Element
  2977. character*(*) ,intent(in) :: Var
  2978. logical ,intent(out) :: Data(*)
  2979. integer, dimension(:),allocatable :: Buffer
  2980. integer ,intent(in) :: Count
  2981. integer ,intent(out) :: OutCount
  2982. integer ,intent(out) :: Status
  2983. integer(hid_t) :: h5_atypeid
  2984. integer(hid_t) :: h5_aspaceid
  2985. integer(hid_t) :: h5_attrid
  2986. integer(hid_t) :: attr_type
  2987. type(wrf_phdf5_data_handle),pointer :: DH
  2988. integer(hsize_t), dimension(7) :: h5_dims
  2989. integer :: hdf5err
  2990. call GetDH(DataHandle,DH,Status)
  2991. if(Status /= WRF_NO_ERR) then
  2992. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  2993. call wrf_debug ( WARN , msg)
  2994. return
  2995. endif
  2996. attr_type = DH%EnumID
  2997. call get_attrid(DataHandle,Element,h5_attrid,Status,Var)
  2998. if(Status /= WRF_NO_ERR) then
  2999. return
  3000. endif
  3001. call check_type(DataHandle,attr_type,h5_attrid,Status)
  3002. if (status /= WRF_NO_ERR) then
  3003. return
  3004. endif
  3005. call retrieve_ti_info(DataHandle,h5_attrid,h5_atypeid,&
  3006. Count,OutCount,Status)
  3007. if (status /= WRF_NO_ERR) then
  3008. return
  3009. endif
  3010. h5_dims(1) = OutCount
  3011. allocate(buffer(OutCount))
  3012. call h5aread_f(h5_attrid,attr_type,buffer,h5_dims,hdf5err)
  3013. if(hdf5err.lt.0) then
  3014. Status = WRF_HDF5_ERR_ATTRIBUTE_READ
  3015. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  3016. call wrf_debug ( WARN , msg)
  3017. deallocate(buffer)
  3018. return
  3019. endif
  3020. Data(1:OutCount) = buffer(1:OutCount)==1
  3021. deallocate(buffer)
  3022. return
  3023. end subroutine ext_phdf5_get_var_ti_logical
  3024. ! obtain the domain variable independent attribute with Char type
  3025. subroutine ext_phdf5_get_var_ti_char(DataHandle,Element,Var,Data,Status)
  3026. use wrf_phdf5_data
  3027. use ext_phdf5_support_routines
  3028. USE HDF5 ! This module contains all necessary modules
  3029. use get_attrid_routine
  3030. implicit none
  3031. include 'wrf_status_codes.h'
  3032. integer ,intent(in) :: DataHandle
  3033. character*(*) ,intent(in) :: Element
  3034. character*(*) ,intent(in) :: Var
  3035. character*(*) ,intent(out) :: Data
  3036. integer ,intent(out) :: Status
  3037. integer(hid_t) :: h5_atypeid
  3038. integer(hid_t) :: h5_aspaceid
  3039. integer(hid_t) :: h5_attrid
  3040. integer(hid_t) :: attr_type
  3041. integer(hsize_t), dimension(7) :: h5_dims
  3042. integer :: Count
  3043. integer :: OutCount
  3044. integer :: hdf5err
  3045. attr_type = H5T_NATIVE_CHARACTER
  3046. call get_attrid(DataHandle,Element,h5_attrid,Status,Var)
  3047. if (status /= WRF_NO_ERR) then
  3048. return
  3049. endif
  3050. call check_type(DataHandle,attr_type,h5_attrid,Status)
  3051. if (status /= WRF_NO_ERR) then
  3052. return
  3053. endif
  3054. call retrieve_ti_info(DataHandle,h5_attrid,h5_atypeid,&
  3055. Count,OutCount,Status)
  3056. if (status /= WRF_NO_ERR) then
  3057. return
  3058. endif
  3059. if(OutCount /= 1) then
  3060. Status = WRF_HDF5_ERR_ATTRIBUTE_OTHERS
  3061. endif
  3062. h5_dims(1) = OutCount
  3063. call h5aread_f(h5_attrid,h5_atypeid,data,h5_dims,hdf5err)
  3064. if(hdf5err.lt.0) then
  3065. Status = WRF_HDF5_ERR_ATTRIBUTE_READ
  3066. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  3067. call wrf_debug ( WARN , msg)
  3068. return
  3069. endif
  3070. return
  3071. end subroutine ext_phdf5_get_var_ti_char
  3072. ! write the domain time independent attribute with real type
  3073. subroutine ext_phdf5_put_dom_ti_real(DataHandle,Element,Data,Count,Status)
  3074. use wrf_phdf5_data
  3075. use ext_phdf5_support_routines
  3076. USE HDF5 ! This module contains all necessary modules
  3077. implicit none
  3078. include 'wrf_status_codes.h'
  3079. integer ,intent(in) :: DataHandle
  3080. character*(*) ,intent(in) :: Element
  3081. real ,intent(in) :: Data(*)
  3082. integer ,intent(in) :: Count
  3083. integer ,intent(out) :: Status
  3084. integer(hid_t) :: h5_objid
  3085. integer(hid_t) :: h5_atypeid
  3086. integer(hid_t) :: h5_aspaceid
  3087. integer(hid_t) :: h5_attrid
  3088. integer(hsize_t), dimension(7) :: adata_dims
  3089. character*3 :: routine_type
  3090. integer :: routine_atype
  3091. integer :: str_flag = 0 ! not a string type
  3092. integer(hid_t) :: hdf5err
  3093. character(VarNameLen) :: var
  3094. ! Do nothing unless it is time to write time-independent domain metadata.
  3095. IF ( .NOT. phdf5_ok_to_put_dom_ti( DataHandle ) ) THEN
  3096. Status = WRF_NO_ERR
  3097. return
  3098. ENDIF
  3099. var = 'DUMMY'
  3100. routine_type = 'DOM'
  3101. routine_atype = WRF_REAL
  3102. adata_dims(1) = Count
  3103. call create_phdf5_objid(DataHandle,h5_objid,routine_type,var,Status)
  3104. if(Status /= WRF_NO_ERR) then
  3105. return
  3106. endif
  3107. call create_phdf5_adtypeid(h5_atypeid,routine_atype,Count,Status)
  3108. if(Status /= WRF_NO_ERR) then
  3109. return
  3110. endif
  3111. call create_phdf5_adspaceid(Count,str_flag,h5_aspaceid,Status)
  3112. if(Status /= WRF_NO_ERR) then
  3113. return
  3114. endif
  3115. call h5acreate_f(h5_objid,Element,h5_atypeid,h5_aspaceid, &
  3116. h5_attrid, hdf5err)
  3117. if(hdf5err.lt.0) then
  3118. Status = WRF_HDF5_ERR_ATTRIBUTE_CREATE
  3119. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  3120. call wrf_debug ( WARN , msg)
  3121. return
  3122. endif
  3123. call h5awrite_f(h5_attrid,h5_atypeid,Data,adata_dims,hdf5err)
  3124. if(hdf5err.lt.0) then
  3125. Status = WRF_HDF5_ERR_ATTRIBUTE_WRITE
  3126. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  3127. call wrf_debug ( WARN , msg)
  3128. return
  3129. endif
  3130. call clean_phdf5_attrids(h5_atypeid,h5_aspaceid,h5_attrid,str_flag,Status)
  3131. if(Status /= WRF_NO_ERR) then
  3132. return
  3133. endif
  3134. return
  3135. end subroutine ext_phdf5_put_dom_ti_real
  3136. ! write the domain time independent attribute with integer type
  3137. subroutine ext_phdf5_put_dom_ti_integer(DataHandle,Element,Data,Count,Status)
  3138. use wrf_phdf5_data
  3139. use ext_phdf5_support_routines
  3140. USE HDF5 ! This module contains all necessary modules
  3141. implicit none
  3142. include 'wrf_status_codes.h'
  3143. integer ,intent(in) :: DataHandle
  3144. character*(*) ,intent(in) :: Element
  3145. integer ,intent(in) :: Data(*)
  3146. integer ,intent(in) :: Count
  3147. integer ,intent(out) :: Status
  3148. integer(hid_t) :: h5_objid
  3149. integer(hid_t) :: h5_atypeid
  3150. integer(hid_t) :: h5_aspaceid
  3151. integer(hid_t) :: h5_attrid
  3152. integer(hsize_t), dimension(7) :: adata_dims
  3153. character*3 :: routine_type
  3154. integer :: routine_atype
  3155. integer :: str_flag = 0 ! not a string type
  3156. integer(hid_t) :: hdf5err
  3157. character(VarNameLen) :: var
  3158. ! Do nothing unless it is time to write time-independent domain metadata.
  3159. IF ( .NOT. phdf5_ok_to_put_dom_ti( DataHandle ) ) THEN
  3160. Status = WRF_NO_ERR
  3161. return
  3162. ENDIF
  3163. var = 'DUMMY'
  3164. routine_type = 'DOM'
  3165. routine_atype = WRF_INTEGER
  3166. adata_dims(1) = Count
  3167. call create_phdf5_objid(DataHandle,h5_objid,routine_type,var,Status)
  3168. if(Status /= WRF_NO_ERR) then
  3169. return
  3170. endif
  3171. call create_phdf5_adtypeid(h5_atypeid,routine_atype,Count,Status)
  3172. if(Status /= WRF_NO_ERR) then
  3173. return
  3174. endif
  3175. call create_phdf5_adspaceid(Count,str_flag,h5_aspaceid,Status)
  3176. if(Status /= WRF_NO_ERR) then
  3177. return
  3178. endif
  3179. call h5acreate_f(h5_objid,Element,h5_atypeid,h5_aspaceid, &
  3180. h5_attrid, hdf5err)
  3181. if(hdf5err.lt.0) then
  3182. Status = WRF_HDF5_ERR_ATTRIBUTE_CREATE
  3183. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  3184. call wrf_debug ( WARN , msg)
  3185. return
  3186. endif
  3187. call h5awrite_f(h5_attrid,h5_atypeid,Data,adata_dims,hdf5err)
  3188. if(hdf5err.lt.0) then
  3189. Status = WRF_HDF5_ERR_ATTRIBUTE_WRITE
  3190. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  3191. call wrf_debug ( WARN , msg)
  3192. return
  3193. endif
  3194. call clean_phdf5_attrids(h5_atypeid,h5_aspaceid,h5_attrid,str_flag,Status)
  3195. if(Status /= WRF_NO_ERR) then
  3196. return
  3197. endif
  3198. return
  3199. end subroutine ext_phdf5_put_dom_ti_integer
  3200. ! write the domain time independent attribute with double type
  3201. subroutine ext_phdf5_put_dom_ti_double(DataHandle,Element,Data,Count,Status)
  3202. use wrf_phdf5_data
  3203. use ext_phdf5_support_routines
  3204. USE HDF5 ! This module contains all necessary modules
  3205. implicit none
  3206. include 'wrf_status_codes.h'
  3207. integer ,intent(in) :: DataHandle
  3208. character*(*) ,intent(in) :: Element
  3209. real*8 ,intent(in) :: Data(*)
  3210. integer ,intent(in) :: Count
  3211. integer ,intent(out) :: Status
  3212. integer(hid_t) :: h5_objid
  3213. integer(hid_t) :: h5_atypeid
  3214. integer(hid_t) :: h5_aspaceid
  3215. integer(hid_t) :: h5_attrid
  3216. integer(hsize_t), dimension(7) :: adata_dims
  3217. character*3 :: routine_type
  3218. integer :: routine_atype
  3219. integer :: str_flag = 0 ! not a string type
  3220. integer(hid_t) :: hdf5err
  3221. character(VarNameLen) :: var
  3222. ! Do nothing unless it is time to write time-independent domain metadata.
  3223. IF ( .NOT. phdf5_ok_to_put_dom_ti( DataHandle ) ) THEN
  3224. Status = WRF_NO_ERR
  3225. return
  3226. ENDIF
  3227. var = 'DUMMY'
  3228. routine_type = 'DOM'
  3229. routine_atype = WRF_DOUBLE
  3230. adata_dims(1) = Count
  3231. call create_phdf5_objid(DataHandle,h5_objid,routine_type,var,Status)
  3232. if(Status /= WRF_NO_ERR) then
  3233. return
  3234. endif
  3235. call create_phdf5_adtypeid(h5_atypeid,routine_atype,Count,Status)
  3236. if(Status /= WRF_NO_ERR) then
  3237. return
  3238. endif
  3239. call create_phdf5_adspaceid(Count,str_flag,h5_aspaceid,Status)
  3240. if(Status /= WRF_NO_ERR) then
  3241. return
  3242. endif
  3243. call h5acreate_f(h5_objid,Element,h5_atypeid,h5_aspaceid, &
  3244. h5_attrid, hdf5err)
  3245. if(hdf5err.lt.0) then
  3246. Status = WRF_HDF5_ERR_ATTRIBUTE_CREATE
  3247. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  3248. call wrf_debug ( WARN , msg)
  3249. return
  3250. endif
  3251. call h5awrite_f(h5_attrid,h5_atypeid,Data,adata_dims,hdf5err)
  3252. if(hdf5err.lt.0) then
  3253. Status = WRF_HDF5_ERR_ATTRIBUTE_WRITE
  3254. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  3255. call wrf_debug ( WARN , msg)
  3256. return
  3257. endif
  3258. call clean_phdf5_attrids(h5_atypeid,h5_aspaceid,h5_attrid,str_flag,Status)
  3259. if(Status /= WRF_NO_ERR) then
  3260. return
  3261. endif
  3262. return
  3263. end subroutine ext_phdf5_put_dom_ti_double
  3264. ! write the domain time independent attribute with logical type
  3265. subroutine ext_phdf5_put_dom_ti_logical(DataHandle,Element,Data,Count,Status)
  3266. use wrf_phdf5_data
  3267. use ext_phdf5_support_routines
  3268. USE HDF5 ! This module contains all necessary modules
  3269. implicit none
  3270. include 'wrf_status_codes.h'
  3271. integer ,intent(in) :: DataHandle
  3272. character*(*) ,intent(in) :: Element
  3273. logical ,intent(in) :: Data(*)
  3274. integer ,dimension(:),allocatable :: Buffer
  3275. integer ,intent(in) :: Count
  3276. integer ,intent(out) :: Status
  3277. integer :: i
  3278. integer(hid_t) :: h5_objid
  3279. integer(hid_t) :: h5_atypeid
  3280. integer(hid_t) :: h5_aspaceid
  3281. integer(hid_t) :: h5_attrid
  3282. integer(hsize_t), dimension(7) :: adata_dims
  3283. character*3 :: routine_type
  3284. integer :: routine_atype
  3285. integer :: str_flag = 0 ! not a string type
  3286. integer(hid_t) :: hdf5err
  3287. character(VarNameLen) :: var
  3288. ! Do nothing unless it is time to write time-independent domain metadata.
  3289. IF ( .NOT. phdf5_ok_to_put_dom_ti( DataHandle ) ) THEN
  3290. Status = WRF_NO_ERR
  3291. return
  3292. ENDIF
  3293. var = 'DUMMY'
  3294. routine_type = 'DOM'
  3295. routine_atype = WRF_LOGICAL
  3296. adata_dims(1) = Count
  3297. allocate(Buffer(Count))
  3298. do i = 1,Count
  3299. if(Data(i) .EQV. .TRUE.) then
  3300. Buffer(i) = 1
  3301. else
  3302. Buffer(i) = 0
  3303. endif
  3304. enddo
  3305. call create_phdf5_objid(DataHandle,h5_objid,routine_type,var,Status)
  3306. if(Status /= WRF_NO_ERR) then
  3307. return
  3308. endif
  3309. call create_phdf5_adtypeid(h5_atypeid,routine_atype,Count,Status,DataHandle)
  3310. if(Status /= WRF_NO_ERR) then
  3311. return
  3312. endif
  3313. call create_phdf5_adspaceid(Count,str_flag,h5_aspaceid,Status)
  3314. if(Status /= WRF_NO_ERR) then
  3315. return
  3316. endif
  3317. call h5acreate_f(h5_objid,Element,h5_atypeid,h5_aspaceid, &
  3318. h5_attrid, hdf5err)
  3319. if(hdf5err.lt.0) then
  3320. Status = WRF_HDF5_ERR_ATTRIBUTE_CREATE
  3321. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  3322. call wrf_debug ( WARN , msg)
  3323. deallocate(buffer)
  3324. return
  3325. endif
  3326. call h5awrite_f(h5_attrid,h5_atypeid,Buffer,adata_dims,hdf5err)
  3327. if(hdf5err.lt.0) then
  3328. Status = WRF_HDF5_ERR_ATTRIBUTE_WRITE
  3329. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  3330. call wrf_debug ( WARN , msg)
  3331. deallocate(buffer)
  3332. return
  3333. endif
  3334. call clean_phdf5_attrids(h5_atypeid,h5_aspaceid,h5_attrid,str_flag,Status)
  3335. if(Status /= WRF_NO_ERR) then
  3336. return
  3337. endif
  3338. deallocate(Buffer)
  3339. end subroutine ext_phdf5_put_dom_ti_logical
  3340. ! write the domain time independent attribute with char type
  3341. subroutine ext_phdf5_put_dom_ti_char(DataHandle,Element,Data,Status)
  3342. use wrf_phdf5_data
  3343. use ext_phdf5_support_routines
  3344. USE HDF5 ! This module contains all necessary modules
  3345. implicit none
  3346. include 'wrf_status_codes.h'
  3347. !!!! Need more work.
  3348. integer ,intent(in) :: DataHandle
  3349. character*(*) ,intent(in) :: Element
  3350. character*(*) ,intent(in) :: Data
  3351. integer :: Count ! always 1 for char
  3352. integer ,intent(out) :: Status
  3353. integer(hid_t) :: h5_objid
  3354. integer(hid_t) :: h5_atypeid
  3355. integer(hid_t) :: h5_aspaceid
  3356. integer(hid_t) :: h5_attrid
  3357. integer(hsize_t), dimension(7) :: adata_dims
  3358. character*3 :: routine_type
  3359. integer :: routine_atype
  3360. integer :: str_flag = 1 ! is a string type
  3361. integer(hid_t) :: hdf5err
  3362. integer :: len_str
  3363. character(VarNameLen) :: var
  3364. character(1) :: RepData =' '
  3365. ! Do nothing unless it is time to write time-independent domain metadata.
  3366. IF ( .NOT. phdf5_ok_to_put_dom_ti( DataHandle ) ) THEN
  3367. Status = WRF_NO_ERR
  3368. return
  3369. ENDIF
  3370. Count = 1
  3371. var = 'DUMMY'
  3372. routine_type = 'DOM'
  3373. routine_atype = WRF_CHARACTER
  3374. adata_dims(1) = Count
  3375. call create_phdf5_objid(DataHandle,h5_objid,routine_type,var,Status)
  3376. if(Status /= WRF_NO_ERR) then
  3377. return
  3378. endif
  3379. ! This part may need more work, a special case is that the length of the
  3380. ! string may be 0, HDF5 cannot handle 0 length string(?),so set the length
  3381. ! to 1
  3382. len_str = len_trim(Data)
  3383. if(len_str == 0) then
  3384. len_str = 1
  3385. endif
  3386. call create_phdf5_adtypeid(h5_atypeid,routine_atype,len_str,Status)
  3387. if(Status /= WRF_NO_ERR) then
  3388. return
  3389. endif
  3390. call create_phdf5_adspaceid(Count,str_flag,h5_aspaceid,Status)
  3391. if(Status /= WRF_NO_ERR) then
  3392. return
  3393. endif
  3394. call h5acreate_f(h5_objid,Element,h5_atypeid,h5_aspaceid, &
  3395. h5_attrid, hdf5err)
  3396. if(hdf5err.lt.0) then
  3397. Status = WRF_HDF5_ERR_ATTRIBUTE_CREATE
  3398. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  3399. call wrf_debug ( WARN , msg)
  3400. return
  3401. endif
  3402. if(len_trim(Data) == 0) then
  3403. call h5awrite_f(h5_attrid,h5_atypeid,RepData,adata_dims,hdf5err)
  3404. if(hdf5err.lt.0) then
  3405. Status = WRF_HDF5_ERR_ATTRIBUTE_WRITE
  3406. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  3407. call wrf_debug ( WARN , msg)
  3408. return
  3409. endif
  3410. else
  3411. call h5awrite_f(h5_attrid,h5_atypeid,trim(Data),adata_dims,hdf5err)
  3412. if(hdf5err.lt.0) then
  3413. Status = WRF_HDF5_ERR_ATTRIBUTE_WRITE
  3414. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  3415. call wrf_debug ( WARN , msg)
  3416. return
  3417. endif
  3418. endif
  3419. call clean_phdf5_attrids(h5_atypeid,h5_aspaceid,h5_attrid,str_flag,Status)
  3420. if(Status /= WRF_NO_ERR) then
  3421. return
  3422. endif
  3423. return
  3424. end subroutine ext_phdf5_put_dom_ti_char
  3425. ! write the variable time independent attribute with real type
  3426. subroutine ext_phdf5_put_var_ti_real(DataHandle,Element,Var,Data,Count,Status)
  3427. use wrf_phdf5_data
  3428. use ext_phdf5_support_routines
  3429. USE HDF5 ! This module contains all necessary modules
  3430. implicit none
  3431. include 'wrf_status_codes.h'
  3432. integer ,intent(in) :: DataHandle
  3433. character*(*) ,intent(in) :: Element
  3434. character*(*) ,intent(in) :: Var
  3435. real ,intent(in) :: Data(*)
  3436. integer ,intent(in) :: Count
  3437. integer ,intent(out) :: Status
  3438. integer(hid_t) :: h5_objid
  3439. integer(hid_t) :: h5_atypeid
  3440. integer(hid_t) :: h5_aspaceid
  3441. integer(hid_t) :: h5_attrid
  3442. integer(hsize_t), dimension(7) :: adata_dims
  3443. character*3 :: routine_type
  3444. integer :: routine_atype
  3445. integer :: str_flag = 0 ! not a string type
  3446. integer(hid_t) :: hdf5err
  3447. type(wrf_phdf5_data_handle),pointer :: DH
  3448. routine_type = 'VAR'
  3449. routine_atype = WRF_REAL
  3450. adata_dims(1) = Count
  3451. call GetDH(DataHandle,DH,Status)
  3452. if(Status /= WRF_NO_ERR) then
  3453. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  3454. call wrf_debug ( WARN , msg)
  3455. return
  3456. endif
  3457. ! The following two checks must be here to avoid duplicating attributes
  3458. if (DH%FileStatus == WRF_FILE_OPENED_NOT_COMMITTED) then
  3459. Status = WRF_NO_ERR
  3460. return
  3461. endif
  3462. if(DH%TimeIndex > 1) then
  3463. Status = WRF_NO_ERR
  3464. return
  3465. endif
  3466. call create_phdf5_objid(DataHandle,h5_objid,routine_type,Var,Status)
  3467. if(Status /= WRF_NO_ERR) then
  3468. return
  3469. endif
  3470. call create_phdf5_adtypeid(h5_atypeid,routine_atype,Count,Status)
  3471. if(Status /= WRF_NO_ERR) then
  3472. return
  3473. endif
  3474. call create_phdf5_adspaceid(Count,str_flag,h5_aspaceid,Status)
  3475. if(Status /= WRF_NO_ERR) then
  3476. return
  3477. endif
  3478. call h5acreate_f(h5_objid,Element,h5_atypeid,h5_aspaceid, &
  3479. h5_attrid, hdf5err)
  3480. if(hdf5err.lt.0) then
  3481. Status = WRF_HDF5_ERR_ATTRIBUTE_CREATE
  3482. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  3483. call wrf_debug ( WARN , msg)
  3484. return
  3485. endif
  3486. call h5awrite_f(h5_attrid,h5_atypeid,Data,adata_dims,hdf5err)
  3487. if(hdf5err.lt.0) then
  3488. Status = WRF_HDF5_ERR_ATTRIBUTE_WRITE
  3489. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  3490. call wrf_debug ( WARN , msg)
  3491. return
  3492. endif
  3493. call clean_phdf5_attrids(h5_atypeid,h5_aspaceid,h5_attrid,str_flag,Status)
  3494. if(Status /= WRF_NO_ERR) then
  3495. return
  3496. endif
  3497. return
  3498. end subroutine ext_phdf5_put_var_ti_real
  3499. ! write the variable time independent attribute with double type
  3500. subroutine ext_phdf5_put_var_ti_double(DataHandle,Element,Var,Data,Count,Status)
  3501. use wrf_phdf5_data
  3502. use ext_phdf5_support_routines
  3503. USE HDF5 ! This module contains all necessary modules
  3504. implicit none
  3505. include 'wrf_status_codes.h'
  3506. integer ,intent(in) :: DataHandle
  3507. character*(*) ,intent(in) :: Element
  3508. real*8 ,intent(in) :: Data(*)
  3509. character*(*) ,intent(in) :: Var
  3510. integer ,intent(in) :: Count
  3511. integer ,intent(out) :: Status
  3512. integer(hid_t) :: h5_objid
  3513. integer(hid_t) :: h5_atypeid
  3514. integer(hid_t) :: h5_aspaceid
  3515. integer(hid_t) :: h5_attrid
  3516. integer(hsize_t), dimension(7) :: adata_dims
  3517. character*3 :: routine_type
  3518. integer :: routine_atype
  3519. integer :: str_flag = 0 ! not a string type
  3520. integer(hid_t) :: hdf5err
  3521. type(wrf_phdf5_data_handle),pointer :: DH
  3522. routine_type = 'VAR'
  3523. routine_atype = WRF_DOUBLE
  3524. adata_dims(1) = Count
  3525. call GetDH(DataHandle,DH,Status)
  3526. if(Status /= WRF_NO_ERR) then
  3527. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  3528. call wrf_debug ( WARN , msg)
  3529. return
  3530. endif
  3531. if (DH%FileStatus == WRF_FILE_OPENED_NOT_COMMITTED) then
  3532. Status = WRF_NO_ERR
  3533. return
  3534. endif
  3535. if(DH%TimeIndex > 1) then
  3536. Status = WRF_NO_ERR
  3537. return
  3538. endif
  3539. call create_phdf5_objid(DataHandle,h5_objid,routine_type,Var,Status)
  3540. if(Status /= WRF_NO_ERR) then
  3541. return
  3542. endif
  3543. call create_phdf5_adtypeid(h5_atypeid,routine_atype,Count,Status)
  3544. if(Status /= WRF_NO_ERR) then
  3545. return
  3546. endif
  3547. call create_phdf5_adspaceid(Count,str_flag,h5_aspaceid,Status)
  3548. if(Status /= WRF_NO_ERR) then
  3549. return
  3550. endif
  3551. call h5acreate_f(h5_objid,Element,h5_atypeid,h5_aspaceid, &
  3552. h5_attrid, hdf5err)
  3553. if(hdf5err.lt.0) then
  3554. Status = WRF_HDF5_ERR_ATTRIBUTE_CREATE
  3555. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  3556. call wrf_debug ( WARN , msg)
  3557. return
  3558. endif
  3559. call h5awrite_f(h5_attrid,h5_atypeid,Data,adata_dims,hdf5err)
  3560. if(hdf5err.lt.0) then
  3561. Status = WRF_HDF5_ERR_ATTRIBUTE_CREATE
  3562. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  3563. call wrf_debug ( WARN , msg)
  3564. return
  3565. endif
  3566. call clean_phdf5_attrids(h5_atypeid,h5_aspaceid,h5_attrid,str_flag,Status)
  3567. if(Status /= WRF_NO_ERR) then
  3568. return
  3569. endif
  3570. return
  3571. end subroutine ext_phdf5_put_var_ti_double
  3572. ! write the variable time independent attribute with integer type
  3573. subroutine ext_phdf5_put_var_ti_integer(DataHandle,Element,Var,Data,Count,Status)
  3574. use wrf_phdf5_data
  3575. use ext_phdf5_support_routines
  3576. USE HDF5 ! This module contains all necessary modules
  3577. implicit none
  3578. include 'wrf_status_codes.h'
  3579. integer ,intent(in) :: DataHandle
  3580. character*(*) ,intent(in) :: Element
  3581. character*(*) ,intent(in) :: Var
  3582. integer ,intent(in) :: Data(*)
  3583. integer ,intent(in) :: Count
  3584. integer ,intent(out) :: Status
  3585. integer(hid_t) :: h5_objid
  3586. integer(hid_t) :: h5_atypeid
  3587. integer(hid_t) :: h5_aspaceid
  3588. integer(hid_t) :: h5_attrid
  3589. integer(hsize_t), dimension(7) :: adata_dims
  3590. character*3 :: routine_type
  3591. integer :: routine_atype
  3592. integer :: str_flag = 0 ! not a string type
  3593. integer(hid_t) :: hdf5err
  3594. type(wrf_phdf5_data_handle),pointer :: DH
  3595. routine_type = 'VAR'
  3596. routine_atype = WRF_INTEGER
  3597. adata_dims(1) = Count
  3598. call GetDH(DataHandle,DH,Status)
  3599. if(Status /= WRF_NO_ERR) then
  3600. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  3601. call wrf_debug ( WARN , msg)
  3602. return
  3603. endif
  3604. ! The following two checks must be here to avoid duplicating attributes
  3605. if (DH%FileStatus == WRF_FILE_OPENED_NOT_COMMITTED) then
  3606. Status = WRF_NO_ERR
  3607. return
  3608. endif
  3609. if(DH%TimeIndex > 1) then
  3610. Status = WRF_NO_ERR
  3611. return
  3612. endif
  3613. call create_phdf5_objid(DataHandle,h5_objid,routine_type,Var,Status)
  3614. if(Status /= WRF_NO_ERR) then
  3615. return
  3616. endif
  3617. call create_phdf5_adtypeid(h5_atypeid,routine_atype,Count,Status)
  3618. if(Status /= WRF_NO_ERR) then
  3619. return
  3620. endif
  3621. call create_phdf5_adspaceid(Count,str_flag,h5_aspaceid,Status)
  3622. if(Status /= WRF_NO_ERR) then
  3623. return
  3624. endif
  3625. call h5acreate_f(h5_objid,Element,h5_atypeid,h5_aspaceid, &
  3626. h5_attrid, hdf5err)
  3627. if(hdf5err.lt.0) then
  3628. Status = WRF_HDF5_ERR_ATTRIBUTE_CREATE
  3629. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  3630. call wrf_debug ( WARN , msg)
  3631. return
  3632. endif
  3633. call h5awrite_f(h5_attrid,h5_atypeid,Data,adata_dims,hdf5err)
  3634. if(hdf5err.lt.0) then
  3635. Status = WRF_HDF5_ERR_ATTRIBUTE_WRITE
  3636. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  3637. call wrf_debug ( WARN , msg)
  3638. return
  3639. endif
  3640. call clean_phdf5_attrids(h5_atypeid,h5_aspaceid,h5_attrid,str_flag,Status)
  3641. if(Status /= WRF_NO_ERR) then
  3642. return
  3643. endif
  3644. return
  3645. end subroutine ext_phdf5_put_var_ti_integer
  3646. ! write the variable time independent attribute with logical type
  3647. subroutine ext_phdf5_put_var_ti_logical(DataHandle,Element,Var,Data,Count,Status)
  3648. use wrf_phdf5_data
  3649. use ext_phdf5_support_routines
  3650. USE HDF5 ! This module contains all necessary modules
  3651. implicit none
  3652. include 'wrf_status_codes.h'
  3653. integer ,intent(in) :: DataHandle
  3654. character*(*) ,intent(in) :: Element
  3655. character*(*) ,intent(in) :: Var
  3656. logical ,intent(in) :: Data(*)
  3657. integer ,dimension(:),allocatable :: Buffer
  3658. integer ,intent(in) :: Count
  3659. integer ,intent(out) :: Status
  3660. integer :: i
  3661. integer(hid_t) :: h5_objid
  3662. integer(hid_t) :: h5_atypeid
  3663. integer(hid_t) :: h5_aspaceid
  3664. integer(hid_t) :: h5_attrid
  3665. integer(hsize_t), dimension(7) :: adata_dims
  3666. character*3 :: routine_type
  3667. integer :: routine_atype
  3668. integer :: str_flag = 0 ! not a string type
  3669. integer(hid_t) :: hdf5err
  3670. type(wrf_phdf5_data_handle),pointer :: DH
  3671. routine_type = 'VAR'
  3672. routine_atype = WRF_LOGICAL
  3673. adata_dims(1) = Count
  3674. allocate(Buffer(Count))
  3675. do i = 1,Count
  3676. if(Data(i) .EQV. .TRUE.) then
  3677. Buffer(i) = 1
  3678. else
  3679. Buffer(i) = 0
  3680. endif
  3681. enddo
  3682. call GetDH(DataHandle,DH,Status)
  3683. if(Status /= WRF_NO_ERR) then
  3684. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  3685. call wrf_debug ( WARN , msg)
  3686. return
  3687. endif
  3688. ! The following two checks must be here to avoid duplicating attributes
  3689. if (DH%FileStatus == WRF_FILE_OPENED_NOT_COMMITTED) then
  3690. Status = WRF_NO_ERR
  3691. return
  3692. endif
  3693. if(DH%TimeIndex > 1) then
  3694. Status = WRF_NO_ERR
  3695. return
  3696. endif
  3697. call create_phdf5_objid(DataHandle,h5_objid,routine_type,var,Status)
  3698. if(Status /= WRF_NO_ERR) then
  3699. return
  3700. endif
  3701. call create_phdf5_adtypeid(h5_atypeid,routine_atype,Count,Status)
  3702. if(Status /= WRF_NO_ERR) then
  3703. return
  3704. endif
  3705. call create_phdf5_adspaceid(Count,str_flag,h5_aspaceid,Status)
  3706. if(Status /= WRF_NO_ERR) then
  3707. return
  3708. endif
  3709. call h5acreate_f(h5_objid,Element,h5_atypeid,h5_aspaceid, &
  3710. h5_attrid, hdf5err)
  3711. if(hdf5err.lt.0) then
  3712. Status = WRF_HDF5_ERR_ATTRIBUTE_CREATE
  3713. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  3714. call wrf_debug ( WARN , msg)
  3715. deallocate(buffer)
  3716. return
  3717. endif
  3718. call h5awrite_f(h5_attrid,h5_atypeid,Buffer,adata_dims,hdf5err)
  3719. if(hdf5err.lt.0) then
  3720. Status = WRF_HDF5_ERR_ATTRIBUTE_WRITE
  3721. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  3722. call wrf_debug ( WARN , msg)
  3723. deallocate(buffer)
  3724. return
  3725. endif
  3726. call clean_phdf5_attrids(h5_atypeid,h5_aspaceid,h5_attrid,str_flag,Status)
  3727. if(Status /= WRF_NO_ERR) then
  3728. return
  3729. endif
  3730. return
  3731. end subroutine ext_phdf5_put_var_ti_logical
  3732. ! write the variable time independent attribute with char type
  3733. subroutine ext_phdf5_put_var_ti_char(DataHandle,Element,Var,Data,Status)
  3734. use wrf_phdf5_data
  3735. use ext_phdf5_support_routines
  3736. USE HDF5 ! This module contains all necessary modules
  3737. implicit none
  3738. include 'wrf_status_codes.h'
  3739. integer ,intent(in) :: DataHandle
  3740. character*(*) ,intent(in) :: Element
  3741. character*(*) ,intent(in) :: Data
  3742. character*(*) ,intent(in) :: Var
  3743. integer :: Count
  3744. integer ,intent(out) :: Status
  3745. integer(hid_t) :: h5_objid
  3746. integer(hid_t) :: h5_atypeid
  3747. integer(hid_t) :: h5_aspaceid
  3748. integer(hid_t) :: h5_attrid
  3749. integer(hsize_t), dimension(7) :: adata_dims
  3750. character*3 :: routine_type
  3751. integer :: routine_atype
  3752. integer :: str_flag = 1 ! IS string type
  3753. integer(hid_t) :: hdf5err
  3754. integer :: len_str
  3755. character(1) :: RepData = ' '
  3756. type(wrf_phdf5_data_handle),pointer :: DH
  3757. Count = 1
  3758. routine_type = 'VAR'
  3759. routine_atype = WRF_CHARACTER
  3760. adata_dims(1) = Count
  3761. call GetDH(DataHandle,DH,Status)
  3762. if(Status /= WRF_NO_ERR) then
  3763. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__, &
  3764. ', line', __LINE__
  3765. call wrf_debug ( WARN , msg)
  3766. return
  3767. endif
  3768. ! The following two checks must be here to avoid duplicating attributes
  3769. if (DH%FileStatus == WRF_FILE_OPENED_NOT_COMMITTED) then
  3770. Status = WRF_NO_ERR
  3771. return
  3772. endif
  3773. if(DH%TimeIndex > 1) then
  3774. Status = WRF_NO_ERR
  3775. return
  3776. endif
  3777. call create_phdf5_objid(DataHandle,h5_objid,routine_type,Var,Status)
  3778. if(Status /= WRF_NO_ERR) then
  3779. return
  3780. endif
  3781. len_str = len_trim(Data)
  3782. if(len_str .eq. 0) then
  3783. len_str = 1
  3784. endif
  3785. call create_phdf5_adtypeid(h5_atypeid,routine_atype,len_str,Status)
  3786. if(Status /= WRF_NO_ERR) then
  3787. return
  3788. endif
  3789. call create_phdf5_adspaceid(Count,str_flag,h5_aspaceid,Status)
  3790. if(Status /= WRF_NO_ERR) then
  3791. return
  3792. endif
  3793. call h5acreate_f(h5_objid,Element,h5_atypeid,h5_aspaceid, &
  3794. h5_attrid, hdf5err)
  3795. if(hdf5err.lt.0) then
  3796. Status = WRF_HDF5_ERR_ATTRIBUTE_CREATE
  3797. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  3798. call wrf_debug ( WARN , msg)
  3799. return
  3800. endif
  3801. if(len_trim(Data) == 0) then
  3802. call h5awrite_f(h5_attrid,h5_atypeid,RepData,adata_dims,hdf5err)
  3803. if(hdf5err.lt.0) then
  3804. Status = WRF_HDF5_ERR_ATTRIBUTE_WRITE
  3805. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  3806. call wrf_debug ( WARN , msg)
  3807. return
  3808. endif
  3809. else
  3810. call h5awrite_f(h5_attrid,h5_atypeid,trim(Data),adata_dims,hdf5err)
  3811. if(hdf5err.lt.0) then
  3812. Status = WRF_HDF5_ERR_ATTRIBUTE_WRITE
  3813. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  3814. call wrf_debug ( WARN , msg)
  3815. return
  3816. endif
  3817. endif
  3818. call clean_phdf5_attrids(h5_atypeid,h5_aspaceid,h5_attrid,str_flag,Status)
  3819. if(Status /= WRF_NO_ERR) then
  3820. return
  3821. endif
  3822. return
  3823. end subroutine ext_phdf5_put_var_ti_char
  3824. ! This routine will retrieve the dimensional table, should be useful
  3825. ! for tool developers.
  3826. subroutine retrieve_table(DataHandle,Status)
  3827. use wrf_phdf5_data
  3828. use ext_phdf5_support_routines
  3829. use hdf5
  3830. implicit none
  3831. include 'wrf_status_codes.h'
  3832. character*256,dimension(MaxTabDims) :: dim_name
  3833. integer,dimension(:),allocatable :: length
  3834. integer,dimension(:),allocatable :: unlimited
  3835. integer, intent(in) :: DataHandle
  3836. integer, intent(out) :: Status
  3837. integer(hid_t) :: dset_id
  3838. integer(hid_t) :: dataspace_id
  3839. integer(hid_t) :: dtstr_id
  3840. integer(hid_t) :: dt1_id
  3841. integer(hid_t) :: dtint1_id
  3842. integer(hid_t) :: dtint2_id
  3843. integer(size_t) :: type_sizei
  3844. integer(size_t) :: offset
  3845. integer :: table_length
  3846. integer(size_t) :: string_size
  3847. integer(hsize_t),dimension(7) :: data_dims
  3848. integer(hsize_t) :: table_size
  3849. integer :: i
  3850. integer :: hdf5err
  3851. type(wrf_phdf5_data_handle),pointer :: DH
  3852. call GetDH(DataHandle,DH,Status)
  3853. if(Status /= WRF_NO_ERR) then
  3854. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  3855. call wrf_debug ( WARN , msg)
  3856. return
  3857. endif
  3858. call h5dopen_f(DH%DimGroupID,"h5dim_table",dset_id,hdf5err)
  3859. if(hdf5err.lt.0) then
  3860. Status = WRF_HDF5_ERR_DATASET_OPEN
  3861. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  3862. call wrf_debug ( WARN , msg)
  3863. return
  3864. endif
  3865. call h5dget_space_f(dset_id,dataspace_id,hdf5err)
  3866. if(hdf5err.lt.0) then
  3867. Status = WRF_HDF5_ERR_DATASPACE
  3868. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  3869. call wrf_debug ( WARN , msg)
  3870. return
  3871. endif
  3872. call h5sget_simple_extent_npoints_f(dataspace_id,table_size,hdf5err)
  3873. if(hdf5err.lt.0) then
  3874. Status = WRF_HDF5_ERR_DATASPACE
  3875. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  3876. call wrf_debug ( WARN , msg)
  3877. return
  3878. endif
  3879. data_dims(1) = table_size
  3880. allocate(length(table_size))
  3881. allocate(unlimited(table_size))
  3882. ! the name of the dimension
  3883. call h5tcopy_f(H5T_NATIVE_CHARACTER,dtstr_id,hdf5err)
  3884. if(hdf5err.lt.0) then
  3885. Status = WRF_HDF5_ERR_DATATYPE
  3886. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  3887. call wrf_debug ( WARN , msg)
  3888. deallocate(length)
  3889. deallocate(unlimited)
  3890. return
  3891. endif
  3892. string_size = 256
  3893. call h5tset_size_f(dtstr_id,string_size,hdf5err)
  3894. if(hdf5err.lt.0) then
  3895. Status = WRF_HDF5_ERR_DATATYPE
  3896. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  3897. call wrf_debug ( WARN , msg)
  3898. deallocate(length)
  3899. deallocate(unlimited)
  3900. return
  3901. endif
  3902. call h5tcreate_f(H5T_COMPOUND_F,string_size,dt1_id,hdf5err)
  3903. if(hdf5err.lt.0) then
  3904. Status = WRF_HDF5_ERR_DATATYPE
  3905. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  3906. call wrf_debug ( WARN , msg)
  3907. deallocate(length)
  3908. deallocate(unlimited)
  3909. return
  3910. endif
  3911. offset = 0
  3912. call h5tinsert_f(dt1_id,"dim_name",offset,dtstr_id,hdf5err)
  3913. if(hdf5err.lt.0) then
  3914. Status = WRF_HDF5_ERR_DATATYPE
  3915. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  3916. call wrf_debug ( WARN , msg)
  3917. deallocate(length)
  3918. deallocate(unlimited)
  3919. return
  3920. endif
  3921. call h5dread_f(dset_id,dt1_id,dim_name,data_dims,hdf5err)
  3922. if(hdf5err.lt.0) then
  3923. Status = WRF_HDF5_ERR_DATASET_READ
  3924. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  3925. call wrf_debug ( WARN , msg)
  3926. deallocate(length)
  3927. deallocate(unlimited)
  3928. return
  3929. endif
  3930. ! the length of the dimension
  3931. call h5tget_size_f(H5T_NATIVE_INTEGER,type_sizei,hdf5err)
  3932. if(hdf5err.lt.0) then
  3933. Status = WRF_HDF5_ERR_DATATYPE
  3934. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  3935. call wrf_debug ( WARN , msg)
  3936. deallocate(length)
  3937. deallocate(unlimited)
  3938. return
  3939. endif
  3940. call h5tcreate_f(H5T_COMPOUND_F,type_sizei,dtint1_id,hdf5err)
  3941. if(hdf5err.lt.0) then
  3942. Status = WRF_HDF5_ERR_DATATYPE
  3943. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  3944. call wrf_debug ( WARN , msg)
  3945. deallocate(length)
  3946. deallocate(unlimited)
  3947. return
  3948. endif
  3949. offset = 0
  3950. call h5tinsert_f(dtint1_id,"dim_length",offset,H5T_NATIVE_INTEGER,hdf5err)
  3951. if(hdf5err.lt.0) then
  3952. Status = WRF_HDF5_ERR_DATATYPE
  3953. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  3954. call wrf_debug ( WARN , msg)
  3955. deallocate(length)
  3956. deallocate(unlimited)
  3957. return
  3958. endif
  3959. call h5dread_f(dset_id,dtint1_id,length,data_dims,hdf5err)
  3960. if(hdf5err.lt.0) then
  3961. Status = WRF_HDF5_ERR_DATASET_READ
  3962. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  3963. call wrf_debug ( WARN , msg)
  3964. deallocate(length)
  3965. deallocate(unlimited)
  3966. return
  3967. endif
  3968. ! the unlimited info. of the dimension
  3969. call h5tget_size_f(H5T_NATIVE_INTEGER,type_sizei,hdf5err)
  3970. if(hdf5err.lt.0) then
  3971. Status = WRF_HDF5_ERR_DATATYPE
  3972. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  3973. call wrf_debug ( WARN , msg)
  3974. deallocate(length)
  3975. deallocate(unlimited)
  3976. return
  3977. endif
  3978. call h5tcreate_f(H5T_COMPOUND_F,type_sizei,dtint2_id,hdf5err)
  3979. if(hdf5err.lt.0) then
  3980. Status = WRF_HDF5_ERR_DATATYPE
  3981. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  3982. call wrf_debug ( WARN , msg)
  3983. deallocate(length)
  3984. deallocate(unlimited)
  3985. return
  3986. endif
  3987. offset = 0
  3988. call h5tinsert_f(dtint2_id,"dim_unlimited",offset,H5T_NATIVE_INTEGER,hdf5err)
  3989. if(hdf5err.lt.0) then
  3990. Status = WRF_HDF5_ERR_DATATYPE
  3991. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  3992. call wrf_debug ( WARN , msg)
  3993. deallocate(length)
  3994. deallocate(unlimited)
  3995. return
  3996. endif
  3997. call h5dread_f(dset_id,dtint2_id,unlimited,data_dims,hdf5err)
  3998. if(hdf5err.lt.0) then
  3999. Status = WRF_HDF5_ERR_DATASET_READ
  4000. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  4001. call wrf_debug ( WARN , msg)
  4002. deallocate(length)
  4003. deallocate(unlimited)
  4004. return
  4005. endif
  4006. ! Store the information to the table array
  4007. do i =1,table_size
  4008. DH%DIMTABLE(i)%dim_name = dim_name(i)
  4009. DH%DIMTABLE(i)%length = length(i)
  4010. DH%DIMTABLE(i)%unlimited = unlimited(i)
  4011. enddo
  4012. deallocate(length)
  4013. deallocate(unlimited)
  4014. call h5tclose_f(dtint1_id,hdf5err)
  4015. if(hdf5err.lt.0) then
  4016. Status = WRF_HDF5_ERR_CLOSE_GENERAL
  4017. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  4018. call wrf_debug ( WARN , msg)
  4019. return
  4020. endif
  4021. call h5tclose_f(dtstr_id,hdf5err)
  4022. if(hdf5err.lt.0) then
  4023. Status = WRF_HDF5_ERR_CLOSE_GENERAL
  4024. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  4025. call wrf_debug ( WARN , msg)
  4026. return
  4027. endif
  4028. call h5tclose_f(dtint2_id,hdf5err)
  4029. if(hdf5err.lt.0) then
  4030. Status = WRF_HDF5_ERR_CLOSE_GENERAL
  4031. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  4032. call wrf_debug ( WARN , msg)
  4033. return
  4034. endif
  4035. call h5tclose_f(dt1_id,hdf5err)
  4036. if(hdf5err.lt.0) then
  4037. Status = WRF_HDF5_ERR_CLOSE_GENERAL
  4038. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  4039. call wrf_debug ( WARN , msg)
  4040. return
  4041. endif
  4042. call h5sclose_f(dataspace_id,hdf5err)
  4043. if(hdf5err.lt.0) then
  4044. Status = WRF_HDF5_ERR_CLOSE_GENERAL
  4045. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  4046. call wrf_debug ( WARN , msg)
  4047. return
  4048. endif
  4049. call h5dclose_f(dset_id,hdf5err)
  4050. if(hdf5err.lt.0) then
  4051. Status = WRF_HDF5_ERR_DATASET_CLOSE
  4052. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  4053. call wrf_debug ( WARN , msg)
  4054. return
  4055. endif
  4056. Status = WRF_NO_ERR
  4057. return
  4058. end subroutine retrieve_table
  4059. ! store(write) the dimensional table into the HDF5 file
  4060. subroutine store_table(DataHandle,table_length,Status)
  4061. use wrf_phdf5_data
  4062. use ext_phdf5_support_routines
  4063. use hdf5
  4064. implicit none
  4065. include 'wrf_status_codes.h'
  4066. integer ,intent(in) :: DataHandle
  4067. integer, intent(in) :: table_length
  4068. integer, intent(out) :: Status
  4069. type(wrf_phdf5_data_handle),pointer :: DH
  4070. integer(hid_t) :: group_id
  4071. integer(hid_t) :: dset_id
  4072. integer(hid_t) :: dtype_id
  4073. integer(hid_t) :: dtstr_id
  4074. integer(hid_t) :: dtstrm_id
  4075. integer(hid_t) :: dtint1_id
  4076. integer(hid_t) :: dtint2_id
  4077. integer(hid_t) :: plist_id
  4078. integer(size_t) :: type_size
  4079. integer(size_t) :: type_sizes
  4080. integer(size_t) :: type_sizei
  4081. integer(size_t) :: offset
  4082. character*256 ,dimension(MaxTabDims) :: dim_name
  4083. integer ,dimension(:),allocatable :: length
  4084. integer ,dimension(:),allocatable :: unlimited
  4085. integer(hid_t) :: dspace_id
  4086. integer(hsize_t) ,dimension(1) :: table_dims
  4087. integer :: table_rank
  4088. integer(hsize_t) ,dimension(7) :: data_dims
  4089. integer :: i,j
  4090. integer :: hdf5err
  4091. data_dims(1) = table_length
  4092. call GetDH(DataHandle,DH,Status)
  4093. if(Status /= WRF_NO_ERR) then
  4094. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__, &
  4095. ', line', __LINE__
  4096. call wrf_debug ( WARN , msg)
  4097. return
  4098. endif
  4099. call create_h5filetype(dtype_id,Status)
  4100. if(Status /= WRF_NO_ERR) then
  4101. return
  4102. endif
  4103. ! obtain group id
  4104. group_id = DH%DimGroupID
  4105. ! create data space
  4106. table_rank = 1
  4107. table_dims(1) = table_length
  4108. call h5screate_simple_f(table_rank,table_dims,dspace_id,hdf5err)
  4109. if(hdf5err.lt.0) then
  4110. Status = WRF_HDF5_ERR_DATASPACE
  4111. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  4112. call wrf_debug ( WARN , msg)
  4113. return
  4114. endif
  4115. ! obtain the data
  4116. allocate(length(table_length))
  4117. allocate(unlimited(table_length))
  4118. do i =1, table_length
  4119. length(i) = DH%DIMTABLE(i)%length
  4120. unlimited(i) = DH%DIMTABLE(i)%unlimited
  4121. enddo
  4122. do i=1,table_length
  4123. do j=1,256
  4124. dim_name(i)(j:j)=DH%DIMTABLE(i)%dim_name(j:j)
  4125. enddo
  4126. enddo
  4127. ! under dimensional group
  4128. call h5dcreate_f(group_id,"h5dim_table",dtype_id,dspace_id,&
  4129. dset_id,hdf5err)
  4130. if(hdf5err.lt.0) then
  4131. Status = WRF_HDF5_ERR_DATASET_CREATE
  4132. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  4133. call wrf_debug ( WARN , msg)
  4134. deallocate(length)
  4135. deallocate(unlimited)
  4136. return
  4137. endif
  4138. ! create memory types
  4139. call h5tget_size_f(H5T_NATIVE_INTEGER,type_sizei,hdf5err)
  4140. if(hdf5err.lt.0) then
  4141. Status = WRF_HDF5_ERR_DATATYPE
  4142. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  4143. call wrf_debug ( WARN , msg)
  4144. deallocate(length)
  4145. deallocate(unlimited)
  4146. return
  4147. endif
  4148. ! FOR string, it needs extra handling
  4149. call h5tcopy_f(H5T_NATIVE_CHARACTER,dtstr_id,hdf5err)
  4150. if(hdf5err.lt.0) then
  4151. Status = WRF_HDF5_ERR_DATATYPE
  4152. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  4153. call wrf_debug ( WARN , msg)
  4154. deallocate(length)
  4155. deallocate(unlimited)
  4156. return
  4157. endif
  4158. type_size = 256
  4159. call h5tset_size_f(dtstr_id, type_size,hdf5err)
  4160. if(hdf5err.lt.0) then
  4161. Status = WRF_HDF5_ERR_DATATYPE
  4162. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  4163. call wrf_debug ( WARN , msg)
  4164. deallocate(length)
  4165. deallocate(unlimited)
  4166. return
  4167. endif
  4168. call h5tget_size_f(dtstr_id, type_size,hdf5err)
  4169. if(hdf5err.lt.0) then
  4170. Status = WRF_HDF5_ERR_DATATYPE
  4171. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  4172. call wrf_debug ( WARN , msg)
  4173. deallocate(length)
  4174. deallocate(unlimited)
  4175. return
  4176. endif
  4177. call h5tcreate_f(H5T_COMPOUND_F,type_size,dtstrm_id,hdf5err)
  4178. if(hdf5err.lt.0) then
  4179. Status = WRF_HDF5_ERR_DATATYPE
  4180. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  4181. call wrf_debug ( WARN , msg)
  4182. deallocate(length)
  4183. deallocate(unlimited)
  4184. return
  4185. endif
  4186. offset = 0
  4187. call h5tinsert_f(dtstrm_id,"dim_name",offset,dtstr_id,hdf5err)
  4188. if(hdf5err.lt.0) then
  4189. Status = WRF_HDF5_ERR_DATATYPE
  4190. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  4191. call wrf_debug ( WARN , msg)
  4192. deallocate(length)
  4193. deallocate(unlimited)
  4194. return
  4195. endif
  4196. call h5tcreate_f(H5T_COMPOUND_F,type_sizei,dtint1_id,hdf5err)
  4197. if(hdf5err.lt.0) then
  4198. Status = WRF_HDF5_ERR_DATATYPE
  4199. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  4200. call wrf_debug ( WARN , msg)
  4201. deallocate(length)
  4202. deallocate(unlimited)
  4203. return
  4204. endif
  4205. offset = 0
  4206. call h5tinsert_f(dtint1_id,"dim_length",offset,H5T_NATIVE_INTEGER,&
  4207. hdf5err)
  4208. if(hdf5err.lt.0) then
  4209. Status = WRF_HDF5_ERR_DATATYPE
  4210. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  4211. call wrf_debug ( WARN , msg)
  4212. deallocate(length)
  4213. deallocate(unlimited)
  4214. return
  4215. endif
  4216. call h5tcreate_f(H5T_COMPOUND_F,type_sizei,dtint2_id,hdf5err)
  4217. if(hdf5err.lt.0) then
  4218. Status = WRF_HDF5_ERR_DATATYPE
  4219. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  4220. call wrf_debug ( WARN , msg)
  4221. deallocate(length)
  4222. deallocate(unlimited)
  4223. return
  4224. endif
  4225. offset = 0
  4226. call h5tinsert_f(dtint2_id,"dim_unlimited",offset,H5T_NATIVE_INTEGER,&
  4227. hdf5err)
  4228. if(hdf5err.lt.0) then
  4229. Status = WRF_HDF5_ERR_DATATYPE
  4230. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  4231. call wrf_debug ( WARN , msg)
  4232. deallocate(length)
  4233. deallocate(unlimited)
  4234. return
  4235. endif
  4236. ! write data by fields in the datatype,but first create a property list
  4237. call h5pcreate_f(H5P_DATASET_XFER_F,plist_id, hdf5err)
  4238. if(hdf5err.lt.0) then
  4239. Status = WRF_HDF5_ERR_PROPERTY_LIST
  4240. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  4241. call wrf_debug ( WARN , msg)
  4242. deallocate(length)
  4243. deallocate(unlimited)
  4244. return
  4245. endif
  4246. call h5pset_preserve_f(plist_id,.TRUE.,hdf5err)
  4247. if(hdf5err.lt.0) then
  4248. Status = WRF_HDF5_ERR_PROPERTY_LIST
  4249. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  4250. call wrf_debug ( WARN , msg)
  4251. deallocate(length)
  4252. deallocate(unlimited)
  4253. return
  4254. endif
  4255. call h5dwrite_f(dset_id,dtstrm_id,dim_name,data_dims,hdf5err,&
  4256. xfer_prp = plist_id)
  4257. if(hdf5err.lt.0) then
  4258. Status = WRF_HDF5_ERR_DATASET_WRITE
  4259. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  4260. call wrf_debug ( WARN , msg)
  4261. deallocate(length)
  4262. deallocate(unlimited)
  4263. return
  4264. endif
  4265. call h5dwrite_f(dset_id,dtint1_id,length,data_dims,hdf5err,&
  4266. xfer_prp = plist_id)
  4267. if(hdf5err.lt.0) then
  4268. Status = WRF_HDF5_ERR_DATASET_WRITE
  4269. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  4270. call wrf_debug ( WARN , msg)
  4271. deallocate(length)
  4272. deallocate(unlimited)
  4273. return
  4274. endif
  4275. call h5dwrite_f(dset_id,dtint2_id,unlimited,data_dims,hdf5err,&
  4276. xfer_prp = plist_id)
  4277. if(hdf5err.lt.0) then
  4278. Status = WRF_HDF5_ERR_DATASET_WRITE
  4279. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  4280. call wrf_debug ( WARN , msg)
  4281. deallocate(length)
  4282. deallocate(unlimited)
  4283. return
  4284. endif
  4285. deallocate(length)
  4286. deallocate(unlimited)
  4287. ! release resources
  4288. call h5tclose_f(dtstr_id,hdf5err)
  4289. if(hdf5err.lt.0) then
  4290. Status = WRF_HDF5_ERR_CLOSE_GENERAL
  4291. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  4292. call wrf_debug ( WARN , msg)
  4293. return
  4294. endif
  4295. call h5tclose_f(dtstrm_id,hdf5err)
  4296. if(hdf5err.lt.0) then
  4297. Status = WRF_HDF5_ERR_CLOSE_GENERAL
  4298. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  4299. call wrf_debug ( WARN , msg)
  4300. return
  4301. endif
  4302. call h5tclose_f(dtint1_id,hdf5err)
  4303. if(hdf5err.lt.0) then
  4304. Status = WRF_HDF5_ERR_CLOSE_GENERAL
  4305. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  4306. call wrf_debug ( WARN , msg)
  4307. return
  4308. endif
  4309. call h5tclose_f(dtint2_id,hdf5err)
  4310. if(hdf5err.lt.0) then
  4311. Status = WRF_HDF5_ERR_CLOSE_GENERAL
  4312. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  4313. call wrf_debug ( WARN , msg)
  4314. return
  4315. endif
  4316. call h5tclose_f(dtype_id,hdf5err)
  4317. if(hdf5err.lt.0) then
  4318. Status = WRF_HDF5_ERR_CLOSE_GENERAL
  4319. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  4320. call wrf_debug ( WARN , msg)
  4321. return
  4322. endif
  4323. call h5pclose_f(plist_id,hdf5err)
  4324. if(hdf5err.lt.0) then
  4325. Status = WRF_HDF5_ERR_CLOSE_GENERAL
  4326. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  4327. call wrf_debug ( WARN , msg)
  4328. return
  4329. endif
  4330. call h5dclose_f(dset_id,hdf5err)
  4331. if(hdf5err.lt.0) then
  4332. Status = WRF_HDF5_ERR_DATASET_CLOSE
  4333. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  4334. call wrf_debug ( WARN , msg)
  4335. return
  4336. endif
  4337. call h5sclose_f(dspace_id,hdf5err)
  4338. if(hdf5err.lt.0) then
  4339. Status = WRF_HDF5_ERR_CLOSE_GENERAL
  4340. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  4341. call wrf_debug ( WARN , msg)
  4342. return
  4343. endif
  4344. return
  4345. end subroutine store_table
  4346. subroutine free_memory(DataHandle,Status)
  4347. use wrf_phdf5_data
  4348. use ext_phdf5_support_routines
  4349. use HDF5
  4350. implicit none
  4351. include 'wrf_status_codes.h'
  4352. include 'mpif.h'
  4353. integer ,intent(in) :: DataHandle
  4354. integer ,intent(out) :: Status
  4355. integer :: hdf5err
  4356. type(wrf_phdf5_data_handle),pointer :: DH
  4357. integer :: i
  4358. integer :: stat
  4359. real*8 :: timeaw,timebw
  4360. call GetDH(DataHandle,DH,Status)
  4361. if(Status /= WRF_NO_ERR) then
  4362. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  4363. call wrf_debug ( WARN , msg)
  4364. return
  4365. endif
  4366. if(DH%Free) then
  4367. Status = WRF_HDF5_ERR_OTHERS
  4368. write(msg,*) '',__FILE__,', line', __LINE__
  4369. call wrf_debug ( WARN , msg)
  4370. return
  4371. endif
  4372. deallocate(DH%Times, STAT=stat)
  4373. if(stat/= 0) then
  4374. Status = WRF_HDF5_ERR_DEALLOCATION
  4375. write(msg,*) 'Fatal DEALLOCATION ERROR in ',__FILE__,', line', __LINE__
  4376. call wrf_debug ( FATAL , msg)
  4377. return
  4378. endif
  4379. deallocate(DH%DimLengths, STAT=stat)
  4380. if(stat/= 0) then
  4381. Status = WRF_HDF5_ERR_DEALLOCATION
  4382. write(msg,*) 'Fatal DEALLOCATION ERROR in ',__FILE__,', line', __LINE__
  4383. call wrf_debug ( FATAL , msg)
  4384. return
  4385. endif
  4386. deallocate(DH%DimIDs, STAT=stat)
  4387. if(stat/= 0) then
  4388. Status = WRF_HDF5_ERR_DEALLOCATION
  4389. write(msg,*) 'Fatal DEALLOCATION ERROR in ',__FILE__,', line', __LINE__
  4390. call wrf_debug ( FATAL , msg)
  4391. return
  4392. endif
  4393. deallocate(DH%DimNames, STAT=stat)
  4394. if(stat/= 0) then
  4395. Status = WRF_HDF5_ERR_DEALLOCATION
  4396. write(msg,*) 'Fatal DEALLOCATION ERROR in ',__FILE__,', line', __LINE__
  4397. call wrf_debug ( FATAL , msg)
  4398. return
  4399. endif
  4400. deallocate(DH%DIMTABLE, STAT=stat)
  4401. if(stat/= 0) then
  4402. Status = WRF_HDF5_ERR_DEALLOCATION
  4403. write(msg,*) 'Fatal DEALLOCATION ERROR in ',__FILE__,', line', __LINE__
  4404. call wrf_debug ( FATAL , msg)
  4405. return
  4406. endif
  4407. deallocate(DH%MDDsetIDs, STAT=stat)
  4408. if(stat/= 0) then
  4409. Status = WRF_HDF5_ERR_DEALLOCATION
  4410. write(msg,*) 'Fatal DEALLOCATION ERROR in ',__FILE__,', line', __LINE__
  4411. call wrf_debug ( FATAL , msg)
  4412. return
  4413. endif
  4414. deallocate(DH%MDVarDimLens, STAT=stat)
  4415. if(stat/= 0) then
  4416. Status = WRF_HDF5_ERR_DEALLOCATION
  4417. write(msg,*) 'Fatal DEALLOCATION ERROR in ',__FILE__,', line', __LINE__
  4418. call wrf_debug ( FATAL , msg)
  4419. return
  4420. endif
  4421. deallocate(DH%MDVarNames, STAT=stat)
  4422. if(stat/= 0) then
  4423. Status = WRF_HDF5_ERR_DEALLOCATION
  4424. write(msg,*) 'Fatal DEALLOCATION ERROR in ',__FILE__,', line', __LINE__
  4425. call wrf_debug ( FATAL , msg)
  4426. return
  4427. endif
  4428. deallocate(DH%DsetIDs, STAT=stat)
  4429. if(stat/= 0) then
  4430. Status = WRF_HDF5_ERR_DEALLOCATION
  4431. write(msg,*) 'Fatal DEALLOCATION ERROR in ',__FILE__,', line', __LINE__
  4432. call wrf_debug ( FATAL , msg)
  4433. return
  4434. endif
  4435. deallocate(DH%VarDimLens, STAT=stat)
  4436. if(stat/= 0) then
  4437. Status = WRF_HDF5_ERR_DEALLOCATION
  4438. write(msg,*) 'Fatal DEALLOCATION ERROR in ',__FILE__,', line', __LINE__
  4439. call wrf_debug ( FATAL , msg)
  4440. return
  4441. endif
  4442. deallocate(DH%VarNames, STAT=stat)
  4443. if(stat/= 0) then
  4444. Status = WRF_HDF5_ERR_DEALLOCATION
  4445. write(msg,*) 'Fatal DEALLOCATION ERROR in ',__FILE__,', line', __LINE__
  4446. call wrf_debug ( FATAL , msg)
  4447. return
  4448. endif
  4449. return
  4450. end subroutine free_memory
  4451. subroutine write_hdf5_attributes(DataHandle,MemoryOrder,WrfDType,DimRank,&
  4452. NDim,dset_id,Status)
  4453. use wrf_phdf5_data
  4454. use ext_phdf5_support_routines
  4455. use HDF5
  4456. implicit none
  4457. include 'mpif.h'
  4458. include 'wrf_status_codes.h'
  4459. integer ,intent(in) :: DataHandle
  4460. character*(*) ,intent(in) :: MemoryOrder
  4461. integer ,intent(in) :: WrfDType
  4462. integer,dimension(*) ,intent(in) :: DimRank
  4463. integer ,intent(in) :: NDim
  4464. integer(hid_t) ,intent(in) :: dset_id
  4465. integer ,intent(out) :: Status
  4466. character (3) :: Mem0
  4467. character (3) :: UCMem0
  4468. type(wrf_phdf5_data_handle) ,pointer :: DH
  4469. ! attribute defination
  4470. integer(hid_t) :: dimaspace_id ! DimRank dataspace id
  4471. integer(hid_t) :: dimattr_id ! DimRank attribute id
  4472. integer(hsize_t) ,dimension(1) :: dim_space
  4473. integer(hid_t) :: h5_atypeid ! for fieldtype,memorder attribute
  4474. integer(hid_t) :: h5_aspaceid ! for fieldtype,memorder
  4475. integer(hid_t) :: h5_attrid ! for fieldtype,memorder
  4476. integer(hsize_t), dimension(7) :: adata_dims
  4477. integer :: routine_atype
  4478. integer, dimension(:),allocatable :: dimrank_data
  4479. integer :: hdf5err
  4480. integer :: j
  4481. ! For time function
  4482. real*8 :: timebw
  4483. real*8 :: timeaw
  4484. integer :: total_ele
  4485. !
  4486. ! write dimensional rank attribute. This is the temporary fix for dim. scale
  4487. ! the first dimension is always time
  4488. allocate(dimrank_data(NDim+1))
  4489. do j =1, NDim+1
  4490. dimrank_data(j) = DimRank(j)
  4491. enddo
  4492. dim_space(1) = NDim+1
  4493. adata_dims(1) = NDim+1
  4494. call h5screate_simple_f(1,dim_space,dimaspace_id,hdf5err)
  4495. if(hdf5err.lt.0) then
  4496. Status = WRF_HDF5_ERR_DATASPACE
  4497. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  4498. call wrf_debug ( WARN , msg)
  4499. deallocate(dimrank_data)
  4500. return
  4501. endif
  4502. call h5acreate_f(dset_id,'H5_DimRank',H5T_NATIVE_INTEGER,dimaspace_id, &
  4503. dimattr_id,hdf5err)
  4504. if(hdf5err.lt.0) then
  4505. Status = WRF_HDF5_ERR_ATTRIBUTE_CREATE
  4506. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  4507. call wrf_debug ( WARN , msg)
  4508. deallocate(dimrank_data)
  4509. return
  4510. endif
  4511. call h5awrite_f(dimattr_id,H5T_NATIVE_INTEGER,dimrank_data,adata_dims,hdf5err)
  4512. if(hdf5err.lt.0) then
  4513. Status = WRF_HDF5_ERR_ATTRIBUTE_WRITE
  4514. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  4515. call wrf_debug ( WARN , msg)
  4516. deallocate(dimrank_data)
  4517. return
  4518. endif
  4519. deallocate(dimrank_data)
  4520. ! close space and attribute id
  4521. call clean_phdf5_attrids(H5T_NATIVE_INTEGER,dimaspace_id,dimattr_id,0,Status)
  4522. if(Status.ne.WRF_NO_ERR) then
  4523. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  4524. call wrf_debug ( WARN , msg)
  4525. return
  4526. endif
  4527. ! Write memory order and FieldType attribute, both MemoryOrder and FieldType are 1 element
  4528. adata_dims(1) = 1
  4529. ! output memoryorder attribute
  4530. call reorder(MemoryOrder,Mem0)
  4531. call uppercase(Mem0,UCMem0)
  4532. routine_atype = WRF_CHARACTER
  4533. ! The size of memoryorder string is always MemOrdLen
  4534. call create_phdf5_adtypeid(h5_atypeid,routine_atype,MemOrdLen,Status)
  4535. if(Status.ne.WRF_NO_ERR) then
  4536. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  4537. call wrf_debug ( WARN , msg)
  4538. return
  4539. endif
  4540. ! Count for string attribute is always 1
  4541. call create_phdf5_adspaceid(1,1,h5_aspaceid,Status)
  4542. if(Status.ne.WRF_NO_ERR) then
  4543. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  4544. call wrf_debug ( WARN , msg)
  4545. return
  4546. endif
  4547. call h5acreate_f(dset_id,'MemoryOrder',h5_atypeid,h5_aspaceid, &
  4548. h5_attrid, hdf5err)
  4549. if(hdf5err.lt.0) then
  4550. Status = WRF_HDF5_ERR_ATTRIBUTE_CREATE
  4551. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  4552. call wrf_debug ( WARN , msg)
  4553. return
  4554. endif
  4555. call h5awrite_f(h5_attrid,h5_atypeid,UCMem0,adata_dims,hdf5err)
  4556. if(hdf5err.lt.0) then
  4557. Status = WRF_HDF5_ERR_ATTRIBUTE_WRITE
  4558. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  4559. call wrf_debug ( WARN , msg)
  4560. return
  4561. endif
  4562. call clean_phdf5_attrids(h5_atypeid,h5_aspaceid,h5_attrid,1,Status)
  4563. if(Status.ne.WRF_NO_ERR) then
  4564. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  4565. call wrf_debug ( WARN , msg)
  4566. return
  4567. endif
  4568. ! output fieldtype attribute
  4569. call create_phdf5_adspaceid(1,1,h5_aspaceid,Status)
  4570. if(Status.ne.WRF_NO_ERR) then
  4571. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  4572. call wrf_debug ( WARN , msg)
  4573. return
  4574. endif
  4575. call h5acreate_f(dset_id,'FieldType',H5T_NATIVE_INTEGER,h5_aspaceid, &
  4576. h5_attrid, hdf5err)
  4577. if(hdf5err.lt.0) then
  4578. Status = WRF_HDF5_ERR_ATTRIBUTE_CREATE
  4579. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  4580. call wrf_debug ( WARN , msg)
  4581. return
  4582. endif
  4583. call h5awrite_f(h5_attrid,H5T_NATIVE_INTEGER,WrfDType,adata_dims,hdf5err)
  4584. if(hdf5err.lt.0) then
  4585. Status = WRF_HDF5_ERR_ATTRIBUTE_WRITE
  4586. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  4587. call wrf_debug ( WARN , msg)
  4588. return
  4589. endif
  4590. call clean_phdf5_attrids(H5T_NATIVE_INTEGER,h5_aspaceid,h5_attrid,0,Status)
  4591. if(Status.ne.WRF_NO_ERR) then
  4592. write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
  4593. call wrf_debug ( WARN , msg)
  4594. return
  4595. endif
  4596. end subroutine write_hdf5_attributes