Fortran

Topics related to Fortran:

Getting started with Fortran

Fortran is a language used extensively in the scientific community due to its suitability for numerical computation. Particularly attractive is its intuitive array notation, which makes writing fast vectorised computations easy.

Despite its age, Fortran is still actively developed, with numerous implementations, including GNU, Intel, PGI and Cray.

Data Types

Arrays

Procedures - Functions and Subroutines

Functions and subroutines, in conjunction with modules, are the tools to break down a program into units. This makes the program more readable and manageable. Each one of these units can be thought of as part of the code that, ideally, could be compiled and tested in isolation. The main program(s) can call (or invoke) such subprograms (functions or subroutines) to accomplish a task.

Functions and subroutines are different in the following sense:

  • Functions return a single object and - usually - don't alter the values of its arguments (i.e. they act just like a mathematical function!);
  • Subroutines usually perform a more complicated task and they ordinarily alter their arguments (if any is present), as well as other variables (e.g. those declared in the module that contains the subroutine).

Functions and subroutines collectively go under the name of procedures. (In the following we will use the verb "call" as synonym of "invoke" even if technically the procedures to be called are subroutines, whereas functions appear as right hand side of assignment or in expressions.)

Usage of Modules

Execution Control

Modern alternatives to historical features

C interoperability

Program units and file layout

Object Oriented Programming

Intrinsic procedures

Many of the available intrinsic procedures have argument types in common. For example:

  • a logical argument MASK which selects elements of input arrays to be processed
  • an integer scalar argument KIND which determines the kind of the function result
  • an integer argument DIM for a reduction function which controls the dimension over which the reduction is performed

Explicit and implicit interfaces

I/O

Source file extensions (.f, .f90, .f95, ...) and how they are related to the compiler.