3. The layout of a program (free form and fix form)

Sometimes we require more than one line for a statement
   Print *, 'This is a long output line',&
            ' this is the second part',&
            ' and this is the third part!'
Nowadays, in the free form, we continue a line with the symbol "&" (called ampersand), i.e. with the sign & at the end of the old line instead of an almost arbitrary character in column 6 of the new line. With the compiler we are now using it is possible to include the Swedish characters in character strings and in comments.

Sometimes a certain identifier or a certain numerical number does not fit on one line. We can then interrupt the identifier anywhere with the character "&" and then on the next line give a new "&" as the first non-blank character. You continue then directly from this "&" without any extra blank. The character "&" therefore works as a kind of delimiting or syllabification sign. You can write

     PI = 3.141592653589793
or you can write equivalently
     PI = 3.14159265&
            &3589793
Please note that comment lines can not be continued. The reason for this is that in a comment line the sign "&" is also treated as belonging to the comment. However, you can also add comment lines inside the continuation lines. Note that it is the final "&" of a line that indicates a continuation line, it is therefore possible to write a text string of characters including the character "&".

Sometimes you may wish to do it in the opposite way, to have several statements on the same line. This is done with the use of semicolon. And with the exclamation mark we can include a comment on the same line.

     A = 0.0 ; B = 1.0 ; C = 2.0       !  Initialization
A line may include up to 132 characters, a statement may have up to 39 lines of continuation.

Note that in the free form, blanks are significant, as can be seen in my favorite example:

     DO 25 I = 1. 25
This gives a compilation error since the compiler does not find a comma between the lower and upper the limits, but the compressed version
     DO25I=1.25
gives the same result as the non-compressed form and as in Fortran 77 or using the old form (fix form) of Fortran 90, namely that the variable DO25I is being assigned the value 1.25.

Comments are started with "!" (exclamation mark) and ended with the end of line. The old types of comments introduced with C or * in column 1 are no longer permitted if you use free form, but are, of course, if you use the fix form. Upper case and lower case characters are equivalent except in character strings.

The above applies to the new free form. In the old, column-oriented or fix form, we can also use a semicolon or exclamation mark between columns 7 and 72 but you can not continue with "&" in columns 1 to 6 or 73 to 80 or write comments in columns 1 to 6. Exclamation mark in column 1 of course means a comment line also in the old fix form. Some possibilities of longer lines do exist within the old fix form (implementation dependent).

Exercises

(3.1) What does the following line mean?
  A = 0.0 ; B = 370 ! First variables ; C = 17.0 ; D = 33.0
Solution.

(3.2) Are the following lines correct according to Fortran 90?

  Y = SIN(MAX(X1,X2)) * EXP( - COS(X3)**I ) - TAN(AT&
             & AN(X4))
Solution.


Last modified: 6 April 1999
boein@nsc.liu.se