    Program m01defe

!     M01DEF Example Program Text

!     Mark 24 Release. NAG Copyright 2012.

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

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

      Read (nin,*) m2, n2
      ldm = m2
      Allocate (rm(ldm,n2),irank(m2))

      m1 = 1
      n1 = 1

      Do i = m1, m2
        Read (nin,*)(rm(i,j),j=n1,n2)
      End Do

      ifail = 0
      Call m01def(rm,ldm,m1,m2,n1,n2,'Ascending',irank,ifail)

      Write (nout,*)
      Write (nout,*) 'Data                        Ranks'
      Write (nout,*)

      Do i = m1, m2
        Write (nout,99999)(rm(i,j),j=n1,n2), irank(i)
      End Do

99999 Format (1X,3F7.1,I11)
    End Program m01defe
