<< >> Title Contents Index Home Help

1 Language Overview

This chapter describes the basic elements of the Fortran language, the format of Fortran records and the types of expressions and assignments accepted by pgf77 Fortran.

1.1 Elements of a Fortran Module

A Fortran module is either a SUBROUTINE, FUNCTION, BLOCK DATA or PROGRAM subprogram.

Fortran source consists of a sequence of modules which are to be compiled into object modules. Every module consists of statements and optionally comments beginning with the module statement, either a SUBROUTINE, FUNCTION, BLOCK DATA or PROGRAM statement, and finishing with an END statement.

In the absence of a module statement, the compiler will insert a PROGRAM statement.

1.1.1 Statements and Comments

Statements are either executable statements or specification statements. Each statement consists of a single line or source record, possibly followed by one or more continuation lines. Comments may appear anywhere in the source.

To append a comment to a Fortran statement line, follow the line with an exclamation mark, '!' followed by the comment on the same line. @

1.1.2 Debug Statements

The letter "D" in column 1 designates the statement on that line to be a debugging statement. The compiler will treat the debugging statement as a comment unless the command line option -Mdlines is set during the compilation. In that case, the compiler acts as if the "D" were a blank and compiles the line according to the standard rules.

1.1.3 Statement Ordering

The rules defining the order in which statements appear in a program unit have been relaxed, as compared to the ANSI standard, as follows:

1.2 The Fortran Character Set

Table 1-1 shows the Fortran character set. Character variables and constants can use any ASCII character.

A-Z, a-z
space character
left parenthesis
right parenthesis
underscore character
decimal point
exclamation mark
tabulation character
carriage return
Table 1-2 shows C language character escape sequences that are recognized in pgf77 Fortran character string constants.[*]

vertical tab
alert (bell)
carriage return
apostrophe (does not terminate a string)
double quotes (does not terminate a string)
x, where x is any other character
character with the given octal representation.

1.3 Formatting

A Fortran record may be formatted with tabs or by column formatting.

1.3.1 Column Formatting

A Fortran record consists of a sequence of up to 73 ASCII characters, the last being <CR>. There is a fixed layout as shown in Table 1-3.

Label field
Continuation field
Statement field

Characters beyond position 72 on a line are ignored.[*]

1.3.2 Tab Formatting @

A tab formatted record consists of up to 72 ASCII characters. It is made up of a label field, an optional continuation indicator and a statement field. The label field is terminated by a tab character. The label cannot be more than 5 characters.

A continuation line is indicated by a tab character followed immediately by a digit. The statement field starts after a continuation indicator, when one is present. The 73rd and subsequent characters are ignored.*

1.3.3 Label Field

The label field holds up to five characters. The characters C or * in the first character position of a label field indicate a comment line.

In addition, to C or *, either of the characters D or ! in the first character position of a label field also indicate a comment line. @

When a numeric field drawn from digits 0 to 9 is placed in the label field, the field is a label. A line with no label, and with five space characters or a <TAB> (the tab is an extention @ ) in the label field, is an unlabeled statement. Each label must be unique in its module. Continuation lines must not be labeled. Labels can only be jumped to when they are on executable statements.

1.3.4 Continuation Field

The sixth character position, or the position after the tab, is the continuation field. This field is ignored in comment lines. It is invalid if the label field is not five spaces. A value of 0, <space> or <TAB> indicates the first line of a statement. Any other value indicates a subsequent (continuation) line to the preceding statement.

1.3.5 Statement Field

This consists of valid identifiers and symbols, possibly separated by <space> or <TAB> and terminated by <CR>.

Within the statement field tabs and spaces are ignored as are characters following a ! or beyond the 72nd character.[*] @

1.3.6 Including Fortran Source Files

The sequence of consecutive compilation of source statements may be interrupted so that an extra source file can be included. This is carried out using the INCLUDE statement which takes the following form:

INCLUDE "filename"
where filename is the name of the file to be included. Pairs of either single or double quotes are acceptable enclosing filename.

The INCLUDE file is compiled to replace the INCLUDE statement, and on completion of that source the file is closed and compilation continues with the statement following the INCLUDE.

INCLUDE files are especially recommended when the same COMMON blocks and the same COMMON block data mappings are used in several modules.

For example the following statement includes the file MYFILE.CMN.


1.3.7 Input File Format Summary of Extensions @

Input source file format has been extended from Fortran 77 to allow the following extensions:

1.4 The Components of Fortran Statements

Fortran modules are made up of statements which consist of expressions and elements. An expression can be broken down to simpler expressions and eventually to its elements combined with operators. Hence the basic building block of a statement is an element. An element takes one of the following forms:

1.4.1 Symbolic Names

Symbolic names identify different entities in Fortran source. A symbolic name is a string of letters and digits, which must start with a letter and is terminated by a character not in the symbolic names set (for example a <space> or a <TAB> character). Underscore (_) characters may appear within symbolic names. Symbolic names may start with a dollar sign ($) or underscore (_) character (this is a pgf77 extension). Only the first thirty-one characters identify the symbol. Below are several symbolic names:

The last example is identified by its first 31 characters and is equivalent to:
The following are examples are invalid symbolic names.
This is invalid because it begins with a number.
This is invalid because it contains a period which is an invalid character.

1.4.2 Symbolic Name Scope

Symbolic names may be declared locally or globally.

Names of COMMON blocks, SUBROUTINEs and FUNCTIONs are global to those modules that reference them. They must refer to unique objects, not only during compilation, but also in the link stage.

The scope of names other than these is local to the module in which they occur, and any reference to the name in a different module will imply a new local declaration. This includes the arithmetic function statement.

1.5 Expressions

Each data item, such as a variable or a constant, represents a particular value at any point during program execution. These elements may be combined together to form expressions, using binary or unary operators, so that the expression itself yields a value.

An expression is formed as:

expr binary-operator expr
unary-operator expr
where an expr is formed as
expression or element
For example,
These are simple expressions whose components are elements. Expressions fall into one of four classes: arithmetic, relational, logical or character.

1.5.1 Arithmetic Expressions

Arithmetic expressions are formed from arithmetic elements and arithmetic operators. An arithmetic element may be:

The arithmetic operators specify a computation to be performed on the elements. The result is a numeric result. Table 1-4 shows the arithmetic operators.

Note that a value should be associated with a variable or array element before it is used in an expression. Arithmetic expressions are evaluated in an order determined by a precedence associated with each operator. Table 1-5 shows the precedence of each arithmetic operator.

This following example is resolved into the arithmetic expressions (A) + (B * C) rather than (A + B) * (C).

A + B * C
Normal ranked precedence may be overcome using parentheses which force the item(s) enclosed to be evaluated first.
(A + B) * C
The compiler resolves this into the expressions (A + B) * (C).

Addition or unary plus
Subtraction or unary minus

* and /
+ and -

The type of an arithmetic expression is:


if it contains only integer elements.
if it contains only real and integer elements.
if it contains only double precision, real and integer elements.
if any element is complex. Any element which needs conversion to complex will be converted by taking the real part from the original value and setting the imaginary part to zero.

if any element is double complex.

1.5.2 Relational Expressions

A relational expression is composed of two arithmetic expressions separated by a relational operator. The value of the expression is true or false (.TRUE. or .FALSE.) depending on the value of the expressions and the nature of the operator.

Table 1-6 shows the relational operators.

Less than
Less than or equal to
Equal to
Not equal to
Greater than
Greater than or equal to

In relational expressions the arithmetic elements are evaluated to obtain their values. The relationship is then evaluated to obtain the true or false result. Thus the relational expression:

means if the sum of TIME and MEAN is less than the value of LAST, then the result is true, otherwise it is false.

1.5.3 Logical Expressions

A logical expression is composed of two relational or logical expressions separated by a logical operator. Each logical expression yields the value true or false (.TRUE. or .FALSE.) .

Table 1-7 shows the logical operators.

True if both expressions are true.
True if either expression or both is true.
This is a unary operator; it is true if the expression is false, otherwise it is false.
False if both expressions have the same logical value
Same as .NEQV.
True if both expressions have the same logical value

In the following example, TEST will be .TRUE. if A is greater than B or I is not equal to J+17.

TEST = A .GT. B .OR. I .NE. J+17

1.5.4 Character Expressions

An expression of type CHARACTER can consist of one or more printable characters. Its length is the number of characters in the string. Each character is numbered consecutively from left to right beginning with 1. For example:


1.5.5 Character Concatenation

A character expression can be formed by concatenating two (or more) valid character expressions using the concatenation operator //.

Table 1-8 shows several examples of concatenation

'J '//'JAMES '//'JOY'

1.6 Precedence Rules

Arithmetic, relational and logical expressions may be identified to the compiler by the use of parentheses, as described in the section on arithmetic expressions. When no guidance is given to the compiler it will impose a set of precedence rules to identify each expression uniquely. Table 1-9 shows the operator precedence rules for expressions.

* and /
+ and -
Relational operators
.NEQV. and .EQV.
Operators of equal rank are evaluated left to right. Thus:
	 A*B+B**C .EQ. X+Y/Z .AND. .NOT. K-3.0 .GT. T 
is equivalent to:
	((((A*B)+(B**C)) .EQ. (X+(Y/Z))) .AND. (.NOT. ((K-3.0) .GT. T)))

1.7 Assignment Statements

A Fortran assignment statement can be any of the following:

1.7.1 Arithmetic Assignment

The arithmetic assignment statement has the following form:

object = arithmetic-expression
where object is one of the following: The type of object determines the type of the assignment (INTEGER, REAL, DOUBLE PRECISION or COMPLEX) and the arithmetic-expression is coerced into the correct type if necessary.

In the case of:

complex = real expression
the implication is that the real part of the complex number becomes the result of the expression and the imaginary part becomes zero. The same applies if the expression is double precision, except that the expression will be coerced to real.

The following are examples of arithmetic assignment statements.


1.7.2 Logical Assignment Statement

The logical assignment statement has the following form:

object = logical-expression
where object is one of the following: The type of object must be logical.

In the following example, FLAG takes the logical value .TRUE. if P+Q is greater than R; otherwise FLAG has the logical value .FALSE.


1.7.3 Character assignment

The form of a character assignment is

object = character expression
where object is one of the following: Above, object must be of type character.

None of the character positions being defined in object can be referenced in the character expression and only such characters as are necessary for the assignment to object need to be defined in the character expression. The character expression and object can have different lengths. When object is longer than the character expression trailing blanks are added to the object ; and if object is shorter than the character expression the righthand characters of the character expression are truncated as necessary.

In the following example, note that all the variables and arrays are assumed to be of type character.

PLOT(3:8) = 'PLANTS'
TEXT(I,K+1)(2:B-1) = TITLE//X

1.8 Listing Controls

The compiler, pgf77, recognizes three VAX/VMS compiler directives that affect the program listing process:

Turns on the listing process beginning at the following source code line.
Turns off the listing process (including the %NOLIST line itself).
Causes a new listing page to be started.
These directives have an affect only when the -Mlist driver option is used.

All of the directives must begin in column one.

[*] The pgf77 option -Mbackslash enables and disables this enhancement.

[*] Extended lines containing up to 132 characters are valid. For information on the extend option, refer to the description of -Mextend in the pgf77 User's Guide.

[*] Extended lines containing up to 132 characters are valid. For information on the extend option, refer to the description of -Mextend in the pgf77 User's Guide.

<< >> Title Contents Index Home Help