MATH7601: A Summary of Fortran 90 Programming Commands
(you need to know how to....)
• Use PROGRAM NAME...END PROGRAM NAME to set up a program with a suitable name. Use
IMPLICIT NONE (spell-checker!).
• Be able to correctly declare and initialise variables of type INTEGER, REAL, COMPLEX,
LOGICAL, CHARACTER and CHARACTER(len=xx). Know about PARAMETERS and when to
use them.
• Know the syntax for simple arithmetic operations +, −, ∗, ∗∗, / etc. Remember integer division!
• Be able to use comparative operators ==, / =, >=, >, < etc. to initialise logical variables or define
conditional clauses based on the value of real or integer variables.
• Be able to use logical operators .NOT., .AND., .OR., .NEQV. etc. to perform operations with
logical variables.
• Use Fortran intrinsic functions EXP, ALOG, COS, ASIN, etc. to perform standard mathematical
operations.
• Use PRINT *, or WRITE (*,*) to write to the screen and READ *, or READ (*,*) to input from
the keyboard.
• Use OPEN(23,file=’filename.dat’) to open a file to read from or write to.
• Use format strings (e.g. ’(F12.6,A,2x,2I6)’) to control the organisation of output data.
• To repeat operations: Know the three different types of DO loop and when to use them, and the
effect of the variable STEP in the final type.
DO DO WHILE (condition) DO count=1,N(,STEP)
IF (condition) EXIT . .
END DO END DO END DO
• Use single-line IF (condition) clauses to execute statements if and only if (condition) is true.
• Use IF (condition) THEN...ELSE....END IF to execute different sequences of statements depending
on whether (condition) is true or false.
• Declare and initialise arrays of different dimension (different types of initialisation: element by
element, as vectors, in DO loops or using assignment statements). Be able to control the index range
(e.g. A(-2:2,0:4)). Use ‘:’ to define subarrays (e.g. B=A(:,2), C=A(-1:1,0:1).)
• Use SUM to add (some or all) elements of an array or sub-array. Use SIZE to recover the dimension
of an array or sub-array.
• Use SUBROUTINEs to perform self-contained operations. Understand the difference between
INTENT(IN), INTENT(OUT), INTENT(INOUT) and local variables in subroutines (and
functions). Use FUNCTIONs to evaluate specific self-contained calculations.
• Understand when and why a subroutine or function should be declared RECURSIVE (e.g. Towers of
Hanoi example).
• Use MODULEs to store variable declarations, subroutines and functions.
• Use TYPE MYTYPE....END TYPE MYTYPE to create a user-defined data type for storing
different forms of data together (e.g. medical records). Know how to declare (e.g.
TYPE(MYTYPE)::DATASET1) and initialise them (e.g. DATASET1%VARIABLE1(1)=..., or
DATASET1=MYTYPE(...,...,...) ).
• Operator Overloading: Be able to use
INTERFACE OPERATOR (*)
MODULE PROCEDURE FUNCTIONNAME
END INTERFACE
in order to extend the meaning of an operator *,+,- etc. to act on user-defined data types according
to the algorithm set out in the function FUNCTIONNAME.