Program f03bhfe

!     F03BHF Example Program Text

!     Mark 26.1 Release. NAG Copyright 2016.

!     .. Use Statements ..
      Use nag_library, Only: dpbtrf, f03bhf, nag_wp, x04cef
!     .. Implicit None Statement ..
      Implicit None
!     .. Parameters ..
      Integer, Parameter               :: nin = 5, nout = 6
!     .. Local Scalars ..
      Real (Kind=nag_wp)               :: d
      Integer                          :: i, id, ifail, info, j, kd, kl, ku,   &
                                          ldab, n
      Character (1)                    :: uplo
!     .. Local Arrays ..
      Real (Kind=nag_wp), Allocatable  :: ab(:,:)
!     .. Intrinsic Procedures ..
      Intrinsic                        :: index, max, min
!     .. Executable Statements ..
      Write (nout,*) 'F03BHF Example Program Results'

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

      Read (nin,*) uplo

      Read (nin,*) n, kd
      ldab = kd + 1
      Allocate (ab(ldab,n))

      If (index('Ll',uplo)<=0) Then
!       Read in upper triangular banded matrix
        ku = kd
        kl = 0
        Do i = 1, n
          Read (nin,*)(ab(kd+1+i-j,j),j=i,min(i+kd,n))
        End Do
      Else
!       Read in lower triangular banded matrix
        ku = 0
        kl = kd
        Do i = 1, n
          Read (nin,*)(ab(1+i-j,j),j=max(1,i-kd),i)
        End Do
      End If
!     Factorize A
!     The NAG name equivalent of dpbtrf is f07hdf
      Call dpbtrf(uplo,n,kd,ab,ldab,info)

      If (info==0) Then
        Write (nout,*)
        Flush (nout)
        ifail = 0
        Call x04cef(n,n,kl,ku,ab,ldab,'Array AB after factorization',ifail)

        ifail = 0
        Call f03bhf(uplo,n,kd,ab,ldab,d,id,ifail)

        Write (nout,*)
        Write (nout,99999) d, id
        Write (nout,*)
        Write (nout,99998) d*2.0E0_nag_wp**id
      Else
        Write (nout,99997) info
      End If

99999 Format (1X,'D = ',F13.5,' ID = ',I0)
99998 Format (1X,'Value of determinant = ',E13.5)
99997 Format (' ** Factorization routine return error flag info = ',I0,'.')
    End Program f03bhfe