Software Engineers Handbook/Language Dictionary/FORTRAN

FORTRAN
Here is the wikipedia entry. The following briefly describes Fortran77. Fortran 77 was a refinement of Fortran 66 and Fortran IV, but added some desirable new features. Most notably types.

Type
Fortran is a full procedural language.

Execution Entry Point
The main entry point to a program is at a  statement.

General Syntax
Fortran was designed with punch card in mind, hence the actual Fortran code start on the 7th character offset. Characters are prefix by 6 characters. Characters 1 to 5 indicate a label, character 6 indicates a line continuation.

For example:

N.B. inserting an extra character at the wrong place may cause unexpected behaviour. c.f. wikiquote:Special:Search=C._A._R._Hoare regarding the Mariner space rocket.

A  and the  statement are optional in this example.

Note also:
 * 1) The characters from position 76 onward are ignored.  So be careful when you insert a character into a long line.  (IBM FORT/VS compiler used to insert line numbers in this column for some odd reason)
 * 2) The space character is ignored, except in quotes, most notably these two lines are interpreted the same, hence the suspicion relating to the Mariner crash.

Comments
A 'C', '*' and sometimes a 'c' character in the first column indicates a comment. For example:

Variable Declarations
In Fortran the type of a variable is implicitly defined by the first letter of the variable name. Variables beginning with the letters I through N were automatically considered to be integers, while A through H and O through Z were considered to be real numbers.

This behavior can be modified with an IMPLICIT INTEGER declaration (setting the letter range of integers) or an explicit declaration of a variable giving its type.

Hence "GOD is REAL (unless declared INTEGER)."

Example:

Method Declaration/Implementation
Fortran has several kind of. Example: Produces: Note that in the output the first character is normally a blank character. By inserting other characters in the first column you can force the printer to do form feeds, and perform other interesting behaviors.

Scope
The scope of variable was strictly limited to the current PROGRAM/SUBROUTINE or DATA BLOCK. DATA BLOCK can be shared between PROGRAM/SUBROUTINEs, allowed the programmer to extend the scope of a variable.

Conditional Statements
 Conditional statements also include GOTO statements. FORTRAN also has a 3 way condition.

Looping Statements
FORTRAN 77  > DO / WHILE LOOP In older FORTRANS labels and GOTOs would be used to the same effect. For example:

Output Statements
Example one hello world: Or: Or (The stand output channel is 6): Or: Or: Or: Fortran includes OPEN, CLOSE, READ, WRITE and PRINT statements. The READ and WRITE commands could access recorded in a file by record number, hence Fortran contains a semblence of random file access. Unfortunately on File IO the size of a "word" is implementation dependent, and ranges from 6 bits on CDC, 8bits on IBM and 32 bits on VAXVMS.

Containers
FORTRAN 77 has no structure or class definition. The closest example was the COMMON statement. An EQUIVALENCE statement allows such COMMON block statement be be overlayed, and allow direct assignment. But this is problematic. An EQUIVALENCE also have a similar effect as the union from Algol68 (and then C) language union statement. The net effect is two variables ALLREC,CUSREC share the same location in memory.

Algorithms
Access to other languages was only available if the language supported FORTRANs SUBROUTINE calling conventions (Not all FORTRANs used the stack!). And the actual conventions varied from machine to machine.

Garbage collection
Garbage collection is not part of the language, but has been implemented separately using datablock. In Fortran the memory at program startup was all that would be available to the program until it terminated. (The exception would be if the compiler supported recursion with local variables, but this was not always the case.)

Physical Structure
The  scoping rules of Fortran is similar to the scoping found in the C programming language. However Fortran 77 does not have a standard  statement.
 * DATABLOCK EXTNM1
 * EXTERNAL EXTNM2
 * PROGRAM EXTNM3
 * FUNCTION EXTNM3
 * ENTRY EXTNM4
 * SUBROUTINE EXTNM5
 * DATA BLOCK
 * COMMON EXTNM6

Tips

 * Arrays are indexed starting with 1.

Web References

 * The Fortran Wikibook
 * The FAQ page for the comp.lang.fortran usenet group

Books and Articles
