I’m new to using HDF5 directly in Fortran. Up until now I’ve been creating HDF5 files with Flash, the numerical hydro code and reading them with python via the yt package.
Now I want to read some of the datafiles produced by Flash and process them within Fortran code.
To get started I’m trying to do something simple - read a small hdf5 file that I created with python (h5py). The file has 5 groups and several datasets under each group. I’m trying to use h5dread_f to read a dataset and during the compile I’m getting
CALL h5dread_f(dset11_id, H5T_NATIVE_INTEGER, projm, arrdim, error)
Error: There is no specific subroutine for the generic ‘h5dread_f’ at (1)
The arguments to h5dread_f are:
INTEGER(HID_T) :: dset11_id
DOUBLE PRECISION, DIMENSION(5) :: projm
INTEGER(HSIZE_T) :: arrdim
INTEGER :: error
I have to say that I really don’t understand the meaning of the memory datatype identifier argument. Any hints would be appreciated.
Is there an easier way of doing this?
I can’t advise on the specifics of h5dread_f. However, there is a generic explanation for that message "There is no specific subroutine for the generic ‘h5dread_f’. This simply means one or more of your calling arguments differs in type, number of dimensions, or ordering from what is expected by the HDF5 fortran 90 interface, i.e. the module interface.
If you sort out the argument mismatch(es), you might be able to make further progress. HTH.
Okay, I discovered what my problem was. It turns out that the dimensions argument needs to be an array even though it only contains one value. So in the end the call to h5dread_f is:
CALL h5dread_f(dset, H5T_NATIVE_DOUBLE, data, dims, error)
where dset is INTEGER(HID_T), data is a DOUBLE PRECISION array (for me it is a rank 1 array with DIMENSION(5)), dims is declared INTEGER(HSIZE_T) with DIMENSION(1:1) and error is simply decalared INTEGER.
I don’t know how HID_T differs (if it does) from HSIZE_T.
It’d really be nice if somewhere in the docs it was mentioned that the dimensions variable needs to be an array if the data is an array, even if it contains only a single value.
Jon, glad you solved that array vs. scalar problem. That is a basic fortran issue. Unlike some other languages, fortran 90+ does not permit scalar X and array X of size and shape (1) to be equivalent through the calling interface. I have been caught by this too. This even extends to some of the fortran intrinsic procedures that use things like dimension lists.
It would be possible to handle a scalar dimension argument by adding an extra interface to the generic h5dread_f module procedure in the library. There are probably several other HDF5 fortran procedures that could also take the same upgrade. My personal preference is to just get used to this fortran pedantry, because it will keep coming back in other contexts.
I agree, docs for h5dread_f and others should say “dims argument must be array, not scalar”.
One of the reasons we introduced the F2003 interfaces was to end the ever-expanding number of F90 interfaces. Keep in mind that the F90 interfaces need to handle all the different sizes of integers (for example, five kinds), reals (three kinds), characters (one kind) and for each of these kinds you need to support (currently) up to rank seven arrays. If we add a scalar for another argument in the interface we’ve now doubled the number of interfaces. We don’t plan on expanding the F90 interfaces beyond what is currently implemented; they are there for backward compatibility.
It’s best to switch to the Fortran 2003 interfaces, so you don’t need to worry about the dims array, plus F2003 has other advantages such as getting rid of the rank seven limitations.
These fortran documents are next to impossible to find through the newly redesigned documentation. Can you add a few links and references to the new table of contents, and the new interface introductory documentation? Thanks.