    PROGRAM g01adfe

!      G01ADF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

!      .. Use Statements ..
       USE nag_library, ONLY : g01adf, nag_wp
!      .. Implicit None Statement ..
       IMPLICIT NONE
!      .. Parameters ..
       INTEGER, PARAMETER              :: nin = 5, nout = 6
!      .. Local Scalars ..
       REAL (KIND=nag_wp)              :: s2, s3, s4, xmean
       INTEGER                         :: i, ifail, k, kmin1, n
!      .. Local Arrays ..
       REAL (KIND=nag_wp), ALLOCATABLE :: x(:)
       INTEGER, ALLOCATABLE            :: ifreq(:)
!      .. Executable Statements ..
       WRITE (nout,*) 'G01ADF Example Program Results'
       WRITE (nout,*)

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

!      Read in the problem size
       READ (nin,*) kmin1
       k = kmin1 + 1

       ALLOCATE (ifreq(k),x(k))

!      Read in data
       READ (nin,*) (x(i),ifreq(i),i=1,kmin1), x(k)

!      Calculate summary statistics
       ifail = 0
       CALL g01adf(k,x,ifreq,xmean,s2,s3,s4,n,ifail)

!      Display results
       WRITE (nout,99999) 'Number of classes ', kmin1
       WRITE (nout,*)
       WRITE (nout,*) '          Class          Frequency'
       WRITE (nout,*)
       WRITE (nout,99998) (x(i),x(i+1),ifreq(i),i=1,kmin1)
       WRITE (nout,*)
       WRITE (nout,99997) ' Mean ', xmean
       WRITE (nout,99996) ' Std devn', s2
       WRITE (nout,99996) ' Skewness', s3
       WRITE (nout,99996) ' Kurtosis', s4
       WRITE (nout,99995) ' Number of cases', n


99999  FORMAT (1X,A,I4)
99998  FORMAT (1X,2F10.2,I12)
99997  FORMAT (1X,A,F16.4)
99996  FORMAT (1X,A,F13.4)
99995  FORMAT (1X,A,I8)
    END PROGRAM g01adfe
