PARAMETER Statement (Nonexecutable) [ HP FORTRAN 77/iX Reference ] MPE/iX 5.0 Documentation
HP FORTRAN 77/iX Reference
PARAMETER Statement (Nonexecutable)
The PARAMETER statement defines named constants. After a name is defined
in a PARAMETER statement, subsequent uses of the name are treated as if
the value of the constant was used.
-----------------------------------------------------------------------------------------------
| | | |
| Item | Description/Default | Restrictions |
| | | |
-----------------------------------------------------------------------------------------------
| | | |
| cname | Symbolic name that represents a | Name cannot appear in any |
| | constant. | statement before PARAMETER, except |
| | | a type statement. |
| | | |
-----------------------------------------------------------------------------------------------
| | | |
| cexp | Constant expression or intrinsic | If cexp is an intrinsic function, |
| | function. | its arguments must be constants. |
| | | |
-----------------------------------------------------------------------------------------------
PARAMETER statements must precede any statement function and executable
statements in a program unit.
If the symbolic name cname is an integer, real, complex, or logical data
type, the corresponding expression cexp must be an arithmetic or logical
constant expression. If the symbolic name cname is a character data
type, the corresponding expression cexp must be a character constant
expression.
As an extension to the ANSI 77 standard, the following FORTRAN intrinsics
can be used in cexp. When used in cexp, these intrinsics must have
constant arguments and the type of their return value must be the same as
that of cname.
ABS IAND MAX
CHAR ICHAR MIN
CMPLX IMAG MOD
CONJG IOR NOT
DCMPLX ISHFT SIGN
DIM IXOR
Each cname is the symbolic name of a constant that is defined with the
value of the expression cexp appearing to the right of the equal sign, in
accordance with the rules for assignment statements. Any symbolic name
of a constant that appears in an expression cexp must have been defined
previously in the same or a different PARAMETER statement in the same
program unit.
A symbolic name of a constant must not be defined more than once in a
program unit.
If a symbolic name of a constant is not of the default implied type, its
type must be specified by a type statement or IMPLICIT statement prior to
its first appearance in a PARAMETER statement. If the length specified
for the symbolic name of a constant of type character is not the default
length of one, its length must be specified in a type statement or
IMPLICIT statement prior to the first appearance of the symbolic name of
the constant. Its type and 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 is the
length of the expression assigned to it.
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. A symbolic name of a constant must not be
part of a format specification.
A symbolic name in a PARAMETER statement can identify only the
corresponding constant in that program unit.
Examples Notes
--------------------------------------------------------------------------------------
PARAMETER (minval=-10,maxval=50)
PARAMETER (debug=.TRUE.)
PARAMETER (file='WELCOM')
INTEGER lower,upper
PARAMETER (lower=0, upper=7)
DIMENSION a (lower:upper)
DO 10 i=lower,upper
a (i) = 1.0
10 CONTINUE
PARAMETER (pi=3.14159)
radius = diameter/2
area = pi *(radius**2)
CHARACTER bell CHAR in constant expression.
PARAMETER (bell = CHAR(7))
INTEGER case_shift ICHAR in constant expression.
PARAMETER (case_shift = ICHAR('a') - ICHAR('A'))
COMPLEX complex_two Arithmetic conversion performed.
PARAMETER (complex_two = 2)
PARAMETER (limit = 1000) Legal use of previously defined
PARAMETER (limit_plus_1 = limit+1) name.
Example
The following program:
PROGRAM parameters
LOGICAL first_name_greater, scnd_name_greater
CHARACTER ch*(*), name1*(*), name2*(*)
INTEGER length
PARAMETER (ch = 'Guess my length')
PARAMETER (name1 = 'William',
+ name2 = 'David')
PARAMETER (length = LEN(ch))
C Either form of lexical compare is allowed in PARAMETER
PARAMETER (first_name_greater = LGT(name1, name2),
+ scnd_name_greater = name2 .GT. name1)
WRITE (6,10) ch, length
IF (first_name_greater) THEN
WRITE (6,*) name1, 'is lexically greater than', name2
ELSE IF (scnd_name_greater) THEN
WRITE (6,*) name2, 'is lexically greater than', name1
ELSE
WRITE (6,*) name1, 'and', name2, 'have the same name'
END IF
10 FORMAT (' The length of ''',(A),''' is ',I2)
END
produces the following output:
The length of 'Guess my length' is 15
William is lexically greater than David
Alternate PARAMETER Statement (Nonexecutable)
An alternate version of the PARAMETER statement is included for
compatibility with other versions of FORTRAN. The alternate version
differs from the ANSI 77 standard in two ways:
* The parameter list is not bounded by parentheses.
* The type of the constant cexp determines the type of cname
(regardless of explicit or implicit typing).
Alternate PARAMETER statements must precede any executable statements in
a program unit.
The following example illustrates the alternate PARAMETER statement. The
output follows the example.
Example
PROGRAM showpars
IMPLICIT INTEGER (i), REAL (r)
PARAMETER i1 = 'AB' ! Alternate; i1 is type character
PARAMETER (i2 = 2.0) ! Standard; i2 is type integer
PARAMETER i3 = 3.0 ! Alternate; i3 is type real
PARAMETER r1 = 6 ! Alternate; r1 is type integer
PARAMETER (r2 = 6) ! Standard; r2 is type real
i4 = 4 ! First executable statement
PARAMETER i5 = 5 ! Assignment statement, not PARAMETER
! PARAMETER i5 is a variable
WRITE (*,*) i1, i2, i3, i4, i5, PARAMETER i5, r1, r2
END
Output:
AB 2 3.0 4 0 5.0 6 6.0
Note that PARAMETER i5 in the example above is a variable because it
follows an executable statement. (FORTRAN assumes meaning from context
and has no reserved words.)
MPE/iX 5.0 Documentation