Introduction
Fortran is the compiled language developed at IBM by a team led by John Backus and first released in 1957. It remains in use for scientific and numerical computing. The language is an ISO standard, revised as Fortran 90, 95, 2003, 2008, 2018 and 2023.
The extension tells the compiler how the source is laid out, not which version of the
language it uses. .f, .for, .f77 and
.ftn mean fixed form, the punched-card layout of early Fortran.
.f90, .f95, .f03 and .f08 mean free
form. On Linux and macOS a capital letter, as in .F or .F90,
usually asks the compiler to run the C preprocessor first.
.f is also used for Forth source by some Forth systems.
Structure
A Fortran file is plain text, and the language ignores case. A file holds program
units: one program and any number of module,
subroutine and function units, each closed by
end.
In fixed form, position on the line has meaning:
- column 1:
C,cor*makes the line a comment - columns 1 to 5: an optional statement label, a number
- column 6: any character except a space or zero continues the previous line
- columns 7 to 72: the statement
- columns 73 and beyond: ignored, once used for card sequence numbers
PROGRAM HELLO
C Statements start in column 7.
INTEGER I
DO 10 I = 1, 3
WRITE (*,*) 'HELLO', I
10 CONTINUE
END
In free form, statements can start anywhere on a line of up to 132
characters (10,000 in Fortran 2023). Comments start with !, and a line ending in
& continues on the next.
program hello
implicit none
integer :: i
do i = 1, 3
print *, 'Hello', i ! one line for each pass
end do
end program hello
Links
Software
- GNU Fortran –
gfortran, the free compiler in GCC (Windows, macOS, Linux) - Intel Fortran Compiler – Intel’s
ifxcompiler (Windows, Linux) - Flang – the Fortran compiler in the LLVM project (Linux, macOS, Windows)
- fpm – the Fortran Package Manager (Windows, macOS, Linux)
Developers
- fortls – language server for Fortran (Python)
- tree-sitter-fortran – Fortran grammar for the Tree-sitter parser used by editors
Reference
- Fortran-lang – community site with tutorials and documentation
- WG5 – the ISO working group that maintains the standard
- GNU Fortran manual – how
gfortrantreats each extension and source form - ISO/IEC 1539-1 – the international standard for Fortran