001:       SUBROUTINE SSTEV( JOBZ, N, D, E, 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
009:       INTEGER            INFO, LDZ, N
010: *     ..
011: *     .. Array Arguments ..
012:       REAL               D( * ), E( * ), WORK( * ), Z( LDZ, * )
013: *     ..
014: *
015: *  Purpose
016: *  =======
017: *
018: *  SSTEV computes all eigenvalues and, optionally, eigenvectors of a
019: *  real symmetric tridiagonal matrix A.
020: *
021: *  Arguments
022: *  =========
023: *
024: *  JOBZ    (input) CHARACTER*1
025: *          = 'N':  Compute eigenvalues only;
026: *          = 'V':  Compute eigenvalues and eigenvectors.
027: *
028: *  N       (input) INTEGER
029: *          The order of the matrix.  N >= 0.
030: *
031: *  D       (input/output) REAL array, dimension (N)
032: *          On entry, the n diagonal elements of the tridiagonal matrix
033: *          A.
034: *          On exit, if INFO = 0, the eigenvalues in ascending order.
035: *
036: *  E       (input/output) REAL array, dimension (N-1)
037: *          On entry, the (n-1) subdiagonal elements of the tridiagonal
038: *          matrix A, stored in elements 1 to N-1 of E.
039: *          On exit, the contents of E are destroyed.
040: *
041: *  Z       (output) REAL array, dimension (LDZ, N)
042: *          If JOBZ = 'V', then if INFO = 0, Z contains the orthonormal
043: *          eigenvectors of the matrix A, with the i-th column of Z
044: *          holding the eigenvector associated with D(i).
045: *          If JOBZ = 'N', then Z is not referenced.
046: *
047: *  LDZ     (input) INTEGER
048: *          The leading dimension of the array Z.  LDZ >= 1, and if
049: *          JOBZ = 'V', LDZ >= max(1,N).
050: *
051: *  WORK    (workspace) REAL array, dimension (max(1,2*N-2))
052: *          If JOBZ = 'N', WORK is not referenced.
053: *
054: *  INFO    (output) INTEGER
055: *          = 0:  successful exit
056: *          < 0:  if INFO = -i, the i-th argument had an illegal value
057: *          > 0:  if INFO = i, the algorithm failed to converge; i
058: *                off-diagonal elements of E did not converge to zero.
059: *
060: *  =====================================================================
061: *
062: *     .. Parameters ..
063:       REAL               ZERO, ONE
064:       PARAMETER          ( ZERO = 0.0E0, ONE = 1.0E0 )
065: *     ..
066: *     .. Local Scalars ..
067:       LOGICAL            WANTZ
068:       INTEGER            IMAX, ISCALE
069:       REAL               BIGNUM, EPS, RMAX, RMIN, SAFMIN, SIGMA, SMLNUM,
070:      $                   TNRM
071: *     ..
072: *     .. External Functions ..
073:       LOGICAL            LSAME
074:       REAL               SLAMCH, SLANST
075:       EXTERNAL           LSAME, SLAMCH, SLANST
076: *     ..
077: *     .. External Subroutines ..
078:       EXTERNAL           SSCAL, SSTEQR, SSTERF, XERBLA
079: *     ..
080: *     .. Intrinsic Functions ..
081:       INTRINSIC          SQRT
082: *     ..
083: *     .. Executable Statements ..
084: *
085: *     Test the input parameters.
086: *
087:       WANTZ = LSAME( JOBZ, 'V' )
088: *
089:       INFO = 0
090:       IF( .NOT.( WANTZ .OR. LSAME( JOBZ, 'N' ) ) ) THEN
091:          INFO = -1
092:       ELSE IF( N.LT.0 ) THEN
093:          INFO = -2
094:       ELSE IF( LDZ.LT.1 .OR. ( WANTZ .AND. LDZ.LT.N ) ) THEN
095:          INFO = -6
096:       END IF
097: *
098:       IF( INFO.NE.0 ) THEN
099:          CALL XERBLA( 'SSTEV ', -INFO )
100:          RETURN
101:       END IF
102: *
103: *     Quick return if possible
104: *
105:       IF( N.EQ.0 )
106:      $   RETURN
107: *
108:       IF( N.EQ.1 ) THEN
109:          IF( WANTZ )
110:      $      Z( 1, 1 ) = ONE
111:          RETURN
112:       END IF
113: *
114: *     Get machine constants.
115: *
116:       SAFMIN = SLAMCH( 'Safe minimum' )
117:       EPS = SLAMCH( 'Precision' )
118:       SMLNUM = SAFMIN / EPS
119:       BIGNUM = ONE / SMLNUM
120:       RMIN = SQRT( SMLNUM )
121:       RMAX = SQRT( BIGNUM )
122: *
123: *     Scale matrix to allowable range, if necessary.
124: *
125:       ISCALE = 0
126:       TNRM = SLANST( 'M', N, D, E )
127:       IF( TNRM.GT.ZERO .AND. TNRM.LT.RMIN ) THEN
128:          ISCALE = 1
129:          SIGMA = RMIN / TNRM
130:       ELSE IF( TNRM.GT.RMAX ) THEN
131:          ISCALE = 1
132:          SIGMA = RMAX / TNRM
133:       END IF
134:       IF( ISCALE.EQ.1 ) THEN
135:          CALL SSCAL( N, SIGMA, D, 1 )
136:          CALL SSCAL( N-1, SIGMA, E( 1 ), 1 )
137:       END IF
138: *
139: *     For eigenvalues only, call SSTERF.  For eigenvalues and
140: *     eigenvectors, call SSTEQR.
141: *
142:       IF( .NOT.WANTZ ) THEN
143:          CALL SSTERF( N, D, E, INFO )
144:       ELSE
145:          CALL SSTEQR( 'I', N, D, E, Z, LDZ, WORK, INFO )
146:       END IF
147: *
148: *     If matrix was scaled, then rescale eigenvalues appropriately.
149: *
150:       IF( ISCALE.EQ.1 ) THEN
151:          IF( INFO.EQ.0 ) THEN
152:             IMAX = N
153:          ELSE
154:             IMAX = INFO - 1
155:          END IF
156:          CALL SSCAL( IMAX, ONE / SIGMA, D, 1 )
157:       END IF
158: *
159:       RETURN
160: *
161: *     End of SSTEV
162: *
163:       END
164: