    PROGRAM g01amfe

!      G01AMF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

!      .. Use Statements ..
       USE nag_library, ONLY : g01amf, nag_wp
!      .. Implicit None Statement ..
       IMPLICIT NONE
!      .. Parameters ..
       INTEGER, PARAMETER              :: nin = 5, nout = 6
!      .. Local Scalars ..
       INTEGER                         :: i, ifail, n, nq
!      .. Local Arrays ..
       REAL (KIND=nag_wp), ALLOCATABLE :: q(:), qv(:), rv(:)
!      .. Executable Statements ..
       WRITE (nout,*) 'G01AMF Example Program Results'
       WRITE (nout,*)

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

!      Read in the problem size
       READ (nin,*) n, nq

       ALLOCATE (q(nq),qv(nq),rv(n))

!      Read in data
       READ (nin,*) rv(1:n)

!      Read in the required quantiles
       READ (nin,*) q(1:nq)

!      Display data
       WRITE (nout,*) 'Data Values:'
       WRITE (nout,99998) rv(1:n)
       WRITE (nout,*)

!      Calculate the quantiles
       ifail = 0
       CALL g01amf(n,rv,nq,q,qv,ifail)

!      Display results
       WRITE (nout,*) 'Quantile     Result'
       WRITE (nout,*)
       WRITE (nout,99999) (q(i),qv(i),i=1,nq)

99999  FORMAT (1X,F7.2,4X,F7.2)
99998  FORMAT (1X,20F7.2)
    END PROGRAM g01amfe
