    PROGRAM f08ksfe

!      F08KSF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

!      .. Use Statements ..
       USE nag_library, ONLY : nag_wp, zgebrd
!      .. Implicit None Statement ..
       IMPLICIT NONE
!      .. Parameters ..
       INTEGER, PARAMETER              :: nin = 5, nout = 6
!      .. Local Scalars ..
       INTEGER                         :: i, info, lda, lwork, m, n
!      .. Local Arrays ..
       COMPLEX (KIND=nag_wp), ALLOCATABLE :: a(:,:), taup(:), tauq(:), work(:)
       REAL (KIND=nag_wp), ALLOCATABLE :: d(:), e(:)
!      .. Intrinsic Functions ..
       INTRINSIC                          min
!      .. Executable Statements ..
       WRITE (nout,*) 'F08KSF Example Program Results'
!      Skip heading in data file
       READ (nin,*)
       READ (nin,*) m, n
       lda = m
       lwork = 64*(m+n)
       ALLOCATE (a(lda,n),taup(n),tauq(n),work(lwork),d(n),e(n-1))

!      Read A from data file

       READ (nin,*) (a(i,1:n),i=1,m)

!      Reduce A to bidiagonal form

!      The NAG name equivalent of zgebrd is f08ksf
       CALL zgebrd(m,n,a,lda,d,e,tauq,taup,work,lwork,info)

!      Print bidiagonal form

       WRITE (nout,*)
       WRITE (nout,*) 'Diagonal'
       WRITE (nout,99999) d(1:min(m,n))
       IF (m>=n) THEN
          WRITE (nout,*) 'Super-diagonal'
       ELSE
          WRITE (nout,*) 'Sub-diagonal'
       END IF
       WRITE (nout,99999) e(1:min(m,n)-1)

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