For decades, Fortran code was written in fixed source format, with reserved areas for statement labels and indentification fields, caused by the fixed form of Hollerith punch cards. That means, the first six characters of each line are reserved for line numbers, comment identifiers, continuation characters, and so on. Lines were limited to 72 characters.
With Fortran 90, free source format was introduced, which abolished indention patterns and improved readability (tab. 1). Since Fortran 95, fixed source format is declared obsolescent.
c Example in fixed format. program f2c implicit none real :: c, f print *, ' Fahrenheit Celsius' print *, '--------------------------' c Output table: do f = 30, 220, 10 c = (5.0 / 9.0) * (f - 32.0) print '(f13.1, f12.3)', f, c end do end program f2c
! Example in free format. program f2c implicit none real :: c, f print *, ' Fahrenheit Celsius' print *, '--------------------------' ! Output table: do f = 30, 220, 10 c = (5.0 / 9.0) * (f - 32.0) print '(f13.1, f12.3)', f, c end do end program f2c
- Table 1: Fortran source code in old fixed-format (left) and modern free-format (right)
Modern Fortran compilers provide command-line flags in order to distinguish
between the old fixed format and the new free format. Use
-ffree-form to force free format with GNU Fortran:
$ gfortran9 -ffree-form -o foo foo.f
Same with Flang:
$ flang -ffree-form -o foo foo.f
Historically, the file endings of Fortran source files are
.for. These are associated with Fortran < 90, and therefore
with fixed format. Even modern compilers assume fixed format for them, unless a
free format command-line flag is used.
For this reason, file endings should be used that represent modern Fortran
versions. You can either set endings that correspond with the actual language
.f03 for 2003,
.f08 for 2008,
.f18 for 2018) or simply use
.f90 as a default to
indicate modern Fortran. The latter is recommended. Be aware that you must set
the file endings to either
.f95 to be
recognised by CMake.
|< Editors and IDEs||[Index]||Compilation >|