C_LAPACK: Fixes to make it compile with MSVC (#3605)
[platform/upstream/openblas.git] / lapack-netlib / SRC / zstemr.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]/Cd(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 integer c__1 = 1;
516 static doublereal c_b18 = .001;
517
518 /* > \brief \b ZSTEMR */
519
520 /*  =========== DOCUMENTATION =========== */
521
522 /* Online html documentation available at */
523 /*            http://www.netlib.org/lapack/explore-html/ */
524
525 /* > \htmlonly */
526 /* > Download ZSTEMR + dependencies */
527 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zstemr.
528 f"> */
529 /* > [TGZ]</a> */
530 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zstemr.
531 f"> */
532 /* > [ZIP]</a> */
533 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zstemr.
534 f"> */
535 /* > [TXT]</a> */
536 /* > \endhtmlonly */
537
538 /*  Definition: */
539 /*  =========== */
540
541 /*       SUBROUTINE ZSTEMR( JOBZ, RANGE, N, D, E, VL, VU, IL, IU, */
542 /*                          M, W, Z, LDZ, NZC, ISUPPZ, TRYRAC, WORK, LWORK, */
543 /*                          IWORK, LIWORK, INFO ) */
544
545 /*       CHARACTER          JOBZ, RANGE */
546 /*       LOGICAL            TRYRAC */
547 /*       INTEGER            IL, INFO, IU, LDZ, NZC, LIWORK, LWORK, M, N */
548 /*       DOUBLE PRECISION VL, VU */
549 /*       INTEGER            ISUPPZ( * ), IWORK( * ) */
550 /*       DOUBLE PRECISION   D( * ), E( * ), W( * ), WORK( * ) */
551 /*       COMPLEX*16         Z( LDZ, * ) */
552
553
554 /* > \par Purpose: */
555 /*  ============= */
556 /* > */
557 /* > \verbatim */
558 /* > */
559 /* > ZSTEMR computes selected eigenvalues and, optionally, eigenvectors */
560 /* > of a real symmetric tridiagonal matrix T. Any such unreduced matrix has */
561 /* > a well defined set of pairwise different real eigenvalues, the corresponding */
562 /* > real eigenvectors are pairwise orthogonal. */
563 /* > */
564 /* > The spectrum may be computed either completely or partially by specifying */
565 /* > either an interval (VL,VU] or a range of indices IL:IU for the desired */
566 /* > eigenvalues. */
567 /* > */
568 /* > Depending on the number of desired eigenvalues, these are computed either */
569 /* > by bisection or the dqds algorithm. Numerically orthogonal eigenvectors are */
570 /* > computed by the use of various suitable L D L^T factorizations near clusters */
571 /* > of close eigenvalues (referred to as RRRs, Relatively Robust */
572 /* > Representations). An informal sketch of the algorithm follows. */
573 /* > */
574 /* > For each unreduced block (submatrix) of T, */
575 /* >    (a) Compute T - sigma I  = L D L^T, so that L and D */
576 /* >        define all the wanted eigenvalues to high relative accuracy. */
577 /* >        This means that small relative changes in the entries of D and L */
578 /* >        cause only small relative changes in the eigenvalues and */
579 /* >        eigenvectors. The standard (unfactored) representation of the */
580 /* >        tridiagonal matrix T does not have this property in general. */
581 /* >    (b) Compute the eigenvalues to suitable accuracy. */
582 /* >        If the eigenvectors are desired, the algorithm attains full */
583 /* >        accuracy of the computed eigenvalues only right before */
584 /* >        the corresponding vectors have to be computed, see steps c) and d). */
585 /* >    (c) For each cluster of close eigenvalues, select a new */
586 /* >        shift close to the cluster, find a new factorization, and refine */
587 /* >        the shifted eigenvalues to suitable accuracy. */
588 /* >    (d) For each eigenvalue with a large enough relative separation compute */
589 /* >        the corresponding eigenvector by forming a rank revealing twisted */
590 /* >        factorization. Go back to (c) for any clusters that remain. */
591 /* > */
592 /* > For more details, see: */
593 /* > - Inderjit S. Dhillon and Beresford N. Parlett: "Multiple representations */
594 /* >   to compute orthogonal eigenvectors of symmetric tridiagonal matrices," */
595 /* >   Linear Algebra and its Applications, 387(1), pp. 1-28, August 2004. */
596 /* > - Inderjit Dhillon and Beresford Parlett: "Orthogonal Eigenvectors and */
597 /* >   Relative Gaps," SIAM Journal on Matrix Analysis and Applications, Vol. 25, */
598 /* >   2004.  Also LAPACK Working Note 154. */
599 /* > - Inderjit Dhillon: "A new O(n^2) algorithm for the symmetric */
600 /* >   tridiagonal eigenvalue/eigenvector problem", */
601 /* >   Computer Science Division Technical Report No. UCB/CSD-97-971, */
602 /* >   UC Berkeley, May 1997. */
603 /* > */
604 /* > Further Details */
605 /* > 1.ZSTEMR works only on machines which follow IEEE-754 */
606 /* > floating-point standard in their handling of infinities and NaNs. */
607 /* > This permits the use of efficient inner loops avoiding a check for */
608 /* > zero divisors. */
609 /* > */
610 /* > 2. LAPACK routines can be used to reduce a complex Hermitean matrix to */
611 /* > real symmetric tridiagonal form. */
612 /* > */
613 /* > (Any complex Hermitean tridiagonal matrix has real values on its diagonal */
614 /* > and potentially complex numbers on its off-diagonals. By applying a */
615 /* > similarity transform with an appropriate diagonal matrix */
616 /* > diag(1,e^{i \phy_1}, ... , e^{i \phy_{n-1}}), the complex Hermitean */
617 /* > matrix can be transformed into a real symmetric matrix and complex */
618 /* > arithmetic can be entirely avoided.) */
619 /* > */
620 /* > While the eigenvectors of the real symmetric tridiagonal matrix are real, */
621 /* > the eigenvectors of original complex Hermitean matrix have complex entries */
622 /* > in general. */
623 /* > Since LAPACK drivers overwrite the matrix data with the eigenvectors, */
624 /* > ZSTEMR accepts complex workspace to facilitate interoperability */
625 /* > with ZUNMTR or ZUPMTR. */
626 /* > \endverbatim */
627
628 /*  Arguments: */
629 /*  ========== */
630
631 /* > \param[in] JOBZ */
632 /* > \verbatim */
633 /* >          JOBZ is CHARACTER*1 */
634 /* >          = 'N':  Compute eigenvalues only; */
635 /* >          = 'V':  Compute eigenvalues and eigenvectors. */
636 /* > \endverbatim */
637 /* > */
638 /* > \param[in] RANGE */
639 /* > \verbatim */
640 /* >          RANGE is CHARACTER*1 */
641 /* >          = 'A': all eigenvalues will be found. */
642 /* >          = 'V': all eigenvalues in the half-open interval (VL,VU] */
643 /* >                 will be found. */
644 /* >          = 'I': the IL-th through IU-th eigenvalues will be found. */
645 /* > \endverbatim */
646 /* > */
647 /* > \param[in] N */
648 /* > \verbatim */
649 /* >          N is INTEGER */
650 /* >          The order of the matrix.  N >= 0. */
651 /* > \endverbatim */
652 /* > */
653 /* > \param[in,out] D */
654 /* > \verbatim */
655 /* >          D is DOUBLE PRECISION array, dimension (N) */
656 /* >          On entry, the N diagonal elements of the tridiagonal matrix */
657 /* >          T. On exit, D is overwritten. */
658 /* > \endverbatim */
659 /* > */
660 /* > \param[in,out] E */
661 /* > \verbatim */
662 /* >          E is DOUBLE PRECISION array, dimension (N) */
663 /* >          On entry, the (N-1) subdiagonal elements of the tridiagonal */
664 /* >          matrix T in elements 1 to N-1 of E. E(N) need not be set on */
665 /* >          input, but is used internally as workspace. */
666 /* >          On exit, E is overwritten. */
667 /* > \endverbatim */
668 /* > */
669 /* > \param[in] VL */
670 /* > \verbatim */
671 /* >          VL is DOUBLE PRECISION */
672 /* > */
673 /* >          If RANGE='V', the lower bound of the interval to */
674 /* >          be searched for eigenvalues. VL < VU. */
675 /* >          Not referenced if RANGE = 'A' or 'I'. */
676 /* > \endverbatim */
677 /* > */
678 /* > \param[in] VU */
679 /* > \verbatim */
680 /* >          VU is DOUBLE PRECISION */
681 /* > */
682 /* >          If RANGE='V', the upper bound of the interval to */
683 /* >          be searched for eigenvalues. VL < VU. */
684 /* >          Not referenced if RANGE = 'A' or 'I'. */
685 /* > \endverbatim */
686 /* > */
687 /* > \param[in] IL */
688 /* > \verbatim */
689 /* >          IL is INTEGER */
690 /* > */
691 /* >          If RANGE='I', the index of the */
692 /* >          smallest eigenvalue to be returned. */
693 /* >          1 <= IL <= IU <= N, if N > 0. */
694 /* >          Not referenced if RANGE = 'A' or 'V'. */
695 /* > \endverbatim */
696 /* > */
697 /* > \param[in] IU */
698 /* > \verbatim */
699 /* >          IU is INTEGER */
700 /* > */
701 /* >          If RANGE='I', the index of the */
702 /* >          largest eigenvalue to be returned. */
703 /* >          1 <= IL <= IU <= N, if N > 0. */
704 /* >          Not referenced if RANGE = 'A' or 'V'. */
705 /* > \endverbatim */
706 /* > */
707 /* > \param[out] M */
708 /* > \verbatim */
709 /* >          M is INTEGER */
710 /* >          The total number of eigenvalues found.  0 <= M <= N. */
711 /* >          If RANGE = 'A', M = N, and if RANGE = 'I', M = IU-IL+1. */
712 /* > \endverbatim */
713 /* > */
714 /* > \param[out] W */
715 /* > \verbatim */
716 /* >          W is DOUBLE PRECISION array, dimension (N) */
717 /* >          The first M elements contain the selected eigenvalues in */
718 /* >          ascending order. */
719 /* > \endverbatim */
720 /* > */
721 /* > \param[out] Z */
722 /* > \verbatim */
723 /* >          Z is COMPLEX*16 array, dimension (LDZ, f2cmax(1,M) ) */
724 /* >          If JOBZ = 'V', and if INFO = 0, then the first M columns of Z */
725 /* >          contain the orthonormal eigenvectors of the matrix T */
726 /* >          corresponding to the selected eigenvalues, with the i-th */
727 /* >          column of Z holding the eigenvector associated with W(i). */
728 /* >          If JOBZ = 'N', then Z is not referenced. */
729 /* >          Note: the user must ensure that at least f2cmax(1,M) columns are */
730 /* >          supplied in the array Z; if RANGE = 'V', the exact value of M */
731 /* >          is not known in advance and can be computed with a workspace */
732 /* >          query by setting NZC = -1, see below. */
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', then LDZ >= f2cmax(1,N). */
740 /* > \endverbatim */
741 /* > */
742 /* > \param[in] NZC */
743 /* > \verbatim */
744 /* >          NZC is INTEGER */
745 /* >          The number of eigenvectors to be held in the array Z. */
746 /* >          If RANGE = 'A', then NZC >= f2cmax(1,N). */
747 /* >          If RANGE = 'V', then NZC >= the number of eigenvalues in (VL,VU]. */
748 /* >          If RANGE = 'I', then NZC >= IU-IL+1. */
749 /* >          If NZC = -1, then a workspace query is assumed; the */
750 /* >          routine calculates the number of columns of the array Z that */
751 /* >          are needed to hold the eigenvectors. */
752 /* >          This value is returned as the first entry of the Z array, and */
753 /* >          no error message related to NZC is issued by XERBLA. */
754 /* > \endverbatim */
755 /* > */
756 /* > \param[out] ISUPPZ */
757 /* > \verbatim */
758 /* >          ISUPPZ is INTEGER array, dimension ( 2*f2cmax(1,M) ) */
759 /* >          The support of the eigenvectors in Z, i.e., the indices */
760 /* >          indicating the nonzero elements in Z. The i-th computed eigenvector */
761 /* >          is nonzero only in elements ISUPPZ( 2*i-1 ) through */
762 /* >          ISUPPZ( 2*i ). This is relevant in the case when the matrix */
763 /* >          is split. ISUPPZ is only accessed when JOBZ is 'V' and N > 0. */
764 /* > \endverbatim */
765 /* > */
766 /* > \param[in,out] TRYRAC */
767 /* > \verbatim */
768 /* >          TRYRAC is LOGICAL */
769 /* >          If TRYRAC = .TRUE., indicates that the code should check whether */
770 /* >          the tridiagonal matrix defines its eigenvalues to high relative */
771 /* >          accuracy.  If so, the code uses relative-accuracy preserving */
772 /* >          algorithms that might be (a bit) slower depending on the matrix. */
773 /* >          If the matrix does not define its eigenvalues to high relative */
774 /* >          accuracy, the code can uses possibly faster algorithms. */
775 /* >          If TRYRAC = .FALSE., the code is not required to guarantee */
776 /* >          relatively accurate eigenvalues and can use the fastest possible */
777 /* >          techniques. */
778 /* >          On exit, a .TRUE. TRYRAC will be set to .FALSE. if the matrix */
779 /* >          does not define its eigenvalues to high relative accuracy. */
780 /* > \endverbatim */
781 /* > */
782 /* > \param[out] WORK */
783 /* > \verbatim */
784 /* >          WORK is DOUBLE PRECISION array, dimension (LWORK) */
785 /* >          On exit, if INFO = 0, WORK(1) returns the optimal */
786 /* >          (and minimal) LWORK. */
787 /* > \endverbatim */
788 /* > */
789 /* > \param[in] LWORK */
790 /* > \verbatim */
791 /* >          LWORK is INTEGER */
792 /* >          The dimension of the array WORK. LWORK >= f2cmax(1,18*N) */
793 /* >          if JOBZ = 'V', and LWORK >= f2cmax(1,12*N) if JOBZ = 'N'. */
794 /* >          If LWORK = -1, then a workspace query is assumed; the routine */
795 /* >          only calculates the optimal size of the WORK array, returns */
796 /* >          this value as the first entry of the WORK array, and no error */
797 /* >          message related to LWORK is issued by XERBLA. */
798 /* > \endverbatim */
799 /* > */
800 /* > \param[out] IWORK */
801 /* > \verbatim */
802 /* >          IWORK is INTEGER array, dimension (LIWORK) */
803 /* >          On exit, if INFO = 0, IWORK(1) returns the optimal LIWORK. */
804 /* > \endverbatim */
805 /* > */
806 /* > \param[in] LIWORK */
807 /* > \verbatim */
808 /* >          LIWORK is INTEGER */
809 /* >          The dimension of the array IWORK.  LIWORK >= f2cmax(1,10*N) */
810 /* >          if the eigenvectors are desired, and LIWORK >= f2cmax(1,8*N) */
811 /* >          if only the eigenvalues are to be computed. */
812 /* >          If LIWORK = -1, then a workspace query is assumed; the */
813 /* >          routine only calculates the optimal size of the IWORK array, */
814 /* >          returns this value as the first entry of the IWORK array, and */
815 /* >          no error message related to LIWORK is issued by XERBLA. */
816 /* > \endverbatim */
817 /* > */
818 /* > \param[out] INFO */
819 /* > \verbatim */
820 /* >          INFO is INTEGER */
821 /* >          On exit, INFO */
822 /* >          = 0:  successful exit */
823 /* >          < 0:  if INFO = -i, the i-th argument had an illegal value */
824 /* >          > 0:  if INFO = 1X, internal error in DLARRE, */
825 /* >                if INFO = 2X, internal error in ZLARRV. */
826 /* >                Here, the digit X = ABS( IINFO ) < 10, where IINFO is */
827 /* >                the nonzero error code returned by DLARRE or */
828 /* >                ZLARRV, respectively. */
829 /* > \endverbatim */
830
831 /*  Authors: */
832 /*  ======== */
833
834 /* > \author Univ. of Tennessee */
835 /* > \author Univ. of California Berkeley */
836 /* > \author Univ. of Colorado Denver */
837 /* > \author NAG Ltd. */
838
839 /* > \date June 2016 */
840
841 /* > \ingroup complex16OTHERcomputational */
842
843 /* > \par Contributors: */
844 /*  ================== */
845 /* > */
846 /* > Beresford Parlett, University of California, Berkeley, USA \n */
847 /* > Jim Demmel, University of California, Berkeley, USA \n */
848 /* > Inderjit Dhillon, University of Texas, Austin, USA \n */
849 /* > Osni Marques, LBNL/NERSC, USA \n */
850 /* > Christof Voemel, University of California, Berkeley, USA \n */
851
852 /*  ===================================================================== */
853 /* Subroutine */ int zstemr_(char *jobz, char *range, integer *n, doublereal *
854         d__, doublereal *e, doublereal *vl, doublereal *vu, integer *il, 
855         integer *iu, integer *m, doublereal *w, doublecomplex *z__, integer *
856         ldz, integer *nzc, integer *isuppz, logical *tryrac, doublereal *work,
857          integer *lwork, integer *iwork, integer *liwork, integer *info)
858 {
859     /* System generated locals */
860     integer z_dim1, z_offset, i__1, i__2;
861     doublereal d__1, d__2;
862
863     /* Local variables */
864     integer indd, iend, jblk, wend;
865     doublereal rmin, rmax;
866     integer itmp;
867     doublereal tnrm;
868     extern /* Subroutine */ int dlae2_(doublereal *, doublereal *, doublereal 
869             *, doublereal *, doublereal *);
870     integer inde2, itmp2;
871     doublereal rtol1, rtol2;
872     integer i__, j;
873     extern /* Subroutine */ int dscal_(integer *, doublereal *, doublereal *, 
874             integer *);
875     doublereal scale;
876     integer indgp;
877     extern logical lsame_(char *, char *);
878     integer iinfo, iindw, ilast;
879     extern /* Subroutine */ int dcopy_(integer *, doublereal *, integer *, 
880             doublereal *, integer *);
881     integer lwmin;
882     logical wantz;
883     doublereal r1, r2;
884     extern /* Subroutine */ int zswap_(integer *, doublecomplex *, integer *, 
885             doublecomplex *, integer *), dlaev2_(doublereal *, doublereal *, 
886             doublereal *, doublereal *, doublereal *, doublereal *, 
887             doublereal *);
888     integer jj;
889     doublereal cs;
890     integer in;
891     extern doublereal dlamch_(char *);
892     logical alleig, indeig;
893     integer ibegin, iindbl;
894     doublereal sn, wl;
895     logical valeig;
896     extern /* Subroutine */ int dlarrc_(char *, integer *, doublereal *, 
897             doublereal *, doublereal *, doublereal *, doublereal *, integer *,
898              integer *, integer *, integer *), dlarre_(char *, 
899             integer *, doublereal *, doublereal *, integer *, integer *, 
900             doublereal *, doublereal *, doublereal *, doublereal *, 
901             doublereal *, doublereal *, integer *, integer *, integer *, 
902             doublereal *, doublereal *, doublereal *, integer *, integer *, 
903             doublereal *, doublereal *, doublereal *, integer *, integer *);
904     integer wbegin;
905     doublereal safmin, wu;
906     extern /* Subroutine */ int dlarrj_(integer *, doublereal *, doublereal *,
907              integer *, integer *, doublereal *, integer *, doublereal *, 
908             doublereal *, doublereal *, integer *, doublereal *, doublereal *,
909              integer *), xerbla_(char *, integer *, ftnlen);
910     doublereal bignum;
911     integer inderr, iindwk, indgrs, offset;
912     extern doublereal dlanst_(char *, integer *, doublereal *, doublereal *);
913     extern /* Subroutine */ int dlarrr_(integer *, doublereal *, doublereal *,
914              integer *), dlasrt_(char *, integer *, doublereal *, integer *);
915     doublereal thresh;
916     integer iinspl, indwrk, ifirst, liwmin, nzcmin;
917     doublereal pivmin;
918     integer nsplit;
919     doublereal smlnum;
920     extern /* Subroutine */ int zlarrv_(integer *, doublereal *, doublereal *,
921              doublereal *, doublereal *, doublereal *, integer *, integer *, 
922             integer *, integer *, doublereal *, doublereal *, doublereal *, 
923             doublereal *, doublereal *, doublereal *, integer *, integer *, 
924             doublereal *, doublecomplex *, integer *, integer *, doublereal *,
925              integer *, integer *);
926     logical lquery, zquery;
927     integer iil, iiu;
928     doublereal eps, tmp;
929
930
931 /*  -- LAPACK computational routine (version 3.7.1) -- */
932 /*  -- LAPACK is a software package provided by Univ. of Tennessee,    -- */
933 /*  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
934 /*     June 2016 */
935
936
937 /*  ===================================================================== */
938
939
940 /*     Test the input parameters. */
941
942     /* Parameter adjustments */
943     --d__;
944     --e;
945     --w;
946     z_dim1 = *ldz;
947     z_offset = 1 + z_dim1 * 1;
948     z__ -= z_offset;
949     --isuppz;
950     --work;
951     --iwork;
952
953     /* Function Body */
954     wantz = lsame_(jobz, "V");
955     alleig = lsame_(range, "A");
956     valeig = lsame_(range, "V");
957     indeig = lsame_(range, "I");
958
959     lquery = *lwork == -1 || *liwork == -1;
960     zquery = *nzc == -1;
961 /*     DSTEMR needs WORK of size 6*N, IWORK of size 3*N. */
962 /*     In addition, DLARRE needs WORK of size 6*N, IWORK of size 5*N. */
963 /*     Furthermore, ZLARRV needs WORK of size 12*N, IWORK of size 7*N. */
964     if (wantz) {
965         lwmin = *n * 18;
966         liwmin = *n * 10;
967     } else {
968 /*        need less workspace if only the eigenvalues are wanted */
969         lwmin = *n * 12;
970         liwmin = *n << 3;
971     }
972     wl = 0.;
973     wu = 0.;
974     iil = 0;
975     iiu = 0;
976     nsplit = 0;
977     if (valeig) {
978 /*        We do not reference VL, VU in the cases RANGE = 'I','A' */
979 /*        The interval (WL, WU] contains all the wanted eigenvalues. */
980 /*        It is either given by the user or computed in DLARRE. */
981         wl = *vl;
982         wu = *vu;
983     } else if (indeig) {
984 /*        We do not reference IL, IU in the cases RANGE = 'V','A' */
985         iil = *il;
986         iiu = *iu;
987     }
988
989     *info = 0;
990     if (! (wantz || lsame_(jobz, "N"))) {
991         *info = -1;
992     } else if (! (alleig || valeig || indeig)) {
993         *info = -2;
994     } else if (*n < 0) {
995         *info = -3;
996     } else if (valeig && *n > 0 && wu <= wl) {
997         *info = -7;
998     } else if (indeig && (iil < 1 || iil > *n)) {
999         *info = -8;
1000     } else if (indeig && (iiu < iil || iiu > *n)) {
1001         *info = -9;
1002     } else if (*ldz < 1 || wantz && *ldz < *n) {
1003         *info = -13;
1004     } else if (*lwork < lwmin && ! lquery) {
1005         *info = -17;
1006     } else if (*liwork < liwmin && ! lquery) {
1007         *info = -19;
1008     }
1009
1010 /*     Get machine constants. */
1011
1012     safmin = dlamch_("Safe minimum");
1013     eps = dlamch_("Precision");
1014     smlnum = safmin / eps;
1015     bignum = 1. / smlnum;
1016     rmin = sqrt(smlnum);
1017 /* Computing MIN */
1018     d__1 = sqrt(bignum), d__2 = 1. / sqrt(sqrt(safmin));
1019     rmax = f2cmin(d__1,d__2);
1020
1021     if (*info == 0) {
1022         work[1] = (doublereal) lwmin;
1023         iwork[1] = liwmin;
1024
1025         if (wantz && alleig) {
1026             nzcmin = *n;
1027         } else if (wantz && valeig) {
1028             dlarrc_("T", n, vl, vu, &d__[1], &e[1], &safmin, &nzcmin, &itmp, &
1029                     itmp2, info);
1030         } else if (wantz && indeig) {
1031             nzcmin = iiu - iil + 1;
1032         } else {
1033 /*           WANTZ .EQ. FALSE. */
1034             nzcmin = 0;
1035         }
1036         if (zquery && *info == 0) {
1037             i__1 = z_dim1 + 1;
1038             z__[i__1].r = (doublereal) nzcmin, z__[i__1].i = 0.;
1039         } else if (*nzc < nzcmin && ! zquery) {
1040             *info = -14;
1041         }
1042     }
1043     if (*info != 0) {
1044
1045         i__1 = -(*info);
1046         xerbla_("ZSTEMR", &i__1, (ftnlen)6);
1047
1048         return 0;
1049     } else if (lquery || zquery) {
1050         return 0;
1051     }
1052
1053 /*     Handle N = 0, 1, and 2 cases immediately */
1054
1055     *m = 0;
1056     if (*n == 0) {
1057         return 0;
1058     }
1059
1060     if (*n == 1) {
1061         if (alleig || indeig) {
1062             *m = 1;
1063             w[1] = d__[1];
1064         } else {
1065             if (wl < d__[1] && wu >= d__[1]) {
1066                 *m = 1;
1067                 w[1] = d__[1];
1068             }
1069         }
1070         if (wantz && ! zquery) {
1071             i__1 = z_dim1 + 1;
1072             z__[i__1].r = 1., z__[i__1].i = 0.;
1073             isuppz[1] = 1;
1074             isuppz[2] = 1;
1075         }
1076         return 0;
1077     }
1078
1079     if (*n == 2) {
1080         if (! wantz) {
1081             dlae2_(&d__[1], &e[1], &d__[2], &r1, &r2);
1082         } else if (wantz && ! zquery) {
1083             dlaev2_(&d__[1], &e[1], &d__[2], &r1, &r2, &cs, &sn);
1084         }
1085         if (alleig || valeig && r2 > wl && r2 <= wu || indeig && iil == 1) {
1086             ++(*m);
1087             w[*m] = r2;
1088             if (wantz && ! zquery) {
1089                 i__1 = *m * z_dim1 + 1;
1090                 d__1 = -sn;
1091                 z__[i__1].r = d__1, z__[i__1].i = 0.;
1092                 i__1 = *m * z_dim1 + 2;
1093                 z__[i__1].r = cs, z__[i__1].i = 0.;
1094 /*              Note: At most one of SN and CS can be zero. */
1095                 if (sn != 0.) {
1096                     if (cs != 0.) {
1097                         isuppz[(*m << 1) - 1] = 1;
1098                         isuppz[*m * 2] = 2;
1099                     } else {
1100                         isuppz[(*m << 1) - 1] = 1;
1101                         isuppz[*m * 2] = 1;
1102                     }
1103                 } else {
1104                     isuppz[(*m << 1) - 1] = 2;
1105                     isuppz[*m * 2] = 2;
1106                 }
1107             }
1108         }
1109         if (alleig || valeig && r1 > wl && r1 <= wu || indeig && iiu == 2) {
1110             ++(*m);
1111             w[*m] = r1;
1112             if (wantz && ! zquery) {
1113                 i__1 = *m * z_dim1 + 1;
1114                 z__[i__1].r = cs, z__[i__1].i = 0.;
1115                 i__1 = *m * z_dim1 + 2;
1116                 z__[i__1].r = sn, z__[i__1].i = 0.;
1117 /*              Note: At most one of SN and CS can be zero. */
1118                 if (sn != 0.) {
1119                     if (cs != 0.) {
1120                         isuppz[(*m << 1) - 1] = 1;
1121                         isuppz[*m * 2] = 2;
1122                     } else {
1123                         isuppz[(*m << 1) - 1] = 1;
1124                         isuppz[*m * 2] = 1;
1125                     }
1126                 } else {
1127                     isuppz[(*m << 1) - 1] = 2;
1128                     isuppz[*m * 2] = 2;
1129                 }
1130             }
1131         }
1132     } else {
1133 /*        Continue with general N */
1134         indgrs = 1;
1135         inderr = (*n << 1) + 1;
1136         indgp = *n * 3 + 1;
1137         indd = (*n << 2) + 1;
1138         inde2 = *n * 5 + 1;
1139         indwrk = *n * 6 + 1;
1140
1141         iinspl = 1;
1142         iindbl = *n + 1;
1143         iindw = (*n << 1) + 1;
1144         iindwk = *n * 3 + 1;
1145
1146 /*        Scale matrix to allowable range, if necessary. */
1147 /*        The allowable range is related to the PIVMIN parameter; see the */
1148 /*        comments in DLARRD.  The preference for scaling small values */
1149 /*        up is heuristic; we expect users' matrices not to be close to the */
1150 /*        RMAX threshold. */
1151
1152         scale = 1.;
1153         tnrm = dlanst_("M", n, &d__[1], &e[1]);
1154         if (tnrm > 0. && tnrm < rmin) {
1155             scale = rmin / tnrm;
1156         } else if (tnrm > rmax) {
1157             scale = rmax / tnrm;
1158         }
1159         if (scale != 1.) {
1160             dscal_(n, &scale, &d__[1], &c__1);
1161             i__1 = *n - 1;
1162             dscal_(&i__1, &scale, &e[1], &c__1);
1163             tnrm *= scale;
1164             if (valeig) {
1165 /*              If eigenvalues in interval have to be found, */
1166 /*              scale (WL, WU] accordingly */
1167                 wl *= scale;
1168                 wu *= scale;
1169             }
1170         }
1171
1172 /*        Compute the desired eigenvalues of the tridiagonal after splitting */
1173 /*        into smaller subblocks if the corresponding off-diagonal elements */
1174 /*        are small */
1175 /*        THRESH is the splitting parameter for DLARRE */
1176 /*        A negative THRESH forces the old splitting criterion based on the */
1177 /*        size of the off-diagonal. A positive THRESH switches to splitting */
1178 /*        which preserves relative accuracy. */
1179
1180         if (*tryrac) {
1181 /*           Test whether the matrix warrants the more expensive relative approach. */
1182             dlarrr_(n, &d__[1], &e[1], &iinfo);
1183         } else {
1184 /*           The user does not care about relative accurately eigenvalues */
1185             iinfo = -1;
1186         }
1187 /*        Set the splitting criterion */
1188         if (iinfo == 0) {
1189             thresh = eps;
1190         } else {
1191             thresh = -eps;
1192 /*           relative accuracy is desired but T does not guarantee it */
1193             *tryrac = FALSE_;
1194         }
1195
1196         if (*tryrac) {
1197 /*           Copy original diagonal, needed to guarantee relative accuracy */
1198             dcopy_(n, &d__[1], &c__1, &work[indd], &c__1);
1199         }
1200 /*        Store the squares of the offdiagonal values of T */
1201         i__1 = *n - 1;
1202         for (j = 1; j <= i__1; ++j) {
1203 /* Computing 2nd power */
1204             d__1 = e[j];
1205             work[inde2 + j - 1] = d__1 * d__1;
1206 /* L5: */
1207         }
1208 /*        Set the tolerance parameters for bisection */
1209         if (! wantz) {
1210 /*           DLARRE computes the eigenvalues to full precision. */
1211             rtol1 = eps * 4.;
1212             rtol2 = eps * 4.;
1213         } else {
1214 /*           DLARRE computes the eigenvalues to less than full precision. */
1215 /*           ZLARRV will refine the eigenvalue approximations, and we only */
1216 /*           need less accurate initial bisection in DLARRE. */
1217 /*           Note: these settings do only affect the subset case and DLARRE */
1218             rtol1 = sqrt(eps);
1219 /* Computing MAX */
1220             d__1 = sqrt(eps) * .005, d__2 = eps * 4.;
1221             rtol2 = f2cmax(d__1,d__2);
1222         }
1223         dlarre_(range, n, &wl, &wu, &iil, &iiu, &d__[1], &e[1], &work[inde2], 
1224                 &rtol1, &rtol2, &thresh, &nsplit, &iwork[iinspl], m, &w[1], &
1225                 work[inderr], &work[indgp], &iwork[iindbl], &iwork[iindw], &
1226                 work[indgrs], &pivmin, &work[indwrk], &iwork[iindwk], &iinfo);
1227         if (iinfo != 0) {
1228             *info = abs(iinfo) + 10;
1229             return 0;
1230         }
1231 /*        Note that if RANGE .NE. 'V', DLARRE computes bounds on the desired */
1232 /*        part of the spectrum. All desired eigenvalues are contained in */
1233 /*        (WL,WU] */
1234         if (wantz) {
1235
1236 /*           Compute the desired eigenvectors corresponding to the computed */
1237 /*           eigenvalues */
1238
1239             zlarrv_(n, &wl, &wu, &d__[1], &e[1], &pivmin, &iwork[iinspl], m, &
1240                     c__1, m, &c_b18, &rtol1, &rtol2, &w[1], &work[inderr], &
1241                     work[indgp], &iwork[iindbl], &iwork[iindw], &work[indgrs],
1242                      &z__[z_offset], ldz, &isuppz[1], &work[indwrk], &iwork[
1243                     iindwk], &iinfo);
1244             if (iinfo != 0) {
1245                 *info = abs(iinfo) + 20;
1246                 return 0;
1247             }
1248         } else {
1249 /*           DLARRE computes eigenvalues of the (shifted) root representation */
1250 /*           ZLARRV returns the eigenvalues of the unshifted matrix. */
1251 /*           However, if the eigenvectors are not desired by the user, we need */
1252 /*           to apply the corresponding shifts from DLARRE to obtain the */
1253 /*           eigenvalues of the original matrix. */
1254             i__1 = *m;
1255             for (j = 1; j <= i__1; ++j) {
1256                 itmp = iwork[iindbl + j - 1];
1257                 w[j] += e[iwork[iinspl + itmp - 1]];
1258 /* L20: */
1259             }
1260         }
1261
1262         if (*tryrac) {
1263 /*           Refine computed eigenvalues so that they are relatively accurate */
1264 /*           with respect to the original matrix T. */
1265             ibegin = 1;
1266             wbegin = 1;
1267             i__1 = iwork[iindbl + *m - 1];
1268             for (jblk = 1; jblk <= i__1; ++jblk) {
1269                 iend = iwork[iinspl + jblk - 1];
1270                 in = iend - ibegin + 1;
1271                 wend = wbegin - 1;
1272 /*              check if any eigenvalues have to be refined in this block */
1273 L36:
1274                 if (wend < *m) {
1275                     if (iwork[iindbl + wend] == jblk) {
1276                         ++wend;
1277                         goto L36;
1278                     }
1279                 }
1280                 if (wend < wbegin) {
1281                     ibegin = iend + 1;
1282                     goto L39;
1283                 }
1284                 offset = iwork[iindw + wbegin - 1] - 1;
1285                 ifirst = iwork[iindw + wbegin - 1];
1286                 ilast = iwork[iindw + wend - 1];
1287                 rtol2 = eps * 4.;
1288                 dlarrj_(&in, &work[indd + ibegin - 1], &work[inde2 + ibegin - 
1289                         1], &ifirst, &ilast, &rtol2, &offset, &w[wbegin], &
1290                         work[inderr + wbegin - 1], &work[indwrk], &iwork[
1291                         iindwk], &pivmin, &tnrm, &iinfo);
1292                 ibegin = iend + 1;
1293                 wbegin = wend + 1;
1294 L39:
1295                 ;
1296             }
1297         }
1298
1299 /*        If matrix was scaled, then rescale eigenvalues appropriately. */
1300
1301         if (scale != 1.) {
1302             d__1 = 1. / scale;
1303             dscal_(m, &d__1, &w[1], &c__1);
1304         }
1305     }
1306
1307 /*     If eigenvalues are not in increasing order, then sort them, */
1308 /*     possibly along with eigenvectors. */
1309
1310     if (nsplit > 1 || *n == 2) {
1311         if (! wantz) {
1312             dlasrt_("I", m, &w[1], &iinfo);
1313             if (iinfo != 0) {
1314                 *info = 3;
1315                 return 0;
1316             }
1317         } else {
1318             i__1 = *m - 1;
1319             for (j = 1; j <= i__1; ++j) {
1320                 i__ = 0;
1321                 tmp = w[j];
1322                 i__2 = *m;
1323                 for (jj = j + 1; jj <= i__2; ++jj) {
1324                     if (w[jj] < tmp) {
1325                         i__ = jj;
1326                         tmp = w[jj];
1327                     }
1328 /* L50: */
1329                 }
1330                 if (i__ != 0) {
1331                     w[i__] = w[j];
1332                     w[j] = tmp;
1333                     if (wantz) {
1334                         zswap_(n, &z__[i__ * z_dim1 + 1], &c__1, &z__[j * 
1335                                 z_dim1 + 1], &c__1);
1336                         itmp = isuppz[(i__ << 1) - 1];
1337                         isuppz[(i__ << 1) - 1] = isuppz[(j << 1) - 1];
1338                         isuppz[(j << 1) - 1] = itmp;
1339                         itmp = isuppz[i__ * 2];
1340                         isuppz[i__ * 2] = isuppz[j * 2];
1341                         isuppz[j * 2] = itmp;
1342                     }
1343                 }
1344 /* L60: */
1345             }
1346         }
1347     }
1348
1349
1350     work[1] = (doublereal) lwmin;
1351     iwork[1] = liwmin;
1352     return 0;
1353
1354 /*     End of ZSTEMR */
1355
1356 } /* zstemr_ */
1357