typestar

Language basics

27 steps in 9 sets of Fortran.

Fortran is where compiled programming began — 1957, IBM, a team betting that a machine could translate formulas better than most humans write assembly — and it never stopped: today it runs the weather forecast, the climate models, and a healthy share of everything computed on supercomputers. Modern Fortran is not the punch-card FORTRAN of legend: free-form source, modules, and an array language other ecosystems spent decades reinventing.

This tour covers the modern core as gfortran compiles it: programs and declarations under implicit none, arrays with constructors, sections and reducing intrinsics, the whole-array style of where masks and elementwise arithmetic, procedures with intent and pure and elemental, character handling and format descriptors, derived types and allocatables and native complex numbers, and portable kinds from iso_fortran_env. The encore ships complete programs. Every seed compiles clean under -Wall -Wextra -Werror and runs.

Start this tour

Programs & variables

  • The program shapeThe smallest Fortran program: a named block and two list-directed prints.
  • DeclarationsFour typed variables for the lighthouse log, declared before any statement runs.
  • Named constantsparameter makes a constant the compiler will defend, from pi to the crew count.

Arrays

  • Array constructorsArrays built in brackets, sized by their type, walked by an implied-do.
  • Array sectionsstart:end slices of a week of highs, with strides, ends, and in-place assignment.
  • Array intrinsicssum, maxval, and friends replace the counting loop entirely.

Control flow

  • if and end ifA sailing call in an if chain: then blocks, else if rungs, end if closing.
  • select caseDepth bands routed by select case: open ranges, closed ranges, and a default.
  • do loopsThe counted do, plus cycle and exit steering from inside the body.

Whole-array thinking

Procedures

  • Subroutines and intentA causeway verdict via subroutine: intent tells the compiler which way data flows.
  • FunctionsA pure tip calculator: the function's name is its result variable.
  • Elemental functionsWrite the conversion for one value; elemental maps it over arrays for free.

Strings & formats

Types & memory

  • Derived typesA kayak record built with type and read with the percent sign.
  • Allocatable arraysAn array whose size waits for run time, grows on assignment, and cleans up.
  • Complex numberscomplex is a built-in numeric type: rotate, measure, and conjugate without a library.

Kinds & modules

  • Real kindsOne third at 32 and 64 bits: iso_fortran_env names the precisions portably.
  • Math intrinsicsThe numeric toolbox is in the language: hypot, atan2, modulo, and friends.
  • Modules and useA module and its program in one file: constants and functions behind a name.

Encore

  • word_freq.f90A word-frequency table built from index, substring slices, and a hash-mark chart.
  • grade_report.f90Quiz scores fold into averages and letter grades, then a formatted class report.
  • temp_stats.f90A week of daily highs reduced to low, high and mean, with a scaled bar per day.

The other Fortran tours