MODULE Circle_Type
!-------------------------------------------------------------
! Module to define the derived data type Circle for processing
! circles with given centers and radii.  It also extends the
! relational operator == to type Circle.  Two circles are
! equal if they have the same center and equal radii.
!
! Exports:  derived type Point
!           derived type Circle
!           operator ==
!           parameter Pi
!           function Area
!-------------------------------------------------------------

   TYPE Point
      REAL :: X, Y
   END TYPE Point

   TYPE Circle
      TYPE (Point) :: Center
      REAL :: Radius
   END TYPE Circle

   INTERFACE OPERATOR (==)
      MODULE PROCEDURE Equal
   END INTERFACE

   REAL, PARAMETER :: Pi = 3.141592

   CONTAINS

   !----- Equal ---------------------------------------------
   ! Function to determine if two circles are equal.
   ! Accepts:  circles C1 and C2
   ! Returns:  true if C1 and C2 have the same center and
   !           the equal radii; false otherwise.
   !---------------------------------------------------------

   FUNCTION Equal(C1, C2)

      TYPE (Circle), INTENT(IN) :: C1, C2
      LOGICAL :: Equal

      Equal = C1%Center%X == C2%Center%X .AND. &
              C1%Center%Y == C2%Center%Y .AND. &
              C1%Radius == C2%Radius

   END FUNCTION Equal

   !----- Area ----------------------------------------------
   ! Function to calculate area of a circle.
   ! Accepts:  a circle C
   ! Returns:  area of circle
   !---------------------------------------------------------

   REAL FUNCTION Area(C)

      TYPE (Circle) :: C

      Area = Pi * C%Radius ** 2

   END FUNCTION Area

END MODULE Circle_Type
