LAPACK  3.5.0
LAPACK: Linear Algebra PACKage
 All Classes Files Functions Variables Typedefs Macros
ssyevr.f
Go to the documentation of this file.
1 *> \brief <b> SSYEVR computes the eigenvalues and, optionally, the left and/or right eigenvectors for SY matrices</b>
2 *
3 * =========== DOCUMENTATION ===========
4 *
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
7 *
8 *> \htmlonly
9 *> Download SSYEVR + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/ssyevr.f">
11 *> [TGZ]</a>
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/ssyevr.f">
13 *> [ZIP]</a>
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/ssyevr.f">
15 *> [TXT]</a>
16 *> \endhtmlonly
17 *
18 * Definition:
19 * ===========
20 *
21 * SUBROUTINE SSYEVR( JOBZ, RANGE, UPLO, N, A, LDA, VL, VU, IL, IU,
22 * ABSTOL, M, W, Z, LDZ, ISUPPZ, WORK, LWORK,
23 * IWORK, LIWORK, INFO )
24 *
25 * .. Scalar Arguments ..
26 * CHARACTER JOBZ, RANGE, UPLO
27 * INTEGER IL, INFO, IU, LDA, LDZ, LIWORK, LWORK, M, N
28 * REAL ABSTOL, VL, VU
29 * ..
30 * .. Array Arguments ..
31 * INTEGER ISUPPZ( * ), IWORK( * )
32 * REAL A( LDA, * ), W( * ), WORK( * ), Z( LDZ, * )
33 * ..
34 *
35 *
36 *> \par Purpose:
37 * =============
38 *>
39 *> \verbatim
40 *>
41 *> SSYEVR computes selected eigenvalues and, optionally, eigenvectors
42 *> of a real symmetric matrix A. Eigenvalues and eigenvectors can be
43 *> selected by specifying either a range of values or a range of
44 *> indices for the desired eigenvalues.
45 *>
46 *> SSYEVR first reduces the matrix A to tridiagonal form T with a call
47 *> to SSYTRD. Then, whenever possible, SSYEVR calls SSTEMR to compute
48 *> the eigenspectrum using Relatively Robust Representations. SSTEMR
49 *> computes eigenvalues by the dqds algorithm, while orthogonal
50 *> eigenvectors are computed from various "good" L D L^T representations
51 *> (also known as Relatively Robust Representations). Gram-Schmidt
52 *> orthogonalization is avoided as far as possible. More specifically,
53 *> the various steps of the algorithm are as follows.
54 *>
55 *> For each unreduced block (submatrix) of T,
56 *> (a) Compute T - sigma I = L D L^T, so that L and D
57 *> define all the wanted eigenvalues to high relative accuracy.
58 *> This means that small relative changes in the entries of D and L
59 *> cause only small relative changes in the eigenvalues and
60 *> eigenvectors. The standard (unfactored) representation of the
61 *> tridiagonal matrix T does not have this property in general.
62 *> (b) Compute the eigenvalues to suitable accuracy.
63 *> If the eigenvectors are desired, the algorithm attains full
64 *> accuracy of the computed eigenvalues only right before
65 *> the corresponding vectors have to be computed, see steps c) and d).
66 *> (c) For each cluster of close eigenvalues, select a new
67 *> shift close to the cluster, find a new factorization, and refine
68 *> the shifted eigenvalues to suitable accuracy.
69 *> (d) For each eigenvalue with a large enough relative separation compute
70 *> the corresponding eigenvector by forming a rank revealing twisted
71 *> factorization. Go back to (c) for any clusters that remain.
72 *>
73 *> The desired accuracy of the output can be specified by the input
74 *> parameter ABSTOL.
75 *>
76 *> For more details, see SSTEMR's documentation and:
77 *> - Inderjit S. Dhillon and Beresford N. Parlett: "Multiple representations
78 *> to compute orthogonal eigenvectors of symmetric tridiagonal matrices,"
79 *> Linear Algebra and its Applications, 387(1), pp. 1-28, August 2004.
80 *> - Inderjit Dhillon and Beresford Parlett: "Orthogonal Eigenvectors and
81 *> Relative Gaps," SIAM Journal on Matrix Analysis and Applications, Vol. 25,
82 *> 2004. Also LAPACK Working Note 154.
83 *> - Inderjit Dhillon: "A new O(n^2) algorithm for the symmetric
84 *> tridiagonal eigenvalue/eigenvector problem",
85 *> Computer Science Division Technical Report No. UCB/CSD-97-971,
86 *> UC Berkeley, May 1997.
87 *>
88 *>
89 *> Note 1 : SSYEVR calls SSTEMR when the full spectrum is requested
90 *> on machines which conform to the ieee-754 floating point standard.
91 *> SSYEVR calls SSTEBZ and SSTEIN on non-ieee machines and
92 *> when partial spectrum requests are made.
93 *>
94 *> Normal execution of SSTEMR may create NaNs and infinities and
95 *> hence may abort due to a floating point exception in environments
96 *> which do not handle NaNs and infinities in the ieee standard default
97 *> manner.
98 *> \endverbatim
99 *
100 * Arguments:
101 * ==========
102 *
103 *> \param[in] JOBZ
104 *> \verbatim
105 *> JOBZ is CHARACTER*1
106 *> = 'N': Compute eigenvalues only;
107 *> = 'V': Compute eigenvalues and eigenvectors.
108 *> \endverbatim
109 *>
110 *> \param[in] RANGE
111 *> \verbatim
112 *> RANGE is CHARACTER*1
113 *> = 'A': all eigenvalues will be found.
114 *> = 'V': all eigenvalues in the half-open interval (VL,VU]
115 *> will be found.
116 *> = 'I': the IL-th through IU-th eigenvalues will be found.
117 *> For RANGE = 'V' or 'I' and IU - IL < N - 1, SSTEBZ and
118 *> SSTEIN are called
119 *> \endverbatim
120 *>
121 *> \param[in] UPLO
122 *> \verbatim
123 *> UPLO is CHARACTER*1
124 *> = 'U': Upper triangle of A is stored;
125 *> = 'L': Lower triangle of A is stored.
126 *> \endverbatim
127 *>
128 *> \param[in] N
129 *> \verbatim
130 *> N is INTEGER
131 *> The order of the matrix A. N >= 0.
132 *> \endverbatim
133 *>
134 *> \param[in,out] A
135 *> \verbatim
136 *> A is REAL array, dimension (LDA, N)
137 *> On entry, the symmetric matrix A. If UPLO = 'U', the
138 *> leading N-by-N upper triangular part of A contains the
139 *> upper triangular part of the matrix A. If UPLO = 'L',
140 *> the leading N-by-N lower triangular part of A contains
141 *> the lower triangular part of the matrix A.
142 *> On exit, the lower triangle (if UPLO='L') or the upper
143 *> triangle (if UPLO='U') of A, including the diagonal, is
144 *> destroyed.
145 *> \endverbatim
146 *>
147 *> \param[in] LDA
148 *> \verbatim
149 *> LDA is INTEGER
150 *> The leading dimension of the array A. LDA >= max(1,N).
151 *> \endverbatim
152 *>
153 *> \param[in] VL
154 *> \verbatim
155 *> VL is REAL
156 *> \endverbatim
157 *>
158 *> \param[in] VU
159 *> \verbatim
160 *> VU is REAL
161 *> If RANGE='V', the lower and upper bounds of the interval to
162 *> be searched for eigenvalues. VL < VU.
163 *> Not referenced if RANGE = 'A' or 'I'.
164 *> \endverbatim
165 *>
166 *> \param[in] IL
167 *> \verbatim
168 *> IL is INTEGER
169 *> \endverbatim
170 *>
171 *> \param[in] IU
172 *> \verbatim
173 *> IU is INTEGER
174 *> If RANGE='I', the indices (in ascending order) of the
175 *> smallest and largest eigenvalues to be returned.
176 *> 1 <= IL <= IU <= N, if N > 0; IL = 1 and IU = 0 if N = 0.
177 *> Not referenced if RANGE = 'A' or 'V'.
178 *> \endverbatim
179 *>
180 *> \param[in] ABSTOL
181 *> \verbatim
182 *> ABSTOL is REAL
183 *> The absolute error tolerance for the eigenvalues.
184 *> An approximate eigenvalue is accepted as converged
185 *> when it is determined to lie in an interval [a,b]
186 *> of width less than or equal to
187 *>
188 *> ABSTOL + EPS * max( |a|,|b| ) ,
189 *>
190 *> where EPS is the machine precision. If ABSTOL is less than
191 *> or equal to zero, then EPS*|T| will be used in its place,
192 *> where |T| is the 1-norm of the tridiagonal matrix obtained
193 *> by reducing A to tridiagonal form.
194 *>
195 *> See "Computing Small Singular Values of Bidiagonal Matrices
196 *> with Guaranteed High Relative Accuracy," by Demmel and
197 *> Kahan, LAPACK Working Note #3.
198 *>
199 *> If high relative accuracy is important, set ABSTOL to
200 *> SLAMCH( 'Safe minimum' ). Doing so will guarantee that
201 *> eigenvalues are computed to high relative accuracy when
202 *> possible in future releases. The current code does not
203 *> make any guarantees about high relative accuracy, but
204 *> future releases will. See J. Barlow and J. Demmel,
205 *> "Computing Accurate Eigensystems of Scaled Diagonally
206 *> Dominant Matrices", LAPACK Working Note #7, for a discussion
207 *> of which matrices define their eigenvalues to high relative
208 *> accuracy.
209 *> \endverbatim
210 *>
211 *> \param[out] M
212 *> \verbatim
213 *> M is INTEGER
214 *> The total number of eigenvalues found. 0 <= M <= N.
215 *> If RANGE = 'A', M = N, and if RANGE = 'I', M = IU-IL+1.
216 *> \endverbatim
217 *>
218 *> \param[out] W
219 *> \verbatim
220 *> W is REAL array, dimension (N)
221 *> The first M elements contain the selected eigenvalues in
222 *> ascending order.
223 *> \endverbatim
224 *>
225 *> \param[out] Z
226 *> \verbatim
227 *> Z is REAL array, dimension (LDZ, max(1,M))
228 *> If JOBZ = 'V', then if INFO = 0, the first M columns of Z
229 *> contain the orthonormal eigenvectors of the matrix A
230 *> corresponding to the selected eigenvalues, with the i-th
231 *> column of Z holding the eigenvector associated with W(i).
232 *> If JOBZ = 'N', then Z is not referenced.
233 *> Note: the user must ensure that at least max(1,M) columns are
234 *> supplied in the array Z; if RANGE = 'V', the exact value of M
235 *> is not known in advance and an upper bound must be used.
236 *> Supplying N columns is always safe.
237 *> \endverbatim
238 *>
239 *> \param[in] LDZ
240 *> \verbatim
241 *> LDZ is INTEGER
242 *> The leading dimension of the array Z. LDZ >= 1, and if
243 *> JOBZ = 'V', LDZ >= max(1,N).
244 *> \endverbatim
245 *>
246 *> \param[out] ISUPPZ
247 *> \verbatim
248 *> ISUPPZ is INTEGER array, dimension ( 2*max(1,M) )
249 *> The support of the eigenvectors in Z, i.e., the indices
250 *> indicating the nonzero elements in Z. The i-th eigenvector
251 *> is nonzero only in elements ISUPPZ( 2*i-1 ) through
252 *> ISUPPZ( 2*i ).
253 *> Implemented only for RANGE = 'A' or 'I' and IU - IL = N - 1
254 *> \endverbatim
255 *>
256 *> \param[out] WORK
257 *> \verbatim
258 *> WORK is REAL array, dimension (MAX(1,LWORK))
259 *> On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
260 *> \endverbatim
261 *>
262 *> \param[in] LWORK
263 *> \verbatim
264 *> LWORK is INTEGER
265 *> The dimension of the array WORK. LWORK >= max(1,26*N).
266 *> For optimal efficiency, LWORK >= (NB+6)*N,
267 *> where NB is the max of the blocksize for SSYTRD and SORMTR
268 *> returned by ILAENV.
269 *>
270 *> If LWORK = -1, then a workspace query is assumed; the routine
271 *> only calculates the optimal sizes of the WORK and IWORK
272 *> arrays, returns these values as the first entries of the WORK
273 *> and IWORK arrays, and no error message related to LWORK or
274 *> LIWORK is issued by XERBLA.
275 *> \endverbatim
276 *>
277 *> \param[out] IWORK
278 *> \verbatim
279 *> IWORK is INTEGER array, dimension (MAX(1,LIWORK))
280 *> On exit, if INFO = 0, IWORK(1) returns the optimal LWORK.
281 *> \endverbatim
282 *>
283 *> \param[in] LIWORK
284 *> \verbatim
285 *> LIWORK is INTEGER
286 *> The dimension of the array IWORK. LIWORK >= max(1,10*N).
287 *>
288 *> If LIWORK = -1, then a workspace query is assumed; the
289 *> routine only calculates the optimal sizes of the WORK and
290 *> IWORK arrays, returns these values as the first entries of
291 *> the WORK and IWORK arrays, and no error message related to
292 *> LWORK or LIWORK is issued by XERBLA.
293 *> \endverbatim
294 *>
295 *> \param[out] INFO
296 *> \verbatim
297 *> INFO is INTEGER
298 *> = 0: successful exit
299 *> < 0: if INFO = -i, the i-th argument had an illegal value
300 *> > 0: Internal error
301 *> \endverbatim
302 *
303 * Authors:
304 * ========
305 *
306 *> \author Univ. of Tennessee
307 *> \author Univ. of California Berkeley
308 *> \author Univ. of Colorado Denver
309 *> \author NAG Ltd.
310 *
311 *> \date September 2012
312 *
313 *> \ingroup realSYeigen
314 *
315 *> \par Contributors:
316 * ==================
317 *>
318 *> Inderjit Dhillon, IBM Almaden, USA \n
319 *> Osni Marques, LBNL/NERSC, USA \n
320 *> Ken Stanley, Computer Science Division, University of
321 *> California at Berkeley, USA \n
322 *> Jason Riedy, Computer Science Division, University of
323 *> California at Berkeley, USA \n
324 *>
325 * =====================================================================
326  SUBROUTINE ssyevr( JOBZ, RANGE, UPLO, N, A, LDA, VL, VU, IL, IU,
327  $ abstol, m, w, z, ldz, isuppz, work, lwork,
328  $ iwork, liwork, info )
329 *
330 * -- LAPACK driver routine (version 3.4.2) --
331 * -- LAPACK is a software package provided by Univ. of Tennessee, --
332 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
333 * September 2012
334 *
335 * .. Scalar Arguments ..
336  CHARACTER jobz, range, uplo
337  INTEGER il, info, iu, lda, ldz, liwork, lwork, m, n
338  REAL abstol, vl, vu
339 * ..
340 * .. Array Arguments ..
341  INTEGER isuppz( * ), iwork( * )
342  REAL a( lda, * ), w( * ), work( * ), z( ldz, * )
343 * ..
344 *
345 * =====================================================================
346 *
347 * .. Parameters ..
348  REAL zero, one, two
349  parameter( zero = 0.0e+0, one = 1.0e+0, two = 2.0e+0 )
350 * ..
351 * .. Local Scalars ..
352  LOGICAL alleig, indeig, lower, lquery, test, valeig,
353  $ wantz, tryrac
354  CHARACTER order
355  INTEGER i, ieeeok, iinfo, imax, indd, inddd, inde,
356  $ indee, indibl, indifl, indisp, indiwo, indtau,
357  $ indwk, indwkn, iscale, j, jj, liwmin,
358  $ llwork, llwrkn, lwkopt, lwmin, nb, nsplit
359  REAL abstll, anrm, bignum, eps, rmax, rmin, safmin,
360  $ sigma, smlnum, tmp1, vll, vuu
361 * ..
362 * .. External Functions ..
363  LOGICAL lsame
364  INTEGER ilaenv
365  REAL slamch, slansy
366  EXTERNAL lsame, ilaenv, slamch, slansy
367 * ..
368 * .. External Subroutines ..
369  EXTERNAL scopy, sormtr, sscal, sstebz, sstemr, sstein,
371 * ..
372 * .. Intrinsic Functions ..
373  INTRINSIC max, min, sqrt
374 * ..
375 * .. Executable Statements ..
376 *
377 * Test the input parameters.
378 *
379  ieeeok = ilaenv( 10, 'SSYEVR', 'N', 1, 2, 3, 4 )
380 *
381  lower = lsame( uplo, 'L' )
382  wantz = lsame( jobz, 'V' )
383  alleig = lsame( range, 'A' )
384  valeig = lsame( range, 'V' )
385  indeig = lsame( range, 'I' )
386 *
387  lquery = ( ( lwork.EQ.-1 ) .OR. ( liwork.EQ.-1 ) )
388 *
389  lwmin = max( 1, 26*n )
390  liwmin = max( 1, 10*n )
391 *
392  info = 0
393  IF( .NOT.( wantz .OR. lsame( jobz, 'N' ) ) ) THEN
394  info = -1
395  ELSE IF( .NOT.( alleig .OR. valeig .OR. indeig ) ) THEN
396  info = -2
397  ELSE IF( .NOT.( lower .OR. lsame( uplo, 'U' ) ) ) THEN
398  info = -3
399  ELSE IF( n.LT.0 ) THEN
400  info = -4
401  ELSE IF( lda.LT.max( 1, n ) ) THEN
402  info = -6
403  ELSE
404  IF( valeig ) THEN
405  IF( n.GT.0 .AND. vu.LE.vl )
406  $ info = -8
407  ELSE IF( indeig ) THEN
408  IF( il.LT.1 .OR. il.GT.max( 1, n ) ) THEN
409  info = -9
410  ELSE IF( iu.LT.min( n, il ) .OR. iu.GT.n ) THEN
411  info = -10
412  END IF
413  END IF
414  END IF
415  IF( info.EQ.0 ) THEN
416  IF( ldz.LT.1 .OR. ( wantz .AND. ldz.LT.n ) ) THEN
417  info = -15
418  END IF
419  END IF
420 *
421  IF( info.EQ.0 ) THEN
422  nb = ilaenv( 1, 'SSYTRD', uplo, n, -1, -1, -1 )
423  nb = max( nb, ilaenv( 1, 'SORMTR', uplo, n, -1, -1, -1 ) )
424  lwkopt = max( ( nb+1 )*n, lwmin )
425  work( 1 ) = lwkopt
426  iwork( 1 ) = liwmin
427 *
428  IF( lwork.LT.lwmin .AND. .NOT.lquery ) THEN
429  info = -18
430  ELSE IF( liwork.LT.liwmin .AND. .NOT.lquery ) THEN
431  info = -20
432  END IF
433  END IF
434 *
435  IF( info.NE.0 ) THEN
436  CALL xerbla( 'SSYEVR', -info )
437  RETURN
438  ELSE IF( lquery ) THEN
439  RETURN
440  END IF
441 *
442 * Quick return if possible
443 *
444  m = 0
445  IF( n.EQ.0 ) THEN
446  work( 1 ) = 1
447  RETURN
448  END IF
449 *
450  IF( n.EQ.1 ) THEN
451  work( 1 ) = 26
452  IF( alleig .OR. indeig ) THEN
453  m = 1
454  w( 1 ) = a( 1, 1 )
455  ELSE
456  IF( vl.LT.a( 1, 1 ) .AND. vu.GE.a( 1, 1 ) ) THEN
457  m = 1
458  w( 1 ) = a( 1, 1 )
459  END IF
460  END IF
461  IF( wantz ) THEN
462  z( 1, 1 ) = one
463  isuppz( 1 ) = 1
464  isuppz( 2 ) = 1
465  END IF
466  RETURN
467  END IF
468 *
469 * Get machine constants.
470 *
471  safmin = slamch( 'Safe minimum' )
472  eps = slamch( 'Precision' )
473  smlnum = safmin / eps
474  bignum = one / smlnum
475  rmin = sqrt( smlnum )
476  rmax = min( sqrt( bignum ), one / sqrt( sqrt( safmin ) ) )
477 *
478 * Scale matrix to allowable range, if necessary.
479 *
480  iscale = 0
481  abstll = abstol
482  IF (valeig) THEN
483  vll = vl
484  vuu = vu
485  END IF
486  anrm = slansy( 'M', uplo, n, a, lda, work )
487  IF( anrm.GT.zero .AND. anrm.LT.rmin ) THEN
488  iscale = 1
489  sigma = rmin / anrm
490  ELSE IF( anrm.GT.rmax ) THEN
491  iscale = 1
492  sigma = rmax / anrm
493  END IF
494  IF( iscale.EQ.1 ) THEN
495  IF( lower ) THEN
496  DO 10 j = 1, n
497  CALL sscal( n-j+1, sigma, a( j, j ), 1 )
498  10 CONTINUE
499  ELSE
500  DO 20 j = 1, n
501  CALL sscal( j, sigma, a( 1, j ), 1 )
502  20 CONTINUE
503  END IF
504  IF( abstol.GT.0 )
505  $ abstll = abstol*sigma
506  IF( valeig ) THEN
507  vll = vl*sigma
508  vuu = vu*sigma
509  END IF
510  END IF
511 
512 * Initialize indices into workspaces. Note: The IWORK indices are
513 * used only if SSTERF or SSTEMR fail.
514 
515 * WORK(INDTAU:INDTAU+N-1) stores the scalar factors of the
516 * elementary reflectors used in SSYTRD.
517  indtau = 1
518 * WORK(INDD:INDD+N-1) stores the tridiagonal's diagonal entries.
519  indd = indtau + n
520 * WORK(INDE:INDE+N-1) stores the off-diagonal entries of the
521 * tridiagonal matrix from SSYTRD.
522  inde = indd + n
523 * WORK(INDDD:INDDD+N-1) is a copy of the diagonal entries over
524 * -written by SSTEMR (the SSTERF path copies the diagonal to W).
525  inddd = inde + n
526 * WORK(INDEE:INDEE+N-1) is a copy of the off-diagonal entries over
527 * -written while computing the eigenvalues in SSTERF and SSTEMR.
528  indee = inddd + n
529 * INDWK is the starting offset of the left-over workspace, and
530 * LLWORK is the remaining workspace size.
531  indwk = indee + n
532  llwork = lwork - indwk + 1
533 
534 * IWORK(INDIBL:INDIBL+M-1) corresponds to IBLOCK in SSTEBZ and
535 * stores the block indices of each of the M<=N eigenvalues.
536  indibl = 1
537 * IWORK(INDISP:INDISP+NSPLIT-1) corresponds to ISPLIT in SSTEBZ and
538 * stores the starting and finishing indices of each block.
539  indisp = indibl + n
540 * IWORK(INDIFL:INDIFL+N-1) stores the indices of eigenvectors
541 * that corresponding to eigenvectors that fail to converge in
542 * SSTEIN. This information is discarded; if any fail, the driver
543 * returns INFO > 0.
544  indifl = indisp + n
545 * INDIWO is the offset of the remaining integer workspace.
546  indiwo = indifl + n
547 
548 *
549 * Call SSYTRD to reduce symmetric matrix to tridiagonal form.
550 *
551  CALL ssytrd( uplo, n, a, lda, work( indd ), work( inde ),
552  $ work( indtau ), work( indwk ), llwork, iinfo )
553 *
554 * If all eigenvalues are desired
555 * then call SSTERF or SSTEMR and SORMTR.
556 *
557  test = .false.
558  IF( indeig ) THEN
559  IF( il.EQ.1 .AND. iu.EQ.n ) THEN
560  test = .true.
561  END IF
562  END IF
563  IF( ( alleig.OR.test ) .AND. ( ieeeok.EQ.1 ) ) THEN
564  IF( .NOT.wantz ) THEN
565  CALL scopy( n, work( indd ), 1, w, 1 )
566  CALL scopy( n-1, work( inde ), 1, work( indee ), 1 )
567  CALL ssterf( n, w, work( indee ), info )
568  ELSE
569  CALL scopy( n-1, work( inde ), 1, work( indee ), 1 )
570  CALL scopy( n, work( indd ), 1, work( inddd ), 1 )
571 *
572  IF (abstol .LE. two*n*eps) THEN
573  tryrac = .true.
574  ELSE
575  tryrac = .false.
576  END IF
577  CALL sstemr( jobz, 'A', n, work( inddd ), work( indee ),
578  $ vl, vu, il, iu, m, w, z, ldz, n, isuppz,
579  $ tryrac, work( indwk ), lwork, iwork, liwork,
580  $ info )
581 *
582 *
583 *
584 * Apply orthogonal matrix used in reduction to tridiagonal
585 * form to eigenvectors returned by SSTEIN.
586 *
587  IF( wantz .AND. info.EQ.0 ) THEN
588  indwkn = inde
589  llwrkn = lwork - indwkn + 1
590  CALL sormtr( 'L', uplo, 'N', n, m, a, lda,
591  $ work( indtau ), z, ldz, work( indwkn ),
592  $ llwrkn, iinfo )
593  END IF
594  END IF
595 *
596 *
597  IF( info.EQ.0 ) THEN
598 * Everything worked. Skip SSTEBZ/SSTEIN. IWORK(:) are
599 * undefined.
600  m = n
601  go to 30
602  END IF
603  info = 0
604  END IF
605 *
606 * Otherwise, call SSTEBZ and, if eigenvectors are desired, SSTEIN.
607 * Also call SSTEBZ and SSTEIN if SSTEMR fails.
608 *
609  IF( wantz ) THEN
610  order = 'B'
611  ELSE
612  order = 'E'
613  END IF
614 
615  CALL sstebz( range, order, n, vll, vuu, il, iu, abstll,
616  $ work( indd ), work( inde ), m, nsplit, w,
617  $ iwork( indibl ), iwork( indisp ), work( indwk ),
618  $ iwork( indiwo ), info )
619 *
620  IF( wantz ) THEN
621  CALL sstein( n, work( indd ), work( inde ), m, w,
622  $ iwork( indibl ), iwork( indisp ), z, ldz,
623  $ work( indwk ), iwork( indiwo ), iwork( indifl ),
624  $ info )
625 *
626 * Apply orthogonal matrix used in reduction to tridiagonal
627 * form to eigenvectors returned by SSTEIN.
628 *
629  indwkn = inde
630  llwrkn = lwork - indwkn + 1
631  CALL sormtr( 'L', uplo, 'N', n, m, a, lda, work( indtau ), z,
632  $ ldz, work( indwkn ), llwrkn, iinfo )
633  END IF
634 *
635 * If matrix was scaled, then rescale eigenvalues appropriately.
636 *
637 * Jump here if SSTEMR/SSTEIN succeeded.
638  30 CONTINUE
639  IF( iscale.EQ.1 ) THEN
640  IF( info.EQ.0 ) THEN
641  imax = m
642  ELSE
643  imax = info - 1
644  END IF
645  CALL sscal( imax, one / sigma, w, 1 )
646  END IF
647 *
648 * If eigenvalues are not in order, then sort them, along with
649 * eigenvectors. Note: We do not sort the IFAIL portion of IWORK.
650 * It may not be initialized (if SSTEMR/SSTEIN succeeded), and we do
651 * not return this detailed information to the user.
652 *
653  IF( wantz ) THEN
654  DO 50 j = 1, m - 1
655  i = 0
656  tmp1 = w( j )
657  DO 40 jj = j + 1, m
658  IF( w( jj ).LT.tmp1 ) THEN
659  i = jj
660  tmp1 = w( jj )
661  END IF
662  40 CONTINUE
663 *
664  IF( i.NE.0 ) THEN
665  w( i ) = w( j )
666  w( j ) = tmp1
667  CALL sswap( n, z( 1, i ), 1, z( 1, j ), 1 )
668  END IF
669  50 CONTINUE
670  END IF
671 *
672 * Set WORK(1) to optimal workspace size.
673 *
674  work( 1 ) = lwkopt
675  iwork( 1 ) = liwmin
676 *
677  RETURN
678 *
679 * End of SSYEVR
680 *
681  END