|Fortran 77 Language Reference|
Elements of FORTRAN
This chapter introduces the basic elements of Sun WorkShop FORTRAN 77.
f77was designed to be compatible with the ANSI X3.9-1978 FORTRAN standard and the corresponding International Organization for Standardization (ISO) 1539-1980, as well as standards FIPS 69-1, BS 6832, and MIL-STD-1753. (This is no longer the current Fortran standard.)
- Floating-point arithmetic for both compilers is based on IEEE standard 754-1985, and international standard IEC 60559:1989.
- On SPARC platforms, both compilers provide support for the optimization-exploiting features of SPARC V8, and SPARC V9, including the UltraSPARCTM implementation. These features are defined in the SPARC Architecture Manuals, Version 8 (ISBN 0-13-825001-4), and Version 9 (ISBN 0-13-099227-5), published by Prentice-Hall for SPARC International.
- In this document, "Standard" means conforming to the versions of the standards listed above. "Non-standard" or "Extension" refers to features that go beyond these versions of these standards.
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 Fortran compilers that create incompatibilities with earlier releases.
Extensions to the standard FORTRAN 77 language include recursion, pointers, double-precision complex, quadruple-precision real, quadruple-precision complex, and many VAXTM and VMSTM FORTRAN 5.0 extensions, including
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
f77that are not part of the applicable standards mentioned in Standards Conformance are flagged with the special character mark throughout this manual.
Some of the FORTRAN basic terms and concepts are:
- A program consists of one or more program units.
- A program unit is a sequence of statements, terminated by an END.
- A statement consists of zero or more key words, symbolic names, literal constants, statement labels, operators, and special characters.
- Each key word, symbolic name, literal constant, and operator consists of one or more characters from the FORTRAN character set.
- A character constant can include any valid ASCII character.
- A statement label consists of 1 to 5 digits, with at least one nonzero.
The character set consists of the following:
- Uppercase and lowercase letters, A - Z and a - z
- Numerals 0 - 9
- Special characters--The following table shows the special characters that are used for punctuation:
TABLE 1-1 Special Character Usage Space Space Ignored in statements, except as part of a character constant Tab Tab Establish the line as a tab-format source line
Plus Add, unary operator
Minus Subtract, unary operator
Asterisk Multiply, alternate returns, comments, exponentiation,
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
Colon Array declarators, substrings, edit descriptor
Percent Special functions:
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:
- Uppercase or lowercase is not significant in the key words of FORTRAN statements or in symbolic names. The
f77makes case significant in symbolic names.
- Most control characters are allowed as data even though they are not in the character set. The exceptions are: Control
C, which are not allowed as data. These characters can be entered into the program in other ways, such as with the
- Any ASCII character is valid as literal data in a character string.
- For the backslash (\) character, you may need to use an escape sequence or use the
-xlcompiler option. For the newline (\
n) character, you must use an escape sequence. See also TABLE 2-3.
The items in the following table can have symbolic names:
TABLE 1-2 Items with Symbolic Names Symbolic constants
Structures Records Record fields
Namelist groups Main programs
The following restrictions apply:
- Symbolic names can be any number of characters long . The standard is 6.
- Symbolic names consist of letters, digits, the dollar sign (
$), and the underscore character (
_are not standard.
- Symbolic names generally start with a letter--never with a digit or dollar sign (
$). Names that start with an underscore (
_) are allowed, but may conflict with names in the Fortran and system libraries.
Note Procedure names that begin with exactly two underscores are considered special support functions internal to the compiler. Avoid naming functions or subroutines with exactly two initial underscores (for example
_xfunc) as this will conflict with the compiler's usage.
- Uppercase and lowercase are not significant; the compiler converts them all to lowercase. The
-Uoption on the
f77command line overrides this default, thereby preserving any uppercase used in your source file.
- Example: These names are equivalent:
IF ( X .LT. ATAD ) GO TO 9IF ( X .LT. A TAD ) GO TO 9IF(X.LT.ATAD)GOTO9
- Here are some sample symbolic names:
TABLE 1-3 Sample Symbolic Names X2 2X Starts with a digit. DELTA_TEMP
Starts with an
_(reserved for the compiler).
Y$Dot Y|Dot There is an invalid character
- In general, for any single program unit, different entities cannot have the same symbolic name. The exceptions are:
- A variable or array can have the same name as a common block.
- A field of a record can have the same name as a structure.
- A field of a record can have the same name as a field at a different level of the structure.
- Throughout any program of more than one programming unit, no two of the following can have the same name:
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.
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.
TABLE 1-4 FORTRAN Statements
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:
- The first 72 columns of each line are scanned. See Extended Lines.
- The first five columns must be blank or contain a numeric label.
- Continuation lines are identified by a nonblank, nonzero in column 6.
- Short lines are padded to 72 characters.
- Long lines are truncated. See Extended Lines.
The tab-format source lines are defined as follows:
- A tab in any of columns 1 through 6, or an ampersand in column 1, establishes the line as a tab-format source line.
- If the tab is the first nonblank character, the text following the tab is scanned as if it started in column 7.
- A comment indicator or a statement number can precede the tab.
- Continuation lines are identified by an ampersand (
&) in column 1, or a nonzero digit after the first tab.
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
To extend the source line length to 132 characters, use the
-eoption. Otherwise, by default,
f77ignores any characters after column 72.
Comments and Blank Lines
A line with a c, C, *, d, D, or! in column one is a comment line, except that if the
-xldoption is set, then the lines starting with D or d are compiled as debug lines. The
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.
!, 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
CALL TOLOWER ! To lowercase EoL comment
D PRINT *, N! Debug comment & EoL comment
! expression analyzer
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 WorkShop Fortran User's Guide and the Fortran Programming Guide for details on the specific directives available with
The form of a general directive is one of the following:
The variable id identifies the directive keyword; a is an argument.
A directive has the following syntax:
- In column one, any of the comment-indicator characters
- In any column, the
- The next 7 characters are
$PRAGMA, no blanks, any uppercase or lowercase
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$PRAGMAlines, 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 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
-explicitparare used. (
f77parallelization options are described in the Fortran Programming Guide.)
Parallelization directives have the following syntax:
- The first character must be in column one.
- The first character can be any one of
- The next four characters are
$PAR, no blanks, either upper or lower case.
- Next follows the directive keyword and options, separated by blanks.
- The explicit parallelization directive keywords are:
TASKCOMMON, DOALL, DOSERIAL,and
Each parallelization directive has its own set of optional qualifiers that follow the keyword.
See the Fortran Programming Guide for details about parallelization and these directives. Fortran parallelization features require a Sun WorkShop HPC license.
Sun Microsystems, Inc.
Copyright information. All rights reserved.
|Library | Contents | Previous | Next | Index|