ZetCode

Fortran tutorials

Fortran is a compiled, statically typed language for numerical and scientific computing. It was created at IBM in the 1950s, which makes it the oldest high-level language still in everyday use, and it has been revised many times since: FORTRAN 66 and 77, Fortran 90, 95, 2003, 2008, 2018, and 2023. Modern Fortran has modules, derived types, object-oriented features, whole-array operations, and built-in parallel constructs, and it remains the language of many weather and climate models, physics codes, and numerical libraries.

E-books

Fortran is built around arrays: whole arrays can be added, multiplied, sliced, and passed to procedures as single values, and the compiler optimises them for speed. Numbers come in several kinds, so a program states the precision it needs and gets the same result on every compiler. Procedures are collected in modules, which give the compiler the information it needs to check every call.

The examples are compiled and run with gfortran, the Fortran front end of the GNU Compiler Collection (version 13.2). The tutorials use free-form source in .f90 files, write implicit none in every program, and compile with -std=f2018 -Wall -Wextra -fcheck=all. Each article is self-contained, and every example is run before its output is shown.

Language basics

Program structure, variables, types and kinds, operators, flow control, procedures, and modules.

Arrays and strings

Whole-array operations, array intrinsics, allocatable arrays, and text processing.

Input, output, and files

Formatted output, reading input, text and binary files, namelists, and CSV data.

Derived types and data structures

Derived types, object-oriented features, pointers, and linked data structures.

Algorithms

Recursion, sorting, searching, and procedures passed as arguments.

Numbers and precision

Complex numbers, bits, IEEE floating point, arbitrary precision, and random numbers.

Numerical and parallel computing

Integration, root finding, linear algebra, simulations, do concurrent, OpenMP, and coarrays.

System and interoperability

Date and time, command-line arguments, environment, error handling, and calling C.

Tools, legacy code, and standards

Compiling, debugging, testing, style, FORTRAN 77, and the history of the standards.

last modified November 18, 2026