Hello everyone,
I am trying to read some data from an HDF5 file (rainfall.hdf5), the file is in the link below.
I am compiling my FORTRAN code using Visual Studio Professional 2019 (MVS2019) and IFORT Intel® Fortran Compiler Classic (IntelOneAPI).
The HDF5 version that I am using is HDF5 1.8.1. I included the following directories to my properties in MVS2019: “C:\Program Files\HDF_Group\HDF5\1.8.17 \include\static” and "C:\Program Files\HDF_Group\HDF5\1.8.17\lib My code (inserted below) compiles with no errors.
I am able to open the file (rainfall.hdf5), open the groups ( h5dopen_f) but when I tried to read the data using h5dread_f, the error is equal to -1 and the data is not retrieved from the HDF5 data file.
My code is the following:
use HDF5
use H5FORTRAN_TYPES
IMPLICIT NONE
INTEGER :: error
CHARACTER(LEN=16), PARAMETER :: filename = “rainfall.hdf5”
INTEGER(HID_T) :: file
INTEGER(HID_T) :: dset_id1,dset_id2,dset_id3,dset_id4 !Dataset identifier
INTEGER(HID_T) :: group,group1 !Handles
CHARACTER(LEN=8), PARAMETER :: dsetname = “raincell” !Dataset name
CHARACTER(LEN=8), PARAMETER :: dsetIRAINDUM = “IRAINDUM” !Dataset name
CHARACTER(LEN=8), PARAMETER :: dsetIRINTERS = “IRINTERS” !Dataset name
CHARACTER(LEN=10), PARAMETER :: dsetRAININTIME = “RAININTI” !Dataset name
CHARACTER(LEN=9), PARAMETER :: dsetTIMESTAMP = “TIMESTAM” !Dataset name
INTEGER , PARAMETER :: dim0 = 54310 !Change to NNOD after testing
INTEGER , PARAMETER :: dim1 = 288 !Change to IRINTERS after testing Number of output intervals
INTEGER , PARAMETER :: dim2 = 1 !Change to IRINTERS after testing Number of output intervals
INTEGER(HSIZE_T), DIMENSION(1:3) :: dims = (/dim1,dim0,dim2/)
INTEGER(HSIZE_T), DIMENSION(1) :: dims1 = (/dim2/)
DOUBLE PRECISION, DIMENSION(:,:,:), ALLOCATABLE, TARGET :: rdata4 !Read buffer
INTEGER, DIMENSION(:), ALLOCATABLE, TARGET :: rdata1,rdata2,rdata3 !Read buffer
ALLOCATE(rdata1(1))
ALLOCATE(rdata2(1))
ALLOCATE(rdata3(1))
ALLOCATE(rdata4(dim1,dim0,dim2))
! open the file and edit the values
! Initialize FORTRAN interface.
CALL h5open_f(error)
! Open file. Error = 0 means no issues
CALL h5fopen_f(filename,H5T_NATIVE_DOUBLE, file, error)
! Open group, file is the same variable identifier initialized by the h5open_f() subroutine.
! This gives the HDF5 library the link between the file and the requested group to be opened.
CALL h5gopen_f(file, dsetname, group, error)
!Open an existing dataset IRAINDUM
CALL h5dopen_f(group, dsetIRAINDUM, dset_id1, error)
!Read data IRAINDUM
CALL h5dread_f(dset_id1,H5T_NATIVE_DOUBLE, rdata4, dims, error)
!Open an existing dataset IRINTERS
CALL h5dopen_f(group, dsetIRINTERS, dset_id2, error)
!Read data IRINTERS
CALL h5dread_f(dset_id2,H5T_NATIVE_INTEGER, rdata1, dims1, error)
!Open an existing dataset RAININTIME
CALL h5dopen_f(group, dsetRAININTIME, dset_id3, error)
!Read data RAININTIME
CALL h5dread_f(dset_id3,H5T_NATIVE_INTEGER, rdata2, dims1, error)
!Open an existing dataset TIMESTAMP
CALL h5dopen_f(group, dsetTIMESTAMP, dset_id4, error)
!Read data TIMESTAMP
CALL h5dread_f(dset_id4,H5T_NATIVE_INTEGER, rdata3, dims1, error)
Can someone please help me figure out why h5dread_f doesn’t work?
Thanks!
N