Fortran lessons
Ancestor of scientific computing
Fortran was developed at IBM in 1957 and is considered the first high-level programming language. Its name comes from "Formula Translation"; its purpose was to allow scientists to write mathematical formulas directly without translating them into machine language. It is the starting point of software history.
The reason Fortran is still used today is not sentimental, but technical. In numerical computation, especially in large array and matrix operations, Fortran compilers have been optimized for decades and are still among those that produce the fastest machine code. Weather models, fluid dynamics simulations, nuclear calculations, and astrophysics codes are written in Fortran.
In addition, some of the world's most used scientific libraries — linear algebra libraries like BLAS and LAPACK — are written in Fortran. When you multiply matrices with NumPy in Python, Fortran code is most likely running in the background.
- •→
Introduction to Fortran
First step into Fortran, the ancestor of scientific computing: program structure and printing with print.
- •→
Variables
integer, real, character types; declarations at the beginning of the code, and parameter constants.
- •→
Operators
Arithmetic (+ - * / **), remainder with mod() and comparison operators.
- •→
Conditions (if)
if-then-else and comparison/logical operators (==, .and., .or.).
- •→
Loops (do)
Numeric loop with do (end value INCLUDED) and accumulating the sum.
- •→
Arrays
1-indexed arrays, assignment with [ ] and whole-array operations like sum.
- •→
Functions
Define a function in the contains block; the return value is assigned to the function name.
What you will learn
- Program structure and declaration section
- Printing output with print and reading input with read
- Type declarations and the concept of precision
- Defining arrays and performing bulk operations on arrays
- The do loop and if structures
- Writing subroutines and functions
Who is this for?
- Researchers doing scientific computing and engineering simulation
- Ph.D. students inheriting existing Fortran scientific code
- Those who want to write high-performance numerical code
When to use?
For large-scale numerical simulation, linear algebra, climate and fluid models, and scientific code running on supercomputers, Fortran is still a first-class tool.
It is not suitable for web, mobile, database applications, and general software development. In new scientific projects, a combination of Julia or Python with NumPy might be more agile.
Frequently asked questions
Is Fortran a dead language?
No. New web applications are not being written in it, but a significant portion of scientific code running on supercomputers is in Fortran, and this code is actively developed. The language itself is also up to date: Fortran 2018 and 2023 standards added modern features.
Why is Fortran so fast?
The language design allows the compiler to make strong assumptions; knowing how arrays are laid out in memory and that two arrays do not overlap, in particular, allows for aggressive optimization. Sixty years of compiler development expertise adds on top of this.
What is the difference between Fortran 77 and modern Fortran?
Fortran 77 uses fixed-form formatting: code must start from certain columns and line length is limited. Fortran 90 and later introduced free-form, dynamic arrays, module structures, and array operations. You see the first format in legacy code and the second in new code.
Do arrays start at 1?
By default yes, but in Fortran you can define your own array bounds; it is possible to define an array starting from zero or a negative number. This flexibility reduces index conversions in scientific code.
Summary
Beyond being the first high-level language, Fortran remains the standing foundation of scientific software with its performance in numerical computing. In this tutorial, we progress from program structure to array operations and subroutines.