The PARAMETER statement associates a symbolic name with a constant
value. It takes the following form:
PARAMETER (p = c[,p = c] . . . )
- p
- Is a symbolic name.
- c
- Is a constant, a compile-time constant expression, or the
symbolic name of a constant.
Rules and Behavior
The data type of a symbolic name associated with a constant is
determined as follows:
- By an explicit type declaration statement preceding the
defining PARAMETER statement. In the case of PARAMETER statements
within structure declarations, the type declaration must be
outside the structure declaration.
- By the same rules for implicit declarations that determine
the data type of any other symbolic name.
For example, the following PARAMETER statement is interpreted as
MU=1 (MU has an integer data type by implication):
PARAMETER (MU=1.23)
If the PARAMETER statement is preceded by an appropriate type
declaration or IMPLICIT statement, it could be interpreted as
MU=1.23; for example:
REAL MU
PARAMETER (MU=1.23)
Once a symbolic name is associated with a constant, it can appear
anywhere in a program that any other constant can appear-except in
FORMAT statements (where constants can only be
used in variable format expressions) and as the character count for
Hollerith constants. For compilation purposes, writing the
name is the same as writing the value.
The following additional rules apply to symbolic names:
- If the symbolic name is used as the length specifier in a
CHARACTER declaration, it must be enclosed in parentheses.
- If the symbolic name is used as a
numeric item in a FORMAT edit description, it must be enclosed in
angle brackets (<>).
- The symbolic 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.
- A symbolic name can be defined only once within the same
program unit.
- You can only use a symbolic name defined to be a constant
within the program unit containing the defining PARAMETER
statement.
Compile-Time Constant Expressions
A compile-time constant expression can be a logical, character, or
arithmetic expression.
A compile-time logical expression has the following characteristics:
- Each operand is one of the following:
- A constant
- The symbolic name of a constant
- One of the intrinsic functions
IAND, IOR, NOT, IEOR, ISHFT, LGE, LGT, LLE, LLT with constant
operands
- Another compile-time constant expression
- Each operand has a data type of logical or integer.
- Each operator is a Boolean or relational operator.
A compile-time character expression has the following
characteristics:
- Each operand is one of the following:
- A constant
- The symbolic name of a constant
- The intrinsic function CHAR with a
constant operand
- Another compile-time constant expression
- Each operand has a data type of character.
- Each operator is the concatenation operator (//).
A compile-time arithmetic expression has the following
characteristics:
- Each operand is one of the following:
- A constant
- The symbolic name of a constant
- One of the intrinsic functions MIN,
MAX, ABS, MOD, ICHAR, NINT, DIM, DPROD, CMPLX, CONJG, IMAG
with constant operands
- Another compile-time constant expression
- Each operand has a data type of integer, real, or complex.
- Each operator is a plus, minus, multiplication, division,
or exponentiation sign. (The exponentiation operator is evaluated
at compile time only if the exponent has an integer data type.)
Example
The following example shows valid Fortran PARAMETER statements:
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