Skip to content

The FORTRAN parameter statement

Home arrow Computational arrow FORTRAN arrow The FORTRAN parameter statement


The FORTRAN parameter statement E-mail
User Rating: / 0
PoorBest 
Some constants appear many times in a program. It is then often desirable to define them only once, in the beginning of the program. This is what the parameter statement is for. It also makes programs more readable.
For example, the circle area program should have been written like this:
program circle
real r, area, pi
parameter (pi = 3.14159)
c This program reads a real number r and prints
c the area of a circle with radius r.
write (*,*) 'Give radius r:'
read (*,*) r
area = pi*r*r
write (*,*) 'Area = ', area
stop
end
The syntax of the parameter statement is parameter ( name = constant, ... , name = constant)

The rules for the parameter statement are:
  • The "variable" defined in the parameter statement is not a variable but rather a constant whose value can never change
  • A "variable" can appear in at most one parameter statement
  • The parameter statement(s) must come before the first executable statement

Some good reasons to use the parameter statement are:
  • it helps reduce the number of typos
  • it is easy to change a constant that appears many times in a program