    PROGRAM g10bafe

!      G10BAF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

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