```    Program f08bafe

!     F08BAF Example Program Text

!     Mark 25 Release. NAG Copyright 2014.

!     .. Use Statements ..
Use nag_library, Only: dgelsy, nag_wp
!     .. Implicit None Statement ..
Implicit None
!     .. Parameters ..
Integer, Parameter               :: nb = 64, nin = 5, nout = 6
!     .. Local Scalars ..
Real (Kind=nag_wp)               :: rcond
Integer                          :: i, info, lda, lwork, m, n, rank
!     .. Local Arrays ..
Real (Kind=nag_wp), Allocatable  :: a(:,:), b(:), work(:)
Integer, Allocatable             :: jpvt(:)
!     .. Executable Statements ..
Write (nout,*) 'F08BAF Example Program Results'
Write (nout,*)
!     Skip heading in data file
lda = m
lwork = 3*n + nb*(n+1)
Allocate (a(lda,n),b(m),work(lwork),jpvt(n))

!     Read A and B from data file

!     Initialize JPVT to be zero so that all columns are free

jpvt(1:n) = 0

!     Choose RCOND to reflect the relative accuracy of the input data

rcond = 0.01_nag_wp

!     Solve the least squares problem min( norm2(b - Ax) ) for the x
!     of minimum norm.

!     The NAG name equivalent of dgelsy is f08baf
Call dgelsy(m,n,1,a,lda,b,m,jpvt,rcond,rank,work,lwork,info)

!     Print solution

Write (nout,*) 'Least squares solution'
Write (nout,99999) b(1:n)

!     Print the effective rank of A

Write (nout,*)
Write (nout,*) 'Tolerance used to estimate the rank of A'
Write (nout,99998) rcond
Write (nout,*) 'Estimated rank of A'
Write (nout,99997) rank

99999 Format (1X,7F11.4)
99998 Format (3X,1P,E11.2)
99997 Format (1X,I6)
End Program f08bafe
```