Program g01ahfe

!     G01AHF Example Program Text

!     Mark 25 Release. NAG Copyright 2014.

!     .. Use Statements ..
      Use nag_library, Only: g01ahf, nag_wp, x04abf
!     .. Implicit None Statement ..
      Implicit None
!     .. Parameters ..
      Integer, Parameter               :: iset = 1, nin = 5, nout = 6
!     .. Local Scalars ..
      Real (Kind=nag_wp)               :: xbar, xstd
      Integer                          :: ifail, istand, lwork, nobs, nstepx,  &
                                          nstepy, outchn
      Character (80)                   :: title
!     .. Local Arrays ..
      Real (Kind=nag_wp), Allocatable  :: work(:), x(:), xsort(:)
      Integer, Allocatable             :: iwork(:)
!     .. Intrinsic Procedures ..
      Intrinsic                        :: len_trim
!     .. Executable Statements ..
      Write (nout,*) 'G01AHF Example Program Results'
      Write (nout,*)

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

!     Read in the problem size
      Read (nin,*) nobs, nstepx, nstepy, istand

      lwork = 5*nobs/2
      Allocate (iwork(nobs),xsort(nobs),x(nobs),work(lwork))

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

!     Read in the title
      Read (nin,99997) title

!     Set advisory channel
      outchn = nout
      Call x04abf(iset,outchn)

!     Display data to be plotted
      Write (nout,*) 'Data values to be plotted'
      Write (nout,99998) x(1:nobs)
      Write (nout,*)
      Write (nout,*)

!     Display title
      Write (nout,*)
      Write (nout,*) title(1:len_trim(title))
      Write (nout,*)
      Flush (nout)

!     Produce the plot
      ifail = 0
      Call g01ahf(x,nobs,nstepx,nstepy,istand,iwork,work,lwork,xsort,xbar, &
        xstd,ifail)

!     Display additional results
      Write (nout,*)
      Write (nout,99999) 'Mean of data values = ', xbar
      Write (nout,99999) 'Standard deviation  = ', xstd
      Write (nout,*)
      Write (nout,*) 'Sorted standardised data values'
      Write (nout,99998) xsort(1:nobs)

99999 Format (1X,A,F5.2)
99998 Format (5X,5F7.2)
99997 Format (A80)
    End Program g01ahfe