001:       SUBROUTINE DSTEVD( JOBZ, N, D, E, Z, LDZ, WORK, LWORK, IWORK,
002:      $                   LIWORK, INFO )
003: *
004: *  -- LAPACK driver routine (version 3.2) --
005: *  -- LAPACK is a software package provided by Univ. of Tennessee,    --
006: *  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
007: *     November 2006
008: *
009: *     .. Scalar Arguments ..
010:       CHARACTER          JOBZ
011:       INTEGER            INFO, LDZ, LIWORK, LWORK, N
012: *     ..
013: *     .. Array Arguments ..
014:       INTEGER            IWORK( * )
015:       DOUBLE PRECISION   D( * ), E( * ), WORK( * ), Z( LDZ, * )
016: *     ..
017: *
018: *  Purpose
019: *  =======
020: *
021: *  DSTEVD computes all eigenvalues and, optionally, eigenvectors of a
022: *  real symmetric tridiagonal matrix. If eigenvectors are desired, it
023: *  uses a divide and conquer algorithm.
024: *
025: *  The divide and conquer algorithm makes very mild assumptions about
026: *  floating point arithmetic. It will work on machines with a guard
027: *  digit in add/subtract, or on those binary machines without guard
028: *  digits which subtract like the Cray X-MP, Cray Y-MP, Cray C-90, or
029: *  Cray-2. It could conceivably fail on hexadecimal or decimal machines
030: *  without guard digits, but we know of none.
031: *
032: *  Arguments
033: *  =========
034: *
035: *  JOBZ    (input) CHARACTER*1
036: *          = 'N':  Compute eigenvalues only;
037: *          = 'V':  Compute eigenvalues and eigenvectors.
038: *
039: *  N       (input) INTEGER
040: *          The order of the matrix.  N >= 0.
041: *
042: *  D       (input/output) DOUBLE PRECISION array, dimension (N)
043: *          On entry, the n diagonal elements of the tridiagonal matrix
044: *          A.
045: *          On exit, if INFO = 0, the eigenvalues in ascending order.
046: *
047: *  E       (input/output) DOUBLE PRECISION array, dimension (N-1)
048: *          On entry, the (n-1) subdiagonal elements of the tridiagonal
049: *          matrix A, stored in elements 1 to N-1 of E.
050: *          On exit, the contents of E are destroyed.
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 D(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/output) DOUBLE PRECISION array,
063: *                                         dimension (LWORK)
064: *          On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
065: *
066: *  LWORK   (input) INTEGER
067: *          The dimension of the array WORK.
068: *          If JOBZ  = 'N' or N <= 1 then LWORK must be at least 1.
069: *          If JOBZ  = 'V' and N > 1 then LWORK must be at least
070: *                         ( 1 + 4*N + N**2 ).
071: *
072: *          If LWORK = -1, then a workspace query is assumed; the routine
073: *          only calculates the optimal sizes of the WORK and IWORK
074: *          arrays, returns these values as the first entries of the WORK
075: *          and IWORK arrays, and no error message related to LWORK or
076: *          LIWORK is issued by XERBLA.
077: *
078: *  IWORK   (workspace/output) INTEGER array, dimension (MAX(1,LIWORK))
079: *          On exit, if INFO = 0, IWORK(1) returns the optimal LIWORK.
080: *
081: *  LIWORK  (input) INTEGER
082: *          The dimension of the array IWORK.
083: *          If JOBZ  = 'N' or N <= 1 then LIWORK must be at least 1.
084: *          If JOBZ  = 'V' and N > 1 then LIWORK must be at least 3+5*N.
085: *
086: *          If LIWORK = -1, then a workspace query is assumed; the
087: *          routine only calculates the optimal sizes of the WORK and
088: *          IWORK arrays, returns these values as the first entries of
089: *          the WORK and IWORK arrays, and no error message related to
090: *          LWORK or LIWORK is issued by XERBLA.
091: *
092: *  INFO    (output) INTEGER
093: *          = 0:  successful exit
094: *          < 0:  if INFO = -i, the i-th argument had an illegal value
095: *          > 0:  if INFO = i, the algorithm failed to converge; i
096: *                off-diagonal elements of E did not converge to zero.
097: *
098: *  =====================================================================
099: *
100: *     .. Parameters ..
101:       DOUBLE PRECISION   ZERO, ONE
102:       PARAMETER          ( ZERO = 0.0D0, ONE = 1.0D0 )
103: *     ..
104: *     .. Local Scalars ..
105:       LOGICAL            LQUERY, WANTZ
106:       INTEGER            ISCALE, LIWMIN, LWMIN
107:       DOUBLE PRECISION   BIGNUM, EPS, RMAX, RMIN, SAFMIN, SIGMA, SMLNUM,
108:      $                   TNRM
109: *     ..
110: *     .. External Functions ..
111:       LOGICAL            LSAME
112:       DOUBLE PRECISION   DLAMCH, DLANST
113:       EXTERNAL           LSAME, DLAMCH, DLANST
114: *     ..
115: *     .. External Subroutines ..
116:       EXTERNAL           DSCAL, DSTEDC, DSTERF, XERBLA
117: *     ..
118: *     .. Intrinsic Functions ..
119:       INTRINSIC          SQRT
120: *     ..
121: *     .. Executable Statements ..
122: *
123: *     Test the input parameters.
124: *
125:       WANTZ = LSAME( JOBZ, 'V' )
126:       LQUERY = ( LWORK.EQ.-1 .OR. LIWORK.EQ.-1 )
127: *
128:       INFO = 0
129:       LIWMIN = 1
130:       LWMIN = 1
131:       IF( N.GT.1 .AND. WANTZ ) THEN
132:          LWMIN = 1 + 4*N + N**2
133:          LIWMIN = 3 + 5*N
134:       END IF
135: *
136:       IF( .NOT.( WANTZ .OR. LSAME( JOBZ, 'N' ) ) ) THEN
137:          INFO = -1
138:       ELSE IF( N.LT.0 ) THEN
139:          INFO = -2
140:       ELSE IF( LDZ.LT.1 .OR. ( WANTZ .AND. LDZ.LT.N ) ) THEN
141:          INFO = -6
142:       END IF
143: *
144:       IF( INFO.EQ.0 ) THEN
145:          WORK( 1 ) = LWMIN
146:          IWORK( 1 ) = LIWMIN
147: *
148:          IF( LWORK.LT.LWMIN .AND. .NOT.LQUERY ) THEN
149:             INFO = -8
150:          ELSE IF( LIWORK.LT.LIWMIN .AND. .NOT.LQUERY ) THEN
151:             INFO = -10
152:          END IF
153:       END IF
154: *
155:       IF( INFO.NE.0 ) THEN
156:          CALL XERBLA( 'DSTEVD', -INFO )
157:          RETURN
158:       ELSE IF( LQUERY ) THEN
159:          RETURN
160:       END IF
161: *
162: *     Quick return if possible
163: *
164:       IF( N.EQ.0 )
165:      $   RETURN
166: *
167:       IF( N.EQ.1 ) THEN
168:          IF( WANTZ )
169:      $      Z( 1, 1 ) = ONE
170:          RETURN
171:       END IF
172: *
173: *     Get machine constants.
174: *
175:       SAFMIN = DLAMCH( 'Safe minimum' )
176:       EPS = DLAMCH( 'Precision' )
177:       SMLNUM = SAFMIN / EPS
178:       BIGNUM = ONE / SMLNUM
179:       RMIN = SQRT( SMLNUM )
180:       RMAX = SQRT( BIGNUM )
181: *
182: *     Scale matrix to allowable range, if necessary.
183: *
184:       ISCALE = 0
185:       TNRM = DLANST( 'M', N, D, E )
186:       IF( TNRM.GT.ZERO .AND. TNRM.LT.RMIN ) THEN
187:          ISCALE = 1
188:          SIGMA = RMIN / TNRM
189:       ELSE IF( TNRM.GT.RMAX ) THEN
190:          ISCALE = 1
191:          SIGMA = RMAX / TNRM
192:       END IF
193:       IF( ISCALE.EQ.1 ) THEN
194:          CALL DSCAL( N, SIGMA, D, 1 )
195:          CALL DSCAL( N-1, SIGMA, E( 1 ), 1 )
196:       END IF
197: *
198: *     For eigenvalues only, call DSTERF.  For eigenvalues and
199: *     eigenvectors, call DSTEDC.
200: *
201:       IF( .NOT.WANTZ ) THEN
202:          CALL DSTERF( N, D, E, INFO )
203:       ELSE
204:          CALL DSTEDC( 'I', N, D, E, Z, LDZ, WORK, LWORK, IWORK, LIWORK,
205:      $                INFO )
206:       END IF
207: *
208: *     If matrix was scaled, then rescale eigenvalues appropriately.
209: *
210:       IF( ISCALE.EQ.1 )
211:      $   CALL DSCAL( N, ONE / SIGMA, D, 1 )
212: *
213:       WORK( 1 ) = LWMIN
214:       IWORK( 1 ) = LIWMIN
215: *
216:       RETURN
217: *
218: *     End of DSTEVD
219: *
220:       END
221: