    PROGRAM f08lefe

!      F08LEF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

!      .. Use Statements ..
       USE nag_library, ONLY : dgbbrd, nag_wp
!      .. Implicit None Statement ..
       IMPLICIT NONE
!      .. Parameters ..
       INTEGER, PARAMETER              :: nin = 5, nout = 6
       CHARACTER (1), PARAMETER        :: vect = 'N'
!      .. Local Scalars ..
       INTEGER                         :: i, info, j, kl, ku, ldab, ldc, ldpt, &
                                          ldq, m, n, ncc
!      .. Local Arrays ..
       REAL (KIND=nag_wp), ALLOCATABLE :: ab(:,:), c(:,:), d(:), e(:),         &
                                          pt(:,:), q(:,:), work(:)
!      .. Intrinsic Functions ..
       INTRINSIC                          max, min
!      .. Executable Statements ..
       WRITE (nout,*) 'F08LEF Example Program Results'
!      Skip heading in data file
       READ (nin,*)
       READ (nin,*) m, n, kl, ku, ncc
       ldab = kl + ku + 1
       ldc = m
       ldpt = n
       ldq = m
       ALLOCATE (ab(ldab,n),c(m,ncc),d(n),e(n-1),pt(ldpt,n),q(ldq,m), &
          work(2*m+2*n))

!      Read A from data file

       READ (nin,*) ((ab(ku+1+i-j,j),j=max(i-kl,1),min(i+ku,n)),i=1,m)

!      Reduce A to upper bidiagonal form

!      The NAG name equivalent of dgbbrd is f08lef
       CALL dgbbrd(vect,m,n,ncc,kl,ku,ab,ldab,d,e,q,ldq,pt,ldpt,c,ldc,work, &
          info)

!      Print bidiagonal form

       WRITE (nout,*)
       WRITE (nout,*) 'Diagonal'
       WRITE (nout,99999) d(1:min(m,n))
       WRITE (nout,*) 'Super-diagonal'
       WRITE (nout,99999) e(1:min(m,n)-1)

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