Fortran basics: what the language is and where it is used
What Fortran is
Fortran is a compiled language for numerical work: it speaks arrays, complex
numbers and floating point as its first language, and the compiler turns a
readable source file into machine code that runs directly on the processor.
The name comes from Formula Translation. The language dates from 1957 and
is still developed: the current standards are Fortran 2008, 2018 and 2023,
and this site teaches the modern free form style, not the fixed form of
old listings.
Modern Fortran - modules, derived types, coarrays, DO CONCURRENT - is a
different language from the fixed-form folklore.
Where Fortran is used
Fortran powers weather models, fluid dynamics, and half the
supercomputers on Earth. Climate codes, computational chemistry, finite
element packages and engineering simulations are still written in it,
because decades of tuned libraries are hard to replace.
It runs on all common systems: Linux on clusters and
servers, macOS and Windows on the desktop. The free
gfortran compiler comes with the C toolchain on every
one of them, so the same standard source builds almost everywhere.
Hello world
A complete program is short: a program line, implicit none, one print, and the end line. Save it as hello.f90, compile it, and run the binary.
program hello
implicit none
print *, "Hello, Fortran"
end program hello
gfortran -Wall -Wextra -std=f2018 hello.f90 -o hello
./hello
Hello, Fortran
The implicit none line is not decoration: it turns off the old rule that guessed the type of an undeclared name from its first letter, and it makes the compiler report every typo in a variable name.
The course
The full course takes you from this program to parallel coarrays and two
capstone projects, one idea per lesson:
Fortran course: zero to hero in 50 lessons.
Every lesson ends with a link to the next one, and the course index shows
all fifty lessons grouped by topic, so you can read it start to finish or
jump to the part you need.
The code on this page was run with gfortran 15.2.0 on Alpine Linux 3.24 (x86_64) in a Docker container.
Article author: Arthur Isaev