C_LAPACK: Fixes to make it compile with MSVC (#3605)
[platform/upstream/openblas.git] / lapack-netlib / SRC / dlaqtr.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 integer c__1 = 1;
516 static logical c_false = FALSE_;
517 static integer c__2 = 2;
518 static doublereal c_b21 = 1.;
519 static doublereal c_b25 = 0.;
520 static logical c_true = TRUE_;
521
522 /* > \brief \b DLAQTR solves a real quasi-triangular system of equations, or a complex quasi-triangular system
523  of special form, in real arithmetic. */
524
525 /*  =========== DOCUMENTATION =========== */
526
527 /* Online html documentation available at */
528 /*            http://www.netlib.org/lapack/explore-html/ */
529
530 /* > \htmlonly */
531 /* > Download DLAQTR + dependencies */
532 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dlaqtr.
533 f"> */
534 /* > [TGZ]</a> */
535 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dlaqtr.
536 f"> */
537 /* > [ZIP]</a> */
538 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dlaqtr.
539 f"> */
540 /* > [TXT]</a> */
541 /* > \endhtmlonly */
542
543 /*  Definition: */
544 /*  =========== */
545
546 /*       SUBROUTINE DLAQTR( LTRAN, LREAL, N, T, LDT, B, W, SCALE, X, WORK, */
547 /*                          INFO ) */
548
549 /*       LOGICAL            LREAL, LTRAN */
550 /*       INTEGER            INFO, LDT, N */
551 /*       DOUBLE PRECISION   SCALE, W */
552 /*       DOUBLE PRECISION   B( * ), T( LDT, * ), WORK( * ), X( * ) */
553
554
555 /* > \par Purpose: */
556 /*  ============= */
557 /* > */
558 /* > \verbatim */
559 /* > */
560 /* > DLAQTR solves the real quasi-triangular system */
561 /* > */
562 /* >              op(T)*p = scale*c,               if LREAL = .TRUE. */
563 /* > */
564 /* > or the complex quasi-triangular systems */
565 /* > */
566 /* >            op(T + iB)*(p+iq) = scale*(c+id),  if LREAL = .FALSE. */
567 /* > */
568 /* > in real arithmetic, where T is upper quasi-triangular. */
569 /* > If LREAL = .FALSE., then the first diagonal block of T must be */
570 /* > 1 by 1, B is the specially structured matrix */
571 /* > */
572 /* >                B = [ b(1) b(2) ... b(n) ] */
573 /* >                    [       w            ] */
574 /* >                    [           w        ] */
575 /* >                    [              .     ] */
576 /* >                    [                 w  ] */
577 /* > */
578 /* > op(A) = A or A**T, A**T denotes the transpose of */
579 /* > matrix A. */
580 /* > */
581 /* > On input, X = [ c ].  On output, X = [ p ]. */
582 /* >               [ d ]                  [ q ] */
583 /* > */
584 /* > This subroutine is designed for the condition number estimation */
585 /* > in routine DTRSNA. */
586 /* > \endverbatim */
587
588 /*  Arguments: */
589 /*  ========== */
590
591 /* > \param[in] LTRAN */
592 /* > \verbatim */
593 /* >          LTRAN is LOGICAL */
594 /* >          On entry, LTRAN specifies the option of conjugate transpose: */
595 /* >             = .FALSE.,    op(T+i*B) = T+i*B, */
596 /* >             = .TRUE.,     op(T+i*B) = (T+i*B)**T. */
597 /* > \endverbatim */
598 /* > */
599 /* > \param[in] LREAL */
600 /* > \verbatim */
601 /* >          LREAL is LOGICAL */
602 /* >          On entry, LREAL specifies the input matrix structure: */
603 /* >             = .FALSE.,    the input is complex */
604 /* >             = .TRUE.,     the input is real */
605 /* > \endverbatim */
606 /* > */
607 /* > \param[in] N */
608 /* > \verbatim */
609 /* >          N is INTEGER */
610 /* >          On entry, N specifies the order of T+i*B. N >= 0. */
611 /* > \endverbatim */
612 /* > */
613 /* > \param[in] T */
614 /* > \verbatim */
615 /* >          T is DOUBLE PRECISION array, dimension (LDT,N) */
616 /* >          On entry, T contains a matrix in Schur canonical form. */
617 /* >          If LREAL = .FALSE., then the first diagonal block of T mu */
618 /* >          be 1 by 1. */
619 /* > \endverbatim */
620 /* > */
621 /* > \param[in] LDT */
622 /* > \verbatim */
623 /* >          LDT is INTEGER */
624 /* >          The leading dimension of the matrix T. LDT >= f2cmax(1,N). */
625 /* > \endverbatim */
626 /* > */
627 /* > \param[in] B */
628 /* > \verbatim */
629 /* >          B is DOUBLE PRECISION array, dimension (N) */
630 /* >          On entry, B contains the elements to form the matrix */
631 /* >          B as described above. */
632 /* >          If LREAL = .TRUE., B is not referenced. */
633 /* > \endverbatim */
634 /* > */
635 /* > \param[in] W */
636 /* > \verbatim */
637 /* >          W is DOUBLE PRECISION */
638 /* >          On entry, W is the diagonal element of the matrix B. */
639 /* >          If LREAL = .TRUE., W is not referenced. */
640 /* > \endverbatim */
641 /* > */
642 /* > \param[out] SCALE */
643 /* > \verbatim */
644 /* >          SCALE is DOUBLE PRECISION */
645 /* >          On exit, SCALE is the scale factor. */
646 /* > \endverbatim */
647 /* > */
648 /* > \param[in,out] X */
649 /* > \verbatim */
650 /* >          X is DOUBLE PRECISION array, dimension (2*N) */
651 /* >          On entry, X contains the right hand side of the system. */
652 /* >          On exit, X is overwritten by the solution. */
653 /* > \endverbatim */
654 /* > */
655 /* > \param[out] WORK */
656 /* > \verbatim */
657 /* >          WORK is DOUBLE PRECISION array, dimension (N) */
658 /* > \endverbatim */
659 /* > */
660 /* > \param[out] INFO */
661 /* > \verbatim */
662 /* >          INFO is INTEGER */
663 /* >          On exit, INFO is set to */
664 /* >             0: successful exit. */
665 /* >               1: the some diagonal 1 by 1 block has been perturbed by */
666 /* >                  a small number SMIN to keep nonsingularity. */
667 /* >               2: the some diagonal 2 by 2 block has been perturbed by */
668 /* >                  a small number in DLALN2 to keep nonsingularity. */
669 /* >          NOTE: In the interests of speed, this routine does not */
670 /* >                check the inputs for errors. */
671 /* > \endverbatim */
672
673 /*  Authors: */
674 /*  ======== */
675
676 /* > \author Univ. of Tennessee */
677 /* > \author Univ. of California Berkeley */
678 /* > \author Univ. of Colorado Denver */
679 /* > \author NAG Ltd. */
680
681 /* > \date December 2016 */
682
683 /* > \ingroup doubleOTHERauxiliary */
684
685 /*  ===================================================================== */
686 /* Subroutine */ int dlaqtr_(logical *ltran, logical *lreal, integer *n, 
687         doublereal *t, integer *ldt, doublereal *b, doublereal *w, doublereal 
688         *scale, doublereal *x, doublereal *work, integer *info)
689 {
690     /* System generated locals */
691     integer t_dim1, t_offset, i__1, i__2;
692     doublereal d__1, d__2, d__3, d__4, d__5, d__6;
693
694     /* Local variables */
695     extern doublereal ddot_(integer *, doublereal *, integer *, doublereal *, 
696             integer *);
697     integer ierr;
698     doublereal smin, xmax, d__[4]       /* was [2][2] */;
699     integer i__, j, k;
700     doublereal v[4]     /* was [2][2] */, z__;
701     extern /* Subroutine */ int dscal_(integer *, doublereal *, doublereal *, 
702             integer *);
703     extern doublereal dasum_(integer *, doublereal *, integer *);
704     extern /* Subroutine */ int daxpy_(integer *, doublereal *, doublereal *, 
705             integer *, doublereal *, integer *);
706     integer jnext, j1, j2;
707     doublereal sminw;
708     integer n1, n2;
709     doublereal xnorm;
710     extern /* Subroutine */ int dlaln2_(logical *, integer *, integer *, 
711             doublereal *, doublereal *, doublereal *, integer *, doublereal *,
712              doublereal *, doublereal *, integer *, doublereal *, doublereal *
713             , doublereal *, integer *, doublereal *, doublereal *, integer *);
714     extern doublereal dlamch_(char *), dlange_(char *, integer *, 
715             integer *, doublereal *, integer *, doublereal *);
716     doublereal si, xj;
717     extern integer idamax_(integer *, doublereal *, integer *);
718     doublereal scaloc, sr;
719     extern /* Subroutine */ int dladiv_(doublereal *, doublereal *, 
720             doublereal *, doublereal *, doublereal *, doublereal *);
721     doublereal bignum;
722     logical notran;
723     doublereal smlnum, rec, eps, tjj, tmp;
724
725
726 /*  -- LAPACK auxiliary routine (version 3.7.0) -- */
727 /*  -- LAPACK is a software package provided by Univ. of Tennessee,    -- */
728 /*  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
729 /*     December 2016 */
730
731
732 /* ===================================================================== */
733
734
735 /*     Do not test the input parameters for errors */
736
737     /* Parameter adjustments */
738     t_dim1 = *ldt;
739     t_offset = 1 + t_dim1 * 1;
740     t -= t_offset;
741     --b;
742     --x;
743     --work;
744
745     /* Function Body */
746     notran = ! (*ltran);
747     *info = 0;
748
749 /*     Quick return if possible */
750
751     if (*n == 0) {
752         return 0;
753     }
754
755 /*     Set constants to control overflow */
756
757     eps = dlamch_("P");
758     smlnum = dlamch_("S") / eps;
759     bignum = 1. / smlnum;
760
761     xnorm = dlange_("M", n, n, &t[t_offset], ldt, d__);
762     if (! (*lreal)) {
763 /* Computing MAX */
764         d__1 = xnorm, d__2 = abs(*w), d__1 = f2cmax(d__1,d__2), d__2 = dlange_(
765                 "M", n, &c__1, &b[1], n, d__);
766         xnorm = f2cmax(d__1,d__2);
767     }
768 /* Computing MAX */
769     d__1 = smlnum, d__2 = eps * xnorm;
770     smin = f2cmax(d__1,d__2);
771
772 /*     Compute 1-norm of each column of strictly upper triangular */
773 /*     part of T to control overflow in triangular solver. */
774
775     work[1] = 0.;
776     i__1 = *n;
777     for (j = 2; j <= i__1; ++j) {
778         i__2 = j - 1;
779         work[j] = dasum_(&i__2, &t[j * t_dim1 + 1], &c__1);
780 /* L10: */
781     }
782
783     if (! (*lreal)) {
784         i__1 = *n;
785         for (i__ = 2; i__ <= i__1; ++i__) {
786             work[i__] += (d__1 = b[i__], abs(d__1));
787 /* L20: */
788         }
789     }
790
791     n2 = *n << 1;
792     n1 = *n;
793     if (! (*lreal)) {
794         n1 = n2;
795     }
796     k = idamax_(&n1, &x[1], &c__1);
797     xmax = (d__1 = x[k], abs(d__1));
798     *scale = 1.;
799
800     if (xmax > bignum) {
801         *scale = bignum / xmax;
802         dscal_(&n1, scale, &x[1], &c__1);
803         xmax = bignum;
804     }
805
806     if (*lreal) {
807
808         if (notran) {
809
810 /*           Solve T*p = scale*c */
811
812             jnext = *n;
813             for (j = *n; j >= 1; --j) {
814                 if (j > jnext) {
815                     goto L30;
816                 }
817                 j1 = j;
818                 j2 = j;
819                 jnext = j - 1;
820                 if (j > 1) {
821                     if (t[j + (j - 1) * t_dim1] != 0.) {
822                         j1 = j - 1;
823                         jnext = j - 2;
824                     }
825                 }
826
827                 if (j1 == j2) {
828
829 /*                 Meet 1 by 1 diagonal block */
830
831 /*                 Scale to avoid overflow when computing */
832 /*                     x(j) = b(j)/T(j,j) */
833
834                     xj = (d__1 = x[j1], abs(d__1));
835                     tjj = (d__1 = t[j1 + j1 * t_dim1], abs(d__1));
836                     tmp = t[j1 + j1 * t_dim1];
837                     if (tjj < smin) {
838                         tmp = smin;
839                         tjj = smin;
840                         *info = 1;
841                     }
842
843                     if (xj == 0.) {
844                         goto L30;
845                     }
846
847                     if (tjj < 1.) {
848                         if (xj > bignum * tjj) {
849                             rec = 1. / xj;
850                             dscal_(n, &rec, &x[1], &c__1);
851                             *scale *= rec;
852                             xmax *= rec;
853                         }
854                     }
855                     x[j1] /= tmp;
856                     xj = (d__1 = x[j1], abs(d__1));
857
858 /*                 Scale x if necessary to avoid overflow when adding a */
859 /*                 multiple of column j1 of T. */
860
861                     if (xj > 1.) {
862                         rec = 1. / xj;
863                         if (work[j1] > (bignum - xmax) * rec) {
864                             dscal_(n, &rec, &x[1], &c__1);
865                             *scale *= rec;
866                         }
867                     }
868                     if (j1 > 1) {
869                         i__1 = j1 - 1;
870                         d__1 = -x[j1];
871                         daxpy_(&i__1, &d__1, &t[j1 * t_dim1 + 1], &c__1, &x[1]
872                                 , &c__1);
873                         i__1 = j1 - 1;
874                         k = idamax_(&i__1, &x[1], &c__1);
875                         xmax = (d__1 = x[k], abs(d__1));
876                     }
877
878                 } else {
879
880 /*                 Meet 2 by 2 diagonal block */
881
882 /*                 Call 2 by 2 linear system solve, to take */
883 /*                 care of possible overflow by scaling factor. */
884
885                     d__[0] = x[j1];
886                     d__[1] = x[j2];
887                     dlaln2_(&c_false, &c__2, &c__1, &smin, &c_b21, &t[j1 + j1 
888                             * t_dim1], ldt, &c_b21, &c_b21, d__, &c__2, &
889                             c_b25, &c_b25, v, &c__2, &scaloc, &xnorm, &ierr);
890                     if (ierr != 0) {
891                         *info = 2;
892                     }
893
894                     if (scaloc != 1.) {
895                         dscal_(n, &scaloc, &x[1], &c__1);
896                         *scale *= scaloc;
897                     }
898                     x[j1] = v[0];
899                     x[j2] = v[1];
900
901 /*                 Scale V(1,1) (= X(J1)) and/or V(2,1) (=X(J2)) */
902 /*                 to avoid overflow in updating right-hand side. */
903
904 /* Computing MAX */
905                     d__1 = abs(v[0]), d__2 = abs(v[1]);
906                     xj = f2cmax(d__1,d__2);
907                     if (xj > 1.) {
908                         rec = 1. / xj;
909 /* Computing MAX */
910                         d__1 = work[j1], d__2 = work[j2];
911                         if (f2cmax(d__1,d__2) > (bignum - xmax) * rec) {
912                             dscal_(n, &rec, &x[1], &c__1);
913                             *scale *= rec;
914                         }
915                     }
916
917 /*                 Update right-hand side */
918
919                     if (j1 > 1) {
920                         i__1 = j1 - 1;
921                         d__1 = -x[j1];
922                         daxpy_(&i__1, &d__1, &t[j1 * t_dim1 + 1], &c__1, &x[1]
923                                 , &c__1);
924                         i__1 = j1 - 1;
925                         d__1 = -x[j2];
926                         daxpy_(&i__1, &d__1, &t[j2 * t_dim1 + 1], &c__1, &x[1]
927                                 , &c__1);
928                         i__1 = j1 - 1;
929                         k = idamax_(&i__1, &x[1], &c__1);
930                         xmax = (d__1 = x[k], abs(d__1));
931                     }
932
933                 }
934
935 L30:
936                 ;
937             }
938
939         } else {
940
941 /*           Solve T**T*p = scale*c */
942
943             jnext = 1;
944             i__1 = *n;
945             for (j = 1; j <= i__1; ++j) {
946                 if (j < jnext) {
947                     goto L40;
948                 }
949                 j1 = j;
950                 j2 = j;
951                 jnext = j + 1;
952                 if (j < *n) {
953                     if (t[j + 1 + j * t_dim1] != 0.) {
954                         j2 = j + 1;
955                         jnext = j + 2;
956                     }
957                 }
958
959                 if (j1 == j2) {
960
961 /*                 1 by 1 diagonal block */
962
963 /*                 Scale if necessary to avoid overflow in forming the */
964 /*                 right-hand side element by inner product. */
965
966                     xj = (d__1 = x[j1], abs(d__1));
967                     if (xmax > 1.) {
968                         rec = 1. / xmax;
969                         if (work[j1] > (bignum - xj) * rec) {
970                             dscal_(n, &rec, &x[1], &c__1);
971                             *scale *= rec;
972                             xmax *= rec;
973                         }
974                     }
975
976                     i__2 = j1 - 1;
977                     x[j1] -= ddot_(&i__2, &t[j1 * t_dim1 + 1], &c__1, &x[1], &
978                             c__1);
979
980                     xj = (d__1 = x[j1], abs(d__1));
981                     tjj = (d__1 = t[j1 + j1 * t_dim1], abs(d__1));
982                     tmp = t[j1 + j1 * t_dim1];
983                     if (tjj < smin) {
984                         tmp = smin;
985                         tjj = smin;
986                         *info = 1;
987                     }
988
989                     if (tjj < 1.) {
990                         if (xj > bignum * tjj) {
991                             rec = 1. / xj;
992                             dscal_(n, &rec, &x[1], &c__1);
993                             *scale *= rec;
994                             xmax *= rec;
995                         }
996                     }
997                     x[j1] /= tmp;
998 /* Computing MAX */
999                     d__2 = xmax, d__3 = (d__1 = x[j1], abs(d__1));
1000                     xmax = f2cmax(d__2,d__3);
1001
1002                 } else {
1003
1004 /*                 2 by 2 diagonal block */
1005
1006 /*                 Scale if necessary to avoid overflow in forming the */
1007 /*                 right-hand side elements by inner product. */
1008
1009 /* Computing MAX */
1010                     d__3 = (d__1 = x[j1], abs(d__1)), d__4 = (d__2 = x[j2], 
1011                             abs(d__2));
1012                     xj = f2cmax(d__3,d__4);
1013                     if (xmax > 1.) {
1014                         rec = 1. / xmax;
1015 /* Computing MAX */
1016                         d__1 = work[j2], d__2 = work[j1];
1017                         if (f2cmax(d__1,d__2) > (bignum - xj) * rec) {
1018                             dscal_(n, &rec, &x[1], &c__1);
1019                             *scale *= rec;
1020                             xmax *= rec;
1021                         }
1022                     }
1023
1024                     i__2 = j1 - 1;
1025                     d__[0] = x[j1] - ddot_(&i__2, &t[j1 * t_dim1 + 1], &c__1, 
1026                             &x[1], &c__1);
1027                     i__2 = j1 - 1;
1028                     d__[1] = x[j2] - ddot_(&i__2, &t[j2 * t_dim1 + 1], &c__1, 
1029                             &x[1], &c__1);
1030
1031                     dlaln2_(&c_true, &c__2, &c__1, &smin, &c_b21, &t[j1 + j1 *
1032                              t_dim1], ldt, &c_b21, &c_b21, d__, &c__2, &c_b25,
1033                              &c_b25, v, &c__2, &scaloc, &xnorm, &ierr);
1034                     if (ierr != 0) {
1035                         *info = 2;
1036                     }
1037
1038                     if (scaloc != 1.) {
1039                         dscal_(n, &scaloc, &x[1], &c__1);
1040                         *scale *= scaloc;
1041                     }
1042                     x[j1] = v[0];
1043                     x[j2] = v[1];
1044 /* Computing MAX */
1045                     d__3 = (d__1 = x[j1], abs(d__1)), d__4 = (d__2 = x[j2], 
1046                             abs(d__2)), d__3 = f2cmax(d__3,d__4);
1047                     xmax = f2cmax(d__3,xmax);
1048
1049                 }
1050 L40:
1051                 ;
1052             }
1053         }
1054
1055     } else {
1056
1057 /* Computing MAX */
1058         d__1 = eps * abs(*w);
1059         sminw = f2cmax(d__1,smin);
1060         if (notran) {
1061
1062 /*           Solve (T + iB)*(p+iq) = c+id */
1063
1064             jnext = *n;
1065             for (j = *n; j >= 1; --j) {
1066                 if (j > jnext) {
1067                     goto L70;
1068                 }
1069                 j1 = j;
1070                 j2 = j;
1071                 jnext = j - 1;
1072                 if (j > 1) {
1073                     if (t[j + (j - 1) * t_dim1] != 0.) {
1074                         j1 = j - 1;
1075                         jnext = j - 2;
1076                     }
1077                 }
1078
1079                 if (j1 == j2) {
1080
1081 /*                 1 by 1 diagonal block */
1082
1083 /*                 Scale if necessary to avoid overflow in division */
1084
1085                     z__ = *w;
1086                     if (j1 == 1) {
1087                         z__ = b[1];
1088                     }
1089                     xj = (d__1 = x[j1], abs(d__1)) + (d__2 = x[*n + j1], abs(
1090                             d__2));
1091                     tjj = (d__1 = t[j1 + j1 * t_dim1], abs(d__1)) + abs(z__);
1092                     tmp = t[j1 + j1 * t_dim1];
1093                     if (tjj < sminw) {
1094                         tmp = sminw;
1095                         tjj = sminw;
1096                         *info = 1;
1097                     }
1098
1099                     if (xj == 0.) {
1100                         goto L70;
1101                     }
1102
1103                     if (tjj < 1.) {
1104                         if (xj > bignum * tjj) {
1105                             rec = 1. / xj;
1106                             dscal_(&n2, &rec, &x[1], &c__1);
1107                             *scale *= rec;
1108                             xmax *= rec;
1109                         }
1110                     }
1111                     dladiv_(&x[j1], &x[*n + j1], &tmp, &z__, &sr, &si);
1112                     x[j1] = sr;
1113                     x[*n + j1] = si;
1114                     xj = (d__1 = x[j1], abs(d__1)) + (d__2 = x[*n + j1], abs(
1115                             d__2));
1116
1117 /*                 Scale x if necessary to avoid overflow when adding a */
1118 /*                 multiple of column j1 of T. */
1119
1120                     if (xj > 1.) {
1121                         rec = 1. / xj;
1122                         if (work[j1] > (bignum - xmax) * rec) {
1123                             dscal_(&n2, &rec, &x[1], &c__1);
1124                             *scale *= rec;
1125                         }
1126                     }
1127
1128                     if (j1 > 1) {
1129                         i__1 = j1 - 1;
1130                         d__1 = -x[j1];
1131                         daxpy_(&i__1, &d__1, &t[j1 * t_dim1 + 1], &c__1, &x[1]
1132                                 , &c__1);
1133                         i__1 = j1 - 1;
1134                         d__1 = -x[*n + j1];
1135                         daxpy_(&i__1, &d__1, &t[j1 * t_dim1 + 1], &c__1, &x[*
1136                                 n + 1], &c__1);
1137
1138                         x[1] += b[j1] * x[*n + j1];
1139                         x[*n + 1] -= b[j1] * x[j1];
1140
1141                         xmax = 0.;
1142                         i__1 = j1 - 1;
1143                         for (k = 1; k <= i__1; ++k) {
1144 /* Computing MAX */
1145                             d__3 = xmax, d__4 = (d__1 = x[k], abs(d__1)) + (
1146                                     d__2 = x[k + *n], abs(d__2));
1147                             xmax = f2cmax(d__3,d__4);
1148 /* L50: */
1149                         }
1150                     }
1151
1152                 } else {
1153
1154 /*                 Meet 2 by 2 diagonal block */
1155
1156                     d__[0] = x[j1];
1157                     d__[1] = x[j2];
1158                     d__[2] = x[*n + j1];
1159                     d__[3] = x[*n + j2];
1160                     d__1 = -(*w);
1161                     dlaln2_(&c_false, &c__2, &c__2, &sminw, &c_b21, &t[j1 + 
1162                             j1 * t_dim1], ldt, &c_b21, &c_b21, d__, &c__2, &
1163                             c_b25, &d__1, v, &c__2, &scaloc, &xnorm, &ierr);
1164                     if (ierr != 0) {
1165                         *info = 2;
1166                     }
1167
1168                     if (scaloc != 1.) {
1169                         i__1 = *n << 1;
1170                         dscal_(&i__1, &scaloc, &x[1], &c__1);
1171                         *scale = scaloc * *scale;
1172                     }
1173                     x[j1] = v[0];
1174                     x[j2] = v[1];
1175                     x[*n + j1] = v[2];
1176                     x[*n + j2] = v[3];
1177
1178 /*                 Scale X(J1), .... to avoid overflow in */
1179 /*                 updating right hand side. */
1180
1181 /* Computing MAX */
1182                     d__1 = abs(v[0]) + abs(v[2]), d__2 = abs(v[1]) + abs(v[3])
1183                             ;
1184                     xj = f2cmax(d__1,d__2);
1185                     if (xj > 1.) {
1186                         rec = 1. / xj;
1187 /* Computing MAX */
1188                         d__1 = work[j1], d__2 = work[j2];
1189                         if (f2cmax(d__1,d__2) > (bignum - xmax) * rec) {
1190                             dscal_(&n2, &rec, &x[1], &c__1);
1191                             *scale *= rec;
1192                         }
1193                     }
1194
1195 /*                 Update the right-hand side. */
1196
1197                     if (j1 > 1) {
1198                         i__1 = j1 - 1;
1199                         d__1 = -x[j1];
1200                         daxpy_(&i__1, &d__1, &t[j1 * t_dim1 + 1], &c__1, &x[1]
1201                                 , &c__1);
1202                         i__1 = j1 - 1;
1203                         d__1 = -x[j2];
1204                         daxpy_(&i__1, &d__1, &t[j2 * t_dim1 + 1], &c__1, &x[1]
1205                                 , &c__1);
1206
1207                         i__1 = j1 - 1;
1208                         d__1 = -x[*n + j1];
1209                         daxpy_(&i__1, &d__1, &t[j1 * t_dim1 + 1], &c__1, &x[*
1210                                 n + 1], &c__1);
1211                         i__1 = j1 - 1;
1212                         d__1 = -x[*n + j2];
1213                         daxpy_(&i__1, &d__1, &t[j2 * t_dim1 + 1], &c__1, &x[*
1214                                 n + 1], &c__1);
1215
1216                         x[1] = x[1] + b[j1] * x[*n + j1] + b[j2] * x[*n + j2];
1217                         x[*n + 1] = x[*n + 1] - b[j1] * x[j1] - b[j2] * x[j2];
1218
1219                         xmax = 0.;
1220                         i__1 = j1 - 1;
1221                         for (k = 1; k <= i__1; ++k) {
1222 /* Computing MAX */
1223                             d__3 = (d__1 = x[k], abs(d__1)) + (d__2 = x[k + *
1224                                     n], abs(d__2));
1225                             xmax = f2cmax(d__3,xmax);
1226 /* L60: */
1227                         }
1228                     }
1229
1230                 }
1231 L70:
1232                 ;
1233             }
1234
1235         } else {
1236
1237 /*           Solve (T + iB)**T*(p+iq) = c+id */
1238
1239             jnext = 1;
1240             i__1 = *n;
1241             for (j = 1; j <= i__1; ++j) {
1242                 if (j < jnext) {
1243                     goto L80;
1244                 }
1245                 j1 = j;
1246                 j2 = j;
1247                 jnext = j + 1;
1248                 if (j < *n) {
1249                     if (t[j + 1 + j * t_dim1] != 0.) {
1250                         j2 = j + 1;
1251                         jnext = j + 2;
1252                     }
1253                 }
1254
1255                 if (j1 == j2) {
1256
1257 /*                 1 by 1 diagonal block */
1258
1259 /*                 Scale if necessary to avoid overflow in forming the */
1260 /*                 right-hand side element by inner product. */
1261
1262                     xj = (d__1 = x[j1], abs(d__1)) + (d__2 = x[j1 + *n], abs(
1263                             d__2));
1264                     if (xmax > 1.) {
1265                         rec = 1. / xmax;
1266                         if (work[j1] > (bignum - xj) * rec) {
1267                             dscal_(&n2, &rec, &x[1], &c__1);
1268                             *scale *= rec;
1269                             xmax *= rec;
1270                         }
1271                     }
1272
1273                     i__2 = j1 - 1;
1274                     x[j1] -= ddot_(&i__2, &t[j1 * t_dim1 + 1], &c__1, &x[1], &
1275                             c__1);
1276                     i__2 = j1 - 1;
1277                     x[*n + j1] -= ddot_(&i__2, &t[j1 * t_dim1 + 1], &c__1, &x[
1278                             *n + 1], &c__1);
1279                     if (j1 > 1) {
1280                         x[j1] -= b[j1] * x[*n + 1];
1281                         x[*n + j1] += b[j1] * x[1];
1282                     }
1283                     xj = (d__1 = x[j1], abs(d__1)) + (d__2 = x[j1 + *n], abs(
1284                             d__2));
1285
1286                     z__ = *w;
1287                     if (j1 == 1) {
1288                         z__ = b[1];
1289                     }
1290
1291 /*                 Scale if necessary to avoid overflow in */
1292 /*                 complex division */
1293
1294                     tjj = (d__1 = t[j1 + j1 * t_dim1], abs(d__1)) + abs(z__);
1295                     tmp = t[j1 + j1 * t_dim1];
1296                     if (tjj < sminw) {
1297                         tmp = sminw;
1298                         tjj = sminw;
1299                         *info = 1;
1300                     }
1301
1302                     if (tjj < 1.) {
1303                         if (xj > bignum * tjj) {
1304                             rec = 1. / xj;
1305                             dscal_(&n2, &rec, &x[1], &c__1);
1306                             *scale *= rec;
1307                             xmax *= rec;
1308                         }
1309                     }
1310                     d__1 = -z__;
1311                     dladiv_(&x[j1], &x[*n + j1], &tmp, &d__1, &sr, &si);
1312                     x[j1] = sr;
1313                     x[j1 + *n] = si;
1314 /* Computing MAX */
1315                     d__3 = (d__1 = x[j1], abs(d__1)) + (d__2 = x[j1 + *n], 
1316                             abs(d__2));
1317                     xmax = f2cmax(d__3,xmax);
1318
1319                 } else {
1320
1321 /*                 2 by 2 diagonal block */
1322
1323 /*                 Scale if necessary to avoid overflow in forming the */
1324 /*                 right-hand side element by inner product. */
1325
1326 /* Computing MAX */
1327                     d__5 = (d__1 = x[j1], abs(d__1)) + (d__2 = x[*n + j1], 
1328                             abs(d__2)), d__6 = (d__3 = x[j2], abs(d__3)) + (
1329                             d__4 = x[*n + j2], abs(d__4));
1330                     xj = f2cmax(d__5,d__6);
1331                     if (xmax > 1.) {
1332                         rec = 1. / xmax;
1333 /* Computing MAX */
1334                         d__1 = work[j1], d__2 = work[j2];
1335                         if (f2cmax(d__1,d__2) > (bignum - xj) / xmax) {
1336                             dscal_(&n2, &rec, &x[1], &c__1);
1337                             *scale *= rec;
1338                             xmax *= rec;
1339                         }
1340                     }
1341
1342                     i__2 = j1 - 1;
1343                     d__[0] = x[j1] - ddot_(&i__2, &t[j1 * t_dim1 + 1], &c__1, 
1344                             &x[1], &c__1);
1345                     i__2 = j1 - 1;
1346                     d__[1] = x[j2] - ddot_(&i__2, &t[j2 * t_dim1 + 1], &c__1, 
1347                             &x[1], &c__1);
1348                     i__2 = j1 - 1;
1349                     d__[2] = x[*n + j1] - ddot_(&i__2, &t[j1 * t_dim1 + 1], &
1350                             c__1, &x[*n + 1], &c__1);
1351                     i__2 = j1 - 1;
1352                     d__[3] = x[*n + j2] - ddot_(&i__2, &t[j2 * t_dim1 + 1], &
1353                             c__1, &x[*n + 1], &c__1);
1354                     d__[0] -= b[j1] * x[*n + 1];
1355                     d__[1] -= b[j2] * x[*n + 1];
1356                     d__[2] += b[j1] * x[1];
1357                     d__[3] += b[j2] * x[1];
1358
1359                     dlaln2_(&c_true, &c__2, &c__2, &sminw, &c_b21, &t[j1 + j1 
1360                             * t_dim1], ldt, &c_b21, &c_b21, d__, &c__2, &
1361                             c_b25, w, v, &c__2, &scaloc, &xnorm, &ierr);
1362                     if (ierr != 0) {
1363                         *info = 2;
1364                     }
1365
1366                     if (scaloc != 1.) {
1367                         dscal_(&n2, &scaloc, &x[1], &c__1);
1368                         *scale = scaloc * *scale;
1369                     }
1370                     x[j1] = v[0];
1371                     x[j2] = v[1];
1372                     x[*n + j1] = v[2];
1373                     x[*n + j2] = v[3];
1374 /* Computing MAX */
1375                     d__5 = (d__1 = x[j1], abs(d__1)) + (d__2 = x[*n + j1], 
1376                             abs(d__2)), d__6 = (d__3 = x[j2], abs(d__3)) + (
1377                             d__4 = x[*n + j2], abs(d__4)), d__5 = f2cmax(d__5,
1378                             d__6);
1379                     xmax = f2cmax(d__5,xmax);
1380
1381                 }
1382
1383 L80:
1384                 ;
1385             }
1386
1387         }
1388
1389     }
1390
1391     return 0;
1392
1393 /*     End of DLAQTR */
1394
1395 } /* dlaqtr_ */
1396