NAG Library Manual, Mark 28.5
Interfaces:  FL   CL   CPP   AD 

NAG FL Interface Introduction
Example description
    Program g04bcfe

!     G04BCF Example Program Text

!     Mark 28.5 Release. NAG Copyright 2022.

!     .. Use Statements ..
      Use nag_library, Only: g04bcf, nag_wp
!     .. Implicit None Statement ..
      Implicit None
!     .. Parameters ..
      Integer, Parameter               :: ldtabl = 6, nin = 5, nout = 6
!     .. Local Scalars ..
      Real (Kind=nag_wp)               :: gmean, tol
      Integer                          :: ifail, irdf, ldc, lit, n, ncol,      &
                                          nrep, nrow, nt
!     .. Local Arrays ..
      Real (Kind=nag_wp), Allocatable  :: c(:,:), cmean(:), ef(:), r(:),       &
                                          rmean(:), rpmean(:), tmean(:),       &
                                          wk(:), y(:)
      Real (Kind=nag_wp)               :: tabl(ldtabl,5)
      Integer, Allocatable             :: irep(:), it(:)
!     .. Executable Statements ..
      Write (nout,*) 'G04BCF Example Program Results'
      Write (nout,*)

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

!     Read in the problem size
      Read (nin,*) nrep, nrow, ncol, nt

      n = nrep*nrow*ncol
      If (nt>1) Then
        lit = n
      Else
        lit = 1
      End If
      ldc = nt
      Allocate (irep(nt),y(n),tmean(nt),it(lit),c(ldc,nt),rpmean(nrep),        &
        rmean(nrep*nrow),cmean(nrep*ncol),r(n),ef(nt),wk(3*nt))

!     Read in the data
      Read (nin,*) y(1:n)
      If (nt>1) Then
        Read (nin,*) it(1:n)
      End If

!     Use default tolerance
      tol = 0.0E0_nag_wp

!     Use standard degrees of freedom
      irdf = 0

!     Calculate the ANOVA table
      ifail = 0
      Call g04bcf(nrep,nrow,ncol,y,nt,it,gmean,tmean,tabl,ldtabl,c,ldc,irep,   &
        rpmean,rmean,cmean,r,ef,tol,irdf,wk,ifail)

!     Display results
      Write (nout,*) ' ANOVA TABLE'
      Write (nout,*)
      If (nrep>1) Then
        Write (nout,99998) ' Reps        ', tabl(1,1:5)
      End If
      Write (nout,99998) ' Rows        ', tabl(2,1:5)
      Write (nout,99998) ' Columns     ', tabl(3,1:5)
      If (nt>1) Then
        Write (nout,99998) ' Treatments  ', tabl(4,1:5)
      End If
      Write (nout,99998) ' Residual    ', tabl(5,1:3)
      Write (nout,99998) ' Total       ', tabl(6,1:2)
      If (nt>1) Then
        Write (nout,*)
        Write (nout,*) ' Treatment means'
        Write (nout,*)
        Write (nout,99999) tmean(1:nt)
        Write (nout,*)
        Write (nout,99997) ' S.E. of difference (orthogonal design) = ',       &
          c(2,1)
      End If

99999 Format (10F10.4)
99998 Format (A,F3.0,2X,3(F10.4,2X),F8.4)
99997 Format (A,F10.4)
    End Program g04bcfe