      SUBROUTINE RSP(A,N,MATZ,W,Z)
      implicit double precision (A-H,O-Z)
      include 'SIZES'
      include 'MOP6FILE'
      dimension A(*),  W(N), Z(N,N)
*******************************************************************
*
*   EISPACK DIAGONALIZATION ROUTINES: TO FIND THE EIGENVALUES AND
*           EIGENVECTORS (IF DESIRED) OF A REAL SYMMETRIC PACKED MATRIX.
* ON INPUT-      N  IS THE ORDER OF THE MATRIX  A,
*                A  CONTAINS THE LOWER TRIANGLE OF THE REAL SYMMETRIC
*                   PACKED MATRIX STORED ROW-WISE,
*             MATZ  IS AN INTEGER VARIABLE SET EQUAL TO ZERO IF ONLY
*                   EIGENVALUES ARE DESIRED,  OTHERWISE IT IS SET TO
*                   ANY NON-ZERO INTEGER FOR BOTH EIGENVALUES AND
*                   EIGENVECTORS.
* ON OUTPUT-     W  CONTAINS THE EIGENVALUES IN ASCENDING ORDER,
*                Z  CONTAINS THE EIGENVECTORS IF MATZ IS NOT ZERO,
*
*******************************************************************
* THIS SUBROUTINE WAS CHOSEN AS BEING THE MOST RELIABLE. (JJPS)
C     QUESTIONS AND COMMENTS SHOULD BE DIRECTED TO B. S. GARBOW,
C     APPLIED MATHEMATICS DIVISION, ARGONNE NATIONAL LABORATORY
C
C     ------------------------------------------------------------------
C
      dimension FV1(MAXHEV*4+MAXLIT*3),FV2(MAXHEV*4+MAXLIT*3)
      logical FIRST
      save FIRST, EPS, ETA, NV
      data FIRST /.TRUE./
      if (FIRST) then
         FIRST=.FALSE.
         call EPSETA(EPS,ETA)
      end if
      NV=(N*(N+1))/2
      NM=N
      call  TRED3(N,NV,A,W,FV1,FV2,EPS,EPS)
      if (MATZ .NE. 0) go to 10
C     ********** FIND EIGENVALUES ONLY **********
      call  TQLRAT(N,W,FV2,IERR,EPS)
      go to 40
C     ********** FIND BOTH EIGENVALUES AND EIGENVECTORS **********
   10 do 30    I = 1, N
C
         do 20    J = 1, N
            Z(J,I)=0.0D0
   20    continue
C
         Z(I,I)=1.0D0
   30 continue
C
      call  TQL2(NM,N,W,FV1,Z,IERR,EPS)
      if (IERR .NE. 0) go to 40
      call  TRBAK3(NM,N,NV,A,N,Z,EPS)
C     ********** LAST CARD OF RSP **********
   40 return
      end
