```    Program f07bffe

!     F07BFF Example Program Text

!     Mark 26.1 Release. NAG Copyright 2017.

!     .. Use Statements ..
Use nag_library, Only: dgbequ, dscal, f06fcf, nag_wp, x02ajf, x02amf,    &
x02bhf, x04cef
!     .. Implicit None Statement ..
Implicit None
!     .. Parameters ..
Real (Kind=nag_wp), Parameter    :: one = 1.0_nag_wp
Real (Kind=nag_wp), Parameter    :: thresh = 0.1_nag_wp
Integer, Parameter               :: nin = 5, nout = 6
!     .. Local Scalars ..
Real (Kind=nag_wp)               :: amax, big, colcnd, rowcnd, small
Integer                          :: i, i0, i1, ifail, ilen, info, j, k,  &
kl, ku, ldab, n
!     .. Local Arrays ..
Real (Kind=nag_wp), Allocatable  :: ab(:,:), c(:), r(:)
!     .. Intrinsic Procedures ..
Intrinsic                        :: max, min, real
!     .. Executable Statements ..
Write (nout,*) 'F07BFF Example Program Results'
Write (nout,*)
Flush (nout)
!     Skip heading in data file
ldab = kl + ku + 1
Allocate (ab(ldab,n),c(n),r(n))

!     Read the band matrix A from data file

k = ku + 1

!     Print the matrix A

!     ifail: behaviour on error exit
!             =0 for hard exit, =1 for quiet-soft, =-1 for noisy-soft
ifail = 0
Call x04cef(n,n,kl,ku,ab,ldab,'Matrix A',ifail)

Write (nout,*)

!     Compute row and column scaling factors

!     The NAG name equivalent of dgbequ is f07bff
Call dgbequ(n,n,kl,ku,ab,ldab,r,c,rowcnd,colcnd,amax,info)

If (info>0) Then
If (info<=n) Then
Write (nout,99999) 'Row ', info, ' of A is exactly zero'
Else
Write (nout,99999) 'Column ', info - n, ' of A is exactly zero'
End If
Else

!       Print ROWCND, COLCND, AMAX and the scale factors

Write (nout,99998) 'ROWCND =', rowcnd, ', COLCND =', colcnd,           &
', AMAX =', amax
Write (nout,*)
Write (nout,*) 'Row scale factors'
Write (nout,99997) r(1:n)
Write (nout,*)
Write (nout,*) 'Column scale factors'
Write (nout,99997) c(1:n)
Write (nout,*)
Flush (nout)

!       Compute values close to underflow and overflow

small = x02amf()/(x02ajf()*real(x02bhf(),kind=nag_wp))
big = one/small
If ((rowcnd>=thresh) .And. (amax>=small) .And. (amax<=big)) Then
If (colcnd<thresh) Then
!           Just column scale A
!           The NAG name equivalent of dscal is f06edf
Do j = 1, n
i1 = 1 + max(1,j-ku) - (j-ku)
ilen = min(n,j+kl) - max(1,j-ku) + 1
Call dscal(ilen,c(j),ab(i1,j),1)
End Do

End If
Else If (colcnd>=thresh) Then

!         Just row scale A
Do j = 1, n
i0 = max(1,j-ku)
i1 = 1 + i0 - (j-ku)
ilen = min(n,j+kl) - i0 + 1
Call f06fcf(ilen,r(i0),1,ab(i1,j),1)
End Do

Else

!         Row and column scale A
Do j = 1, n
i0 = max(1,j-ku)
i1 = 1 + i0 - (j-ku)
ilen = min(n,j+kl) - i0 + 1
Call dscal(ilen,c(j),ab(i1,j),1)
Call f06fcf(ilen,r(i0),1,ab(i1,j),1)
End Do

End If

!       Print the scaled matrix
ifail = 0
Call x04cef(n,n,kl,ku,ab,ldab,'Scaled matrix',ifail)

End If

99999 Format (1X,A,I4,A)
99998 Format (1X,3(A,1P,E8.1))
99997 Format ((1X,1P,7E11.2))
End Program f07bffe
```