Lumenary CS · Programming languages
Fortran
The first high-level language, still at the heart of weather forecasting, climate models and physics codes, taught as modern Fortran 2018 with whole-array operations, modules and objects.
Fortran (originally FORTRAN, for Formula Translation) was created at IBM by a team led by John Backus, and its first compiler shipped in 1957. It was the first widely used high-level programming language, and it proved that a compiler could produce code nearly as fast as hand-written assembly. Nearly seventy years later it is still a living language, revised by an ISO committee (most recently as Fortran 2023), and it still runs much of the world's heaviest numerical computing: weather and climate models, computational fluid dynamics, quantum chemistry, nuclear and astrophysics codes, and the linear-algebra libraries that Python, R, Julia and MATLAB call under the hood.
This course teaches modern Fortran, the free-form language of the 2008 and 2018 standards, not the punched-card FORTRAN 77 many people imagine. It covers the compiler and program structure, types and declarations, control flow, arrays as first-class values, procedures and modules, derived types and object-oriented features, numerical precision, formatted and file I/O, parallelism with do concurrent, coarrays, OpenMP and MPI, calling Fortran from C and Python, and the modern tooling of the Fortran-lang community, ending with an orbital-simulation project. It assumes the Start level of Lumenary CS or equivalent experience: you know what a variable, a loop and a function are. No previous Fortran is needed.
To run the programs, install GFortran, the Fortran compiler of the GNU Compiler Collection (on Debian and Ubuntu sudo apt install gfortran, on macOS through Homebrew with brew install gcc, on Windows through MSYS2 or WSL); fortran-lang.org lists it alongside the other free and commercial compilers, such as LLVM Flang and Intel's ifx. You can also try small programs in the browser in the Fortran-lang community's online playground. Every program marked as checked was compiled by Lumenary's test suite with GFortran 11 using gfortran -std=f2018 -Wall and run, and the output shown is the output it printed. The lessons were drafted with AI assistance and are awaiting review by a human computer scientist.
- Chloe · The Designer
“Why is the language built this way?” - Margaret · The Profiler
“What does it print, and what does it cost?” - Gideon · The Language Lawyer
“What exactly does the language guarantee?”
Foundations · 3 lessons
The core language
Where Fortran came from and why it endures, compiling a first program, types, declarations and control flow, and the arrays that are Fortran's greatest strength.
- 1First steps in FortranHow the first high-level language was born at IBM, why it still runs the world's weather forecasts, and how to compile and run modern Fortran. 50 min
- 2Types, declarations and control flowFortran's intrinsic types and their arithmetic rules, character strings, and the if, select case and do constructs that structure every program. 55 min
- 3Arrays, Fortran's greatest strengthArrays as first-class values, with custom bounds, sections, whole-array arithmetic, masks, reductions and allocatable storage. 60 min
Practice · 3 lessons
Building numerical software
Procedures and modules for organising code, kind parameters and floating-point precision, formatted and file input and output, and derived types with Fortran's object-oriented features.
- 4Procedures and modulesFunctions and subroutines with declared intents, pure, elemental and recursive procedures, optional and keyword arguments, and modules that organise code and give it safe interfaces. 60 min
- 5Numerical precision and input/outputKind parameters and iso_fortran_env for portable precision, the behaviour of floating-point arithmetic, and formatted, file and namelist I/O with proper error handling. 60 min
- 6Derived types and object-oriented FortranYour own types with components, operators and type-bound procedures, then inheritance, abstract types and polymorphism as Fortran 2003 defines them. 65 min
Professional · 2 lessons
Fortran in research and industry
Parallel Fortran with do concurrent, coarrays, OpenMP and MPI, calling Fortran from C and Python, and the fpm package manager and community tools, brought together in an orbital-simulation project.
- 7Parallelism and interoperabilityMany cores and many machines with do concurrent, OpenMP, coarrays and MPI, and the standard bridge between Fortran, C and Python. 70 min
- 8Tools of the trade, and an orbital simulatorCompilers, fpm, tests and the habits of professional Fortran teams, brought together in a small N-body simulation of planets and a comet. 70 min
Further reading and resources
- Fortran-langThe community website: tutorials, a list of compilers, packages, news and links to the forum and playground.
- Fortran PlaygroundFortran-lang's online playground for compiling and running small programs in the browser.
- ISO/IEC JTC1/SC22/WG5, the Fortran standards committeeThe international committee that maintains the standard, with drafts and summaries of each revision.
- INCITS/Fortran (J3)The US committee that does most of the technical work on new Fortran standards, with its papers and draft documents.
- The GNU Fortran compiler documentationThe GFortran manual: options, intrinsic procedures and language extensions.
- Fortran Package Manager (fpm)The community build tool and package manager for Fortran projects.
- Fortran DiscourseThe community forum, where compiler developers, committee members and users answer questions.