Fortran module file format
The Fortran standard does not define a specific Fortran module file format. Each compiler vendor has a unique incompatible Fortran module file format. Fortran module files are not portable between different compilers or even different versions of the same compiler.
The per-compiler examples below assume Fortran source file “example.f90”:
module dummy
real, parameter :: pi = 4*atan(1.0)
contains
real function tau()
tau = 2*pi
end function tau
end module dummy
Flang-new (LLVM)
The flang-f18 or flang-new LLVM Fortran .mod files generated are legal Fortran syntax – they are text files. The .mod format gives the version number.
Build:
gfortran -c example.f90
This generates Fortran module file “dummy.mod” and object file “example.o”.
Get the .mod file header:
head -n1 dummy.mod
The output starts like:
!mod$ v1
GNU Fortran (GFortran)
The GFortran header version is defined in module.cc as variable “MOD_VERSION”. GNU Fortran “gfortran” .mod files are GZIP and is not documented
GCC version | module file version |
---|---|
15.x | 16 |
8.x - 14.x | 15 |
5.1.0 | 14 |
4.9.2 | 12 |
4.8.1 | 10 |
4.7.1 | 9 |
Build a Fortran module source file like:
gfortran -c example.f90
This generates Fortran module file “dummy.mod” and object file “example.o”.
Extract the .mod file header like:
gunzip -c dummy.mod | head -n1
The output starts like:
GFORTRAN module version ‘15’ created from …
If you get:
gzip: not in gzip format
the .mod file is probably from another compiler vendor e.g. Intel oneAPI.
Intel oneAPI (ifx)
Intel oneAPI .mod files are a proprietary binary format. It is possible to determine the version of the .mod file by using od to look at the first 2 bytes of the .mod file.
od -N4 -d dummy.mod
The first number is like “13” and is the module format version. This version may change over time as oneAPI internals change. The second number is the update version, which is fixed at “1”.
NVHPC and AOCC
NVIDIA HPC SDK (NVHPC) and AOCC compilers generate .mod files that are text files. The format for legacy Flang module files is distinct than flang-new Fortran module files.
Create the .mod file like:
nvfortran -c example.f90
# or
flang -c example.f90
generates a text file, beginning with the version number.
head -n1 dummy.mod
the output is like:
V34 :0x24 dummy
Cray Fortran
By default, Cray Fortran stores uppercase DUMMY.mod filenames.
This can be made lowercase witht the ftn -ef
flag.
The
Cray Fortran .mod format
is proprietary, but the version number might be seen like:
ftn -c example.f90
head -n2 DUMMY.mod
Related: Fortran submodule file naming