Source Program Lines - Fortran

A source program line is a sequence of character positions, called columns, numbered consecutively starting from column 1 on the left.


The two formats for Fortran programs are

  1. Fixed format—based on columns
  2. TAB format—based on the tab character

1. Fixed Format

A Fortran line is divided into columns, with one character per column as indicated in Table below.

Table: Fortran Line Structure

Fortran Line Structure

The –col72, –col120, –extend_source, and –noextend_source command line options are provided to change this format.

2. TAB Character Formatting

Rather than aligning characters in specific columns, the TAB character can be used as an alternative field delimiter, as follows:

  • Type the statement label and follow it with a TAB. If there is no statement label, start the line with a TAB.
  • After the TAB, type either a statement initial line or a continuation line.
    A continuation line must contain a digit (1 through 9) immediately following the TAB. If any character other than a nonzero digit follows the TAB, the line will be interpreted as an initial line.
  • In a continuation line beginning with a TAB followed by a nonzero digit, any characters following the digit to the end of the line are a continuation of the current statement.
  • TAB-formatted lines do not have preassigned comment fields. All characters to the end of the line are considered part of the statement.

However, you can use an exclamation point (!) to explicitly define a comment field. The comment field extends from the exclamation point to the end of the line.
The rules for TAB formatting can be summarized as statement label TAB statement (initial line)
TAB continuation field statement (continuation line)
TAB statement (initial line)

Note that although many terminal and text editors advance the cursor to a predetermined position when a TAB is entered, this action is not related to how the TAB will be ultimately interpreted by the compiler. The compiler interprets TABs in the statement field as blanks.

Types of Lines
The four types of Fortran program lines are

  1. comment
  2. debugging (an extension to Fortran 77)
  3. initial
  4. continuation

A comment line is used solely for documentation purposes and does not affect program execution. A comment line can appear anywhere in a program and has one of the following characteristics:

  • An uppercase C or an asterisk (*) in column 1 and any sequence of characters from column 2 through to the end of the line
  • A blank line
  • Text preceded by an exclamation point (!) at any position of the line

2. Debugging Lines
Specify a D in column 1 for debugging purposes; it conditionally compiles source lines in conjunction with the –d_lines option described earlier. When the option is specified at compilation, all lines with aD in column 1 are treated as lines of source code and compiled; when the option is omitted, all lines with aD in column 1 are treated as comments.

3. Initial Lines
Initial lines contain the Fortran language statements that make up the source program; these statements are described in detail in “Program Organization”. These fields divide each Fortran line into

  • statement label field
  • continuation indicator field
  • statement field
  • comment field

The fields in a Fortran line can be entered either on a character-per-column basis or by using the TAB character to delineate the fields, as described in the previous section.

4. Continuation Lines
A continuation line continues a Fortran statement and is identified as follows:

  • Columns 1 through 5 must be blank.
  • Column 6 contains any Fortran character other than a blank or the digit 0. Column 6 is frequently used to number the continuation lines.

As with initial lines, columns 7 through the end of the line contain the Fortran statement or a continuation of the statement.

Alternatively, you can use an ampersand (&) in column 1 to identify a continuation line. Using an & in column 1 implies that columns 2 through the end of the line are part of the statement. In Fortran 77, any remaining columns (column 73 and on) of a continuation line are not interpreted.

The maximum number of consecutive continuation lines is 99 unless you change this limit with the –NC compiler option.

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd Protection Status

Fortran Topics