    PROGRAM m01zbfe

!      M01ZBF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

!      .. Use Statements ..
       USE nag_library, ONLY : m01eaf, m01zbf, 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            :: iperm(:)
!      .. Executable Statements ..
       WRITE (nout,*) 'M01ZBF Example Program Results'

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

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

       m1 = 1

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

       ifail = 0
       CALL m01zbf(iperm,m1,m2,ifail)

       ifail = 0
       CALL m01eaf(rv,m1,m2,iperm,ifail)

       WRITE (nout,*)
       WRITE (nout,*) 'Numbers in rank order'
       WRITE (nout,*)
       WRITE (nout,99999) (rv(i),i=m1,m2)

99999  FORMAT (1X,10F7.1)
    END PROGRAM m01zbfe
