Program m01eafe

!     M01EAF Example Program Text

!     Mark 25 Release. NAG Copyright 2014.

!     .. Use Statements ..
      Use nag_library, Only: m01daf, m01eaf, nag_wp
!     .. Implicit None Statement ..
      Implicit None
!     .. Parameters ..
      Integer, Parameter               :: nin = 5, nout = 6
!     .. Local Scalars ..
      Integer                          :: i, ifail, j, k, m1, m2, n
!     .. Local Arrays ..
      Real (Kind=nag_wp), Allocatable  :: rm(:,:)
      Integer, Allocatable             :: irank(:)
!     .. Executable Statements ..
      Write (nout,*) 'M01EAF Example Program Results'

!     Skip heading in data file
      Read (nin,*)

      Read (nin,*) m2, n, k

      If (k<1 .Or. k>n) Then
        Go To 100
      End If

      Allocate (rm(m2,n),irank(m2))

      m1 = 1

      Do i = m1, m2
        Read (nin,*)(rm(i,j),j=1,n)
      End Do

      ifail = 0
      Call m01daf(rm(1,k),m1,m2,'Ascending',irank,ifail)

      Do j = 1, n

        ifail = 0
        Call m01eaf(rm(m1,j),m1,m2,irank,ifail)

      End Do

      Write (nout,*)
      Write (nout,99999) 'Matrix sorted on column', k
      Write (nout,*)

      Do i = m1, m2
        Write (nout,99998)(rm(i,j),j=1,n)
      End Do

100   Continue

99999 Format (1X,A,I3)
99998 Format (1X,3F7.1)
    End Program m01eafe