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:

Syntax

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.

The use of parentheses is optional and can be controlled using the /[no]altparam compiler option.

Compatibility

CONSOLE STANDARD GRAPHICS QUICKWIN GRAPHICS WINDOWS DLL LIB

See Also: DATA, Type Declarations, Using the Compiler and Linker from the Command Line, Compatible attributes, Initialization Expressions, IMPLICIT, Alternative syntax for the PARAMETER statement

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')

The following shows another example:

 ! 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