Use C preprocessor macros (e.g. version numbers) in Fortran


#1

Hi there,

I am currently working on a Fortran codebase, which uses HDF5 as output file format. The code runs on various machines, from laptops to supercomputers (hence many different compilers, versions of HDF5 etc.). The build system currently in use is make.

In the Fortran code to read the files ouput by the names code, I use h5lget_info_f for querying if a Dataset is present in a file or not.
The API of h5lget_info_fchanged from HDF5-1.10 to HDF5-1.12. My current approach is to use the C preprocessor on the Fortran sources to only enable the call applicable to the HDF5 version in use. However, in the Fortran sources, the version number preprocessor macros defined in H5public.h are not availabe and I cannot simply include H5public.h into the Fortran sources, since it also contains some C source code. So, I wrote a small C program (get_hdf5_version; you can find it on https://github.com/jonathanschilling/get_hdf5_version) to print the HDF5 version numbers. I use this program to define the preprocessor macros H5_VERS_MAJOR etc. in the Makefile.

First question: Is there a more elegant way of solving this issue? Probably we should simply migrate to cmake for a build system, but this is currently not an option.

Second question: Would you like to integrate get_hdf5_version (probably renamed to h5version or similar) into the HDF5 releases? As you can see, it does not have any external dependencies, so it should be relatively easy to do this. Of course this only makes sense if you back-integrate it also into HDF5 versions 1.8 and 1.10 and make new releases there, which then include the utility.

Best regards,
Jonathan Schilling


#2

FYI - H5Lexists may be better than H5Lget_info for checking if an object/link exists.


#3

@koziol Thanks for the hint. I can use this method for now.

@all: How about the remaining issue of using preprocessor macros (e.g. for version numbers) within other programming languages than C?