! Program Example from "Essential Fortran 90 & 95" by Loren P. Meissner
! Copyright 1996. Copying for sale requires permission from the author.
! Otherwise, distribution is permitted if these three lines are included.

  module H09M
    implicit none
    public :: maxval
    private :: S_MaxVal
    intrinsic maxval  ! Required by F; prohibited by ELF
    interface maxval  ! Same as intrinsic function name
      module procedure S_MaxVal
    end interface
  contains
    function S_MaxVal( Vector ) result( S_MV_R )
      character(len = *), intent(in), dimension(:) :: Vector
      character(len = len(Vector)) :: S_MV_R
      integer :: Loop
  ! start function S_MaxVal
      S_MV_R = ""
      do Loop = 1, size( Vector )
        S_MV_R = merge(Vector(Loop), S_MV_R, Vector(Loop) > S_MV_R)
      end do
      return
    end function S_MaxVal
  end module H09M
