! 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 F21M
    implicit none
    public :: Diagonal
  contains
    function Diagonal( Matrix ) result( Vector )
      real, intent (in), dimension(:, :) :: Matrix
      real, dimension(min( size( Matrix, dim = 1 ), size( Matrix, dim = 2 ) )) :: Vector
      integer :: Loop
  ! start function Diagonal
      do Loop = 1, min( size( Matrix, dim = 1 ), size( Matrix, dim = 2 ) )
        Vector(Loop) = Matrix(Loop, Loop)
      end do
      return
    end function Diagonal
  end module F21M

