NAG Library Manual, Mark 29.3
```    Program g03cafe

!     G03CAF Example Program Text

!     Mark 29.3 Release. NAG Copyright 2023.

!     .. Use Statements ..
Use nag_library, Only: g03caf, nag_wp
!     .. Implicit None Statement ..
Implicit None
!     .. Parameters ..
Integer, Parameter               :: nin = 5, nout = 6
!     .. Local Scalars ..
Integer                          :: i, ifail, l, ldfl, ldx, liwk, lres,  &
lwk, lwt, m, n, nfac, nvar
Character (1)                    :: matrix, weight
!     .. Local Arrays ..
Real (Kind=nag_wp), Allocatable  :: com(:), e(:), fl(:,:), psi(:),       &
res(:), wk(:), wt(:), x(:,:)
Real (Kind=nag_wp)               :: stat(4)
Integer                          :: iop(5)
Integer, Allocatable             :: isx(:), iwk(:)
!     .. Intrinsic Procedures ..
Intrinsic                        :: max
!     .. Executable Statements ..
Write (nout,*) 'G03CAF Example Program Results'
Write (nout,*)

!     Skip headings in data file

!     Read in the problem size
Read (nin,*) matrix, weight, n, m, nvar, nfac

lwk = (5*nvar*nvar+33*nvar-4)/2
If (matrix=='C' .Or. matrix=='c') Then
lwt = 0
ldx = m
Else
If (weight=='W' .Or. weight=='w') Then
lwt = n
Else
lwt = 0
End If
ldx = n
lwk = max(lwk,n*nvar+7*nvar+nvar*(nvar-1)/2)
End If
ldfl = nvar
lres = nvar*(nvar-1)/2
liwk = 4*nvar + 2
Allocate (x(ldx,m),isx(m),wt(lwt),e(nvar),com(nvar),psi(nvar),res(lres), &
fl(ldfl,nfac),iwk(liwk),wk(lwk))

If (lwt>0) Then
Else
End If

!     Read in variable inclusion flags

!     Fit factor analysis model
ifail = -1
Call g03caf(matrix,weight,n,m,x,ldx,nvar,isx,nfac,wt,e,stat,com,psi,res, &
fl,ldfl,iop,iwk,wk,lwk,ifail)
If (ifail/=0) Then
If (ifail<=4) Then
Go To 100
End If
End If

!     Display results
Write (nout,*) ' Eigenvalues'
Write (nout,*)
Write (nout,99998) e(1:nvar)
Write (nout,*)
Write (nout,99997) '     Test Statistic = ', stat(2)
Write (nout,99997) '                 df = ', stat(3)
Write (nout,99997) ' Significance level = ', stat(4)
Write (nout,*)
Write (nout,*) ' Residuals'
Write (nout,*)
l = 1
Do i = 1, nvar - 1
Write (nout,99999) res(l:(l+i-1))
l = l + i
End Do
Write (nout,*)