FORTRAN 77 Language Reference

Chapter 1 Elements of FORTRAN

This chapter introduces the basic elements of Sun FORTRAN 77.

Standards Conformance

The responsible standards bodies may revise these standards from time to time. The versions of the applicable standards to which these compilers conform may be revised or replaced, resulting in features in future releases of the Sun Fortran compilers that create incompatibilities with earlier releases.

Extensions

Extensions to the standard FORTRAN 77 language include recursion, pointers, double-precision complex, quadruple-precision real, quadruple-precision complex, and many VAX® and VMS® FORTRAN 5.0 extensions, including NAMELIST, DO WHILE, structures, records, unions, maps, and variable formats. Multiprocessor FORTRAN includes automatic and explicit loop parallelization.

Sun FORTRAN 77 accepts many VMS extensions, so that programs originally written for VAX systems will port easily to Solaris.

Features implemented in Sun f77 that are not part of the applicable standards mentioned in "Standards Conformance" are flagged with the special character mark @@ throughout this manual.

Basic Terms

Some of the FORTRAN basic terms and concepts are:

Character Set

The character set consists of the following:

Table 1-1 Special Character Usage

Character 

Name 

Usage  

Space  

Space 

Ignored in statements, except as part of a character constant  

Tab  

Tab 

Establish the line as a tab-format source line @

=

Equals 

Assignment  

+

Plus 

Add, unary operator  

-

Minus 

Subtract, unary operator  

*

Asterisk 

Multiply, alternate returns, comments, exponentiation, stdin, stdout, list-directed I/O

/

Slash 

Divide, delimit data, labeled commons, structures, end-of-record  

( )

Parentheses 

Enclose expressions, complex constants, equivalence, parameter, or implicit groups, formats, argument lists, subscripts  

,

Comma 

Separator for data, expressions, complex constants, equivalence groups, formats, argument lists, subscripts  

.

Period 

Radix point, delimiter for logical constants and operators, record fields 

'

Apostrophe 

Quoted character literals  

"

Quote 

Quoted character literals, octal constants @

$

Dollar sign 

Delimit namelist input, edit descriptor, directives @

!

Exclamation 

Comments @

:

Colon 

Array declarators, substrings, edit descriptor  

%

Percent 

Special functions: %REF, %VAL, %LOC @

&

Ampersand 

Continuation, alternate return, delimit namelist input; use in column 1 establishes the line as a tab-format source line @ 

?

Question mark 

Request names in namelist group@ 

\

Backslash 

Escape character @ 

 < >

Angle brackets 

Enclose variable expressions in formats @ 

Note the following usage and restrictions:

Symbolic Names

The items in the following table can have symbolic names:

Table 1-2 Items with Symbolic Names

Symbolic constants 

Variables 

Arrays 

Structures @ 

Records @ 

Record fields @ 

Labeled commons 

Namelist groups @ 

Main programs  

Block data 

Subroutines  

Functions  

Entry points  

The following restrictions apply:

Table 1-3 Sample Symbolic Names

Valid 

Invalid 

Reason  

X2

2X

Starts with a digit. 

DELTA_TEMP

_DELTA_TEMP

Starts with an _ (reserved for the compiler).

Y$Dot

Y|Dot

There is an invalid character |.

Program Units

A program unit is a sequence of statements, terminated by an END statement. Every program unit is either a main program or a subprogram. If a program is to be executable, it must have a main program.

There are three types of subprograms: subroutines, functions, and block data subprograms. The subroutines and functions are called procedures, which are invoked from other procedures or from the main program. The block data subprograms are handled by the loader.

Statements

A statement consists of one or more key words, symbolic names, literal constants, and operators, with appropriate punctuation. In FORTRAN, no keywords are reserved in all contexts. Most statements begin with a keyword; the exceptions are the statement function and assignment statements.

Executable and Nonexecutable Statements

Every statement is either executable or nonexecutable. In general, if a statement specifies an action to be taken at runtime, it is executable. Otherwise, it is nonexecutable.

The nonexecutable statements specify attributes, such as type and size; determine arrangement or order; define initial data values; specify editing instructions; define statement functions; classify program units; and define entry points. In general, nonexecutable statements are completed before execution of the first executable statement.

FORTRAN Statements

Table 1-4 FORTRAN Statements

ACCEPT*

ASSIGN*

Assignment*

AUTOMATIC

BACKSPACE*

BLOCK DATA

BYTE

CALL*

CHARACTER

CLOSE*

COMMON

COMPLEX

CONTINUE*

DATA

DECODE*

DIMENSION

DO*

DO WHILE*

DOUBLE COMPLEX

DOUBLE PRECISION

ELSE*

ELSE IF*

ENCODE*

END*

END DO*

END FILE*

END IF*

END MAP

END STRUCTURE

END UNION

ENTRY

EQUIVALENCE

EXTERNAL

FORMAT

FUNCTION

GOTO*

GOTO (Assigned)*

GOTO (Unconditional)*

IF (Arithmetic)*

IF (Block)*

IF (Logical)*

IMPLICIT

INCLUDE

INQUIRE*

INTEGER

INTRINSIC

LOGICAL

MAP

NAMELIST

OPEN*

OPTIONS

PARAMETER

PAUSE*

POINTER

PRINT*

PRAGMA

PROGRAM

REAL

RECORD

RETURN*

REWIND*

SAVE

Statement Function

STATIC*

STOP*

STRUCTURE

SUBROUTINE

TYPE

UNION

VIRTUAL

VOLATILE

WRITE*

The asterisk (*) in the table indicates an executable statement.

Source Line Formats

A statement takes one or more lines; the first line is called the initial line; the subsequent lines are called the continuation lines.

You can format a source line in either of two ways:

Standard Fixed Format

The standard fixed format source lines are defined as follows:

Tab-Format

The tab-format source lines are defined as follows: @

Mixing Formats

You can format lines both ways in one program unit, but not in the same line.

Continuation Lines

The default maximum number of continuation lines is 99 @ (1 initial and 99 continuation). To change this number of lines, use the -Nln option. @

Extended Lines

To extend the source line length to 132 characters, use the -e option.@ Otherwise, by default, f77 ignores any characters after column 72.

Example: Compile to allow extended lines:


demo% f77 -e prog.f 

Padding

Padding is significant in lines such as the two in the following DATA statement:


C        1         2         3         4         5         6         7
C23456789012345678901234567890123456789012345678901234567890123456789012
      DATA SIXTYH/60H
     1                              /

Comments and Blank Lines

A line with a c, C, *, d, D, or! in column one is a comment line, except that if the -xld option is set, then the lines starting with D or d are compiled as debug lines. The d, D, and! are nonstandard. @

If you put an exclamation mark (!) in any column of the statement field, except within character literals, then everything after the ! on that line is a comment. @

A totally blank line is a comment line.

Example: c, C, d, D, *,!, and blank comments:


c      Start expression analyzer 
       CHARACTER S, STACK*80 
       COMMON /PRMS/ N, S, STACK 
       ... 
*      Crack the expression:
       IF ( S .GE. '0' .AND. S .LE. '9' ) THEN ! EoL comment 
              CALL PUSH        ! Save on stack. EoL comment 
d             PRINT *, S       ! Debug comment & EoL comment 
       ELSE 
              CALL TOLOWER ! To lowercase EoL comment 
       END IF 
D      PRINT *, N!       Debug comment & EoL comment 
       ... 
C      Finished 
!       expression analyzer

Directives

A directive passes information to a compiler in a special form of comment. @ Directives are also called compiler pragmas. There are two kinds of directives:

See the Sun Fortran User's Guide and the Fortran Programming Guide for details on the specific directives available with f77.

General Directives

The form of a general directive is one of the following:@

The variable id identifies the directive keyword; a is an argument.

Syntax

A directive has the following syntax:

Rules and Restrictions

After the first eight characters, blanks are ignored, and uppercase and lowercase are equivalent, as in FORTRAN text.

Because it is a comment, a directive cannot be continued, but you can have many C$PRAGMA lines, one after the other, as needed.

If a comment satisfies the above syntax, it is expected to contain one or more directives recognized by the compiler; if it does not, a warning is issued.

Parallelization Directives

Parallelization directives explicitly request the compiler attempt to parallelize the DO loop that follows the directive. The syntax differs from general directives. Parallelization directives are only recognized when compilation options --parallel or --explicitpar are used. (f77 parallelization options are described in the Fortran User's Guide.)

Parallelization directives have the following syntax:

Each parallelization directive has its own set of optional qualifiers that follow the keyword.

Example: Specifying a loop with a shared variable:


C$PAR DOALL SHARED(yvalue)

See the Fortran Programming Guide for details about parallelization and these directives.