HDFql Reference Manual v2.6.0

3.6Fortran

HDFql can be used in the Fortran programming language through a shared library, which is stored in the directory “fortran” found under the directory “wrapper”. The following short program illustrates how HDFql can be used in this language.

PROGRAM Example
    ! use HDFql module (make sure it can be found by the Fortran compiler)
    USE HDFql

    ! declare variable
    INTEGER :: state

    ! display HDFql version in use 
    WRITE(*, *) "HDFql version: ", HDFQL_VERSION

    ! create an HDF5 file named "my_file.h5" and use (i.e. open) it 
    state = hdfql_execute("CREATE AND USE FILE my_file.h5")

    ! create an HDF5 dataset named "my_dataset" of data type int 
    state = hdfql_execute("CREATE DATASET my_dataset AS INT VALUES(10)") 

    ! select (i.e. read) data from dataset "my_dataset" and populate cursor in use with it 
    state = hdfql_execute("SELECT FROM my_dataset") 

    ! move cursor in use to the first position within the result set 
    state = hdfql_cursor_first() 

    ! display content of cursor in use
    WRITE(*, *) "Dataset value: ", hdfql_cursor_get_int()
END PROGRAM

Assuming that the program is stored in a file named “example.f90”, it must first be compiled before it can be launched. To compile the program against the HDFql Fortran shared library, execute the following command in a terminal:

  • On Windows using Intel IFX:
    ifx.exe example.f90 /module:<hdfql_ifx_fortran_wrapper_directory> <hdfql_ifx_fortran_wrapper_directory>\HDFql_dll.lib
  • On Linux using Intel IFX:
    • With an HDFql non MPI-based distribution:
      ifx example.f90 -module <hdfql_ifx_fortran_wrapper_directory> -L<hdfql_ifx_fortran_wrapper_directory> -lHDFql
    • With an HDFql MPI-based distribution:
      ifx example.f90 -module <hdfql_ifx_fortran_wrapper_directory> -L<hdfql_ifx_fortran_wrapper_directory> -L<mpi_lib_directory> -lHDFql -lmpi
  • On Linux and macOS using GCC8:
    • With an HDFql non MPI-based distribution:
      gfortran example.f90 -I<hdfql_gcc_fortran_wrapper_directory> -L<hdfql_gcc_fortran_wrapper_directory> -lHDFql -ldl
    • With an HDFql MPI-based distribution:
      gfortran example.f90 -I<hdfql_gcc_fortran_wrapper_directory> -L<hdfql_gcc_fortran_wrapper_directory> -L<mpi_lib_directory> -lHDFql -lmpi -ldl

In case the program does not compile, check whether a Fortran compiler is installed. If a Fortran compiler is missing, the solution is:

In case the compiled program does not launch, it is most likely the HDFql Fortran shared library and/or the MPI shared library were not found (these are needed to launch the program). The solution is:

  • On Windows, add the directory where the file “HDFql_dll.dll” is located to the environment variable “PATH” by executing the following command in a terminal:
    set PATH=<hdfql_fortran_wrapper_directory>;%PATH%
  • On Linux, add the directories where the files “libHDFql.so” and (optionally) “libmpi.so” are located to the environment variable “LD_LIBRARY_PATH” by executing the following command in a terminal:
    • With an HDFql non MPI-based distribution:
      export LD_LIBRARY_PATH=<hdfql_fortran_wrapper_directory>:$LD_LIBRARY_PATH
    • With an HDFql MPI-based distribution:
      export LD_LIBRARY_PATH=<hdfql_fortran_wrapper_directory>:<mpi_lib_directory>:$LD_LIBRARY_PATH
  • On macOS, add the directories where the files “libHDFql.dylib” and (optionally) “libmpi.dylib” are located to the environment variable “DYLD_LIBRARY_PATH”9 by executing the following command in a terminal:
    • With an HDFql non MPI-based distribution:
      export DYLD_LIBRARY_PATH=<hdfql_fortran_wrapper_directory>:$DYLD_LIBRARY_PATH
    • With an HDFql MPI-based distribution:
      export DYLD_LIBRARY_PATH=<hdfql_fortran_wrapper_directory>:<mpi_lib_directory>:$DYLD_LIBRARY_PATH

Notes

  1. An incorrect warning is raised by the GCC Fortran compiler when using the HDFql module (“Warning: Only array FINAL procedures declared for derived type 'hdfql_cursor' defined at (1), suggest also scalar one”). This warning does not interfere with the final compilation result, though, and it was resolved in the GCC Fortran compiler version 7.0.0 (please refer to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58175 for additional information). ↩
  2. Starting with version 10.11 (i.e. El Capitan), Apple introduced a security feature named System Integrity Protection (SIP) that may prevent setting the environment variable “DYLD_LIBRARY_PATH” and, ultimately, launching the program. To overcome this, SIP should be disabled (please refer to https://developer.apple.com/library/archive/documentation/Security/Conceptual/System_Integrity_Protection_Guide/ConfiguringSystemIntegrityProtection/ConfiguringSystemIntegrityProtection.html for additional information). ↩