Welcome to AE Resources
Converted document Converted document

FORTRAN 90+: LINE CONTINUATION

Most mathematical programs can be easily programmed on one line. In some cases, this is not possible, and the operation must be continued on a second line or more. This is common for statements defining input and output formats. The compiler must be notified that the line is not independent, but must include additional lines.
In fixed-form programs (FORTRAN 77) the first character of a line started in column 7 and ended in column 72. If a line of code exceeded these 66 characters, the line was continued in column 7 of the next line. The compiler was notified of this continuation by the presence of a character in column 6. Note that the character in column 6 can be anything; it is not restricted to the “&” character.
In free-form programs, the regimentation of the columns is no longer required. Instead, the character “&” is reserved for the use in continuations. The only time that the “&” character can be used is in a character string where the contents are used verbatim. The compiler knows that a line is continued with a “&” at the end of the line that will be continued.
Consider the following example:
X = variable1 + variable2 + variable3 + 2.0 * (a + bb&
      + ccc)
 
Note that the leading blanks prior to the “+” of the second line are ignored. The mathematical operation is continued in the first column after the “&”.
Breaking a variable name is not good programming practice, but it can be done with the addition of another “&” in the continuation line, as illustrated below:
X = variable1 + variable2 + variable3 + 2.0 * (a + b&
        &b+ ccc)
It is bad programming practice to break up a variable name in this way, but it will work. This type of continuation is typically used to keep character strings intact. Note what happens when an extra blank is included (or if no “&” is included on the second line):
X = variable1 + variable2 + variable3 + 2.0 * (a + b&
        & b+ ccc)
or
X = variable1 + variable2 + variable3 + 2.0 * (a + b&
         b+ ccc)
These last two examples are bad programming practice, and they will result in an error since the compiler interprets these as “bb b”.