    Program g01kkfe
!     G01KKF Example Program Text

!     Mark 24 Release. NAG Copyright 2012.

!     .. Use Statements ..
      Use nag_library, Only: g01kkf, nag_wp
!     .. Implicit None Statement ..
      Implicit None
!     .. Parameters ..
      Integer, Parameter               :: nin = 5, nout = 6
!     .. Local Scalars ..
      Integer                          :: i, ifail, ilog, la, lb, lout, lx
!     .. Local Arrays ..
      Real (Kind=nag_wp), Allocatable  :: a(:), b(:), pdf(:), x(:)
      Integer, Allocatable             :: ivalid(:)
!     .. Intrinsic Procedures ..
      Intrinsic                        :: max, mod, repeat
!     .. Executable Statements ..
      Write (nout,*) 'G01KKF 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,*) la
      Allocate (a(la))
      Read (nin,*) a(1:la)

      Read (nin,*) lb
      Allocate (b(lb))
      Read (nin,*) b(1:lb)

!     Allocate memory for output
      lout = max(lx,la,lb)
      Allocate (pdf(lout),ivalid(lout))

!     Calculate the PDF
      ifail = -1
      Call g01kkf(ilog,lx,x,la,a,lb,b,pdf,ivalid,ifail)

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

!       Display results
        Do i = 1, lout
          Write (nout,99999) x(mod(i-1,lx)+1), a(mod(i-1,la)+1), &
            b(mod(i-1,lb)+1), pdf(i), ivalid(i)
        End Do
      End If

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