    PROGRAM f02ecfe

!      F02ECF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

!      .. Use Statements ..
       USE nag_library, ONLY : f02ecf, nag_wp, x04dbf
!      .. Implicit None Statement ..
       IMPLICIT NONE
!      .. Parameters ..
       INTEGER, PARAMETER              :: nin = 5, nout = 6
!      .. Local Scalars ..
       REAL (KIND=nag_wp)              :: wl, wu
       INTEGER                         :: i, ifail, j, lda, ldv, ldvi, ldvr,   &
                                          lwork, m, mest, n
!      .. Local Arrays ..
       COMPLEX (KIND=nag_wp), ALLOCATABLE :: v(:,:)
       REAL (KIND=nag_wp), ALLOCATABLE :: a(:,:), vi(:,:), vr(:,:), wi(:),     &
                                          work(:), wr(:)
       INTEGER, ALLOCATABLE            :: iwork(:)
       LOGICAL, ALLOCATABLE            :: bwork(:)
       CHARACTER (1)                   :: clabs(1), rlabs(1)
!      .. Intrinsic Functions ..
       INTRINSIC                          cmplx
!      .. Executable Statements ..
       WRITE (nout,*) 'F02ECF Example Program Results'
!      Skip heading in data file
       READ (nin,*)
       READ (nin,*) n, mest, wl, wu
       lda = n
       ldv = n
       ldvi = n
       ldvr = n
       lwork = 64*n
       ALLOCATE (v(ldv,n),a(lda,n),vi(ldvi,mest),vr(ldvr,mest),wi(n), &
          work(lwork),wr(n),iwork(n),bwork(n))

!      Read A from data file

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

!      Compute selected eigenvalues and eigenvectors of A

!      ifail: behaviour on error exit
!             =0 for hard exit, =1 for quiet-soft, =-1 for noisy-soft
       ifail = 0
       CALL f02ecf('Moduli',n,a,lda,wl,wu,mest,m,wr,wi,vr,ldvr,vi,ldvi,work, &
          lwork,iwork,bwork,ifail)

       WRITE (nout,*)
       WRITE (nout,*) 'Eigenvalues'
       WRITE (nout,99999) (' (',wr(i),',',wi(i),')',i=1,m)
       WRITE (nout,*)
       FLUSH (nout)
       DO j = 1, m
          DO i = 1, n
             v(i,j) = cmplx(vr(i,j),vi(i,j),kind=nag_wp)
          END DO
       END DO

       ifail = 0
       CALL x04dbf('General',' ',n,m,v,ldv,'Bracketed','F7.4','Eigenvectors', &
          'Integer',rlabs,'Integer',clabs,80,0,ifail)

99999  FORMAT ((3X,4(A,F7.4,A,F7.4,A:)))
    END PROGRAM f02ecfe
