      SUBROUTINE DEIGEN(NM,N,A,WR,WI,Z)
      DOUBLE PRECISION A(NM,N),WR(N),WI(N),Z(NM,N)
C
      COMMON/CSTAK/D
      DOUBLE PRECISION D(500)
C
C DEIGEN FINDS THE EIGENVALUES AND EIGENVECTORS
C OF A DOUBLE-PRECISION MATRIX (NOT IMAGINARY) BY
C CALLING THE SEQUENCE OF SUBROUTINES
C DORTHE,DORTRA, AND DHQR2, WHICH, IN TURN, ARE
C THE EISPACK ROUTINES ORTHES, ORTRAN, AND HQR2,
C ADJUSTED FOR DOUBLE PRECISION.
C
C ON INPUT -
C
C   NM - AN INTEGER INPUT VARIABLE SET EQUAL TO
C        THE ROW DIMENSION OF THE TWO-DIMENSIONAL ARRAYS
C        A AND Z AS SPECIFIED IN THE DIMENSION STATEMENTS
C        FOR A AND Z IN THE CALLING PROGRAM.
C
C   N -  AN INTEGER INPUT VARIABLE SET EQUAL TO THE
C        ORDER OF THE MATRIX A.
C
C     N MUST NOT BE GREATER THAN NM.
C
C   A - THE MATRIX, A DOUBLE-PRECISION TWO-DIMENSIONAL
C       ARRAY WITH ROW DIMENSION NM AND COLUMN
C       DIMENSION AT LEAST N.
C
C     A IS OVERWRITTEN.
C
C
C
C ON OUTPUT -
C
C   WR - A DOUBLE-PRECISION ARRAY OF DIMENSION
C        AT LEAST N CONTAINING THE REAL PARTS OF THE EIGENVALUES
C
C   WI - A DOUBLE-PRECISION ARRAY OF DIMENSION
C        AT LEAST N CONTAINING THE IMAGINARY PARTS OF THE EIGENVALUES.
C
C     THE EIGENVALUES ARE UNORDERED EXCEPT THAT
C     COMPLEX CONJUGATE PAIRS OF EIGENVALUES
C     APPEAR CONSECUTIVELY WITH THE EIGENVALUE HAVING
C     THE POSITIVE IMAGINARY PART FIRST.
C
C   Z - A DOUBLE-PRECISION TWO-DIMENSIONAL ARRAY
C       WITH ROW DIMENSION NM AND COLUMN DIMENSION
C       AT LEAST N CONTAINING THE REAL AND IMAGINARY PARTS
C       OF THE EIGENVECTORS.
C
C       IF THE J-TH EIGENVALUE IS REAL, THE J-TH
C       COLUMN OF Z CONTAINS ITS EIGENVECTOR.
C
C       IF THE J-TH EIGENVALUE IS COMPLEX WITH
C       POSITIVE REAL PART, THE J-TH AND (J+1)-TH
C       COLUMNS OF Z CONTAIN THE REAL AND IMAGINARY
C       PARTS OF ITS EIGENVECTOR.
C
C       THE CONJUGATE OF THIS VECTOR IS THE
C       EIGENVECTOR FOR THE CONJUGATE EIGENVALUE.
C       THE EIGENVECTORS ARE NOT NORMALIZED.
C
C
C ERROR STATES -
C
C          1 - N IS GREATER THAN NM
C
C          K - THE K-TH EIGENVALUE COULD NOT BE COMPUTED
C              WITHIN 30 ITERATIONS.
C
C              THE EIGENVALUES IN THE WR AND WRI ARRAYS
C              SHOULD BE CORRECT FOR INDICES
C              K+1, K+2,...,N, BUT NO EIGENVECTORS ARE COMPUTED.
C
C
C
C
C CHECK FOR INPUT ERROR IN N
C
C/6S
C     IF (N .GT. NM) CALL SETERR(
C    1   29HDEIGEN - N IS GREATER THAN NM,29,1,2)
C/7S
      IF (N .GT. NM) CALL SETERR(
     1   'DEIGEN - N IS GREATER THAN NM',29,1,2)
C/
C
C ALLOCATE A SCRATCH VECTOR
      IORT = ISTKGT(N,4)
C
      CALL DORTHE (NM,N,1,N,A,D(IORT))
      CALL DORTRA (NM,N,1,N,A,D(IORT),Z)
      CALL DHQR2 (NM,N,1,N,A,WR,WI,Z,IERR)
C
      IF (IERR .NE. 0) GO TO 10
      CALL ISTKRL(1)
      RETURN
C/6S
C 10  CALL SETERR(
C    1   34HDEIGEN - FAILED ON THAT EIGENVALUE,34,IERR,1)
C/7S
  10  CALL SETERR(
     1   'DEIGEN - FAILED ON THAT EIGENVALUE',34,IERR,1)
C/
C
      CALL ISTKRL(1)
      RETURN
      END
