    Program g01kqfe
!     G01KQF Example Program Text

!     Mark 24 Release. NAG Copyright 2012.

!     .. Use Statements ..
      Use nag_library, Only: g01kqf, nag_wp
!     .. Implicit None Statement ..
      Implicit None
!     .. Parameters ..
      Integer, Parameter               :: nin = 5, nout = 6
!     .. Local Scalars ..
      Integer                          :: i, ifail, ilog, lout, lx, lxmu, lxstd
!     .. Local Arrays ..
      Real (Kind=nag_wp), Allocatable  :: pdf(:), x(:), xmu(:), xstd(:)
      Integer, Allocatable             :: ivalid(:)
!     .. Intrinsic Procedures ..
      Intrinsic                        :: max, mod, repeat
!     .. Executable Statements ..
      Write (nout,*) 'G01KQF Example Program Results'
      Write (nout,*)

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

!     Read in flag indicating whether logs are required
      Read (nin,*) ilog

!     Read in the input vectors
      Read (nin,*) lx
      Allocate (x(lx))
      Read (nin,*) x(1:lx)

      Read (nin,*) lxmu
      Allocate (xmu(lxmu))
      Read (nin,*) xmu(1:lxmu)

      Read (nin,*) lxstd
      Allocate (xstd(lxstd))
      Read (nin,*) xstd(1:lxstd)

!     Allocate memory for output
      lout = max(lx,lxmu,lxstd)
      Allocate (pdf(lout),ivalid(lout))

!     Calculate the PDF
      ifail = -1
      Call g01kqf(ilog,lx,x,lxmu,xmu,lxstd,xstd,pdf,ivalid,ifail)

      If (ifail==0 .Or. ifail==1) Then
!       Display titles
        Write (nout,*) '    X        XMU      XSTD        PDF      IVALID'
        Write (nout,*) repeat('-',50)

!       Display results
        Do i = 1, lout
          Write (nout,99999) x(mod(i-1,lx)+1), xmu(mod(i-1,lxmu)+1), &
            xstd(mod(i-1,lxstd)+1), pdf(i), ivalid(i)
        End Do
      End If

99999 Format (1X,3(F6.2,4X),E10.3,4X,I3)
    End Program g01kqfe
