Jump to content United States-English
HP.com Home Products and Services Support and Drivers Solutions How to Buy
» Contact HP
More options
HP.com home
HP Fortran 90 Programmer's Reference: HP Fortran 90 Programmer's Reference > Chapter 10 HP Fortran 90 statements

PARAMETER (statement and attribute)

» 

Technical documentation

Complete book in PDF
» Feedback
Content starts here

 » Table of Contents

 » Glossary

Defines a named constant.

Syntax

A type declaration statement with the PARAMETER attribute is:

type, attrib-list :: cname1 = cexpr1[, cname2 = cexpr2]...
type

is a valid type specification (INTEGER, REAL, LOGICAL, CHARACTER, TYPE (name), etc.).

attrib-list

is a comma-separated list of attributes including PARAMETER and optionally those attributes compatible with it, namely:

DIMENSION

PUBLIC

PRIVATE

SAVE

Specifying the SAVE attribute in a PARAMETER statement has no effect.

cname

is the name that will represent the constant.

cexpr

is an initialization expression that evaluates to the constant represented by cname. In the case of an array constant, cexpr must be an array constructor. In the case of a derived type constant, cexpr must be a structure constructor.

The syntax of the PARAMETER statement is:

PARAMETER (cname1 = cexpr1 [, cname2 = cexpr2]...)

Description

The PARAMETER statement associates a symbolic name with a constant. A symbolic name defined in a PARAMETER statement is known as a named constant. A named constant must not become defined more than once in a program unit. Once defined, it can be used only as a named constant. This means that a named constant cannot be assigned a value like a variable.

When the PARAMETER attribute is used, the value of the named constant must be provided by the initialization part of the statement in which the PARAMETER attribute appears.

The type of a named constant is determined by the implicit typing rules, unless its type is specified by a type declaration statement prior to its first appearance in a PARAMETER statement or by a type declaration statement that includes PARAMETER as one of its attributes. If a PARAMETER statement declares and implicitly types a named constant, the named constant may appear in a subsequent type declaration or IMPLICIT statement, but only to confirm the type of the named constant.

When the type of the symbolic name and the constant do not agree, the value of the named constant is assigned in accordance with assignment statement type-conversion rules, as given in Table 5-5 “Conversion of variable=expression.

The following rules apply to type agreement between the constant and the symbolic name:

  • If cname is of numeric type, cexpr must be an arithmetic constant expression.

  • If cname is of type character, the corresponding cexpr must be a character constant expression.

  • If cname is of type logical, the corresponding cexpr may be either an arithmetic or logical constant expression.

Any symbolic name of a constant that appears in cexpr must have been defined previously in the same or a different PARAMETER statement in the same program unit. For example, the expression in the second PARAMETER statement below is built from the expression in the first PARAMETER statement, and is legal:

PARAMETER (limit = 1000)
PARAMETER (limit_plus_1 = limit + 1)

The logical operators (.EQ., .NE., .LT., .LE., .GT., and .GE.), as well as the following intrinsic functions, can appear in the PARAMETER statement:

ABS

IAND

IXOR

MAX

CHAR

ICHAR

LEN

MIN

CMPLX

IEOR

LGE

MOD

CONJB

IMAG

LGT

NINT

DIM

IOR

LLE

NOT

DPROD

ISHFT

LLT

If these intrinsic functions are used in a PARAMETER statement, their arguments must be constants.

If the named constant is of type character and its length is not specified, the length must be specified in a type declaration statement or IMPLICIT statement prior to the first appearance of the named constant. Its type and/or length must not be changed by subsequent statements, including IMPLICIT statements. If a symbolic name of type CHARACTER*(*) is defined in a PARAMETER statement, its length becomes the length of the expression assigned to it.

If the named constant is an array, the bounds must be explicit and determined by an initialization expression.

Once such a symbolic name is defined, that name can appear in any subsequent statement of the defining program unit as a constant in an expression or DATA statement.

Examples

! PARAMETER used in a type declaration statement as an attribute
REAL, DIMENSION(4), PARAMETER :: const = &
(/1.2, 1.45, 0.9, 24.3/)

INTEGER year
! PARAMETER used as a statement
PARAMETER year = 1996

! Type declaration statement declaring a derived-type constant
TYPE (postal_info), PARAMETER :: package = &
postal_info (9.5, (/10.0, 5.5, 2.25/) )

Related concepts

For information about the type declaration statement, see “Type declaration for intrinsic types”.

Printable version
Privacy statement Using this site means you accept its terms Feedback to webmaster
© Hewlett-Packard Development Company, L.P.