Chapter 3. Language Elements and Source Form

This chapter describes the language elements that a Fortran statement can contain. Language elements consist of lexical tokens, which include names, keywords, operators, and statement labels. Rules for forming lexical tokens from the characters in the Fortran character set are also presented.

CF90 and MIPSpro 7 Fortran 90 Character Set

The CF90 and MIPSpro 7 Fortran 90 character sets contain the following characters:

  • The Fortran character set, which includes the 26 uppercase letters of the alphabet, the corresponding 26 lowercase letters, and several special characters.

  • The numerical digits 0, 1, 2, 3, 4, 5, 6, 7, 8, 9.

  • The underscore character (_).

  • The newline and tab characters, which are control characters and have no graphic representation. These characters are part of the processor-dependent control characters as allowed by the standard.

Table 3-1, shows the special characters of the CF90 and MIPSpro 7 Fortran 90 character sets.

Table 3-1. CF90 and MIPSpro 7 Fortran 90 special characters

Graphic

Character name

Graphic

Character name

 

Blank

:

Colon

=

Equals

!

Exclamation point

+

Plus

"

Quotation mark

-

Minus

%

Percent

*

Asterisk

&

Ampersand

/

Slash

;

Semicolon

(

Left parenthesis

<

Less than

)

Right parenthesis

>

Great than

,

Comma

?

Question mark

'

Apostrophe

$

Currency symbol

@

At sign[a]

.

Decimal point or period

[a] Use of the at sign (@) differs depending on your hardware platform. On UNICOS and UNICOS/mk systems, the compiler allows you to use the at sign (@) in certain cases; these cases are described in “Names”. Use of the @ symbol is not permitted on IRIX systems.



Note: The at sign (@) is not included in the Fortran character set. The newline and tab characters are not part of the graphic character set as defined by the standard, but the standard allows them as part of the processor-dependent control character set.



Note: : The MIPSpro 7 Fortran 90 compiler does not support the at sign (@) on IRIX systems.

The 52 letters define the syntax class letter.

In most cases, the compiler is not case sensitive; lowercase letters are considered the same as uppercase letters. In the following cases, however, lowercase and uppercase letters are considered to have different data values:

  • Within a character constant

  • Within a quotation mark, apostrophe, or H edit descriptor

  • Within a Hollerith constant (nonstandard)


Note: Hollerith data is not included in the Fortran standard.

The CF90 and MIPSpro 7 Fortran 90 compilers consider the following two statements to be equivalent:

PRINT *, N
Print *, n

The CF90 and MIPSpro 7 Fortran 90 compilers distinguish between uppercase and lowercase letters in the FILE= or NAME= specifier in an OPEN or an INQUIRE statement.

The digits 0 through 9 define the syntax class digit. The digits are assumed to be decimal numbers when used to describe a numeric value, except in binary, octal, and hexadecimal (BOZ) literal constants or input/output (I/O) records corresponding to B, O, or Z edit descriptors.

For example, in the following DATA statement, the digits of the first constant are decimal digits, those of the second constant are binary digits, and those of the third are hexadecimal digits:

DATA  X, I, J / 4.89, B'1011', Z'BAC91' /

The underscore can be used to make names more readable. For example, in the identifier NUMBER_OF_CARS, each underscore is used to separate the obvious English words. It is a significant character in any name. An underscore cannot be used as the first character of a name, but it can be the last character. An underscore is also used to separate the kind value from the actual value of a literal constant (for example, 123_2).

There are 22 special characters used for operators like multiply and add. They are also used as separators or delimiters in Fortran statements. Separators and delimiters make the form of a statement unambiguous.


Note: On UNICOS and UNICOS/mk systems, the at sign (@) can be used in an identifier in the same way that you would use an underscore (_). The at sign cannot be used as the first character in an identifier. Using the at sign is not recommended because it is reserved for internal use.



Note: : The MIPSpro 7 Fortran 90 compiler does not support the at sign (@).

Fortran's treatment of uppercase and lowercase letters can lead to portability problems when calling subprograms written in other languages. The problem occurs because the standard does not specify the case of letters used for external names. The following program fragment illustrates the problem:

EXTERNAL  FOO
  . . .
CALL  FOO
  . . .
END 

The CF90 compiler uses uppercase for external names, so the CF90 compiler would use FOO as the external name. The MIPSpro 7 Fortran 90 compiler converts external names into lowercase and appends an underscore, so the MIPSpro 7 Fortran 90 compiler would use foo_ as the external name. If the subprogram were written in C, which is case sensitive, and if foo were written in lowercase, the external name used in C would then be different from the name produced by the CF90 or MIPSpro 7 Fortran 90 compiler.

The NAME compiler directive allows you to specify a case-sensitive external name in a Fortran program. You can use this directive, for example, when writing calls to C routines. For more information on the NAME directive, see the CF90 Commands and Directives Reference Manual, or the MIPSpro 7 Fortran 90 Commands and Directives Reference Manual.

Lexical Tokens

A statement is constructed from low-level syntax. The low-level syntax describes the basic language elements, called lexical tokens, in a statement. A lexical token is the smallest meaningful unit of a statement and can consist of 1 or more characters. Tokens are names, keywords, literal constants (except for complex literal constants), labels, operator symbols, comma, =, =>, :, ::, ;,%, and delimiters. A literal of type complex consists of several tokens. Examples of operator symbols are + and //.

Delimiters are pairs of symbols that enclose parts of a statement. The following symbol pairs are delimiters:

/ ... /
( ... )
(/ ... /)

In the following statements, the slashes distinguish the value list from the object list in a DATA statement, the parentheses are delimiters that mark the beginning and end of the argument list in the CALL statement, and the pairs (/ and /) mark the beginning and end of the elements of an array constructor:

DATA  X, Y / 1.0, -10.2/
CALL PRINT_LIST(LIST, SIZE)
VECTOR = (/ 10, 20, 30, 40 /)

Statement Keywords

Statement keywords appear in uppercase letters in the syntax rules. Some statement keywords identify the statement, such as in the following DO statement:

DO I = 1, 10

DO is a statement keyword that identifies the DO statement. Other keywords identify parts of a statement such as ONLY in a USE statement or WHILE in one of the forms of a DO construct, as follows:

DO WHILE( .NOT. FOUND )

Others specify options in the statement such as IN, OUT, or INOUT in the INTENT statement.

There are three statements in Fortran that have no statement keyword. They are the assignment statement, the pointer assignment statement, and the statement function.

Some sequences of capital letters in the formal syntax rules are not statement keywords. For example, EQ, in the lexical token .EQ., and EN, as an edit descriptor, are not statement keywords.

A dummy argument keyword, a different sort of keyword, is discussed in the Fortran Language Reference Manual, Volume 2.

Names

Variables, named constants, program units, common blocks, procedures, arguments, constructs, derived types (types for structures), namelist groups, structure components, dummy arguments, and function results are among the elements in a program that have a name. Fortran permits up to 31 characters in a name.

 

character

is

alphanumeric_character

 

 

or

special_character

 

alphanumeric_character

is

letter

 

 

or

digit

 

 

or

underscore

EXT

 

or

currency_symbol

EXT

 

or

at_sign

 

underscore

is

_

EXT

currency_symbol

is

$

EXT

at_sign

is

@

 

name

is

letter[alphanumeric_character]...

A name must begin with a letter and can consist of letters, digits, and underscores. The CF90 and MIPSpro 7 Fortran 90 compilers allow you to use the underscore (_), at sign (@), and dollar sign ($) in a name, but none of these can be the first character of a name. Use of @ and $ is not recommended, however, because these are intended for internal use.

The following are examples of names:

A
CAR_STOCK_NUMBER
A__BUTTERFLY
Z_28
TEMP_


Note: The Fortran standard does not allow the dollar sign ($) or the at sign (@) character in a name. The at sign (@) is not included in the standard character set.



Note: : The MIPSpro 7 Fortran 90 compiler does not support the at sign (@).


Constants

A constant is a syntactic notation for a value. The value can be of any intrinsic type; that is, it can be a numeric (integer, real, or complex) value, a character value, or a logical value. A constant is defined as follows:

 

constant

is

literal_constant

 

 

or

named_constant

 

literal_constant

is

int_literal_constant

 

 

or

real_literal_constant

 

 

or

logical_literal_constant

 

 

or

complex_literal_constant

 

 

or

char_literal_constant

 

 

or

boz_literal_constant

EXT

 

or

typeless_constant

EXT

typeless_constant

is

octal_typeless_constant

 

 

or

hexadecimal_typeless_constant

 

 

or

binary_typeless_constant

EXT

octal_typeless_constant

is

digit[digit... ]B

 

 

or

O"digit[digit... ]"

 

 

or

O'digit[digit... ]'

 

 

or

"digit[digit... ]"O

 

 

or

' digit[digit... ]'O

EXT

hexadecimal_typeless_constant

is

X'hex_digit[hex_digit... ]'

 

 

or

X"hex_digit[hex_digit... ]"

 

 

or

'hex_digit[hex_digit... ]'X

 

 

or

"hex_digit[hex_digit... ]"X

 

 

or

Z'hex_digit[hex_digit... ]'

 

 

or

Z"hex_digit[hex_digit... ]"

EXT

binary_typeless_constant

is

B'digit[digit... ]'

 

 

or

B"digit[digit... ]"

 

constant

is

literal_constant

 

 

or

named_constant

 

named_constant

is

name

 

int_constant

is

constant

 

char_constant

is

constant


The following notes pertain to the preceding format:

  • digit must have one of the values 0 through 7 in octal_typeless_constant

  • digit must have a value of 0 or 1 in binary_typeless_constant

  • The B, O, X, and Z characters can be in uppercase or lowercase.

A value that does not have a name is a literal constant. The following are examples of literal constants:

1.23
400
( 0.0, 1.0 )
"ABC"
B'0110110'
.TRUE.

The BOZ constants are described in “Format for Constant Values” in Chapter 4.

No literal constant can be array-valued or of derived type. “Intrinsic Data Types” in Chapter 4 describes the formats of literal constants in more detail.

A value that has a name is called a named constant and can be of any type, including a derived type. A named constant can also be array-valued. In the following statements, X_AXIS and MY_SPOUSE are examples of named constants:

REAL, DIMENSION(2), PARAMETER :: X_AXIS = (/ 0.0, 1.0 /)
TYPE(PERSON), PARAMETER :: MY_SPOUSE = PERSON( 39, 'PAT' )

Note that the entity on the right of the equal sign is not itself a constant but a constant expression. The forms for defining named constants are described in more detail in “PARAMETER Attribute and Statement” in Chapter 5.

Operators

Operators are used with operands in expressions to produce other values. The following are examples of intrinsic operators:

Operator 

Representation

* 

Multiplication of numeric values

// 

Concatenation of character values

== 

Comparison for equality (same as .EQ.)

.OR. 

Logical disjunction

.NOT. 

Logical negation

The intrinsic_operators are defined as follows:

 

intrinsic_operator

is

power_op

 

 

or

mult_op

 

 

or

add_op

 

 

or

concat_op

 

 

or

rel_op

 

 

or

not_op

 

 

or

and_op

 

 

or

or_op

 

 

or

equiv_op

 

power_op

is

**

 

mult_op

is

*

 

 

or

/

 

add_op

is

+

 

 

or

-

 

concat_op

is

//

 

rel_op

is

.EQ.

 

 

or

.NE.

 

 

or

.LT.

 

 

or

.LE.

 

 

or

.GT.

 

 

or

.GE.

EXT

 

or

.LG.

 

 

or

==

 

 

or

/=

 

 

or

<

 

 

or

<=

 

 

or

>

 

 

or

>=

EXT

 

or

<>

 

not_op

is

.NOT.

EXT

 

or

.N.

 

and_op

is

.AND.

EXT

 

or

.A.

 

or_op

is

.OR.

EXT

 

or

.O.

 

equiv_op

is

.EQV.

 

 

or

.NEQV.

EXT

exclusive_disjunct_op

is

.XOR.

EXT

 

or

.X.

The abbreviations .A., .O., .N., and .X. are synonyms for .AND., .OR., .NOT., and .XOR., respectively. If the abbreviated operator is overloaded in an interface block as a defined operator, the abbreviated form of the intrinsic operator cannot be used in any scope in which the defined operator is accessible.


Note: The Fortran standard does not specify the .A., .O., or .N., abbreviations for the logical operators, nor does it specify the .XOR. operator or its .X. abbreviation. The Fortran standard does not specify the .LG. or <> operators.

You can define operators in addition to the intrinsic operators. User-defined operators begin with a period (.), followed by a sequence of up to 31 letters, and end with a period (.), except that the letter sequence must not be the same as any intrinsic operator defined by the Fortran standard or the logical constants .FALSE. or .TRUE.


Statement Labels

A label can be used to identify a statement. A label consists of 1 to 5 decimal digits, one of which must be nonzero. If a statement has a label, it is uniquely identified and the label can be used in DO constructs, CALL statements, branching statements, and I/O statements.

Leading zeros in a label are not significant. In other words, the labels 020 and 20 are considered to be the same label. A statement label is local to a scoping unit. This means that a program unit can contain more than one definition of the same label as long as the labels are defined in different scoping units. For example, a main program and a contained internal subprogram can both define the same statement label. The cases in which duplicate labels can be used in the same program unit are explained as part of the general treatment of the scope of entities in the Fortran Language Reference Manual, Volume 2.

The following are examples of statements with labels:

100 CONTINUE
 21 X = X + 1.2
101 FORMAT (1X, 2F10.2)

Fortran syntax does not permit a statement with no content. This is sometimes referred to as a blank statement. Such a statement is always treated as a comment; therefore, if such a statement is created, it must not be labeled. For example, each of the following lines is nonstandard Fortran. They generate an error message from the CF90 and MIPSpro 7 Fortran 90 compilers:

10
X=0;101;

Source Form

A Fortran program consists of statements, comments, and INCLUDE lines. This collection of statements, comments, and INCLUDE lines is called source text. A statement consists of one or more lines of source text and is constructed from low-level syntax.

The lines within a program unit (except comment lines) and the order of the lines are, in general, significant.

Because all program units terminate with their own END statement, lines following such an END statement are never part of the preceding program unit; they are part of the program unit that follows. END statements can be continued.


Note: The Fortran standard does not describe END statement continuation.

There are two source forms for writing source text: free source form and fixed source form.


Note: The Fortran standard has declared fixed source form to be obsolescent. The preferred alternative is free source form.

Fixed source form is the default for Fortran source files with a .f or .F suffix. Free source form is the default source for Fortran source files with a .f90 or .F90 suffix. The compiler allows you to use the FIXED and FREE compiler directives to switch from one source form to the other within a program unit. The f90(1) command line allows you to override the source form implied by the input file suffix. See the CF90 Commands and Directives Reference Manual, or the MIPSpro 7 Fortran 90 Commands and Directives Reference Manual, for information on the f90(1) command line and on the FIXED and FREE compiler directives. “Portable Source Form”, describes a way to write Fortran statements so that the source text is acceptable to both free and fixed source forms.


Note: The Fortran standard does not describe compiler directives or command lines.

Characters that form the value of a character literal constant, a Hollerith constant, or a character string edit descriptor (quotation mark, apostrophe, or H edit descriptor) are in a character context. The characters in a character context do not include the delimiters used to indicate the beginning and end of the character constant or string. Also, the ampersands (&) in free source form, which are used to indicate that a character string is being continued and used to indicate the beginning of the character string on the continued line, are never part of the character string value and thus are not in character context.


Note: The Fortran standard does not describe Hollerith constants.

The rules that apply to characters in a character context are different from the rules that apply to characters in other contexts. For example, blanks are always significant in a character context but are never significant in other parts of a program written using fixed source form. The following code fragment illustrates this:

CHAR = CHAR1 // "Mary K. Williams"
! The blanks within the character string
! (within the quotation marks) are significant.
! The next two statements are equivalent
! in fixed source form.
DO2I=1,N
DO 2 I = 1, N

Comments can contain any printable character.

Free Source Form

In free source form, the only restriction on statement positioning within a line is that the line itself cannot contain more than 132 characters. A blank character is significant and may be required to separate lexical tokens.

Blank characters are significant everywhere, but a sequence of blank characters outside a character context is treated as a single blank character. They can be used freely between tokens and delimiters to improve the readability of the source text. For example, the following two statements are interpreted identically:

SUM=SUM+A(I)
SUM = SUM + A (I)

Each line can contain from 0 through 132 characters.

The exclamation mark (!), not in character context, indicates the beginning of a comment that ends with the end of the line. A line can consist of nothing but a comment. Comments, including the !, are ignored and do not alter the interpretation of statements in any way.

The CF90 and MIPSpro 7 Fortran 90 compilers support compiler directives. Compiler directives are lines inserted into source code that specify actions to be performed by the compiler. Compilers other than the CF90 and MIPSpro 7 Fortran 90 compilers may treat compiler directive lines as comments. For more information on compiler directives, see the CF90 Commands and Directives Reference Manual, or the MIPSpro 7 Fortran 90 Commands and Directives Reference Manual.

A line whose first nonblank character is an exclamation mark is called a comment line.

The following is an example of a comment line:

! Begin the next iteration.

The following is an example of a statement with a trailing comment:

ITER = ITER + 1   ! Begin the next iteration.

An ampersand (&), not in a character context, is a continuation symbol and must be followed by one of the following:

  • Zero or more blanks.

  • A comment and the end of the line. If the line following this line is not a comment line; it is a continuation line.

The following is an example of a continued line and a continuation line:

FORCE = G * MASS1 *  & ! This is a continued line.
       MASS2 / R**2 ! This is a continuation line.

The CF90 and MIPSpro 7 Fortran 90 compilers allow a statement to be continued with up to 99 continuation lines.


Note: If you are using free source form, the Fortran standard allows no more than 39 continuation lines within a statement.

No line can contain an ampersand as the only nonblank character before an exclamation mark. Comment lines cannot be continued. That is, the ampersand as the last character in a comment is part of the comment and does not indicate continuation.

A line with only blank characters or with no characters is treated as a comment line.

More than one statement or partial statement can appear on a line. The statement separator is the semicolon (;), provided it is not in a character context. Multiple successive semicolons on a line with or without blanks intervening are considered as a single separator. The end of a line is also a statement separator, but a semicolon at the end of a line that is not part of a comment is considered as a single separator. Essentially, a null statement is a legal Fortran statement. The following statements show use of the semicolon:

! The semicolon is a statement separator.
X = 1.0;  Y = 2.0
! However, the semicolon below, at the end of a
! line, is not treated as a separator and is
! ignored.
Z = 3.0;
! Also, consecutive semicolons are treated as one
! semicolon, even if blanks intervene.
Z = 3.0; ; W = 4.0

A label can appear before a statement, provided that it is not part of another statement, but it must be separated from the statement by at least one blank. Examples:

10 FORMAT(10X,2I5)                ! 10 is a label
   IF (X == 0.0) 200 Y = SQRT(X)  ! Label 200 is
                                  ! not allowed.

Any printable character can be used in character literal constants and character string edit descriptors.

The CF90 and MIPSpro 7 Fortran 90 compilers support only the ASCII character set. The Fortran Language Reference Manual, Volume 3, describes the ASCII character set.

The Ampersand (&) As a Continuation Symbol

The ampersand (&) is used as the continuation symbol in free source form. If it is the last nonblank character in a line after any comments are deleted and it is not in a character context, the statement is continued on the next line that does not begin with a comment. If the first nonblank character on the continuing line is an ampersand, the statement continues after the ampersand; otherwise, the statement continues with the first position of the line. The ampersand or ampersands used as the continuation symbols are not considered part of the statement. For example, the following statement takes two lines (one continuation line) because it is too long to fit on one line:

STOKES_LAW_VELOCITY = 2 * GRAVITY * RADIUS ** 2 *  &
      (DENSITY_1 - DENSITY_2) / (9 * COEFF_OF_VISCOSITY)

The leading blanks on the continued line are included in the statement and are allowed in this case because they are between lexical tokens.

The double ampersand convention must be used to continue a name, a character constant, or a lexical token consisting of more than 1 character split across lines. The following statement is the same statement as in the previous example:

STOKES_LAW_VELOCITY = 2 * GRAVITY * RADIUS ** 2 * (DEN&
      &SITY_1 - DENSITY_2) / (9 * COEFF_OF_VISCOSITY)

However, splitting names across lines makes the code difficult to read and is not recommended.

Ampersands can be included in a character constant. Only the last ampersand on the line is the continuation symbol, as illustrated in the following example:

LAWYERS = "Jones & Clay & &
&Davis"

The value of this constant is Jones & Clay & Davis. The first two ampersands are in a character context; they are part of the value of the character string.

END statements cannot be continued.

Blanks As Separators

Blanks in free source form cannot appear within tokens, such as names or symbols consisting of more than 1 character, but blanks can be used freely in format specifications. For example, blanks cannot appear between the characters of multicharacter operators such as ** and .NE.. Format specifications are an exception because blanks can appear within edit descriptors such as BN, SS, or TR.

The CF90 and MIPSpro 7 Fortran 90 compilers treat tabs and single blanks as equivalent in free source form, except in character literal strings.


Note: The Fortran standard does not allow tabs in Fortran source files.

A blank must be used to separate a statement keyword, name, constant, or label from an adjacent name, constant, or label. For example, the blanks in the following statements are required:

INTEGER SIZE
PRINT 10,N
DO I=1,N

Adjacent keywords require a blank separator in some cases (for example, CASE DEFAULT). In other cases, two adjacent keywords can be written either with or without intervening blanks (for example, BLOCK DATA).

Blank separators are optional in the following keywords:

  • BLOCK DATA

  • DOUBLE PRECISION

  • ELSE IF

  • END BLOCK DATA

  • END DO

  • END FILE

  • END IF

  • END INTERFACE

  • END MODULE

  • END PROGRAM

  • END SELECT

  • END SUBROUTINE

  • END TYPE

  • END WHERE

  • GO TO

  • IN OUT

  • SELECT CASE

Blank separators are mandatory in the following keywords:

  • CASE DEFAULT

  • DO WHILE

  • IMPLICIT type_spec

  • IMPLICIT NONE

  • INTERFACE ASSIGNMENT

  • INTERFACE OPERATOR

  • MODULE PROCEDURE

  • RECURSIVE FUNCTION

  • RECURSIVE SUBROUTINE

  • RECURSIVE type_spec

  • type_spec FUNCTION

  • type_spec RECURSIVE

Blanks are not mandatory in all cases, but blank separators between statement keywords make the source text more readable and clarify the statements. Generally, if common rules of English text are followed, everything will be correct. For example, blank separators in the following statements make them quite readable, and the blanks in DOUBLE PRECISION and END FUNCTION are optional:

RECURSIVE FUNCTION F(X)
DOUBLE PRECISION X
END FUNCTION F

Sample Program, Free Source Form

The following is a sample program in free source form. Note that the numbers and the line at the top are not part of the program; the vertical bars to the left of the program are also not part of the program. These graphics are included to show the columns this program uses in free source form.

 123456789.......
 -----------------------------------------------------
|PROGRAM LEFT_RIGHT
| REAL  X(5), Y(5)
|       ! Print arrays X and Y
|       PRINT 100, X, Y
|       100 FORMAT (F10.1, F10.2, F10.3, F10.4,  &
|                   F10.5)
|   . . .
|END

Fixed Source Form

Fixed source form is position oriented on a line using the historical Fortran conventions for position that were used on punched cards.


Note: The Fortran standard has declared fixed source form to be obsolescent. The preferred alternative is free source form.

By default, statements or parts of statements must be written between positions 7 and 72, inclusive. The f90(1) command line includes options that allow you to specify different line lengths. For information on specifying different line lengths, see the CF90 Commands and Directives Reference Manual, or the MIPSpro 7 Fortran 90 Commands and Directives Reference Manual.

Regardless of the command line specification, character positions 1 through 6 are reserved for special purposes.


Note: The Fortran standard does not allow a compiler to recognize characters beyond column 72.

Blanks are not significant in fixed source form except in a character context. For example, the following two statements are identical:

D O  10  I = 1, L O O P E N D
DO 10 I = 1, LOOPEND

A C or * in position 1 identifies a comment. In this case, the entire line is a comment and is called a comment line. A ! in any position except position 6 and not in a character context indicates that a comment follows to the end of the line. Comments are not significant.

A line with only blank characters or with no characters is treated as a comment line.

Multiple statements on a line are separated by one or more semicolons. Semicolons can occur at the end of a line, and these are ignored.

Any character (including ! and ;) other than blank or 0 in position 6 indicates that the line is a continuation of the previous line. Such a line is called a continuation line. The text on the continuation line begins in position 7. There can be no more than 99 continuation lines for one statement in fixed source form. The first line of a continued statement is called the initial line.


Note: If you are using fixed source form, the Fortran standard allows no more than 19 continuation lines within a statement.

Statement labels can appear only in positions 1 through 5. A label can appear only on the initial line of a continued statement. Thus, positions 1 through 5 of continuation lines must contain blanks.

The CF90 and MIPSpro 7 Fortran 90 compilers allow you to continue an END statement, as follows:

 E
&N
&D


Note: The Fortran standard states that an END statement must not be continued.

The characters END can appear as the only characters on the initial line of a statement, as follows:

 END
&FILE(10)


Note: The Fortran standard states that END cannot be an initial line of a statement other than an END statement.

Any character from the CF90 and MIPSpro 7 Fortran 90 character set (including graphic and control characters) can be used in character literal constants and character edit descriptors. Although the Fortran standard permits a processor to limit the use of control characters (such as the newline) to such character contexts, the compilers impose no such limitation.

Tab Character

You can substitute the tab character for spaces at the beginning of a line, but it is not actually converted to spaces. The compiler uses the tab as follows:

  • If a tab is the first character on a line, the next character determines how the line is interpreted. A nonzero digit indicates a continuation line. Otherwise, this line is the initial line of a statement.

  • A statement label, if present, must precede the first tab.

  • The compiler treats the tab character in a statement the same way it treats a blank character.

A tab character is not converted to spaces, so the exact visual placement of tabbed statements depends on the utility you use to edit or display text.


Note: : A tab counts as 1 character even though it may expand to more than one space in the listing or editor. Thus, statements that include tabs may appear to have data beyond column 72 (or 80) in the editor or listing.


Sample Program, Fixed Source Form

The following is a sample program in fixed source form. Note that the numbers and the line at the top are not part of the program; the vertical bars to the left of the program are also not part of the program. These graphics are included to show the columns this program uses in fixed source form.

 123456789.....
---------------------------------------------
|      PROGRAM LEFT_RIGHT
|      REAL  X(5), Y(5)
|C     Print arrays X and Y
|      PRINT 100, X, Y
|  100 FORMAT (F10.1, F10.2, F10.3, F10.4,
|     1        F10.5)
|         . . .
|      END

Portable Source Form

For portability in many cases, such as an included file, it is desirable to use a form of the source code that is valid and equivalent for either free source form or fixed source form. Such a source form can be written by obeying the following rules and restrictions:

  • Limit labels to positions 1 through 5, and statements to positions 7 through 72. These are the limits required in fixed source form.

  • Treat blanks as significant. Because blanks are ignored in fixed source form, using the rules of free source form will not impact the requirements of fixed source form.

  • Use the exclamation mark (!) for a comment, but do not place it in position 6, which indicates continuation in fixed source form. Do not use the C or * forms for a comment.

  • To continue statements, use the ampersand in both position 73 of the line to be continued and in position 6 of the continuation. Positions 74 to 80 must remain blank or contain only a comment. Positions 1 through 5 must be blank. The first ampersand continues the line after position 72 in free source form and is ignored in fixed source form. The second ampersand indicates continuation in fixed source form and in free source form indicates that the text for the continuation of the previous line begins after the ampersand.

  • The CF90 and MIPSpro 7 Fortran 90 compilers allow you to switch between fixed and free source forms within a file or include file by using the FIXED and FREE compiler directives. All compiler directives should begin in column 1. For more information on compiler directives, see the CF90 Commands and Directives Reference Manual, or the MIPSpro 7 Fortran 90 Commands and Directives Reference Manual.

Sample Program, Use with Either Source Form

The following is a sample program that is acceptable in either fixed or free source form. Note that the numbers and the line at the top are not part of the program; the vertical bars to the left of the program are also not part of the program. These graphics are included to show the columns this program uses in fixed source form.

 123456789.....                                      73
 -------------------------------------------.....----
|      PROGRAM LEFT_RIGHT
|      REAL  X(5), Y(5)
|!     Print arrays X and Y
|      PRINT 100, X, Y
|  100 FORMAT (F10.1, F10.2, F10.3, F10.4,           &
|     &        F10.5)
|         . . .
|      END

The INCLUDE Line

Source text can be imported from another file and included within a program file during processing. An INCLUDE line consists of the keyword INCLUDE followed by a character literal constant. The following is an example of an INCLUDE line:

INCLUDE  'MY_COMMON_BLOCKS'

The specified text is substituted for the INCLUDE line during compilation and is treated as if it were part of the original program source text. The CF90 and MIPSpro 7 Fortran 90 compilers allow you to specify search path names on the f90(1) command line for locating files to be included. For more information on INCLUDE lines, see the CF90 Commands and Directives Reference Manual, or the MIPSpro 7 Fortran 90 Commands and Directives Reference Manual.

The INCLUDE line provides a convenient way to include source text that is the same in several program units. For example, the specification of interface blocks or objects in common blocks may constitute a file that is referenced in the INCLUDE line.

The format for an INCLUDE line is as follows:

INCLUDE character_literal_constant

The character_literal_constant used cannot have a kind parameter that is a named constant.

The INCLUDE line is a directive (but not a compiler directive) to the compiler; it is not a Fortran statement.

The INCLUDE line is placed where the included text is to appear in the program.

The INCLUDE line must appear on one line with no other text except possibly a trailing comment. There can be no statement label.

The INCLUDE lines can be nested. That is, a second INCLUDE line may appear within the text to be included. The Fortran standard does not specify the permitted level of nesting, and the CF90 and MIPSpro 7 Fortran 90 compilers impose no limit. The text inclusion cannot be recursive at any level. For example, included text A cannot include text B, which includes text A.

A file intended to be referenced in an INCLUDE line cannot begin or end with an incomplete statement.

An example of a program unit with an INCLUDE line follows:

PROGRAM MATH
REAL, DIMENSION(10,5,79) :: X, ZT!  Some arithmetic
INCLUDE 'FOURIER'!  More arithmetic
   . . .
END

The source text in the file FOURIER in effect replaces the INCLUDE line.

Low-level Syntax

The basic lexical elements of the language consist of the classes character, name, constant, intrinsic_operator, defined_operator, and label. These are defined as follows:

 

defined_operator

is

defined_unary_op

 

 

or

defined_binary_op

 

 

or

extended_intrinsic_op

 

defined_unary_op

is

. letter[letter] ... .

 

defined_binary_op

is

. letter[letter] ... .

 

extended_intrinsic_op

is

intrinsic_operator

 

label

is

digit[digit[digit[digit[digit]]]]