Good habits of programing in Fortran 77 (standard Fortran).

    by Nasser M. Abbasi

 

  1. F77 does not insist on declaring a variable before using it. This can lead to problems (such as mistyping a variable name, leading to having 2 different variables when the intension is one). Hence always use IMPLICIT NONE.

 

  1. This is a famous story: From http://www.star.le.ac.uk/~cgp/prof77.html

    “There is a useful lesson to be learned from the failure of one of the earliest planetary probes launched by NASA. The cause of the failure was eventually traced to a statement in its control software similar to this:

    DO 15 I = 1.100

    when what should have been written was:

    DO 15 I = 1,100

    but somehow a dot had replaced the comma. Because Fortran ignores spaces, this was seen by the compiler as:

    DO15I = 1.100

    which is a perfectly valid assignment to a variable called DO15I and not at all what was intended.

    Fortran77 permits an additional comma to be inserted after the label in a DO statement, so it could now be written as:

    DO 15,I = 1,100

    which has the great advantage that it is no longer as vulnerable to a single-point failure.”

 

  1. do NOT use GOTO

 

 

character set:

the 26 upper-case letters

A B C ... X Y Z

the 10 digits

0 1 2 3 4 5 6 7 8 9

and 13 special characters:

 

 

+

plus

-

minus

*

asterisk

/

slash

 

blank

 

equals

(

left parenthesis

)

right parenthesis

.

decimal point

,

comma

'

apostrophe

:

colon

$

currency symbol

 

 

·  columns 1 to 5 form the label field,

·  column 6 forms the continuation marker field,

·  columns 7 to 72 form the statement field.

 

PROGRAM, FUNCTION, SUBROUTINE, BLOCK DATA

 

 

IMPLICIT

 

PARAMETER

Type statements:

 

 

INTEGER, REAL, DOUBLE PRECISION,

 

 

COMPLEX, LOGICAL, CHARACTER

 

 

Other specification statements:

 

 

COMMON, DIMENSION, EQUIVALENCE,

 

 

EXTERNAL, INTRINSIC, SAVE

FORMAT

 

Statement function statements

 

DATA

Executable statements:

 

 

BACKSPACE, CALL, CLOSE, CONTINUE, DO,

 

 

ELSE, ELSE IF, END IF, GO TO, IF,

 

 

INQUIRE, OPEN, READ, RETURN, REWIND,

 

Standard Data Types

The table below summarises the properties of the six data types provided in Standard Fortran:

Data type

Characteristics

 

 

Integer

Whole numbers stored exactly.

Real

Numbers, which may have fractional parts, stored using a floating-point representation with limited precision.

Double Precision

Similar to real but with greater precision.

Complex

Complex numbers: stored as an ordered pair of real numbers.

Logical

A Boolean value, i.e. one which is either true or false.

Character

A string of characters of fixed length.

 

Type statements must precede all executable statements in the unit;

 

If an operator has two operands of the same data type then the result has the same type. If the operands have different data types then an implicit type conversion is applied to one of them to bring it to the type of the other. These conversions always go in the direction which minimises loss of information:

integer converts to real converts to complex or double precision

 

http://www.fortran.com/fortran/F77_std/rjcnf0001.html