5.14 PARAMETER Attribute and Statement

The PARAMETER attribute defines a named constant.

The PARAMETER attribute can be specified in a type declaration statement or a PARAMETER statement, and takes one of the following forms:

Type Declaration Statement:

type, [att-ls,] PARAMETER [, att-ls] :: c = expr [, c = expr]...

Statement:

PARAMETER [(] c = expr [, c = expr]...[)]

type
Is a data type specifier.

att-ls
Is an optional list of attribute specifiers.

c
Is the name of the constant.

expr
Is an initialization expression. It can be of any data type.

Rules and Behavior

The type, type parameters, and shape of the named constant are determined in one of the following ways:

For example, consider the following statement:

PARAMETER (MU=1.23)

According to implicit typing, MU is of integer type, so MU=1. For MU to equal 1.23, it should previously be declared REAL in a type declaration or be declared in an IMPLICIT statement.

A named constant must not appear in a format specification or as the character count for Hollerith constants. For compilation purposes, writing the name is the same as writing the value.

If the named constant is used as the length specifier in a CHARACTER declaration, it must be enclosed in parentheses.

The name of a constant cannot appear as part of another constant, although it can appear as either the real or imaginary part of a complex constant.

You can only use the named constant within the scoping unit containing the defining PARAMETER statement.

Any named constant that appears in the initialization expression must have been defined previously in the same type declaration statement (or in a previous type declaration statement or PARAMETER statement), or made accessible by use or host association.

Examples

The following example shows a type declaration statement specifying the PARAMETER attribute:

REAL, PARAMETER :: C = 2.9979251, Y = (4.1 / 3.0)

The following is an example of the PARAMETER statement:

REAL(4) PI, PIOV2
REAL(8) DPI, DPIOV2
LOGICAL FLAG
CHARACTER*(*) LONGNAME

PARAMETER (PI=3.1415927, DPI=3.141592653589793238D0)
PARAMETER (PIOV2=PI/2, DPIOV2=DPI/2)
PARAMETER (FLAG=.TRUE., LONGNAME='A STRING OF 25 CHARACTERS')

For More Information:


Previous Page Next Page Table of Contents