- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am trying to read HDF5 files using Intel Fortran and Visual Studio Community 2017. I have installed the Fortran HDF5 libraries from the HDF5 group. There are many library files sitting in C:\Program Files\HDF_Group\HDF5\1.12.0\lib. I have not attempted to do anything with CMAKE.
I have begun with:
program read_hdf5
integer :: error_flag
C initialise fortran calls
call h5open_f(Error_Flag)
...
which unsurprisingly results in
unresolved external symbol H5OPEN_F referenced in function MAIN__
how do I get it to find the various functions? I presume I need a statement like
USE HDF5
but as far as I know that module file does not exist. How would I make one or otherwise get the program to find the functions?
There is useful advice here https://testsubjector.github.io/blog/2020/09/30/A-Primer-On-HDF5-File-Reading-In-Fortran-90 on reading hdf5 but only after this initial problem is solved.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you very much. I had just managed to do what you suggest and it looks like it is working. The guidance given by the hdf group in USING_HDF5_VS.txt which comes with the installation says more or less the same but not as clearly. It also says the installation needs to match the version of Visual Studio but only mention VS2010 and above so I did not have much confidence.
For other users: you need to figure out whether you want static libraries or not and then find the paths to the directories where the hdf installation has put the relevant .lib and .mod files. In my case they were:
compiler: C:\Program Files\HDF_Group\HDF5\1.12.0\include\static
linker: C:\Program Files\HDF_Group\HDF5\1.12.0\lib
library files: szip.lib zlib.lib libhdf5.lib libhdf5_fortran.lib libhdf5_f90cstub.lib
these lines of fortran now work:
USE HDF5
INTEGER :: ErrorFlag
integer (HID_T) :: hFile, root_id
character*1 rootname
call h5open_f(ErrorFlag)
call h5fopen_f('myhdffile.hdf5'C,H5F_ACC_RDONLY_F,hFile,ErrorFlag)
rootname = "/"
call h5gopen_f(hFile, rootname, root_id, ErrorFlag)
...
The links are helpful - thanks again.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You would have to read the voluminous and scattered documentation to get things to work, but here is how to get past the compile-and-link steps:
- Add "use h5lib" to your source code.
- Add the HDF5 include\shared directory path to %INCLUDE% or use the /I compiler option.
- Add the HDF5 lib directory path to %LIB%
- Compile and link using the command
ifort h5x.f hdf5_fortran.lib szip.lib hdf5_f90cstub.lib hdf5.lib zlib.lib
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks. I don't use the command line version of the compiler. Is it possible to tell me what I would do within Visual Studio? And do I have to follow the instructions for using CMake that came with the hdf installation package? Right now Visual Studio can't find the HDF5 module. Does CMake create that?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
NSwindale wrote: "I don't use the command line version of the compiler. "
Impressions notwithstanding, there is only one compiler, rather than one version for the command line and another for VS, etc.
When you use Visual Studio and modify the project settings and then run a compilation, VS collects the options, forms a command line with the settings rephrased as command line optional arguments, and launches the compiler with those arguments. You have a record of these events in the build log, which you can open and see for yourself.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
you are right I am sure - the same program is being called from different environments. The command string always looks very complicated so I much prefer VS to take care of it. I am sure there are ways around this but I prefer not to go that route. I had enough of it in the days of DOS.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@NSwindale wrote:
I am trying to read HDF5 files using Intel Fortran and Visual Studio Community 2017. I have installed the Fortran HDF5 libraries from the HDF5 group. There are many library files sitting in C:\Program Files\HDF_Group\HDF5\1.12.0\lib. I have not attempted to do anything with CMAKE.
I have begun with:
program read_hdf5
integer :: error_flagC initialise fortran calls
call h5open_f(Error_Flag)
...which unsurprisingly results in
unresolved external symbol H5OPEN_F referenced in function MAIN__
how do I get it to find the various functions? I presume I need a statement like
USE HDF5
but as far as I know that module file does not exist. How would I make one or otherwise get the program to find the functions?
There is useful advice here https://testsubjector.github.io/blog/2020/09/30/A-Primer-On-HDF5-File-Reading-In-Fortran-90/ on reading hdf5 but only after this initial problem is solved.
No, CMake cant create that for you. It will be done through command line.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have found the file HDF5.MOD. How do I tell Visual Studio (2017) where to find it? And the hdf5 libraries? I tried putting these directories on the Windows PATH and rebooted but it still could not find them.
it is really helpful to know I don't have to bother with CMake - thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Within Visual Studio, the place to specify where to search for Fortran modules for a project is under the project Configuration Property (right click on the project name in the solution explorer and select Properties) Fortran > General > Additional Include Directories.
You will also need to specify the location and names of the relevant HDF5 libraries in the project properties under Linker > General > Additional Library Directories and Linker > Input > Additional Dependencies. The additional libraries to be specified will depend on the HDF5 features that you are using and whether you are doing a debug or release build (these properties need to be specified for each build configuration), but might be something like "szip.lib zlib.lib hdf5.lib hdf5_fortran.lib hdf5_hl_fortran.lib hdf5_hl.lib"
The documentation for the Intel Fortran compiler contains further information on how to use the compiler from within Visual Studio. The description for relevant compiler command line options also describing the equivalent project property (e.g. for the include path). For linker related options refer to the relevant Microsoft documentation.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you very much. I had just managed to do what you suggest and it looks like it is working. The guidance given by the hdf group in USING_HDF5_VS.txt which comes with the installation says more or less the same but not as clearly. It also says the installation needs to match the version of Visual Studio but only mention VS2010 and above so I did not have much confidence.
For other users: you need to figure out whether you want static libraries or not and then find the paths to the directories where the hdf installation has put the relevant .lib and .mod files. In my case they were:
compiler: C:\Program Files\HDF_Group\HDF5\1.12.0\include\static
linker: C:\Program Files\HDF_Group\HDF5\1.12.0\lib
library files: szip.lib zlib.lib libhdf5.lib libhdf5_fortran.lib libhdf5_f90cstub.lib
these lines of fortran now work:
USE HDF5
INTEGER :: ErrorFlag
integer (HID_T) :: hFile, root_id
character*1 rootname
call h5open_f(ErrorFlag)
call h5fopen_f('myhdffile.hdf5'C,H5F_ACC_RDONLY_F,hFile,ErrorFlag)
rootname = "/"
call h5gopen_f(hFile, rootname, root_id, ErrorFlag)
...
The links are helpful - thanks again.
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page