FORTRAN parameter statement

Home Computational Physics FORTRAN FORTRAN parameter statement


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