Fortran Reference

This content was generated with the assistance of AI and should be verified against the official documentation before being relied on in production.

The reference material consulted while preparing these pages is listed in the section bibliography.

This section is written against Fortran 2023 (ISO/IEC 1539-1:2023, read in its final draft J3/23-007r1), the current published standard. Its first corrigendum (2026) is a bug-fix document and changes no feature used here, and Fortran 2028 is only a work in progress: the committee draft stage has been reached and nothing in the section depends on it, but the preview page says what is coming. Every program was compiled and run on 2026-10-18 with GNU Fortran 16.2 (-std=f2023 -Wall -Wextra -pedantic -fimplicit-none -fcheck=all) and, where a page says so, with LLVM Flang 23; Intel ifx 2026.1 and the other commercial compilers are described from their manuals, because they were not available for testing. The tools around the language are at fpm 0.13.0, stdlib 0.8.1, fortls 3.2.2 and test-drive 0.6.1, with OpenMP 6.0, OpenACC 3.4 and MPI 5.0 as the parallel specifications. Features newer than Fortran 2008 are marked with the standard that introduced them, and the pages say which compilers do not accept them yet.

What Fortran is

Fortran (FORmula TRANslation) is the oldest high-level programming language still in wide use: the first compiler shipped for the IBM 704 in 1957. It is a compiled, statically typed, array-oriented language that ISO/IEC standardizes, designed so that a compiler can turn mathematical formulas over large arrays into fast machine code. That is why weather and climate models, computational fluid dynamics, quantum chemistry, astrophysics and many numerical libraries are written and still being extended in it.

Modern Fortran is far from the punched-card language of its reputation. Since Fortran 90 it has free-form source, modules, whole-array expressions and dynamic memory with allocatable; later revisions added derived types with type-bound procedures and polymorphism (Fortran 2003), coarrays and do concurrent (2008), teams, events and collectives (2018) and, in 2023, conditional expressions, rank-independent code, enumeration types and the split and tokenize string intrinsics. Parallelism is part of the language through coarrays and do concurrent, and OpenMP, OpenACC and MPI have first-class Fortran bindings. Compilers include GNU Fortran, LLVM Flang, Intel ifx, NAG, the HPE Cray and NVIDIA compilers; the community maintains the Fortran Package Manager (fpm), a standard library (stdlib), a language server (fortls) and a documentation generator (FORD).

The heatflow scenario

The examples across the section share one small, original, numerical domain: heatflow, a solver for heat diffusion on a rectangular plate, organised as an fpm project (fpm.toml, src/, app/, test/ and example/). Fortran is used where numbers are the point, so, unlike the Rust, Go and Ruby references, it deliberately does not use the shelf library catalogue.

  • heatflow_kinds defines the dp kind from iso_fortran_env, and heatflow_constants the defaults.

  • grid_t is a derived type holding the sizes, the spacing and an allocatable temperature field u(:,:), with a constructor function.

  • The boundary condition (dirichlet, neumann, periodic) is an enumeration; the enum, bind(c) form is the one the compilers accept today.

  • An abstract solver_t with a deferred step binding is extended by jacobi_solver_t and ftcs_solver_t, implemented in submodules, with a final procedure.

  • A run configuration is read from a namelist file, and results are written as CSV and as unformatted stream files, with defined derived-type I/O for grid_t.

  • Parallel variants of the stencil use do concurrent (with reduce for the residual), OpenMP, a coarray halo exchange across images and an mpi_f08 domain decomposition.

  • A bind(c) C API, a C client, a Python wrapper built with f2py and Meson and a MATLAB MEX gateway call the same kernel.

  • Tests with test-drive, a CMake build next to the fpm build and FORD documentation grow alongside the code.

The pages build on each other, and the comparison page maps heatflow concepts to the C and the Python and Rust references. The cheat sheet summarises the whole section.

New here? Read in this order

Then pick topics as you need them and keep the cheat sheet at hand. If you know older Fortran, start with Legacy Features and Modernization and What’s New and Fortran 2028 Preview; if you come from another language, start with Fortran for Programmers of Other Languages.

mindmap root((Fortran Reference)) Getting started Toolchain and standards Differences from other languages Core language Types and kinds Expressions and control flow Procedures Modules and submodules Arrays Sections and column-major order Allocatables Assumed shape and rank Array intrinsics Data Characters Pointers Derived types Object orientation Input and output Units and files Edit descriptors Namelist Numerics Intrinsics IEEE arithmetic Errors Parallel Coarrays do concurrent OpenMP and OpenACC MPI Interoperability C and C descriptors C++ and Python MATLAB Tooling Compilers fpm and stdlib CMake and Meson Testing and documentation Practice Best practices Gotchas Performance Legacy and Fortran 2028

What’s covered

Getting started

Page What it covers

Getting Started

what Fortran is used for, installing a compiler, Hello world, file extensions and module files, a first fpm project and reading diagnostics

History, Standards and Compilers

from FORTRAN I (1957) to Fortran 2023, WG5 and J3, conformance, the compiler landscape

Fortran for Programmers of Other Languages

the differences that surprise newcomers, mapped to C, Python and Rust

IDEs & Tools

the IDEs, editors and tools commonly used for Fortran, with links to the official pages

Core language

Page What it covers

Program Structure and Source Form

program units, scoping units, statement order, tokens, free source form and the F2023 line limits

Intrinsic Types and Kinds

the five intrinsic types, kind parameters, selected_*_kind, literals with kinds, BOZ constants and the real model

Variables, Declarations and Attributes

type declarations, every attribute, initialization, implicit none, save, block and specification expressions

Expressions and Assignment

operators and precedence, mixed-mode rules, integer division, defined operators, F2023 conditional expressions

Control Flow

if, select case, do, do while, exit and cycle, named constructs, block, associate, select type and select rank

Procedures, Functions and Subroutines

functions and subroutines, intent, optional and keyword arguments, pure, elemental and recursive, internal procedures, procedure pointers

Modules and Submodules

module contents, access control, use association, submodules and separate module procedures, compilation order

Interfaces, Generics and Operator Overloading

explicit and abstract interfaces, generic interfaces, defined operators and assignment

Arrays

Page What it covers

Arrays Fundamentals

rank, shape and conformance, column-major order, sections, constructors, where and forall

Allocatable Arrays and Dynamic Memory

allocate and deallocate, source and mold, automatic reallocation, move_alloc, allocation lifecycle

Array Arguments: Assumed Shape, Size and Rank

explicit-shape, assumed-shape, assumed-size and assumed-rank dummies, contiguity and the F2023 rank clause

Array Intrinsics and Reductions

sum, maxval, findloc, pack, reshape, matmul, reduce and the dim and mask arguments

Generic and Rank Independent Programming

kind, type and rank genericity: generic interfaces, class(*), templates and assumed rank

Characters, strings and pointers

Page What it covers

Characters and Strings

character kinds and lengths, deferred length, substrings, intrinsics, split and tokenize, encodings

Pointers and Targets

pointer and target, association states, pointer assignment, bounds and rank remapping, pointer versus allocatable

Derived types and object-oriented programming

Page What it covers

Derived Types

components, constructors, default initialization, access control, sequence and bind(c) types

Parameterized Derived Types

kind and len type parameters, assumed and deferred parameters

Object Oriented Programming

extends, polymorphic class(t) and class(*), select type, allocation of polymorphic objects, dispatch

Type-Bound Procedures, Abstract Types and Finalization

bindings, pass and nopass, deferred and abstract, generic bindings, final procedures

Enumerations

enum, bind(c), the F2023 enumeration type, flags and select case

Input/output

Page What it covers

Input/Output: Units and Files

units, open, close, inquire, sequential, direct and stream access, formatted and unformatted data

Format Specifications and Edit Descriptors

every edit descriptor, format reversion, rounding and sign modes, list-directed output

Internal Files, Namelist and Non-Advancing I/O

internal reads and writes, list-directed input, namelist, non-advancing and CSV-style input

Derived-Type and Asynchronous I/O

defined derived-type I/O, the DT edit descriptor, asynchronous transfers and wait

Intrinsics, numerics and errors

Page What it covers

Intrinsic Procedures Overview

the classes of intrinsics, argument keywords, the catalogue of every intrinsic with its purpose

Numeric Model, Bit Manipulation and Conversion

model inquiries, bit procedures, shifts, transfer, conversions and out_of_range

Intrinsic Modules and iso_fortran_env

the standard intrinsic modules and every iso_fortran_env entity

Floating-Point and IEEE Arithmetic

IEEE formats, subnormals, NaN, rounding, comparing reals, the ieee_* modules and exception flags

Error Handling and Program Termination

stat, iostat and errmsg, error stop, exit codes and failure handling without exceptions

Parallel programming

Page What it covers

Coarrays, Images and Synchronization

SPMD images, coindexed access, sync statements, critical and locks, halo exchange

Coarray Teams, Events, Collectives and Atomics

teams, events, notify, collective subroutines and atomic procedures

do concurrent and GPU Offload

iteration independence, locality specifiers, reduce, compiler support and offload

OpenMP and OpenACC

directive sentinels, parallel do, reductions, tasks, data regions and accelerators

MPI with mpi_f08

typed handles, point-to-point and collective calls, domain decomposition of the plate

Interoperability

Page What it covers

Interoperability with C

iso_c_binding, bind(c), c_loc and c_f_pointer, strings, callbacks, interoperable types

C Descriptors and ISO_Fortran_binding

CFI_cdesc_t and the CFI functions for assumed-shape and allocatable arguments

Calling Fortran from C, C++ and Python

a bind(c) library with a header, C++ linkage, f2py, ctypes and CFFI, layout and runtime libraries

MATLAB: MEX, Engine and MAT-File APIs

the mexFunction gateway, the Fortran Matrix API, the Engine API and MAT-files

Tooling and ecosystem

Page What it covers

Compilers and Compiler Options

gfortran, Flang and ifx options for standards, warnings, runtime checks, optimization and debugging

Building with Make, CMake and Meson

module dependencies, libraries and installation with Make, CMake and Meson

Fortran Package Manager (fpm)

commands, the fpm.toml manifest, profiles, dependencies, tests, examples and publishing

Fortran stdlib

what the community standard library offers, installing it and a tour of its modules

BLAS, LAPACK and Numerical Libraries

calling dgemm and dgesv, leading dimensions, linking and other libraries

Testing, Debugging and Profiling

test-drive, pFUnit, runtime checks, gdb, sanitizers, valgrind and profilers

Documentation and Editor Tooling

FORD, fortls, formatters and linters, compile_commands.json and editors

Practice and modernization

Page What it covers

Best Practices and Style

naming, layout, kinds, modules, intent and a style checklist

Common Gotchas and Pitfalls

implicit save, literal kinds, aliasing, loop order and each trap shown with the flag that catches it

Performance and Memory Layout

timing, column-major loops, contiguity and array temporaries, vectorization and structure layouts

Legacy Features and Modernization

deleted and obsolescent features, real diagnostics and a step-by-step modernization path

Evolution and reference

Page What it covers

What’s New and Fortran 2028 Preview

version-by-version changes, every Fortran 2023 change with compiler support, the Fortran 2028 draft

Cheat Sheet

a one-page A4 summary as a PDF, with links to every page

Bibliography

Every source used by the pages of this section is listed here, grouped by origin, and each is cited again on the page that uses it (in the == References section and after each example). Links were reachable on 2026-10-18; the Oxford University Press, ISO, Intel and MathWorks sites block scripted requests, so those links were opened in a browser or fetched through a web reader where possible.

Books

  • Michael Metcalf, John Reid, Malcolm Cohen and Reinhold Bader, Modern Fortran Explained: Incorporating Fortran 2023, 3rd edition of Modern Fortran Explained. Oxford University Press (Numerical Mathematics and Scientific Computation), 2023. ISBN 978-0-19-887657-1 (hardback), 978-0-19-887658-8 (paperback). Publisher page; book site (example code and errata; the address printed in the book, oup.com/fortran2023, redirects there). It describes Fortran 2018 as the base language plus Fortran 2023, and it is the main narrative source for the language chapters.

  • The MathWorks, Inc., MATLAB C/C++, Fortran, Java, and Python API Reference, release R2023a (MATLAB 9.14), 2023. Documentation PDF; the current online version is Fortran with MATLAB (release R2026b when checked). Only its Fortran parts were consulted, for the MATLAB page of this section.

The books are consulted references, not the primary source: no text, listing, figure or exercise was taken from them, and every example was written against the current official documentation and compiled and run. On any discrepancy, and wherever a book is silent on a later feature, the official documentation wins; where a book shows an outdated form, the pages say so in prose, collected on What’s New and Fortran 2028 Preview and Legacy Features and Modernization.

Standards and committee documents

fortran-lang.org and its projects

Compiler documentation

Interoperability, MATLAB and build systems

Community tools (labelled as such)

These are third-party projects rather than part of the language or its official tooling; the pages label them as community tools.