c    @(#)eigvec.f	1.1
c
      subroutine eigvec (nm,n,wr,wi,z,select,k,zr,zi,ierr)
      integer  nm,n,k,ierr
      real wr(n),wi(n),z(nm,1),zr(n),zi(n)
      logical select(n)
      ierr = 0
      if (select(k)) go to 10
      ierr = 33
      print 1002
 1002 format(' error in eigenvector selection')
      do 5 i = 1,n
      zr(i) = 0.
      zi(i) = 0.
    5 continue
      return
   10 continue
      sign = 1.
      kvec = 0
      do 30 i = 1,k
      if (.not. select(i)) go to 30
      if (wi(i) .eq. 0.) go to 20
      kvec = kvec + 2
      sign = 1.
      if (i .eq. 1) go to 30
      if (wi(i) .ne. (-wi(i-1)) .or. .not. select(i-1)) go to 30
      kvec = kvec - 2
      sign = -1.
      go to 30
   20 kvec = kvec + 1
   30 continue
      if (wi(k) .eq. 0.) go to 50
      do 40 i = 1,n
      zr(i) = z(i,kvec-1) 
      zi(i) = z(i,kvec)*sign
   40 continue
      return
   50 continue
      do 60 i = 1,n
      zr(i) = z(i,kvec)
      zi(i) = 0.
   60 continue
      return
      end
