Skip to content. Skip to navigation

ICTP Portal

Sections
You are here: Home Manuals on-line PGI Compiler pgf77_ref PGF77 Workstation Reference Manual - 1 Language Overview
Personal tools
Document Actions

PGF77 Workstation Reference Manual - 1 Language Overview

<< << " border=0> >> > " border=0> 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:

  • DATA statements can be freely interspersed with PARAMETER statements and other specification statements.
  • NAMELIST statements are supported and have the same order requirements as FORMAT and ENTRY statements.
  • The IMPLICIT NONE statement can precede other IMPLICIT statements.

1.2 The Fortran Character Set

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

Character
Description
A-Z, a-z
alphabetic
0-9
numeric
<space>
space character
=
equals
+
plus
-
minus
*
asterisk
/
slash
(
left parenthesis
)
right parenthesis
,
comma
_
underscore character
.
decimal point
!
exclamation mark
<TAB>
tabulation character
<CR>
carriage return
Table 1-2 shows C language character escape sequences that are recognized in pgf77 Fortran character string constants.[*]

Character
Description
\v
vertical tab
\a
alert (bell)
\n
newline
\t
tab
\b
backspace
\f
formfeed
\r
carriage return
\0
null
\'
apostrophe (does not terminate a string)
\"
double quotes (does not terminate a string)
\\
\
\x
x, where x is any other character
\ddd
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.

Position
Field
1-5
Label field
6
Continuation field
7-72
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.

INCLUDE "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:

  • A continuation line may also be indicated by using an ampersand (&) in column one of a line.
  • Tab-Format lines are supported. A tab in columns 1-6 ends the statement label field and begins an optional continuation indicator field. If a non-zero digit follows the tab character, the continuation field exists and indicates a continuation field. If anything other than a non-zero digit follows the tab character, the statement body begins with that character and extends to the end of the source statement. Note that this does not override Fortran 77's source line handling since no valid Fortran statement can begin with a non-zero digit. The tab character is ignored if it occurs in a line except in Hollerith or character constants.
  • Input lines may be of varying lengths. If there are fewer than 72 characters, the line is padded with blanks; characters after the 72nd are ignored unless you use the -Mextend option on the command line.
  • If the -Mextend option is used on the command line then the input line can extend to 132 characters. The line is padded with blanks if it is fewer than 132; characters after the 132nd are ignored. Note that use of this option extends the statement field to position 132.
  • Blank lines are allowed at the end of a program unit.
  • The number of continuation lines allowed is extended to 99.

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:

  • A constant represents a fixed value.
  • A variable represents a value which may change during program execution.
  • An array is a group of values, stored contiguously, that can be referred to as a whole or separately. The separate values are known as the elements of the array. The array has a symbolic name.
  • A function reference is the name of a function followed by an argument list. The reference causes the code specified at function definition to be executed and the result substituted for the function reference.

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:

NUM
CRA9
Y
numericabcdefghijklmnopqrstuvwxyz	
The last example is identified by its first 31 characters and is equivalent to:
numericabcdefghijklmnopqrstuvwx	
The following are examples are invalid symbolic names.
8Q	
This is invalid because it begins with a number.
FIVE.4	
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
or
unary-operator expr
where an expr is formed as
expression or element
For example,
A+B
-C
+D
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:

  • an arithmetic expression
  • a variable
  • a constant
  • an array element
  • a function reference

  • * a field of a structure @
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).

Operator
Function
**
Exponentiation
*
Multiplication
/
Division
+
Addition or unary plus
-
Subtraction or unary minus

Operator
Precedence
**
First
* and /
Second
+ and -
Third

The type of an arithmetic expression is:

INTEGER

if it contains only integer elements.
REAL
if it contains only real and integer elements.
DOUBLE
PRECISION
if it contains only double precision, real and integer elements.
COMPLEX
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.
DOUBLE COMPLEX @

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.

Operator
Relationship
.LT.
Less than
.LE.
Less than or equal to
.EQ.
Equal to
.NE.
Not equal to
.GT.
Greater than
.GE.
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:

TIME + MEAN .LT. LAST
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.

Operator
Relationship
.AND.
True if both expressions are true.
.OR.
True if either expression or both is true.
.NOT.
This is a unary operator; it is true if the expression is false, otherwise it is false.
.NEQV.
False if both expressions have the same logical value
.XOR.
Same as .NEQV.
.EQV.
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:

 'ab_&'
'A@HJi2'
'var[1,12]'

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

Expression
Value
'ABC'//'YZ'
"ABCYZ"
'JOHN '//'SMITH'
"JOHN SMITH"
'J '//'JAMES '//'JOY'
"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.

Operator
Evaluated
**
First
* and /
Second
+ and -
Third
Relational operators
Fourth
.NOT.
Fifth
.AND.
Sixth
.OR.
Seventh
.NEQV. and .EQV.
Eighth
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:

  • An arithmetic assignment
  • A logical assignment
  • A character assignment
  • A statement label assignment

  • * A structure field assignment (if the field is a scalar data type) @

1.7.1 Arithmetic Assignment

The arithmetic assignment statement has the following form:

object = arithmetic-expression
where object is one of the following:
  • Variable
  • Function name (within a function body)
  • Subroutine argument
  • Array element
  • Field of a structure
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.

A=(P+Q)*(T/V)
B=R**T**2

1.7.2 Logical Assignment Statement

The logical assignment statement has the following form:

object = logical-expression
where object is one of the following:
  • Variable
  • Function name (only within the body of the function)
  • Subroutine argument
  • Array element
  • A field of a structure
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.

FLAG=(P+Q) .GT. R

1.7.3 Character assignment

The form of a character assignment is

object = character expression
where object is one of the following:
  • Variable
  • Function name (only within the body of the function)
  • Subroutine argument
  • Array element
  • Character substring
  • A field of a structure
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.

FILE = 'BOOKS'
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:

%LIST
Turns on the listing process beginning at the following source code line.
%NOLIST
Turns off the listing process (including the %NOLIST line itself).
%EJECT
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.


<< << " border=0> >> > " border=0> Title Contents Index Home Help
Weather
No information available
 

Powered by Plone This site conforms to the following standards: