next up previous contents
Next: Taylor Approximation of the Up: Global Storage Previous: Global Storage   Contents

Circle Example

We want to write two functions, which calculate the perimeter and the area of a circle, respectively. Both functions need the value of . We define this value in a module:

 
module define_pi
 implicit none
 real, parameter :: pi = 3.1415926
end module  define_pi

By USE-ing the module in both functions, we make sure that they see the same value of . The main program reads in the value of the radius and prints the perimeter and the area of the circle.

 
real function perimeter(r)
use define_pi
  implicit none 
  real :: r
  perimeter = 2.0*pi*r
end function perimeter

 
real function area(r)
use define_pi
  implicit none 
  real :: r
  area = pi*r*r
end function area

 
program circle
  implicit none 
  real :: r
  real, external :: perimeter, area
  print*, 'radius ='
  read*,  r 
  print*,'area = ',area(r)
  print*,'perimeter = ',perimeter(r)
end program circle



Adrian Sandu 2001-08-26