C_LAPACK: Fixes to make it compile with MSVC (#3605)
[platform/upstream/openblas.git] / lapack-netlib / SRC / clatps.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 real c_b36 = .5f;
517
518 /* > \brief \b CLATPS solves a triangular system of equations with the matrix held in packed storage. */
519
520 /*  =========== DOCUMENTATION =========== */
521
522 /* Online html documentation available at */
523 /*            http://www.netlib.org/lapack/explore-html/ */
524
525 /* > \htmlonly */
526 /* > Download CLATPS + dependencies */
527 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/clatps.
528 f"> */
529 /* > [TGZ]</a> */
530 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/clatps.
531 f"> */
532 /* > [ZIP]</a> */
533 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/clatps.
534 f"> */
535 /* > [TXT]</a> */
536 /* > \endhtmlonly */
537
538 /*  Definition: */
539 /*  =========== */
540
541 /*       SUBROUTINE CLATPS( UPLO, TRANS, DIAG, NORMIN, N, AP, X, SCALE, */
542 /*                          CNORM, INFO ) */
543
544 /*       CHARACTER          DIAG, NORMIN, TRANS, UPLO */
545 /*       INTEGER            INFO, N */
546 /*       REAL               SCALE */
547 /*       REAL               CNORM( * ) */
548 /*       COMPLEX            AP( * ), X( * ) */
549
550
551 /* > \par Purpose: */
552 /*  ============= */
553 /* > */
554 /* > \verbatim */
555 /* > */
556 /* > CLATPS solves one of the triangular systems */
557 /* > */
558 /* >    A * x = s*b,  A**T * x = s*b,  or  A**H * x = s*b, */
559 /* > */
560 /* > with scaling to prevent overflow, where A is an upper or lower */
561 /* > triangular matrix stored in packed form.  Here A**T denotes the */
562 /* > transpose of A, A**H denotes the conjugate transpose of A, x and b */
563 /* > are n-element vectors, and s is a scaling factor, usually less than */
564 /* > or equal to 1, chosen so that the components of x will be less than */
565 /* > the overflow threshold.  If the unscaled problem will not cause */
566 /* > overflow, the Level 2 BLAS routine CTPSV is called. If the matrix A */
567 /* > is singular (A(j,j) = 0 for some j), then s is set to 0 and a */
568 /* > non-trivial solution to A*x = 0 is returned. */
569 /* > \endverbatim */
570
571 /*  Arguments: */
572 /*  ========== */
573
574 /* > \param[in] UPLO */
575 /* > \verbatim */
576 /* >          UPLO is CHARACTER*1 */
577 /* >          Specifies whether the matrix A is upper or lower triangular. */
578 /* >          = 'U':  Upper triangular */
579 /* >          = 'L':  Lower triangular */
580 /* > \endverbatim */
581 /* > */
582 /* > \param[in] TRANS */
583 /* > \verbatim */
584 /* >          TRANS is CHARACTER*1 */
585 /* >          Specifies the operation applied to A. */
586 /* >          = 'N':  Solve A * x = s*b     (No transpose) */
587 /* >          = 'T':  Solve A**T * x = s*b  (Transpose) */
588 /* >          = 'C':  Solve A**H * x = s*b  (Conjugate transpose) */
589 /* > \endverbatim */
590 /* > */
591 /* > \param[in] DIAG */
592 /* > \verbatim */
593 /* >          DIAG is CHARACTER*1 */
594 /* >          Specifies whether or not the matrix A is unit triangular. */
595 /* >          = 'N':  Non-unit triangular */
596 /* >          = 'U':  Unit triangular */
597 /* > \endverbatim */
598 /* > */
599 /* > \param[in] NORMIN */
600 /* > \verbatim */
601 /* >          NORMIN is CHARACTER*1 */
602 /* >          Specifies whether CNORM has been set or not. */
603 /* >          = 'Y':  CNORM contains the column norms on entry */
604 /* >          = 'N':  CNORM is not set on entry.  On exit, the norms will */
605 /* >                  be computed and stored in CNORM. */
606 /* > \endverbatim */
607 /* > */
608 /* > \param[in] N */
609 /* > \verbatim */
610 /* >          N is INTEGER */
611 /* >          The order of the matrix A.  N >= 0. */
612 /* > \endverbatim */
613 /* > */
614 /* > \param[in] AP */
615 /* > \verbatim */
616 /* >          AP is COMPLEX array, dimension (N*(N+1)/2) */
617 /* >          The upper or lower triangular matrix A, packed columnwise in */
618 /* >          a linear array.  The j-th column of A is stored in the array */
619 /* >          AP as follows: */
620 /* >          if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j; */
621 /* >          if UPLO = 'L', AP(i + (j-1)*(2n-j)/2) = A(i,j) for j<=i<=n. */
622 /* > \endverbatim */
623 /* > */
624 /* > \param[in,out] X */
625 /* > \verbatim */
626 /* >          X is COMPLEX array, dimension (N) */
627 /* >          On entry, the right hand side b of the triangular system. */
628 /* >          On exit, X is overwritten by the solution vector x. */
629 /* > \endverbatim */
630 /* > */
631 /* > \param[out] SCALE */
632 /* > \verbatim */
633 /* >          SCALE is REAL */
634 /* >          The scaling factor s for the triangular system */
635 /* >             A * x = s*b,  A**T * x = s*b,  or  A**H * x = s*b. */
636 /* >          If SCALE = 0, the matrix A is singular or badly scaled, and */
637 /* >          the vector x is an exact or approximate solution to A*x = 0. */
638 /* > \endverbatim */
639 /* > */
640 /* > \param[in,out] CNORM */
641 /* > \verbatim */
642 /* >          CNORM is REAL array, dimension (N) */
643 /* > */
644 /* >          If NORMIN = 'Y', CNORM is an input argument and CNORM(j) */
645 /* >          contains the norm of the off-diagonal part of the j-th column */
646 /* >          of A.  If TRANS = 'N', CNORM(j) must be greater than or equal */
647 /* >          to the infinity-norm, and if TRANS = 'T' or 'C', CNORM(j) */
648 /* >          must be greater than or equal to the 1-norm. */
649 /* > */
650 /* >          If NORMIN = 'N', CNORM is an output argument and CNORM(j) */
651 /* >          returns the 1-norm of the offdiagonal part of the j-th column */
652 /* >          of A. */
653 /* > \endverbatim */
654 /* > */
655 /* > \param[out] INFO */
656 /* > \verbatim */
657 /* >          INFO is INTEGER */
658 /* >          = 0:  successful exit */
659 /* >          < 0:  if INFO = -k, the k-th argument had an illegal value */
660 /* > \endverbatim */
661
662 /*  Authors: */
663 /*  ======== */
664
665 /* > \author Univ. of Tennessee */
666 /* > \author Univ. of California Berkeley */
667 /* > \author Univ. of Colorado Denver */
668 /* > \author NAG Ltd. */
669
670 /* > \date December 2016 */
671
672 /* > \ingroup complexOTHERauxiliary */
673
674 /* > \par Further Details: */
675 /*  ===================== */
676 /* > */
677 /* > \verbatim */
678 /* > */
679 /* >  A rough bound on x is computed; if that is less than overflow, CTPSV */
680 /* >  is called, otherwise, specific code is used which checks for possible */
681 /* >  overflow or divide-by-zero at every operation. */
682 /* > */
683 /* >  A columnwise scheme is used for solving A*x = b.  The basic algorithm */
684 /* >  if A is lower triangular is */
685 /* > */
686 /* >       x[1:n] := b[1:n] */
687 /* >       for j = 1, ..., n */
688 /* >            x(j) := x(j) / A(j,j) */
689 /* >            x[j+1:n] := x[j+1:n] - x(j) * A[j+1:n,j] */
690 /* >       end */
691 /* > */
692 /* >  Define bounds on the components of x after j iterations of the loop: */
693 /* >     M(j) = bound on x[1:j] */
694 /* >     G(j) = bound on x[j+1:n] */
695 /* >  Initially, let M(0) = 0 and G(0) = f2cmax{x(i), i=1,...,n}. */
696 /* > */
697 /* >  Then for iteration j+1 we have */
698 /* >     M(j+1) <= G(j) / | A(j+1,j+1) | */
699 /* >     G(j+1) <= G(j) + M(j+1) * | A[j+2:n,j+1] | */
700 /* >            <= G(j) ( 1 + CNORM(j+1) / | A(j+1,j+1) | ) */
701 /* > */
702 /* >  where CNORM(j+1) is greater than or equal to the infinity-norm of */
703 /* >  column j+1 of A, not counting the diagonal.  Hence */
704 /* > */
705 /* >     G(j) <= G(0) product ( 1 + CNORM(i) / | A(i,i) | ) */
706 /* >                  1<=i<=j */
707 /* >  and */
708 /* > */
709 /* >     |x(j)| <= ( G(0) / |A(j,j)| ) product ( 1 + CNORM(i) / |A(i,i)| ) */
710 /* >                                   1<=i< j */
711 /* > */
712 /* >  Since |x(j)| <= M(j), we use the Level 2 BLAS routine CTPSV if the */
713 /* >  reciprocal of the largest M(j), j=1,..,n, is larger than */
714 /* >  f2cmax(underflow, 1/overflow). */
715 /* > */
716 /* >  The bound on x(j) is also used to determine when a step in the */
717 /* >  columnwise method can be performed without fear of overflow.  If */
718 /* >  the computed bound is greater than a large constant, x is scaled to */
719 /* >  prevent overflow, but if the bound overflows, x is set to 0, x(j) to */
720 /* >  1, and scale to 0, and a non-trivial solution to A*x = 0 is found. */
721 /* > */
722 /* >  Similarly, a row-wise scheme is used to solve A**T *x = b  or */
723 /* >  A**H *x = b.  The basic algorithm for A upper triangular is */
724 /* > */
725 /* >       for j = 1, ..., n */
726 /* >            x(j) := ( b(j) - A[1:j-1,j]' * x[1:j-1] ) / A(j,j) */
727 /* >       end */
728 /* > */
729 /* >  We simultaneously compute two bounds */
730 /* >       G(j) = bound on ( b(i) - A[1:i-1,i]' * x[1:i-1] ), 1<=i<=j */
731 /* >       M(j) = bound on x(i), 1<=i<=j */
732 /* > */
733 /* >  The initial values are G(0) = 0, M(0) = f2cmax{b(i), i=1,..,n}, and we */
734 /* >  add the constraint G(j) >= G(j-1) and M(j) >= M(j-1) for j >= 1. */
735 /* >  Then the bound on x(j) is */
736 /* > */
737 /* >       M(j) <= M(j-1) * ( 1 + CNORM(j) ) / | A(j,j) | */
738 /* > */
739 /* >            <= M(0) * product ( ( 1 + CNORM(i) ) / |A(i,i)| ) */
740 /* >                      1<=i<=j */
741 /* > */
742 /* >  and we can safely call CTPSV if 1/M(n) and 1/G(n) are both greater */
743 /* >  than f2cmax(underflow, 1/overflow). */
744 /* > \endverbatim */
745 /* > */
746 /*  ===================================================================== */
747 /* Subroutine */ int clatps_(char *uplo, char *trans, char *diag, char *
748         normin, integer *n, complex *ap, complex *x, real *scale, real *cnorm,
749          integer *info)
750 {
751     /* System generated locals */
752     integer i__1, i__2, i__3, i__4, i__5;
753     real r__1, r__2, r__3, r__4;
754     complex q__1, q__2, q__3, q__4;
755
756     /* Local variables */
757     integer jinc, jlen;
758     real xbnd;
759     integer imax;
760     real tmax;
761     complex tjjs;
762     real xmax, grow;
763     integer i__, j;
764     extern /* Complex */ VOID cdotc_(complex *, integer *, complex *, integer 
765             *, complex *, integer *);
766     extern logical lsame_(char *, char *);
767     extern /* Subroutine */ int sscal_(integer *, real *, real *, integer *);
768     real tscal;
769     complex uscal;
770     integer jlast;
771     extern /* Complex */ VOID cdotu_(complex *, integer *, complex *, integer 
772             *, complex *, integer *);
773     complex csumj;
774     extern /* Subroutine */ int caxpy_(integer *, complex *, complex *, 
775             integer *, complex *, integer *);
776     logical upper;
777     extern /* Subroutine */ int ctpsv_(char *, char *, char *, integer *, 
778             complex *, complex *, integer *), slabad_(
779             real *, real *);
780     integer ip;
781     real xj;
782     extern integer icamax_(integer *, complex *, integer *);
783     extern /* Complex */ VOID cladiv_(complex *, complex *, complex *);
784     extern real slamch_(char *);
785     extern /* Subroutine */ int csscal_(integer *, real *, complex *, integer 
786             *), xerbla_(char *, integer *, ftnlen);
787     real bignum;
788     extern integer isamax_(integer *, real *, integer *);
789     extern real scasum_(integer *, complex *, integer *);
790     logical notran;
791     integer jfirst;
792     real smlnum;
793     logical nounit;
794     real 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     --cnorm;
808     --x;
809     --ap;
810
811     /* Function Body */
812     *info = 0;
813     upper = lsame_(uplo, "U");
814     notran = lsame_(trans, "N");
815     nounit = lsame_(diag, "N");
816
817 /*     Test the input parameters. */
818
819     if (! upper && ! lsame_(uplo, "L")) {
820         *info = -1;
821     } else if (! notran && ! lsame_(trans, "T") && ! 
822             lsame_(trans, "C")) {
823         *info = -2;
824     } else if (! nounit && ! lsame_(diag, "U")) {
825         *info = -3;
826     } else if (! lsame_(normin, "Y") && ! lsame_(normin,
827              "N")) {
828         *info = -4;
829     } else if (*n < 0) {
830         *info = -5;
831     }
832     if (*info != 0) {
833         i__1 = -(*info);
834         xerbla_("CLATPS", &i__1, (ftnlen)6);
835         return 0;
836     }
837
838 /*     Quick return if possible */
839
840     if (*n == 0) {
841         return 0;
842     }
843
844 /*     Determine machine dependent parameters to control overflow. */
845
846     smlnum = slamch_("Safe minimum");
847     bignum = 1.f / smlnum;
848     slabad_(&smlnum, &bignum);
849     smlnum /= slamch_("Precision");
850     bignum = 1.f / smlnum;
851     *scale = 1.f;
852
853     if (lsame_(normin, "N")) {
854
855 /*        Compute the 1-norm of each column, not including the diagonal. */
856
857         if (upper) {
858
859 /*           A is upper triangular. */
860
861             ip = 1;
862             i__1 = *n;
863             for (j = 1; j <= i__1; ++j) {
864                 i__2 = j - 1;
865                 cnorm[j] = scasum_(&i__2, &ap[ip], &c__1);
866                 ip += j;
867 /* L10: */
868             }
869         } else {
870
871 /*           A is lower triangular. */
872
873             ip = 1;
874             i__1 = *n - 1;
875             for (j = 1; j <= i__1; ++j) {
876                 i__2 = *n - j;
877                 cnorm[j] = scasum_(&i__2, &ap[ip + 1], &c__1);
878                 ip = ip + *n - j + 1;
879 /* L20: */
880             }
881             cnorm[*n] = 0.f;
882         }
883     }
884
885 /*     Scale the column norms by TSCAL if the maximum element in CNORM is */
886 /*     greater than BIGNUM/2. */
887
888     imax = isamax_(n, &cnorm[1], &c__1);
889     tmax = cnorm[imax];
890     if (tmax <= bignum * .5f) {
891         tscal = 1.f;
892     } else {
893         tscal = .5f / (smlnum * tmax);
894         sscal_(n, &tscal, &cnorm[1], &c__1);
895     }
896
897 /*     Compute a bound on the computed solution vector to see if the */
898 /*     Level 2 BLAS routine CTPSV can be used. */
899
900     xmax = 0.f;
901     i__1 = *n;
902     for (j = 1; j <= i__1; ++j) {
903 /* Computing MAX */
904         i__2 = j;
905         r__3 = xmax, r__4 = (r__1 = x[i__2].r / 2.f, abs(r__1)) + (r__2 = 
906                 r_imag(&x[j]) / 2.f, abs(r__2));
907         xmax = f2cmax(r__3,r__4);
908 /* L30: */
909     }
910     xbnd = xmax;
911     if (notran) {
912
913 /*        Compute the growth in A * x = b. */
914
915         if (upper) {
916             jfirst = *n;
917             jlast = 1;
918             jinc = -1;
919         } else {
920             jfirst = 1;
921             jlast = *n;
922             jinc = 1;
923         }
924
925         if (tscal != 1.f) {
926             grow = 0.f;
927             goto L60;
928         }
929
930         if (nounit) {
931
932 /*           A is non-unit triangular. */
933
934 /*           Compute GROW = 1/G(j) and XBND = 1/M(j). */
935 /*           Initially, G(0) = f2cmax{x(i), i=1,...,n}. */
936
937             grow = .5f / f2cmax(xbnd,smlnum);
938             xbnd = grow;
939             ip = jfirst * (jfirst + 1) / 2;
940             jlen = *n;
941             i__1 = jlast;
942             i__2 = jinc;
943             for (j = jfirst; i__2 < 0 ? j >= i__1 : j <= i__1; j += i__2) {
944
945 /*              Exit the loop if the growth factor is too small. */
946
947                 if (grow <= smlnum) {
948                     goto L60;
949                 }
950
951                 i__3 = ip;
952                 tjjs.r = ap[i__3].r, tjjs.i = ap[i__3].i;
953                 tjj = (r__1 = tjjs.r, abs(r__1)) + (r__2 = r_imag(&tjjs), abs(
954                         r__2));
955
956                 if (tjj >= smlnum) {
957
958 /*                 M(j) = G(j-1) / abs(A(j,j)) */
959
960 /* Computing MIN */
961                     r__1 = xbnd, r__2 = f2cmin(1.f,tjj) * grow;
962                     xbnd = f2cmin(r__1,r__2);
963                 } else {
964
965 /*                 M(j) could overflow, set XBND to 0. */
966
967                     xbnd = 0.f;
968                 }
969
970                 if (tjj + cnorm[j] >= smlnum) {
971
972 /*                 G(j) = G(j-1)*( 1 + CNORM(j) / abs(A(j,j)) ) */
973
974                     grow *= tjj / (tjj + cnorm[j]);
975                 } else {
976
977 /*                 G(j) could overflow, set GROW to 0. */
978
979                     grow = 0.f;
980                 }
981                 ip += jinc * jlen;
982                 --jlen;
983 /* L40: */
984             }
985             grow = xbnd;
986         } else {
987
988 /*           A is unit triangular. */
989
990 /*           Compute GROW = 1/G(j), where G(0) = f2cmax{x(i), i=1,...,n}. */
991
992 /* Computing MIN */
993             r__1 = 1.f, r__2 = .5f / f2cmax(xbnd,smlnum);
994             grow = f2cmin(r__1,r__2);
995             i__2 = jlast;
996             i__1 = jinc;
997             for (j = jfirst; i__1 < 0 ? j >= i__2 : j <= i__2; j += i__1) {
998
999 /*              Exit the loop if the growth factor is too small. */
1000
1001                 if (grow <= smlnum) {
1002                     goto L60;
1003                 }
1004
1005 /*              G(j) = G(j-1)*( 1 + CNORM(j) ) */
1006
1007                 grow *= 1.f / (cnorm[j] + 1.f);
1008 /* L50: */
1009             }
1010         }
1011 L60:
1012
1013         ;
1014     } else {
1015
1016 /*        Compute the growth in A**T * x = b  or  A**H * x = b. */
1017
1018         if (upper) {
1019             jfirst = 1;
1020             jlast = *n;
1021             jinc = 1;
1022         } else {
1023             jfirst = *n;
1024             jlast = 1;
1025             jinc = -1;
1026         }
1027
1028         if (tscal != 1.f) {
1029             grow = 0.f;
1030             goto L90;
1031         }
1032
1033         if (nounit) {
1034
1035 /*           A is non-unit triangular. */
1036
1037 /*           Compute GROW = 1/G(j) and XBND = 1/M(j). */
1038 /*           Initially, M(0) = f2cmax{x(i), i=1,...,n}. */
1039
1040             grow = .5f / f2cmax(xbnd,smlnum);
1041             xbnd = grow;
1042             ip = jfirst * (jfirst + 1) / 2;
1043             jlen = 1;
1044             i__1 = jlast;
1045             i__2 = jinc;
1046             for (j = jfirst; i__2 < 0 ? j >= i__1 : j <= i__1; j += i__2) {
1047
1048 /*              Exit the loop if the growth factor is too small. */
1049
1050                 if (grow <= smlnum) {
1051                     goto L90;
1052                 }
1053
1054 /*              G(j) = f2cmax( G(j-1), M(j-1)*( 1 + CNORM(j) ) ) */
1055
1056                 xj = cnorm[j] + 1.f;
1057 /* Computing MIN */
1058                 r__1 = grow, r__2 = xbnd / xj;
1059                 grow = f2cmin(r__1,r__2);
1060
1061                 i__3 = ip;
1062                 tjjs.r = ap[i__3].r, tjjs.i = ap[i__3].i;
1063                 tjj = (r__1 = tjjs.r, abs(r__1)) + (r__2 = r_imag(&tjjs), abs(
1064                         r__2));
1065
1066                 if (tjj >= smlnum) {
1067
1068 /*                 M(j) = M(j-1)*( 1 + CNORM(j) ) / abs(A(j,j)) */
1069
1070                     if (xj > tjj) {
1071                         xbnd *= tjj / xj;
1072                     }
1073                 } else {
1074
1075 /*                 M(j) could overflow, set XBND to 0. */
1076
1077                     xbnd = 0.f;
1078                 }
1079                 ++jlen;
1080                 ip += jinc * jlen;
1081 /* L70: */
1082             }
1083             grow = f2cmin(grow,xbnd);
1084         } else {
1085
1086 /*           A is unit triangular. */
1087
1088 /*           Compute GROW = 1/G(j), where G(0) = f2cmax{x(i), i=1,...,n}. */
1089
1090 /* Computing MIN */
1091             r__1 = 1.f, r__2 = .5f / f2cmax(xbnd,smlnum);
1092             grow = f2cmin(r__1,r__2);
1093             i__2 = jlast;
1094             i__1 = jinc;
1095             for (j = jfirst; i__1 < 0 ? j >= i__2 : j <= i__2; j += i__1) {
1096
1097 /*              Exit the loop if the growth factor is too small. */
1098
1099                 if (grow <= smlnum) {
1100                     goto L90;
1101                 }
1102
1103 /*              G(j) = ( 1 + CNORM(j) )*G(j-1) */
1104
1105                 xj = cnorm[j] + 1.f;
1106                 grow /= xj;
1107 /* L80: */
1108             }
1109         }
1110 L90:
1111         ;
1112     }
1113
1114     if (grow * tscal > smlnum) {
1115
1116 /*        Use the Level 2 BLAS solve if the reciprocal of the bound on */
1117 /*        elements of X is not too small. */
1118
1119         ctpsv_(uplo, trans, diag, n, &ap[1], &x[1], &c__1);
1120     } else {
1121
1122 /*        Use a Level 1 BLAS solve, scaling intermediate results. */
1123
1124         if (xmax > bignum * .5f) {
1125
1126 /*           Scale X so that its components are less than or equal to */
1127 /*           BIGNUM in absolute value. */
1128
1129             *scale = bignum * .5f / xmax;
1130             csscal_(n, scale, &x[1], &c__1);
1131             xmax = bignum;
1132         } else {
1133             xmax *= 2.f;
1134         }
1135
1136         if (notran) {
1137
1138 /*           Solve A * x = b */
1139
1140             ip = jfirst * (jfirst + 1) / 2;
1141             i__1 = jlast;
1142             i__2 = jinc;
1143             for (j = jfirst; i__2 < 0 ? j >= i__1 : j <= i__1; j += i__2) {
1144
1145 /*              Compute x(j) = b(j) / A(j,j), scaling x if necessary. */
1146
1147                 i__3 = j;
1148                 xj = (r__1 = x[i__3].r, abs(r__1)) + (r__2 = r_imag(&x[j]), 
1149                         abs(r__2));
1150                 if (nounit) {
1151                     i__3 = ip;
1152                     q__1.r = tscal * ap[i__3].r, q__1.i = tscal * ap[i__3].i;
1153                     tjjs.r = q__1.r, tjjs.i = q__1.i;
1154                 } else {
1155                     tjjs.r = tscal, tjjs.i = 0.f;
1156                     if (tscal == 1.f) {
1157                         goto L105;
1158                     }
1159                 }
1160                 tjj = (r__1 = tjjs.r, abs(r__1)) + (r__2 = r_imag(&tjjs), abs(
1161                         r__2));
1162                 if (tjj > smlnum) {
1163
1164 /*                    abs(A(j,j)) > SMLNUM: */
1165
1166                     if (tjj < 1.f) {
1167                         if (xj > tjj * bignum) {
1168
1169 /*                          Scale x by 1/b(j). */
1170
1171                             rec = 1.f / xj;
1172                             csscal_(n, &rec, &x[1], &c__1);
1173                             *scale *= rec;
1174                             xmax *= rec;
1175                         }
1176                     }
1177                     i__3 = j;
1178                     cladiv_(&q__1, &x[j], &tjjs);
1179                     x[i__3].r = q__1.r, x[i__3].i = q__1.i;
1180                     i__3 = j;
1181                     xj = (r__1 = x[i__3].r, abs(r__1)) + (r__2 = r_imag(&x[j])
1182                             , abs(r__2));
1183                 } else if (tjj > 0.f) {
1184
1185 /*                    0 < abs(A(j,j)) <= SMLNUM: */
1186
1187                     if (xj > tjj * bignum) {
1188
1189 /*                       Scale x by (1/abs(x(j)))*abs(A(j,j))*BIGNUM */
1190 /*                       to avoid overflow when dividing by A(j,j). */
1191
1192                         rec = tjj * bignum / xj;
1193                         if (cnorm[j] > 1.f) {
1194
1195 /*                          Scale by 1/CNORM(j) to avoid overflow when */
1196 /*                          multiplying x(j) times column j. */
1197
1198                             rec /= cnorm[j];
1199                         }
1200                         csscal_(n, &rec, &x[1], &c__1);
1201                         *scale *= rec;
1202                         xmax *= rec;
1203                     }
1204                     i__3 = j;
1205                     cladiv_(&q__1, &x[j], &tjjs);
1206                     x[i__3].r = q__1.r, x[i__3].i = q__1.i;
1207                     i__3 = j;
1208                     xj = (r__1 = x[i__3].r, abs(r__1)) + (r__2 = r_imag(&x[j])
1209                             , abs(r__2));
1210                 } else {
1211
1212 /*                    A(j,j) = 0:  Set x(1:n) = 0, x(j) = 1, and */
1213 /*                    scale = 0, and compute a solution to A*x = 0. */
1214
1215                     i__3 = *n;
1216                     for (i__ = 1; i__ <= i__3; ++i__) {
1217                         i__4 = i__;
1218                         x[i__4].r = 0.f, x[i__4].i = 0.f;
1219 /* L100: */
1220                     }
1221                     i__3 = j;
1222                     x[i__3].r = 1.f, x[i__3].i = 0.f;
1223                     xj = 1.f;
1224                     *scale = 0.f;
1225                     xmax = 0.f;
1226                 }
1227 L105:
1228
1229 /*              Scale x if necessary to avoid overflow when adding a */
1230 /*              multiple of column j of A. */
1231
1232                 if (xj > 1.f) {
1233                     rec = 1.f / xj;
1234                     if (cnorm[j] > (bignum - xmax) * rec) {
1235
1236 /*                    Scale x by 1/(2*abs(x(j))). */
1237
1238                         rec *= .5f;
1239                         csscal_(n, &rec, &x[1], &c__1);
1240                         *scale *= rec;
1241                     }
1242                 } else if (xj * cnorm[j] > bignum - xmax) {
1243
1244 /*                 Scale x by 1/2. */
1245
1246                     csscal_(n, &c_b36, &x[1], &c__1);
1247                     *scale *= .5f;
1248                 }
1249
1250                 if (upper) {
1251                     if (j > 1) {
1252
1253 /*                    Compute the update */
1254 /*                       x(1:j-1) := x(1:j-1) - x(j) * A(1:j-1,j) */
1255
1256                         i__3 = j - 1;
1257                         i__4 = j;
1258                         q__2.r = -x[i__4].r, q__2.i = -x[i__4].i;
1259                         q__1.r = tscal * q__2.r, q__1.i = tscal * q__2.i;
1260                         caxpy_(&i__3, &q__1, &ap[ip - j + 1], &c__1, &x[1], &
1261                                 c__1);
1262                         i__3 = j - 1;
1263                         i__ = icamax_(&i__3, &x[1], &c__1);
1264                         i__3 = i__;
1265                         xmax = (r__1 = x[i__3].r, abs(r__1)) + (r__2 = r_imag(
1266                                 &x[i__]), abs(r__2));
1267                     }
1268                     ip -= j;
1269                 } else {
1270                     if (j < *n) {
1271
1272 /*                    Compute the update */
1273 /*                       x(j+1:n) := x(j+1:n) - x(j) * A(j+1:n,j) */
1274
1275                         i__3 = *n - j;
1276                         i__4 = j;
1277                         q__2.r = -x[i__4].r, q__2.i = -x[i__4].i;
1278                         q__1.r = tscal * q__2.r, q__1.i = tscal * q__2.i;
1279                         caxpy_(&i__3, &q__1, &ap[ip + 1], &c__1, &x[j + 1], &
1280                                 c__1);
1281                         i__3 = *n - j;
1282                         i__ = j + icamax_(&i__3, &x[j + 1], &c__1);
1283                         i__3 = i__;
1284                         xmax = (r__1 = x[i__3].r, abs(r__1)) + (r__2 = r_imag(
1285                                 &x[i__]), abs(r__2));
1286                     }
1287                     ip = ip + *n - j + 1;
1288                 }
1289 /* L110: */
1290             }
1291
1292         } else if (lsame_(trans, "T")) {
1293
1294 /*           Solve A**T * x = b */
1295
1296             ip = jfirst * (jfirst + 1) / 2;
1297             jlen = 1;
1298             i__2 = jlast;
1299             i__1 = jinc;
1300             for (j = jfirst; i__1 < 0 ? j >= i__2 : j <= i__2; j += i__1) {
1301
1302 /*              Compute x(j) = b(j) - sum A(k,j)*x(k). */
1303 /*                                    k<>j */
1304
1305                 i__3 = j;
1306                 xj = (r__1 = x[i__3].r, abs(r__1)) + (r__2 = r_imag(&x[j]), 
1307                         abs(r__2));
1308                 uscal.r = tscal, uscal.i = 0.f;
1309                 rec = 1.f / f2cmax(xmax,1.f);
1310                 if (cnorm[j] > (bignum - xj) * rec) {
1311
1312 /*                 If x(j) could overflow, scale x by 1/(2*XMAX). */
1313
1314                     rec *= .5f;
1315                     if (nounit) {
1316                         i__3 = ip;
1317                         q__1.r = tscal * ap[i__3].r, q__1.i = tscal * ap[i__3]
1318                                 .i;
1319                         tjjs.r = q__1.r, tjjs.i = q__1.i;
1320                     } else {
1321                         tjjs.r = tscal, tjjs.i = 0.f;
1322                     }
1323                     tjj = (r__1 = tjjs.r, abs(r__1)) + (r__2 = r_imag(&tjjs), 
1324                             abs(r__2));
1325                     if (tjj > 1.f) {
1326
1327 /*                       Divide by A(j,j) when scaling x if A(j,j) > 1. */
1328
1329 /* Computing MIN */
1330                         r__1 = 1.f, r__2 = rec * tjj;
1331                         rec = f2cmin(r__1,r__2);
1332                         cladiv_(&q__1, &uscal, &tjjs);
1333                         uscal.r = q__1.r, uscal.i = q__1.i;
1334                     }
1335                     if (rec < 1.f) {
1336                         csscal_(n, &rec, &x[1], &c__1);
1337                         *scale *= rec;
1338                         xmax *= rec;
1339                     }
1340                 }
1341
1342                 csumj.r = 0.f, csumj.i = 0.f;
1343                 if (uscal.r == 1.f && uscal.i == 0.f) {
1344
1345 /*                 If the scaling needed for A in the dot product is 1, */
1346 /*                 call CDOTU to perform the dot product. */
1347
1348                     if (upper) {
1349                         i__3 = j - 1;
1350                         cdotu_(&q__1, &i__3, &ap[ip - j + 1], &c__1, &x[1], &
1351                                 c__1);
1352                         csumj.r = q__1.r, csumj.i = q__1.i;
1353                     } else if (j < *n) {
1354                         i__3 = *n - j;
1355                         cdotu_(&q__1, &i__3, &ap[ip + 1], &c__1, &x[j + 1], &
1356                                 c__1);
1357                         csumj.r = q__1.r, csumj.i = q__1.i;
1358                     }
1359                 } else {
1360
1361 /*                 Otherwise, use in-line code for the dot product. */
1362
1363                     if (upper) {
1364                         i__3 = j - 1;
1365                         for (i__ = 1; i__ <= i__3; ++i__) {
1366                             i__4 = ip - j + i__;
1367                             q__3.r = ap[i__4].r * uscal.r - ap[i__4].i * 
1368                                     uscal.i, q__3.i = ap[i__4].r * uscal.i + 
1369                                     ap[i__4].i * uscal.r;
1370                             i__5 = i__;
1371                             q__2.r = q__3.r * x[i__5].r - q__3.i * x[i__5].i, 
1372                                     q__2.i = q__3.r * x[i__5].i + q__3.i * x[
1373                                     i__5].r;
1374                             q__1.r = csumj.r + q__2.r, q__1.i = csumj.i + 
1375                                     q__2.i;
1376                             csumj.r = q__1.r, csumj.i = q__1.i;
1377 /* L120: */
1378                         }
1379                     } else if (j < *n) {
1380                         i__3 = *n - j;
1381                         for (i__ = 1; i__ <= i__3; ++i__) {
1382                             i__4 = ip + i__;
1383                             q__3.r = ap[i__4].r * uscal.r - ap[i__4].i * 
1384                                     uscal.i, q__3.i = ap[i__4].r * uscal.i + 
1385                                     ap[i__4].i * uscal.r;
1386                             i__5 = j + i__;
1387                             q__2.r = q__3.r * x[i__5].r - q__3.i * x[i__5].i, 
1388                                     q__2.i = q__3.r * x[i__5].i + q__3.i * x[
1389                                     i__5].r;
1390                             q__1.r = csumj.r + q__2.r, q__1.i = csumj.i + 
1391                                     q__2.i;
1392                             csumj.r = q__1.r, csumj.i = q__1.i;
1393 /* L130: */
1394                         }
1395                     }
1396                 }
1397
1398                 q__1.r = tscal, q__1.i = 0.f;
1399                 if (uscal.r == q__1.r && uscal.i == q__1.i) {
1400
1401 /*                 Compute x(j) := ( x(j) - CSUMJ ) / A(j,j) if 1/A(j,j) */
1402 /*                 was not used to scale the dotproduct. */
1403
1404                     i__3 = j;
1405                     i__4 = j;
1406                     q__1.r = x[i__4].r - csumj.r, q__1.i = x[i__4].i - 
1407                             csumj.i;
1408                     x[i__3].r = q__1.r, x[i__3].i = q__1.i;
1409                     i__3 = j;
1410                     xj = (r__1 = x[i__3].r, abs(r__1)) + (r__2 = r_imag(&x[j])
1411                             , abs(r__2));
1412                     if (nounit) {
1413
1414 /*                    Compute x(j) = x(j) / A(j,j), scaling if necessary. */
1415
1416                         i__3 = ip;
1417                         q__1.r = tscal * ap[i__3].r, q__1.i = tscal * ap[i__3]
1418                                 .i;
1419                         tjjs.r = q__1.r, tjjs.i = q__1.i;
1420                     } else {
1421                         tjjs.r = tscal, tjjs.i = 0.f;
1422                         if (tscal == 1.f) {
1423                             goto L145;
1424                         }
1425                     }
1426                     tjj = (r__1 = tjjs.r, abs(r__1)) + (r__2 = r_imag(&tjjs), 
1427                             abs(r__2));
1428                     if (tjj > smlnum) {
1429
1430 /*                       abs(A(j,j)) > SMLNUM: */
1431
1432                         if (tjj < 1.f) {
1433                             if (xj > tjj * bignum) {
1434
1435 /*                             Scale X by 1/abs(x(j)). */
1436
1437                                 rec = 1.f / xj;
1438                                 csscal_(n, &rec, &x[1], &c__1);
1439                                 *scale *= rec;
1440                                 xmax *= rec;
1441                             }
1442                         }
1443                         i__3 = j;
1444                         cladiv_(&q__1, &x[j], &tjjs);
1445                         x[i__3].r = q__1.r, x[i__3].i = q__1.i;
1446                     } else if (tjj > 0.f) {
1447
1448 /*                       0 < abs(A(j,j)) <= SMLNUM: */
1449
1450                         if (xj > tjj * bignum) {
1451
1452 /*                          Scale x by (1/abs(x(j)))*abs(A(j,j))*BIGNUM. */
1453
1454                             rec = tjj * bignum / xj;
1455                             csscal_(n, &rec, &x[1], &c__1);
1456                             *scale *= rec;
1457                             xmax *= rec;
1458                         }
1459                         i__3 = j;
1460                         cladiv_(&q__1, &x[j], &tjjs);
1461                         x[i__3].r = q__1.r, x[i__3].i = q__1.i;
1462                     } else {
1463
1464 /*                       A(j,j) = 0:  Set x(1:n) = 0, x(j) = 1, and */
1465 /*                       scale = 0 and compute a solution to A**T *x = 0. */
1466
1467                         i__3 = *n;
1468                         for (i__ = 1; i__ <= i__3; ++i__) {
1469                             i__4 = i__;
1470                             x[i__4].r = 0.f, x[i__4].i = 0.f;
1471 /* L140: */
1472                         }
1473                         i__3 = j;
1474                         x[i__3].r = 1.f, x[i__3].i = 0.f;
1475                         *scale = 0.f;
1476                         xmax = 0.f;
1477                     }
1478 L145:
1479                     ;
1480                 } else {
1481
1482 /*                 Compute x(j) := x(j) / A(j,j) - CSUMJ if the dot */
1483 /*                 product has already been divided by 1/A(j,j). */
1484
1485                     i__3 = j;
1486                     cladiv_(&q__2, &x[j], &tjjs);
1487                     q__1.r = q__2.r - csumj.r, q__1.i = q__2.i - csumj.i;
1488                     x[i__3].r = q__1.r, x[i__3].i = q__1.i;
1489                 }
1490 /* Computing MAX */
1491                 i__3 = j;
1492                 r__3 = xmax, r__4 = (r__1 = x[i__3].r, abs(r__1)) + (r__2 = 
1493                         r_imag(&x[j]), abs(r__2));
1494                 xmax = f2cmax(r__3,r__4);
1495                 ++jlen;
1496                 ip += jinc * jlen;
1497 /* L150: */
1498             }
1499
1500         } else {
1501
1502 /*           Solve A**H * x = b */
1503
1504             ip = jfirst * (jfirst + 1) / 2;
1505             jlen = 1;
1506             i__1 = jlast;
1507             i__2 = jinc;
1508             for (j = jfirst; i__2 < 0 ? j >= i__1 : j <= i__1; j += i__2) {
1509
1510 /*              Compute x(j) = b(j) - sum A(k,j)*x(k). */
1511 /*                                    k<>j */
1512
1513                 i__3 = j;
1514                 xj = (r__1 = x[i__3].r, abs(r__1)) + (r__2 = r_imag(&x[j]), 
1515                         abs(r__2));
1516                 uscal.r = tscal, uscal.i = 0.f;
1517                 rec = 1.f / f2cmax(xmax,1.f);
1518                 if (cnorm[j] > (bignum - xj) * rec) {
1519
1520 /*                 If x(j) could overflow, scale x by 1/(2*XMAX). */
1521
1522                     rec *= .5f;
1523                     if (nounit) {
1524                         r_cnjg(&q__2, &ap[ip]);
1525                         q__1.r = tscal * q__2.r, q__1.i = tscal * q__2.i;
1526                         tjjs.r = q__1.r, tjjs.i = q__1.i;
1527                     } else {
1528                         tjjs.r = tscal, tjjs.i = 0.f;
1529                     }
1530                     tjj = (r__1 = tjjs.r, abs(r__1)) + (r__2 = r_imag(&tjjs), 
1531                             abs(r__2));
1532                     if (tjj > 1.f) {
1533
1534 /*                       Divide by A(j,j) when scaling x if A(j,j) > 1. */
1535
1536 /* Computing MIN */
1537                         r__1 = 1.f, r__2 = rec * tjj;
1538                         rec = f2cmin(r__1,r__2);
1539                         cladiv_(&q__1, &uscal, &tjjs);
1540                         uscal.r = q__1.r, uscal.i = q__1.i;
1541                     }
1542                     if (rec < 1.f) {
1543                         csscal_(n, &rec, &x[1], &c__1);
1544                         *scale *= rec;
1545                         xmax *= rec;
1546                     }
1547                 }
1548
1549                 csumj.r = 0.f, csumj.i = 0.f;
1550                 if (uscal.r == 1.f && uscal.i == 0.f) {
1551
1552 /*                 If the scaling needed for A in the dot product is 1, */
1553 /*                 call CDOTC to perform the dot product. */
1554
1555                     if (upper) {
1556                         i__3 = j - 1;
1557                         cdotc_(&q__1, &i__3, &ap[ip - j + 1], &c__1, &x[1], &
1558                                 c__1);
1559                         csumj.r = q__1.r, csumj.i = q__1.i;
1560                     } else if (j < *n) {
1561                         i__3 = *n - j;
1562                         cdotc_(&q__1, &i__3, &ap[ip + 1], &c__1, &x[j + 1], &
1563                                 c__1);
1564                         csumj.r = q__1.r, csumj.i = q__1.i;
1565                     }
1566                 } else {
1567
1568 /*                 Otherwise, use in-line code for the dot product. */
1569
1570                     if (upper) {
1571                         i__3 = j - 1;
1572                         for (i__ = 1; i__ <= i__3; ++i__) {
1573                             r_cnjg(&q__4, &ap[ip - j + i__]);
1574                             q__3.r = q__4.r * uscal.r - q__4.i * uscal.i, 
1575                                     q__3.i = q__4.r * uscal.i + q__4.i * 
1576                                     uscal.r;
1577                             i__4 = i__;
1578                             q__2.r = q__3.r * x[i__4].r - q__3.i * x[i__4].i, 
1579                                     q__2.i = q__3.r * x[i__4].i + q__3.i * x[
1580                                     i__4].r;
1581                             q__1.r = csumj.r + q__2.r, q__1.i = csumj.i + 
1582                                     q__2.i;
1583                             csumj.r = q__1.r, csumj.i = q__1.i;
1584 /* L160: */
1585                         }
1586                     } else if (j < *n) {
1587                         i__3 = *n - j;
1588                         for (i__ = 1; i__ <= i__3; ++i__) {
1589                             r_cnjg(&q__4, &ap[ip + i__]);
1590                             q__3.r = q__4.r * uscal.r - q__4.i * uscal.i, 
1591                                     q__3.i = q__4.r * uscal.i + q__4.i * 
1592                                     uscal.r;
1593                             i__4 = j + i__;
1594                             q__2.r = q__3.r * x[i__4].r - q__3.i * x[i__4].i, 
1595                                     q__2.i = q__3.r * x[i__4].i + q__3.i * x[
1596                                     i__4].r;
1597                             q__1.r = csumj.r + q__2.r, q__1.i = csumj.i + 
1598                                     q__2.i;
1599                             csumj.r = q__1.r, csumj.i = q__1.i;
1600 /* L170: */
1601                         }
1602                     }
1603                 }
1604
1605                 q__1.r = tscal, q__1.i = 0.f;
1606                 if (uscal.r == q__1.r && uscal.i == q__1.i) {
1607
1608 /*                 Compute x(j) := ( x(j) - CSUMJ ) / A(j,j) if 1/A(j,j) */
1609 /*                 was not used to scale the dotproduct. */
1610
1611                     i__3 = j;
1612                     i__4 = j;
1613                     q__1.r = x[i__4].r - csumj.r, q__1.i = x[i__4].i - 
1614                             csumj.i;
1615                     x[i__3].r = q__1.r, x[i__3].i = q__1.i;
1616                     i__3 = j;
1617                     xj = (r__1 = x[i__3].r, abs(r__1)) + (r__2 = r_imag(&x[j])
1618                             , abs(r__2));
1619                     if (nounit) {
1620
1621 /*                    Compute x(j) = x(j) / A(j,j), scaling if necessary. */
1622
1623                         r_cnjg(&q__2, &ap[ip]);
1624                         q__1.r = tscal * q__2.r, q__1.i = tscal * q__2.i;
1625                         tjjs.r = q__1.r, tjjs.i = q__1.i;
1626                     } else {
1627                         tjjs.r = tscal, tjjs.i = 0.f;
1628                         if (tscal == 1.f) {
1629                             goto L185;
1630                         }
1631                     }
1632                     tjj = (r__1 = tjjs.r, abs(r__1)) + (r__2 = r_imag(&tjjs), 
1633                             abs(r__2));
1634                     if (tjj > smlnum) {
1635
1636 /*                       abs(A(j,j)) > SMLNUM: */
1637
1638                         if (tjj < 1.f) {
1639                             if (xj > tjj * bignum) {
1640
1641 /*                             Scale X by 1/abs(x(j)). */
1642
1643                                 rec = 1.f / xj;
1644                                 csscal_(n, &rec, &x[1], &c__1);
1645                                 *scale *= rec;
1646                                 xmax *= rec;
1647                             }
1648                         }
1649                         i__3 = j;
1650                         cladiv_(&q__1, &x[j], &tjjs);
1651                         x[i__3].r = q__1.r, x[i__3].i = q__1.i;
1652                     } else if (tjj > 0.f) {
1653
1654 /*                       0 < abs(A(j,j)) <= SMLNUM: */
1655
1656                         if (xj > tjj * bignum) {
1657
1658 /*                          Scale x by (1/abs(x(j)))*abs(A(j,j))*BIGNUM. */
1659
1660                             rec = tjj * bignum / xj;
1661                             csscal_(n, &rec, &x[1], &c__1);
1662                             *scale *= rec;
1663                             xmax *= rec;
1664                         }
1665                         i__3 = j;
1666                         cladiv_(&q__1, &x[j], &tjjs);
1667                         x[i__3].r = q__1.r, x[i__3].i = q__1.i;
1668                     } else {
1669
1670 /*                       A(j,j) = 0:  Set x(1:n) = 0, x(j) = 1, and */
1671 /*                       scale = 0 and compute a solution to A**H *x = 0. */
1672
1673                         i__3 = *n;
1674                         for (i__ = 1; i__ <= i__3; ++i__) {
1675                             i__4 = i__;
1676                             x[i__4].r = 0.f, x[i__4].i = 0.f;
1677 /* L180: */
1678                         }
1679                         i__3 = j;
1680                         x[i__3].r = 1.f, x[i__3].i = 0.f;
1681                         *scale = 0.f;
1682                         xmax = 0.f;
1683                     }
1684 L185:
1685                     ;
1686                 } else {
1687
1688 /*                 Compute x(j) := x(j) / A(j,j) - CSUMJ if the dot */
1689 /*                 product has already been divided by 1/A(j,j). */
1690
1691                     i__3 = j;
1692                     cladiv_(&q__2, &x[j], &tjjs);
1693                     q__1.r = q__2.r - csumj.r, q__1.i = q__2.i - csumj.i;
1694                     x[i__3].r = q__1.r, x[i__3].i = q__1.i;
1695                 }
1696 /* Computing MAX */
1697                 i__3 = j;
1698                 r__3 = xmax, r__4 = (r__1 = x[i__3].r, abs(r__1)) + (r__2 = 
1699                         r_imag(&x[j]), abs(r__2));
1700                 xmax = f2cmax(r__3,r__4);
1701                 ++jlen;
1702                 ip += jinc * jlen;
1703 /* L190: */
1704             }
1705         }
1706         *scale /= tscal;
1707     }
1708
1709 /*     Scale the column norms by 1/TSCAL for return. */
1710
1711     if (tscal != 1.f) {
1712         r__1 = 1.f / tscal;
1713         sscal_(n, &r__1, &cnorm[1], &c__1);
1714     }
1715
1716     return 0;
1717
1718 /*     End of CLATPS */
1719
1720 } /* clatps_ */
1721