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