    Program g01amfe

!     G01AMF Example Program Text

!     Mark 24 Release. NAG Copyright 2012.

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