Program m01dffe

!     M01DFF Example Program Text

!     Mark 25 Release. NAG Copyright 2014.

!     .. Use Statements ..
      Use nag_library, Only: m01dff
!     .. 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 ..
      Integer, Allocatable             :: im(:,:), irank(:)
!     .. Executable Statements ..
      Write (nout,*) 'M01DFF Example Program Results'

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

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

      m1 = 1
      n1 = 1

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

      ifail = 0
      Call m01dff(im,ldm,m1,m2,n1,n2,'Descending',irank,ifail)

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

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

99999 Format (1X,3I7,I11)
    End Program m01dffe