【发布时间】:2019-11-15 19:02:09
【问题描述】:
我无法使用 Fortran 读取一组 HDF5 文件的成员数据集。
我可以列出我的 HDF5 组的成员。但是我无法访问组中成员的数据,
program sds_info
use hdf5
implicit none
! Variables declaration
CHARACTER*100 :: file_name
CHARACTER*100 :: sds_name
CHARACTER*100 :: gr_name
INTEGER(HID_T):: file_id, gr_id, dset_id, attr_id
INTEGER :: status, error, storage, nlinks,max_corder, attr_num
REAL, DIMENSION(1) :: dset_data, data_out
INTEGER, DIMENSION(1) :: buf
INTEGER(HSIZE_T), DIMENSION(1):: data_dims
INTEGER(HSIZE_T), DIMENSION(1) ::dims
!
! varaibles to read a dataset in a group
CHARACTER*100 :: ap_name
integer(HID_T):: ap_id
real, allocatable, dimension(:) :: ap
integer(HSIZE_T), dimension(15624960) :: ap_dim
integer :: nmembers ! Number of group members
CHARACTER(LEN=20) :: name_buffer ! Buffer to hold object's name
integer :: i
integer :: type
!
! Variables initalization
file_name = "PVAR8.h5"
sds_name = "time"
gr_name = "part"
attr_name = "attr1"
ap_name="ap"
! Initialize the interface
call h5open_f(status)
! Open an hdf5 file
call h5fopen_f(file_name, H5F_ACC_RDWR_F, file_id, status)
! Open a group
call h5gopen_f(file_id, gr_name, gr_id, status )
!
! Open a dataset
call h5dopen_f(file_id, sds_name, dset_id, error)
! Get the number of attributes
call h5aget_num_attrs_f(dset_id, attr_num, error)
print *, "attr_num ",attr_num
! Read the dataset
call h5dread_f(dset_id, H5T_NATIVE_REAL, data_out, data_dims, error)
print *, "data_out ",data_out
! Terminate access to the group
call h5gclose_f(gr_id, error)
! Terminate access to the dataset
call h5dclose_f(dset_id, error)
! Terminate access to the file
call h5fclose_f(file_id, error)
! Close FORTRAN interface.
call h5close_f(status)
end program sds_info
我可以读取组,但如何使用 Fortran 在 HDF5 中访问和读取组成员的数据?
【问题讨论】:
-
程序在什么时候没有按预期工作?程序的错误信息和/或输出是什么?