      program discover
!
!     Define interface to extend assignment operator.
      interface assignment ( = )
        subroutine bubble ( sorted, unsorted )
          type discovery
               sequence
               character (len=21) :: name
               character (len=21) :: event
               character (len=10) :: nationality
               integer            :: when
          end  type discovery
          type ( discovery ), intent (out) :: sorted(:)
          type ( discovery ), intent (in ) :: unsorted(:)
        end subroutine bubble
      end interface
!
!     Declare the data structure.
      INCLUDE 'discover.inc'
      type ( discovery ) :: explorer(5)
      type ( discovery ) :: timeline(5)
!
!     Initialize.
      explorer(1) = discovery ( 'Amundsen, Roald', &
                    'reach South Pole', 'Norwegian', 1911 )
      explorer(2) = discovery ( 'Cook, James', &
                    'map New Zealand', 'English', 1770 )
      explorer(3) = discovery ( 'Lewis, M. & W. Clark', &
                    'explore NW USA', 'American', 1805 )
      explorer(4) = discovery ( 'Magellan, Ferdinand', &
                    'circumnavigate world', 'Portugese', 1521 )
      explorer(5) = discovery ( 'Polo, Marco', &
                    'overland to China', 'Venetian', 1275 )
!
!     Display the event data.
      print *, " "
      do i = 1, size(explorer), 1
         print *, "EXPLORER: ", explorer(i)
      end do
!
!     Sort it.
      timeline = explorer
!
!     Display the explorer in chronological order.
      print *, " "
      do i = 1, size(timeline), 1
         print *, "TIMELINE: ", timeline(i)
      end do
!
!     End of processing.
      print *, " "
      end program discover

      subroutine bubble ( sorted, unsorted )
!
!     Define interface for chronological order operator.
      interface operator ( .gt. )
        logical function chronology ( event, other_event )
          INCLUDE 'discover.inc'
          type ( discovery ), intent (in) :: event
          type ( discovery ), intent (in) :: other_event
        end function chronology
      end interface
!
!     Establish interface to this routine.
      INCLUDE 'discover.inc'
      integer                          :: n
      type ( discovery )               :: temporary
      type ( discovery ), intent (out) :: sorted(:)
      type ( discovery ), intent (in ) :: unsorted(:)
!
!     Use a "bubble" sort to order the data.
      sorted = unsorted
      n = size(sorted)
      do i = 1, n-1, 1
	 do j = i+1, n, 1
            if ( sorted(i) .gt. sorted(j) ) then
                 temporary = sorted(j)
                 sorted(j) = sorted(i)
                 sorted(i) = temporary
            end if
         end do
      end do
      end subroutine bubble

      logical function chronology ( event, other_event )
      INCLUDE 'discover.inc'
      type ( discovery ), intent (in) :: event
      type ( discovery ), intent (in) :: other_event
      if ( event%when .gt. other_event%when) then
           chronology = .true.
      else
           chronology = .false.
      end if
      end function chronology
