Program m01dafe

!     M01DAF Example Program Text

!     Mark 25 Release. NAG Copyright 2014.

!     .. 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