Fortran compiler flags for legacy code
To compile legacy Fortran code, certain compiler flags can be used to enable non-standard Fortran syntax that was common before the Fortran 95 standard became widely adopted. It’s hard to pin an exact year for when developers transitioned to more standard Fortran code, but the mid-2000s is a reasonable estimate for when Fortran codebases started to modernize in significant numbers. Gfortran took over from g77 as the default Fortran compiler circa 2005 and was the first widely used free Fortran compiler capable of the Fortran 95 standard. Here are legacy-enabling flags for currently maintained Fortran compilers.
In addition to the flags below, it may be necessary to provide default real and / or integer precision flags to compile old code that relies on the default precision being different than the modern default of 4 bytes for real and 4 bytes for integer.
GNU GFortran
-std=legacyenables pre-Fortran 77 arbitrary length arrays, whereA(1)was declared instead ofA(*)in Fortran 77 orA(:)in modern Fortran.- -fdec- options enable various non-standard extensions in the DEC Fortran style.
- see also Gfortran runtime options for issues reading binary files.
LLVM Flang
Flang compiler flags have a “-std” option that might be checked to see if the project sets it too restrictively.
Intel oneAPI
- -nostand does not change compiler behavior–it disables standard-based warnings.
- -f66 apples Fortran 66 semantic rules, including Do loops that always run at least once.
IBM OpenXL
- -qlanglvl=extended disables compiler language level checks, and is the default.
- several more options may be employed if needed for compatibility
Cray Fortran
The ftn compiler
can disable some checks with flags like -d C