Fortran compiler standard enforce
Fortran compilers typically have options for enforcing Fortran standards.
The compilers raise additional warnings or errors for code that is not deemed compliant.
Fortran standard options can make false warnings, so we generally do not enable standards checking for user defaults.
However, we do enforce implicit none as a quality measure.
It’s also important to use implicit none so that each variable must be assigned beforehand.
We recommend the Fortran 2018 statement:
implicit none (type, external)which requires explicitly defined procedure interfaces as well.
- type
- the traditional implicit nonedefault
- external
- new for Fortran 2018, requires explicit interface for external procedures.
GCC Gfortran -std=f2018 enforces Fortran 2018 standard. Consider these Gfortran options:
gfortran -Wall -fimplicit-noneIntel oneAPI
-stand f18
enforces Fortran 2018 standard.
Consider these
options
that also enforce implicit none:
ifx -warnCray Fortran compiler enforces implicit none via
option:
ftn -eInote that’s a capital “I” not a lowercase “ell”.
Nvidia HPC Fortran compiler enforces implicit none via:
nvfortran -MdclchkNAG Fortran has
-f2018
Fortran 2018 flag.
Enforce implicit none by:
nagfor -uCMake logic to enforce these standards:
if(CMAKE_Fortran_COMPILER_ID STREQUAL "Cray")
  add_compile_options("$<$<COMPILE_LANGUAGE:Fortran>:-eI>")
elseif(CMAKE_Fortran_COMPILER_ID STREQUAL "GNU")
  add_compile_options(-Wall "$<$<COMPILE_LANGUAGE:Fortran>:-fimplicit-none>")
elseif(CMAKE_Fortran_COMPILER_ID MATCHES "^Intel")
  add_compile_options("$<$<COMPILE_LANGUAGE:Fortran>:-warn>")
elseif(CMAKE_Fortran_COMPILER_ID STREQUAL "NVHPC")
  add_compile_options("$<$<COMPILE_LANGUAGE:Fortran>:-Mdclchk>")
elseif(CMAKE_Fortran_COMPILER_ID STREQUAL "NAG")
  add_compile_options("$<$<COMPILE_LANGUAGE:Fortran>:-u>")
endif()