Update to 2.0.0 tree from current Fremantle build
[opencv] / 3rdparty / lapack / dstemr.c
1 #include "clapack.h"
2
3 /* Table of constant values */
4
5 static integer c__1 = 1;
6 static doublereal c_b18 = .001;
7
8 /* Subroutine */ int dstemr_(char *jobz, char *range, integer *n, doublereal *
9         d__, doublereal *e, doublereal *vl, doublereal *vu, integer *il, 
10         integer *iu, integer *m, doublereal *w, doublereal *z__, integer *ldz, 
11          integer *nzc, integer *isuppz, logical *tryrac, doublereal *work, 
12         integer *lwork, integer *iwork, integer *liwork, integer *info)
13 {
14     /* System generated locals */
15     integer z_dim1, z_offset, i__1, i__2;
16     doublereal d__1, d__2;
17
18     /* Builtin functions */
19     double sqrt(doublereal);
20
21     /* Local variables */
22     integer i__, j;
23     doublereal r1, r2;
24     integer jj;
25     doublereal cs;
26     integer in;
27     doublereal sn, wl, wu;
28     integer iil, iiu;
29     doublereal eps, tmp;
30     integer indd, iend, jblk, wend;
31     doublereal rmin, rmax;
32     integer itmp;
33     doublereal tnrm;
34     extern /* Subroutine */ int dlae2_(doublereal *, doublereal *, doublereal 
35             *, doublereal *, doublereal *);
36     integer inde2, itmp2;
37     doublereal rtol1, rtol2;
38     extern /* Subroutine */ int dscal_(integer *, doublereal *, doublereal *, 
39             integer *);
40     doublereal scale;
41     integer indgp;
42     extern logical lsame_(char *, char *);
43     integer iinfo, iindw, ilast;
44     extern /* Subroutine */ int dcopy_(integer *, doublereal *, integer *, 
45             doublereal *, integer *), dswap_(integer *, doublereal *, integer 
46             *, doublereal *, integer *);
47     integer lwmin;
48     logical wantz;
49     extern /* Subroutine */ int dlaev2_(doublereal *, doublereal *, 
50             doublereal *, doublereal *, doublereal *, doublereal *, 
51             doublereal *);
52     extern doublereal dlamch_(char *);
53     logical alleig;
54     integer ibegin;
55     logical indeig;
56     integer iindbl;
57     logical valeig;
58     extern /* Subroutine */ int dlarrc_(char *, integer *, doublereal *, 
59             doublereal *, doublereal *, doublereal *, doublereal *, integer *, 
60              integer *, integer *, integer *), dlarre_(char *, 
61             integer *, doublereal *, doublereal *, integer *, integer *, 
62             doublereal *, doublereal *, doublereal *, doublereal *, 
63             doublereal *, doublereal *, integer *, integer *, integer *, 
64             doublereal *, doublereal *, doublereal *, integer *, integer *, 
65             doublereal *, doublereal *, doublereal *, integer *, integer *);
66     integer wbegin;
67     doublereal safmin;
68     extern /* Subroutine */ int dlarrj_(integer *, doublereal *, doublereal *, 
69              integer *, integer *, doublereal *, integer *, doublereal *, 
70             doublereal *, doublereal *, integer *, doublereal *, doublereal *, 
71              integer *), xerbla_(char *, integer *);
72     doublereal bignum;
73     integer inderr, iindwk, indgrs, offset;
74     extern doublereal dlanst_(char *, integer *, doublereal *, doublereal *);
75     extern /* Subroutine */ int dlarrr_(integer *, doublereal *, doublereal *, 
76              integer *), dlarrv_(integer *, doublereal *, doublereal *, 
77             doublereal *, doublereal *, doublereal *, integer *, integer *, 
78             integer *, integer *, doublereal *, doublereal *, doublereal *, 
79             doublereal *, doublereal *, doublereal *, integer *, integer *, 
80             doublereal *, doublereal *, integer *, integer *, doublereal *, 
81             integer *, integer *), dlasrt_(char *, integer *, doublereal *, 
82             integer *);
83     doublereal thresh;
84     integer iinspl, ifirst, indwrk, liwmin, nzcmin;
85     doublereal pivmin;
86     integer nsplit;
87     doublereal smlnum;
88     logical lquery, zquery;
89
90
91 /*  -- LAPACK computational routine (version 3.1) -- */
92 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
93 /*     November 2006 */
94
95 /*     .. Scalar Arguments .. */
96 /*     .. */
97 /*     .. Array Arguments .. */
98 /*     .. */
99
100 /*  Purpose */
101 /*  ======= */
102
103 /*  DSTEMR computes selected eigenvalues and, optionally, eigenvectors */
104 /*  of a real symmetric tridiagonal matrix T. Any such unreduced matrix has */
105 /*  a well defined set of pairwise different real eigenvalues, the corresponding */
106 /*  real eigenvectors are pairwise orthogonal. */
107
108 /*  The spectrum may be computed either completely or partially by specifying */
109 /*  either an interval (VL,VU] or a range of indices IL:IU for the desired */
110 /*  eigenvalues. */
111
112 /*  Depending on the number of desired eigenvalues, these are computed either */
113 /*  by bisection or the dqds algorithm. Numerically orthogonal eigenvectors are */
114 /*  computed by the use of various suitable L D L^T factorizations near clusters */
115 /*  of close eigenvalues (referred to as RRRs, Relatively Robust */
116 /*  Representations). An informal sketch of the algorithm follows. */
117
118 /*  For each unreduced block (submatrix) of T, */
119 /*     (a) Compute T - sigma I  = L D L^T, so that L and D */
120 /*         define all the wanted eigenvalues to high relative accuracy. */
121 /*         This means that small relative changes in the entries of D and L */
122 /*         cause only small relative changes in the eigenvalues and */
123 /*         eigenvectors. The standard (unfactored) representation of the */
124 /*         tridiagonal matrix T does not have this property in general. */
125 /*     (b) Compute the eigenvalues to suitable accuracy. */
126 /*         If the eigenvectors are desired, the algorithm attains full */
127 /*         accuracy of the computed eigenvalues only right before */
128 /*         the corresponding vectors have to be computed, see steps c) and d). */
129 /*     (c) For each cluster of close eigenvalues, select a new */
130 /*         shift close to the cluster, find a new factorization, and refine */
131 /*         the shifted eigenvalues to suitable accuracy. */
132 /*     (d) For each eigenvalue with a large enough relative separation compute */
133 /*         the corresponding eigenvector by forming a rank revealing twisted */
134 /*         factorization. Go back to (c) for any clusters that remain. */
135
136 /*  For more details, see: */
137 /*  - Inderjit S. Dhillon and Beresford N. Parlett: "Multiple representations */
138 /*    to compute orthogonal eigenvectors of symmetric tridiagonal matrices," */
139 /*    Linear Algebra and its Applications, 387(1), pp. 1-28, August 2004. */
140 /*  - Inderjit Dhillon and Beresford Parlett: "Orthogonal Eigenvectors and */
141 /*    Relative Gaps," SIAM Journal on Matrix Analysis and Applications, Vol. 25, */
142 /*    2004.  Also LAPACK Working Note 154. */
143 /*  - Inderjit Dhillon: "A new O(n^2) algorithm for the symmetric */
144 /*    tridiagonal eigenvalue/eigenvector problem", */
145 /*    Computer Science Division Technical Report No. UCB/CSD-97-971, */
146 /*    UC Berkeley, May 1997. */
147
148 /*  Notes: */
149 /*  1.DSTEMR works only on machines which follow IEEE-754 */
150 /*  floating-point standard in their handling of infinities and NaNs. */
151 /*  This permits the use of efficient inner loops avoiding a check for */
152 /*  zero divisors. */
153
154 /*  Arguments */
155 /*  ========= */
156
157 /*  JOBZ    (input) CHARACTER*1 */
158 /*          = 'N':  Compute eigenvalues only; */
159 /*          = 'V':  Compute eigenvalues and eigenvectors. */
160
161 /*  RANGE   (input) CHARACTER*1 */
162 /*          = 'A': all eigenvalues will be found. */
163 /*          = 'V': all eigenvalues in the half-open interval (VL,VU] */
164 /*                 will be found. */
165 /*          = 'I': the IL-th through IU-th eigenvalues will be found. */
166
167 /*  N       (input) INTEGER */
168 /*          The order of the matrix.  N >= 0. */
169
170 /*  D       (input/output) DOUBLE PRECISION array, dimension (N) */
171 /*          On entry, the N diagonal elements of the tridiagonal matrix */
172 /*          T. On exit, D is overwritten. */
173
174 /*  E       (input/output) DOUBLE PRECISION array, dimension (N) */
175 /*          On entry, the (N-1) subdiagonal elements of the tridiagonal */
176 /*          matrix T in elements 1 to N-1 of E. E(N) need not be set on */
177 /*          input, but is used internally as workspace. */
178 /*          On exit, E is overwritten. */
179
180 /*  VL      (input) DOUBLE PRECISION */
181 /*  VU      (input) DOUBLE PRECISION */
182 /*          If RANGE='V', the lower and upper bounds of the interval to */
183 /*          be searched for eigenvalues. VL < VU. */
184 /*          Not referenced if RANGE = 'A' or 'I'. */
185
186 /*  IL      (input) INTEGER */
187 /*  IU      (input) INTEGER */
188 /*          If RANGE='I', the indices (in ascending order) of the */
189 /*          smallest and largest eigenvalues to be returned. */
190 /*          1 <= IL <= IU <= N, if N > 0. */
191 /*          Not referenced if RANGE = 'A' or 'V'. */
192
193 /*  M       (output) INTEGER */
194 /*          The total number of eigenvalues found.  0 <= M <= N. */
195 /*          If RANGE = 'A', M = N, and if RANGE = 'I', M = IU-IL+1. */
196
197 /*  W       (output) DOUBLE PRECISION array, dimension (N) */
198 /*          The first M elements contain the selected eigenvalues in */
199 /*          ascending order. */
200
201 /*  Z       (output) DOUBLE PRECISION array, dimension (LDZ, max(1,M) ) */
202 /*          If JOBZ = 'V', and if INFO = 0, then the first M columns of Z */
203 /*          contain the orthonormal eigenvectors of the matrix T */
204 /*          corresponding to the selected eigenvalues, with the i-th */
205 /*          column of Z holding the eigenvector associated with W(i). */
206 /*          If JOBZ = 'N', then Z is not referenced. */
207 /*          Note: the user must ensure that at least max(1,M) columns are */
208 /*          supplied in the array Z; if RANGE = 'V', the exact value of M */
209 /*          is not known in advance and can be computed with a workspace */
210 /*          query by setting NZC = -1, see below. */
211
212 /*  LDZ     (input) INTEGER */
213 /*          The leading dimension of the array Z.  LDZ >= 1, and if */
214 /*          JOBZ = 'V', then LDZ >= max(1,N). */
215
216 /*  NZC     (input) INTEGER */
217 /*          The number of eigenvectors to be held in the array Z. */
218 /*          If RANGE = 'A', then NZC >= max(1,N). */
219 /*          If RANGE = 'V', then NZC >= the number of eigenvalues in (VL,VU]. */
220 /*          If RANGE = 'I', then NZC >= IU-IL+1. */
221 /*          If NZC = -1, then a workspace query is assumed; the */
222 /*          routine calculates the number of columns of the array Z that */
223 /*          are needed to hold the eigenvectors. */
224 /*          This value is returned as the first entry of the Z array, and */
225 /*          no error message related to NZC is issued by XERBLA. */
226
227 /*  ISUPPZ  (output) INTEGER ARRAY, dimension ( 2*max(1,M) ) */
228 /*          The support of the eigenvectors in Z, i.e., the indices */
229 /*          indicating the nonzero elements in Z. The i-th computed eigenvector */
230 /*          is nonzero only in elements ISUPPZ( 2*i-1 ) through */
231 /*          ISUPPZ( 2*i ). This is relevant in the case when the matrix */
232 /*          is split. ISUPPZ is only accessed when JOBZ is 'V' and N > 0. */
233
234 /*  TRYRAC  (input/output) LOGICAL */
235 /*          If TRYRAC.EQ..TRUE., indicates that the code should check whether */
236 /*          the tridiagonal matrix defines its eigenvalues to high relative */
237 /*          accuracy.  If so, the code uses relative-accuracy preserving */
238 /*          algorithms that might be (a bit) slower depending on the matrix. */
239 /*          If the matrix does not define its eigenvalues to high relative */
240 /*          accuracy, the code can uses possibly faster algorithms. */
241 /*          If TRYRAC.EQ..FALSE., the code is not required to guarantee */
242 /*          relatively accurate eigenvalues and can use the fastest possible */
243 /*          techniques. */
244 /*          On exit, a .TRUE. TRYRAC will be set to .FALSE. if the matrix */
245 /*          does not define its eigenvalues to high relative accuracy. */
246
247 /*  WORK    (workspace/output) DOUBLE PRECISION array, dimension (LWORK) */
248 /*          On exit, if INFO = 0, WORK(1) returns the optimal */
249 /*          (and minimal) LWORK. */
250
251 /*  LWORK   (input) INTEGER */
252 /*          The dimension of the array WORK. LWORK >= max(1,18*N) */
253 /*          if JOBZ = 'V', and LWORK >= max(1,12*N) if JOBZ = 'N'. */
254 /*          If LWORK = -1, then a workspace query is assumed; the routine */
255 /*          only calculates the optimal size of the WORK array, returns */
256 /*          this value as the first entry of the WORK array, and no error */
257 /*          message related to LWORK is issued by XERBLA. */
258
259 /*  IWORK   (workspace/output) INTEGER array, dimension (LIWORK) */
260 /*          On exit, if INFO = 0, IWORK(1) returns the optimal LIWORK. */
261
262 /*  LIWORK  (input) INTEGER */
263 /*          The dimension of the array IWORK.  LIWORK >= max(1,10*N) */
264 /*          if the eigenvectors are desired, and LIWORK >= max(1,8*N) */
265 /*          if only the eigenvalues are to be computed. */
266 /*          If LIWORK = -1, then a workspace query is assumed; the */
267 /*          routine only calculates the optimal size of the IWORK array, */
268 /*          returns this value as the first entry of the IWORK array, and */
269 /*          no error message related to LIWORK is issued by XERBLA. */
270
271 /*  INFO    (output) INTEGER */
272 /*          On exit, INFO */
273 /*          = 0:  successful exit */
274 /*          < 0:  if INFO = -i, the i-th argument had an illegal value */
275 /*          > 0:  if INFO = 1X, internal error in DLARRE, */
276 /*                if INFO = 2X, internal error in DLARRV. */
277 /*                Here, the digit X = ABS( IINFO ) < 10, where IINFO is */
278 /*                the nonzero error code returned by DLARRE or */
279 /*                DLARRV, respectively. */
280
281
282 /*  Further Details */
283 /*  =============== */
284
285 /*  Based on contributions by */
286 /*     Beresford Parlett, University of California, Berkeley, USA */
287 /*     Jim Demmel, University of California, Berkeley, USA */
288 /*     Inderjit Dhillon, University of Texas, Austin, USA */
289 /*     Osni Marques, LBNL/NERSC, USA */
290 /*     Christof Voemel, University of California, Berkeley, USA */
291
292 /*  ===================================================================== */
293
294 /*     .. Parameters .. */
295 /*     .. */
296 /*     .. Local Scalars .. */
297 /*     .. */
298 /*     .. */
299 /*     .. External Functions .. */
300 /*     .. */
301 /*     .. External Subroutines .. */
302 /*     .. */
303 /*     .. Intrinsic Functions .. */
304 /*     .. */
305 /*     .. Executable Statements .. */
306
307 /*     Test the input parameters. */
308
309     /* Parameter adjustments */
310     --d__;
311     --e;
312     --w;
313     z_dim1 = *ldz;
314     z_offset = 1 + z_dim1;
315     z__ -= z_offset;
316     --isuppz;
317     --work;
318     --iwork;
319
320     /* Function Body */
321     wantz = lsame_(jobz, "V");
322     alleig = lsame_(range, "A");
323     valeig = lsame_(range, "V");
324     indeig = lsame_(range, "I");
325
326     lquery = *lwork == -1 || *liwork == -1;
327     zquery = *nzc == -1;
328     *tryrac = *info != 0;
329 /*     DSTEMR needs WORK of size 6*N, IWORK of size 3*N. */
330 /*     In addition, DLARRE needs WORK of size 6*N, IWORK of size 5*N. */
331 /*     Furthermore, DLARRV needs WORK of size 12*N, IWORK of size 7*N. */
332     if (wantz) {
333         lwmin = *n * 18;
334         liwmin = *n * 10;
335     } else {
336 /*        need less workspace if only the eigenvalues are wanted */
337         lwmin = *n * 12;
338         liwmin = *n << 3;
339     }
340     wl = 0.;
341     wu = 0.;
342     iil = 0;
343     iiu = 0;
344     if (valeig) {
345 /*        We do not reference VL, VU in the cases RANGE = 'I','A' */
346 /*        The interval (WL, WU] contains all the wanted eigenvalues. */
347 /*        It is either given by the user or computed in DLARRE. */
348         wl = *vl;
349         wu = *vu;
350     } else if (indeig) {
351 /*        We do not reference IL, IU in the cases RANGE = 'V','A' */
352         iil = *il;
353         iiu = *iu;
354     }
355
356     *info = 0;
357     if (! (wantz || lsame_(jobz, "N"))) {
358         *info = -1;
359     } else if (! (alleig || valeig || indeig)) {
360         *info = -2;
361     } else if (*n < 0) {
362         *info = -3;
363     } else if (valeig && *n > 0 && wu <= wl) {
364         *info = -7;
365     } else if (indeig && (iil < 1 || iil > *n)) {
366         *info = -8;
367     } else if (indeig && (iiu < iil || iiu > *n)) {
368         *info = -9;
369     } else if (*ldz < 1 || wantz && *ldz < *n) {
370         *info = -13;
371     } else if (*lwork < lwmin && ! lquery) {
372         *info = -17;
373     } else if (*liwork < liwmin && ! lquery) {
374         *info = -19;
375     }
376
377 /*     Get machine constants. */
378
379     safmin = dlamch_("Safe minimum");
380     eps = dlamch_("Precision");
381     smlnum = safmin / eps;
382     bignum = 1. / smlnum;
383     rmin = sqrt(smlnum);
384 /* Computing MIN */
385     d__1 = sqrt(bignum), d__2 = 1. / sqrt(sqrt(safmin));
386     rmax = min(d__1,d__2);
387
388     if (*info == 0) {
389         work[1] = (doublereal) lwmin;
390         iwork[1] = liwmin;
391
392         if (wantz && alleig) {
393             nzcmin = *n;
394         } else if (wantz && valeig) {
395             dlarrc_("T", n, vl, vu, &d__[1], &e[1], &safmin, &nzcmin, &itmp, &
396                     itmp2, info);
397         } else if (wantz && indeig) {
398             nzcmin = iiu - iil + 1;
399         } else {
400 /*           WANTZ .EQ. FALSE. */
401             nzcmin = 0;
402         }
403         if (zquery && *info == 0) {
404             z__[z_dim1 + 1] = (doublereal) nzcmin;
405         } else if (*nzc < nzcmin && ! zquery) {
406             *info = -14;
407         }
408     }
409     if (*info != 0) {
410
411         i__1 = -(*info);
412         xerbla_("DSTEMR", &i__1);
413
414         return 0;
415     } else if (lquery || zquery) {
416         return 0;
417     }
418
419 /*     Handle N = 0, 1, and 2 cases immediately */
420
421     *m = 0;
422     if (*n == 0) {
423         return 0;
424     }
425
426     if (*n == 1) {
427         if (alleig || indeig) {
428             *m = 1;
429             w[1] = d__[1];
430         } else {
431             if (wl < d__[1] && wu >= d__[1]) {
432                 *m = 1;
433                 w[1] = d__[1];
434             }
435         }
436         if (wantz && ! zquery) {
437             z__[z_dim1 + 1] = 1.;
438             isuppz[1] = 1;
439             isuppz[2] = 1;
440         }
441         return 0;
442     }
443
444     if (*n == 2) {
445         if (! wantz) {
446             dlae2_(&d__[1], &e[1], &d__[2], &r1, &r2);
447         } else if (wantz && ! zquery) {
448             dlaev2_(&d__[1], &e[1], &d__[2], &r1, &r2, &cs, &sn);
449         }
450         if (alleig || valeig && r2 > wl && r2 <= wu || indeig && iil == 1) {
451             ++(*m);
452             w[*m] = r2;
453             if (wantz && ! zquery) {
454                 z__[*m * z_dim1 + 1] = -sn;
455                 z__[*m * z_dim1 + 2] = cs;
456 /*              Note: At most one of SN and CS can be zero. */
457                 if (sn != 0.) {
458                     if (cs != 0.) {
459                         isuppz[(*m << 1) - 1] = 1;
460                         isuppz[(*m << 1) - 1] = 2;
461                     } else {
462                         isuppz[(*m << 1) - 1] = 1;
463                         isuppz[(*m << 1) - 1] = 1;
464                     }
465                 } else {
466                     isuppz[(*m << 1) - 1] = 2;
467                     isuppz[*m * 2] = 2;
468                 }
469             }
470         }
471         if (alleig || valeig && r1 > wl && r1 <= wu || indeig && iiu == 2) {
472             ++(*m);
473             w[*m] = r1;
474             if (wantz && ! zquery) {
475                 z__[*m * z_dim1 + 1] = cs;
476                 z__[*m * z_dim1 + 2] = sn;
477 /*              Note: At most one of SN and CS can be zero. */
478                 if (sn != 0.) {
479                     if (cs != 0.) {
480                         isuppz[(*m << 1) - 1] = 1;
481                         isuppz[(*m << 1) - 1] = 2;
482                     } else {
483                         isuppz[(*m << 1) - 1] = 1;
484                         isuppz[(*m << 1) - 1] = 1;
485                     }
486                 } else {
487                     isuppz[(*m << 1) - 1] = 2;
488                     isuppz[*m * 2] = 2;
489                 }
490             }
491         }
492         return 0;
493     }
494 /*     Continue with general N */
495     indgrs = 1;
496     inderr = (*n << 1) + 1;
497     indgp = *n * 3 + 1;
498     indd = (*n << 2) + 1;
499     inde2 = *n * 5 + 1;
500     indwrk = *n * 6 + 1;
501
502     iinspl = 1;
503     iindbl = *n + 1;
504     iindw = (*n << 1) + 1;
505     iindwk = *n * 3 + 1;
506
507 /*     Scale matrix to allowable range, if necessary. */
508 /*     The allowable range is related to the PIVMIN parameter; see the */
509 /*     comments in DLARRD.  The preference for scaling small values */
510 /*     up is heuristic; we expect users' matrices not to be close to the */
511 /*     RMAX threshold. */
512
513     scale = 1.;
514     tnrm = dlanst_("M", n, &d__[1], &e[1]);
515     if (tnrm > 0. && tnrm < rmin) {
516         scale = rmin / tnrm;
517     } else if (tnrm > rmax) {
518         scale = rmax / tnrm;
519     }
520     if (scale != 1.) {
521         dscal_(n, &scale, &d__[1], &c__1);
522         i__1 = *n - 1;
523         dscal_(&i__1, &scale, &e[1], &c__1);
524         tnrm *= scale;
525         if (valeig) {
526 /*           If eigenvalues in interval have to be found, */
527 /*           scale (WL, WU] accordingly */
528             wl *= scale;
529             wu *= scale;
530         }
531     }
532
533 /*     Compute the desired eigenvalues of the tridiagonal after splitting */
534 /*     into smaller subblocks if the corresponding off-diagonal elements */
535 /*     are small */
536 /*     THRESH is the splitting parameter for DLARRE */
537 /*     A negative THRESH forces the old splitting criterion based on the */
538 /*     size of the off-diagonal. A positive THRESH switches to splitting */
539 /*     which preserves relative accuracy. */
540
541     if (*tryrac) {
542 /*        Test whether the matrix warrants the more expensive relative approach. */
543         dlarrr_(n, &d__[1], &e[1], &iinfo);
544     } else {
545 /*        The user does not care about relative accurately eigenvalues */
546         iinfo = -1;
547     }
548 /*     Set the splitting criterion */
549     if (iinfo == 0) {
550         thresh = eps;
551     } else {
552         thresh = -eps;
553 /*        relative accuracy is desired but T does not guarantee it */
554         *tryrac = FALSE_;
555     }
556
557     if (*tryrac) {
558 /*        Copy original diagonal, needed to guarantee relative accuracy */
559         dcopy_(n, &d__[1], &c__1, &work[indd], &c__1);
560     }
561 /*     Store the squares of the offdiagonal values of T */
562     i__1 = *n - 1;
563     for (j = 1; j <= i__1; ++j) {
564 /* Computing 2nd power */
565         d__1 = e[j];
566         work[inde2 + j - 1] = d__1 * d__1;
567 /* L5: */
568     }
569 /*     Set the tolerance parameters for bisection */
570     if (! wantz) {
571 /*        DLARRE computes the eigenvalues to full precision. */
572         rtol1 = eps * 4.;
573         rtol2 = eps * 4.;
574     } else {
575 /*        DLARRE computes the eigenvalues to less than full precision. */
576 /*        DLARRV will refine the eigenvalue approximations, and we can */
577 /*        need less accurate initial bisection in DLARRE. */
578 /*        Note: these settings do only affect the subset case and DLARRE */
579         rtol1 = sqrt(eps);
580 /* Computing MAX */
581         d__1 = sqrt(eps) * .005, d__2 = eps * 4.;
582         rtol2 = max(d__1,d__2);
583     }
584     dlarre_(range, n, &wl, &wu, &iil, &iiu, &d__[1], &e[1], &work[inde2], &
585             rtol1, &rtol2, &thresh, &nsplit, &iwork[iinspl], m, &w[1], &work[
586             inderr], &work[indgp], &iwork[iindbl], &iwork[iindw], &work[
587             indgrs], &pivmin, &work[indwrk], &iwork[iindwk], &iinfo);
588     if (iinfo != 0) {
589         *info = abs(iinfo) + 10;
590         return 0;
591     }
592 /*     Note that if RANGE .NE. 'V', DLARRE computes bounds on the desired */
593 /*     part of the spectrum. All desired eigenvalues are contained in */
594 /*     (WL,WU] */
595     if (wantz) {
596
597 /*        Compute the desired eigenvectors corresponding to the computed */
598 /*        eigenvalues */
599
600         dlarrv_(n, &wl, &wu, &d__[1], &e[1], &pivmin, &iwork[iinspl], m, &
601                 c__1, m, &c_b18, &rtol1, &rtol2, &w[1], &work[inderr], &work[
602                 indgp], &iwork[iindbl], &iwork[iindw], &work[indgrs], &z__[
603                 z_offset], ldz, &isuppz[1], &work[indwrk], &iwork[iindwk], &
604                 iinfo);
605         if (iinfo != 0) {
606             *info = abs(iinfo) + 20;
607             return 0;
608         }
609     } else {
610 /*        DLARRE computes eigenvalues of the (shifted) root representation */
611 /*        DLARRV returns the eigenvalues of the unshifted matrix. */
612 /*        However, if the eigenvectors are not desired by the user, we need */
613 /*        to apply the corresponding shifts from DLARRE to obtain the */
614 /*        eigenvalues of the original matrix. */
615         i__1 = *m;
616         for (j = 1; j <= i__1; ++j) {
617             itmp = iwork[iindbl + j - 1];
618             w[j] += e[iwork[iinspl + itmp - 1]];
619 /* L20: */
620         }
621     }
622
623     if (*tryrac) {
624 /*        Refine computed eigenvalues so that they are relatively accurate */
625 /*        with respect to the original matrix T. */
626         ibegin = 1;
627         wbegin = 1;
628         i__1 = iwork[iindbl + *m - 1];
629         for (jblk = 1; jblk <= i__1; ++jblk) {
630             iend = iwork[iinspl + jblk - 1];
631             in = iend - ibegin + 1;
632             wend = wbegin - 1;
633 /*           check if any eigenvalues have to be refined in this block */
634 L36:
635             if (wend < *m) {
636                 if (iwork[iindbl + wend] == jblk) {
637                     ++wend;
638                     goto L36;
639                 }
640             }
641             if (wend < wbegin) {
642                 ibegin = iend + 1;
643                 goto L39;
644             }
645             offset = iwork[iindw + wbegin - 1] - 1;
646             ifirst = iwork[iindw + wbegin - 1];
647             ilast = iwork[iindw + wend - 1];
648             rtol2 = eps * 4.;
649             dlarrj_(&in, &work[indd + ibegin - 1], &work[inde2 + ibegin - 1], 
650                     &ifirst, &ilast, &rtol2, &offset, &w[wbegin], &work[
651                     inderr + wbegin - 1], &work[indwrk], &iwork[iindwk], &
652                     pivmin, &tnrm, &iinfo);
653             ibegin = iend + 1;
654             wbegin = wend + 1;
655 L39:
656             ;
657         }
658     }
659
660 /*     If matrix was scaled, then rescale eigenvalues appropriately. */
661
662     if (scale != 1.) {
663         d__1 = 1. / scale;
664         dscal_(m, &d__1, &w[1], &c__1);
665     }
666
667 /*     If eigenvalues are not in increasing order, then sort them, */
668 /*     possibly along with eigenvectors. */
669
670     if (nsplit > 1) {
671         if (! wantz) {
672             dlasrt_("I", m, &w[1], &iinfo);
673             if (iinfo != 0) {
674                 *info = 3;
675                 return 0;
676             }
677         } else {
678             i__1 = *m - 1;
679             for (j = 1; j <= i__1; ++j) {
680                 i__ = 0;
681                 tmp = w[j];
682                 i__2 = *m;
683                 for (jj = j + 1; jj <= i__2; ++jj) {
684                     if (w[jj] < tmp) {
685                         i__ = jj;
686                         tmp = w[jj];
687                     }
688 /* L50: */
689                 }
690                 if (i__ != 0) {
691                     w[i__] = w[j];
692                     w[j] = tmp;
693                     if (wantz) {
694                         dswap_(n, &z__[i__ * z_dim1 + 1], &c__1, &z__[j * 
695                                 z_dim1 + 1], &c__1);
696                         itmp = isuppz[(i__ << 1) - 1];
697                         isuppz[(i__ << 1) - 1] = isuppz[(j << 1) - 1];
698                         isuppz[(j << 1) - 1] = itmp;
699                         itmp = isuppz[i__ * 2];
700                         isuppz[i__ * 2] = isuppz[j * 2];
701                         isuppz[j * 2] = itmp;
702                     }
703                 }
704 /* L60: */
705             }
706         }
707     }
708
709
710     work[1] = (doublereal) lwmin;
711     iwork[1] = liwmin;
712     return 0;
713
714 /*     End of DSTEMR */
715
716 } /* dstemr_ */