    Program g08agfe

!     G08AGF Example Program Text

!     Mark 24 Release. NAG Copyright 2012.

!     .. Use Statements ..
      Use nag_library, Only: g08agf, nag_wp
!     .. Implicit None Statement ..
      Implicit None
!     .. Parameters ..
      Integer, Parameter               :: nin = 5, nout = 6
!     .. Local Scalars ..
      Real (Kind=nag_wp)               :: p, w, wnor, xme
      Integer                          :: ifail, n, n1
      Character (1)                    :: tail, zer
!     .. Local Arrays ..
      Real (Kind=nag_wp), Allocatable  :: wrk(:), x(:), y(:), z(:)
!     .. Executable Statements ..
      Write (nout,*) 'G08AGF Example Program Results'
      Write (nout,*)

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

!     Read in the problem size, median test value and details of
!     test to perform
      Read (nin,*) n, xme, tail, zer

      Allocate (x(n),y(n),z(n),wrk(3*n))

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

!     Display title
      Write (nout,*) 'Wilcoxon one sample signed ranks test'
      Write (nout,*)

!     Display input data
      Write (nout,*) 'Data values'
      Write (nout,99999) x(1:n)
      Write (nout,99999) y(1:n)

!     Calculate difference
      z(1:n) = x(1:n) - y(1:n)

!     Perform test
      ifail = 0
      Call g08agf(n,z,xme,tail,zer,w,wnor,p,n1,wrk,ifail)

!     Display results
      Write (nout,*)
      Write (nout,99998) 'Test statistic            = ', w
      Write (nout,99998) 'Normalized test statistic = ', wnor
      Write (nout,99997) 'Degrees of freedom        = ', n1
      Write (nout,99998) 'Two tail probability      = ', p

99999 Format (4X,8F5.1)
99998 Format (1X,A,F8.4)
99997 Format (1X,A,I8)
    End Program g08agfe
