    PROGRAM m01cafe

!      M01CAF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

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

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

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

       m1 = 1

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

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

       WRITE (nout,*)
       WRITE (nout,*) 'Sorted numbers'
       WRITE (nout,*)
       WRITE (nout,99999) (rv(i),i=m1,m2)

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