    PROGRAM g13aufe

!      G13AUF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

!      .. Use Statements ..
       USE nag_library, ONLY : g01agf, g13auf, nag_wp, x04abf
!      .. Implicit None Statement ..
       IMPLICIT NONE
!      .. Parameters ..
       INTEGER, PARAMETER              :: iset = 1, nin = 5, nout = 6
!      .. Local Scalars ..
       INTEGER                         :: ifail, m, n, nadv, ngrps, nstepx,    &
                                          nstepy
!      .. Local Arrays ..
       REAL (KIND=nag_wp), ALLOCATABLE :: mean(:), y(:), z(:)
       INTEGER, ALLOCATABLE            :: isort(:)
!      .. Executable Statements ..
       WRITE (nout,*) 'G13AUF Example Program Results'
       WRITE (nout,*)

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

!      Read in the problem size
       READ (nin,*) n, m

       ngrps = n/m

       ALLOCATE (z(n),y(ngrps),mean(ngrps),isort(ngrps))

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

!      Calculate summary statistics
       ifail = 0
       CALL g13auf(n,z,m,ngrps,'RANGE',y,mean,ifail)

!      Set the advisory channel to NOUT for the plot
       nadv = nout
       CALL x04abf(iset,nadv)

!      Read in parameters controlling scatter plot
       READ (nin,*) nstepx, nstepy

!      Display title
       WRITE (nout,*) '                                 Range-mean plot'
       WRITE (nout,*)
       FLUSH (nout)

!      Produce scatter plot
       CALL g01agf(mean,y,ngrps,isort,nstepx,nstepy,ifail)

    END PROGRAM g13aufe
