    Program g13aufe

!     G13AUF Example Program Text

!     Mark 24 Release. NAG Copyright 2012.

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