You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

zlatrs.c 47 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714
  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. #if defined(_WIN64)
  13. typedef long long BLASLONG;
  14. typedef unsigned long long BLASULONG;
  15. #else
  16. typedef long BLASLONG;
  17. typedef unsigned long BLASULONG;
  18. #endif
  19. #ifdef LAPACK_ILP64
  20. typedef BLASLONG blasint;
  21. #if defined(_WIN64)
  22. #define blasabs(x) llabs(x)
  23. #else
  24. #define blasabs(x) labs(x)
  25. #endif
  26. #else
  27. typedef int blasint;
  28. #define blasabs(x) abs(x)
  29. #endif
  30. typedef blasint integer;
  31. typedef unsigned int uinteger;
  32. typedef char *address;
  33. typedef short int shortint;
  34. typedef float real;
  35. typedef double doublereal;
  36. typedef struct { real r, i; } complex;
  37. typedef struct { doublereal r, i; } doublecomplex;
  38. #ifdef _MSC_VER
  39. static inline _Fcomplex Cf(complex *z) {_Fcomplex zz={z->r , z->i}; return zz;}
  40. static inline _Dcomplex Cd(doublecomplex *z) {_Dcomplex zz={z->r , z->i};return zz;}
  41. static inline _Fcomplex * _pCf(complex *z) {return (_Fcomplex*)z;}
  42. static inline _Dcomplex * _pCd(doublecomplex *z) {return (_Dcomplex*)z;}
  43. #else
  44. static inline _Complex float Cf(complex *z) {return z->r + z->i*_Complex_I;}
  45. static inline _Complex double Cd(doublecomplex *z) {return z->r + z->i*_Complex_I;}
  46. static inline _Complex float * _pCf(complex *z) {return (_Complex float*)z;}
  47. static inline _Complex double * _pCd(doublecomplex *z) {return (_Complex double*)z;}
  48. #endif
  49. #define pCf(z) (*_pCf(z))
  50. #define pCd(z) (*_pCd(z))
  51. typedef blasint logical;
  52. typedef char logical1;
  53. typedef char integer1;
  54. #define TRUE_ (1)
  55. #define FALSE_ (0)
  56. /* Extern is for use with -E */
  57. #ifndef Extern
  58. #define Extern extern
  59. #endif
  60. /* I/O stuff */
  61. typedef int flag;
  62. typedef int ftnlen;
  63. typedef int ftnint;
  64. /*external read, write*/
  65. typedef struct
  66. { flag cierr;
  67. ftnint ciunit;
  68. flag ciend;
  69. char *cifmt;
  70. ftnint cirec;
  71. } cilist;
  72. /*internal read, write*/
  73. typedef struct
  74. { flag icierr;
  75. char *iciunit;
  76. flag iciend;
  77. char *icifmt;
  78. ftnint icirlen;
  79. ftnint icirnum;
  80. } icilist;
  81. /*open*/
  82. typedef struct
  83. { flag oerr;
  84. ftnint ounit;
  85. char *ofnm;
  86. ftnlen ofnmlen;
  87. char *osta;
  88. char *oacc;
  89. char *ofm;
  90. ftnint orl;
  91. char *oblnk;
  92. } olist;
  93. /*close*/
  94. typedef struct
  95. { flag cerr;
  96. ftnint cunit;
  97. char *csta;
  98. } cllist;
  99. /*rewind, backspace, endfile*/
  100. typedef struct
  101. { flag aerr;
  102. ftnint aunit;
  103. } alist;
  104. /* inquire */
  105. typedef struct
  106. { flag inerr;
  107. ftnint inunit;
  108. char *infile;
  109. ftnlen infilen;
  110. ftnint *inex; /*parameters in standard's order*/
  111. ftnint *inopen;
  112. ftnint *innum;
  113. ftnint *innamed;
  114. char *inname;
  115. ftnlen innamlen;
  116. char *inacc;
  117. ftnlen inacclen;
  118. char *inseq;
  119. ftnlen inseqlen;
  120. char *indir;
  121. ftnlen indirlen;
  122. char *infmt;
  123. ftnlen infmtlen;
  124. char *inform;
  125. ftnint informlen;
  126. char *inunf;
  127. ftnlen inunflen;
  128. ftnint *inrecl;
  129. ftnint *innrec;
  130. char *inblank;
  131. ftnlen inblanklen;
  132. } inlist;
  133. #define VOID void
  134. union Multitype { /* for multiple entry points */
  135. integer1 g;
  136. shortint h;
  137. integer i;
  138. /* longint j; */
  139. real r;
  140. doublereal d;
  141. complex c;
  142. doublecomplex z;
  143. };
  144. typedef union Multitype Multitype;
  145. struct Vardesc { /* for Namelist */
  146. char *name;
  147. char *addr;
  148. ftnlen *dims;
  149. int type;
  150. };
  151. typedef struct Vardesc Vardesc;
  152. struct Namelist {
  153. char *name;
  154. Vardesc **vars;
  155. int nvars;
  156. };
  157. typedef struct Namelist Namelist;
  158. #define abs(x) ((x) >= 0 ? (x) : -(x))
  159. #define dabs(x) (fabs(x))
  160. #define f2cmin(a,b) ((a) <= (b) ? (a) : (b))
  161. #define f2cmax(a,b) ((a) >= (b) ? (a) : (b))
  162. #define dmin(a,b) (f2cmin(a,b))
  163. #define dmax(a,b) (f2cmax(a,b))
  164. #define bit_test(a,b) ((a) >> (b) & 1)
  165. #define bit_clear(a,b) ((a) & ~((uinteger)1 << (b)))
  166. #define bit_set(a,b) ((a) | ((uinteger)1 << (b)))
  167. #define abort_() { sig_die("Fortran abort routine called", 1); }
  168. #define c_abs(z) (cabsf(Cf(z)))
  169. #define c_cos(R,Z) { pCf(R)=ccos(Cf(Z)); }
  170. #ifdef _MSC_VER
  171. #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]);}
  172. #define z_div(c, a, b) {Cd(c)._Val[0] = (Cd(a)._Val[0]/Cd(b)._Val[0]); Cd(c)._Val[1]=(Cd(a)._Val[1]/Cd(b)._Val[1]);}
  173. #else
  174. #define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);}
  175. #define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);}
  176. #endif
  177. #define c_exp(R, Z) {pCf(R) = cexpf(Cf(Z));}
  178. #define c_log(R, Z) {pCf(R) = clogf(Cf(Z));}
  179. #define c_sin(R, Z) {pCf(R) = csinf(Cf(Z));}
  180. //#define c_sqrt(R, Z) {*(R) = csqrtf(Cf(Z));}
  181. #define c_sqrt(R, Z) {pCf(R) = csqrtf(Cf(Z));}
  182. #define d_abs(x) (fabs(*(x)))
  183. #define d_acos(x) (acos(*(x)))
  184. #define d_asin(x) (asin(*(x)))
  185. #define d_atan(x) (atan(*(x)))
  186. #define d_atn2(x, y) (atan2(*(x),*(y)))
  187. #define d_cnjg(R, Z) { pCd(R) = conj(Cd(Z)); }
  188. #define r_cnjg(R, Z) { pCf(R) = conjf(Cf(Z)); }
  189. #define d_cos(x) (cos(*(x)))
  190. #define d_cosh(x) (cosh(*(x)))
  191. #define d_dim(__a, __b) ( *(__a) > *(__b) ? *(__a) - *(__b) : 0.0 )
  192. #define d_exp(x) (exp(*(x)))
  193. #define d_imag(z) (cimag(Cd(z)))
  194. #define r_imag(z) (cimagf(Cf(z)))
  195. #define d_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  196. #define r_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  197. #define d_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  198. #define r_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  199. #define d_log(x) (log(*(x)))
  200. #define d_mod(x, y) (fmod(*(x), *(y)))
  201. #define u_nint(__x) ((__x)>=0 ? floor((__x) + .5) : -floor(.5 - (__x)))
  202. #define d_nint(x) u_nint(*(x))
  203. #define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a)))
  204. #define d_sign(a,b) u_sign(*(a),*(b))
  205. #define r_sign(a,b) u_sign(*(a),*(b))
  206. #define d_sin(x) (sin(*(x)))
  207. #define d_sinh(x) (sinh(*(x)))
  208. #define d_sqrt(x) (sqrt(*(x)))
  209. #define d_tan(x) (tan(*(x)))
  210. #define d_tanh(x) (tanh(*(x)))
  211. #define i_abs(x) abs(*(x))
  212. #define i_dnnt(x) ((integer)u_nint(*(x)))
  213. #define i_len(s, n) (n)
  214. #define i_nint(x) ((integer)u_nint(*(x)))
  215. #define i_sign(a,b) ((integer)u_sign((integer)*(a),(integer)*(b)))
  216. #define pow_dd(ap, bp) ( pow(*(ap), *(bp)))
  217. #define pow_si(B,E) spow_ui(*(B),*(E))
  218. #define pow_ri(B,E) spow_ui(*(B),*(E))
  219. #define pow_di(B,E) dpow_ui(*(B),*(E))
  220. #define pow_zi(p, a, b) {pCd(p) = zpow_ui(Cd(a), *(b));}
  221. #define pow_ci(p, a, b) {pCf(p) = cpow_ui(Cf(a), *(b));}
  222. #define pow_zz(R,A,B) {pCd(R) = cpow(Cd(A),*(B));}
  223. #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++ = ' '; }
  224. #define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d))))
  225. #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]; }
  226. #define sig_die(s, kill) { exit(1); }
  227. #define s_stop(s, n) {exit(0);}
  228. static char junk[] = "\n@(#)LIBF77 VERSION 19990503\n";
  229. #define z_abs(z) (cabs(Cd(z)))
  230. #define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));}
  231. #define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));}
  232. #define myexit_() break;
  233. #define mycycle() continue;
  234. #define myceiling(w) {ceil(w)}
  235. #define myhuge(w) {HUGE_VAL}
  236. //#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);}
  237. #define mymaxloc(w,s,e,n) {dmaxloc_(w,*(s),*(e),n)}
  238. /* procedure parameter types for -A and -C++ */
  239. #ifdef __cplusplus
  240. typedef logical (*L_fp)(...);
  241. #else
  242. typedef logical (*L_fp)();
  243. #endif
  244. static float spow_ui(float x, integer n) {
  245. float pow=1.0; unsigned long int u;
  246. if(n != 0) {
  247. if(n < 0) n = -n, x = 1/x;
  248. for(u = n; ; ) {
  249. if(u & 01) pow *= x;
  250. if(u >>= 1) x *= x;
  251. else break;
  252. }
  253. }
  254. return pow;
  255. }
  256. static double dpow_ui(double x, integer n) {
  257. double pow=1.0; unsigned long int u;
  258. if(n != 0) {
  259. if(n < 0) n = -n, x = 1/x;
  260. for(u = n; ; ) {
  261. if(u & 01) pow *= x;
  262. if(u >>= 1) x *= x;
  263. else break;
  264. }
  265. }
  266. return pow;
  267. }
  268. #ifdef _MSC_VER
  269. static _Fcomplex cpow_ui(complex x, integer n) {
  270. complex pow={1.0,0.0}; unsigned long int u;
  271. if(n != 0) {
  272. if(n < 0) n = -n, x.r = 1/x.r, x.i=1/x.i;
  273. for(u = n; ; ) {
  274. if(u & 01) pow.r *= x.r, pow.i *= x.i;
  275. if(u >>= 1) x.r *= x.r, x.i *= x.i;
  276. else break;
  277. }
  278. }
  279. _Fcomplex p={pow.r, pow.i};
  280. return p;
  281. }
  282. #else
  283. static _Complex float cpow_ui(_Complex float x, integer n) {
  284. _Complex float pow=1.0; unsigned long int u;
  285. if(n != 0) {
  286. if(n < 0) n = -n, x = 1/x;
  287. for(u = n; ; ) {
  288. if(u & 01) pow *= x;
  289. if(u >>= 1) x *= x;
  290. else break;
  291. }
  292. }
  293. return pow;
  294. }
  295. #endif
  296. #ifdef _MSC_VER
  297. static _Dcomplex zpow_ui(_Dcomplex x, integer n) {
  298. _Dcomplex pow={1.0,0.0}; unsigned long int u;
  299. if(n != 0) {
  300. if(n < 0) n = -n, x._Val[0] = 1/x._Val[0], x._Val[1] =1/x._Val[1];
  301. for(u = n; ; ) {
  302. if(u & 01) pow._Val[0] *= x._Val[0], pow._Val[1] *= x._Val[1];
  303. if(u >>= 1) x._Val[0] *= x._Val[0], x._Val[1] *= x._Val[1];
  304. else break;
  305. }
  306. }
  307. _Dcomplex p = {pow._Val[0], pow._Val[1]};
  308. return p;
  309. }
  310. #else
  311. static _Complex double zpow_ui(_Complex double x, integer n) {
  312. _Complex double pow=1.0; unsigned long int u;
  313. if(n != 0) {
  314. if(n < 0) n = -n, x = 1/x;
  315. for(u = n; ; ) {
  316. if(u & 01) pow *= x;
  317. if(u >>= 1) x *= x;
  318. else break;
  319. }
  320. }
  321. return pow;
  322. }
  323. #endif
  324. static integer pow_ii(integer x, integer n) {
  325. integer pow; unsigned long int u;
  326. if (n <= 0) {
  327. if (n == 0 || x == 1) pow = 1;
  328. else if (x != -1) pow = x == 0 ? 1/x : 0;
  329. else n = -n;
  330. }
  331. if ((n > 0) || !(n == 0 || x == 1 || x != -1)) {
  332. u = n;
  333. for(pow = 1; ; ) {
  334. if(u & 01) pow *= x;
  335. if(u >>= 1) x *= x;
  336. else break;
  337. }
  338. }
  339. return pow;
  340. }
  341. static integer dmaxloc_(double *w, integer s, integer e, integer *n)
  342. {
  343. double m; integer i, mi;
  344. for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
  345. if (w[i-1]>m) mi=i ,m=w[i-1];
  346. return mi-s+1;
  347. }
  348. static integer smaxloc_(float *w, integer s, integer e, integer *n)
  349. {
  350. float m; integer i, mi;
  351. for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
  352. if (w[i-1]>m) mi=i ,m=w[i-1];
  353. return mi-s+1;
  354. }
  355. static inline void cdotc_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
  356. integer n = *n_, incx = *incx_, incy = *incy_, i;
  357. #ifdef _MSC_VER
  358. _Fcomplex zdotc = {0.0, 0.0};
  359. if (incx == 1 && incy == 1) {
  360. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  361. zdotc._Val[0] += conjf(Cf(&x[i]))._Val[0] * Cf(&y[i])._Val[0];
  362. zdotc._Val[1] += conjf(Cf(&x[i]))._Val[1] * Cf(&y[i])._Val[1];
  363. }
  364. } else {
  365. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  366. zdotc._Val[0] += conjf(Cf(&x[i*incx]))._Val[0] * Cf(&y[i*incy])._Val[0];
  367. zdotc._Val[1] += conjf(Cf(&x[i*incx]))._Val[1] * Cf(&y[i*incy])._Val[1];
  368. }
  369. }
  370. pCf(z) = zdotc;
  371. }
  372. #else
  373. _Complex float zdotc = 0.0;
  374. if (incx == 1 && incy == 1) {
  375. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  376. zdotc += conjf(Cf(&x[i])) * Cf(&y[i]);
  377. }
  378. } else {
  379. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  380. zdotc += conjf(Cf(&x[i*incx])) * Cf(&y[i*incy]);
  381. }
  382. }
  383. pCf(z) = zdotc;
  384. }
  385. #endif
  386. static inline void zdotc_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
  387. integer n = *n_, incx = *incx_, incy = *incy_, i;
  388. #ifdef _MSC_VER
  389. _Dcomplex zdotc = {0.0, 0.0};
  390. if (incx == 1 && incy == 1) {
  391. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  392. zdotc._Val[0] += conj(Cd(&x[i]))._Val[0] * Cd(&y[i])._Val[0];
  393. zdotc._Val[1] += conj(Cd(&x[i]))._Val[1] * Cd(&y[i])._Val[1];
  394. }
  395. } else {
  396. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  397. zdotc._Val[0] += conj(Cd(&x[i*incx]))._Val[0] * Cd(&y[i*incy])._Val[0];
  398. zdotc._Val[1] += conj(Cd(&x[i*incx]))._Val[1] * Cd(&y[i*incy])._Val[1];
  399. }
  400. }
  401. pCd(z) = zdotc;
  402. }
  403. #else
  404. _Complex double zdotc = 0.0;
  405. if (incx == 1 && incy == 1) {
  406. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  407. zdotc += conj(Cd(&x[i])) * Cd(&y[i]);
  408. }
  409. } else {
  410. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  411. zdotc += conj(Cd(&x[i*incx])) * Cd(&y[i*incy]);
  412. }
  413. }
  414. pCd(z) = zdotc;
  415. }
  416. #endif
  417. static inline void cdotu_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
  418. integer n = *n_, incx = *incx_, incy = *incy_, i;
  419. #ifdef _MSC_VER
  420. _Fcomplex zdotc = {0.0, 0.0};
  421. if (incx == 1 && incy == 1) {
  422. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  423. zdotc._Val[0] += Cf(&x[i])._Val[0] * Cf(&y[i])._Val[0];
  424. zdotc._Val[1] += Cf(&x[i])._Val[1] * Cf(&y[i])._Val[1];
  425. }
  426. } else {
  427. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  428. zdotc._Val[0] += Cf(&x[i*incx])._Val[0] * Cf(&y[i*incy])._Val[0];
  429. zdotc._Val[1] += Cf(&x[i*incx])._Val[1] * Cf(&y[i*incy])._Val[1];
  430. }
  431. }
  432. pCf(z) = zdotc;
  433. }
  434. #else
  435. _Complex float zdotc = 0.0;
  436. if (incx == 1 && incy == 1) {
  437. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  438. zdotc += Cf(&x[i]) * Cf(&y[i]);
  439. }
  440. } else {
  441. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  442. zdotc += Cf(&x[i*incx]) * Cf(&y[i*incy]);
  443. }
  444. }
  445. pCf(z) = zdotc;
  446. }
  447. #endif
  448. static inline void zdotu_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
  449. integer n = *n_, incx = *incx_, incy = *incy_, i;
  450. #ifdef _MSC_VER
  451. _Dcomplex zdotc = {0.0, 0.0};
  452. if (incx == 1 && incy == 1) {
  453. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  454. zdotc._Val[0] += Cd(&x[i])._Val[0] * Cd(&y[i])._Val[0];
  455. zdotc._Val[1] += Cd(&x[i])._Val[1] * Cd(&y[i])._Val[1];
  456. }
  457. } else {
  458. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  459. zdotc._Val[0] += Cd(&x[i*incx])._Val[0] * Cd(&y[i*incy])._Val[0];
  460. zdotc._Val[1] += Cd(&x[i*incx])._Val[1] * Cd(&y[i*incy])._Val[1];
  461. }
  462. }
  463. pCd(z) = zdotc;
  464. }
  465. #else
  466. _Complex double zdotc = 0.0;
  467. if (incx == 1 && incy == 1) {
  468. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  469. zdotc += Cd(&x[i]) * Cd(&y[i]);
  470. }
  471. } else {
  472. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  473. zdotc += Cd(&x[i*incx]) * Cd(&y[i*incy]);
  474. }
  475. }
  476. pCd(z) = zdotc;
  477. }
  478. #endif
  479. /* -- translated by f2c (version 20000121).
  480. You must link the resulting object file with the libraries:
  481. -lf2c -lm (in that order)
  482. */
  483. /* Table of constant values */
  484. static integer c__1 = 1;
  485. static doublereal c_b36 = .5;
  486. /* > \brief \b ZLATRS solves a triangular system of equations with the scale factor set to prevent overflow.
  487. */
  488. /* =========== DOCUMENTATION =========== */
  489. /* Online html documentation available at */
  490. /* http://www.netlib.org/lapack/explore-html/ */
  491. /* > \htmlonly */
  492. /* > Download ZLATRS + dependencies */
  493. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zlatrs.
  494. f"> */
  495. /* > [TGZ]</a> */
  496. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zlatrs.
  497. f"> */
  498. /* > [ZIP]</a> */
  499. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zlatrs.
  500. f"> */
  501. /* > [TXT]</a> */
  502. /* > \endhtmlonly */
  503. /* Definition: */
  504. /* =========== */
  505. /* SUBROUTINE ZLATRS( UPLO, TRANS, DIAG, NORMIN, N, A, LDA, X, SCALE, */
  506. /* CNORM, INFO ) */
  507. /* CHARACTER DIAG, NORMIN, TRANS, UPLO */
  508. /* INTEGER INFO, LDA, N */
  509. /* DOUBLE PRECISION SCALE */
  510. /* DOUBLE PRECISION CNORM( * ) */
  511. /* COMPLEX*16 A( LDA, * ), X( * ) */
  512. /* > \par Purpose: */
  513. /* ============= */
  514. /* > */
  515. /* > \verbatim */
  516. /* > */
  517. /* > ZLATRS solves one of the triangular systems */
  518. /* > */
  519. /* > A * x = s*b, A**T * x = s*b, or A**H * x = s*b, */
  520. /* > */
  521. /* > with scaling to prevent overflow. Here A is an upper or lower */
  522. /* > triangular matrix, A**T denotes the transpose of A, A**H denotes the */
  523. /* > conjugate transpose of A, x and b are n-element vectors, and s is a */
  524. /* > scaling factor, usually less than or equal to 1, chosen so that the */
  525. /* > components of x will be less than the overflow threshold. If the */
  526. /* > unscaled problem will not cause overflow, the Level 2 BLAS routine */
  527. /* > ZTRSV is called. If the matrix A is singular (A(j,j) = 0 for some j), */
  528. /* > then s is set to 0 and a non-trivial solution to A*x = 0 is returned. */
  529. /* > \endverbatim */
  530. /* Arguments: */
  531. /* ========== */
  532. /* > \param[in] UPLO */
  533. /* > \verbatim */
  534. /* > UPLO is CHARACTER*1 */
  535. /* > Specifies whether the matrix A is upper or lower triangular. */
  536. /* > = 'U': Upper triangular */
  537. /* > = 'L': Lower triangular */
  538. /* > \endverbatim */
  539. /* > */
  540. /* > \param[in] TRANS */
  541. /* > \verbatim */
  542. /* > TRANS is CHARACTER*1 */
  543. /* > Specifies the operation applied to A. */
  544. /* > = 'N': Solve A * x = s*b (No transpose) */
  545. /* > = 'T': Solve A**T * x = s*b (Transpose) */
  546. /* > = 'C': Solve A**H * x = s*b (Conjugate transpose) */
  547. /* > \endverbatim */
  548. /* > */
  549. /* > \param[in] DIAG */
  550. /* > \verbatim */
  551. /* > DIAG is CHARACTER*1 */
  552. /* > Specifies whether or not the matrix A is unit triangular. */
  553. /* > = 'N': Non-unit triangular */
  554. /* > = 'U': Unit triangular */
  555. /* > \endverbatim */
  556. /* > */
  557. /* > \param[in] NORMIN */
  558. /* > \verbatim */
  559. /* > NORMIN is CHARACTER*1 */
  560. /* > Specifies whether CNORM has been set or not. */
  561. /* > = 'Y': CNORM contains the column norms on entry */
  562. /* > = 'N': CNORM is not set on entry. On exit, the norms will */
  563. /* > be computed and stored in CNORM. */
  564. /* > \endverbatim */
  565. /* > */
  566. /* > \param[in] N */
  567. /* > \verbatim */
  568. /* > N is INTEGER */
  569. /* > The order of the matrix A. N >= 0. */
  570. /* > \endverbatim */
  571. /* > */
  572. /* > \param[in] A */
  573. /* > \verbatim */
  574. /* > A is COMPLEX*16 array, dimension (LDA,N) */
  575. /* > The triangular matrix A. If UPLO = 'U', the leading n by n */
  576. /* > upper triangular part of the array A contains the upper */
  577. /* > triangular matrix, and the strictly lower triangular part of */
  578. /* > A is not referenced. If UPLO = 'L', the leading n by n lower */
  579. /* > triangular part of the array A contains the lower triangular */
  580. /* > matrix, and the strictly upper triangular part of A is not */
  581. /* > referenced. If DIAG = 'U', the diagonal elements of A are */
  582. /* > also not referenced and are assumed to be 1. */
  583. /* > \endverbatim */
  584. /* > */
  585. /* > \param[in] LDA */
  586. /* > \verbatim */
  587. /* > LDA is INTEGER */
  588. /* > The leading dimension of the array A. LDA >= f2cmax (1,N). */
  589. /* > \endverbatim */
  590. /* > */
  591. /* > \param[in,out] X */
  592. /* > \verbatim */
  593. /* > X is COMPLEX*16 array, dimension (N) */
  594. /* > On entry, the right hand side b of the triangular system. */
  595. /* > On exit, X is overwritten by the solution vector x. */
  596. /* > \endverbatim */
  597. /* > */
  598. /* > \param[out] SCALE */
  599. /* > \verbatim */
  600. /* > SCALE is DOUBLE PRECISION */
  601. /* > The scaling factor s for the triangular system */
  602. /* > A * x = s*b, A**T * x = s*b, or A**H * x = s*b. */
  603. /* > If SCALE = 0, the matrix A is singular or badly scaled, and */
  604. /* > the vector x is an exact or approximate solution to A*x = 0. */
  605. /* > \endverbatim */
  606. /* > */
  607. /* > \param[in,out] CNORM */
  608. /* > \verbatim */
  609. /* > CNORM is DOUBLE PRECISION array, dimension (N) */
  610. /* > */
  611. /* > If NORMIN = 'Y', CNORM is an input argument and CNORM(j) */
  612. /* > contains the norm of the off-diagonal part of the j-th column */
  613. /* > of A. If TRANS = 'N', CNORM(j) must be greater than or equal */
  614. /* > to the infinity-norm, and if TRANS = 'T' or 'C', CNORM(j) */
  615. /* > must be greater than or equal to the 1-norm. */
  616. /* > */
  617. /* > If NORMIN = 'N', CNORM is an output argument and CNORM(j) */
  618. /* > returns the 1-norm of the offdiagonal part of the j-th column */
  619. /* > of A. */
  620. /* > \endverbatim */
  621. /* > */
  622. /* > \param[out] INFO */
  623. /* > \verbatim */
  624. /* > INFO is INTEGER */
  625. /* > = 0: successful exit */
  626. /* > < 0: if INFO = -k, the k-th argument had an illegal value */
  627. /* > \endverbatim */
  628. /* Authors: */
  629. /* ======== */
  630. /* > \author Univ. of Tennessee */
  631. /* > \author Univ. of California Berkeley */
  632. /* > \author Univ. of Colorado Denver */
  633. /* > \author NAG Ltd. */
  634. /* > \date November 2017 */
  635. /* > \ingroup complex16OTHERauxiliary */
  636. /* > \par Further Details: */
  637. /* ===================== */
  638. /* > */
  639. /* > \verbatim */
  640. /* > */
  641. /* > A rough bound on x is computed; if that is less than overflow, ZTRSV */
  642. /* > is called, otherwise, specific code is used which checks for possible */
  643. /* > overflow or divide-by-zero at every operation. */
  644. /* > */
  645. /* > A columnwise scheme is used for solving A*x = b. The basic algorithm */
  646. /* > if A is lower triangular is */
  647. /* > */
  648. /* > x[1:n] := b[1:n] */
  649. /* > for j = 1, ..., n */
  650. /* > x(j) := x(j) / A(j,j) */
  651. /* > x[j+1:n] := x[j+1:n] - x(j) * A[j+1:n,j] */
  652. /* > end */
  653. /* > */
  654. /* > Define bounds on the components of x after j iterations of the loop: */
  655. /* > M(j) = bound on x[1:j] */
  656. /* > G(j) = bound on x[j+1:n] */
  657. /* > Initially, let M(0) = 0 and G(0) = f2cmax{x(i), i=1,...,n}. */
  658. /* > */
  659. /* > Then for iteration j+1 we have */
  660. /* > M(j+1) <= G(j) / | A(j+1,j+1) | */
  661. /* > G(j+1) <= G(j) + M(j+1) * | A[j+2:n,j+1] | */
  662. /* > <= G(j) ( 1 + CNORM(j+1) / | A(j+1,j+1) | ) */
  663. /* > */
  664. /* > where CNORM(j+1) is greater than or equal to the infinity-norm of */
  665. /* > column j+1 of A, not counting the diagonal. Hence */
  666. /* > */
  667. /* > G(j) <= G(0) product ( 1 + CNORM(i) / | A(i,i) | ) */
  668. /* > 1<=i<=j */
  669. /* > and */
  670. /* > */
  671. /* > |x(j)| <= ( G(0) / |A(j,j)| ) product ( 1 + CNORM(i) / |A(i,i)| ) */
  672. /* > 1<=i< j */
  673. /* > */
  674. /* > Since |x(j)| <= M(j), we use the Level 2 BLAS routine ZTRSV if the */
  675. /* > reciprocal of the largest M(j), j=1,..,n, is larger than */
  676. /* > f2cmax(underflow, 1/overflow). */
  677. /* > */
  678. /* > The bound on x(j) is also used to determine when a step in the */
  679. /* > columnwise method can be performed without fear of overflow. If */
  680. /* > the computed bound is greater than a large constant, x is scaled to */
  681. /* > prevent overflow, but if the bound overflows, x is set to 0, x(j) to */
  682. /* > 1, and scale to 0, and a non-trivial solution to A*x = 0 is found. */
  683. /* > */
  684. /* > Similarly, a row-wise scheme is used to solve A**T *x = b or */
  685. /* > A**H *x = b. The basic algorithm for A upper triangular is */
  686. /* > */
  687. /* > for j = 1, ..., n */
  688. /* > x(j) := ( b(j) - A[1:j-1,j]' * x[1:j-1] ) / A(j,j) */
  689. /* > end */
  690. /* > */
  691. /* > We simultaneously compute two bounds */
  692. /* > G(j) = bound on ( b(i) - A[1:i-1,i]' * x[1:i-1] ), 1<=i<=j */
  693. /* > M(j) = bound on x(i), 1<=i<=j */
  694. /* > */
  695. /* > The initial values are G(0) = 0, M(0) = f2cmax{b(i), i=1,..,n}, and we */
  696. /* > add the constraint G(j) >= G(j-1) and M(j) >= M(j-1) for j >= 1. */
  697. /* > Then the bound on x(j) is */
  698. /* > */
  699. /* > M(j) <= M(j-1) * ( 1 + CNORM(j) ) / | A(j,j) | */
  700. /* > */
  701. /* > <= M(0) * product ( ( 1 + CNORM(i) ) / |A(i,i)| ) */
  702. /* > 1<=i<=j */
  703. /* > */
  704. /* > and we can safely call ZTRSV if 1/M(n) and 1/G(n) are both greater */
  705. /* > than f2cmax(underflow, 1/overflow). */
  706. /* > \endverbatim */
  707. /* > */
  708. /* ===================================================================== */
  709. /* Subroutine */ void zlatrs_(char *uplo, char *trans, char *diag, char *
  710. normin, integer *n, doublecomplex *a, integer *lda, doublecomplex *x,
  711. doublereal *scale, doublereal *cnorm, integer *info)
  712. {
  713. /* System generated locals */
  714. integer a_dim1, a_offset, i__1, i__2, i__3, i__4, i__5;
  715. doublereal d__1, d__2, d__3, d__4;
  716. doublecomplex z__1, z__2, z__3, z__4;
  717. /* Local variables */
  718. integer jinc;
  719. doublereal xbnd;
  720. integer imax;
  721. doublereal tmax;
  722. doublecomplex tjjs;
  723. doublereal xmax, grow;
  724. integer i__, j;
  725. extern /* Subroutine */ void dscal_(integer *, doublereal *, doublereal *,
  726. integer *);
  727. extern logical lsame_(char *, char *);
  728. doublereal tscal;
  729. doublecomplex uscal;
  730. integer jlast;
  731. doublecomplex csumj;
  732. extern /* Double Complex */ VOID zdotc_(doublecomplex *, integer *,
  733. doublecomplex *, integer *, doublecomplex *, integer *);
  734. logical upper;
  735. extern /* Double Complex */ VOID zdotu_(doublecomplex *, integer *,
  736. doublecomplex *, integer *, doublecomplex *, integer *);
  737. extern /* Subroutine */ void zaxpy_(integer *, doublecomplex *,
  738. doublecomplex *, integer *, doublecomplex *, integer *), ztrsv_(
  739. char *, char *, char *, integer *, doublecomplex *, integer *,
  740. doublecomplex *, integer *), dlabad_(
  741. doublereal *, doublereal *);
  742. extern doublereal dlamch_(char *);
  743. doublereal xj;
  744. extern integer idamax_(integer *, doublereal *, integer *);
  745. extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen);
  746. extern void zdscal_(
  747. integer *, doublereal *, doublecomplex *, integer *);
  748. doublereal bignum;
  749. extern integer izamax_(integer *, doublecomplex *, integer *);
  750. extern /* Double Complex */ VOID zladiv_(doublecomplex *, doublecomplex *,
  751. doublecomplex *);
  752. logical notran;
  753. integer jfirst;
  754. extern doublereal dzasum_(integer *, doublecomplex *, integer *);
  755. doublereal smlnum;
  756. logical nounit;
  757. doublereal rec, tjj;
  758. /* -- LAPACK auxiliary routine (version 3.8.0) -- */
  759. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  760. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  761. /* November 2017 */
  762. /* ===================================================================== */
  763. /* Parameter adjustments */
  764. a_dim1 = *lda;
  765. a_offset = 1 + a_dim1 * 1;
  766. a -= a_offset;
  767. --x;
  768. --cnorm;
  769. /* Function Body */
  770. *info = 0;
  771. upper = lsame_(uplo, "U");
  772. notran = lsame_(trans, "N");
  773. nounit = lsame_(diag, "N");
  774. /* Test the input parameters. */
  775. if (! upper && ! lsame_(uplo, "L")) {
  776. *info = -1;
  777. } else if (! notran && ! lsame_(trans, "T") && !
  778. lsame_(trans, "C")) {
  779. *info = -2;
  780. } else if (! nounit && ! lsame_(diag, "U")) {
  781. *info = -3;
  782. } else if (! lsame_(normin, "Y") && ! lsame_(normin,
  783. "N")) {
  784. *info = -4;
  785. } else if (*n < 0) {
  786. *info = -5;
  787. } else if (*lda < f2cmax(1,*n)) {
  788. *info = -7;
  789. }
  790. if (*info != 0) {
  791. i__1 = -(*info);
  792. xerbla_("ZLATRS", &i__1, (ftnlen)6);
  793. return;
  794. }
  795. /* Quick return if possible */
  796. if (*n == 0) {
  797. return;
  798. }
  799. /* Determine machine dependent parameters to control overflow. */
  800. smlnum = dlamch_("Safe minimum");
  801. bignum = 1. / smlnum;
  802. dlabad_(&smlnum, &bignum);
  803. smlnum /= dlamch_("Precision");
  804. bignum = 1. / smlnum;
  805. *scale = 1.;
  806. if (lsame_(normin, "N")) {
  807. /* Compute the 1-norm of each column, not including the diagonal. */
  808. if (upper) {
  809. /* A is upper triangular. */
  810. i__1 = *n;
  811. for (j = 1; j <= i__1; ++j) {
  812. i__2 = j - 1;
  813. cnorm[j] = dzasum_(&i__2, &a[j * a_dim1 + 1], &c__1);
  814. /* L10: */
  815. }
  816. } else {
  817. /* A is lower triangular. */
  818. i__1 = *n - 1;
  819. for (j = 1; j <= i__1; ++j) {
  820. i__2 = *n - j;
  821. cnorm[j] = dzasum_(&i__2, &a[j + 1 + j * a_dim1], &c__1);
  822. /* L20: */
  823. }
  824. cnorm[*n] = 0.;
  825. }
  826. }
  827. /* Scale the column norms by TSCAL if the maximum element in CNORM is */
  828. /* greater than BIGNUM/2. */
  829. imax = idamax_(n, &cnorm[1], &c__1);
  830. tmax = cnorm[imax];
  831. if (tmax <= bignum * .5) {
  832. tscal = 1.;
  833. } else {
  834. tscal = .5 / (smlnum * tmax);
  835. dscal_(n, &tscal, &cnorm[1], &c__1);
  836. }
  837. /* Compute a bound on the computed solution vector to see if the */
  838. /* Level 2 BLAS routine ZTRSV can be used. */
  839. xmax = 0.;
  840. i__1 = *n;
  841. for (j = 1; j <= i__1; ++j) {
  842. /* Computing MAX */
  843. i__2 = j;
  844. d__3 = xmax, d__4 = (d__1 = x[i__2].r / 2., abs(d__1)) + (d__2 =
  845. d_imag(&x[j]) / 2., abs(d__2));
  846. xmax = f2cmax(d__3,d__4);
  847. /* L30: */
  848. }
  849. xbnd = xmax;
  850. if (notran) {
  851. /* Compute the growth in A * x = b. */
  852. if (upper) {
  853. jfirst = *n;
  854. jlast = 1;
  855. jinc = -1;
  856. } else {
  857. jfirst = 1;
  858. jlast = *n;
  859. jinc = 1;
  860. }
  861. if (tscal != 1.) {
  862. grow = 0.;
  863. goto L60;
  864. }
  865. if (nounit) {
  866. /* A is non-unit triangular. */
  867. /* Compute GROW = 1/G(j) and XBND = 1/M(j). */
  868. /* Initially, G(0) = f2cmax{x(i), i=1,...,n}. */
  869. grow = .5 / f2cmax(xbnd,smlnum);
  870. xbnd = grow;
  871. i__1 = jlast;
  872. i__2 = jinc;
  873. for (j = jfirst; i__2 < 0 ? j >= i__1 : j <= i__1; j += i__2) {
  874. /* Exit the loop if the growth factor is too small. */
  875. if (grow <= smlnum) {
  876. goto L60;
  877. }
  878. i__3 = j + j * a_dim1;
  879. tjjs.r = a[i__3].r, tjjs.i = a[i__3].i;
  880. tjj = (d__1 = tjjs.r, abs(d__1)) + (d__2 = d_imag(&tjjs), abs(
  881. d__2));
  882. if (tjj >= smlnum) {
  883. /* M(j) = G(j-1) / abs(A(j,j)) */
  884. /* Computing MIN */
  885. d__1 = xbnd, d__2 = f2cmin(1.,tjj) * grow;
  886. xbnd = f2cmin(d__1,d__2);
  887. } else {
  888. /* M(j) could overflow, set XBND to 0. */
  889. xbnd = 0.;
  890. }
  891. if (tjj + cnorm[j] >= smlnum) {
  892. /* G(j) = G(j-1)*( 1 + CNORM(j) / abs(A(j,j)) ) */
  893. grow *= tjj / (tjj + cnorm[j]);
  894. } else {
  895. /* G(j) could overflow, set GROW to 0. */
  896. grow = 0.;
  897. }
  898. /* L40: */
  899. }
  900. grow = xbnd;
  901. } else {
  902. /* A is unit triangular. */
  903. /* Compute GROW = 1/G(j), where G(0) = f2cmax{x(i), i=1,...,n}. */
  904. /* Computing MIN */
  905. d__1 = 1., d__2 = .5 / f2cmax(xbnd,smlnum);
  906. grow = f2cmin(d__1,d__2);
  907. i__2 = jlast;
  908. i__1 = jinc;
  909. for (j = jfirst; i__1 < 0 ? j >= i__2 : j <= i__2; j += i__1) {
  910. /* Exit the loop if the growth factor is too small. */
  911. if (grow <= smlnum) {
  912. goto L60;
  913. }
  914. /* G(j) = G(j-1)*( 1 + CNORM(j) ) */
  915. grow *= 1. / (cnorm[j] + 1.);
  916. /* L50: */
  917. }
  918. }
  919. L60:
  920. ;
  921. } else {
  922. /* Compute the growth in A**T * x = b or A**H * x = b. */
  923. if (upper) {
  924. jfirst = 1;
  925. jlast = *n;
  926. jinc = 1;
  927. } else {
  928. jfirst = *n;
  929. jlast = 1;
  930. jinc = -1;
  931. }
  932. if (tscal != 1.) {
  933. grow = 0.;
  934. goto L90;
  935. }
  936. if (nounit) {
  937. /* A is non-unit triangular. */
  938. /* Compute GROW = 1/G(j) and XBND = 1/M(j). */
  939. /* Initially, M(0) = f2cmax{x(i), i=1,...,n}. */
  940. grow = .5 / f2cmax(xbnd,smlnum);
  941. xbnd = grow;
  942. i__1 = jlast;
  943. i__2 = jinc;
  944. for (j = jfirst; i__2 < 0 ? j >= i__1 : j <= i__1; j += i__2) {
  945. /* Exit the loop if the growth factor is too small. */
  946. if (grow <= smlnum) {
  947. goto L90;
  948. }
  949. /* G(j) = f2cmax( G(j-1), M(j-1)*( 1 + CNORM(j) ) ) */
  950. xj = cnorm[j] + 1.;
  951. /* Computing MIN */
  952. d__1 = grow, d__2 = xbnd / xj;
  953. grow = f2cmin(d__1,d__2);
  954. i__3 = j + j * a_dim1;
  955. tjjs.r = a[i__3].r, tjjs.i = a[i__3].i;
  956. tjj = (d__1 = tjjs.r, abs(d__1)) + (d__2 = d_imag(&tjjs), abs(
  957. d__2));
  958. if (tjj >= smlnum) {
  959. /* M(j) = M(j-1)*( 1 + CNORM(j) ) / abs(A(j,j)) */
  960. if (xj > tjj) {
  961. xbnd *= tjj / xj;
  962. }
  963. } else {
  964. /* M(j) could overflow, set XBND to 0. */
  965. xbnd = 0.;
  966. }
  967. /* L70: */
  968. }
  969. grow = f2cmin(grow,xbnd);
  970. } else {
  971. /* A is unit triangular. */
  972. /* Compute GROW = 1/G(j), where G(0) = f2cmax{x(i), i=1,...,n}. */
  973. /* Computing MIN */
  974. d__1 = 1., d__2 = .5 / f2cmax(xbnd,smlnum);
  975. grow = f2cmin(d__1,d__2);
  976. i__2 = jlast;
  977. i__1 = jinc;
  978. for (j = jfirst; i__1 < 0 ? j >= i__2 : j <= i__2; j += i__1) {
  979. /* Exit the loop if the growth factor is too small. */
  980. if (grow <= smlnum) {
  981. goto L90;
  982. }
  983. /* G(j) = ( 1 + CNORM(j) )*G(j-1) */
  984. xj = cnorm[j] + 1.;
  985. grow /= xj;
  986. /* L80: */
  987. }
  988. }
  989. L90:
  990. ;
  991. }
  992. if (grow * tscal > smlnum) {
  993. /* Use the Level 2 BLAS solve if the reciprocal of the bound on */
  994. /* elements of X is not too small. */
  995. ztrsv_(uplo, trans, diag, n, &a[a_offset], lda, &x[1], &c__1);
  996. } else {
  997. /* Use a Level 1 BLAS solve, scaling intermediate results. */
  998. if (xmax > bignum * .5) {
  999. /* Scale X so that its components are less than or equal to */
  1000. /* BIGNUM in absolute value. */
  1001. *scale = bignum * .5 / xmax;
  1002. zdscal_(n, scale, &x[1], &c__1);
  1003. xmax = bignum;
  1004. } else {
  1005. xmax *= 2.;
  1006. }
  1007. if (notran) {
  1008. /* Solve A * x = b */
  1009. i__1 = jlast;
  1010. i__2 = jinc;
  1011. for (j = jfirst; i__2 < 0 ? j >= i__1 : j <= i__1; j += i__2) {
  1012. /* Compute x(j) = b(j) / A(j,j), scaling x if necessary. */
  1013. i__3 = j;
  1014. xj = (d__1 = x[i__3].r, abs(d__1)) + (d__2 = d_imag(&x[j]),
  1015. abs(d__2));
  1016. if (nounit) {
  1017. i__3 = j + j * a_dim1;
  1018. z__1.r = tscal * a[i__3].r, z__1.i = tscal * a[i__3].i;
  1019. tjjs.r = z__1.r, tjjs.i = z__1.i;
  1020. } else {
  1021. tjjs.r = tscal, tjjs.i = 0.;
  1022. if (tscal == 1.) {
  1023. goto L110;
  1024. }
  1025. }
  1026. tjj = (d__1 = tjjs.r, abs(d__1)) + (d__2 = d_imag(&tjjs), abs(
  1027. d__2));
  1028. if (tjj > smlnum) {
  1029. /* abs(A(j,j)) > SMLNUM: */
  1030. if (tjj < 1.) {
  1031. if (xj > tjj * bignum) {
  1032. /* Scale x by 1/b(j). */
  1033. rec = 1. / xj;
  1034. zdscal_(n, &rec, &x[1], &c__1);
  1035. *scale *= rec;
  1036. xmax *= rec;
  1037. }
  1038. }
  1039. i__3 = j;
  1040. zladiv_(&z__1, &x[j], &tjjs);
  1041. x[i__3].r = z__1.r, x[i__3].i = z__1.i;
  1042. i__3 = j;
  1043. xj = (d__1 = x[i__3].r, abs(d__1)) + (d__2 = d_imag(&x[j])
  1044. , abs(d__2));
  1045. } else if (tjj > 0.) {
  1046. /* 0 < abs(A(j,j)) <= SMLNUM: */
  1047. if (xj > tjj * bignum) {
  1048. /* Scale x by (1/abs(x(j)))*abs(A(j,j))*BIGNUM */
  1049. /* to avoid overflow when dividing by A(j,j). */
  1050. rec = tjj * bignum / xj;
  1051. if (cnorm[j] > 1.) {
  1052. /* Scale by 1/CNORM(j) to avoid overflow when */
  1053. /* multiplying x(j) times column j. */
  1054. rec /= cnorm[j];
  1055. }
  1056. zdscal_(n, &rec, &x[1], &c__1);
  1057. *scale *= rec;
  1058. xmax *= rec;
  1059. }
  1060. i__3 = j;
  1061. zladiv_(&z__1, &x[j], &tjjs);
  1062. x[i__3].r = z__1.r, x[i__3].i = z__1.i;
  1063. i__3 = j;
  1064. xj = (d__1 = x[i__3].r, abs(d__1)) + (d__2 = d_imag(&x[j])
  1065. , abs(d__2));
  1066. } else {
  1067. /* A(j,j) = 0: Set x(1:n) = 0, x(j) = 1, and */
  1068. /* scale = 0, and compute a solution to A*x = 0. */
  1069. i__3 = *n;
  1070. for (i__ = 1; i__ <= i__3; ++i__) {
  1071. i__4 = i__;
  1072. x[i__4].r = 0., x[i__4].i = 0.;
  1073. /* L100: */
  1074. }
  1075. i__3 = j;
  1076. x[i__3].r = 1., x[i__3].i = 0.;
  1077. xj = 1.;
  1078. *scale = 0.;
  1079. xmax = 0.;
  1080. }
  1081. L110:
  1082. /* Scale x if necessary to avoid overflow when adding a */
  1083. /* multiple of column j of A. */
  1084. if (xj > 1.) {
  1085. rec = 1. / xj;
  1086. if (cnorm[j] > (bignum - xmax) * rec) {
  1087. /* Scale x by 1/(2*abs(x(j))). */
  1088. rec *= .5;
  1089. zdscal_(n, &rec, &x[1], &c__1);
  1090. *scale *= rec;
  1091. }
  1092. } else if (xj * cnorm[j] > bignum - xmax) {
  1093. /* Scale x by 1/2. */
  1094. zdscal_(n, &c_b36, &x[1], &c__1);
  1095. *scale *= .5;
  1096. }
  1097. if (upper) {
  1098. if (j > 1) {
  1099. /* Compute the update */
  1100. /* x(1:j-1) := x(1:j-1) - x(j) * A(1:j-1,j) */
  1101. i__3 = j - 1;
  1102. i__4 = j;
  1103. z__2.r = -x[i__4].r, z__2.i = -x[i__4].i;
  1104. z__1.r = tscal * z__2.r, z__1.i = tscal * z__2.i;
  1105. zaxpy_(&i__3, &z__1, &a[j * a_dim1 + 1], &c__1, &x[1],
  1106. &c__1);
  1107. i__3 = j - 1;
  1108. i__ = izamax_(&i__3, &x[1], &c__1);
  1109. i__3 = i__;
  1110. xmax = (d__1 = x[i__3].r, abs(d__1)) + (d__2 = d_imag(
  1111. &x[i__]), abs(d__2));
  1112. }
  1113. } else {
  1114. if (j < *n) {
  1115. /* Compute the update */
  1116. /* x(j+1:n) := x(j+1:n) - x(j) * A(j+1:n,j) */
  1117. i__3 = *n - j;
  1118. i__4 = j;
  1119. z__2.r = -x[i__4].r, z__2.i = -x[i__4].i;
  1120. z__1.r = tscal * z__2.r, z__1.i = tscal * z__2.i;
  1121. zaxpy_(&i__3, &z__1, &a[j + 1 + j * a_dim1], &c__1, &
  1122. x[j + 1], &c__1);
  1123. i__3 = *n - j;
  1124. i__ = j + izamax_(&i__3, &x[j + 1], &c__1);
  1125. i__3 = i__;
  1126. xmax = (d__1 = x[i__3].r, abs(d__1)) + (d__2 = d_imag(
  1127. &x[i__]), abs(d__2));
  1128. }
  1129. }
  1130. /* L120: */
  1131. }
  1132. } else if (lsame_(trans, "T")) {
  1133. /* Solve A**T * x = b */
  1134. i__2 = jlast;
  1135. i__1 = jinc;
  1136. for (j = jfirst; i__1 < 0 ? j >= i__2 : j <= i__2; j += i__1) {
  1137. /* Compute x(j) = b(j) - sum A(k,j)*x(k). */
  1138. /* k<>j */
  1139. i__3 = j;
  1140. xj = (d__1 = x[i__3].r, abs(d__1)) + (d__2 = d_imag(&x[j]),
  1141. abs(d__2));
  1142. uscal.r = tscal, uscal.i = 0.;
  1143. rec = 1. / f2cmax(xmax,1.);
  1144. if (cnorm[j] > (bignum - xj) * rec) {
  1145. /* If x(j) could overflow, scale x by 1/(2*XMAX). */
  1146. rec *= .5;
  1147. if (nounit) {
  1148. i__3 = j + j * a_dim1;
  1149. z__1.r = tscal * a[i__3].r, z__1.i = tscal * a[i__3]
  1150. .i;
  1151. tjjs.r = z__1.r, tjjs.i = z__1.i;
  1152. } else {
  1153. tjjs.r = tscal, tjjs.i = 0.;
  1154. }
  1155. tjj = (d__1 = tjjs.r, abs(d__1)) + (d__2 = d_imag(&tjjs),
  1156. abs(d__2));
  1157. if (tjj > 1.) {
  1158. /* Divide by A(j,j) when scaling x if A(j,j) > 1. */
  1159. /* Computing MIN */
  1160. d__1 = 1., d__2 = rec * tjj;
  1161. rec = f2cmin(d__1,d__2);
  1162. zladiv_(&z__1, &uscal, &tjjs);
  1163. uscal.r = z__1.r, uscal.i = z__1.i;
  1164. }
  1165. if (rec < 1.) {
  1166. zdscal_(n, &rec, &x[1], &c__1);
  1167. *scale *= rec;
  1168. xmax *= rec;
  1169. }
  1170. }
  1171. csumj.r = 0., csumj.i = 0.;
  1172. if (uscal.r == 1. && uscal.i == 0.) {
  1173. /* If the scaling needed for A in the dot product is 1, */
  1174. /* call ZDOTU to perform the dot product. */
  1175. if (upper) {
  1176. i__3 = j - 1;
  1177. zdotu_(&z__1, &i__3, &a[j * a_dim1 + 1], &c__1, &x[1],
  1178. &c__1);
  1179. csumj.r = z__1.r, csumj.i = z__1.i;
  1180. } else if (j < *n) {
  1181. i__3 = *n - j;
  1182. zdotu_(&z__1, &i__3, &a[j + 1 + j * a_dim1], &c__1, &
  1183. x[j + 1], &c__1);
  1184. csumj.r = z__1.r, csumj.i = z__1.i;
  1185. }
  1186. } else {
  1187. /* Otherwise, use in-line code for the dot product. */
  1188. if (upper) {
  1189. i__3 = j - 1;
  1190. for (i__ = 1; i__ <= i__3; ++i__) {
  1191. i__4 = i__ + j * a_dim1;
  1192. z__3.r = a[i__4].r * uscal.r - a[i__4].i *
  1193. uscal.i, z__3.i = a[i__4].r * uscal.i + a[
  1194. i__4].i * uscal.r;
  1195. i__5 = i__;
  1196. z__2.r = z__3.r * x[i__5].r - z__3.i * x[i__5].i,
  1197. z__2.i = z__3.r * x[i__5].i + z__3.i * x[
  1198. i__5].r;
  1199. z__1.r = csumj.r + z__2.r, z__1.i = csumj.i +
  1200. z__2.i;
  1201. csumj.r = z__1.r, csumj.i = z__1.i;
  1202. /* L130: */
  1203. }
  1204. } else if (j < *n) {
  1205. i__3 = *n;
  1206. for (i__ = j + 1; i__ <= i__3; ++i__) {
  1207. i__4 = i__ + j * a_dim1;
  1208. z__3.r = a[i__4].r * uscal.r - a[i__4].i *
  1209. uscal.i, z__3.i = a[i__4].r * uscal.i + a[
  1210. i__4].i * uscal.r;
  1211. i__5 = i__;
  1212. z__2.r = z__3.r * x[i__5].r - z__3.i * x[i__5].i,
  1213. z__2.i = z__3.r * x[i__5].i + z__3.i * x[
  1214. i__5].r;
  1215. z__1.r = csumj.r + z__2.r, z__1.i = csumj.i +
  1216. z__2.i;
  1217. csumj.r = z__1.r, csumj.i = z__1.i;
  1218. /* L140: */
  1219. }
  1220. }
  1221. }
  1222. z__1.r = tscal, z__1.i = 0.;
  1223. if (uscal.r == z__1.r && uscal.i == z__1.i) {
  1224. /* Compute x(j) := ( x(j) - CSUMJ ) / A(j,j) if 1/A(j,j) */
  1225. /* was not used to scale the dotproduct. */
  1226. i__3 = j;
  1227. i__4 = j;
  1228. z__1.r = x[i__4].r - csumj.r, z__1.i = x[i__4].i -
  1229. csumj.i;
  1230. x[i__3].r = z__1.r, x[i__3].i = z__1.i;
  1231. i__3 = j;
  1232. xj = (d__1 = x[i__3].r, abs(d__1)) + (d__2 = d_imag(&x[j])
  1233. , abs(d__2));
  1234. if (nounit) {
  1235. i__3 = j + j * a_dim1;
  1236. z__1.r = tscal * a[i__3].r, z__1.i = tscal * a[i__3]
  1237. .i;
  1238. tjjs.r = z__1.r, tjjs.i = z__1.i;
  1239. } else {
  1240. tjjs.r = tscal, tjjs.i = 0.;
  1241. if (tscal == 1.) {
  1242. goto L160;
  1243. }
  1244. }
  1245. /* Compute x(j) = x(j) / A(j,j), scaling if necessary. */
  1246. tjj = (d__1 = tjjs.r, abs(d__1)) + (d__2 = d_imag(&tjjs),
  1247. abs(d__2));
  1248. if (tjj > smlnum) {
  1249. /* abs(A(j,j)) > SMLNUM: */
  1250. if (tjj < 1.) {
  1251. if (xj > tjj * bignum) {
  1252. /* Scale X by 1/abs(x(j)). */
  1253. rec = 1. / xj;
  1254. zdscal_(n, &rec, &x[1], &c__1);
  1255. *scale *= rec;
  1256. xmax *= rec;
  1257. }
  1258. }
  1259. i__3 = j;
  1260. zladiv_(&z__1, &x[j], &tjjs);
  1261. x[i__3].r = z__1.r, x[i__3].i = z__1.i;
  1262. } else if (tjj > 0.) {
  1263. /* 0 < abs(A(j,j)) <= SMLNUM: */
  1264. if (xj > tjj * bignum) {
  1265. /* Scale x by (1/abs(x(j)))*abs(A(j,j))*BIGNUM. */
  1266. rec = tjj * bignum / xj;
  1267. zdscal_(n, &rec, &x[1], &c__1);
  1268. *scale *= rec;
  1269. xmax *= rec;
  1270. }
  1271. i__3 = j;
  1272. zladiv_(&z__1, &x[j], &tjjs);
  1273. x[i__3].r = z__1.r, x[i__3].i = z__1.i;
  1274. } else {
  1275. /* A(j,j) = 0: Set x(1:n) = 0, x(j) = 1, and */
  1276. /* scale = 0 and compute a solution to A**T *x = 0. */
  1277. i__3 = *n;
  1278. for (i__ = 1; i__ <= i__3; ++i__) {
  1279. i__4 = i__;
  1280. x[i__4].r = 0., x[i__4].i = 0.;
  1281. /* L150: */
  1282. }
  1283. i__3 = j;
  1284. x[i__3].r = 1., x[i__3].i = 0.;
  1285. *scale = 0.;
  1286. xmax = 0.;
  1287. }
  1288. L160:
  1289. ;
  1290. } else {
  1291. /* Compute x(j) := x(j) / A(j,j) - CSUMJ if the dot */
  1292. /* product has already been divided by 1/A(j,j). */
  1293. i__3 = j;
  1294. zladiv_(&z__2, &x[j], &tjjs);
  1295. z__1.r = z__2.r - csumj.r, z__1.i = z__2.i - csumj.i;
  1296. x[i__3].r = z__1.r, x[i__3].i = z__1.i;
  1297. }
  1298. /* Computing MAX */
  1299. i__3 = j;
  1300. d__3 = xmax, d__4 = (d__1 = x[i__3].r, abs(d__1)) + (d__2 =
  1301. d_imag(&x[j]), abs(d__2));
  1302. xmax = f2cmax(d__3,d__4);
  1303. /* L170: */
  1304. }
  1305. } else {
  1306. /* Solve A**H * x = b */
  1307. i__1 = jlast;
  1308. i__2 = jinc;
  1309. for (j = jfirst; i__2 < 0 ? j >= i__1 : j <= i__1; j += i__2) {
  1310. /* Compute x(j) = b(j) - sum A(k,j)*x(k). */
  1311. /* k<>j */
  1312. i__3 = j;
  1313. xj = (d__1 = x[i__3].r, abs(d__1)) + (d__2 = d_imag(&x[j]),
  1314. abs(d__2));
  1315. uscal.r = tscal, uscal.i = 0.;
  1316. rec = 1. / f2cmax(xmax,1.);
  1317. if (cnorm[j] > (bignum - xj) * rec) {
  1318. /* If x(j) could overflow, scale x by 1/(2*XMAX). */
  1319. rec *= .5;
  1320. if (nounit) {
  1321. d_cnjg(&z__2, &a[j + j * a_dim1]);
  1322. z__1.r = tscal * z__2.r, z__1.i = tscal * z__2.i;
  1323. tjjs.r = z__1.r, tjjs.i = z__1.i;
  1324. } else {
  1325. tjjs.r = tscal, tjjs.i = 0.;
  1326. }
  1327. tjj = (d__1 = tjjs.r, abs(d__1)) + (d__2 = d_imag(&tjjs),
  1328. abs(d__2));
  1329. if (tjj > 1.) {
  1330. /* Divide by A(j,j) when scaling x if A(j,j) > 1. */
  1331. /* Computing MIN */
  1332. d__1 = 1., d__2 = rec * tjj;
  1333. rec = f2cmin(d__1,d__2);
  1334. zladiv_(&z__1, &uscal, &tjjs);
  1335. uscal.r = z__1.r, uscal.i = z__1.i;
  1336. }
  1337. if (rec < 1.) {
  1338. zdscal_(n, &rec, &x[1], &c__1);
  1339. *scale *= rec;
  1340. xmax *= rec;
  1341. }
  1342. }
  1343. csumj.r = 0., csumj.i = 0.;
  1344. if (uscal.r == 1. && uscal.i == 0.) {
  1345. /* If the scaling needed for A in the dot product is 1, */
  1346. /* call ZDOTC to perform the dot product. */
  1347. if (upper) {
  1348. i__3 = j - 1;
  1349. zdotc_(&z__1, &i__3, &a[j * a_dim1 + 1], &c__1, &x[1],
  1350. &c__1);
  1351. csumj.r = z__1.r, csumj.i = z__1.i;
  1352. } else if (j < *n) {
  1353. i__3 = *n - j;
  1354. zdotc_(&z__1, &i__3, &a[j + 1 + j * a_dim1], &c__1, &
  1355. x[j + 1], &c__1);
  1356. csumj.r = z__1.r, csumj.i = z__1.i;
  1357. }
  1358. } else {
  1359. /* Otherwise, use in-line code for the dot product. */
  1360. if (upper) {
  1361. i__3 = j - 1;
  1362. for (i__ = 1; i__ <= i__3; ++i__) {
  1363. d_cnjg(&z__4, &a[i__ + j * a_dim1]);
  1364. z__3.r = z__4.r * uscal.r - z__4.i * uscal.i,
  1365. z__3.i = z__4.r * uscal.i + z__4.i *
  1366. uscal.r;
  1367. i__4 = i__;
  1368. z__2.r = z__3.r * x[i__4].r - z__3.i * x[i__4].i,
  1369. z__2.i = z__3.r * x[i__4].i + z__3.i * x[
  1370. i__4].r;
  1371. z__1.r = csumj.r + z__2.r, z__1.i = csumj.i +
  1372. z__2.i;
  1373. csumj.r = z__1.r, csumj.i = z__1.i;
  1374. /* L180: */
  1375. }
  1376. } else if (j < *n) {
  1377. i__3 = *n;
  1378. for (i__ = j + 1; i__ <= i__3; ++i__) {
  1379. d_cnjg(&z__4, &a[i__ + j * a_dim1]);
  1380. z__3.r = z__4.r * uscal.r - z__4.i * uscal.i,
  1381. z__3.i = z__4.r * uscal.i + z__4.i *
  1382. uscal.r;
  1383. i__4 = i__;
  1384. z__2.r = z__3.r * x[i__4].r - z__3.i * x[i__4].i,
  1385. z__2.i = z__3.r * x[i__4].i + z__3.i * x[
  1386. i__4].r;
  1387. z__1.r = csumj.r + z__2.r, z__1.i = csumj.i +
  1388. z__2.i;
  1389. csumj.r = z__1.r, csumj.i = z__1.i;
  1390. /* L190: */
  1391. }
  1392. }
  1393. }
  1394. z__1.r = tscal, z__1.i = 0.;
  1395. if (uscal.r == z__1.r && uscal.i == z__1.i) {
  1396. /* Compute x(j) := ( x(j) - CSUMJ ) / A(j,j) if 1/A(j,j) */
  1397. /* was not used to scale the dotproduct. */
  1398. i__3 = j;
  1399. i__4 = j;
  1400. z__1.r = x[i__4].r - csumj.r, z__1.i = x[i__4].i -
  1401. csumj.i;
  1402. x[i__3].r = z__1.r, x[i__3].i = z__1.i;
  1403. i__3 = j;
  1404. xj = (d__1 = x[i__3].r, abs(d__1)) + (d__2 = d_imag(&x[j])
  1405. , abs(d__2));
  1406. if (nounit) {
  1407. d_cnjg(&z__2, &a[j + j * a_dim1]);
  1408. z__1.r = tscal * z__2.r, z__1.i = tscal * z__2.i;
  1409. tjjs.r = z__1.r, tjjs.i = z__1.i;
  1410. } else {
  1411. tjjs.r = tscal, tjjs.i = 0.;
  1412. if (tscal == 1.) {
  1413. goto L210;
  1414. }
  1415. }
  1416. /* Compute x(j) = x(j) / A(j,j), scaling if necessary. */
  1417. tjj = (d__1 = tjjs.r, abs(d__1)) + (d__2 = d_imag(&tjjs),
  1418. abs(d__2));
  1419. if (tjj > smlnum) {
  1420. /* abs(A(j,j)) > SMLNUM: */
  1421. if (tjj < 1.) {
  1422. if (xj > tjj * bignum) {
  1423. /* Scale X by 1/abs(x(j)). */
  1424. rec = 1. / xj;
  1425. zdscal_(n, &rec, &x[1], &c__1);
  1426. *scale *= rec;
  1427. xmax *= rec;
  1428. }
  1429. }
  1430. i__3 = j;
  1431. zladiv_(&z__1, &x[j], &tjjs);
  1432. x[i__3].r = z__1.r, x[i__3].i = z__1.i;
  1433. } else if (tjj > 0.) {
  1434. /* 0 < abs(A(j,j)) <= SMLNUM: */
  1435. if (xj > tjj * bignum) {
  1436. /* Scale x by (1/abs(x(j)))*abs(A(j,j))*BIGNUM. */
  1437. rec = tjj * bignum / xj;
  1438. zdscal_(n, &rec, &x[1], &c__1);
  1439. *scale *= rec;
  1440. xmax *= rec;
  1441. }
  1442. i__3 = j;
  1443. zladiv_(&z__1, &x[j], &tjjs);
  1444. x[i__3].r = z__1.r, x[i__3].i = z__1.i;
  1445. } else {
  1446. /* A(j,j) = 0: Set x(1:n) = 0, x(j) = 1, and */
  1447. /* scale = 0 and compute a solution to A**H *x = 0. */
  1448. i__3 = *n;
  1449. for (i__ = 1; i__ <= i__3; ++i__) {
  1450. i__4 = i__;
  1451. x[i__4].r = 0., x[i__4].i = 0.;
  1452. /* L200: */
  1453. }
  1454. i__3 = j;
  1455. x[i__3].r = 1., x[i__3].i = 0.;
  1456. *scale = 0.;
  1457. xmax = 0.;
  1458. }
  1459. L210:
  1460. ;
  1461. } else {
  1462. /* Compute x(j) := x(j) / A(j,j) - CSUMJ if the dot */
  1463. /* product has already been divided by 1/A(j,j). */
  1464. i__3 = j;
  1465. zladiv_(&z__2, &x[j], &tjjs);
  1466. z__1.r = z__2.r - csumj.r, z__1.i = z__2.i - csumj.i;
  1467. x[i__3].r = z__1.r, x[i__3].i = z__1.i;
  1468. }
  1469. /* Computing MAX */
  1470. i__3 = j;
  1471. d__3 = xmax, d__4 = (d__1 = x[i__3].r, abs(d__1)) + (d__2 =
  1472. d_imag(&x[j]), abs(d__2));
  1473. xmax = f2cmax(d__3,d__4);
  1474. /* L220: */
  1475. }
  1476. }
  1477. *scale /= tscal;
  1478. }
  1479. /* Scale the column norms by 1/TSCAL for return. */
  1480. if (tscal != 1.) {
  1481. d__1 = 1. / tscal;
  1482. dscal_(n, &d__1, &cnorm[1], &c__1);
  1483. }
  1484. return;
  1485. /* End of ZLATRS */
  1486. } /* zlatrs_ */