Fortran

Fortran, WTF? My great-grandparents used that language! Why should I care?

Overview

Yes, Fortran was created in the 1950s, but modern Fortran looks nothing at all like the original.

Today, Fortran is a high-performance parallel programming language, ideal for computationally intensive applications. It is still very popular in scientific, numeric, and engineering applications.

The Language Home Page

Everything you need to know to get started can be found at Fortran-lang.org. They have examples, learning guides, an online playground, a link to their Discourse, and more.

Getting Started

We'll assume you have gfortran, the most current Fortran compiler for gcc. To get going, see Getting Started With gfortran.

Let’s jump into some examples.

Hello

Tradition!

hello.f90
! Best greeting ever

program hello
    print '(a)', 'Hello, World'
end
$ gfortran hello.f90 && ./a.out
Hello, World

The convention is to use a file suffix of .f90 for all Fortran versions from Fortran 90 onward, and .f for prior versions.

Fibonacci Numbers

Another classic:

TODO

Version History

Fortran was created as one of the very first “high-level” programming languages, meaning “not an assembly language,” before much was known about language processing, so its designers used all sorts of clever engineering techniques to make translation to machine code as fast as possible. The look-and-feel of the original Fortan had assembly language vibes, especially fixed formatting: code had to start in column 7, columns 1–5 were for line numbers, column 6 was a continutation character (for line wrapping), and a wild computed goto statement allowed jumping to one of three destinations based on the result of a comparison. Here’s a Fortran I program found here:

C      PROGRAM FOR FINDING THE LARGEST VALUE
C    X      ATTAINED BY A SET OF NUMBERS
       DIMENSION A(999)
       FREQUENCY 30(2,1,10), 5(100)
       READ 1, N, (A(I), I = 1,N)
   1   FORMAT (I3/(12F6.2))
       BIGA = A(1)
   5   DO 20 I = 2,N
  30   IF (BIGA - A(I)) 10, 20, 20
  10   BIGA = A(I)
  20   CONTINUE
       PRINT 2 N, BIGA
   2   FORMAT (22H1THE LARGEST OF THESE I3, 12H NUMBERS IS F7.2)
       STOP 0

Here’s how Fortran has evolved into the modern ultra-high-performance language it is today:

Version Year Highlights
Fortran I 1957 First release; focus on numerical computation; basic control structures
Fortran II 1958 Subroutines, functions, separate compilation
Fortran III Late 1950s Experimental; early dynamic memory; interrupt handling
Fortran IV 1962 COMMON blocks; logical IF; machine independence improvements
Fortran 66 1966 First ANSI standard; widespread portability
Fortran 77 1978 Structured programming (IF/THEN/ELSE); CHARACTER type; better I/O
Fortran 90 1991 Modules; array operations; dynamic memory; recursion; derived types
Fortran 95 1997 Pure/elemental procedures; FORALL construct; parallelism foundations
Fortran 2003 2004 Object-oriented programming; C interoperability; stream I/O
Fortran 2008 2010 Coarrays for parallelism; submodules; DO CONCURRENT; better C interoperability
Fortran 2018 2018 Teams and collectives for coarrays; BLOCK construct; scalability enhancements
Fortran 2023 2024 Generics via parameterized modules; exception handling; modern parallelism support

TODO

A Brief Language Guide

TODO

Recall Practice

Here are some questions useful for your spaced repetition learning. Many of the answers are not found on this page. Some will have popped up in lecture. Others will require you to do your own research.

TODO

Summary

We’ve covered:

    ...