Using the IMAS-Fortran

Making the IMAS-Fortran available for use

When you’re working with a local installation (see the building and installation documentation), you can source the installed environment file:

Set environment variables (replace <install_dir> with the folder of your local install)
source <install_dir>/bin/al_env.sh

Using the Access Layer with your Fortran program

The following example program will load the Fortran interface to the Access Layer to print the version of the access layer and data dictionary.

imas_hello_world.f90
program imas_hello_world
    ! Make the Access Layer available
    use ids_routines
    implicit none

    character, pointer, dimension(:) :: al_version

    call al_get_version(al_version)

    write(*,*) 'Hello world!'
    write(*,*) 'Access Layer version info:'
    write(*,*) '  Low level version: ', al_version
    write(*,*) '  Data Dictionary version: ', al_dd_version
    write(*,*) '  Fortran HLI version: ', al_fortran_version

end program imas_hello_world

If you save this as a file imas_hello_world.f90, you can compile it as follows:

# gfortran compiler
gfortran imas_hello_world.f90 `pkg-config --libs --cflags al-fortran` -o imas_hello_world
# ifort compiler
ifort imas_hello_world.f90 `pkg-config --libs --cflags al-fortran` -o imas_hello_world

We use pkg-config to output the required libraries and compiler flags to use the Fortran Access Layer. You should use the same compiler as was used for compiling the Access Layer (gfortran for the foss IMAS modules on SDCC, ifort for the intel IMAS modules on SDCC). If you don’t, the compiler will generate an error message, for example This module file was not generated by any release of this compiler.   [IDS_ROUTINES]

When the compilation is successful, a program imas_hello_world was compiled for you. When you execute it, the result is:

$ ./imas_hello_world
 Hello world!
 Access Layer version info:
   Low level version: 5.0.0
   Data Dictionary version: 3.39.0
   Fortran HLI version: 5.0.0

Congratulations if this runs successfully! You have included the Fortran Access Layer successfully in a program. In the next sections of the documentation you can see how to: