C_LAPACK: Fixes to make it compile with MSVC (#3605)
[platform/upstream/openblas.git] / lapack-netlib / SRC / dlatbs.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 doublereal c_b36 = .5;
517
518 /* > \brief \b DLATBS solves a triangular banded system of equations. */
519
520 /*  =========== DOCUMENTATION =========== */
521
522 /* Online html documentation available at */
523 /*            http://www.netlib.org/lapack/explore-html/ */
524
525 /* > \htmlonly */
526 /* > Download DLATBS + dependencies */
527 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dlatbs.
528 f"> */
529 /* > [TGZ]</a> */
530 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dlatbs.
531 f"> */
532 /* > [ZIP]</a> */
533 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dlatbs.
534 f"> */
535 /* > [TXT]</a> */
536 /* > \endhtmlonly */
537
538 /*  Definition: */
539 /*  =========== */
540
541 /*       SUBROUTINE DLATBS( UPLO, TRANS, DIAG, NORMIN, N, KD, AB, LDAB, X, */
542 /*                          SCALE, CNORM, INFO ) */
543
544 /*       CHARACTER          DIAG, NORMIN, TRANS, UPLO */
545 /*       INTEGER            INFO, KD, LDAB, N */
546 /*       DOUBLE PRECISION   SCALE */
547 /*       DOUBLE PRECISION   AB( LDAB, * ), CNORM( * ), X( * ) */
548
549
550 /* > \par Purpose: */
551 /*  ============= */
552 /* > */
553 /* > \verbatim */
554 /* > */
555 /* > DLATBS solves one of the triangular systems */
556 /* > */
557 /* >    A *x = s*b  or  A**T*x = s*b */
558 /* > */
559 /* > with scaling to prevent overflow, where A is an upper or lower */
560 /* > triangular band matrix.  Here A**T denotes the transpose of A, x and b */
561 /* > are n-element vectors, and s is a scaling factor, usually less than */
562 /* > or equal to 1, chosen so that the components of x will be less than */
563 /* > the overflow threshold.  If the unscaled problem will not cause */
564 /* > overflow, the Level 2 BLAS routine DTBSV is called.  If the matrix A */
565 /* > is singular (A(j,j) = 0 for some j), then s is set to 0 and a */
566 /* > non-trivial solution to A*x = 0 is returned. */
567 /* > \endverbatim */
568
569 /*  Arguments: */
570 /*  ========== */
571
572 /* > \param[in] UPLO */
573 /* > \verbatim */
574 /* >          UPLO is CHARACTER*1 */
575 /* >          Specifies whether the matrix A is upper or lower triangular. */
576 /* >          = 'U':  Upper triangular */
577 /* >          = 'L':  Lower triangular */
578 /* > \endverbatim */
579 /* > */
580 /* > \param[in] TRANS */
581 /* > \verbatim */
582 /* >          TRANS is CHARACTER*1 */
583 /* >          Specifies the operation applied to A. */
584 /* >          = 'N':  Solve A * x = s*b  (No transpose) */
585 /* >          = 'T':  Solve A**T* x = s*b  (Transpose) */
586 /* >          = 'C':  Solve A**T* x = s*b  (Conjugate transpose = Transpose) */
587 /* > \endverbatim */
588 /* > */
589 /* > \param[in] DIAG */
590 /* > \verbatim */
591 /* >          DIAG is CHARACTER*1 */
592 /* >          Specifies whether or not the matrix A is unit triangular. */
593 /* >          = 'N':  Non-unit triangular */
594 /* >          = 'U':  Unit triangular */
595 /* > \endverbatim */
596 /* > */
597 /* > \param[in] NORMIN */
598 /* > \verbatim */
599 /* >          NORMIN is CHARACTER*1 */
600 /* >          Specifies whether CNORM has been set or not. */
601 /* >          = 'Y':  CNORM contains the column norms on entry */
602 /* >          = 'N':  CNORM is not set on entry.  On exit, the norms will */
603 /* >                  be computed and stored in CNORM. */
604 /* > \endverbatim */
605 /* > */
606 /* > \param[in] N */
607 /* > \verbatim */
608 /* >          N is INTEGER */
609 /* >          The order of the matrix A.  N >= 0. */
610 /* > \endverbatim */
611 /* > */
612 /* > \param[in] KD */
613 /* > \verbatim */
614 /* >          KD is INTEGER */
615 /* >          The number of subdiagonals or superdiagonals in the */
616 /* >          triangular matrix A.  KD >= 0. */
617 /* > \endverbatim */
618 /* > */
619 /* > \param[in] AB */
620 /* > \verbatim */
621 /* >          AB is DOUBLE PRECISION array, dimension (LDAB,N) */
622 /* >          The upper or lower triangular band matrix A, stored in the */
623 /* >          first KD+1 rows of the array. The j-th column of A is stored */
624 /* >          in the j-th column of the array AB as follows: */
625 /* >          if UPLO = 'U', AB(kd+1+i-j,j) = A(i,j) for f2cmax(1,j-kd)<=i<=j; */
626 /* >          if UPLO = 'L', AB(1+i-j,j)    = A(i,j) for j<=i<=f2cmin(n,j+kd). */
627 /* > \endverbatim */
628 /* > */
629 /* > \param[in] LDAB */
630 /* > \verbatim */
631 /* >          LDAB is INTEGER */
632 /* >          The leading dimension of the array AB.  LDAB >= KD+1. */
633 /* > \endverbatim */
634 /* > */
635 /* > \param[in,out] X */
636 /* > \verbatim */
637 /* >          X is DOUBLE PRECISION array, dimension (N) */
638 /* >          On entry, the right hand side b of the triangular system. */
639 /* >          On exit, X is overwritten by the solution vector x. */
640 /* > \endverbatim */
641 /* > */
642 /* > \param[out] SCALE */
643 /* > \verbatim */
644 /* >          SCALE is DOUBLE PRECISION */
645 /* >          The scaling factor s for the triangular system */
646 /* >             A * x = s*b  or  A**T* x = s*b. */
647 /* >          If SCALE = 0, the matrix A is singular or badly scaled, and */
648 /* >          the vector x is an exact or approximate solution to A*x = 0. */
649 /* > \endverbatim */
650 /* > */
651 /* > \param[in,out] CNORM */
652 /* > \verbatim */
653 /* >          CNORM is DOUBLE PRECISION array, dimension (N) */
654 /* > */
655 /* >          If NORMIN = 'Y', CNORM is an input argument and CNORM(j) */
656 /* >          contains the norm of the off-diagonal part of the j-th column */
657 /* >          of A.  If TRANS = 'N', CNORM(j) must be greater than or equal */
658 /* >          to the infinity-norm, and if TRANS = 'T' or 'C', CNORM(j) */
659 /* >          must be greater than or equal to the 1-norm. */
660 /* > */
661 /* >          If NORMIN = 'N', CNORM is an output argument and CNORM(j) */
662 /* >          returns the 1-norm of the offdiagonal part of the j-th column */
663 /* >          of A. */
664 /* > \endverbatim */
665 /* > */
666 /* > \param[out] INFO */
667 /* > \verbatim */
668 /* >          INFO is INTEGER */
669 /* >          = 0:  successful exit */
670 /* >          < 0:  if INFO = -k, the k-th argument had an illegal value */
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 /* > \par Further Details: */
686 /*  ===================== */
687 /* > */
688 /* > \verbatim */
689 /* > */
690 /* >  A rough bound on x is computed; if that is less than overflow, DTBSV */
691 /* >  is called, otherwise, specific code is used which checks for possible */
692 /* >  overflow or divide-by-zero at every operation. */
693 /* > */
694 /* >  A columnwise scheme is used for solving A*x = b.  The basic algorithm */
695 /* >  if A is lower triangular is */
696 /* > */
697 /* >       x[1:n] := b[1:n] */
698 /* >       for j = 1, ..., n */
699 /* >            x(j) := x(j) / A(j,j) */
700 /* >            x[j+1:n] := x[j+1:n] - x(j) * A[j+1:n,j] */
701 /* >       end */
702 /* > */
703 /* >  Define bounds on the components of x after j iterations of the loop: */
704 /* >     M(j) = bound on x[1:j] */
705 /* >     G(j) = bound on x[j+1:n] */
706 /* >  Initially, let M(0) = 0 and G(0) = f2cmax{x(i), i=1,...,n}. */
707 /* > */
708 /* >  Then for iteration j+1 we have */
709 /* >     M(j+1) <= G(j) / | A(j+1,j+1) | */
710 /* >     G(j+1) <= G(j) + M(j+1) * | A[j+2:n,j+1] | */
711 /* >            <= G(j) ( 1 + CNORM(j+1) / | A(j+1,j+1) | ) */
712 /* > */
713 /* >  where CNORM(j+1) is greater than or equal to the infinity-norm of */
714 /* >  column j+1 of A, not counting the diagonal.  Hence */
715 /* > */
716 /* >     G(j) <= G(0) product ( 1 + CNORM(i) / | A(i,i) | ) */
717 /* >                  1<=i<=j */
718 /* >  and */
719 /* > */
720 /* >     |x(j)| <= ( G(0) / |A(j,j)| ) product ( 1 + CNORM(i) / |A(i,i)| ) */
721 /* >                                   1<=i< j */
722 /* > */
723 /* >  Since |x(j)| <= M(j), we use the Level 2 BLAS routine DTBSV if the */
724 /* >  reciprocal of the largest M(j), j=1,..,n, is larger than */
725 /* >  f2cmax(underflow, 1/overflow). */
726 /* > */
727 /* >  The bound on x(j) is also used to determine when a step in the */
728 /* >  columnwise method can be performed without fear of overflow.  If */
729 /* >  the computed bound is greater than a large constant, x is scaled to */
730 /* >  prevent overflow, but if the bound overflows, x is set to 0, x(j) to */
731 /* >  1, and scale to 0, and a non-trivial solution to A*x = 0 is found. */
732 /* > */
733 /* >  Similarly, a row-wise scheme is used to solve A**T*x = b.  The basic */
734 /* >  algorithm for A upper triangular is */
735 /* > */
736 /* >       for j = 1, ..., n */
737 /* >            x(j) := ( b(j) - A[1:j-1,j]**T * x[1:j-1] ) / A(j,j) */
738 /* >       end */
739 /* > */
740 /* >  We simultaneously compute two bounds */
741 /* >       G(j) = bound on ( b(i) - A[1:i-1,i]**T * x[1:i-1] ), 1<=i<=j */
742 /* >       M(j) = bound on x(i), 1<=i<=j */
743 /* > */
744 /* >  The initial values are G(0) = 0, M(0) = f2cmax{b(i), i=1,..,n}, and we */
745 /* >  add the constraint G(j) >= G(j-1) and M(j) >= M(j-1) for j >= 1. */
746 /* >  Then the bound on x(j) is */
747 /* > */
748 /* >       M(j) <= M(j-1) * ( 1 + CNORM(j) ) / | A(j,j) | */
749 /* > */
750 /* >            <= M(0) * product ( ( 1 + CNORM(i) ) / |A(i,i)| ) */
751 /* >                      1<=i<=j */
752 /* > */
753 /* >  and we can safely call DTBSV if 1/M(n) and 1/G(n) are both greater */
754 /* >  than f2cmax(underflow, 1/overflow). */
755 /* > \endverbatim */
756 /* > */
757 /*  ===================================================================== */
758 /* Subroutine */ int dlatbs_(char *uplo, char *trans, char *diag, char *
759         normin, integer *n, integer *kd, doublereal *ab, integer *ldab, 
760         doublereal *x, doublereal *scale, doublereal *cnorm, integer *info)
761 {
762     /* System generated locals */
763     integer ab_dim1, ab_offset, i__1, i__2, i__3, i__4;
764     doublereal d__1, d__2, d__3;
765
766     /* Local variables */
767     integer jinc, jlen;
768     extern doublereal ddot_(integer *, doublereal *, integer *, doublereal *, 
769             integer *);
770     doublereal xbnd;
771     integer imax;
772     doublereal tmax, tjjs, xmax, grow, sumj;
773     integer i__, j;
774     extern /* Subroutine */ int dscal_(integer *, doublereal *, doublereal *, 
775             integer *);
776     integer maind;
777     extern logical lsame_(char *, char *);
778     doublereal tscal, uscal;
779     extern doublereal dasum_(integer *, doublereal *, integer *);
780     integer jlast;
781     extern /* Subroutine */ int dtbsv_(char *, char *, char *, integer *, 
782             integer *, doublereal *, integer *, doublereal *, integer *), daxpy_(integer *, doublereal *, 
783             doublereal *, integer *, doublereal *, integer *);
784     logical upper;
785     extern doublereal dlamch_(char *);
786     doublereal xj;
787     extern integer idamax_(integer *, doublereal *, integer *);
788     extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen);
789     doublereal bignum;
790     logical notran;
791     integer jfirst;
792     doublereal smlnum;
793     logical nounit;
794     doublereal rec, tjj;
795
796
797 /*  -- LAPACK auxiliary routine (version 3.7.0) -- */
798 /*  -- LAPACK is a software package provided by Univ. of Tennessee,    -- */
799 /*  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
800 /*     December 2016 */
801
802
803 /*  ===================================================================== */
804
805
806     /* Parameter adjustments */
807     ab_dim1 = *ldab;
808     ab_offset = 1 + ab_dim1 * 1;
809     ab -= ab_offset;
810     --x;
811     --cnorm;
812
813     /* Function Body */
814     *info = 0;
815     upper = lsame_(uplo, "U");
816     notran = lsame_(trans, "N");
817     nounit = lsame_(diag, "N");
818
819 /*     Test the input parameters. */
820
821     if (! upper && ! lsame_(uplo, "L")) {
822         *info = -1;
823     } else if (! notran && ! lsame_(trans, "T") && ! 
824             lsame_(trans, "C")) {
825         *info = -2;
826     } else if (! nounit && ! lsame_(diag, "U")) {
827         *info = -3;
828     } else if (! lsame_(normin, "Y") && ! lsame_(normin,
829              "N")) {
830         *info = -4;
831     } else if (*n < 0) {
832         *info = -5;
833     } else if (*kd < 0) {
834         *info = -6;
835     } else if (*ldab < *kd + 1) {
836         *info = -8;
837     }
838     if (*info != 0) {
839         i__1 = -(*info);
840         xerbla_("DLATBS", &i__1, (ftnlen)6);
841         return 0;
842     }
843
844 /*     Quick return if possible */
845
846     if (*n == 0) {
847         return 0;
848     }
849
850 /*     Determine machine dependent parameters to control overflow. */
851
852     smlnum = dlamch_("Safe minimum") / dlamch_("Precision");
853     bignum = 1. / smlnum;
854     *scale = 1.;
855
856     if (lsame_(normin, "N")) {
857
858 /*        Compute the 1-norm of each column, not including the diagonal. */
859
860         if (upper) {
861
862 /*           A is upper triangular. */
863
864             i__1 = *n;
865             for (j = 1; j <= i__1; ++j) {
866 /* Computing MIN */
867                 i__2 = *kd, i__3 = j - 1;
868                 jlen = f2cmin(i__2,i__3);
869                 cnorm[j] = dasum_(&jlen, &ab[*kd + 1 - jlen + j * ab_dim1], &
870                         c__1);
871 /* L10: */
872             }
873         } else {
874
875 /*           A is lower triangular. */
876
877             i__1 = *n;
878             for (j = 1; j <= i__1; ++j) {
879 /* Computing MIN */
880                 i__2 = *kd, i__3 = *n - j;
881                 jlen = f2cmin(i__2,i__3);
882                 if (jlen > 0) {
883                     cnorm[j] = dasum_(&jlen, &ab[j * ab_dim1 + 2], &c__1);
884                 } else {
885                     cnorm[j] = 0.;
886                 }
887 /* L20: */
888             }
889         }
890     }
891
892 /*     Scale the column norms by TSCAL if the maximum element in CNORM is */
893 /*     greater than BIGNUM. */
894
895     imax = idamax_(n, &cnorm[1], &c__1);
896     tmax = cnorm[imax];
897     if (tmax <= bignum) {
898         tscal = 1.;
899     } else {
900         tscal = 1. / (smlnum * tmax);
901         dscal_(n, &tscal, &cnorm[1], &c__1);
902     }
903
904 /*     Compute a bound on the computed solution vector to see if the */
905 /*     Level 2 BLAS routine DTBSV can be used. */
906
907     j = idamax_(n, &x[1], &c__1);
908     xmax = (d__1 = x[j], abs(d__1));
909     xbnd = xmax;
910     if (notran) {
911
912 /*        Compute the growth in A * x = b. */
913
914         if (upper) {
915             jfirst = *n;
916             jlast = 1;
917             jinc = -1;
918             maind = *kd + 1;
919         } else {
920             jfirst = 1;
921             jlast = *n;
922             jinc = 1;
923             maind = 1;
924         }
925
926         if (tscal != 1.) {
927             grow = 0.;
928             goto L50;
929         }
930
931         if (nounit) {
932
933 /*           A is non-unit triangular. */
934
935 /*           Compute GROW = 1/G(j) and XBND = 1/M(j). */
936 /*           Initially, G(0) = f2cmax{x(i), i=1,...,n}. */
937
938             grow = 1. / f2cmax(xbnd,smlnum);
939             xbnd = grow;
940             i__1 = jlast;
941             i__2 = jinc;
942             for (j = jfirst; i__2 < 0 ? j >= i__1 : j <= i__1; j += i__2) {
943
944 /*              Exit the loop if the growth factor is too small. */
945
946                 if (grow <= smlnum) {
947                     goto L50;
948                 }
949
950 /*              M(j) = G(j-1) / abs(A(j,j)) */
951
952                 tjj = (d__1 = ab[maind + j * ab_dim1], abs(d__1));
953 /* Computing MIN */
954                 d__1 = xbnd, d__2 = f2cmin(1.,tjj) * grow;
955                 xbnd = f2cmin(d__1,d__2);
956                 if (tjj + cnorm[j] >= smlnum) {
957
958 /*                 G(j) = G(j-1)*( 1 + CNORM(j) / abs(A(j,j)) ) */
959
960                     grow *= tjj / (tjj + cnorm[j]);
961                 } else {
962
963 /*                 G(j) could overflow, set GROW to 0. */
964
965                     grow = 0.;
966                 }
967 /* L30: */
968             }
969             grow = xbnd;
970         } else {
971
972 /*           A is unit triangular. */
973
974 /*           Compute GROW = 1/G(j), where G(0) = f2cmax{x(i), i=1,...,n}. */
975
976 /* Computing MIN */
977             d__1 = 1., d__2 = 1. / f2cmax(xbnd,smlnum);
978             grow = f2cmin(d__1,d__2);
979             i__2 = jlast;
980             i__1 = jinc;
981             for (j = jfirst; i__1 < 0 ? j >= i__2 : j <= i__2; j += i__1) {
982
983 /*              Exit the loop if the growth factor is too small. */
984
985                 if (grow <= smlnum) {
986                     goto L50;
987                 }
988
989 /*              G(j) = G(j-1)*( 1 + CNORM(j) ) */
990
991                 grow *= 1. / (cnorm[j] + 1.);
992 /* L40: */
993             }
994         }
995 L50:
996
997         ;
998     } else {
999
1000 /*        Compute the growth in A**T * x = b. */
1001
1002         if (upper) {
1003             jfirst = 1;
1004             jlast = *n;
1005             jinc = 1;
1006             maind = *kd + 1;
1007         } else {
1008             jfirst = *n;
1009             jlast = 1;
1010             jinc = -1;
1011             maind = 1;
1012         }
1013
1014         if (tscal != 1.) {
1015             grow = 0.;
1016             goto L80;
1017         }
1018
1019         if (nounit) {
1020
1021 /*           A is non-unit triangular. */
1022
1023 /*           Compute GROW = 1/G(j) and XBND = 1/M(j). */
1024 /*           Initially, M(0) = f2cmax{x(i), i=1,...,n}. */
1025
1026             grow = 1. / f2cmax(xbnd,smlnum);
1027             xbnd = grow;
1028             i__1 = jlast;
1029             i__2 = jinc;
1030             for (j = jfirst; i__2 < 0 ? j >= i__1 : j <= i__1; j += i__2) {
1031
1032 /*              Exit the loop if the growth factor is too small. */
1033
1034                 if (grow <= smlnum) {
1035                     goto L80;
1036                 }
1037
1038 /*              G(j) = f2cmax( G(j-1), M(j-1)*( 1 + CNORM(j) ) ) */
1039
1040                 xj = cnorm[j] + 1.;
1041 /* Computing MIN */
1042                 d__1 = grow, d__2 = xbnd / xj;
1043                 grow = f2cmin(d__1,d__2);
1044
1045 /*              M(j) = M(j-1)*( 1 + CNORM(j) ) / abs(A(j,j)) */
1046
1047                 tjj = (d__1 = ab[maind + j * ab_dim1], abs(d__1));
1048                 if (xj > tjj) {
1049                     xbnd *= tjj / xj;
1050                 }
1051 /* L60: */
1052             }
1053             grow = f2cmin(grow,xbnd);
1054         } else {
1055
1056 /*           A is unit triangular. */
1057
1058 /*           Compute GROW = 1/G(j), where G(0) = f2cmax{x(i), i=1,...,n}. */
1059
1060 /* Computing MIN */
1061             d__1 = 1., d__2 = 1. / f2cmax(xbnd,smlnum);
1062             grow = f2cmin(d__1,d__2);
1063             i__2 = jlast;
1064             i__1 = jinc;
1065             for (j = jfirst; i__1 < 0 ? j >= i__2 : j <= i__2; j += i__1) {
1066
1067 /*              Exit the loop if the growth factor is too small. */
1068
1069                 if (grow <= smlnum) {
1070                     goto L80;
1071                 }
1072
1073 /*              G(j) = ( 1 + CNORM(j) )*G(j-1) */
1074
1075                 xj = cnorm[j] + 1.;
1076                 grow /= xj;
1077 /* L70: */
1078             }
1079         }
1080 L80:
1081         ;
1082     }
1083
1084     if (grow * tscal > smlnum) {
1085
1086 /*        Use the Level 2 BLAS solve if the reciprocal of the bound on */
1087 /*        elements of X is not too small. */
1088
1089         dtbsv_(uplo, trans, diag, n, kd, &ab[ab_offset], ldab, &x[1], &c__1);
1090     } else {
1091
1092 /*        Use a Level 1 BLAS solve, scaling intermediate results. */
1093
1094         if (xmax > bignum) {
1095
1096 /*           Scale X so that its components are less than or equal to */
1097 /*           BIGNUM in absolute value. */
1098
1099             *scale = bignum / xmax;
1100             dscal_(n, scale, &x[1], &c__1);
1101             xmax = bignum;
1102         }
1103
1104         if (notran) {
1105
1106 /*           Solve A * x = b */
1107
1108             i__1 = jlast;
1109             i__2 = jinc;
1110             for (j = jfirst; i__2 < 0 ? j >= i__1 : j <= i__1; j += i__2) {
1111
1112 /*              Compute x(j) = b(j) / A(j,j), scaling x if necessary. */
1113
1114                 xj = (d__1 = x[j], abs(d__1));
1115                 if (nounit) {
1116                     tjjs = ab[maind + j * ab_dim1] * tscal;
1117                 } else {
1118                     tjjs = tscal;
1119                     if (tscal == 1.) {
1120                         goto L100;
1121                     }
1122                 }
1123                 tjj = abs(tjjs);
1124                 if (tjj > smlnum) {
1125
1126 /*                    abs(A(j,j)) > SMLNUM: */
1127
1128                     if (tjj < 1.) {
1129                         if (xj > tjj * bignum) {
1130
1131 /*                          Scale x by 1/b(j). */
1132
1133                             rec = 1. / xj;
1134                             dscal_(n, &rec, &x[1], &c__1);
1135                             *scale *= rec;
1136                             xmax *= rec;
1137                         }
1138                     }
1139                     x[j] /= tjjs;
1140                     xj = (d__1 = x[j], abs(d__1));
1141                 } else if (tjj > 0.) {
1142
1143 /*                    0 < abs(A(j,j)) <= SMLNUM: */
1144
1145                     if (xj > tjj * bignum) {
1146
1147 /*                       Scale x by (1/abs(x(j)))*abs(A(j,j))*BIGNUM */
1148 /*                       to avoid overflow when dividing by A(j,j). */
1149
1150                         rec = tjj * bignum / xj;
1151                         if (cnorm[j] > 1.) {
1152
1153 /*                          Scale by 1/CNORM(j) to avoid overflow when */
1154 /*                          multiplying x(j) times column j. */
1155
1156                             rec /= cnorm[j];
1157                         }
1158                         dscal_(n, &rec, &x[1], &c__1);
1159                         *scale *= rec;
1160                         xmax *= rec;
1161                     }
1162                     x[j] /= tjjs;
1163                     xj = (d__1 = x[j], abs(d__1));
1164                 } else {
1165
1166 /*                    A(j,j) = 0:  Set x(1:n) = 0, x(j) = 1, and */
1167 /*                    scale = 0, and compute a solution to A*x = 0. */
1168
1169                     i__3 = *n;
1170                     for (i__ = 1; i__ <= i__3; ++i__) {
1171                         x[i__] = 0.;
1172 /* L90: */
1173                     }
1174                     x[j] = 1.;
1175                     xj = 1.;
1176                     *scale = 0.;
1177                     xmax = 0.;
1178                 }
1179 L100:
1180
1181 /*              Scale x if necessary to avoid overflow when adding a */
1182 /*              multiple of column j of A. */
1183
1184                 if (xj > 1.) {
1185                     rec = 1. / xj;
1186                     if (cnorm[j] > (bignum - xmax) * rec) {
1187
1188 /*                    Scale x by 1/(2*abs(x(j))). */
1189
1190                         rec *= .5;
1191                         dscal_(n, &rec, &x[1], &c__1);
1192                         *scale *= rec;
1193                     }
1194                 } else if (xj * cnorm[j] > bignum - xmax) {
1195
1196 /*                 Scale x by 1/2. */
1197
1198                     dscal_(n, &c_b36, &x[1], &c__1);
1199                     *scale *= .5;
1200                 }
1201
1202                 if (upper) {
1203                     if (j > 1) {
1204
1205 /*                    Compute the update */
1206 /*                       x(f2cmax(1,j-kd):j-1) := x(f2cmax(1,j-kd):j-1) - */
1207 /*                                             x(j)* A(f2cmax(1,j-kd):j-1,j) */
1208
1209 /* Computing MIN */
1210                         i__3 = *kd, i__4 = j - 1;
1211                         jlen = f2cmin(i__3,i__4);
1212                         d__1 = -x[j] * tscal;
1213                         daxpy_(&jlen, &d__1, &ab[*kd + 1 - jlen + j * ab_dim1]
1214                                 , &c__1, &x[j - jlen], &c__1);
1215                         i__3 = j - 1;
1216                         i__ = idamax_(&i__3, &x[1], &c__1);
1217                         xmax = (d__1 = x[i__], abs(d__1));
1218                     }
1219                 } else if (j < *n) {
1220
1221 /*                 Compute the update */
1222 /*                    x(j+1:f2cmin(j+kd,n)) := x(j+1:f2cmin(j+kd,n)) - */
1223 /*                                          x(j) * A(j+1:f2cmin(j+kd,n),j) */
1224
1225 /* Computing MIN */
1226                     i__3 = *kd, i__4 = *n - j;
1227                     jlen = f2cmin(i__3,i__4);
1228                     if (jlen > 0) {
1229                         d__1 = -x[j] * tscal;
1230                         daxpy_(&jlen, &d__1, &ab[j * ab_dim1 + 2], &c__1, &x[
1231                                 j + 1], &c__1);
1232                     }
1233                     i__3 = *n - j;
1234                     i__ = j + idamax_(&i__3, &x[j + 1], &c__1);
1235                     xmax = (d__1 = x[i__], abs(d__1));
1236                 }
1237 /* L110: */
1238             }
1239
1240         } else {
1241
1242 /*           Solve A**T * x = b */
1243
1244             i__2 = jlast;
1245             i__1 = jinc;
1246             for (j = jfirst; i__1 < 0 ? j >= i__2 : j <= i__2; j += i__1) {
1247
1248 /*              Compute x(j) = b(j) - sum A(k,j)*x(k). */
1249 /*                                    k<>j */
1250
1251                 xj = (d__1 = x[j], abs(d__1));
1252                 uscal = tscal;
1253                 rec = 1. / f2cmax(xmax,1.);
1254                 if (cnorm[j] > (bignum - xj) * rec) {
1255
1256 /*                 If x(j) could overflow, scale x by 1/(2*XMAX). */
1257
1258                     rec *= .5;
1259                     if (nounit) {
1260                         tjjs = ab[maind + j * ab_dim1] * tscal;
1261                     } else {
1262                         tjjs = tscal;
1263                     }
1264                     tjj = abs(tjjs);
1265                     if (tjj > 1.) {
1266
1267 /*                       Divide by A(j,j) when scaling x if A(j,j) > 1. */
1268
1269 /* Computing MIN */
1270                         d__1 = 1., d__2 = rec * tjj;
1271                         rec = f2cmin(d__1,d__2);
1272                         uscal /= tjjs;
1273                     }
1274                     if (rec < 1.) {
1275                         dscal_(n, &rec, &x[1], &c__1);
1276                         *scale *= rec;
1277                         xmax *= rec;
1278                     }
1279                 }
1280
1281                 sumj = 0.;
1282                 if (uscal == 1.) {
1283
1284 /*                 If the scaling needed for A in the dot product is 1, */
1285 /*                 call DDOT to perform the dot product. */
1286
1287                     if (upper) {
1288 /* Computing MIN */
1289                         i__3 = *kd, i__4 = j - 1;
1290                         jlen = f2cmin(i__3,i__4);
1291                         sumj = ddot_(&jlen, &ab[*kd + 1 - jlen + j * ab_dim1],
1292                                  &c__1, &x[j - jlen], &c__1);
1293                     } else {
1294 /* Computing MIN */
1295                         i__3 = *kd, i__4 = *n - j;
1296                         jlen = f2cmin(i__3,i__4);
1297                         if (jlen > 0) {
1298                             sumj = ddot_(&jlen, &ab[j * ab_dim1 + 2], &c__1, &
1299                                     x[j + 1], &c__1);
1300                         }
1301                     }
1302                 } else {
1303
1304 /*                 Otherwise, use in-line code for the dot product. */
1305
1306                     if (upper) {
1307 /* Computing MIN */
1308                         i__3 = *kd, i__4 = j - 1;
1309                         jlen = f2cmin(i__3,i__4);
1310                         i__3 = jlen;
1311                         for (i__ = 1; i__ <= i__3; ++i__) {
1312                             sumj += ab[*kd + i__ - jlen + j * ab_dim1] * 
1313                                     uscal * x[j - jlen - 1 + i__];
1314 /* L120: */
1315                         }
1316                     } else {
1317 /* Computing MIN */
1318                         i__3 = *kd, i__4 = *n - j;
1319                         jlen = f2cmin(i__3,i__4);
1320                         i__3 = jlen;
1321                         for (i__ = 1; i__ <= i__3; ++i__) {
1322                             sumj += ab[i__ + 1 + j * ab_dim1] * uscal * x[j + 
1323                                     i__];
1324 /* L130: */
1325                         }
1326                     }
1327                 }
1328
1329                 if (uscal == tscal) {
1330
1331 /*                 Compute x(j) := ( x(j) - sumj ) / A(j,j) if 1/A(j,j) */
1332 /*                 was not used to scale the dotproduct. */
1333
1334                     x[j] -= sumj;
1335                     xj = (d__1 = x[j], abs(d__1));
1336                     if (nounit) {
1337
1338 /*                    Compute x(j) = x(j) / A(j,j), scaling if necessary. */
1339
1340                         tjjs = ab[maind + j * ab_dim1] * tscal;
1341                     } else {
1342                         tjjs = tscal;
1343                         if (tscal == 1.) {
1344                             goto L150;
1345                         }
1346                     }
1347                     tjj = abs(tjjs);
1348                     if (tjj > smlnum) {
1349
1350 /*                       abs(A(j,j)) > SMLNUM: */
1351
1352                         if (tjj < 1.) {
1353                             if (xj > tjj * bignum) {
1354
1355 /*                             Scale X by 1/abs(x(j)). */
1356
1357                                 rec = 1. / xj;
1358                                 dscal_(n, &rec, &x[1], &c__1);
1359                                 *scale *= rec;
1360                                 xmax *= rec;
1361                             }
1362                         }
1363                         x[j] /= tjjs;
1364                     } else if (tjj > 0.) {
1365
1366 /*                       0 < abs(A(j,j)) <= SMLNUM: */
1367
1368                         if (xj > tjj * bignum) {
1369
1370 /*                          Scale x by (1/abs(x(j)))*abs(A(j,j))*BIGNUM. */
1371
1372                             rec = tjj * bignum / xj;
1373                             dscal_(n, &rec, &x[1], &c__1);
1374                             *scale *= rec;
1375                             xmax *= rec;
1376                         }
1377                         x[j] /= tjjs;
1378                     } else {
1379
1380 /*                       A(j,j) = 0:  Set x(1:n) = 0, x(j) = 1, and */
1381 /*                       scale = 0, and compute a solution to A**T*x = 0. */
1382
1383                         i__3 = *n;
1384                         for (i__ = 1; i__ <= i__3; ++i__) {
1385                             x[i__] = 0.;
1386 /* L140: */
1387                         }
1388                         x[j] = 1.;
1389                         *scale = 0.;
1390                         xmax = 0.;
1391                     }
1392 L150:
1393                     ;
1394                 } else {
1395
1396 /*                 Compute x(j) := x(j) / A(j,j) - sumj if the dot */
1397 /*                 product has already been divided by 1/A(j,j). */
1398
1399                     x[j] = x[j] / tjjs - sumj;
1400                 }
1401 /* Computing MAX */
1402                 d__2 = xmax, d__3 = (d__1 = x[j], abs(d__1));
1403                 xmax = f2cmax(d__2,d__3);
1404 /* L160: */
1405             }
1406         }
1407         *scale /= tscal;
1408     }
1409
1410 /*     Scale the column norms by 1/TSCAL for return. */
1411
1412     if (tscal != 1.) {
1413         d__1 = 1. / tscal;
1414         dscal_(n, &d__1, &cnorm[1], &c__1);
1415     }
1416
1417     return 0;
1418
1419 /*     End of DLATBS */
1420
1421 } /* dlatbs_ */
1422