001:       SUBROUTINE DSYEVR( JOBZ, RANGE, UPLO, N, A, LDA, VL, VU, IL, IU,
002:      $                   ABSTOL, M, W, Z, LDZ, ISUPPZ, WORK, LWORK,
003:      $                   IWORK, LIWORK, INFO )
004: *
005: *  -- LAPACK driver routine (version 3.2) --
006: *     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
007: *     November 2006
008: *
009: *     .. Scalar Arguments ..
010:       CHARACTER          JOBZ, RANGE, UPLO
011:       INTEGER            IL, INFO, IU, LDA, LDZ, LIWORK, LWORK, M, N
012:       DOUBLE PRECISION   ABSTOL, VL, VU
013: *     ..
014: *     .. Array Arguments ..
015:       INTEGER            ISUPPZ( * ), IWORK( * )
016:       DOUBLE PRECISION   A( LDA, * ), W( * ), WORK( * ), Z( LDZ, * )
017: *     ..
018: *
019: *  Purpose
020: *  =======
021: *
022: *  DSYEVR computes selected eigenvalues and, optionally, eigenvectors
023: *  of a real symmetric matrix A.  Eigenvalues and eigenvectors can be
024: *  selected by specifying either a range of values or a range of
025: *  indices for the desired eigenvalues.
026: *
027: *  DSYEVR first reduces the matrix A to tridiagonal form T with a call
028: *  to DSYTRD.  Then, whenever possible, DSYEVR calls DSTEMR to compute
029: *  the eigenspectrum using Relatively Robust Representations.  DSTEMR
030: *  computes eigenvalues by the dqds algorithm, while orthogonal
031: *  eigenvectors are computed from various "good" L D L^T representations
032: *  (also known as Relatively Robust Representations). Gram-Schmidt
033: *  orthogonalization is avoided as far as possible. More specifically,
034: *  the various steps of the algorithm are as follows.
035: *
036: *  For each unreduced block (submatrix) of T,
037: *     (a) Compute T - sigma I  = L D L^T, so that L and D
038: *         define all the wanted eigenvalues to high relative accuracy.
039: *         This means that small relative changes in the entries of D and L
040: *         cause only small relative changes in the eigenvalues and
041: *         eigenvectors. The standard (unfactored) representation of the
042: *         tridiagonal matrix T does not have this property in general.
043: *     (b) Compute the eigenvalues to suitable accuracy.
044: *         If the eigenvectors are desired, the algorithm attains full
045: *         accuracy of the computed eigenvalues only right before
046: *         the corresponding vectors have to be computed, see steps c) and d).
047: *     (c) For each cluster of close eigenvalues, select a new
048: *         shift close to the cluster, find a new factorization, and refine
049: *         the shifted eigenvalues to suitable accuracy.
050: *     (d) For each eigenvalue with a large enough relative separation compute
051: *         the corresponding eigenvector by forming a rank revealing twisted
052: *         factorization. Go back to (c) for any clusters that remain.
053: *
054: *  The desired accuracy of the output can be specified by the input
055: *  parameter ABSTOL.
056: *
057: *  For more details, see DSTEMR's documentation and:
058: *  - Inderjit S. Dhillon and Beresford N. Parlett: "Multiple representations
059: *    to compute orthogonal eigenvectors of symmetric tridiagonal matrices,"
060: *    Linear Algebra and its Applications, 387(1), pp. 1-28, August 2004.
061: *  - Inderjit Dhillon and Beresford Parlett: "Orthogonal Eigenvectors and
062: *    Relative Gaps," SIAM Journal on Matrix Analysis and Applications, Vol. 25,
063: *    2004.  Also LAPACK Working Note 154.
064: *  - Inderjit Dhillon: "A new O(n^2) algorithm for the symmetric
065: *    tridiagonal eigenvalue/eigenvector problem",
066: *    Computer Science Division Technical Report No. UCB/CSD-97-971,
067: *    UC Berkeley, May 1997.
068: *
069: *
070: *  Note 1 : DSYEVR calls DSTEMR when the full spectrum is requested
071: *  on machines which conform to the ieee-754 floating point standard.
072: *  DSYEVR calls DSTEBZ and SSTEIN on non-ieee machines and
073: *  when partial spectrum requests are made.
074: *
075: *  Normal execution of DSTEMR may create NaNs and infinities and
076: *  hence may abort due to a floating point exception in environments
077: *  which do not handle NaNs and infinities in the ieee standard default
078: *  manner.
079: *
080: *  Arguments
081: *  =========
082: *
083: *  JOBZ    (input) CHARACTER*1
084: *          = 'N':  Compute eigenvalues only;
085: *          = 'V':  Compute eigenvalues and eigenvectors.
086: *
087: *  RANGE   (input) CHARACTER*1
088: *          = 'A': all eigenvalues will be found.
089: *          = 'V': all eigenvalues in the half-open interval (VL,VU]
090: *                 will be found.
091: *          = 'I': the IL-th through IU-th eigenvalues will be found.
092: ********** For RANGE = 'V' or 'I' and IU - IL < N - 1, DSTEBZ and
093: ********** DSTEIN are called
094: *
095: *  UPLO    (input) CHARACTER*1
096: *          = 'U':  Upper triangle of A is stored;
097: *          = 'L':  Lower triangle of A is stored.
098: *
099: *  N       (input) INTEGER
100: *          The order of the matrix A.  N >= 0.
101: *
102: *  A       (input/output) DOUBLE PRECISION array, dimension (LDA, N)
103: *          On entry, the symmetric matrix A.  If UPLO = 'U', the
104: *          leading N-by-N upper triangular part of A contains the
105: *          upper triangular part of the matrix A.  If UPLO = 'L',
106: *          the leading N-by-N lower triangular part of A contains
107: *          the lower triangular part of the matrix A.
108: *          On exit, the lower triangle (if UPLO='L') or the upper
109: *          triangle (if UPLO='U') of A, including the diagonal, is
110: *          destroyed.
111: *
112: *  LDA     (input) INTEGER
113: *          The leading dimension of the array A.  LDA >= max(1,N).
114: *
115: *  VL      (input) DOUBLE PRECISION
116: *  VU      (input) DOUBLE PRECISION
117: *          If RANGE='V', the lower and upper bounds of the interval to
118: *          be searched for eigenvalues. VL < VU.
119: *          Not referenced if RANGE = 'A' or 'I'.
120: *
121: *  IL      (input) INTEGER
122: *  IU      (input) INTEGER
123: *          If RANGE='I', the indices (in ascending order) of the
124: *          smallest and largest eigenvalues to be returned.
125: *          1 <= IL <= IU <= N, if N > 0; IL = 1 and IU = 0 if N = 0.
126: *          Not referenced if RANGE = 'A' or 'V'.
127: *
128: *  ABSTOL  (input) DOUBLE PRECISION
129: *          The absolute error tolerance for the eigenvalues.
130: *          An approximate eigenvalue is accepted as converged
131: *          when it is determined to lie in an interval [a,b]
132: *          of width less than or equal to
133: *
134: *                  ABSTOL + EPS *   max( |a|,|b| ) ,
135: *
136: *          where EPS is the machine precision.  If ABSTOL is less than
137: *          or equal to zero, then  EPS*|T|  will be used in its place,
138: *          where |T| is the 1-norm of the tridiagonal matrix obtained
139: *          by reducing A to tridiagonal form.
140: *
141: *          See "Computing Small Singular Values of Bidiagonal Matrices
142: *          with Guaranteed High Relative Accuracy," by Demmel and
143: *          Kahan, LAPACK Working Note #3.
144: *
145: *          If high relative accuracy is important, set ABSTOL to
146: *          DLAMCH( 'Safe minimum' ).  Doing so will guarantee that
147: *          eigenvalues are computed to high relative accuracy when
148: *          possible in future releases.  The current code does not
149: *          make any guarantees about high relative accuracy, but
150: *          future releases will. See J. Barlow and J. Demmel,
151: *          "Computing Accurate Eigensystems of Scaled Diagonally
152: *          Dominant Matrices", LAPACK Working Note #7, for a discussion
153: *          of which matrices define their eigenvalues to high relative
154: *          accuracy.
155: *
156: *  M       (output) INTEGER
157: *          The total number of eigenvalues found.  0 <= M <= N.
158: *          If RANGE = 'A', M = N, and if RANGE = 'I', M = IU-IL+1.
159: *
160: *  W       (output) DOUBLE PRECISION array, dimension (N)
161: *          The first M elements contain the selected eigenvalues in
162: *          ascending order.
163: *
164: *  Z       (output) DOUBLE PRECISION array, dimension (LDZ, max(1,M))
165: *          If JOBZ = 'V', then if INFO = 0, the first M columns of Z
166: *          contain the orthonormal eigenvectors of the matrix A
167: *          corresponding to the selected eigenvalues, with the i-th
168: *          column of Z holding the eigenvector associated with W(i).
169: *          If JOBZ = 'N', then Z is not referenced.
170: *          Note: the user must ensure that at least max(1,M) columns are
171: *          supplied in the array Z; if RANGE = 'V', the exact value of M
172: *          is not known in advance and an upper bound must be used.
173: *          Supplying N columns is always safe.
174: *
175: *  LDZ     (input) INTEGER
176: *          The leading dimension of the array Z.  LDZ >= 1, and if
177: *          JOBZ = 'V', LDZ >= max(1,N).
178: *
179: *  ISUPPZ  (output) INTEGER array, dimension ( 2*max(1,M) )
180: *          The support of the eigenvectors in Z, i.e., the indices
181: *          indicating the nonzero elements in Z. The i-th eigenvector
182: *          is nonzero only in elements ISUPPZ( 2*i-1 ) through
183: *          ISUPPZ( 2*i ).
184: ********** Implemented only for RANGE = 'A' or 'I' and IU - IL = N - 1
185: *
186: *  WORK    (workspace/output) DOUBLE PRECISION array, dimension (MAX(1,LWORK))
187: *          On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
188: *
189: *  LWORK   (input) INTEGER
190: *          The dimension of the array WORK.  LWORK >= max(1,26*N).
191: *          For optimal efficiency, LWORK >= (NB+6)*N,
192: *          where NB is the max of the blocksize for DSYTRD and DORMTR
193: *          returned by ILAENV.
194: *
195: *          If LWORK = -1, then a workspace query is assumed; the routine
196: *          only calculates the optimal size of the WORK array, returns
197: *          this value as the first entry of the WORK array, and no error
198: *          message related to LWORK is issued by XERBLA.
199: *
200: *  IWORK   (workspace/output) INTEGER array, dimension (MAX(1,LIWORK))
201: *          On exit, if INFO = 0, IWORK(1) returns the optimal LWORK.
202: *
203: *  LIWORK  (input) INTEGER
204: *          The dimension of the array IWORK.  LIWORK >= max(1,10*N).
205: *
206: *          If LIWORK = -1, then a workspace query is assumed; the
207: *          routine only calculates the optimal size of the IWORK array,
208: *          returns this value as the first entry of the IWORK array, and
209: *          no error message related to LIWORK is issued by XERBLA.
210: *
211: *  INFO    (output) INTEGER
212: *          = 0:  successful exit
213: *          < 0:  if INFO = -i, the i-th argument had an illegal value
214: *          > 0:  Internal error
215: *
216: *  Further Details
217: *  ===============
218: *
219: *  Based on contributions by
220: *     Inderjit Dhillon, IBM Almaden, USA
221: *     Osni Marques, LBNL/NERSC, USA
222: *     Ken Stanley, Computer Science Division, University of
223: *       California at Berkeley, USA
224: *     Jason Riedy, Computer Science Division, University of
225: *       California at Berkeley, USA
226: *
227: * =====================================================================
228: *
229: *     .. Parameters ..
230:       DOUBLE PRECISION   ZERO, ONE, TWO
231:       PARAMETER          ( ZERO = 0.0D+0, ONE = 1.0D+0, TWO = 2.0D+0 )
232: *     ..
233: *     .. Local Scalars ..
234:       LOGICAL            ALLEIG, INDEIG, LOWER, LQUERY, VALEIG, WANTZ,
235:      $                   TRYRAC
236:       CHARACTER          ORDER
237:       INTEGER            I, IEEEOK, IINFO, IMAX, INDD, INDDD, INDE,
238:      $                   INDEE, INDIBL, INDIFL, INDISP, INDIWO, INDTAU,
239:      $                   INDWK, INDWKN, ISCALE, J, JJ, LIWMIN,
240:      $                   LLWORK, LLWRKN, LWKOPT, LWMIN, NB, NSPLIT
241:       DOUBLE PRECISION   ABSTLL, ANRM, BIGNUM, EPS, RMAX, RMIN, SAFMIN,
242:      $                   SIGMA, SMLNUM, TMP1, VLL, VUU
243: *     ..
244: *     .. External Functions ..
245:       LOGICAL            LSAME
246:       INTEGER            ILAENV
247:       DOUBLE PRECISION   DLAMCH, DLANSY
248:       EXTERNAL           LSAME, ILAENV, DLAMCH, DLANSY
249: *     ..
250: *     .. External Subroutines ..
251:       EXTERNAL           DCOPY, DORMTR, DSCAL, DSTEBZ, DSTEMR, DSTEIN,
252:      $                   DSTERF, DSWAP, DSYTRD, XERBLA
253: *     ..
254: *     .. Intrinsic Functions ..
255:       INTRINSIC          MAX, MIN, SQRT
256: *     ..
257: *     .. Executable Statements ..
258: *
259: *     Test the input parameters.
260: *
261:       IEEEOK = ILAENV( 10, 'DSYEVR', 'N', 1, 2, 3, 4 )
262: *
263:       LOWER = LSAME( UPLO, 'L' )
264:       WANTZ = LSAME( JOBZ, 'V' )
265:       ALLEIG = LSAME( RANGE, 'A' )
266:       VALEIG = LSAME( RANGE, 'V' )
267:       INDEIG = LSAME( RANGE, 'I' )
268: *
269:       LQUERY = ( ( LWORK.EQ.-1 ) .OR. ( LIWORK.EQ.-1 ) )
270: *
271:       LWMIN = MAX( 1, 26*N )
272:       LIWMIN = MAX( 1, 10*N )
273: *
274:       INFO = 0
275:       IF( .NOT.( WANTZ .OR. LSAME( JOBZ, 'N' ) ) ) THEN
276:          INFO = -1
277:       ELSE IF( .NOT.( ALLEIG .OR. VALEIG .OR. INDEIG ) ) THEN
278:          INFO = -2
279:       ELSE IF( .NOT.( LOWER .OR. LSAME( UPLO, 'U' ) ) ) THEN
280:          INFO = -3
281:       ELSE IF( N.LT.0 ) THEN
282:          INFO = -4
283:       ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
284:          INFO = -6
285:       ELSE
286:          IF( VALEIG ) THEN
287:             IF( N.GT.0 .AND. VU.LE.VL )
288:      $         INFO = -8
289:          ELSE IF( INDEIG ) THEN
290:             IF( IL.LT.1 .OR. IL.GT.MAX( 1, N ) ) THEN
291:                INFO = -9
292:             ELSE IF( IU.LT.MIN( N, IL ) .OR. IU.GT.N ) THEN
293:                INFO = -10
294:             END IF
295:          END IF
296:       END IF
297:       IF( INFO.EQ.0 ) THEN
298:          IF( LDZ.LT.1 .OR. ( WANTZ .AND. LDZ.LT.N ) ) THEN
299:             INFO = -15
300:          ELSE IF( LWORK.LT.LWMIN .AND. .NOT.LQUERY ) THEN
301:             INFO = -18
302:          ELSE IF( LIWORK.LT.LIWMIN .AND. .NOT.LQUERY ) THEN
303:             INFO = -20
304:          END IF
305:       END IF
306: *
307:       IF( INFO.EQ.0 ) THEN
308:          NB = ILAENV( 1, 'DSYTRD', UPLO, N, -1, -1, -1 )
309:          NB = MAX( NB, ILAENV( 1, 'DORMTR', UPLO, N, -1, -1, -1 ) )
310:          LWKOPT = MAX( ( NB+1 )*N, LWMIN )
311:          WORK( 1 ) = LWKOPT
312:          IWORK( 1 ) = LIWMIN
313:       END IF
314: *
315:       IF( INFO.NE.0 ) THEN
316:          CALL XERBLA( 'DSYEVR', -INFO )
317:          RETURN
318:       ELSE IF( LQUERY ) THEN
319:          RETURN
320:       END IF
321: *
322: *     Quick return if possible
323: *
324:       M = 0
325:       IF( N.EQ.0 ) THEN
326:          WORK( 1 ) = 1
327:          RETURN
328:       END IF
329: *
330:       IF( N.EQ.1 ) THEN
331:          WORK( 1 ) = 7
332:          IF( ALLEIG .OR. INDEIG ) THEN
333:             M = 1
334:             W( 1 ) = A( 1, 1 )
335:          ELSE
336:             IF( VL.LT.A( 1, 1 ) .AND. VU.GE.A( 1, 1 ) ) THEN
337:                M = 1
338:                W( 1 ) = A( 1, 1 )
339:             END IF
340:          END IF
341:          IF( WANTZ )
342:      $      Z( 1, 1 ) = ONE
343:          RETURN
344:       END IF
345: *
346: *     Get machine constants.
347: *
348:       SAFMIN = DLAMCH( 'Safe minimum' )
349:       EPS = DLAMCH( 'Precision' )
350:       SMLNUM = SAFMIN / EPS
351:       BIGNUM = ONE / SMLNUM
352:       RMIN = SQRT( SMLNUM )
353:       RMAX = MIN( SQRT( BIGNUM ), ONE / SQRT( SQRT( SAFMIN ) ) )
354: *
355: *     Scale matrix to allowable range, if necessary.
356: *
357:       ISCALE = 0
358:       ABSTLL = ABSTOL
359:       VLL = VL
360:       VUU = VU
361:       ANRM = DLANSY( 'M', UPLO, N, A, LDA, WORK )
362:       IF( ANRM.GT.ZERO .AND. ANRM.LT.RMIN ) THEN
363:          ISCALE = 1
364:          SIGMA = RMIN / ANRM
365:       ELSE IF( ANRM.GT.RMAX ) THEN
366:          ISCALE = 1
367:          SIGMA = RMAX / ANRM
368:       END IF
369:       IF( ISCALE.EQ.1 ) THEN
370:          IF( LOWER ) THEN
371:             DO 10 J = 1, N
372:                CALL DSCAL( N-J+1, SIGMA, A( J, J ), 1 )
373:    10       CONTINUE
374:          ELSE
375:             DO 20 J = 1, N
376:                CALL DSCAL( J, SIGMA, A( 1, J ), 1 )
377:    20       CONTINUE
378:          END IF
379:          IF( ABSTOL.GT.0 )
380:      $      ABSTLL = ABSTOL*SIGMA
381:          IF( VALEIG ) THEN
382:             VLL = VL*SIGMA
383:             VUU = VU*SIGMA
384:          END IF
385:       END IF
386: 
387: *     Initialize indices into workspaces.  Note: The IWORK indices are
388: *     used only if DSTERF or DSTEMR fail.
389: 
390: *     WORK(INDTAU:INDTAU+N-1) stores the scalar factors of the
391: *     elementary reflectors used in DSYTRD.
392:       INDTAU = 1
393: *     WORK(INDD:INDD+N-1) stores the tridiagonal's diagonal entries.
394:       INDD = INDTAU + N
395: *     WORK(INDE:INDE+N-1) stores the off-diagonal entries of the
396: *     tridiagonal matrix from DSYTRD.
397:       INDE = INDD + N
398: *     WORK(INDDD:INDDD+N-1) is a copy of the diagonal entries over
399: *     -written by DSTEMR (the DSTERF path copies the diagonal to W).
400:       INDDD = INDE + N
401: *     WORK(INDEE:INDEE+N-1) is a copy of the off-diagonal entries over
402: *     -written while computing the eigenvalues in DSTERF and DSTEMR.
403:       INDEE = INDDD + N
404: *     INDWK is the starting offset of the left-over workspace, and
405: *     LLWORK is the remaining workspace size.
406:       INDWK = INDEE + N
407:       LLWORK = LWORK - INDWK + 1
408: 
409: *     IWORK(INDIBL:INDIBL+M-1) corresponds to IBLOCK in DSTEBZ and
410: *     stores the block indices of each of the M<=N eigenvalues.
411:       INDIBL = 1
412: *     IWORK(INDISP:INDISP+NSPLIT-1) corresponds to ISPLIT in DSTEBZ and
413: *     stores the starting and finishing indices of each block.
414:       INDISP = INDIBL + N
415: *     IWORK(INDIFL:INDIFL+N-1) stores the indices of eigenvectors
416: *     that corresponding to eigenvectors that fail to converge in
417: *     DSTEIN.  This information is discarded; if any fail, the driver
418: *     returns INFO > 0.
419:       INDIFL = INDISP + N
420: *     INDIWO is the offset of the remaining integer workspace.
421:       INDIWO = INDISP + N
422: 
423: *
424: *     Call DSYTRD to reduce symmetric matrix to tridiagonal form.
425: *
426:       CALL DSYTRD( UPLO, N, A, LDA, WORK( INDD ), WORK( INDE ),
427:      $             WORK( INDTAU ), WORK( INDWK ), LLWORK, IINFO )
428: *
429: *     If all eigenvalues are desired
430: *     then call DSTERF or DSTEMR and DORMTR.
431: *
432:       IF( ( ALLEIG .OR. ( INDEIG .AND. IL.EQ.1 .AND. IU.EQ.N ) ) .AND.
433:      $    IEEEOK.EQ.1 ) THEN
434:          IF( .NOT.WANTZ ) THEN
435:             CALL DCOPY( N, WORK( INDD ), 1, W, 1 )
436:             CALL DCOPY( N-1, WORK( INDE ), 1, WORK( INDEE ), 1 )
437:             CALL DSTERF( N, W, WORK( INDEE ), INFO )
438:          ELSE
439:             CALL DCOPY( N-1, WORK( INDE ), 1, WORK( INDEE ), 1 )
440:             CALL DCOPY( N, WORK( INDD ), 1, WORK( INDDD ), 1 )
441: *
442:             IF (ABSTOL .LE. TWO*N*EPS) THEN
443:                TRYRAC = .TRUE.
444:             ELSE
445:                TRYRAC = .FALSE.
446:             END IF
447:             CALL DSTEMR( JOBZ, 'A', N, WORK( INDDD ), WORK( INDEE ),
448:      $                   VL, VU, IL, IU, M, W, Z, LDZ, N, ISUPPZ,
449:      $                   TRYRAC, WORK( INDWK ), LWORK, IWORK, LIWORK,
450:      $                   INFO )
451: *
452: *
453: *
454: *        Apply orthogonal matrix used in reduction to tridiagonal
455: *        form to eigenvectors returned by DSTEIN.
456: *
457:             IF( WANTZ .AND. INFO.EQ.0 ) THEN
458:                INDWKN = INDE
459:                LLWRKN = LWORK - INDWKN + 1
460:                CALL DORMTR( 'L', UPLO, 'N', N, M, A, LDA,
461:      $                      WORK( INDTAU ), Z, LDZ, WORK( INDWKN ),
462:      $                      LLWRKN, IINFO )
463:             END IF
464:          END IF
465: *
466: *
467:          IF( INFO.EQ.0 ) THEN
468: *           Everything worked.  Skip DSTEBZ/DSTEIN.  IWORK(:) are
469: *           undefined.
470:             M = N
471:             GO TO 30
472:          END IF
473:          INFO = 0
474:       END IF
475: *
476: *     Otherwise, call DSTEBZ and, if eigenvectors are desired, DSTEIN.
477: *     Also call DSTEBZ and DSTEIN if DSTEMR fails.
478: *
479:       IF( WANTZ ) THEN
480:          ORDER = 'B'
481:       ELSE
482:          ORDER = 'E'
483:       END IF
484: 
485:       CALL DSTEBZ( RANGE, ORDER, N, VLL, VUU, IL, IU, ABSTLL,
486:      $             WORK( INDD ), WORK( INDE ), M, NSPLIT, W,
487:      $             IWORK( INDIBL ), IWORK( INDISP ), WORK( INDWK ),
488:      $             IWORK( INDIWO ), INFO )
489: *
490:       IF( WANTZ ) THEN
491:          CALL DSTEIN( N, WORK( INDD ), WORK( INDE ), M, W,
492:      $                IWORK( INDIBL ), IWORK( INDISP ), Z, LDZ,
493:      $                WORK( INDWK ), IWORK( INDIWO ), IWORK( INDIFL ),
494:      $                INFO )
495: *
496: *        Apply orthogonal matrix used in reduction to tridiagonal
497: *        form to eigenvectors returned by DSTEIN.
498: *
499:          INDWKN = INDE
500:          LLWRKN = LWORK - INDWKN + 1
501:          CALL DORMTR( 'L', UPLO, 'N', N, M, A, LDA, WORK( INDTAU ), Z,
502:      $                LDZ, WORK( INDWKN ), LLWRKN, IINFO )
503:       END IF
504: *
505: *     If matrix was scaled, then rescale eigenvalues appropriately.
506: *
507: *  Jump here if DSTEMR/DSTEIN succeeded.
508:    30 CONTINUE
509:       IF( ISCALE.EQ.1 ) THEN
510:          IF( INFO.EQ.0 ) THEN
511:             IMAX = M
512:          ELSE
513:             IMAX = INFO - 1
514:          END IF
515:          CALL DSCAL( IMAX, ONE / SIGMA, W, 1 )
516:       END IF
517: *
518: *     If eigenvalues are not in order, then sort them, along with
519: *     eigenvectors.  Note: We do not sort the IFAIL portion of IWORK.
520: *     It may not be initialized (if DSTEMR/DSTEIN succeeded), and we do
521: *     not return this detailed information to the user.
522: *
523:       IF( WANTZ ) THEN
524:          DO 50 J = 1, M - 1
525:             I = 0
526:             TMP1 = W( J )
527:             DO 40 JJ = J + 1, M
528:                IF( W( JJ ).LT.TMP1 ) THEN
529:                   I = JJ
530:                   TMP1 = W( JJ )
531:                END IF
532:    40       CONTINUE
533: *
534:             IF( I.NE.0 ) THEN
535:                W( I ) = W( J )
536:                W( J ) = TMP1
537:                CALL DSWAP( N, Z( 1, I ), 1, Z( 1, J ), 1 )
538:             END IF
539:    50    CONTINUE
540:       END IF
541: *
542: *     Set WORK(1) to optimal workspace size.
543: *
544:       WORK( 1 ) = LWKOPT
545:       IWORK( 1 ) = LIWMIN
546: *
547:       RETURN
548: *
549: *     End of DSYEVR
550: *
551:       END
552: