    PROGRAM f08nnfe

!      F08NNF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

!      .. Use Statements ..
       USE nag_library, ONLY : nag_wp, x04daf, zgeev
!      .. Implicit None Statement ..
       IMPLICIT NONE
!      .. Parameters ..
       INTEGER, PARAMETER              :: nb = 64, nin = 5, nout = 6
!      .. Local Scalars ..
       INTEGER                         :: i, ifail, info, lda, ldvr, lwork, n
!      .. Local Arrays ..
       COMPLEX (KIND=nag_wp), ALLOCATABLE :: a(:,:), vr(:,:), w(:), work(:)
       COMPLEX (KIND=nag_wp)           :: dummy(1,1)
       REAL (KIND=nag_wp), ALLOCATABLE :: rwork(:)
!      .. Intrinsic Functions ..
       INTRINSIC                          max, nint, real
!      .. Executable Statements ..
       WRITE (nout,*) 'F08NNF Example Program Results'
       WRITE (nout,*)
!      Skip heading in data file
       READ (nin,*)
       READ (nin,*) n
       lda = n
       ldvr = n
       ALLOCATE (a(lda,n),vr(ldvr,n),w(n),rwork(2*n))

!      Use routine workspace query to get optimal workspace.
       lwork = -1
!      The NAG name equivalent of zgeev is f08nnf
       CALL zgeev('No left vectors','Vectors (right)',n,a,lda,w,dummy,1,vr, &
          ldvr,dummy,lwork,rwork,info)

!      Make sure that there is enough workspace for blocksize nb.
       lwork = max((nb+1)*n,nint(real(dummy(1,1))))
       ALLOCATE (work(lwork))

!      Read the matrix A from data file

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

!      Compute the eigenvalues and right eigenvectors of A

!      The NAG name equivalent of zgeev is f08nnf
       CALL zgeev('No left vectors','Vectors (right)',n,a,lda,w,dummy,1,vr, &
          ldvr,work,lwork,rwork,info)

       IF (info==0) THEN

!         Print solution

          WRITE (nout,*) 'Eigenvalues'
          WRITE (nout,99999) w(1:n)

          WRITE (nout,*)
          FLUSH (nout)

!         ifail: behaviour on error exit
!                =0 for hard exit, =1 for quiet-soft, =-1 for noisy-soft
          ifail = 0
          CALL x04daf('General',' ',n,n,vr,ldvr,'Eigenvectors',ifail)

       ELSE
          WRITE (nout,*)
          WRITE (nout,99998) 'Failure in ZGEEV.  INFO = ', info
       END IF

99999  FORMAT ((3X,4(' (',F7.4,',',F7.4,')':)))
99998  FORMAT (1X,A,I4)
    END PROGRAM f08nnfe
