    PROGRAM m01dkfe

!      M01DKF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

!      .. Use Statements ..
       USE nag_library, ONLY : m01dkf
!      .. 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,*) 'M01DKF Example Program Results'

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

       READ (nin,*) m2, n2
       ldm = m2
       ALLOCATE (im(ldm,n2),irank(n2))

       m1 = 1
       n1 = 1

       DO i = m1, m2
          READ (nin,*) (im(i,j),j=n1,n2)
       END DO

       ifail = 0
       CALL m01dkf(im,ldm,m1,m2,n1,n2,'Descending',irank,ifail)

       WRITE (nout,*)
       WRITE (nout,*) 'Data'
       WRITE (nout,*)

       DO i = m1, m2
          WRITE (nout,99999) (im(i,j),j=n1,n2)
       END DO

       WRITE (nout,*)
       WRITE (nout,*) 'Ranks'
       WRITE (nout,*)
       WRITE (nout,99999) (irank(i),i=n1,n2)

99999  FORMAT (1X,12I6)
    END PROGRAM m01dkfe
