【发布时间】:2016-01-24 06:06:49
【问题描述】:
我有一个非常大的 HDF5 文件,并希望使用 FORTRAN 读取其中的一小部分。到目前为止,我的尝试都失败了,我对文档感到困惑。 您可以给 FORTRAN 新手(但合理的 C/python 编码器)的任何指针将不胜感激。
特别是我很难理解数据空间和内存空间是什么,在我的代码中,根据我阅读的文档,它们似乎没有按照我的预期做。不过,这可能是我自己的白痴!
这就是我正在尝试的:
integer, allocatable :: tmpdata(:,:) ! Array to contain data subset
integer(HID_T) :: fid ! HDF5 File ID
integer(HID_T) :: did ! Dataset ID
integer :: error ! Error variable
integer(HSIZE_T), dimension(1:2) :: count ! Number of px to read (x,y)
integer(HSIZE_T), dimension(1:2) :: offset ! Starting point for read (x,y)
integer(HID_T) :: dataspace ! Dataspace
integer(HID_T) :: memspace ! Memoryspace
offset=(/58000,22000/) ! Set offset in 2d dataset
count=(/1200,1200/) ! Set # pixels to read (1200x1200 slab)
allocate(tmpdata(1200,1200)) ! Allocate space to store this slab
call h5open_f(error)
call h5fopen_f ("myfile.h5", H5F_ACC_RDWR_F, fid, error) ! Open HDF5 file
call h5dopen_f(fid, "mydataset", did, error) ! Open dataset
call h5dget_space_f(did, dataspace, error) ! Retrieve dataspace
call h5screate_simple_f(2, count, memspace, error) !Create memspace, rank=2,size=1200x1200
call h5sselect_hyperslab_f(dataspace, H5S_SELECT_SET_F, offset, count, error) ! Select slab in the data
call h5dread_f(did, H5T_NATIVE_INTEGER, tmpdata, dimsm, error,memspace,dataspace) ! Read the data from the HDF5 file into the tmpdata array
! Close everything
-snip-
在调用 h5dread_f 之前一切正常。然后我得到一个段错误。如果我将 tmpdata 设置为等于 HDF5 文件中实际数据集的大小,那么它可以工作,但这不是一个好的解决方案,因为对于某些文件,数据集太大而无法存储在内存中。 有任何想法吗?希望我只是在做一些愚蠢的事情。如果这很重要,我将在 Ubuntu 14.04 上使用 ifort 和 HDF5-1.8.15 Patch 1 进行编译
【问题讨论】:
-
dimsm是如何声明的? -
是
dimsm和integer(HSIZE_T) :: dimsm(2)的值[1200, 1200]?
标签: fortran fortran90 hdf5 intel-fortran