    Program g10bafe

!     G10BAF Example Program Text

!     Mark 24 Release. NAG Copyright 2012.

!     .. Use Statements ..
      Use nag_library, Only: g01agf, g10baf, nag_wp
!     .. Implicit None Statement ..
      Implicit None
!     .. Parameters ..
      Integer, Parameter               :: nin = 5, nout = 6
!     .. Local Scalars ..
      Real (Kind=nag_wp)               :: shi, slo, window
      Integer                          :: ifail, n, ns, nstepx, nstepy
      Logical                          :: usefft
!     .. Local Arrays ..
      Real (Kind=nag_wp), Allocatable  :: fft(:), smooth(:), t(:), x(:)
      Integer, Allocatable             :: isort(:)
!     .. Executable Statements ..
      Write (nout,*) 'G10BAF Example Program Results'
      Write (nout,*)
      Flush (nout)

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

!     Read in density estimation information
      Read (nin,*) window, slo, shi, ns

!     Read in plotting information
      Read (nin,*) nstepx, nstepy

!     Read in the size of the dataset
      Read (nin,*) n

      Allocate (smooth(ns),t(ns),fft(ns),x(n),isort(ns))

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

!     Perform kernel density estimation
      usefft = .False.
      ifail = 0
      Call g10baf(n,x,window,slo,shi,ns,smooth,t,usefft,fft,ifail)

!     Display smoothed data
      ifail = 0
      Call g01agf(t,smooth,ns,isort,nstepx,nstepy,ifail)

    End Program g10bafe
