PROGRAM g08agfe

!      G08AGF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

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