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 fc_table IMPLICIT NONE REAL :: f REAL :: c 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 fc_table
! Example in free format. program fc_table implicit none real :: f real :: c 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 fc_table
- Table 1: Fortran source code in fixed source format (left) and free source 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:
$ gfortran7 -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 ending to either
.f95 if you like to build your Fortran projects with
|< Editors and IDEs||[Index]||Libraries >|