C_LAPACK: Fixes to make it compile with MSVC (#3605)
[platform/upstream/openblas.git] / lapack-netlib / SRC / cgbsvxx.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 /*  -- translated by f2c (version 20000121).
512    You must link the resulting object file with the libraries:
513         -lf2c -lm   (in that order)
514 */
515
516
517
518 /*  -- translated by f2c (version 20000121).
519    You must link the resulting object file with the libraries:
520         -lf2c -lm   (in that order)
521 */
522
523
524
525 /* > \brief <b> CGBSVXX computes the solution to system of linear equations A * X = B for GB matrices</b> */
526
527 /*  =========== DOCUMENTATION =========== */
528
529 /* Online html documentation available at */
530 /*            http://www.netlib.org/lapack/explore-html/ */
531
532 /* > \htmlonly */
533 /* > Download CGBSVXX + dependencies */
534 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/cgbsvxx
535 .f"> */
536 /* > [TGZ]</a> */
537 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/cgbsvxx
538 .f"> */
539 /* > [ZIP]</a> */
540 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/cgbsvxx
541 .f"> */
542 /* > [TXT]</a> */
543 /* > \endhtmlonly */
544
545 /*  Definition: */
546 /*  =========== */
547
548 /*       SUBROUTINE CGBSVXX( FACT, TRANS, N, KL, KU, NRHS, AB, LDAB, AFB, */
549 /*                           LDAFB, IPIV, EQUED, R, C, B, LDB, X, LDX, */
550 /*                           RCOND, RPVGRW, BERR, N_ERR_BNDS, */
551 /*                           ERR_BNDS_NORM, ERR_BNDS_COMP, NPARAMS, PARAMS, */
552 /*                           WORK, RWORK, INFO ) */
553
554 /*       CHARACTER          EQUED, FACT, TRANS */
555 /*       INTEGER            INFO, LDAB, LDAFB, LDB, LDX, N, NRHS, NPARAMS, */
556 /*      $                   N_ERR_BNDS */
557 /*       REAL               RCOND, RPVGRW */
558 /*       INTEGER            IPIV( * ) */
559 /*       COMPLEX            AB( LDAB, * ), AFB( LDAFB, * ), B( LDB, * ), */
560 /*      $                   X( LDX , * ),WORK( * ) */
561 /*       REAL               R( * ), C( * ), PARAMS( * ), BERR( * ), */
562 /*      $                   ERR_BNDS_NORM( NRHS, * ), */
563 /*      $                   ERR_BNDS_COMP( NRHS, * ), RWORK( * ) */
564
565
566 /* > \par Purpose: */
567 /*  ============= */
568 /* > */
569 /* > \verbatim */
570 /* > */
571 /* >    CGBSVXX uses the LU factorization to compute the solution to a */
572 /* >    complex system of linear equations  A * X = B,  where A is an */
573 /* >    N-by-N matrix and X and B are N-by-NRHS matrices. */
574 /* > */
575 /* >    If requested, both normwise and maximum componentwise error bounds */
576 /* >    are returned. CGBSVXX will return a solution with a tiny */
577 /* >    guaranteed error (O(eps) where eps is the working machine */
578 /* >    precision) unless the matrix is very ill-conditioned, in which */
579 /* >    case a warning is returned. Relevant condition numbers also are */
580 /* >    calculated and returned. */
581 /* > */
582 /* >    CGBSVXX accepts user-provided factorizations and equilibration */
583 /* >    factors; see the definitions of the FACT and EQUED options. */
584 /* >    Solving with refinement and using a factorization from a previous */
585 /* >    CGBSVXX call will also produce a solution with either O(eps) */
586 /* >    errors or warnings, but we cannot make that claim for general */
587 /* >    user-provided factorizations and equilibration factors if they */
588 /* >    differ from what CGBSVXX would itself produce. */
589 /* > \endverbatim */
590
591 /* > \par Description: */
592 /*  ================= */
593 /* > */
594 /* > \verbatim */
595 /* > */
596 /* >    The following steps are performed: */
597 /* > */
598 /* >    1. If FACT = 'E', real scaling factors are computed to equilibrate */
599 /* >    the system: */
600 /* > */
601 /* >      TRANS = 'N':  diag(R)*A*diag(C)     *inv(diag(C))*X = diag(R)*B */
602 /* >      TRANS = 'T': (diag(R)*A*diag(C))**T *inv(diag(R))*X = diag(C)*B */
603 /* >      TRANS = 'C': (diag(R)*A*diag(C))**H *inv(diag(R))*X = diag(C)*B */
604 /* > */
605 /* >    Whether or not the system will be equilibrated depends on the */
606 /* >    scaling of the matrix A, but if equilibration is used, A is */
607 /* >    overwritten by diag(R)*A*diag(C) and B by diag(R)*B (if TRANS='N') */
608 /* >    or diag(C)*B (if TRANS = 'T' or 'C'). */
609 /* > */
610 /* >    2. If FACT = 'N' or 'E', the LU decomposition is used to factor */
611 /* >    the matrix A (after equilibration if FACT = 'E') as */
612 /* > */
613 /* >      A = P * L * U, */
614 /* > */
615 /* >    where P is a permutation matrix, L is a unit lower triangular */
616 /* >    matrix, and U is upper triangular. */
617 /* > */
618 /* >    3. If some U(i,i)=0, so that U is exactly singular, then the */
619 /* >    routine returns with INFO = i. Otherwise, the factored form of A */
620 /* >    is used to estimate the condition number of the matrix A (see */
621 /* >    argument RCOND). If the reciprocal of the condition number is less */
622 /* >    than machine precision, the routine still goes on to solve for X */
623 /* >    and compute error bounds as described below. */
624 /* > */
625 /* >    4. The system of equations is solved for X using the factored form */
626 /* >    of A. */
627 /* > */
628 /* >    5. By default (unless PARAMS(LA_LINRX_ITREF_I) is set to zero), */
629 /* >    the routine will use iterative refinement to try to get a small */
630 /* >    error and error bounds.  Refinement calculates the residual to at */
631 /* >    least twice the working precision. */
632 /* > */
633 /* >    6. If equilibration was used, the matrix X is premultiplied by */
634 /* >    diag(C) (if TRANS = 'N') or diag(R) (if TRANS = 'T' or 'C') so */
635 /* >    that it solves the original system before equilibration. */
636 /* > \endverbatim */
637
638 /*  Arguments: */
639 /*  ========== */
640
641 /* > \verbatim */
642 /* >     Some optional parameters are bundled in the PARAMS array.  These */
643 /* >     settings determine how refinement is performed, but often the */
644 /* >     defaults are acceptable.  If the defaults are acceptable, users */
645 /* >     can pass NPARAMS = 0 which prevents the source code from accessing */
646 /* >     the PARAMS argument. */
647 /* > \endverbatim */
648 /* > */
649 /* > \param[in] FACT */
650 /* > \verbatim */
651 /* >          FACT is CHARACTER*1 */
652 /* >     Specifies whether or not the factored form of the matrix A is */
653 /* >     supplied on entry, and if not, whether the matrix A should be */
654 /* >     equilibrated before it is factored. */
655 /* >       = 'F':  On entry, AF and IPIV contain the factored form of A. */
656 /* >               If EQUED is not 'N', the matrix A has been */
657 /* >               equilibrated with scaling factors given by R and C. */
658 /* >               A, AF, and IPIV are not modified. */
659 /* >       = 'N':  The matrix A will be copied to AF and factored. */
660 /* >       = 'E':  The matrix A will be equilibrated if necessary, then */
661 /* >               copied to AF and factored. */
662 /* > \endverbatim */
663 /* > */
664 /* > \param[in] TRANS */
665 /* > \verbatim */
666 /* >          TRANS is CHARACTER*1 */
667 /* >     Specifies the form of the system of equations: */
668 /* >       = 'N':  A * X = B     (No transpose) */
669 /* >       = 'T':  A**T * X = B  (Transpose) */
670 /* >       = 'C':  A**H * X = B  (Conjugate Transpose = Transpose) */
671 /* > \endverbatim */
672 /* > */
673 /* > \param[in] N */
674 /* > \verbatim */
675 /* >          N is INTEGER */
676 /* >     The number of linear equations, i.e., the order of the */
677 /* >     matrix A.  N >= 0. */
678 /* > \endverbatim */
679 /* > */
680 /* > \param[in] KL */
681 /* > \verbatim */
682 /* >          KL is INTEGER */
683 /* >     The number of subdiagonals within the band of A.  KL >= 0. */
684 /* > \endverbatim */
685 /* > */
686 /* > \param[in] KU */
687 /* > \verbatim */
688 /* >          KU is INTEGER */
689 /* >     The number of superdiagonals within the band of A.  KU >= 0. */
690 /* > \endverbatim */
691 /* > */
692 /* > \param[in] NRHS */
693 /* > \verbatim */
694 /* >          NRHS is INTEGER */
695 /* >     The number of right hand sides, i.e., the number of columns */
696 /* >     of the matrices B and X.  NRHS >= 0. */
697 /* > \endverbatim */
698 /* > */
699 /* > \param[in,out] AB */
700 /* > \verbatim */
701 /* >          AB is COMPLEX array, dimension (LDAB,N) */
702 /* >     On entry, the matrix A in band storage, in rows 1 to KL+KU+1. */
703 /* >     The j-th column of A is stored in the j-th column of the */
704 /* >     array AB as follows: */
705 /* >     AB(KU+1+i-j,j) = A(i,j) for f2cmax(1,j-KU)<=i<=f2cmin(N,j+kl) */
706 /* > */
707 /* >     If FACT = 'F' and EQUED is not 'N', then AB must have been */
708 /* >     equilibrated by the scaling factors in R and/or C.  AB is not */
709 /* >     modified if FACT = 'F' or 'N', or if FACT = 'E' and */
710 /* >     EQUED = 'N' on exit. */
711 /* > */
712 /* >     On exit, if EQUED .ne. 'N', A is scaled as follows: */
713 /* >     EQUED = 'R':  A := diag(R) * A */
714 /* >     EQUED = 'C':  A := A * diag(C) */
715 /* >     EQUED = 'B':  A := diag(R) * A * diag(C). */
716 /* > \endverbatim */
717 /* > */
718 /* > \param[in] LDAB */
719 /* > \verbatim */
720 /* >          LDAB is INTEGER */
721 /* >     The leading dimension of the array AB.  LDAB >= KL+KU+1. */
722 /* > \endverbatim */
723 /* > */
724 /* > \param[in,out] AFB */
725 /* > \verbatim */
726 /* >          AFB is COMPLEX array, dimension (LDAFB,N) */
727 /* >     If FACT = 'F', then AFB is an input argument and on entry */
728 /* >     contains details of the LU factorization of the band matrix */
729 /* >     A, as computed by CGBTRF.  U is stored as an upper triangular */
730 /* >     band matrix with KL+KU superdiagonals in rows 1 to KL+KU+1, */
731 /* >     and the multipliers used during the factorization are stored */
732 /* >     in rows KL+KU+2 to 2*KL+KU+1.  If EQUED .ne. 'N', then AFB is */
733 /* >     the factored form of the equilibrated matrix A. */
734 /* > */
735 /* >     If FACT = 'N', then AF is an output argument and on exit */
736 /* >     returns the factors L and U from the factorization A = P*L*U */
737 /* >     of the original matrix A. */
738 /* > */
739 /* >     If FACT = 'E', then AF is an output argument and on exit */
740 /* >     returns the factors L and U from the factorization A = P*L*U */
741 /* >     of the equilibrated matrix A (see the description of A for */
742 /* >     the form of the equilibrated matrix). */
743 /* > \endverbatim */
744 /* > */
745 /* > \param[in] LDAFB */
746 /* > \verbatim */
747 /* >          LDAFB is INTEGER */
748 /* >     The leading dimension of the array AFB.  LDAFB >= 2*KL+KU+1. */
749 /* > \endverbatim */
750 /* > */
751 /* > \param[in,out] IPIV */
752 /* > \verbatim */
753 /* >          IPIV is INTEGER array, dimension (N) */
754 /* >     If FACT = 'F', then IPIV is an input argument and on entry */
755 /* >     contains the pivot indices from the factorization A = P*L*U */
756 /* >     as computed by SGETRF; row i of the matrix was interchanged */
757 /* >     with row IPIV(i). */
758 /* > */
759 /* >     If FACT = 'N', then IPIV is an output argument and on exit */
760 /* >     contains the pivot indices from the factorization A = P*L*U */
761 /* >     of the original matrix A. */
762 /* > */
763 /* >     If FACT = 'E', then IPIV is an output argument and on exit */
764 /* >     contains the pivot indices from the factorization A = P*L*U */
765 /* >     of the equilibrated matrix A. */
766 /* > \endverbatim */
767 /* > */
768 /* > \param[in,out] EQUED */
769 /* > \verbatim */
770 /* >          EQUED is CHARACTER*1 */
771 /* >     Specifies the form of equilibration that was done. */
772 /* >       = 'N':  No equilibration (always true if FACT = 'N'). */
773 /* >       = 'R':  Row equilibration, i.e., A has been premultiplied by */
774 /* >               diag(R). */
775 /* >       = 'C':  Column equilibration, i.e., A has been postmultiplied */
776 /* >               by diag(C). */
777 /* >       = 'B':  Both row and column equilibration, i.e., A has been */
778 /* >               replaced by diag(R) * A * diag(C). */
779 /* >     EQUED is an input argument if FACT = 'F'; otherwise, it is an */
780 /* >     output argument. */
781 /* > \endverbatim */
782 /* > */
783 /* > \param[in,out] R */
784 /* > \verbatim */
785 /* >          R is REAL array, dimension (N) */
786 /* >     The row scale factors for A.  If EQUED = 'R' or 'B', A is */
787 /* >     multiplied on the left by diag(R); if EQUED = 'N' or 'C', R */
788 /* >     is not accessed.  R is an input argument if FACT = 'F'; */
789 /* >     otherwise, R is an output argument.  If FACT = 'F' and */
790 /* >     EQUED = 'R' or 'B', each element of R must be positive. */
791 /* >     If R is output, each element of R is a power of the radix. */
792 /* >     If R is input, each element of R should be a power of the radix */
793 /* >     to ensure a reliable solution and error estimates. Scaling by */
794 /* >     powers of the radix does not cause rounding errors unless the */
795 /* >     result underflows or overflows. Rounding errors during scaling */
796 /* >     lead to refining with a matrix that is not equivalent to the */
797 /* >     input matrix, producing error estimates that may not be */
798 /* >     reliable. */
799 /* > \endverbatim */
800 /* > */
801 /* > \param[in,out] C */
802 /* > \verbatim */
803 /* >          C is REAL array, dimension (N) */
804 /* >     The column scale factors for A.  If EQUED = 'C' or 'B', A is */
805 /* >     multiplied on the right by diag(C); if EQUED = 'N' or 'R', C */
806 /* >     is not accessed.  C is an input argument if FACT = 'F'; */
807 /* >     otherwise, C is an output argument.  If FACT = 'F' and */
808 /* >     EQUED = 'C' or 'B', each element of C must be positive. */
809 /* >     If C is output, each element of C is a power of the radix. */
810 /* >     If C is input, each element of C should be a power of the radix */
811 /* >     to ensure a reliable solution and error estimates. Scaling by */
812 /* >     powers of the radix does not cause rounding errors unless the */
813 /* >     result underflows or overflows. Rounding errors during scaling */
814 /* >     lead to refining with a matrix that is not equivalent to the */
815 /* >     input matrix, producing error estimates that may not be */
816 /* >     reliable. */
817 /* > \endverbatim */
818 /* > */
819 /* > \param[in,out] B */
820 /* > \verbatim */
821 /* >          B is COMPLEX array, dimension (LDB,NRHS) */
822 /* >     On entry, the N-by-NRHS right hand side matrix B. */
823 /* >     On exit, */
824 /* >     if EQUED = 'N', B is not modified; */
825 /* >     if TRANS = 'N' and EQUED = 'R' or 'B', B is overwritten by */
826 /* >        diag(R)*B; */
827 /* >     if TRANS = 'T' or 'C' and EQUED = 'C' or 'B', B is */
828 /* >        overwritten by diag(C)*B. */
829 /* > \endverbatim */
830 /* > */
831 /* > \param[in] LDB */
832 /* > \verbatim */
833 /* >          LDB is INTEGER */
834 /* >     The leading dimension of the array B.  LDB >= f2cmax(1,N). */
835 /* > \endverbatim */
836 /* > */
837 /* > \param[out] X */
838 /* > \verbatim */
839 /* >          X is COMPLEX array, dimension (LDX,NRHS) */
840 /* >     If INFO = 0, the N-by-NRHS solution matrix X to the original */
841 /* >     system of equations.  Note that A and B are modified on exit */
842 /* >     if EQUED .ne. 'N', and the solution to the equilibrated system is */
843 /* >     inv(diag(C))*X if TRANS = 'N' and EQUED = 'C' or 'B', or */
844 /* >     inv(diag(R))*X if TRANS = 'T' or 'C' and EQUED = 'R' or 'B'. */
845 /* > \endverbatim */
846 /* > */
847 /* > \param[in] LDX */
848 /* > \verbatim */
849 /* >          LDX is INTEGER */
850 /* >     The leading dimension of the array X.  LDX >= f2cmax(1,N). */
851 /* > \endverbatim */
852 /* > */
853 /* > \param[out] RCOND */
854 /* > \verbatim */
855 /* >          RCOND is REAL */
856 /* >     Reciprocal scaled condition number.  This is an estimate of the */
857 /* >     reciprocal Skeel condition number of the matrix A after */
858 /* >     equilibration (if done).  If this is less than the machine */
859 /* >     precision (in particular, if it is zero), the matrix is singular */
860 /* >     to working precision.  Note that the error may still be small even */
861 /* >     if this number is very small and the matrix appears ill- */
862 /* >     conditioned. */
863 /* > \endverbatim */
864 /* > */
865 /* > \param[out] RPVGRW */
866 /* > \verbatim */
867 /* >          RPVGRW is REAL */
868 /* >     Reciprocal pivot growth.  On exit, this contains the reciprocal */
869 /* >     pivot growth factor norm(A)/norm(U). The "f2cmax absolute element" */
870 /* >     norm is used.  If this is much less than 1, then the stability of */
871 /* >     the LU factorization of the (equilibrated) matrix A could be poor. */
872 /* >     This also means that the solution X, estimated condition numbers, */
873 /* >     and error bounds could be unreliable. If factorization fails with */
874 /* >     0<INFO<=N, then this contains the reciprocal pivot growth factor */
875 /* >     for the leading INFO columns of A.  In SGESVX, this quantity is */
876 /* >     returned in WORK(1). */
877 /* > \endverbatim */
878 /* > */
879 /* > \param[out] BERR */
880 /* > \verbatim */
881 /* >          BERR is REAL array, dimension (NRHS) */
882 /* >     Componentwise relative backward error.  This is the */
883 /* >     componentwise relative backward error of each solution vector X(j) */
884 /* >     (i.e., the smallest relative change in any element of A or B that */
885 /* >     makes X(j) an exact solution). */
886 /* > \endverbatim */
887 /* > */
888 /* > \param[in] N_ERR_BNDS */
889 /* > \verbatim */
890 /* >          N_ERR_BNDS is INTEGER */
891 /* >     Number of error bounds to return for each right hand side */
892 /* >     and each type (normwise or componentwise).  See ERR_BNDS_NORM and */
893 /* >     ERR_BNDS_COMP below. */
894 /* > \endverbatim */
895 /* > */
896 /* > \param[out] ERR_BNDS_NORM */
897 /* > \verbatim */
898 /* >          ERR_BNDS_NORM is REAL array, dimension (NRHS, N_ERR_BNDS) */
899 /* >     For each right-hand side, this array contains information about */
900 /* >     various error bounds and condition numbers corresponding to the */
901 /* >     normwise relative error, which is defined as follows: */
902 /* > */
903 /* >     Normwise relative error in the ith solution vector: */
904 /* >             max_j (abs(XTRUE(j,i) - X(j,i))) */
905 /* >            ------------------------------ */
906 /* >                  max_j abs(X(j,i)) */
907 /* > */
908 /* >     The array is indexed by the type of error information as described */
909 /* >     below. There currently are up to three pieces of information */
910 /* >     returned. */
911 /* > */
912 /* >     The first index in ERR_BNDS_NORM(i,:) corresponds to the ith */
913 /* >     right-hand side. */
914 /* > */
915 /* >     The second index in ERR_BNDS_NORM(:,err) contains the following */
916 /* >     three fields: */
917 /* >     err = 1 "Trust/don't trust" boolean. Trust the answer if the */
918 /* >              reciprocal condition number is less than the threshold */
919 /* >              sqrt(n) * slamch('Epsilon'). */
920 /* > */
921 /* >     err = 2 "Guaranteed" error bound: The estimated forward error, */
922 /* >              almost certainly within a factor of 10 of the true error */
923 /* >              so long as the next entry is greater than the threshold */
924 /* >              sqrt(n) * slamch('Epsilon'). This error bound should only */
925 /* >              be trusted if the previous boolean is true. */
926 /* > */
927 /* >     err = 3  Reciprocal condition number: Estimated normwise */
928 /* >              reciprocal condition number.  Compared with the threshold */
929 /* >              sqrt(n) * slamch('Epsilon') to determine if the error */
930 /* >              estimate is "guaranteed". These reciprocal condition */
931 /* >              numbers are 1 / (norm(Z^{-1},inf) * norm(Z,inf)) for some */
932 /* >              appropriately scaled matrix Z. */
933 /* >              Let Z = S*A, where S scales each row by a power of the */
934 /* >              radix so all absolute row sums of Z are approximately 1. */
935 /* > */
936 /* >     See Lapack Working Note 165 for further details and extra */
937 /* >     cautions. */
938 /* > \endverbatim */
939 /* > */
940 /* > \param[out] ERR_BNDS_COMP */
941 /* > \verbatim */
942 /* >          ERR_BNDS_COMP is REAL array, dimension (NRHS, N_ERR_BNDS) */
943 /* >     For each right-hand side, this array contains information about */
944 /* >     various error bounds and condition numbers corresponding to the */
945 /* >     componentwise relative error, which is defined as follows: */
946 /* > */
947 /* >     Componentwise relative error in the ith solution vector: */
948 /* >                    abs(XTRUE(j,i) - X(j,i)) */
949 /* >             max_j ---------------------- */
950 /* >                         abs(X(j,i)) */
951 /* > */
952 /* >     The array is indexed by the right-hand side i (on which the */
953 /* >     componentwise relative error depends), and the type of error */
954 /* >     information as described below. There currently are up to three */
955 /* >     pieces of information returned for each right-hand side. If */
956 /* >     componentwise accuracy is not requested (PARAMS(3) = 0.0), then */
957 /* >     ERR_BNDS_COMP is not accessed.  If N_ERR_BNDS < 3, then at most */
958 /* >     the first (:,N_ERR_BNDS) entries are returned. */
959 /* > */
960 /* >     The first index in ERR_BNDS_COMP(i,:) corresponds to the ith */
961 /* >     right-hand side. */
962 /* > */
963 /* >     The second index in ERR_BNDS_COMP(:,err) contains the following */
964 /* >     three fields: */
965 /* >     err = 1 "Trust/don't trust" boolean. Trust the answer if the */
966 /* >              reciprocal condition number is less than the threshold */
967 /* >              sqrt(n) * slamch('Epsilon'). */
968 /* > */
969 /* >     err = 2 "Guaranteed" error bound: The estimated forward error, */
970 /* >              almost certainly within a factor of 10 of the true error */
971 /* >              so long as the next entry is greater than the threshold */
972 /* >              sqrt(n) * slamch('Epsilon'). This error bound should only */
973 /* >              be trusted if the previous boolean is true. */
974 /* > */
975 /* >     err = 3  Reciprocal condition number: Estimated componentwise */
976 /* >              reciprocal condition number.  Compared with the threshold */
977 /* >              sqrt(n) * slamch('Epsilon') to determine if the error */
978 /* >              estimate is "guaranteed". These reciprocal condition */
979 /* >              numbers are 1 / (norm(Z^{-1},inf) * norm(Z,inf)) for some */
980 /* >              appropriately scaled matrix Z. */
981 /* >              Let Z = S*(A*diag(x)), where x is the solution for the */
982 /* >              current right-hand side and S scales each row of */
983 /* >              A*diag(x) by a power of the radix so all absolute row */
984 /* >              sums of Z are approximately 1. */
985 /* > */
986 /* >     See Lapack Working Note 165 for further details and extra */
987 /* >     cautions. */
988 /* > \endverbatim */
989 /* > */
990 /* > \param[in] NPARAMS */
991 /* > \verbatim */
992 /* >          NPARAMS is INTEGER */
993 /* >     Specifies the number of parameters set in PARAMS.  If <= 0, the */
994 /* >     PARAMS array is never referenced and default values are used. */
995 /* > \endverbatim */
996 /* > */
997 /* > \param[in,out] PARAMS */
998 /* > \verbatim */
999 /* >          PARAMS is REAL array, dimension NPARAMS */
1000 /* >     Specifies algorithm parameters.  If an entry is < 0.0, then */
1001 /* >     that entry will be filled with default value used for that */
1002 /* >     parameter.  Only positions up to NPARAMS are accessed; defaults */
1003 /* >     are used for higher-numbered parameters. */
1004 /* > */
1005 /* >       PARAMS(LA_LINRX_ITREF_I = 1) : Whether to perform iterative */
1006 /* >            refinement or not. */
1007 /* >         Default: 1.0 */
1008 /* >            = 0.0:  No refinement is performed, and no error bounds are */
1009 /* >                    computed. */
1010 /* >            = 1.0:  Use the double-precision refinement algorithm, */
1011 /* >                    possibly with doubled-single computations if the */
1012 /* >                    compilation environment does not support DOUBLE */
1013 /* >                    PRECISION. */
1014 /* >              (other values are reserved for future use) */
1015 /* > */
1016 /* >       PARAMS(LA_LINRX_ITHRESH_I = 2) : Maximum number of residual */
1017 /* >            computations allowed for refinement. */
1018 /* >         Default: 10 */
1019 /* >         Aggressive: Set to 100 to permit convergence using approximate */
1020 /* >                     factorizations or factorizations other than LU. If */
1021 /* >                     the factorization uses a technique other than */
1022 /* >                     Gaussian elimination, the guarantees in */
1023 /* >                     err_bnds_norm and err_bnds_comp may no longer be */
1024 /* >                     trustworthy. */
1025 /* > */
1026 /* >       PARAMS(LA_LINRX_CWISE_I = 3) : Flag determining if the code */
1027 /* >            will attempt to find a solution with small componentwise */
1028 /* >            relative error in the double-precision algorithm.  Positive */
1029 /* >            is true, 0.0 is false. */
1030 /* >         Default: 1.0 (attempt componentwise convergence) */
1031 /* > \endverbatim */
1032 /* > */
1033 /* > \param[out] WORK */
1034 /* > \verbatim */
1035 /* >          WORK is COMPLEX array, dimension (2*N) */
1036 /* > \endverbatim */
1037 /* > */
1038 /* > \param[out] RWORK */
1039 /* > \verbatim */
1040 /* >          RWORK is REAL array, dimension (2*N) */
1041 /* > \endverbatim */
1042 /* > */
1043 /* > \param[out] INFO */
1044 /* > \verbatim */
1045 /* >          INFO is INTEGER */
1046 /* >       = 0:  Successful exit. The solution to every right-hand side is */
1047 /* >         guaranteed. */
1048 /* >       < 0:  If INFO = -i, the i-th argument had an illegal value */
1049 /* >       > 0 and <= N:  U(INFO,INFO) is exactly zero.  The factorization */
1050 /* >         has been completed, but the factor U is exactly singular, so */
1051 /* >         the solution and error bounds could not be computed. RCOND = 0 */
1052 /* >         is returned. */
1053 /* >       = N+J: The solution corresponding to the Jth right-hand side is */
1054 /* >         not guaranteed. The solutions corresponding to other right- */
1055 /* >         hand sides K with K > J may not be guaranteed as well, but */
1056 /* >         only the first such right-hand side is reported. If a small */
1057 /* >         componentwise error is not requested (PARAMS(3) = 0.0) then */
1058 /* >         the Jth right-hand side is the first with a normwise error */
1059 /* >         bound that is not guaranteed (the smallest J such */
1060 /* >         that ERR_BNDS_NORM(J,1) = 0.0). By default (PARAMS(3) = 1.0) */
1061 /* >         the Jth right-hand side is the first with either a normwise or */
1062 /* >         componentwise error bound that is not guaranteed (the smallest */
1063 /* >         J such that either ERR_BNDS_NORM(J,1) = 0.0 or */
1064 /* >         ERR_BNDS_COMP(J,1) = 0.0). See the definition of */
1065 /* >         ERR_BNDS_NORM(:,1) and ERR_BNDS_COMP(:,1). To get information */
1066 /* >         about all of the right-hand sides check ERR_BNDS_NORM or */
1067 /* >         ERR_BNDS_COMP. */
1068 /* > \endverbatim */
1069
1070 /*  Authors: */
1071 /*  ======== */
1072
1073 /* > \author Univ. of Tennessee */
1074 /* > \author Univ. of California Berkeley */
1075 /* > \author Univ. of Colorado Denver */
1076 /* > \author NAG Ltd. */
1077
1078 /* > \date April 2012 */
1079
1080 /* > \ingroup complexGBsolve */
1081
1082 /*  ===================================================================== */
1083 /* Subroutine */ int cgbsvxx_(char *fact, char *trans, integer *n, integer *
1084         kl, integer *ku, integer *nrhs, complex *ab, integer *ldab, complex *
1085         afb, integer *ldafb, integer *ipiv, char *equed, real *r__, real *c__,
1086          complex *b, integer *ldb, complex *x, integer *ldx, real *rcond, 
1087         real *rpvgrw, real *berr, integer *n_err_bnds__, real *
1088         err_bnds_norm__, real *err_bnds_comp__, integer *nparams, real *
1089         params, complex *work, real *rwork, integer *info)
1090 {
1091     /* System generated locals */
1092     integer ab_dim1, ab_offset, afb_dim1, afb_offset, b_dim1, b_offset, 
1093             x_dim1, x_offset, err_bnds_norm_dim1, err_bnds_norm_offset, 
1094             err_bnds_comp_dim1, err_bnds_comp_offset, i__1, i__2, i__3, i__4;
1095     real r__1, r__2;
1096
1097     /* Local variables */
1098     real amax;
1099     extern real cla_gbrpvgrw_(integer *, integer *, integer *, integer *, 
1100             complex *, integer *, complex *, integer *);
1101     integer i__, j;
1102     extern logical lsame_(char *, char *);
1103     real rcmin, rcmax;
1104     logical equil;
1105     extern /* Subroutine */ int claqgb_(integer *, integer *, integer *, 
1106             integer *, complex *, integer *, real *, real *, real *, real *, 
1107             real *, char *);
1108     real colcnd;
1109     extern real slamch_(char *);
1110     extern /* Subroutine */ int cgbtrf_(integer *, integer *, integer *, 
1111             integer *, complex *, integer *, integer *, integer *);
1112     logical nofact;
1113     extern /* Subroutine */ int clacpy_(char *, integer *, integer *, complex 
1114             *, integer *, complex *, integer *), xerbla_(char *, 
1115             integer *, ftnlen);
1116     real bignum;
1117     extern /* Subroutine */ int cgbtrs_(char *, integer *, integer *, integer 
1118             *, integer *, complex *, integer *, integer *, complex *, integer 
1119             *, integer *);
1120     integer infequ;
1121     logical colequ;
1122     real rowcnd;
1123     logical notran;
1124     real smlnum;
1125     logical rowequ;
1126     extern /* Subroutine */ int clascl2_(integer *, integer *, real *, 
1127             complex *, integer *), cgbequb_(integer *, integer *, integer *, 
1128             integer *, complex *, integer *, real *, real *, real *, real *, 
1129             real *, integer *), cgbrfsx_(char *, char *, integer *, integer *,
1130              integer *, integer *, complex *, integer *, complex *, integer *,
1131              integer *, real *, real *, complex *, integer *, complex *, 
1132             integer *, real *, real *, integer *, real *, real *, integer *, 
1133             real *, complex *, real *, integer *);
1134
1135
1136 /*  -- LAPACK driver routine (version 3.7.0) -- */
1137 /*  -- LAPACK is a software package provided by Univ. of Tennessee,    -- */
1138 /*  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
1139 /*     April 2012 */
1140
1141
1142 /*  ================================================================== */
1143
1144
1145     /* Parameter adjustments */
1146     err_bnds_comp_dim1 = *nrhs;
1147     err_bnds_comp_offset = 1 + err_bnds_comp_dim1 * 1;
1148     err_bnds_comp__ -= err_bnds_comp_offset;
1149     err_bnds_norm_dim1 = *nrhs;
1150     err_bnds_norm_offset = 1 + err_bnds_norm_dim1 * 1;
1151     err_bnds_norm__ -= err_bnds_norm_offset;
1152     ab_dim1 = *ldab;
1153     ab_offset = 1 + ab_dim1 * 1;
1154     ab -= ab_offset;
1155     afb_dim1 = *ldafb;
1156     afb_offset = 1 + afb_dim1 * 1;
1157     afb -= afb_offset;
1158     --ipiv;
1159     --r__;
1160     --c__;
1161     b_dim1 = *ldb;
1162     b_offset = 1 + b_dim1 * 1;
1163     b -= b_offset;
1164     x_dim1 = *ldx;
1165     x_offset = 1 + x_dim1 * 1;
1166     x -= x_offset;
1167     --berr;
1168     --params;
1169     --work;
1170     --rwork;
1171
1172     /* Function Body */
1173     *info = 0;
1174     nofact = lsame_(fact, "N");
1175     equil = lsame_(fact, "E");
1176     notran = lsame_(trans, "N");
1177     smlnum = slamch_("Safe minimum");
1178     bignum = 1.f / smlnum;
1179     if (nofact || equil) {
1180         *(unsigned char *)equed = 'N';
1181         rowequ = FALSE_;
1182         colequ = FALSE_;
1183     } else {
1184         rowequ = lsame_(equed, "R") || lsame_(equed, 
1185                 "B");
1186         colequ = lsame_(equed, "C") || lsame_(equed, 
1187                 "B");
1188     }
1189
1190 /*     Default is failure.  If an input parameter is wrong or */
1191 /*     factorization fails, make everything look horrible.  Only the */
1192 /*     pivot growth is set here, the rest is initialized in CGBRFSX. */
1193
1194     *rpvgrw = 0.f;
1195
1196 /*     Test the input parameters.  PARAMS is not tested until SGERFSX. */
1197
1198     if (! nofact && ! equil && ! lsame_(fact, "F")) {
1199         *info = -1;
1200     } else if (! notran && ! lsame_(trans, "T") && ! 
1201             lsame_(trans, "C")) {
1202         *info = -2;
1203     } else if (*n < 0) {
1204         *info = -3;
1205     } else if (*kl < 0) {
1206         *info = -4;
1207     } else if (*ku < 0) {
1208         *info = -5;
1209     } else if (*nrhs < 0) {
1210         *info = -6;
1211     } else if (*ldab < *kl + *ku + 1) {
1212         *info = -8;
1213     } else if (*ldafb < (*kl << 1) + *ku + 1) {
1214         *info = -10;
1215     } else if (lsame_(fact, "F") && ! (rowequ || colequ 
1216             || lsame_(equed, "N"))) {
1217         *info = -12;
1218     } else {
1219         if (rowequ) {
1220             rcmin = bignum;
1221             rcmax = 0.f;
1222             i__1 = *n;
1223             for (j = 1; j <= i__1; ++j) {
1224 /* Computing MIN */
1225                 r__1 = rcmin, r__2 = r__[j];
1226                 rcmin = f2cmin(r__1,r__2);
1227 /* Computing MAX */
1228                 r__1 = rcmax, r__2 = r__[j];
1229                 rcmax = f2cmax(r__1,r__2);
1230 /* L10: */
1231             }
1232             if (rcmin <= 0.f) {
1233                 *info = -13;
1234             } else if (*n > 0) {
1235                 rowcnd = f2cmax(rcmin,smlnum) / f2cmin(rcmax,bignum);
1236             } else {
1237                 rowcnd = 1.f;
1238             }
1239         }
1240         if (colequ && *info == 0) {
1241             rcmin = bignum;
1242             rcmax = 0.f;
1243             i__1 = *n;
1244             for (j = 1; j <= i__1; ++j) {
1245 /* Computing MIN */
1246                 r__1 = rcmin, r__2 = c__[j];
1247                 rcmin = f2cmin(r__1,r__2);
1248 /* Computing MAX */
1249                 r__1 = rcmax, r__2 = c__[j];
1250                 rcmax = f2cmax(r__1,r__2);
1251 /* L20: */
1252             }
1253             if (rcmin <= 0.f) {
1254                 *info = -14;
1255             } else if (*n > 0) {
1256                 colcnd = f2cmax(rcmin,smlnum) / f2cmin(rcmax,bignum);
1257             } else {
1258                 colcnd = 1.f;
1259             }
1260         }
1261         if (*info == 0) {
1262             if (*ldb < f2cmax(1,*n)) {
1263                 *info = -15;
1264             } else if (*ldx < f2cmax(1,*n)) {
1265                 *info = -16;
1266             }
1267         }
1268     }
1269
1270     if (*info != 0) {
1271         i__1 = -(*info);
1272         xerbla_("CGBSVXX", &i__1, (ftnlen)7);
1273         return 0;
1274     }
1275
1276     if (equil) {
1277
1278 /*     Compute row and column scalings to equilibrate the matrix A. */
1279
1280         cgbequb_(n, n, kl, ku, &ab[ab_offset], ldab, &r__[1], &c__[1], &
1281                 rowcnd, &colcnd, &amax, &infequ);
1282         if (infequ == 0) {
1283
1284 /*     Equilibrate the matrix. */
1285
1286             claqgb_(n, n, kl, ku, &ab[ab_offset], ldab, &r__[1], &c__[1], &
1287                     rowcnd, &colcnd, &amax, equed);
1288             rowequ = lsame_(equed, "R") || lsame_(equed,
1289                      "B");
1290             colequ = lsame_(equed, "C") || lsame_(equed,
1291                      "B");
1292         }
1293
1294 /*     If the scaling factors are not applied, set them to 1.0. */
1295
1296         if (! rowequ) {
1297             i__1 = *n;
1298             for (j = 1; j <= i__1; ++j) {
1299                 r__[j] = 1.f;
1300             }
1301         }
1302         if (! colequ) {
1303             i__1 = *n;
1304             for (j = 1; j <= i__1; ++j) {
1305                 c__[j] = 1.f;
1306             }
1307         }
1308     }
1309
1310 /*     Scale the right-hand side. */
1311
1312     if (notran) {
1313         if (rowequ) {
1314             clascl2_(n, nrhs, &r__[1], &b[b_offset], ldb);
1315         }
1316     } else {
1317         if (colequ) {
1318             clascl2_(n, nrhs, &c__[1], &b[b_offset], ldb);
1319         }
1320     }
1321
1322     if (nofact || equil) {
1323
1324 /*        Compute the LU factorization of A. */
1325
1326         i__1 = *n;
1327         for (j = 1; j <= i__1; ++j) {
1328             i__2 = (*kl << 1) + *ku + 1;
1329             for (i__ = *kl + 1; i__ <= i__2; ++i__) {
1330                 i__3 = i__ + j * afb_dim1;
1331                 i__4 = i__ - *kl + j * ab_dim1;
1332                 afb[i__3].r = ab[i__4].r, afb[i__3].i = ab[i__4].i;
1333 /* L30: */
1334             }
1335 /* L40: */
1336         }
1337         cgbtrf_(n, n, kl, ku, &afb[afb_offset], ldafb, &ipiv[1], info);
1338
1339 /*        Return if INFO is non-zero. */
1340
1341         if (*info > 0) {
1342
1343 /*           Pivot in column INFO is exactly 0 */
1344 /*           Compute the reciprocal pivot growth factor of the */
1345 /*           leading rank-deficient INFO columns of A. */
1346
1347             *rpvgrw = cla_gbrpvgrw_(n, kl, ku, info, &ab[ab_offset], ldab, &
1348                     afb[afb_offset], ldafb);
1349             return 0;
1350         }
1351     }
1352
1353 /*     Compute the reciprocal pivot growth factor RPVGRW. */
1354
1355     *rpvgrw = cla_gbrpvgrw_(n, kl, ku, n, &ab[ab_offset], ldab, &afb[
1356             afb_offset], ldafb);
1357
1358 /*     Compute the solution matrix X. */
1359
1360     clacpy_("Full", n, nrhs, &b[b_offset], ldb, &x[x_offset], ldx);
1361     cgbtrs_(trans, n, kl, ku, nrhs, &afb[afb_offset], ldafb, &ipiv[1], &x[
1362             x_offset], ldx, info);
1363
1364 /*     Use iterative refinement to improve the computed solution and */
1365 /*     compute error bounds and backward error estimates for it. */
1366
1367     cgbrfsx_(trans, equed, n, kl, ku, nrhs, &ab[ab_offset], ldab, &afb[
1368             afb_offset], ldafb, &ipiv[1], &r__[1], &c__[1], &b[b_offset], ldb,
1369              &x[x_offset], ldx, rcond, &berr[1], n_err_bnds__, &
1370             err_bnds_norm__[err_bnds_norm_offset], &err_bnds_comp__[
1371             err_bnds_comp_offset], nparams, &params[1], &work[1], &rwork[1], 
1372             info);
1373
1374 /*     Scale solutions. */
1375
1376     if (colequ && notran) {
1377         clascl2_(n, nrhs, &c__[1], &x[x_offset], ldx);
1378     } else if (rowequ && ! notran) {
1379         clascl2_(n, nrhs, &r__[1], &x[x_offset], ldx);
1380     }
1381
1382     return 0;
1383
1384 /*     End of CGBSVXX */
1385
1386 } /* cgbsvxx_ */
1387