C_LAPACK: Fixes to make it compile with MSVC (#3605)
[platform/upstream/openblas.git] / lapack-netlib / SRC / dlarrv.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 doublereal c_b5 = 0.;
516 static integer c__1 = 1;
517 static integer c__2 = 2;
518
519 /* > \brief \b DLARRV 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 DLARRV + dependencies */
529 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dlarrv.
530 f"> */
531 /* > [TGZ]</a> */
532 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dlarrv.
533 f"> */
534 /* > [ZIP]</a> */
535 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dlarrv.
536 f"> */
537 /* > [TXT]</a> */
538 /* > \endhtmlonly */
539
540 /*  Definition: */
541 /*  =========== */
542
543 /*       SUBROUTINE DLARRV( 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 /*       DOUBLE PRECISION   MINRGP, PIVMIN, RTOL1, RTOL2, VL, VU */
551 /*       INTEGER            IBLOCK( * ), INDEXW( * ), ISPLIT( * ), */
552 /*      $                   ISUPPZ( * ), IWORK( * ) */
553 /*       DOUBLE PRECISION   D( * ), GERS( * ), L( * ), W( * ), WERR( * ), */
554 /*      $                   WGAP( * ), WORK( * ) */
555 /*       DOUBLE PRECISION  Z( LDZ, * ) */
556
557
558 /* > \par Purpose: */
559 /*  ============= */
560 /* > */
561 /* > \verbatim */
562 /* > */
563 /* > DLARRV 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 DLARRE. */
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 DOUBLE PRECISION */
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 DOUBLE PRECISION */
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 DLARRV, VU is */
591 /* >          passed to DLARRV 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 DLARRV. */
597 /* > \endverbatim */
598 /* > */
599 /* > \param[in,out] D */
600 /* > \verbatim */
601 /* >          D is DOUBLE PRECISION 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 DOUBLE PRECISION 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 DLARRE. */
613 /* >          On exit, L is overwritten. */
614 /* > \endverbatim */
615 /* > */
616 /* > \param[in] PIVMIN */
617 /* > \verbatim */
618 /* >          PIVMIN is DOUBLE PRECISION */
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 DOUBLE PRECISION */
658 /* > \endverbatim */
659 /* > */
660 /* > \param[in] RTOL1 */
661 /* > \verbatim */
662 /* >          RTOL1 is DOUBLE PRECISION */
663 /* > \endverbatim */
664 /* > */
665 /* > \param[in] RTOL2 */
666 /* > \verbatim */
667 /* >          RTOL2 is DOUBLE PRECISION */
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 DOUBLE PRECISION 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 DLARRE 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 DOUBLE PRECISION 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 DOUBLE PRECISION 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 DOUBLE PRECISION 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 DOUBLE PRECISION 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 DOUBLE PRECISION 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 DLARRV. */
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 DLARRB when refining a child's eigenvalues. */
772 /* >          =-2:  Problem in DLARRF 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 DLARRB 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 doubleOTHERauxiliary */
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 dlarrv_(integer *n, doublereal *vl, doublereal *vu, 
808         doublereal *d__, doublereal *l, doublereal *pivmin, integer *isplit, 
809         integer *m, integer *dol, integer *dou, doublereal *minrgp, 
810         doublereal *rtol1, doublereal *rtol2, doublereal *w, doublereal *werr,
811          doublereal *wgap, integer *iblock, integer *indexw, doublereal *gers,
812          doublereal *z__, integer *ldz, integer *isuppz, doublereal *work, 
813         integer *iwork, integer *info)
814 {
815     /* System generated locals */
816     integer z_dim1, z_offset, i__1, i__2, i__3, i__4, i__5;
817     doublereal d__1, d__2;
818     logical L__1;
819
820     /* Local variables */
821     integer iend, jblk;
822     doublereal lgap;
823     integer done;
824     doublereal rgap, left;
825     integer wend, iter;
826     doublereal bstw;
827     integer minwsize, itmp1, i__, j, k, p, q;
828     extern /* Subroutine */ int dscal_(integer *, doublereal *, doublereal *, 
829             integer *);
830     integer indld;
831     doublereal fudge;
832     integer idone;
833     doublereal sigma;
834     integer iinfo, iindr;
835     doublereal resid;
836     logical eskip;
837     doublereal right;
838     extern /* Subroutine */ int dcopy_(integer *, doublereal *, integer *, 
839             doublereal *, integer *);
840     integer nclus, zfrom;
841     doublereal rqtol;
842     integer iindc1, iindc2;
843     extern /* Subroutine */ int dlar1v_(integer *, integer *, integer *, 
844             doublereal *, doublereal *, doublereal *, doublereal *, 
845             doublereal *, doublereal *, doublereal *, doublereal *, logical *,
846              integer *, doublereal *, doublereal *, integer *, integer *, 
847             doublereal *, doublereal *, doublereal *, doublereal *);
848     integer miniwsize;
849     logical stp2ii;
850     doublereal lambda;
851     integer ii;
852     doublereal gl;
853     integer im, in;
854     extern doublereal dlamch_(char *);
855     doublereal gu;
856     integer ibegin, indeig;
857     logical needbs;
858     integer indlld;
859     doublereal sgndef, mingma;
860     extern /* Subroutine */ int dlarrb_(integer *, doublereal *, doublereal *,
861              integer *, integer *, doublereal *, doublereal *, integer *, 
862             doublereal *, doublereal *, doublereal *, doublereal *, integer *,
863              doublereal *, doublereal *, integer *, integer *);
864     integer oldien, oldncl, wbegin, negcnt;
865     doublereal spdiam;
866     integer oldcls;
867     doublereal savgap;
868     integer ndepth;
869     doublereal ssigma;
870     extern /* Subroutine */ int dlarrf_(integer *, doublereal *, doublereal *,
871              doublereal *, integer *, integer *, doublereal *, doublereal *, 
872             doublereal *, doublereal *, doublereal *, doublereal *, 
873             doublereal *, doublereal *, doublereal *, doublereal *, 
874             doublereal *, integer *);
875     logical usedbs;
876     integer iindwk, offset;
877     doublereal gaptol;
878     extern /* Subroutine */ int dlaset_(char *, integer *, integer *, 
879             doublereal *, doublereal *, doublereal *, integer *);
880     integer newcls, oldfst, indwrk, windex, oldlst;
881     logical usedrq;
882     integer newfst, newftt, parity, windmn, windpl, isupmn, newlst, zusedl;
883     doublereal bstres;
884     integer newsiz, zusedu, zusedw;
885     doublereal nrminv, rqcorr;
886     logical tryrqc;
887     integer isupmx;
888     doublereal gap, eps, tau, tol, tmp;
889     integer zto;
890     doublereal ztz;
891
892
893 /*  -- LAPACK auxiliary routine (version 3.8.0) -- */
894 /*  -- LAPACK is a software package provided by Univ. of Tennessee,    -- */
895 /*  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
896 /*     June 2016 */
897
898
899 /*  ===================================================================== */
900
901     /* Parameter adjustments */
902     --d__;
903     --l;
904     --isplit;
905     --w;
906     --werr;
907     --wgap;
908     --iblock;
909     --indexw;
910     --gers;
911     z_dim1 = *ldz;
912     z_offset = 1 + z_dim1 * 1;
913     z__ -= z_offset;
914     --isuppz;
915     --work;
916     --iwork;
917
918     /* Function Body */
919     *info = 0;
920
921 /*     Quick return if possible */
922
923     if (*n <= 0 || *m <= 0) {
924         return 0;
925     }
926
927 /*     The first N entries of WORK are reserved for the eigenvalues */
928     indld = *n + 1;
929     indlld = (*n << 1) + 1;
930     indwrk = *n * 3 + 1;
931     minwsize = *n * 12;
932     i__1 = minwsize;
933     for (i__ = 1; i__ <= i__1; ++i__) {
934         work[i__] = 0.;
935 /* L5: */
936     }
937 /*     IWORK(IINDR+1:IINDR+N) hold the twist indices R for the */
938 /*     factorization used to compute the FP vector */
939     iindr = 0;
940 /*     IWORK(IINDC1+1:IINC2+N) are used to store the clusters of the current */
941 /*     layer and the one above. */
942     iindc1 = *n;
943     iindc2 = *n << 1;
944     iindwk = *n * 3 + 1;
945     miniwsize = *n * 7;
946     i__1 = miniwsize;
947     for (i__ = 1; i__ <= i__1; ++i__) {
948         iwork[i__] = 0;
949 /* L10: */
950     }
951     zusedl = 1;
952     if (*dol > 1) {
953 /*        Set lower bound for use of Z */
954         zusedl = *dol - 1;
955     }
956     zusedu = *m;
957     if (*dou < *m) {
958 /*        Set lower bound for use of Z */
959         zusedu = *dou + 1;
960     }
961 /*     The width of the part of Z that is used */
962     zusedw = zusedu - zusedl + 1;
963     dlaset_("Full", n, &zusedw, &c_b5, &c_b5, &z__[zusedl * z_dim1 + 1], ldz);
964     eps = dlamch_("Precision");
965     rqtol = eps * 2.;
966
967 /*     Set expert flags for standard code. */
968     tryrqc = TRUE_;
969     if (*dol == 1 && *dou == *m) {
970     } else {
971 /*        Only selected eigenpairs are computed. Since the other evalues */
972 /*        are not refined by RQ iteration, bisection has to compute to full */
973 /*        accuracy. */
974         *rtol1 = eps * 4.;
975         *rtol2 = eps * 4.;
976     }
977 /*     The entries WBEGIN:WEND in W, WERR, WGAP correspond to the */
978 /*     desired eigenvalues. The support of the nonzero eigenvector */
979 /*     entries is contained in the interval IBEGIN:IEND. */
980 /*     Remark that if k eigenpairs are desired, then the eigenvectors */
981 /*     are stored in k contiguous columns of Z. */
982 /*     DONE is the number of eigenvectors already computed */
983     done = 0;
984     ibegin = 1;
985     wbegin = 1;
986     i__1 = iblock[*m];
987     for (jblk = 1; jblk <= i__1; ++jblk) {
988         iend = isplit[jblk];
989         sigma = l[iend];
990 /*        Find the eigenvectors of the submatrix indexed IBEGIN */
991 /*        through IEND. */
992         wend = wbegin - 1;
993 L15:
994         if (wend < *m) {
995             if (iblock[wend + 1] == jblk) {
996                 ++wend;
997                 goto L15;
998             }
999         }
1000         if (wend < wbegin) {
1001             ibegin = iend + 1;
1002             goto L170;
1003         } else if (wend < *dol || wbegin > *dou) {
1004             ibegin = iend + 1;
1005             wbegin = wend + 1;
1006             goto L170;
1007         }
1008 /*        Find local spectral diameter of the block */
1009         gl = gers[(ibegin << 1) - 1];
1010         gu = gers[ibegin * 2];
1011         i__2 = iend;
1012         for (i__ = ibegin + 1; i__ <= i__2; ++i__) {
1013 /* Computing MIN */
1014             d__1 = gers[(i__ << 1) - 1];
1015             gl = f2cmin(d__1,gl);
1016 /* Computing MAX */
1017             d__1 = gers[i__ * 2];
1018             gu = f2cmax(d__1,gu);
1019 /* L20: */
1020         }
1021         spdiam = gu - gl;
1022 /*        OLDIEN is the last index of the previous block */
1023         oldien = ibegin - 1;
1024 /*        Calculate the size of the current block */
1025         in = iend - ibegin + 1;
1026 /*        The number of eigenvalues in the current block */
1027         im = wend - wbegin + 1;
1028 /*        This is for a 1x1 block */
1029         if (ibegin == iend) {
1030             ++done;
1031             z__[ibegin + wbegin * z_dim1] = 1.;
1032             isuppz[(wbegin << 1) - 1] = ibegin;
1033             isuppz[wbegin * 2] = ibegin;
1034             w[wbegin] += sigma;
1035             work[wbegin] = w[wbegin];
1036             ibegin = iend + 1;
1037             ++wbegin;
1038             goto L170;
1039         }
1040 /*        The desired (shifted) eigenvalues are stored in W(WBEGIN:WEND) */
1041 /*        Note that these can be approximations, in this case, the corresp. */
1042 /*        entries of WERR give the size of the uncertainty interval. */
1043 /*        The eigenvalue approximations will be refined when necessary as */
1044 /*        high relative accuracy is required for the computation of the */
1045 /*        corresponding eigenvectors. */
1046         dcopy_(&im, &w[wbegin], &c__1, &work[wbegin], &c__1);
1047 /*        We store in W the eigenvalue approximations w.r.t. the original */
1048 /*        matrix T. */
1049         i__2 = im;
1050         for (i__ = 1; i__ <= i__2; ++i__) {
1051             w[wbegin + i__ - 1] += sigma;
1052 /* L30: */
1053         }
1054 /*        NDEPTH is the current depth of the representation tree */
1055         ndepth = 0;
1056 /*        PARITY is either 1 or 0 */
1057         parity = 1;
1058 /*        NCLUS is the number of clusters for the next level of the */
1059 /*        representation tree, we start with NCLUS = 1 for the root */
1060         nclus = 1;
1061         iwork[iindc1 + 1] = 1;
1062         iwork[iindc1 + 2] = im;
1063 /*        IDONE is the number of eigenvectors already computed in the current */
1064 /*        block */
1065         idone = 0;
1066 /*        loop while( IDONE.LT.IM ) */
1067 /*        generate the representation tree for the current block and */
1068 /*        compute the eigenvectors */
1069 L40:
1070         if (idone < im) {
1071 /*           This is a crude protection against infinitely deep trees */
1072             if (ndepth > *m) {
1073                 *info = -2;
1074                 return 0;
1075             }
1076 /*           breadth first processing of the current level of the representation */
1077 /*           tree: OLDNCL = number of clusters on current level */
1078             oldncl = nclus;
1079 /*           reset NCLUS to count the number of child clusters */
1080             nclus = 0;
1081
1082             parity = 1 - parity;
1083             if (parity == 0) {
1084                 oldcls = iindc1;
1085                 newcls = iindc2;
1086             } else {
1087                 oldcls = iindc2;
1088                 newcls = iindc1;
1089             }
1090 /*           Process the clusters on the current level */
1091             i__2 = oldncl;
1092             for (i__ = 1; i__ <= i__2; ++i__) {
1093                 j = oldcls + (i__ << 1);
1094 /*              OLDFST, OLDLST = first, last index of current cluster. */
1095 /*                               cluster indices start with 1 and are relative */
1096 /*                               to WBEGIN when accessing W, WGAP, WERR, Z */
1097                 oldfst = iwork[j - 1];
1098                 oldlst = iwork[j];
1099                 if (ndepth > 0) {
1100 /*                 Retrieve relatively robust representation (RRR) of cluster */
1101 /*                 that has been computed at the previous level */
1102 /*                 The RRR is stored in Z and overwritten once the eigenvectors */
1103 /*                 have been computed or when the cluster is refined */
1104                     if (*dol == 1 && *dou == *m) {
1105 /*                    Get representation from location of the leftmost evalue */
1106 /*                    of the cluster */
1107                         j = wbegin + oldfst - 1;
1108                     } else {
1109                         if (wbegin + oldfst - 1 < *dol) {
1110 /*                       Get representation from the left end of Z array */
1111                             j = *dol - 1;
1112                         } else if (wbegin + oldfst - 1 > *dou) {
1113 /*                       Get representation from the right end of Z array */
1114                             j = *dou;
1115                         } else {
1116                             j = wbegin + oldfst - 1;
1117                         }
1118                     }
1119                     dcopy_(&in, &z__[ibegin + j * z_dim1], &c__1, &d__[ibegin]
1120                             , &c__1);
1121                     i__3 = in - 1;
1122                     dcopy_(&i__3, &z__[ibegin + (j + 1) * z_dim1], &c__1, &l[
1123                             ibegin], &c__1);
1124                     sigma = z__[iend + (j + 1) * z_dim1];
1125 /*                 Set the corresponding entries in Z to zero */
1126                     dlaset_("Full", &in, &c__2, &c_b5, &c_b5, &z__[ibegin + j 
1127                             * z_dim1], ldz);
1128                 }
1129 /*              Compute DL and DLL of current RRR */
1130                 i__3 = iend - 1;
1131                 for (j = ibegin; j <= i__3; ++j) {
1132                     tmp = d__[j] * l[j];
1133                     work[indld - 1 + j] = tmp;
1134                     work[indlld - 1 + j] = tmp * l[j];
1135 /* L50: */
1136                 }
1137                 if (ndepth > 0) {
1138 /*                 P and Q are index of the first and last eigenvalue to compute */
1139 /*                 within the current block */
1140                     p = indexw[wbegin - 1 + oldfst];
1141                     q = indexw[wbegin - 1 + oldlst];
1142 /*                 Offset for the arrays WORK, WGAP and WERR, i.e., the P-OFFSET */
1143 /*                 through the Q-OFFSET elements of these arrays are to be used. */
1144 /*                  OFFSET = P-OLDFST */
1145                     offset = indexw[wbegin] - 1;
1146 /*                 perform limited bisection (if necessary) to get approximate */
1147 /*                 eigenvalues to the precision needed. */
1148                     dlarrb_(&in, &d__[ibegin], &work[indlld + ibegin - 1], &p,
1149                              &q, rtol1, rtol2, &offset, &work[wbegin], &wgap[
1150                             wbegin], &werr[wbegin], &work[indwrk], &iwork[
1151                             iindwk], pivmin, &spdiam, &in, &iinfo);
1152                     if (iinfo != 0) {
1153                         *info = -1;
1154                         return 0;
1155                     }
1156 /*                 We also recompute the extremal gaps. W holds all eigenvalues */
1157 /*                 of the unshifted matrix and must be used for computation */
1158 /*                 of WGAP, the entries of WORK might stem from RRRs with */
1159 /*                 different shifts. The gaps from WBEGIN-1+OLDFST to */
1160 /*                 WBEGIN-1+OLDLST are correctly computed in DLARRB. */
1161 /*                 However, we only allow the gaps to become greater since */
1162 /*                 this is what should happen when we decrease WERR */
1163                     if (oldfst > 1) {
1164 /* Computing MAX */
1165                         d__1 = wgap[wbegin + oldfst - 2], d__2 = w[wbegin + 
1166                                 oldfst - 1] - werr[wbegin + oldfst - 1] - w[
1167                                 wbegin + oldfst - 2] - werr[wbegin + oldfst - 
1168                                 2];
1169                         wgap[wbegin + oldfst - 2] = f2cmax(d__1,d__2);
1170                     }
1171                     if (wbegin + oldlst - 1 < wend) {
1172 /* Computing MAX */
1173                         d__1 = wgap[wbegin + oldlst - 1], d__2 = w[wbegin + 
1174                                 oldlst] - werr[wbegin + oldlst] - w[wbegin + 
1175                                 oldlst - 1] - werr[wbegin + oldlst - 1];
1176                         wgap[wbegin + oldlst - 1] = f2cmax(d__1,d__2);
1177                     }
1178 /*                 Each time the eigenvalues in WORK get refined, we store */
1179 /*                 the newly found approximation with all shifts applied in W */
1180                     i__3 = oldlst;
1181                     for (j = oldfst; j <= i__3; ++j) {
1182                         w[wbegin + j - 1] = work[wbegin + j - 1] + sigma;
1183 /* L53: */
1184                     }
1185                 }
1186 /*              Process the current node. */
1187                 newfst = oldfst;
1188                 i__3 = oldlst;
1189                 for (j = oldfst; j <= i__3; ++j) {
1190                     if (j == oldlst) {
1191 /*                    we are at the right end of the cluster, this is also the */
1192 /*                    boundary of the child cluster */
1193                         newlst = j;
1194                     } else if (wgap[wbegin + j - 1] >= *minrgp * (d__1 = work[
1195                             wbegin + j - 1], abs(d__1))) {
1196 /*                    the right relative gap is big enough, the child cluster */
1197 /*                    (NEWFST,..,NEWLST) is well separated from the following */
1198                         newlst = j;
1199                     } else {
1200 /*                    inside a child cluster, the relative gap is not */
1201 /*                    big enough. */
1202                         goto L140;
1203                     }
1204 /*                 Compute size of child cluster found */
1205                     newsiz = newlst - newfst + 1;
1206 /*                 NEWFTT is the place in Z where the new RRR or the computed */
1207 /*                 eigenvector is to be stored */
1208                     if (*dol == 1 && *dou == *m) {
1209 /*                    Store representation at location of the leftmost evalue */
1210 /*                    of the cluster */
1211                         newftt = wbegin + newfst - 1;
1212                     } else {
1213                         if (wbegin + newfst - 1 < *dol) {
1214 /*                       Store representation at the left end of Z array */
1215                             newftt = *dol - 1;
1216                         } else if (wbegin + newfst - 1 > *dou) {
1217 /*                       Store representation at the right end of Z array */
1218                             newftt = *dou;
1219                         } else {
1220                             newftt = wbegin + newfst - 1;
1221                         }
1222                     }
1223                     if (newsiz > 1) {
1224
1225 /*                    Current child is not a singleton but a cluster. */
1226 /*                    Compute and store new representation of child. */
1227
1228
1229 /*                    Compute left and right cluster gap. */
1230
1231 /*                    LGAP and RGAP are not computed from WORK because */
1232 /*                    the eigenvalue approximations may stem from RRRs */
1233 /*                    different shifts. However, W hold all eigenvalues */
1234 /*                    of the unshifted matrix. Still, the entries in WGAP */
1235 /*                    have to be computed from WORK since the entries */
1236 /*                    in W might be of the same order so that gaps are not */
1237 /*                    exhibited correctly for very close eigenvalues. */
1238                         if (newfst == 1) {
1239 /* Computing MAX */
1240                             d__1 = 0., d__2 = w[wbegin] - werr[wbegin] - *vl;
1241                             lgap = f2cmax(d__1,d__2);
1242                         } else {
1243                             lgap = wgap[wbegin + newfst - 2];
1244                         }
1245                         rgap = wgap[wbegin + newlst - 1];
1246
1247 /*                    Compute left- and rightmost eigenvalue of child */
1248 /*                    to high precision in order to shift as close */
1249 /*                    as possible and obtain as large relative gaps */
1250 /*                    as possible */
1251
1252                         for (k = 1; k <= 2; ++k) {
1253                             if (k == 1) {
1254                                 p = indexw[wbegin - 1 + newfst];
1255                             } else {
1256                                 p = indexw[wbegin - 1 + newlst];
1257                             }
1258                             offset = indexw[wbegin] - 1;
1259                             dlarrb_(&in, &d__[ibegin], &work[indlld + ibegin 
1260                                     - 1], &p, &p, &rqtol, &rqtol, &offset, &
1261                                     work[wbegin], &wgap[wbegin], &werr[wbegin]
1262                                     , &work[indwrk], &iwork[iindwk], pivmin, &
1263                                     spdiam, &in, &iinfo);
1264 /* L55: */
1265                         }
1266
1267                         if (wbegin + newlst - 1 < *dol || wbegin + newfst - 1 
1268                                 > *dou) {
1269 /*                       if the cluster contains no desired eigenvalues */
1270 /*                       skip the computation of that branch of the rep. tree */
1271
1272 /*                       We could skip before the refinement of the extremal */
1273 /*                       eigenvalues of the child, but then the representation */
1274 /*                       tree could be different from the one when nothing is */
1275 /*                       skipped. For this reason we skip at this place. */
1276                             idone = idone + newlst - newfst + 1;
1277                             goto L139;
1278                         }
1279
1280 /*                    Compute RRR of child cluster. */
1281 /*                    Note that the new RRR is stored in Z */
1282
1283 /*                    DLARRF needs LWORK = 2*N */
1284                         dlarrf_(&in, &d__[ibegin], &l[ibegin], &work[indld + 
1285                                 ibegin - 1], &newfst, &newlst, &work[wbegin], 
1286                                 &wgap[wbegin], &werr[wbegin], &spdiam, &lgap, 
1287                                 &rgap, pivmin, &tau, &z__[ibegin + newftt * 
1288                                 z_dim1], &z__[ibegin + (newftt + 1) * z_dim1],
1289                                  &work[indwrk], &iinfo);
1290                         if (iinfo == 0) {
1291 /*                       a new RRR for the cluster was found by DLARRF */
1292 /*                       update shift and store it */
1293                             ssigma = sigma + tau;
1294                             z__[iend + (newftt + 1) * z_dim1] = ssigma;
1295 /*                       WORK() are the midpoints and WERR() the semi-width */
1296 /*                       Note that the entries in W are unchanged. */
1297                             i__4 = newlst;
1298                             for (k = newfst; k <= i__4; ++k) {
1299                                 fudge = eps * 3. * (d__1 = work[wbegin + k - 
1300                                         1], abs(d__1));
1301                                 work[wbegin + k - 1] -= tau;
1302                                 fudge += eps * 4. * (d__1 = work[wbegin + k - 
1303                                         1], abs(d__1));
1304 /*                          Fudge errors */
1305                                 werr[wbegin + k - 1] += fudge;
1306 /*                          Gaps are not fudged. Provided that WERR is small */
1307 /*                          when eigenvalues are close, a zero gap indicates */
1308 /*                          that a new representation is needed for resolving */
1309 /*                          the cluster. A fudge could lead to a wrong decision */
1310 /*                          of judging eigenvalues 'separated' which in */
1311 /*                          reality are not. This could have a negative impact */
1312 /*                          on the orthogonality of the computed eigenvectors. */
1313 /* L116: */
1314                             }
1315                             ++nclus;
1316                             k = newcls + (nclus << 1);
1317                             iwork[k - 1] = newfst;
1318                             iwork[k] = newlst;
1319                         } else {
1320                             *info = -2;
1321                             return 0;
1322                         }
1323                     } else {
1324
1325 /*                    Compute eigenvector of singleton */
1326
1327                         iter = 0;
1328
1329                         tol = log((doublereal) in) * 4. * eps;
1330
1331                         k = newfst;
1332                         windex = wbegin + k - 1;
1333 /* Computing MAX */
1334                         i__4 = windex - 1;
1335                         windmn = f2cmax(i__4,1);
1336 /* Computing MIN */
1337                         i__4 = windex + 1;
1338                         windpl = f2cmin(i__4,*m);
1339                         lambda = work[windex];
1340                         ++done;
1341 /*                    Check if eigenvector computation is to be skipped */
1342                         if (windex < *dol || windex > *dou) {
1343                             eskip = TRUE_;
1344                             goto L125;
1345                         } else {
1346                             eskip = FALSE_;
1347                         }
1348                         left = work[windex] - werr[windex];
1349                         right = work[windex] + werr[windex];
1350                         indeig = indexw[windex];
1351 /*                    Note that since we compute the eigenpairs for a child, */
1352 /*                    all eigenvalue approximations are w.r.t the same shift. */
1353 /*                    In this case, the entries in WORK should be used for */
1354 /*                    computing the gaps since they exhibit even very small */
1355 /*                    differences in the eigenvalues, as opposed to the */
1356 /*                    entries in W which might "look" the same. */
1357                         if (k == 1) {
1358 /*                       In the case RANGE='I' and with not much initial */
1359 /*                       accuracy in LAMBDA and VL, the formula */
1360 /*                       LGAP = MAX( ZERO, (SIGMA - VL) + LAMBDA ) */
1361 /*                       can lead to an overestimation of the left gap and */
1362 /*                       thus to inadequately early RQI 'convergence'. */
1363 /*                       Prevent this by forcing a small left gap. */
1364 /* Computing MAX */
1365                             d__1 = abs(left), d__2 = abs(right);
1366                             lgap = eps * f2cmax(d__1,d__2);
1367                         } else {
1368                             lgap = wgap[windmn];
1369                         }
1370                         if (k == im) {
1371 /*                       In the case RANGE='I' and with not much initial */
1372 /*                       accuracy in LAMBDA and VU, the formula */
1373 /*                       can lead to an overestimation of the right gap and */
1374 /*                       thus to inadequately early RQI 'convergence'. */
1375 /*                       Prevent this by forcing a small right gap. */
1376 /* Computing MAX */
1377                             d__1 = abs(left), d__2 = abs(right);
1378                             rgap = eps * f2cmax(d__1,d__2);
1379                         } else {
1380                             rgap = wgap[windex];
1381                         }
1382                         gap = f2cmin(lgap,rgap);
1383                         if (k == 1 || k == im) {
1384 /*                       The eigenvector support can become wrong */
1385 /*                       because significant entries could be cut off due to a */
1386 /*                       large GAPTOL parameter in LAR1V. Prevent this. */
1387                             gaptol = 0.;
1388                         } else {
1389                             gaptol = gap * eps;
1390                         }
1391                         isupmn = in;
1392                         isupmx = 1;
1393 /*                    Update WGAP so that it holds the minimum gap */
1394 /*                    to the left or the right. This is crucial in the */
1395 /*                    case where bisection is used to ensure that the */
1396 /*                    eigenvalue is refined up to the required precision. */
1397 /*                    The correct value is restored afterwards. */
1398                         savgap = wgap[windex];
1399                         wgap[windex] = gap;
1400 /*                    We want to use the Rayleigh Quotient Correction */
1401 /*                    as often as possible since it converges quadratically */
1402 /*                    when we are close enough to the desired eigenvalue. */
1403 /*                    However, the Rayleigh Quotient can have the wrong sign */
1404 /*                    and lead us away from the desired eigenvalue. In this */
1405 /*                    case, the best we can do is to use bisection. */
1406                         usedbs = FALSE_;
1407                         usedrq = FALSE_;
1408 /*                    Bisection is initially turned off unless it is forced */
1409                         needbs = ! tryrqc;
1410 L120:
1411 /*                    Check if bisection should be used to refine eigenvalue */
1412                         if (needbs) {
1413 /*                       Take the bisection as new iterate */
1414                             usedbs = TRUE_;
1415                             itmp1 = iwork[iindr + windex];
1416                             offset = indexw[wbegin] - 1;
1417                             d__1 = eps * 2.;
1418                             dlarrb_(&in, &d__[ibegin], &work[indlld + ibegin 
1419                                     - 1], &indeig, &indeig, &c_b5, &d__1, &
1420                                     offset, &work[wbegin], &wgap[wbegin], &
1421                                     werr[wbegin], &work[indwrk], &iwork[
1422                                     iindwk], pivmin, &spdiam, &itmp1, &iinfo);
1423                             if (iinfo != 0) {
1424                                 *info = -3;
1425                                 return 0;
1426                             }
1427                             lambda = work[windex];
1428 /*                       Reset twist index from inaccurate LAMBDA to */
1429 /*                       force computation of true MINGMA */
1430                             iwork[iindr + windex] = 0;
1431                         }
1432 /*                    Given LAMBDA, compute the eigenvector. */
1433                         L__1 = ! usedbs;
1434                         dlar1v_(&in, &c__1, &in, &lambda, &d__[ibegin], &l[
1435                                 ibegin], &work[indld + ibegin - 1], &work[
1436                                 indlld + ibegin - 1], pivmin, &gaptol, &z__[
1437                                 ibegin + windex * z_dim1], &L__1, &negcnt, &
1438                                 ztz, &mingma, &iwork[iindr + windex], &isuppz[
1439                                 (windex << 1) - 1], &nrminv, &resid, &rqcorr, 
1440                                 &work[indwrk]);
1441                         if (iter == 0) {
1442                             bstres = resid;
1443                             bstw = lambda;
1444                         } else if (resid < bstres) {
1445                             bstres = resid;
1446                             bstw = lambda;
1447                         }
1448 /* Computing MIN */
1449                         i__4 = isupmn, i__5 = isuppz[(windex << 1) - 1];
1450                         isupmn = f2cmin(i__4,i__5);
1451 /* Computing MAX */
1452                         i__4 = isupmx, i__5 = isuppz[windex * 2];
1453                         isupmx = f2cmax(i__4,i__5);
1454                         ++iter;
1455 /*                    sin alpha <= |resid|/gap */
1456 /*                    Note that both the residual and the gap are */
1457 /*                    proportional to the matrix, so ||T|| doesn't play */
1458 /*                    a role in the quotient */
1459
1460 /*                    Convergence test for Rayleigh-Quotient iteration */
1461 /*                    (omitted when Bisection has been used) */
1462
1463                         if (resid > tol * gap && abs(rqcorr) > rqtol * abs(
1464                                 lambda) && ! usedbs) {
1465 /*                       We need to check that the RQCORR update doesn't */
1466 /*                       move the eigenvalue away from the desired one and */
1467 /*                       towards a neighbor. -> protection with bisection */
1468                             if (indeig <= negcnt) {
1469 /*                          The wanted eigenvalue lies to the left */
1470                                 sgndef = -1.;
1471                             } else {
1472 /*                          The wanted eigenvalue lies to the right */
1473                                 sgndef = 1.;
1474                             }
1475 /*                       We only use the RQCORR if it improves the */
1476 /*                       the iterate reasonably. */
1477                             if (rqcorr * sgndef >= 0. && lambda + rqcorr <= 
1478                                     right && lambda + rqcorr >= left) {
1479                                 usedrq = TRUE_;
1480 /*                          Store new midpoint of bisection interval in WORK */
1481                                 if (sgndef == 1.) {
1482 /*                             The current LAMBDA is on the left of the true */
1483 /*                             eigenvalue */
1484                                     left = lambda;
1485 /*                             We prefer to assume that the error estimate */
1486 /*                             is correct. We could make the interval not */
1487 /*                             as a bracket but to be modified if the RQCORR */
1488 /*                             chooses to. In this case, the RIGHT side should */
1489 /*                             be modified as follows: */
1490 /*                              RIGHT = MAX(RIGHT, LAMBDA + RQCORR) */
1491                                 } else {
1492 /*                             The current LAMBDA is on the right of the true */
1493 /*                             eigenvalue */
1494                                     right = lambda;
1495 /*                             See comment about assuming the error estimate is */
1496 /*                             correct above. */
1497 /*                              LEFT = MIN(LEFT, LAMBDA + RQCORR) */
1498                                 }
1499                                 work[windex] = (right + left) * .5;
1500 /*                          Take RQCORR since it has the correct sign and */
1501 /*                          improves the iterate reasonably */
1502                                 lambda += rqcorr;
1503 /*                          Update width of error interval */
1504                                 werr[windex] = (right - left) * .5;
1505                             } else {
1506                                 needbs = TRUE_;
1507                             }
1508                             if (right - left < rqtol * abs(lambda)) {
1509 /*                             The eigenvalue is computed to bisection accuracy */
1510 /*                             compute eigenvector and stop */
1511                                 usedbs = TRUE_;
1512                                 goto L120;
1513                             } else if (iter < 10) {
1514                                 goto L120;
1515                             } else if (iter == 10) {
1516                                 needbs = TRUE_;
1517                                 goto L120;
1518                             } else {
1519                                 *info = 5;
1520                                 return 0;
1521                             }
1522                         } else {
1523                             stp2ii = FALSE_;
1524                             if (usedrq && usedbs && bstres <= resid) {
1525                                 lambda = bstw;
1526                                 stp2ii = TRUE_;
1527                             }
1528                             if (stp2ii) {
1529 /*                          improve error angle by second step */
1530                                 L__1 = ! usedbs;
1531                                 dlar1v_(&in, &c__1, &in, &lambda, &d__[ibegin]
1532                                         , &l[ibegin], &work[indld + ibegin - 
1533                                         1], &work[indlld + ibegin - 1], 
1534                                         pivmin, &gaptol, &z__[ibegin + windex 
1535                                         * z_dim1], &L__1, &negcnt, &ztz, &
1536                                         mingma, &iwork[iindr + windex], &
1537                                         isuppz[(windex << 1) - 1], &nrminv, &
1538                                         resid, &rqcorr, &work[indwrk]);
1539                             }
1540                             work[windex] = lambda;
1541                         }
1542
1543 /*                    Compute FP-vector support w.r.t. whole matrix */
1544
1545                         isuppz[(windex << 1) - 1] += oldien;
1546                         isuppz[windex * 2] += oldien;
1547                         zfrom = isuppz[(windex << 1) - 1];
1548                         zto = isuppz[windex * 2];
1549                         isupmn += oldien;
1550                         isupmx += oldien;
1551 /*                    Ensure vector is ok if support in the RQI has changed */
1552                         if (isupmn < zfrom) {
1553                             i__4 = zfrom - 1;
1554                             for (ii = isupmn; ii <= i__4; ++ii) {
1555                                 z__[ii + windex * z_dim1] = 0.;
1556 /* L122: */
1557                             }
1558                         }
1559                         if (isupmx > zto) {
1560                             i__4 = isupmx;
1561                             for (ii = zto + 1; ii <= i__4; ++ii) {
1562                                 z__[ii + windex * z_dim1] = 0.;
1563 /* L123: */
1564                             }
1565                         }
1566                         i__4 = zto - zfrom + 1;
1567                         dscal_(&i__4, &nrminv, &z__[zfrom + windex * z_dim1], 
1568                                 &c__1);
1569 L125:
1570 /*                    Update W */
1571                         w[windex] = lambda + sigma;
1572 /*                    Recompute the gaps on the left and right */
1573 /*                    But only allow them to become larger and not */
1574 /*                    smaller (which can only happen through "bad" */
1575 /*                    cancellation and doesn't reflect the theory */
1576 /*                    where the initial gaps are underestimated due */
1577 /*                    to WERR being too crude.) */
1578                         if (! eskip) {
1579                             if (k > 1) {
1580 /* Computing MAX */
1581                                 d__1 = wgap[windmn], d__2 = w[windex] - werr[
1582                                         windex] - w[windmn] - werr[windmn];
1583                                 wgap[windmn] = f2cmax(d__1,d__2);
1584                             }
1585                             if (windex < wend) {
1586 /* Computing MAX */
1587                                 d__1 = savgap, d__2 = w[windpl] - werr[windpl]
1588                                          - w[windex] - werr[windex];
1589                                 wgap[windex] = f2cmax(d__1,d__2);
1590                             }
1591                         }
1592                         ++idone;
1593                     }
1594 /*                 here ends the code for the current child */
1595
1596 L139:
1597 /*                 Proceed to any remaining child nodes */
1598                     newfst = j + 1;
1599 L140:
1600                     ;
1601                 }
1602 /* L150: */
1603             }
1604             ++ndepth;
1605             goto L40;
1606         }
1607         ibegin = iend + 1;
1608         wbegin = wend + 1;
1609 L170:
1610         ;
1611     }
1612
1613     return 0;
1614
1615 /*     End of DLARRV */
1616
1617 } /* dlarrv_ */
1618