IBM Books

Language Reference


Lines and Source Formats

A line is a horizontal arrangement of characters. By contrast, a column is a vertical arrangement of characters, where each character in a given column shares the same line position.

Because Fortran measures lines in bytes, these definitions apply to lines containing only single-byte characters. Each byte of a multibyte character occupies one column.

The kinds of lines are:
Initial Line
Is the first line of a statement.
Continuation Line
Continues a statement beyond its initial line.
Comment Line
Does not affect the executable program and can be used for documentation. The comment text continues to the end of a line. Although comment lines can follow one another, a comment line cannot be continued. A line of all white space or a zero-length line is a comment line without any text. Comment text can contain any characters allowed in a character context.

If an initial line or continuation line is not continued, or if it is continued but not in a character context, an inline comment can be placed on the same line, to the right of any statement label, statement text, and continuation character that may be present. An exclamation point (!) begins an inline comment.

Debug Line
Indicates that the line is for debugging code (for fixed source form only). The letter D must be specified in column 1. (See "Debug Lines")
Directive Line
Provides instructions or information to the compiler (see Chapter 11. "Directives").

Source lines can be in fixed source form or free source form format. Use the SOURCEFORM directive to mix source formats within the same program unit. Fixed source form is the default when using the f77, xlf or xlf_r invocation commands. Fortran 90 free source form is the default when using the xlf90 or xlf90_r invocation commands.

See "Compiling an XL Fortran Program" in the User's Guide for details on invocation commands.

Fixed Source Form

A fixed source form line is a sequence of 1 to 132 characters. The default line size (as stipulated in Fortran 90) is 72 characters, but can be changed using the -qfixed=right_margin compiler option (see the User's Guide).

Columns beyond the right margin are not part of the line and can be used for identification, sequencing, or any other purpose.

Except within a character context, white space is insignificant; that is, you can imbed white space between and within lexical tokens.

Tab formatting means there is a tab character in columns 1 through 6 of an initial line, which directs the compiler to interpret the next character as being in column 7.

Requirements for lines and for items on those lines are:

A semicolon (;) separates statements on a single source line, except when it appears in a character context, in a comment, or in columns 1-6. Two or more semicolon separators that are on the same line and are themselves separated by only white space or other semicolons are considered to be a single separator. A separator that is the last character on a line or before an inline comment is ignored. Statements following a semicolon on the same line cannot be labeled. Additional statements cannot follow a program unit END statement on the same line.

Debug Lines

A debug line, allowed only for fixed source form, contains source code used for debugging and is specified by the letter D in column 1. The handling of debug lines depends on the -qdlines compiler option:

If you continue a debugging statement on more than one line, every continuation line must have a D in column 1 and a continuation character. If the initial line is not a debugging line, you can designate any continuation lines as debug lines provided that the statement is syntactically correct whether or not you specify the -qdlines option.

Example of Fixed Source Form
C Column Numbers:
C        1         2         3         4         5         6         7
C23456789012345678901234567890123456789012345678901234567890123456789012
 
!IBM* SOURCEFORM (FIXED)
      CHARACTER ABC ; LOGICAL X          ! 2 statements on 1 line
      DO 10 I=1,10
        PRINT *,'this is the index',I  ! with an inline comment
10    CONTINUE
C
       CHARSTR="THIS IS A CONTINUED
     X CHARACTER STRING"
       ! There will be 38 blanks in the string between "CONTINUED"
       ! and "CHARACTER". You cannot have an inline comment on
       ! the initial line because it would be interpreted as part
       ! of CHARSTR (character context).
  100 PRINT *, IERROR
! The following debug lines are compiled as source lines if
! you use -qdlines
D     IF (I.EQ.IDEBUG.AND.
D    +    J.EQ.IDEBUG)     WRITE(6,*) IERROR
D     IF (I.EQ.
D    +  IDEBUG )
D    +  WRITE(6,*) INFO
       END

Fortran 90 Free Source Form

A Fortran 90 free source form line can specify up to 132 characters on each line, with a maximum of 39 continuation lines for a statement.

XL Fortran allows any line length and number of continuation lines, so long as the number of characters does not exceed 6700.

Items can begin in any column of a line, subject to the following requirements for lines and items on those lines:

A semicolon separates statements on a single source line, except when it appears in a character context or in a comment. Two or more separators that are on the same line and are themselves separated by only white space or other semicolons are considered to be a single separator. A separator that is the last character on a line or before an inline comment is ignored. Additional statements cannot follow a program unit END statement on the same line.

White Space

White space must not appear within lexical tokens, except in a character context or in a format specification. White space can be inserted freely between tokens to improve readability, although it must separate names, constants, and labels from adjacent keywords, names, constants, and labels.

Certain adjacent keywords may require white space:
White Space Optional White Space Mandatory
BLOCK DATA
DOUBLE COMPLEX
DOUBLE PRECISION
ELSE IF
END BLOCK DATA
END DO
END FILE
END FORALL
END FUNCTION
END IF
END INTERFACE
END MODULE
END PROGRAM
END SELECT
END SUBROUTINE
END TYPE
END WHERE
GO TO
IN OUT
SELECT CASE
 

CASE DEFAULT
DO WHILE
IMPLICIT type_spec
IMPLICIT NONE
INTERFACE ASSIGNMENT
INTERFACE OPERATOR
MODULE PROCEDURE
RECURSIVE FUNCTION
RECURSIVE SUBROUTINE
RECURSIVE type_spec
type_spec FUNCTION
type_spec RECURSIVE

See Type Declaration for details about type_spec.

Example of Fortran 90 Free Source Form
!IBM* SOURCEFORM (FREE(F90))
!
! Column Numbers:
!        1         2         3         4         5         6         7
!23456789012345678901234567890123456789012345678901234567890123456789012
 DO I=1,20
   PRINT *,'this statement&
   & is continued' ; IF (I.LT.5) PRINT *, I
 
 ENDDO
 EN&
         &D              ! A lexical token can be continued

IBM Free Source Form

An IBM free source form line or statement is a sequence of up to 6700 characters. Items can begin in any column of a line, subject to the following requirements for lines and items on those lines:

If statement text on an initial line or continuation line is to be continued, a minus sign indicates continuation of the statement text on the next line. In a character context, if the rightmost character of the statement text to be continued is a minus sign, a second minus sign must be entered as a continuation character.

Except within a character context, white space is insignificant; that is, you can imbed white space between and within lexical tokens.

Example of IBM Free Source Form

!IBM* SOURCEFORM (FREE(IBM))
"
" Column Numbers:
"        1         2         3         4         5         6         7
"23456789012345678901234567890123456789012345678901234567890123456789012
 DO I=1,10
  PRINT *,'this is -
             the index',I   ! There will be 14 blanks in the string
                            ! between "is" and "the"
 END DO
 END


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]