    PROGRAM f01bvfe

!      F01BVF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

!      .. Use Statements ..
       USE nag_library, ONLY : dsbtrd, dstebz, f01buf, f01bvf, nag_wp
!      .. Implicit None Statement ..
       IMPLICIT NONE
!      .. Parameters ..
       REAL (KIND=nag_wp), PARAMETER   :: zero = 0.0_nag_wp
       INTEGER, PARAMETER              :: inc1 = 1, nin = 5, nout = 6
!      .. Local Scalars ..
       REAL (KIND=nag_wp)              :: abstol
       INTEGER                         :: i, ifail, info, j, k, lda, ldb, ldv, &
                                          m, m1, m2, m3, ma1, mb1, n, nsplit
!      .. Local Arrays ..
       REAL (KIND=nag_wp), ALLOCATABLE :: a(:,:), b(:,:), d(:), e(:), r(:),    &
                                          v(:,:), w(:), work(:)
       INTEGER, ALLOCATABLE            :: iblock(:), isplit(:), iwork(:)
!      .. Intrinsic Functions ..
       INTRINSIC                          max
!      .. Executable Statements ..
       WRITE (nout,*) 'F01BVF Example Program Results'
!      Skip heading in data file
       READ (nin,*)
       READ (nin,*) n, ma1, mb1
       lda = ma1
       ldb = mb1
       ldv = ma1 + mb1 - 2
       m3 = 3*ma1 + mb1 - 4
       ALLOCATE (a(lda,n),b(ldb,n),d(n),e(n),r(n),v(ldv,m3),w(m3),work(4*n), &
          iblock(n),isplit(n),iwork(3*n))
       READ (nin,*) ((a(j,i),j=max(1,ma1+1-i),ma1),i=1,n)
       READ (nin,*) ((b(j,i),j=max(1,mb1+1-i),mb1),i=1,n)
       k = n/2

!      ifail: behaviour on error exit
!             =0 for hard exit, =1 for quiet-soft, =-1 for noisy-soft
       ifail = 0
       CALL f01buf(n,mb1,k,b,ldb,w,ifail)

       ifail = 0
       CALL f01bvf(n,ma1,mb1,m3,k,a,lda,b,ldb,v,ldv,w,ifail)

       info = 0
!      The NAG name equivalent of dsbtrd is f08hef
       CALL dsbtrd('N','U',n,ma1-1,a,lda,d,e,w,inc1,work,info)

       abstol = zero
       READ (nin,*) m1, m2

       info = 0
!      The NAG name equivalent of dstebz is f08jjf
       CALL dstebz('I','E',n,zero,zero,m1,m2,abstol,d,e,m,nsplit,r,iblock, &
          isplit,work,iwork,info)

       WRITE (nout,*)
       WRITE (nout,*) 'Selected eigenvalues'
       WRITE (nout,99999) r(1:m)

99999  FORMAT (1X,8F9.4)
    END PROGRAM f01bvfe
