! 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 F22M
    implicit none
    public :: Linear_Max
  contains
    function Linear_Max( Vector ) result( Linear_Max_R )
      real, dimension(:), intent(in) :: Vector  ! Assumed-shape
      integer :: Linear_Max_R
      integer :: Loop, Limit
      real :: Big
  ! start function Linear_Max
      Linear_Max_R = 0
      Limit = size( Vector )
      if (Limit > 0) then
        Big = Vector(1)
      else
        Big = 0.0
        return
      end if
      do Loop = 2, Limit
        Linear_Max_R = merge( Loop, Linear_Max_R, Vector(Loop) > Big )
        Big = max( Big, Vector(Loop) )
      end do
      return
    end function Linear_Max
  end module F22M

