Course

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

  1. 01
    Your first Fortran program

    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.

    Beginner · 10 min read

    Not started
  2. 02
    Values, types and arithmetic

    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.

    Beginner · 14 min read

    Not started
  3. 03
    Decisions: if, else if, else

    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 ==.

    Beginner · 12 min read

    Not started
  4. 04
    Loops: do and do while

    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.

    Beginner · 14 min read

    Not started
  5. 05
    Arrays, sections and sum

    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.

    Intermediate · 18 min read

    Not started
  6. 06
    Functions and subroutines

    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.

    Intermediate · 18 min read

    Not started
  7. 07
    Strings and concatenation

    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.

    Intermediate · 16 min read

    Not started
  8. 08
    Formatted output

    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.

    Intermediate · 16 min read

    Not started
  9. 09
    select case

    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.

    Intermediate · 12 min read

    Not started
  10. 10
    Modules: code with a name

    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.

    Advanced · 18 min read

    Not started
  11. 11
    Records with type

    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.

    Advanced · 16 min read

    Not started
  12. 12
    Capstone: a stock report

    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.

    Advanced · 22 min read

    Not started