next up previous contents
Next: Data types, variables and Up: A short summary of Previous: A short summary of   Contents


The structure of a FORTRAN program

A FORTRAN program consists of a main program, possibly followed by one or more subprograms.
For the exercises you can put all of them in the same file
The structure of a program is given in the following scheme:
Main program:
    program statement (bijvoorbeeld program opgave2)
    declarations
    statements
    end
Subprogram:
    subroutine ...  or function ...
    declarations
    statements
    end
NB. Contrary to Pascal recursive programming in FORTRAN is not possible. Variables which are used in the main program, are known only in the main program and not in the subroutines. Vice versa, variables in the subroutines are only known locally.
Exchange of variables between man program and subroutines can in principle only be done with the parameter list. FORTRAN has a second possibility, the common block, which is not treated here.
FORTRAN 77, as used by us, is strictly column oriented. This means that there are very strict rules for how a program text should look like. If you do not follow these rules, you will get a very long list of error messages. Most of them will be totally incomprehensible.
The rules:
  1. Labels must be put in columns 1 to 5.
  2. FORTRAN text must be in columns 7 to 72. All information after column 72 is ignored.
  3. If a statement does not fit on one line, it can be continued on the next line(s). On position 6 of the next line(s) there has to be a symbol, NOT a space, but for instance + or a digit (1 or 2 or ...).
  4. Only one statement per line is permitted
  5. The character c or * in position 1 means that this line contains only comment.

next up previous contents
Next: Data types, variables and Up: A short summary of Previous: A short summary of   Contents
Mathieu Pourquie 2001-02-28