C_LAPACK: Fixes to make it compile with MSVC (#3605)
[platform/upstream/openblas.git] / lapack-netlib / SRC / slarrv.c
1 #include <math.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <stdio.h>
5 #include <complex.h>
6 #ifdef complex
7 #undef complex
8 #endif
9 #ifdef I
10 #undef I
11 #endif
12
13 #if defined(_WIN64)
14 typedef long long BLASLONG;
15 typedef unsigned long long BLASULONG;
16 #else
17 typedef long BLASLONG;
18 typedef unsigned long BLASULONG;
19 #endif
20
21 #ifdef LAPACK_ILP64
22 typedef BLASLONG blasint;
23 #if defined(_WIN64)
24 #define blasabs(x) llabs(x)
25 #else
26 #define blasabs(x) labs(x)
27 #endif
28 #else
29 typedef int blasint;
30 #define blasabs(x) abs(x)
31 #endif
32
33 typedef blasint integer;
34
35 typedef unsigned int uinteger;
36 typedef char *address;
37 typedef short int shortint;
38 typedef float real;
39 typedef double doublereal;
40 typedef struct { real r, i; } complex;
41 typedef struct { doublereal r, i; } doublecomplex;
42 #ifdef _MSC_VER
43 static inline _Fcomplex Cf(complex *z) {_Fcomplex zz={z->r , z->i}; return zz;}
44 static inline _Dcomplex Cd(doublecomplex *z) {_Dcomplex zz={z->r , z->i};return zz;}
45 static inline _Fcomplex * _pCf(complex *z) {return (_Fcomplex*)z;}
46 static inline _Dcomplex * _pCd(doublecomplex *z) {return (_Dcomplex*)z;}
47 #else
48 static inline _Complex float Cf(complex *z) {return z->r + z->i*_Complex_I;}
49 static inline _Complex double Cd(doublecomplex *z) {return z->r + z->i*_Complex_I;}
50 static inline _Complex float * _pCf(complex *z) {return (_Complex float*)z;}
51 static inline _Complex double * _pCd(doublecomplex *z) {return (_Complex double*)z;}
52 #endif
53 #define pCf(z) (*_pCf(z))
54 #define pCd(z) (*_pCd(z))
55 typedef int logical;
56 typedef short int shortlogical;
57 typedef char logical1;
58 typedef char integer1;
59
60 #define TRUE_ (1)
61 #define FALSE_ (0)
62
63 /* Extern is for use with -E */
64 #ifndef Extern
65 #define Extern extern
66 #endif
67
68 /* I/O stuff */
69
70 typedef int flag;
71 typedef int ftnlen;
72 typedef int ftnint;
73
74 /*external read, write*/
75 typedef struct
76 {       flag cierr;
77         ftnint ciunit;
78         flag ciend;
79         char *cifmt;
80         ftnint cirec;
81 } cilist;
82
83 /*internal read, write*/
84 typedef struct
85 {       flag icierr;
86         char *iciunit;
87         flag iciend;
88         char *icifmt;
89         ftnint icirlen;
90         ftnint icirnum;
91 } icilist;
92
93 /*open*/
94 typedef struct
95 {       flag oerr;
96         ftnint ounit;
97         char *ofnm;
98         ftnlen ofnmlen;
99         char *osta;
100         char *oacc;
101         char *ofm;
102         ftnint orl;
103         char *oblnk;
104 } olist;
105
106 /*close*/
107 typedef struct
108 {       flag cerr;
109         ftnint cunit;
110         char *csta;
111 } cllist;
112
113 /*rewind, backspace, endfile*/
114 typedef struct
115 {       flag aerr;
116         ftnint aunit;
117 } alist;
118
119 /* inquire */
120 typedef struct
121 {       flag inerr;
122         ftnint inunit;
123         char *infile;
124         ftnlen infilen;
125         ftnint  *inex;  /*parameters in standard's order*/
126         ftnint  *inopen;
127         ftnint  *innum;
128         ftnint  *innamed;
129         char    *inname;
130         ftnlen  innamlen;
131         char    *inacc;
132         ftnlen  inacclen;
133         char    *inseq;
134         ftnlen  inseqlen;
135         char    *indir;
136         ftnlen  indirlen;
137         char    *infmt;
138         ftnlen  infmtlen;
139         char    *inform;
140         ftnint  informlen;
141         char    *inunf;
142         ftnlen  inunflen;
143         ftnint  *inrecl;
144         ftnint  *innrec;
145         char    *inblank;
146         ftnlen  inblanklen;
147 } inlist;
148
149 #define VOID void
150
151 union Multitype {       /* for multiple entry points */
152         integer1 g;
153         shortint h;
154         integer i;
155         /* longint j; */
156         real r;
157         doublereal d;
158         complex c;
159         doublecomplex z;
160         };
161
162 typedef union Multitype Multitype;
163
164 struct Vardesc {        /* for Namelist */
165         char *name;
166         char *addr;
167         ftnlen *dims;
168         int  type;
169         };
170 typedef struct Vardesc Vardesc;
171
172 struct Namelist {
173         char *name;
174         Vardesc **vars;
175         int nvars;
176         };
177 typedef struct Namelist Namelist;
178
179 #define abs(x) ((x) >= 0 ? (x) : -(x))
180 #define dabs(x) (fabs(x))
181 #define f2cmin(a,b) ((a) <= (b) ? (a) : (b))
182 #define f2cmax(a,b) ((a) >= (b) ? (a) : (b))
183 #define dmin(a,b) (f2cmin(a,b))
184 #define dmax(a,b) (f2cmax(a,b))
185 #define bit_test(a,b)   ((a) >> (b) & 1)
186 #define bit_clear(a,b)  ((a) & ~((uinteger)1 << (b)))
187 #define bit_set(a,b)    ((a) |  ((uinteger)1 << (b)))
188
189 #define abort_() { sig_die("Fortran abort routine called", 1); }
190 #define c_abs(z) (cabsf(Cf(z)))
191 #define c_cos(R,Z) { pCf(R)=ccos(Cf(Z)); }
192 #ifdef _MSC_VER
193 #define c_div(c, a, b) {Cf(c)._Val[0] = (Cf(a)._Val[0]/Cf(b)._Val[0]); Cf(c)._Val[1]=(Cf(a)._Val[1]/Cf(b)._Val[1]);}
194 #define z_div(c, a, b) {Cd(c)._Val[0] = (Cd(a)._Val[0]/Cd(b)._Val[0]); Cd(c)._Val[1]=(Cd(a)._Val[1]/df(b)._Val[1]);}
195 #else
196 #define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);}
197 #define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);}
198 #endif
199 #define c_exp(R, Z) {pCf(R) = cexpf(Cf(Z));}
200 #define c_log(R, Z) {pCf(R) = clogf(Cf(Z));}
201 #define c_sin(R, Z) {pCf(R) = csinf(Cf(Z));}
202 //#define c_sqrt(R, Z) {*(R) = csqrtf(Cf(Z));}
203 #define c_sqrt(R, Z) {pCf(R) = csqrtf(Cf(Z));}
204 #define d_abs(x) (fabs(*(x)))
205 #define d_acos(x) (acos(*(x)))
206 #define d_asin(x) (asin(*(x)))
207 #define d_atan(x) (atan(*(x)))
208 #define d_atn2(x, y) (atan2(*(x),*(y)))
209 #define d_cnjg(R, Z) { pCd(R) = conj(Cd(Z)); }
210 #define r_cnjg(R, Z) { pCf(R) = conjf(Cf(Z)); }
211 #define d_cos(x) (cos(*(x)))
212 #define d_cosh(x) (cosh(*(x)))
213 #define d_dim(__a, __b) ( *(__a) > *(__b) ? *(__a) - *(__b) : 0.0 )
214 #define d_exp(x) (exp(*(x)))
215 #define d_imag(z) (cimag(Cd(z)))
216 #define r_imag(z) (cimagf(Cf(z)))
217 #define d_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
218 #define r_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
219 #define d_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
220 #define r_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
221 #define d_log(x) (log(*(x)))
222 #define d_mod(x, y) (fmod(*(x), *(y)))
223 #define u_nint(__x) ((__x)>=0 ? floor((__x) + .5) : -floor(.5 - (__x)))
224 #define d_nint(x) u_nint(*(x))
225 #define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a)))
226 #define d_sign(a,b) u_sign(*(a),*(b))
227 #define r_sign(a,b) u_sign(*(a),*(b))
228 #define d_sin(x) (sin(*(x)))
229 #define d_sinh(x) (sinh(*(x)))
230 #define d_sqrt(x) (sqrt(*(x)))
231 #define d_tan(x) (tan(*(x)))
232 #define d_tanh(x) (tanh(*(x)))
233 #define i_abs(x) abs(*(x))
234 #define i_dnnt(x) ((integer)u_nint(*(x)))
235 #define i_len(s, n) (n)
236 #define i_nint(x) ((integer)u_nint(*(x)))
237 #define i_sign(a,b) ((integer)u_sign((integer)*(a),(integer)*(b)))
238 #define pow_dd(ap, bp) ( pow(*(ap), *(bp)))
239 #define pow_si(B,E) spow_ui(*(B),*(E))
240 #define pow_ri(B,E) spow_ui(*(B),*(E))
241 #define pow_di(B,E) dpow_ui(*(B),*(E))
242 #define pow_zi(p, a, b) {pCd(p) = zpow_ui(Cd(a), *(b));}
243 #define pow_ci(p, a, b) {pCf(p) = cpow_ui(Cf(a), *(b));}
244 #define pow_zz(R,A,B) {pCd(R) = cpow(Cd(A),*(B));}
245 #define s_cat(lpp, rpp, rnp, np, llp) {         ftnlen i, nc, ll; char *f__rp, *lp;     ll = (llp); lp = (lpp);         for(i=0; i < (int)*(np); ++i) {                 nc = ll;                if((rnp)[i] < nc) nc = (rnp)[i];                ll -= nc;               f__rp = (rpp)[i];               while(--nc >= 0) *lp++ = *(f__rp)++;         }  while(--ll >= 0) *lp++ = ' '; }
246 #define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d))))
247 #define s_copy(A,B,C,D) { int __i,__m; for (__i=0, __m=f2cmin((C),(D)); __i<__m && (B)[__i] != 0; ++__i) (A)[__i] = (B)[__i]; }
248 #define sig_die(s, kill) { exit(1); }
249 #define s_stop(s, n) {exit(0);}
250 static char junk[] = "\n@(#)LIBF77 VERSION 19990503\n";
251 #define z_abs(z) (cabs(Cd(z)))
252 #define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));}
253 #define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));}
254 #define myexit_() break;
255 #define mycycle() continue;
256 #define myceiling(w) {ceil(w)}
257 #define myhuge(w) {HUGE_VAL}
258 //#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);}
259 #define mymaxloc(w,s,e,n) {dmaxloc_(w,*(s),*(e),n)}
260
261 /* procedure parameter types for -A and -C++ */
262
263 #define F2C_proc_par_types 1
264 #ifdef __cplusplus
265 typedef logical (*L_fp)(...);
266 #else
267 typedef logical (*L_fp)();
268 #endif
269
270 static float spow_ui(float x, integer n) {
271         float pow=1.0; unsigned long int u;
272         if(n != 0) {
273                 if(n < 0) n = -n, x = 1/x;
274                 for(u = n; ; ) {
275                         if(u & 01) pow *= x;
276                         if(u >>= 1) x *= x;
277                         else break;
278                 }
279         }
280         return pow;
281 }
282 static double dpow_ui(double x, integer n) {
283         double pow=1.0; unsigned long int u;
284         if(n != 0) {
285                 if(n < 0) n = -n, x = 1/x;
286                 for(u = n; ; ) {
287                         if(u & 01) pow *= x;
288                         if(u >>= 1) x *= x;
289                         else break;
290                 }
291         }
292         return pow;
293 }
294 #ifdef _MSC_VER
295 static _Fcomplex cpow_ui(complex x, integer n) {
296         complex pow={1.0,0.0}; unsigned long int u;
297                 if(n != 0) {
298                 if(n < 0) n = -n, x.r = 1/x.r, x.i=1/x.i;
299                 for(u = n; ; ) {
300                         if(u & 01) pow.r *= x.r, pow.i *= x.i;
301                         if(u >>= 1) x.r *= x.r, x.i *= x.i;
302                         else break;
303                 }
304         }
305         _Fcomplex p={pow.r, pow.i};
306         return p;
307 }
308 #else
309 static _Complex float cpow_ui(_Complex float x, integer n) {
310         _Complex float pow=1.0; unsigned long int u;
311         if(n != 0) {
312                 if(n < 0) n = -n, x = 1/x;
313                 for(u = n; ; ) {
314                         if(u & 01) pow *= x;
315                         if(u >>= 1) x *= x;
316                         else break;
317                 }
318         }
319         return pow;
320 }
321 #endif
322 #ifdef _MSC_VER
323 static _Dcomplex zpow_ui(_Dcomplex x, integer n) {
324         _Dcomplex pow={1.0,0.0}; unsigned long int u;
325         if(n != 0) {
326                 if(n < 0) n = -n, x._Val[0] = 1/x._Val[0], x._Val[1] =1/x._Val[1];
327                 for(u = n; ; ) {
328                         if(u & 01) pow._Val[0] *= x._Val[0], pow._Val[1] *= x._Val[1];
329                         if(u >>= 1) x._Val[0] *= x._Val[0], x._Val[1] *= x._Val[1];
330                         else break;
331                 }
332         }
333         _Dcomplex p = {pow._Val[0], pow._Val[1]};
334         return p;
335 }
336 #else
337 static _Complex double zpow_ui(_Complex double x, integer n) {
338         _Complex double pow=1.0; unsigned long int u;
339         if(n != 0) {
340                 if(n < 0) n = -n, x = 1/x;
341                 for(u = n; ; ) {
342                         if(u & 01) pow *= x;
343                         if(u >>= 1) x *= x;
344                         else break;
345                 }
346         }
347         return pow;
348 }
349 #endif
350 static integer pow_ii(integer x, integer n) {
351         integer pow; unsigned long int u;
352         if (n <= 0) {
353                 if (n == 0 || x == 1) pow = 1;
354                 else if (x != -1) pow = x == 0 ? 1/x : 0;
355                 else n = -n;
356         }
357         if ((n > 0) || !(n == 0 || x == 1 || x != -1)) {
358                 u = n;
359                 for(pow = 1; ; ) {
360                         if(u & 01) pow *= x;
361                         if(u >>= 1) x *= x;
362                         else break;
363                 }
364         }
365         return pow;
366 }
367 static integer dmaxloc_(double *w, integer s, integer e, integer *n)
368 {
369         double m; integer i, mi;
370         for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
371                 if (w[i-1]>m) mi=i ,m=w[i-1];
372         return mi-s+1;
373 }
374 static integer smaxloc_(float *w, integer s, integer e, integer *n)
375 {
376         float m; integer i, mi;
377         for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
378                 if (w[i-1]>m) mi=i ,m=w[i-1];
379         return mi-s+1;
380 }
381 static inline void cdotc_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
382         integer n = *n_, incx = *incx_, incy = *incy_, i;
383 #ifdef _MSC_VER
384         _Fcomplex zdotc = {0.0, 0.0};
385         if (incx == 1 && incy == 1) {
386                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
387                         zdotc._Val[0] += conjf(Cf(&x[i]))._Val[0] * Cf(&y[i])._Val[0];
388                         zdotc._Val[1] += conjf(Cf(&x[i]))._Val[1] * Cf(&y[i])._Val[1];
389                 }
390         } else {
391                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
392                         zdotc._Val[0] += conjf(Cf(&x[i*incx]))._Val[0] * Cf(&y[i*incy])._Val[0];
393                         zdotc._Val[1] += conjf(Cf(&x[i*incx]))._Val[1] * Cf(&y[i*incy])._Val[1];
394                 }
395         }
396         pCf(z) = zdotc;
397 }
398 #else
399         _Complex float zdotc = 0.0;
400         if (incx == 1 && incy == 1) {
401                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
402                         zdotc += conjf(Cf(&x[i])) * Cf(&y[i]);
403                 }
404         } else {
405                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
406                         zdotc += conjf(Cf(&x[i*incx])) * Cf(&y[i*incy]);
407                 }
408         }
409         pCf(z) = zdotc;
410 }
411 #endif
412 static inline void zdotc_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
413         integer n = *n_, incx = *incx_, incy = *incy_, i;
414 #ifdef _MSC_VER
415         _Dcomplex zdotc = {0.0, 0.0};
416         if (incx == 1 && incy == 1) {
417                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
418                         zdotc._Val[0] += conj(Cd(&x[i]))._Val[0] * Cd(&y[i])._Val[0];
419                         zdotc._Val[1] += conj(Cd(&x[i]))._Val[1] * Cd(&y[i])._Val[1];
420                 }
421         } else {
422                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
423                         zdotc._Val[0] += conj(Cd(&x[i*incx]))._Val[0] * Cd(&y[i*incy])._Val[0];
424                         zdotc._Val[1] += conj(Cd(&x[i*incx]))._Val[1] * Cd(&y[i*incy])._Val[1];
425                 }
426         }
427         pCd(z) = zdotc;
428 }
429 #else
430         _Complex double zdotc = 0.0;
431         if (incx == 1 && incy == 1) {
432                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
433                         zdotc += conj(Cd(&x[i])) * Cd(&y[i]);
434                 }
435         } else {
436                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
437                         zdotc += conj(Cd(&x[i*incx])) * Cd(&y[i*incy]);
438                 }
439         }
440         pCd(z) = zdotc;
441 }
442 #endif  
443 static inline void cdotu_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
444         integer n = *n_, incx = *incx_, incy = *incy_, i;
445 #ifdef _MSC_VER
446         _Fcomplex zdotc = {0.0, 0.0};
447         if (incx == 1 && incy == 1) {
448                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
449                         zdotc._Val[0] += Cf(&x[i])._Val[0] * Cf(&y[i])._Val[0];
450                         zdotc._Val[1] += Cf(&x[i])._Val[1] * Cf(&y[i])._Val[1];
451                 }
452         } else {
453                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
454                         zdotc._Val[0] += Cf(&x[i*incx])._Val[0] * Cf(&y[i*incy])._Val[0];
455                         zdotc._Val[1] += Cf(&x[i*incx])._Val[1] * Cf(&y[i*incy])._Val[1];
456                 }
457         }
458         pCf(z) = zdotc;
459 }
460 #else
461         _Complex float zdotc = 0.0;
462         if (incx == 1 && incy == 1) {
463                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
464                         zdotc += Cf(&x[i]) * Cf(&y[i]);
465                 }
466         } else {
467                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
468                         zdotc += Cf(&x[i*incx]) * Cf(&y[i*incy]);
469                 }
470         }
471         pCf(z) = zdotc;
472 }
473 #endif
474 static inline void zdotu_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
475         integer n = *n_, incx = *incx_, incy = *incy_, i;
476 #ifdef _MSC_VER
477         _Dcomplex zdotc = {0.0, 0.0};
478         if (incx == 1 && incy == 1) {
479                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
480                         zdotc._Val[0] += Cd(&x[i])._Val[0] * Cd(&y[i])._Val[0];
481                         zdotc._Val[1] += Cd(&x[i])._Val[1] * Cd(&y[i])._Val[1];
482                 }
483         } else {
484                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
485                         zdotc._Val[0] += Cd(&x[i*incx])._Val[0] * Cd(&y[i*incy])._Val[0];
486                         zdotc._Val[1] += Cd(&x[i*incx])._Val[1] * Cd(&y[i*incy])._Val[1];
487                 }
488         }
489         pCd(z) = zdotc;
490 }
491 #else
492         _Complex double zdotc = 0.0;
493         if (incx == 1 && incy == 1) {
494                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
495                         zdotc += Cd(&x[i]) * Cd(&y[i]);
496                 }
497         } else {
498                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
499                         zdotc += Cd(&x[i*incx]) * Cd(&y[i*incy]);
500                 }
501         }
502         pCd(z) = zdotc;
503 }
504 #endif
505 /*  -- translated by f2c (version 20000121).
506    You must link the resulting object file with the libraries:
507         -lf2c -lm   (in that order)
508 */
509
510
511
512
513 /* Table of constant values */
514
515 static real c_b5 = 0.f;
516 static integer c__1 = 1;
517 static integer c__2 = 2;
518
519 /* > \brief \b SLARRV computes the eigenvectors of the tridiagonal matrix T = L D LT given L, D and the eigenv
520 alues of L D LT. */
521
522 /*  =========== DOCUMENTATION =========== */
523
524 /* Online html documentation available at */
525 /*            http://www.netlib.org/lapack/explore-html/ */
526
527 /* > \htmlonly */
528 /* > Download SLARRV + dependencies */
529 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/slarrv.
530 f"> */
531 /* > [TGZ]</a> */
532 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/slarrv.
533 f"> */
534 /* > [ZIP]</a> */
535 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/slarrv.
536 f"> */
537 /* > [TXT]</a> */
538 /* > \endhtmlonly */
539
540 /*  Definition: */
541 /*  =========== */
542
543 /*       SUBROUTINE SLARRV( N, VL, VU, D, L, PIVMIN, */
544 /*                          ISPLIT, M, DOL, DOU, MINRGP, */
545 /*                          RTOL1, RTOL2, W, WERR, WGAP, */
546 /*                          IBLOCK, INDEXW, GERS, Z, LDZ, ISUPPZ, */
547 /*                          WORK, IWORK, INFO ) */
548
549 /*       INTEGER            DOL, DOU, INFO, LDZ, M, N */
550 /*       REAL               MINRGP, PIVMIN, RTOL1, RTOL2, VL, VU */
551 /*       INTEGER            IBLOCK( * ), INDEXW( * ), ISPLIT( * ), */
552 /*      $                   ISUPPZ( * ), IWORK( * ) */
553 /*       REAL               D( * ), GERS( * ), L( * ), W( * ), WERR( * ), */
554 /*      $                   WGAP( * ), WORK( * ) */
555 /*       REAL              Z( LDZ, * ) */
556
557
558 /* > \par Purpose: */
559 /*  ============= */
560 /* > */
561 /* > \verbatim */
562 /* > */
563 /* > SLARRV computes the eigenvectors of the tridiagonal matrix */
564 /* > T = L D L**T given L, D and APPROXIMATIONS to the eigenvalues of L D L**T. */
565 /* > The input eigenvalues should have been computed by SLARRE. */
566 /* > \endverbatim */
567
568 /*  Arguments: */
569 /*  ========== */
570
571 /* > \param[in] N */
572 /* > \verbatim */
573 /* >          N is INTEGER */
574 /* >          The order of the matrix.  N >= 0. */
575 /* > \endverbatim */
576 /* > */
577 /* > \param[in] VL */
578 /* > \verbatim */
579 /* >          VL is REAL */
580 /* >          Lower bound of the interval that contains the desired */
581 /* >          eigenvalues. VL < VU. Needed to compute gaps on the left or right */
582 /* >          end of the extremal eigenvalues in the desired RANGE. */
583 /* > \endverbatim */
584 /* > */
585 /* > \param[in] VU */
586 /* > \verbatim */
587 /* >          VU is REAL */
588 /* >          Upper bound of the interval that contains the desired */
589 /* >          eigenvalues. VL < VU. */
590 /* >          Note: VU is currently not used by this implementation of SLARRV, VU is */
591 /* >          passed to SLARRV because it could be used compute gaps on the right end */
592 /* >          of the extremal eigenvalues. However, with not much initial accuracy in */
593 /* >          LAMBDA and VU, the formula can lead to an overestimation of the right gap */
594 /* >          and thus to inadequately early RQI 'convergence'. This is currently */
595 /* >          prevented this by forcing a small right gap. And so it turns out that VU */
596 /* >          is currently not used by this implementation of SLARRV. */
597 /* > \endverbatim */
598 /* > */
599 /* > \param[in,out] D */
600 /* > \verbatim */
601 /* >          D is REAL array, dimension (N) */
602 /* >          On entry, the N diagonal elements of the diagonal matrix D. */
603 /* >          On exit, D may be overwritten. */
604 /* > \endverbatim */
605 /* > */
606 /* > \param[in,out] L */
607 /* > \verbatim */
608 /* >          L is REAL array, dimension (N) */
609 /* >          On entry, the (N-1) subdiagonal elements of the unit */
610 /* >          bidiagonal matrix L are in elements 1 to N-1 of L */
611 /* >          (if the matrix is not split.) At the end of each block */
612 /* >          is stored the corresponding shift as given by SLARRE. */
613 /* >          On exit, L is overwritten. */
614 /* > \endverbatim */
615 /* > */
616 /* > \param[in] PIVMIN */
617 /* > \verbatim */
618 /* >          PIVMIN is REAL */
619 /* >          The minimum pivot allowed in the Sturm sequence. */
620 /* > \endverbatim */
621 /* > */
622 /* > \param[in] ISPLIT */
623 /* > \verbatim */
624 /* >          ISPLIT is INTEGER array, dimension (N) */
625 /* >          The splitting points, at which T breaks up into blocks. */
626 /* >          The first block consists of rows/columns 1 to */
627 /* >          ISPLIT( 1 ), the second of rows/columns ISPLIT( 1 )+1 */
628 /* >          through ISPLIT( 2 ), etc. */
629 /* > \endverbatim */
630 /* > */
631 /* > \param[in] M */
632 /* > \verbatim */
633 /* >          M is INTEGER */
634 /* >          The total number of input eigenvalues.  0 <= M <= N. */
635 /* > \endverbatim */
636 /* > */
637 /* > \param[in] DOL */
638 /* > \verbatim */
639 /* >          DOL is INTEGER */
640 /* > \endverbatim */
641 /* > */
642 /* > \param[in] DOU */
643 /* > \verbatim */
644 /* >          DOU is INTEGER */
645 /* >          If the user wants to compute only selected eigenvectors from all */
646 /* >          the eigenvalues supplied, he can specify an index range DOL:DOU. */
647 /* >          Or else the setting DOL=1, DOU=M should be applied. */
648 /* >          Note that DOL and DOU refer to the order in which the eigenvalues */
649 /* >          are stored in W. */
650 /* >          If the user wants to compute only selected eigenpairs, then */
651 /* >          the columns DOL-1 to DOU+1 of the eigenvector space Z contain the */
652 /* >          computed eigenvectors. All other columns of Z are set to zero. */
653 /* > \endverbatim */
654 /* > */
655 /* > \param[in] MINRGP */
656 /* > \verbatim */
657 /* >          MINRGP is REAL */
658 /* > \endverbatim */
659 /* > */
660 /* > \param[in] RTOL1 */
661 /* > \verbatim */
662 /* >          RTOL1 is REAL */
663 /* > \endverbatim */
664 /* > */
665 /* > \param[in] RTOL2 */
666 /* > \verbatim */
667 /* >          RTOL2 is REAL */
668 /* >           Parameters for bisection. */
669 /* >           An interval [LEFT,RIGHT] has converged if */
670 /* >           RIGHT-LEFT < MAX( RTOL1*GAP, RTOL2*MAX(|LEFT|,|RIGHT|) ) */
671 /* > \endverbatim */
672 /* > */
673 /* > \param[in,out] W */
674 /* > \verbatim */
675 /* >          W is REAL array, dimension (N) */
676 /* >          The first M elements of W contain the APPROXIMATE eigenvalues for */
677 /* >          which eigenvectors are to be computed.  The eigenvalues */
678 /* >          should be grouped by split-off block and ordered from */
679 /* >          smallest to largest within the block ( The output array */
680 /* >          W from SLARRE is expected here ). Furthermore, they are with */
681 /* >          respect to the shift of the corresponding root representation */
682 /* >          for their block. On exit, W holds the eigenvalues of the */
683 /* >          UNshifted matrix. */
684 /* > \endverbatim */
685 /* > */
686 /* > \param[in,out] WERR */
687 /* > \verbatim */
688 /* >          WERR is REAL array, dimension (N) */
689 /* >          The first M elements contain the semiwidth of the uncertainty */
690 /* >          interval of the corresponding eigenvalue in W */
691 /* > \endverbatim */
692 /* > */
693 /* > \param[in,out] WGAP */
694 /* > \verbatim */
695 /* >          WGAP is REAL array, dimension (N) */
696 /* >          The separation from the right neighbor eigenvalue in W. */
697 /* > \endverbatim */
698 /* > */
699 /* > \param[in] IBLOCK */
700 /* > \verbatim */
701 /* >          IBLOCK is INTEGER array, dimension (N) */
702 /* >          The indices of the blocks (submatrices) associated with the */
703 /* >          corresponding eigenvalues in W; IBLOCK(i)=1 if eigenvalue */
704 /* >          W(i) belongs to the first block from the top, =2 if W(i) */
705 /* >          belongs to the second block, etc. */
706 /* > \endverbatim */
707 /* > */
708 /* > \param[in] INDEXW */
709 /* > \verbatim */
710 /* >          INDEXW is INTEGER array, dimension (N) */
711 /* >          The indices of the eigenvalues within each block (submatrix); */
712 /* >          for example, INDEXW(i)= 10 and IBLOCK(i)=2 imply that the */
713 /* >          i-th eigenvalue W(i) is the 10-th eigenvalue in the second block. */
714 /* > \endverbatim */
715 /* > */
716 /* > \param[in] GERS */
717 /* > \verbatim */
718 /* >          GERS is REAL array, dimension (2*N) */
719 /* >          The N Gerschgorin intervals (the i-th Gerschgorin interval */
720 /* >          is (GERS(2*i-1), GERS(2*i)). The Gerschgorin intervals should */
721 /* >          be computed from the original UNshifted matrix. */
722 /* > \endverbatim */
723 /* > */
724 /* > \param[out] Z */
725 /* > \verbatim */
726 /* >          Z is REAL array, dimension (LDZ, f2cmax(1,M) ) */
727 /* >          If INFO = 0, the first M columns of Z contain the */
728 /* >          orthonormal eigenvectors of the matrix T */
729 /* >          corresponding to the input eigenvalues, with the i-th */
730 /* >          column of Z holding the eigenvector associated with W(i). */
731 /* >          Note: the user must ensure that at least f2cmax(1,M) columns are */
732 /* >          supplied in the array Z. */
733 /* > \endverbatim */
734 /* > */
735 /* > \param[in] LDZ */
736 /* > \verbatim */
737 /* >          LDZ is INTEGER */
738 /* >          The leading dimension of the array Z.  LDZ >= 1, and if */
739 /* >          JOBZ = 'V', LDZ >= f2cmax(1,N). */
740 /* > \endverbatim */
741 /* > */
742 /* > \param[out] ISUPPZ */
743 /* > \verbatim */
744 /* >          ISUPPZ is INTEGER array, dimension ( 2*f2cmax(1,M) ) */
745 /* >          The support of the eigenvectors in Z, i.e., the indices */
746 /* >          indicating the nonzero elements in Z. The I-th eigenvector */
747 /* >          is nonzero only in elements ISUPPZ( 2*I-1 ) through */
748 /* >          ISUPPZ( 2*I ). */
749 /* > \endverbatim */
750 /* > */
751 /* > \param[out] WORK */
752 /* > \verbatim */
753 /* >          WORK is REAL array, dimension (12*N) */
754 /* > \endverbatim */
755 /* > */
756 /* > \param[out] IWORK */
757 /* > \verbatim */
758 /* >          IWORK is INTEGER array, dimension (7*N) */
759 /* > \endverbatim */
760 /* > */
761 /* > \param[out] INFO */
762 /* > \verbatim */
763 /* >          INFO is INTEGER */
764 /* >          = 0:  successful exit */
765 /* > */
766 /* >          > 0:  A problem occurred in SLARRV. */
767 /* >          < 0:  One of the called subroutines signaled an internal problem. */
768 /* >                Needs inspection of the corresponding parameter IINFO */
769 /* >                for further information. */
770 /* > */
771 /* >          =-1:  Problem in SLARRB when refining a child's eigenvalues. */
772 /* >          =-2:  Problem in SLARRF when computing the RRR of a child. */
773 /* >                When a child is inside a tight cluster, it can be difficult */
774 /* >                to find an RRR. A partial remedy from the user's point of */
775 /* >                view is to make the parameter MINRGP smaller and recompile. */
776 /* >                However, as the orthogonality of the computed vectors is */
777 /* >                proportional to 1/MINRGP, the user should be aware that */
778 /* >                he might be trading in precision when he decreases MINRGP. */
779 /* >          =-3:  Problem in SLARRB when refining a single eigenvalue */
780 /* >                after the Rayleigh correction was rejected. */
781 /* >          = 5:  The Rayleigh Quotient Iteration failed to converge to */
782 /* >                full accuracy in MAXITR steps. */
783 /* > \endverbatim */
784
785 /*  Authors: */
786 /*  ======== */
787
788 /* > \author Univ. of Tennessee */
789 /* > \author Univ. of California Berkeley */
790 /* > \author Univ. of Colorado Denver */
791 /* > \author NAG Ltd. */
792
793 /* > \date June 2016 */
794
795 /* > \ingroup realOTHERauxiliary */
796
797 /* > \par Contributors: */
798 /*  ================== */
799 /* > */
800 /* > Beresford Parlett, University of California, Berkeley, USA \n */
801 /* > Jim Demmel, University of California, Berkeley, USA \n */
802 /* > Inderjit Dhillon, University of Texas, Austin, USA \n */
803 /* > Osni Marques, LBNL/NERSC, USA \n */
804 /* > Christof Voemel, University of California, Berkeley, USA */
805
806 /*  ===================================================================== */
807 /* Subroutine */ int slarrv_(integer *n, real *vl, real *vu, real *d__, real *
808         l, real *pivmin, integer *isplit, integer *m, integer *dol, integer *
809         dou, real *minrgp, real *rtol1, real *rtol2, real *w, real *werr, 
810         real *wgap, integer *iblock, integer *indexw, real *gers, real *z__, 
811         integer *ldz, integer *isuppz, real *work, integer *iwork, integer *
812         info)
813 {
814     /* System generated locals */
815     integer z_dim1, z_offset, i__1, i__2, i__3, i__4, i__5;
816     real r__1, r__2;
817     logical L__1;
818
819     /* Local variables */
820     integer iend, jblk;
821     real lgap;
822     integer done;
823     real rgap, left;
824     integer wend, iter;
825     real bstw;
826     integer minwsize, itmp1, i__, j, k, p, q, indld;
827     real fudge;
828     integer idone;
829     real sigma;
830     integer iinfo, iindr;
831     real resid;
832     extern /* Subroutine */ int sscal_(integer *, real *, real *, integer *);
833     logical eskip;
834     real right;
835     integer nclus, zfrom;
836     extern /* Subroutine */ int scopy_(integer *, real *, integer *, real *, 
837             integer *);
838     real rqtol;
839     integer iindc1, iindc2, miniwsize;
840     extern /* Subroutine */ int slar1v_(integer *, integer *, integer *, real 
841             *, real *, real *, real *, real *, real *, real *, real *, 
842             logical *, integer *, real *, real *, integer *, integer *, real *
843             , real *, real *, real *);
844     logical stp2ii;
845     real lambda;
846     integer ii;
847     real gl;
848     integer im, in;
849     real gu;
850     integer ibegin, indeig;
851     logical needbs;
852     integer indlld;
853     real sgndef, mingma;
854     extern real slamch_(char *);
855     integer oldien, oldncl, wbegin, negcnt;
856     real spdiam;
857     integer oldcls;
858     real savgap;
859     integer ndepth;
860     real ssigma;
861     logical usedbs;
862     integer iindwk, offset;
863     real gaptol;
864     extern /* Subroutine */ int slarrb_(integer *, real *, real *, integer *, 
865             integer *, real *, real *, integer *, real *, real *, real *, 
866             real *, integer *, real *, real *, integer *, integer *), slarrf_(
867             integer *, real *, real *, real *, integer *, integer *, real *, 
868             real *, real *, real *, real *, real *, real *, real *, real *, 
869             real *, real *, integer *);
870     integer newcls, oldfst, indwrk, windex, oldlst;
871     logical usedrq;
872     integer newfst, newftt, parity, windmn, isupmn, newlst, windpl, zusedl, 
873             newsiz, zusedu, zusedw;
874     real bstres, nrminv;
875     logical tryrqc;
876     integer isupmx;
877     real rqcorr;
878     extern /* Subroutine */ int slaset_(char *, integer *, integer *, real *, 
879             real *, real *, integer *);
880     real gap, eps, tau, tol, tmp;
881     integer zto;
882     real ztz;
883
884
885 /*  -- LAPACK auxiliary routine (version 3.8.0) -- */
886 /*  -- LAPACK is a software package provided by Univ. of Tennessee,    -- */
887 /*  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
888 /*     June 2016 */
889
890
891 /*  ===================================================================== */
892
893     /* Parameter adjustments */
894     --d__;
895     --l;
896     --isplit;
897     --w;
898     --werr;
899     --wgap;
900     --iblock;
901     --indexw;
902     --gers;
903     z_dim1 = *ldz;
904     z_offset = 1 + z_dim1 * 1;
905     z__ -= z_offset;
906     --isuppz;
907     --work;
908     --iwork;
909
910     /* Function Body */
911     *info = 0;
912
913 /*     Quick return if possible */
914
915     if (*n <= 0 || *m <= 0) {
916         return 0;
917     }
918
919 /*     The first N entries of WORK are reserved for the eigenvalues */
920     indld = *n + 1;
921     indlld = (*n << 1) + 1;
922     indwrk = *n * 3 + 1;
923     minwsize = *n * 12;
924     i__1 = minwsize;
925     for (i__ = 1; i__ <= i__1; ++i__) {
926         work[i__] = 0.f;
927 /* L5: */
928     }
929 /*     IWORK(IINDR+1:IINDR+N) hold the twist indices R for the */
930 /*     factorization used to compute the FP vector */
931     iindr = 0;
932 /*     IWORK(IINDC1+1:IINC2+N) are used to store the clusters of the current */
933 /*     layer and the one above. */
934     iindc1 = *n;
935     iindc2 = *n << 1;
936     iindwk = *n * 3 + 1;
937     miniwsize = *n * 7;
938     i__1 = miniwsize;
939     for (i__ = 1; i__ <= i__1; ++i__) {
940         iwork[i__] = 0;
941 /* L10: */
942     }
943     zusedl = 1;
944     if (*dol > 1) {
945 /*        Set lower bound for use of Z */
946         zusedl = *dol - 1;
947     }
948     zusedu = *m;
949     if (*dou < *m) {
950 /*        Set lower bound for use of Z */
951         zusedu = *dou + 1;
952     }
953 /*     The width of the part of Z that is used */
954     zusedw = zusedu - zusedl + 1;
955     slaset_("Full", n, &zusedw, &c_b5, &c_b5, &z__[zusedl * z_dim1 + 1], ldz);
956     eps = slamch_("Precision");
957     rqtol = eps * 2.f;
958
959 /*     Set expert flags for standard code. */
960     tryrqc = TRUE_;
961     if (*dol == 1 && *dou == *m) {
962     } else {
963 /*        Only selected eigenpairs are computed. Since the other evalues */
964 /*        are not refined by RQ iteration, bisection has to compute to full */
965 /*        accuracy. */
966         *rtol1 = eps * 4.f;
967         *rtol2 = eps * 4.f;
968     }
969 /*     The entries WBEGIN:WEND in W, WERR, WGAP correspond to the */
970 /*     desired eigenvalues. The support of the nonzero eigenvector */
971 /*     entries is contained in the interval IBEGIN:IEND. */
972 /*     Remark that if k eigenpairs are desired, then the eigenvectors */
973 /*     are stored in k contiguous columns of Z. */
974 /*     DONE is the number of eigenvectors already computed */
975     done = 0;
976     ibegin = 1;
977     wbegin = 1;
978     i__1 = iblock[*m];
979     for (jblk = 1; jblk <= i__1; ++jblk) {
980         iend = isplit[jblk];
981         sigma = l[iend];
982 /*        Find the eigenvectors of the submatrix indexed IBEGIN */
983 /*        through IEND. */
984         wend = wbegin - 1;
985 L15:
986         if (wend < *m) {
987             if (iblock[wend + 1] == jblk) {
988                 ++wend;
989                 goto L15;
990             }
991         }
992         if (wend < wbegin) {
993             ibegin = iend + 1;
994             goto L170;
995         } else if (wend < *dol || wbegin > *dou) {
996             ibegin = iend + 1;
997             wbegin = wend + 1;
998             goto L170;
999         }
1000 /*        Find local spectral diameter of the block */
1001         gl = gers[(ibegin << 1) - 1];
1002         gu = gers[ibegin * 2];
1003         i__2 = iend;
1004         for (i__ = ibegin + 1; i__ <= i__2; ++i__) {
1005 /* Computing MIN */
1006             r__1 = gers[(i__ << 1) - 1];
1007             gl = f2cmin(r__1,gl);
1008 /* Computing MAX */
1009             r__1 = gers[i__ * 2];
1010             gu = f2cmax(r__1,gu);
1011 /* L20: */
1012         }
1013         spdiam = gu - gl;
1014 /*        OLDIEN is the last index of the previous block */
1015         oldien = ibegin - 1;
1016 /*        Calculate the size of the current block */
1017         in = iend - ibegin + 1;
1018 /*        The number of eigenvalues in the current block */
1019         im = wend - wbegin + 1;
1020 /*        This is for a 1x1 block */
1021         if (ibegin == iend) {
1022             ++done;
1023             z__[ibegin + wbegin * z_dim1] = 1.f;
1024             isuppz[(wbegin << 1) - 1] = ibegin;
1025             isuppz[wbegin * 2] = ibegin;
1026             w[wbegin] += sigma;
1027             work[wbegin] = w[wbegin];
1028             ibegin = iend + 1;
1029             ++wbegin;
1030             goto L170;
1031         }
1032 /*        The desired (shifted) eigenvalues are stored in W(WBEGIN:WEND) */
1033 /*        Note that these can be approximations, in this case, the corresp. */
1034 /*        entries of WERR give the size of the uncertainty interval. */
1035 /*        The eigenvalue approximations will be refined when necessary as */
1036 /*        high relative accuracy is required for the computation of the */
1037 /*        corresponding eigenvectors. */
1038         scopy_(&im, &w[wbegin], &c__1, &work[wbegin], &c__1);
1039 /*        We store in W the eigenvalue approximations w.r.t. the original */
1040 /*        matrix T. */
1041         i__2 = im;
1042         for (i__ = 1; i__ <= i__2; ++i__) {
1043             w[wbegin + i__ - 1] += sigma;
1044 /* L30: */
1045         }
1046 /*        NDEPTH is the current depth of the representation tree */
1047         ndepth = 0;
1048 /*        PARITY is either 1 or 0 */
1049         parity = 1;
1050 /*        NCLUS is the number of clusters for the next level of the */
1051 /*        representation tree, we start with NCLUS = 1 for the root */
1052         nclus = 1;
1053         iwork[iindc1 + 1] = 1;
1054         iwork[iindc1 + 2] = im;
1055 /*        IDONE is the number of eigenvectors already computed in the current */
1056 /*        block */
1057         idone = 0;
1058 /*        loop while( IDONE.LT.IM ) */
1059 /*        generate the representation tree for the current block and */
1060 /*        compute the eigenvectors */
1061 L40:
1062         if (idone < im) {
1063 /*           This is a crude protection against infinitely deep trees */
1064             if (ndepth > *m) {
1065                 *info = -2;
1066                 return 0;
1067             }
1068 /*           breadth first processing of the current level of the representation */
1069 /*           tree: OLDNCL = number of clusters on current level */
1070             oldncl = nclus;
1071 /*           reset NCLUS to count the number of child clusters */
1072             nclus = 0;
1073
1074             parity = 1 - parity;
1075             if (parity == 0) {
1076                 oldcls = iindc1;
1077                 newcls = iindc2;
1078             } else {
1079                 oldcls = iindc2;
1080                 newcls = iindc1;
1081             }
1082 /*           Process the clusters on the current level */
1083             i__2 = oldncl;
1084             for (i__ = 1; i__ <= i__2; ++i__) {
1085                 j = oldcls + (i__ << 1);
1086 /*              OLDFST, OLDLST = first, last index of current cluster. */
1087 /*                               cluster indices start with 1 and are relative */
1088 /*                               to WBEGIN when accessing W, WGAP, WERR, Z */
1089                 oldfst = iwork[j - 1];
1090                 oldlst = iwork[j];
1091                 if (ndepth > 0) {
1092 /*                 Retrieve relatively robust representation (RRR) of cluster */
1093 /*                 that has been computed at the previous level */
1094 /*                 The RRR is stored in Z and overwritten once the eigenvectors */
1095 /*                 have been computed or when the cluster is refined */
1096                     if (*dol == 1 && *dou == *m) {
1097 /*                    Get representation from location of the leftmost evalue */
1098 /*                    of the cluster */
1099                         j = wbegin + oldfst - 1;
1100                     } else {
1101                         if (wbegin + oldfst - 1 < *dol) {
1102 /*                       Get representation from the left end of Z array */
1103                             j = *dol - 1;
1104                         } else if (wbegin + oldfst - 1 > *dou) {
1105 /*                       Get representation from the right end of Z array */
1106                             j = *dou;
1107                         } else {
1108                             j = wbegin + oldfst - 1;
1109                         }
1110                     }
1111                     scopy_(&in, &z__[ibegin + j * z_dim1], &c__1, &d__[ibegin]
1112                             , &c__1);
1113                     i__3 = in - 1;
1114                     scopy_(&i__3, &z__[ibegin + (j + 1) * z_dim1], &c__1, &l[
1115                             ibegin], &c__1);
1116                     sigma = z__[iend + (j + 1) * z_dim1];
1117 /*                 Set the corresponding entries in Z to zero */
1118                     slaset_("Full", &in, &c__2, &c_b5, &c_b5, &z__[ibegin + j 
1119                             * z_dim1], ldz);
1120                 }
1121 /*              Compute DL and DLL of current RRR */
1122                 i__3 = iend - 1;
1123                 for (j = ibegin; j <= i__3; ++j) {
1124                     tmp = d__[j] * l[j];
1125                     work[indld - 1 + j] = tmp;
1126                     work[indlld - 1 + j] = tmp * l[j];
1127 /* L50: */
1128                 }
1129                 if (ndepth > 0) {
1130 /*                 P and Q are index of the first and last eigenvalue to compute */
1131 /*                 within the current block */
1132                     p = indexw[wbegin - 1 + oldfst];
1133                     q = indexw[wbegin - 1 + oldlst];
1134 /*                 Offset for the arrays WORK, WGAP and WERR, i.e., the P-OFFSET */
1135 /*                 through the Q-OFFSET elements of these arrays are to be used. */
1136 /*                  OFFSET = P-OLDFST */
1137                     offset = indexw[wbegin] - 1;
1138 /*                 perform limited bisection (if necessary) to get approximate */
1139 /*                 eigenvalues to the precision needed. */
1140                     slarrb_(&in, &d__[ibegin], &work[indlld + ibegin - 1], &p,
1141                              &q, rtol1, rtol2, &offset, &work[wbegin], &wgap[
1142                             wbegin], &werr[wbegin], &work[indwrk], &iwork[
1143                             iindwk], pivmin, &spdiam, &in, &iinfo);
1144                     if (iinfo != 0) {
1145                         *info = -1;
1146                         return 0;
1147                     }
1148 /*                 We also recompute the extremal gaps. W holds all eigenvalues */
1149 /*                 of the unshifted matrix and must be used for computation */
1150 /*                 of WGAP, the entries of WORK might stem from RRRs with */
1151 /*                 different shifts. The gaps from WBEGIN-1+OLDFST to */
1152 /*                 WBEGIN-1+OLDLST are correctly computed in SLARRB. */
1153 /*                 However, we only allow the gaps to become greater since */
1154 /*                 this is what should happen when we decrease WERR */
1155                     if (oldfst > 1) {
1156 /* Computing MAX */
1157                         r__1 = wgap[wbegin + oldfst - 2], r__2 = w[wbegin + 
1158                                 oldfst - 1] - werr[wbegin + oldfst - 1] - w[
1159                                 wbegin + oldfst - 2] - werr[wbegin + oldfst - 
1160                                 2];
1161                         wgap[wbegin + oldfst - 2] = f2cmax(r__1,r__2);
1162                     }
1163                     if (wbegin + oldlst - 1 < wend) {
1164 /* Computing MAX */
1165                         r__1 = wgap[wbegin + oldlst - 1], r__2 = w[wbegin + 
1166                                 oldlst] - werr[wbegin + oldlst] - w[wbegin + 
1167                                 oldlst - 1] - werr[wbegin + oldlst - 1];
1168                         wgap[wbegin + oldlst - 1] = f2cmax(r__1,r__2);
1169                     }
1170 /*                 Each time the eigenvalues in WORK get refined, we store */
1171 /*                 the newly found approximation with all shifts applied in W */
1172                     i__3 = oldlst;
1173                     for (j = oldfst; j <= i__3; ++j) {
1174                         w[wbegin + j - 1] = work[wbegin + j - 1] + sigma;
1175 /* L53: */
1176                     }
1177                 }
1178 /*              Process the current node. */
1179                 newfst = oldfst;
1180                 i__3 = oldlst;
1181                 for (j = oldfst; j <= i__3; ++j) {
1182                     if (j == oldlst) {
1183 /*                    we are at the right end of the cluster, this is also the */
1184 /*                    boundary of the child cluster */
1185                         newlst = j;
1186                     } else if (wgap[wbegin + j - 1] >= *minrgp * (r__1 = work[
1187                             wbegin + j - 1], abs(r__1))) {
1188 /*                    the right relative gap is big enough, the child cluster */
1189 /*                    (NEWFST,..,NEWLST) is well separated from the following */
1190                         newlst = j;
1191                     } else {
1192 /*                    inside a child cluster, the relative gap is not */
1193 /*                    big enough. */
1194                         goto L140;
1195                     }
1196 /*                 Compute size of child cluster found */
1197                     newsiz = newlst - newfst + 1;
1198 /*                 NEWFTT is the place in Z where the new RRR or the computed */
1199 /*                 eigenvector is to be stored */
1200                     if (*dol == 1 && *dou == *m) {
1201 /*                    Store representation at location of the leftmost evalue */
1202 /*                    of the cluster */
1203                         newftt = wbegin + newfst - 1;
1204                     } else {
1205                         if (wbegin + newfst - 1 < *dol) {
1206 /*                       Store representation at the left end of Z array */
1207                             newftt = *dol - 1;
1208                         } else if (wbegin + newfst - 1 > *dou) {
1209 /*                       Store representation at the right end of Z array */
1210                             newftt = *dou;
1211                         } else {
1212                             newftt = wbegin + newfst - 1;
1213                         }
1214                     }
1215                     if (newsiz > 1) {
1216
1217 /*                    Current child is not a singleton but a cluster. */
1218 /*                    Compute and store new representation of child. */
1219
1220
1221 /*                    Compute left and right cluster gap. */
1222
1223 /*                    LGAP and RGAP are not computed from WORK because */
1224 /*                    the eigenvalue approximations may stem from RRRs */
1225 /*                    different shifts. However, W hold all eigenvalues */
1226 /*                    of the unshifted matrix. Still, the entries in WGAP */
1227 /*                    have to be computed from WORK since the entries */
1228 /*                    in W might be of the same order so that gaps are not */
1229 /*                    exhibited correctly for very close eigenvalues. */
1230                         if (newfst == 1) {
1231 /* Computing MAX */
1232                             r__1 = 0.f, r__2 = w[wbegin] - werr[wbegin] - *vl;
1233                             lgap = f2cmax(r__1,r__2);
1234                         } else {
1235                             lgap = wgap[wbegin + newfst - 2];
1236                         }
1237                         rgap = wgap[wbegin + newlst - 1];
1238
1239 /*                    Compute left- and rightmost eigenvalue of child */
1240 /*                    to high precision in order to shift as close */
1241 /*                    as possible and obtain as large relative gaps */
1242 /*                    as possible */
1243
1244                         for (k = 1; k <= 2; ++k) {
1245                             if (k == 1) {
1246                                 p = indexw[wbegin - 1 + newfst];
1247                             } else {
1248                                 p = indexw[wbegin - 1 + newlst];
1249                             }
1250                             offset = indexw[wbegin] - 1;
1251                             slarrb_(&in, &d__[ibegin], &work[indlld + ibegin 
1252                                     - 1], &p, &p, &rqtol, &rqtol, &offset, &
1253                                     work[wbegin], &wgap[wbegin], &werr[wbegin]
1254                                     , &work[indwrk], &iwork[iindwk], pivmin, &
1255                                     spdiam, &in, &iinfo);
1256 /* L55: */
1257                         }
1258
1259                         if (wbegin + newlst - 1 < *dol || wbegin + newfst - 1 
1260                                 > *dou) {
1261 /*                       if the cluster contains no desired eigenvalues */
1262 /*                       skip the computation of that branch of the rep. tree */
1263
1264 /*                       We could skip before the refinement of the extremal */
1265 /*                       eigenvalues of the child, but then the representation */
1266 /*                       tree could be different from the one when nothing is */
1267 /*                       skipped. For this reason we skip at this place. */
1268                             idone = idone + newlst - newfst + 1;
1269                             goto L139;
1270                         }
1271
1272 /*                    Compute RRR of child cluster. */
1273 /*                    Note that the new RRR is stored in Z */
1274
1275 /*                    SLARRF needs LWORK = 2*N */
1276                         slarrf_(&in, &d__[ibegin], &l[ibegin], &work[indld + 
1277                                 ibegin - 1], &newfst, &newlst, &work[wbegin], 
1278                                 &wgap[wbegin], &werr[wbegin], &spdiam, &lgap, 
1279                                 &rgap, pivmin, &tau, &z__[ibegin + newftt * 
1280                                 z_dim1], &z__[ibegin + (newftt + 1) * z_dim1],
1281                                  &work[indwrk], &iinfo);
1282                         if (iinfo == 0) {
1283 /*                       a new RRR for the cluster was found by SLARRF */
1284 /*                       update shift and store it */
1285                             ssigma = sigma + tau;
1286                             z__[iend + (newftt + 1) * z_dim1] = ssigma;
1287 /*                       WORK() are the midpoints and WERR() the semi-width */
1288 /*                       Note that the entries in W are unchanged. */
1289                             i__4 = newlst;
1290                             for (k = newfst; k <= i__4; ++k) {
1291                                 fudge = eps * 3.f * (r__1 = work[wbegin + k - 
1292                                         1], abs(r__1));
1293                                 work[wbegin + k - 1] -= tau;
1294                                 fudge += eps * 4.f * (r__1 = work[wbegin + k 
1295                                         - 1], abs(r__1));
1296 /*                          Fudge errors */
1297                                 werr[wbegin + k - 1] += fudge;
1298 /*                          Gaps are not fudged. Provided that WERR is small */
1299 /*                          when eigenvalues are close, a zero gap indicates */
1300 /*                          that a new representation is needed for resolving */
1301 /*                          the cluster. A fudge could lead to a wrong decision */
1302 /*                          of judging eigenvalues 'separated' which in */
1303 /*                          reality are not. This could have a negative impact */
1304 /*                          on the orthogonality of the computed eigenvectors. */
1305 /* L116: */
1306                             }
1307                             ++nclus;
1308                             k = newcls + (nclus << 1);
1309                             iwork[k - 1] = newfst;
1310                             iwork[k] = newlst;
1311                         } else {
1312                             *info = -2;
1313                             return 0;
1314                         }
1315                     } else {
1316
1317 /*                    Compute eigenvector of singleton */
1318
1319                         iter = 0;
1320
1321                         tol = log((real) in) * 4.f * eps;
1322
1323                         k = newfst;
1324                         windex = wbegin + k - 1;
1325 /* Computing MAX */
1326                         i__4 = windex - 1;
1327                         windmn = f2cmax(i__4,1);
1328 /* Computing MIN */
1329                         i__4 = windex + 1;
1330                         windpl = f2cmin(i__4,*m);
1331                         lambda = work[windex];
1332                         ++done;
1333 /*                    Check if eigenvector computation is to be skipped */
1334                         if (windex < *dol || windex > *dou) {
1335                             eskip = TRUE_;
1336                             goto L125;
1337                         } else {
1338                             eskip = FALSE_;
1339                         }
1340                         left = work[windex] - werr[windex];
1341                         right = work[windex] + werr[windex];
1342                         indeig = indexw[windex];
1343 /*                    Note that since we compute the eigenpairs for a child, */
1344 /*                    all eigenvalue approximations are w.r.t the same shift. */
1345 /*                    In this case, the entries in WORK should be used for */
1346 /*                    computing the gaps since they exhibit even very small */
1347 /*                    differences in the eigenvalues, as opposed to the */
1348 /*                    entries in W which might "look" the same. */
1349                         if (k == 1) {
1350 /*                       In the case RANGE='I' and with not much initial */
1351 /*                       accuracy in LAMBDA and VL, the formula */
1352 /*                       LGAP = MAX( ZERO, (SIGMA - VL) + LAMBDA ) */
1353 /*                       can lead to an overestimation of the left gap and */
1354 /*                       thus to inadequately early RQI 'convergence'. */
1355 /*                       Prevent this by forcing a small left gap. */
1356 /* Computing MAX */
1357                             r__1 = abs(left), r__2 = abs(right);
1358                             lgap = eps * f2cmax(r__1,r__2);
1359                         } else {
1360                             lgap = wgap[windmn];
1361                         }
1362                         if (k == im) {
1363 /*                       In the case RANGE='I' and with not much initial */
1364 /*                       accuracy in LAMBDA and VU, the formula */
1365 /*                       can lead to an overestimation of the right gap and */
1366 /*                       thus to inadequately early RQI 'convergence'. */
1367 /*                       Prevent this by forcing a small right gap. */
1368 /* Computing MAX */
1369                             r__1 = abs(left), r__2 = abs(right);
1370                             rgap = eps * f2cmax(r__1,r__2);
1371                         } else {
1372                             rgap = wgap[windex];
1373                         }
1374                         gap = f2cmin(lgap,rgap);
1375                         if (k == 1 || k == im) {
1376 /*                       The eigenvector support can become wrong */
1377 /*                       because significant entries could be cut off due to a */
1378 /*                       large GAPTOL parameter in LAR1V. Prevent this. */
1379                             gaptol = 0.f;
1380                         } else {
1381                             gaptol = gap * eps;
1382                         }
1383                         isupmn = in;
1384                         isupmx = 1;
1385 /*                    Update WGAP so that it holds the minimum gap */
1386 /*                    to the left or the right. This is crucial in the */
1387 /*                    case where bisection is used to ensure that the */
1388 /*                    eigenvalue is refined up to the required precision. */
1389 /*                    The correct value is restored afterwards. */
1390                         savgap = wgap[windex];
1391                         wgap[windex] = gap;
1392 /*                    We want to use the Rayleigh Quotient Correction */
1393 /*                    as often as possible since it converges quadratically */
1394 /*                    when we are close enough to the desired eigenvalue. */
1395 /*                    However, the Rayleigh Quotient can have the wrong sign */
1396 /*                    and lead us away from the desired eigenvalue. In this */
1397 /*                    case, the best we can do is to use bisection. */
1398                         usedbs = FALSE_;
1399                         usedrq = FALSE_;
1400 /*                    Bisection is initially turned off unless it is forced */
1401                         needbs = ! tryrqc;
1402 L120:
1403 /*                    Check if bisection should be used to refine eigenvalue */
1404                         if (needbs) {
1405 /*                       Take the bisection as new iterate */
1406                             usedbs = TRUE_;
1407                             itmp1 = iwork[iindr + windex];
1408                             offset = indexw[wbegin] - 1;
1409                             r__1 = eps * 2.f;
1410                             slarrb_(&in, &d__[ibegin], &work[indlld + ibegin 
1411                                     - 1], &indeig, &indeig, &c_b5, &r__1, &
1412                                     offset, &work[wbegin], &wgap[wbegin], &
1413                                     werr[wbegin], &work[indwrk], &iwork[
1414                                     iindwk], pivmin, &spdiam, &itmp1, &iinfo);
1415                             if (iinfo != 0) {
1416                                 *info = -3;
1417                                 return 0;
1418                             }
1419                             lambda = work[windex];
1420 /*                       Reset twist index from inaccurate LAMBDA to */
1421 /*                       force computation of true MINGMA */
1422                             iwork[iindr + windex] = 0;
1423                         }
1424 /*                    Given LAMBDA, compute the eigenvector. */
1425                         L__1 = ! usedbs;
1426                         slar1v_(&in, &c__1, &in, &lambda, &d__[ibegin], &l[
1427                                 ibegin], &work[indld + ibegin - 1], &work[
1428                                 indlld + ibegin - 1], pivmin, &gaptol, &z__[
1429                                 ibegin + windex * z_dim1], &L__1, &negcnt, &
1430                                 ztz, &mingma, &iwork[iindr + windex], &isuppz[
1431                                 (windex << 1) - 1], &nrminv, &resid, &rqcorr, 
1432                                 &work[indwrk]);
1433                         if (iter == 0) {
1434                             bstres = resid;
1435                             bstw = lambda;
1436                         } else if (resid < bstres) {
1437                             bstres = resid;
1438                             bstw = lambda;
1439                         }
1440 /* Computing MIN */
1441                         i__4 = isupmn, i__5 = isuppz[(windex << 1) - 1];
1442                         isupmn = f2cmin(i__4,i__5);
1443 /* Computing MAX */
1444                         i__4 = isupmx, i__5 = isuppz[windex * 2];
1445                         isupmx = f2cmax(i__4,i__5);
1446                         ++iter;
1447 /*                    sin alpha <= |resid|/gap */
1448 /*                    Note that both the residual and the gap are */
1449 /*                    proportional to the matrix, so ||T|| doesn't play */
1450 /*                    a role in the quotient */
1451
1452 /*                    Convergence test for Rayleigh-Quotient iteration */
1453 /*                    (omitted when Bisection has been used) */
1454
1455                         if (resid > tol * gap && abs(rqcorr) > rqtol * abs(
1456                                 lambda) && ! usedbs) {
1457 /*                       We need to check that the RQCORR update doesn't */
1458 /*                       move the eigenvalue away from the desired one and */
1459 /*                       towards a neighbor. -> protection with bisection */
1460                             if (indeig <= negcnt) {
1461 /*                          The wanted eigenvalue lies to the left */
1462                                 sgndef = -1.f;
1463                             } else {
1464 /*                          The wanted eigenvalue lies to the right */
1465                                 sgndef = 1.f;
1466                             }
1467 /*                       We only use the RQCORR if it improves the */
1468 /*                       the iterate reasonably. */
1469                             if (rqcorr * sgndef >= 0.f && lambda + rqcorr <= 
1470                                     right && lambda + rqcorr >= left) {
1471                                 usedrq = TRUE_;
1472 /*                          Store new midpoint of bisection interval in WORK */
1473                                 if (sgndef == 1.f) {
1474 /*                             The current LAMBDA is on the left of the true */
1475 /*                             eigenvalue */
1476                                     left = lambda;
1477 /*                             We prefer to assume that the error estimate */
1478 /*                             is correct. We could make the interval not */
1479 /*                             as a bracket but to be modified if the RQCORR */
1480 /*                             chooses to. In this case, the RIGHT side should */
1481 /*                             be modified as follows: */
1482 /*                              RIGHT = MAX(RIGHT, LAMBDA + RQCORR) */
1483                                 } else {
1484 /*                             The current LAMBDA is on the right of the true */
1485 /*                             eigenvalue */
1486                                     right = lambda;
1487 /*                             See comment about assuming the error estimate is */
1488 /*                             correct above. */
1489 /*                              LEFT = MIN(LEFT, LAMBDA + RQCORR) */
1490                                 }
1491                                 work[windex] = (right + left) * .5f;
1492 /*                          Take RQCORR since it has the correct sign and */
1493 /*                          improves the iterate reasonably */
1494                                 lambda += rqcorr;
1495 /*                          Update width of error interval */
1496                                 werr[windex] = (right - left) * .5f;
1497                             } else {
1498                                 needbs = TRUE_;
1499                             }
1500                             if (right - left < rqtol * abs(lambda)) {
1501 /*                             The eigenvalue is computed to bisection accuracy */
1502 /*                             compute eigenvector and stop */
1503                                 usedbs = TRUE_;
1504                                 goto L120;
1505                             } else if (iter < 10) {
1506                                 goto L120;
1507                             } else if (iter == 10) {
1508                                 needbs = TRUE_;
1509                                 goto L120;
1510                             } else {
1511                                 *info = 5;
1512                                 return 0;
1513                             }
1514                         } else {
1515                             stp2ii = FALSE_;
1516                             if (usedrq && usedbs && bstres <= resid) {
1517                                 lambda = bstw;
1518                                 stp2ii = TRUE_;
1519                             }
1520                             if (stp2ii) {
1521 /*                          improve error angle by second step */
1522                                 L__1 = ! usedbs;
1523                                 slar1v_(&in, &c__1, &in, &lambda, &d__[ibegin]
1524                                         , &l[ibegin], &work[indld + ibegin - 
1525                                         1], &work[indlld + ibegin - 1], 
1526                                         pivmin, &gaptol, &z__[ibegin + windex 
1527                                         * z_dim1], &L__1, &negcnt, &ztz, &
1528                                         mingma, &iwork[iindr + windex], &
1529                                         isuppz[(windex << 1) - 1], &nrminv, &
1530                                         resid, &rqcorr, &work[indwrk]);
1531                             }
1532                             work[windex] = lambda;
1533                         }
1534
1535 /*                    Compute FP-vector support w.r.t. whole matrix */
1536
1537                         isuppz[(windex << 1) - 1] += oldien;
1538                         isuppz[windex * 2] += oldien;
1539                         zfrom = isuppz[(windex << 1) - 1];
1540                         zto = isuppz[windex * 2];
1541                         isupmn += oldien;
1542                         isupmx += oldien;
1543 /*                    Ensure vector is ok if support in the RQI has changed */
1544                         if (isupmn < zfrom) {
1545                             i__4 = zfrom - 1;
1546                             for (ii = isupmn; ii <= i__4; ++ii) {
1547                                 z__[ii + windex * z_dim1] = 0.f;
1548 /* L122: */
1549                             }
1550                         }
1551                         if (isupmx > zto) {
1552                             i__4 = isupmx;
1553                             for (ii = zto + 1; ii <= i__4; ++ii) {
1554                                 z__[ii + windex * z_dim1] = 0.f;
1555 /* L123: */
1556                             }
1557                         }
1558                         i__4 = zto - zfrom + 1;
1559                         sscal_(&i__4, &nrminv, &z__[zfrom + windex * z_dim1], 
1560                                 &c__1);
1561 L125:
1562 /*                    Update W */
1563                         w[windex] = lambda + sigma;
1564 /*                    Recompute the gaps on the left and right */
1565 /*                    But only allow them to become larger and not */
1566 /*                    smaller (which can only happen through "bad" */
1567 /*                    cancellation and doesn't reflect the theory */
1568 /*                    where the initial gaps are underestimated due */
1569 /*                    to WERR being too crude.) */
1570                         if (! eskip) {
1571                             if (k > 1) {
1572 /* Computing MAX */
1573                                 r__1 = wgap[windmn], r__2 = w[windex] - werr[
1574                                         windex] - w[windmn] - werr[windmn];
1575                                 wgap[windmn] = f2cmax(r__1,r__2);
1576                             }
1577                             if (windex < wend) {
1578 /* Computing MAX */
1579                                 r__1 = savgap, r__2 = w[windpl] - werr[windpl]
1580                                          - w[windex] - werr[windex];
1581                                 wgap[windex] = f2cmax(r__1,r__2);
1582                             }
1583                         }
1584                         ++idone;
1585                     }
1586 /*                 here ends the code for the current child */
1587
1588 L139:
1589 /*                 Proceed to any remaining child nodes */
1590                     newfst = j + 1;
1591 L140:
1592                     ;
1593                 }
1594 /* L150: */
1595             }
1596             ++ndepth;
1597             goto L40;
1598         }
1599         ibegin = iend + 1;
1600         wbegin = wend + 1;
1601 L170:
1602         ;
1603     }
1604
1605     return 0;
1606
1607 /*     End of SLARRV */
1608
1609 } /* slarrv_ */
1610