    PROGRAM m01dbfe

!      M01DBF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

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

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

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

       m1 = 1

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

       ifail = 0
       CALL m01dbf(iv,m1,m2,'Descending',irank,ifail)

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

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

99999  FORMAT (1X,2I7)
    END PROGRAM m01dbfe
