Errors compiling code with h5dread_f

Hi,

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)
1
Error: There is no specific subroutine for the generic ‘h5dread_f’ at (1)
read_grash_inputs.F90:74.69:

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?

Regards,
Jon

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.

Here is an example of how to write/read double precision using both the F90 and F2003 interfaces.

h5ex_t_dble_F03.f90 (3.1 KB)

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.

Regards,
Jon

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.

@brtnfld, I guess I’m ignorant of the new F2003 interface. Please point me to the documentation. I have been through the docs table of contents a few times, and could not find it.

Hmmm, it appears that some of the F2003 interfaces (for example H5Dread_f) did not make it into the newly redesigned documentation:

https://portal.hdfgroup.org/display/HDF5/H5D_READ

and the H5D_Write interface does not label it as the F2003 interface (it’s the last API example BTW).

You can reference the older documentation pages which have the F2003 interfaces labeled.

https://support.hdfgroup.org/HDF5/doc/RM/RM_H5D.html#Dataset-Read

Sorry for the confusion.

@brtnfld, thanks for those pointers. There is also a wealth of general information about the fortran 90 and 2003 interfaces, and their differences, in older introductory documents:

https://support.hdfgroup.org/HDF5/doc/fortran/index.html

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.

The Fortran documentation is now on the Support Portal, and the Fortran 2003 interface signatures were added to H5Dread and H5Dwrite:


https://portal.hdfgroup.org/display/HDF5/H5D_READ
https://portal.hdfgroup.org/display/HDF5/H5D_WRITE

Thanks!
-Barbara
help@hdfgroup.org

Barbara et al, that looks good. Thanks for getting the Fortran documentation organized and prominent.