001:       SUBROUTINE DSPEV( JOBZ, UPLO, N, AP, W, Z, LDZ, WORK, INFO )
002: *
003: *  -- LAPACK driver routine (version 3.2) --
004: *     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
005: *     November 2006
006: *
007: *     .. Scalar Arguments ..
008:       CHARACTER          JOBZ, UPLO
009:       INTEGER            INFO, LDZ, N
010: *     ..
011: *     .. Array Arguments ..
012:       DOUBLE PRECISION   AP( * ), W( * ), WORK( * ), Z( LDZ, * )
013: *     ..
014: *
015: *  Purpose
016: *  =======
017: *
018: *  DSPEV computes all the eigenvalues and, optionally, eigenvectors of a
019: *  real symmetric matrix A in packed storage.
020: *
021: *  Arguments
022: *  =========
023: *
024: *  JOBZ    (input) CHARACTER*1
025: *          = 'N':  Compute eigenvalues only;
026: *          = 'V':  Compute eigenvalues and eigenvectors.
027: *
028: *  UPLO    (input) CHARACTER*1
029: *          = 'U':  Upper triangle of A is stored;
030: *          = 'L':  Lower triangle of A is stored.
031: *
032: *  N       (input) INTEGER
033: *          The order of the matrix A.  N >= 0.
034: *
035: *  AP      (input/output) DOUBLE PRECISION array, dimension (N*(N+1)/2)
036: *          On entry, the upper or lower triangle of the symmetric matrix
037: *          A, packed columnwise in a linear array.  The j-th column of A
038: *          is stored in the array AP as follows:
039: *          if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j;
040: *          if UPLO = 'L', AP(i + (j-1)*(2*n-j)/2) = A(i,j) for j<=i<=n.
041: *
042: *          On exit, AP is overwritten by values generated during the
043: *          reduction to tridiagonal form.  If UPLO = 'U', the diagonal
044: *          and first superdiagonal of the tridiagonal matrix T overwrite
045: *          the corresponding elements of A, and if UPLO = 'L', the
046: *          diagonal and first subdiagonal of T overwrite the
047: *          corresponding elements of A.
048: *
049: *  W       (output) DOUBLE PRECISION array, dimension (N)
050: *          If INFO = 0, the eigenvalues in ascending order.
051: *
052: *  Z       (output) DOUBLE PRECISION array, dimension (LDZ, N)
053: *          If JOBZ = 'V', then if INFO = 0, Z contains the orthonormal
054: *          eigenvectors of the matrix A, with the i-th column of Z
055: *          holding the eigenvector associated with W(i).
056: *          If JOBZ = 'N', then Z is not referenced.
057: *
058: *  LDZ     (input) INTEGER
059: *          The leading dimension of the array Z.  LDZ >= 1, and if
060: *          JOBZ = 'V', LDZ >= max(1,N).
061: *
062: *  WORK    (workspace) DOUBLE PRECISION array, dimension (3*N)
063: *
064: *  INFO    (output) INTEGER
065: *          = 0:  successful exit.
066: *          < 0:  if INFO = -i, the i-th argument had an illegal value.
067: *          > 0:  if INFO = i, the algorithm failed to converge; i
068: *                off-diagonal elements of an intermediate tridiagonal
069: *                form did not converge to zero.
070: *
071: *  =====================================================================
072: *
073: *     .. Parameters ..
074:       DOUBLE PRECISION   ZERO, ONE
075:       PARAMETER          ( ZERO = 0.0D0, ONE = 1.0D0 )
076: *     ..
077: *     .. Local Scalars ..
078:       LOGICAL            WANTZ
079:       INTEGER            IINFO, IMAX, INDE, INDTAU, INDWRK, ISCALE
080:       DOUBLE PRECISION   ANRM, BIGNUM, EPS, RMAX, RMIN, SAFMIN, SIGMA,
081:      $                   SMLNUM
082: *     ..
083: *     .. External Functions ..
084:       LOGICAL            LSAME
085:       DOUBLE PRECISION   DLAMCH, DLANSP
086:       EXTERNAL           LSAME, DLAMCH, DLANSP
087: *     ..
088: *     .. External Subroutines ..
089:       EXTERNAL           DOPGTR, DSCAL, DSPTRD, DSTEQR, DSTERF, XERBLA
090: *     ..
091: *     .. Intrinsic Functions ..
092:       INTRINSIC          SQRT
093: *     ..
094: *     .. Executable Statements ..
095: *
096: *     Test the input parameters.
097: *
098:       WANTZ = LSAME( JOBZ, 'V' )
099: *
100:       INFO = 0
101:       IF( .NOT.( WANTZ .OR. LSAME( JOBZ, 'N' ) ) ) THEN
102:          INFO = -1
103:       ELSE IF( .NOT.( LSAME( UPLO, 'U' ) .OR. LSAME( UPLO, 'L' ) ) )
104:      $          THEN
105:          INFO = -2
106:       ELSE IF( N.LT.0 ) THEN
107:          INFO = -3
108:       ELSE IF( LDZ.LT.1 .OR. ( WANTZ .AND. LDZ.LT.N ) ) THEN
109:          INFO = -7
110:       END IF
111: *
112:       IF( INFO.NE.0 ) THEN
113:          CALL XERBLA( 'DSPEV ', -INFO )
114:          RETURN
115:       END IF
116: *
117: *     Quick return if possible
118: *
119:       IF( N.EQ.0 )
120:      $   RETURN
121: *
122:       IF( N.EQ.1 ) THEN
123:          W( 1 ) = AP( 1 )
124:          IF( WANTZ )
125:      $      Z( 1, 1 ) = ONE
126:          RETURN
127:       END IF
128: *
129: *     Get machine constants.
130: *
131:       SAFMIN = DLAMCH( 'Safe minimum' )
132:       EPS = DLAMCH( 'Precision' )
133:       SMLNUM = SAFMIN / EPS
134:       BIGNUM = ONE / SMLNUM
135:       RMIN = SQRT( SMLNUM )
136:       RMAX = SQRT( BIGNUM )
137: *
138: *     Scale matrix to allowable range, if necessary.
139: *
140:       ANRM = DLANSP( 'M', UPLO, N, AP, WORK )
141:       ISCALE = 0
142:       IF( ANRM.GT.ZERO .AND. ANRM.LT.RMIN ) THEN
143:          ISCALE = 1
144:          SIGMA = RMIN / ANRM
145:       ELSE IF( ANRM.GT.RMAX ) THEN
146:          ISCALE = 1
147:          SIGMA = RMAX / ANRM
148:       END IF
149:       IF( ISCALE.EQ.1 ) THEN
150:          CALL DSCAL( ( N*( N+1 ) ) / 2, SIGMA, AP, 1 )
151:       END IF
152: *
153: *     Call DSPTRD to reduce symmetric packed matrix to tridiagonal form.
154: *
155:       INDE = 1
156:       INDTAU = INDE + N
157:       CALL DSPTRD( UPLO, N, AP, W, WORK( INDE ), WORK( INDTAU ), IINFO )
158: *
159: *     For eigenvalues only, call DSTERF.  For eigenvectors, first call
160: *     DOPGTR to generate the orthogonal matrix, then call DSTEQR.
161: *
162:       IF( .NOT.WANTZ ) THEN
163:          CALL DSTERF( N, W, WORK( INDE ), INFO )
164:       ELSE
165:          INDWRK = INDTAU + N
166:          CALL DOPGTR( UPLO, N, AP, WORK( INDTAU ), Z, LDZ,
167:      $                WORK( INDWRK ), IINFO )
168:          CALL DSTEQR( JOBZ, N, W, WORK( INDE ), Z, LDZ, WORK( INDTAU ),
169:      $                INFO )
170:       END IF
171: *
172: *     If matrix was scaled, then rescale eigenvalues appropriately.
173: *
174:       IF( ISCALE.EQ.1 ) THEN
175:          IF( INFO.EQ.0 ) THEN
176:             IMAX = N
177:          ELSE
178:             IMAX = INFO - 1
179:          END IF
180:          CALL DSCAL( IMAX, ONE / SIGMA, W, 1 )
181:       END IF
182: *
183:       RETURN
184: *
185: *     End of DSPEV
186: *
187:       END
188: