Example description
    Program f07hffe

!     F07HFF Example Program Text

!     Mark 27.0 Release. NAG Copyright 2019.

!     .. Use Statements ..
      Use nag_library, Only: dpbequ, 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
      Character (1), Parameter         :: uplo = 'U'
!     .. Local Scalars ..
      Real (Kind=nag_wp)               :: amax, big, scond, small
      Integer                          :: i, i0, i1, ifail, ilen, info, j, kd, &
                                          ldab, n
!     .. Local Arrays ..
      Real (Kind=nag_wp), Allocatable  :: ab(:,:), s(:)
!     .. Intrinsic Procedures ..
      Intrinsic                        :: max, min, real
!     .. Executable Statements ..
      Write (nout,*) 'F07HFF Example Program Results'
      Write (nout,*)
      Flush (nout)
!     Skip heading in data file
      Read (nin,*)
      Read (nin,*) n, kd
      ldab = kd + 1
      Allocate (ab(ldab,n),s(n))

!     Read the upper or lower triangular part of the band matrix A
!     from data file

      If (uplo=='U') Then
        Do i = 1, n
          Read (nin,*)(ab(kd+1+i-j,j),j=i,min(n,i+kd))
        End Do
      Else If (uplo=='L') Then
        Do i = 1, n
          Read (nin,*)(ab(1+i-j,j),j=max(1,i-kd),i)
        End Do
      End If

!     Print the matrix A

!     ifail: behaviour on error exit
!             =0 for hard exit, =1 for quiet-soft, =-1 for noisy-soft
      ifail = 0
      If (uplo=='U') Then
        Call x04cef(n,n,0,kd,ab,ldab,'Matrix A',ifail)
      Else If (uplo=='L') Then
        Call x04cef(n,n,kd,0,ab,ldab,'Matrix A',ifail)
      End If

      Write (nout,*)

!     Compute diagonal scaling factors
!     The NAG name equivalent of dpbequ is f07hff
      Call dpbequ(uplo,n,kd,ab,ldab,s,scond,amax,info)

      If (info>0) Then
        Write (nout,99999) 'Diagonal element', info, ' of A is non positive'
      Else

!       Print SCOND, AMAX and the scale factors

        Write (nout,99998) 'SCOND =', scond, ', AMAX =', amax
        Write (nout,*)
        Write (nout,*) 'Diagonal scaling factors'
        Write (nout,99997) s(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 ((scond<thresh) .Or. (amax<small) .Or. (amax>big)) Then

!         Scale A
          If (uplo=='U') Then

!           The NAG name equivalent of dscal is f06edf
            Do j = 1, n
              i0 = max(1,j-kd)
              i1 = 1 + i0 - (j-kd)
              ilen = j - i0 + 1
              Call dscal(ilen,s(j),ab(i1,j),1)
              Call f06fcf(ilen,s(i0),1,ab(i1,j),1)
            End Do

          Else If (uplo=='L') Then
            Do j = 1, n
              i1 = 1
              ilen = min(n,j+kd) - j + 1
              Call dscal(ilen,s(j),ab(i1,j),1)
              Call f06fcf(ilen,s(j),1,ab(i1,j),1)
            End Do
          End If

!         Print the scaled matrix

          ifail = 0
          If (uplo=='U') Then
            Call x04cef(n,n,0,kd,ab,ldab,'Scaled matrix',ifail)
          Else If (uplo=='L') Then
            Call x04cef(n,n,kd,0,ab,ldab,'Scaled matrix',ifail)
          End If
        End If
      End If

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