    PROGRAM g08alfe

!      G08ALF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

!      .. Use Statements ..
       USE nag_library, ONLY : g08alf, nag_wp, x04caf
!      .. Implicit None Statement ..
       IMPLICIT NONE
!      .. Parameters ..
       INTEGER, PARAMETER              :: nin = 5, nout = 6
!      .. Local Scalars ..
       REAL (KIND=nag_wp)              :: df, prob, q
       INTEGER                         :: i, ifail, k, ldx, n
!      .. Local Arrays ..
       REAL (KIND=nag_wp), ALLOCATABLE :: x(:,:)
!      .. Intrinsic Functions ..
       INTRINSIC                          real
!      .. Executable Statements ..
       WRITE (nout,*) 'G08ALF Example Program Results'
       WRITE (nout,*)

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

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

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

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

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

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

!      Perform test
       ifail = 0
       CALL g08alf(n,k,x,ldx,q,prob,ifail)

!      Display results
       df = real(k-1,kind=nag_wp)
       WRITE (nout,*)
       WRITE (nout,99999) 'Cochrans Q test statistic = ', q
       WRITE (nout,99998) 'Degrees of freedom = ', df
       WRITE (nout,99999) 'Upper-tail probability = ', prob

99999  FORMAT (1X,A,F12.4)
99998  FORMAT (1X,A,F6.1)
    END PROGRAM g08alfe
