Elements of FORTRAN |
1 |
![]() |
This chapter introduces the basic elements of Sun FORTRAN 77.
The Sun FORTRAN 77 compiler f77 is an enhanced FORTRAN development system. It conforms to the ANSI X3.9-1978 FORTRAN standard and the corresponding International Standards Organization number is ISO 1539-1980. NIST (formerly GSA and NBS) validates it at appropriate intervals.
This compiler also conforms to the standards FIPS 69-1, BS 6832, and MIL-STD-1753. It provides an IEEE standard 754-1985 floating-point package. On SPARC systems, it provides support for optimization exploiting features of SPARC V8, including the SuperSPARCTM implementation. These features are defined in the SPARC Architecture Manual: Version 8.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.
Some of the FORTRAN basic terms and concepts are:
The character set consists of the following:
Note the following usage and restrictions:
B
, Control C
,
which are not allowed as data. These characters can be entered into the program
in other ways, such as with the char() function. 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 Subroutines Functions Entry points |
The following restrictions apply:
ATAD = 1.0E-6 Atad = 1.0e-6 |
IF ( X .LT. ATAD ) GO TO 9 IF ( X .LT. A TAD ) GO TO 9 IF(X.LT.ATAD)GOTO9 |
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 |. |
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.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.
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.The asterisk (*) in the table indicates an executable statement.
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:The standard fixed format source lines are defined as follows:
The tab-format source lines are defined as follows:
You can format lines both ways in one program unit, but not in the same line.
The default maximum number of continuation lines is 99 (1
initial and 99 continuation). To change this number of lines, use the -Nln
option.
To extend the source line length to 132 characters, use the -e option. Otherwise, by default, f77 ignores any characters
after column 72.
demo% f77 -e prog.f |
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 / |
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.
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:
The form of a general directive is one of the following:
The variable id identifies the kind of directive; a is an argument.
A directive has the following syntax:
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.The C() directive specifies that its arguments are external functions written in the C language. It is equivalent to an EXTERNAL declaration with the addition that the f77 compiler does not append an underscore to such names, as it ordinarily does with external names.
The C() directive for a particular function must appear before the first reference to that function in each subprogram that contains such a reference. The recommended usage is:EXTERNAL ABC, XYZ !$PRAGMA C(ABC, XYZ) |
The unroll directive requires that you specify sun after C$PRAGMA.
The C$PRAGMA sun unroll=n directive allows the optimizer to unroll loops n times, where n is a positive integer. The choices are:Loops are only unrolled if deemed profitable by the optimizer. If any loops are actually unrolled, then the executable file becomes larger. For a discussion of loop unrolling, see the Sun Fortran: Programmer's Guide chapter Performance and Optimization.
Example: To unroll loops two times:C$PRAGMA SUN UNROLL=2 |
WEAK
Directive The WEAK
directive defines a symbol to have less precedence than an
earlier definition of the same symbol. This pragma is used mainly in sources files for
building libraries. The linker does not produe an error message if it is unable to resolve
a weak symbol.
C$PRAGMA WEAK (name1 [=name2]) |
WEAK (
name1=
name2)
defines name1 to be a weak symbol and an alias for name2.
See the Sun Fortran User's Guide and the Solaris Linker and Libraries Guide for more information.
A parallel directive is a special comment that directs the compiler to do something about parallelization. The following are the parallel directives:
For syntax and other information on parallel directives, see the chapter on parallelization in the Fortran Programmer's Guide.