next up previous contents
Next: Building Programs and Using Up: Introduction to FORTRAN Previous: Octal and Hexadecimal

   
Statement Ordering and Program Layout

FORTRAN has two types of statements: executable and non-executable. Executable statements are those that involve action while the program is running e.g. A=B+C. These statements are converted into machine code. Non-executable statements describe the organisation and layout of data in memory but do not specify actions while the program is running and hence do not directly generate machine code. These statements include SUBROUTINE, FUNCTION, PROGRAM, BLOCK DATA, DIMENSION, COMMON, EQUIVALENCE, DATA, REAL, INTEGER, CHARACTER, LOGICAL, FORMAT and END. FORTRAN statements cannot appear in any order although the restrictions on the ordering are not severe. The general rule is that, apart from FORMAT and END, non-executable statements preceed executable ones. This rule makes the program easier to understand for the reader first sees a description of the data and then sees the actions that are to be applied to it. The precise rules for ordering are quite complicated, but if a user lays out a program as follows there will be no problems and the user will have taken the first step towards becoming a good programmer by arranging the program in a simple and logical manner.

1.
First comes SUBROUTINE, FUNCTION, PROGRAM or BLOCK DATA. The user should add comments giving a brief description of what the routine does. If the statement involves an argument list then each argument should be described giving details of which must be defined before calling the routine and which are set up during the call. Also, access to common blocks should be recorded.
2.
Next comes COMMON, DIMENSION, Data Type, and EQUIVALENCE statements preferably in that order. Data Type statements declare the type of data e.g. REAL, INTEGER, CHARACTER, or LOGICAL.
3.
Now come DATA statements.
4.
Next come all executable and FORMAT statements. Try to divide the program up into small logical blocks and preceed each with a comment describing it.
5.
Finally add an END statement.


next up previous contents
Next: Building Programs and Using Up: Introduction to FORTRAN Previous: Octal and Hexadecimal
n west (APC)
2000-03-08