    PROGRAM g08aefe

!      G08AEF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

!      .. Use Statements ..
       USE nag_library, ONLY : g08aef, nag_wp, x04caf
!      .. Implicit None Statement ..
       IMPLICIT NONE
!      .. Parameters ..
       INTEGER, PARAMETER              :: nin = 5, nout = 6
!      .. Local Scalars ..
       REAL (KIND=nag_wp)              :: fr, p
       INTEGER                         :: i, ifail, k, ldx, n
!      .. Local Arrays ..
       REAL (KIND=nag_wp), ALLOCATABLE :: w1(:), w2(:), x(:,:)
!      .. Executable Statements ..
       WRITE (nout,*) 'G08AEF Example Program Results'
       WRITE (nout,*)

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

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

       ldx = k
       ALLOCATE (x(ldx,n),w1(k),w2(k))

!      Read in data
       READ (nin,*) (x(i,1:n),i=1,k)

!      Display title
       WRITE (nout,*) 'Friedman test'
       WRITE (nout,*)
       FLUSH (nout)

!      Display input data
       ifail = 0
       CALL x04caf('General',' ',k,n,x,ldx,'Data values',ifail)

!      Perform ANOVA
       ifail = 0
       CALL g08aef(x,ldx,k,n,w1,w2,fr,p,ifail)

!      Display results
       WRITE (nout,*)
       WRITE (nout,99999) 'Test statistic       ', fr
       WRITE (nout,99998) 'Degrees of freedom   ', k - 1
       WRITE (nout,99999) 'Significance         ', p

99999  FORMAT (1X,A,F6.3)
99998  FORMAT (1X,A,I6)
    END PROGRAM g08aefe
