Fortran from the ground up
The language of formulas, still the fastest
- Beginner
- 12 chapters
- 186 min read
A hands-on introduction to modern Fortran, from the first program to a formatted report: types and integer division, decisions and loops, arrays and their built-in functions, procedures with intent, modules, records, and output that lines up. Every idea runs on a real compiler — the padding and all.
What You'll Learn
- Write and run a Fortran program, and say what implicit none is protecting you from
- Declare and use integer, real, character and logical values
- Do arithmetic that keeps its fraction, and recognise integer division
- Choose a branch with if, else if and else, in the right order
- Repeat work with do and do while, and leave a loop with exit or cycle
- Store a table in an array and use sections, sum, size, maxval and minval
- Write functions and subroutines with intent, and pass arrays by shape
- Join and trim text, and know why a Fortran string is padded with blanks
- Control output with format strings instead of list-directed print
- Choose between cases with select case, ranges and defaults included
- Put code and constants in a module, and import only what you use
- Group fields into a derived type and build a report of records
Prerequisites
- No Fortran at all — the course starts at the first program
- Some experience with any language helps, but the maths is the only real prerequisite
Course Content
- 01Your first Fortran programNot started
Why a language designed in the 1950s still runs the world's weather and physics code, and the smallest complete program: a program block, implicit none, and one print statement.
- 02Values, types and arithmeticNot started
The four everyday types — integer, real, character and logical — how to declare them, and the arithmetic rule that catches everyone: integer division throws the remainder away.
- 03Decisions: if, else if, elseNot started
Comparing values, combining conditions with .and. and .or., and the block if that runs exactly one branch of a chain — plus why two real numbers should never be compared with ==.
- 04Loops: do and do whileNot started
The counted do loop, the do while loop for when the end is a condition rather than a number, and the two statements that change the shape of a loop from inside: exit and cycle.
- 05Arrays, sections and sumNot started
One name for many values: declaring an array, filling it, taking a section out of it, and letting the built-in functions do the counting, summing and searching.
- 06Functions and subroutinesNot started
Naming a piece of work: functions that return a value, subroutines that report through their arguments, intent declarations that say who may change what, and arrays passed without their size.
- 07Strings and concatenationNot started
Text in Fortran has a fixed length and is padded with blanks, so joining two names needs care. trim, len_trim, adjustl and the // operator are the whole toolkit.
- 08Formatted outputNot started
List-directed print chooses its own widths and pads numbers with blanks. A format string says exactly how wide every value is, which is the difference between debugging output and a report.
- 09select caseNot started
When a decision is really one value with several possibilities, select case says so: a list of cases, ranges of cases, and one default for everything left over.
- 10Modules: code with a nameNot started
A module puts procedures and constants in one named place, and `use` brings them in. It is how Fortran code is shared without copying it, and how the compiler checks every call.
- 11Records with typeNot started
A derived type groups fields under one name, so a student is a name and a score rather than two arrays that must be kept in step. Constructors, % access, and arrays of records.
- 12Capstone: a stock reportNot started
A table of records, a total and an average, and a report whose columns line up — the whole course working in one file, from the type declaration to the formatted write.
