! 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 F13M
    implicit none
    public :: Quetzal
  contains
    function Quetzal( M, T ) result( Quetzal_R )
      real, intent(in), dimension (:, :) :: M  ! Assumed-shape array
      real, intent(in) :: T
      real, dimension(size( M, dim = 1 )) :: Quetzal_R  ! Automatic-shape result
      integer :: Degree, Loop
  ! start function Quetzal
      Degree = size( M, dim = 1 ) - 1
      Quetzal_R = 0.0
      do Loop = Degree, 1, -1
        Quetzal_R = Quetzal_R * T + M(:, Loop)  ! Vector * scalar + column of matrix
      end do
      return
    end function Quetzal
  end module F13M

