    PROGRAM m01djfe

!      M01DJF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

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

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

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

       m1 = 1
       n1 = 1

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

       ifail = 0
       CALL m01djf(rm,ldm,m1,m2,n1,n2,'Ascending',irank,ifail)

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

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

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

99999  FORMAT (1X,12F6.1)
99998  FORMAT (1X,12I6)
    END PROGRAM m01djfe
