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.
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 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 call
ed are subroutine
s, whereas function
s appear as right hand side of assignment or in expressions.)
Many of the available intrinsic procedures have argument types in common. For example:
MASK
which selects elements of input arrays to be processedKIND
which determines the kind of the function resultDIM
for a reduction function which controls the dimension over which the reduction is performed