    PROGRAM m01dafe

!      M01DAF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

!      .. Use Statements ..
       USE nag_library, ONLY : m01daf, nag_wp
!      .. Implicit None Statement ..
       IMPLICIT NONE
!      .. Parameters ..
       INTEGER, PARAMETER              :: nin = 5, nout = 6
!      .. Local Scalars ..
       INTEGER                         :: i, ifail, m1, m2
!      .. Local Arrays ..
       REAL (KIND=nag_wp), ALLOCATABLE :: rv(:)
       INTEGER, ALLOCATABLE            :: irank(:)
!      .. Executable Statements ..
       WRITE (nout,*) 'M01DAF Example Program Results'

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

       READ (nin,*) m2
       ALLOCATE (rv(m2),irank(m2))

       m1 = 1

       READ (nin,*) (rv(i),i=m1,m2)

       ifail = 0
       CALL m01daf(rv,m1,m2,'Ascending',irank,ifail)

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

       DO i = m1, m2
          WRITE (nout,99999) rv(i), irank(i)
       END DO

99999  FORMAT (1X,F7.1,I7)
    END PROGRAM m01dafe
