Visible to Intel only — GUID: GUID-35421C2D-F664-423E-A503-FFB001592D8E
Visible to Intel only — GUID: GUID-35421C2D-F664-423E-A503-FFB001592D8E
PARAMETER
Statement and 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 a constant expression. It can be of any data type. |
Description
The type, type parameters, and shape of the named constant are determined in one of the following ways:
By an explicit type declaration statement in the same scoping unit.
By the implicit typing rules in effect for the scoping unit. If the named constant is implicitly typed, it can appear in a subsequent type declaration only if that declaration confirms the implicit typing.
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 array constant defined by a PARAMETER statement must have its rank specified in a previous specification 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 constant 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.
An entity with the PARAMETER attribute must not be a variable, a coarray, or a procedure.
Omission of the parentheses in a PARAMETER statement is an extension controlled by compiler option altparam. In this form, the type of the name is taken from the form of the constant rather than from implicit or explicit typing of the name.
Example
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')
The following shows implicit-shape arrays declared using a PARAMETER attribute and PARAMETER statements:
INTEGER, PARAMETER :: R(*) = [1,2,3]
REAL :: M (2:*, -1:*)
PARAMETER (M = RESHAPE ([R,R], [3,2]))
The following shows other examples:
! implicit integer type
PARAMETER (nblocks = 10)
!
! implicit real type
IMPLICIT REAL (L-M)
PARAMETER (loads = 10.0, mass = 32.2)
!
! typed by PARAMETER statement
! Requires compiler option
PARAMETER mass = 47.3, pi = 3.14159
PARAMETER bigone = 'This constant is larger than forty characters'
!
! PARAMETER in attribute syntax
REAL, PARAMETER :: mass=47.3, pi=3.14159, loads=10.0, mass=32.2