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.

slatrs.c 37 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383
  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]/df(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 real c_b36 = .5f;
  486. /* > \brief \b SLATRS 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 SLATRS + dependencies */
  493. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/slatrs.
  494. f"> */
  495. /* > [TGZ]</a> */
  496. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/slatrs.
  497. f"> */
  498. /* > [ZIP]</a> */
  499. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/slatrs.
  500. f"> */
  501. /* > [TXT]</a> */
  502. /* > \endhtmlonly */
  503. /* Definition: */
  504. /* =========== */
  505. /* SUBROUTINE SLATRS( UPLO, TRANS, DIAG, NORMIN, N, A, LDA, X, SCALE, */
  506. /* CNORM, INFO ) */
  507. /* CHARACTER DIAG, NORMIN, TRANS, UPLO */
  508. /* INTEGER INFO, LDA, N */
  509. /* REAL SCALE */
  510. /* REAL A( LDA, * ), CNORM( * ), X( * ) */
  511. /* > \par Purpose: */
  512. /* ============= */
  513. /* > */
  514. /* > \verbatim */
  515. /* > */
  516. /* > SLATRS solves one of the triangular systems */
  517. /* > */
  518. /* > A *x = s*b or A**T*x = s*b */
  519. /* > */
  520. /* > with scaling to prevent overflow. Here A is an upper or lower */
  521. /* > triangular matrix, A**T denotes the transpose of A, x and b are */
  522. /* > n-element vectors, and s is a scaling factor, usually less than */
  523. /* > or equal to 1, chosen so that the components of x will be less than */
  524. /* > the overflow threshold. If the unscaled problem will not cause */
  525. /* > overflow, the Level 2 BLAS routine STRSV is called. If the matrix A */
  526. /* > is singular (A(j,j) = 0 for some j), then s is set to 0 and a */
  527. /* > non-trivial solution to A*x = 0 is returned. */
  528. /* > \endverbatim */
  529. /* Arguments: */
  530. /* ========== */
  531. /* > \param[in] UPLO */
  532. /* > \verbatim */
  533. /* > UPLO is CHARACTER*1 */
  534. /* > Specifies whether the matrix A is upper or lower triangular. */
  535. /* > = 'U': Upper triangular */
  536. /* > = 'L': Lower triangular */
  537. /* > \endverbatim */
  538. /* > */
  539. /* > \param[in] TRANS */
  540. /* > \verbatim */
  541. /* > TRANS is CHARACTER*1 */
  542. /* > Specifies the operation applied to A. */
  543. /* > = 'N': Solve A * x = s*b (No transpose) */
  544. /* > = 'T': Solve A**T* x = s*b (Transpose) */
  545. /* > = 'C': Solve A**T* x = s*b (Conjugate transpose = Transpose) */
  546. /* > \endverbatim */
  547. /* > */
  548. /* > \param[in] DIAG */
  549. /* > \verbatim */
  550. /* > DIAG is CHARACTER*1 */
  551. /* > Specifies whether or not the matrix A is unit triangular. */
  552. /* > = 'N': Non-unit triangular */
  553. /* > = 'U': Unit triangular */
  554. /* > \endverbatim */
  555. /* > */
  556. /* > \param[in] NORMIN */
  557. /* > \verbatim */
  558. /* > NORMIN is CHARACTER*1 */
  559. /* > Specifies whether CNORM has been set or not. */
  560. /* > = 'Y': CNORM contains the column norms on entry */
  561. /* > = 'N': CNORM is not set on entry. On exit, the norms will */
  562. /* > be computed and stored in CNORM. */
  563. /* > \endverbatim */
  564. /* > */
  565. /* > \param[in] N */
  566. /* > \verbatim */
  567. /* > N is INTEGER */
  568. /* > The order of the matrix A. N >= 0. */
  569. /* > \endverbatim */
  570. /* > */
  571. /* > \param[in] A */
  572. /* > \verbatim */
  573. /* > A is REAL array, dimension (LDA,N) */
  574. /* > The triangular matrix A. If UPLO = 'U', the leading n by n */
  575. /* > upper triangular part of the array A contains the upper */
  576. /* > triangular matrix, and the strictly lower triangular part of */
  577. /* > A is not referenced. If UPLO = 'L', the leading n by n lower */
  578. /* > triangular part of the array A contains the lower triangular */
  579. /* > matrix, and the strictly upper triangular part of A is not */
  580. /* > referenced. If DIAG = 'U', the diagonal elements of A are */
  581. /* > also not referenced and are assumed to be 1. */
  582. /* > \endverbatim */
  583. /* > */
  584. /* > \param[in] LDA */
  585. /* > \verbatim */
  586. /* > LDA is INTEGER */
  587. /* > The leading dimension of the array A. LDA >= f2cmax (1,N). */
  588. /* > \endverbatim */
  589. /* > */
  590. /* > \param[in,out] X */
  591. /* > \verbatim */
  592. /* > X is REAL array, dimension (N) */
  593. /* > On entry, the right hand side b of the triangular system. */
  594. /* > On exit, X is overwritten by the solution vector x. */
  595. /* > \endverbatim */
  596. /* > */
  597. /* > \param[out] SCALE */
  598. /* > \verbatim */
  599. /* > SCALE is REAL */
  600. /* > The scaling factor s for the triangular system */
  601. /* > A * x = s*b or A**T* x = s*b. */
  602. /* > If SCALE = 0, the matrix A is singular or badly scaled, and */
  603. /* > the vector x is an exact or approximate solution to A*x = 0. */
  604. /* > \endverbatim */
  605. /* > */
  606. /* > \param[in,out] CNORM */
  607. /* > \verbatim */
  608. /* > CNORM is REAL array, dimension (N) */
  609. /* > */
  610. /* > If NORMIN = 'Y', CNORM is an input argument and CNORM(j) */
  611. /* > contains the norm of the off-diagonal part of the j-th column */
  612. /* > of A. If TRANS = 'N', CNORM(j) must be greater than or equal */
  613. /* > to the infinity-norm, and if TRANS = 'T' or 'C', CNORM(j) */
  614. /* > must be greater than or equal to the 1-norm. */
  615. /* > */
  616. /* > If NORMIN = 'N', CNORM is an output argument and CNORM(j) */
  617. /* > returns the 1-norm of the offdiagonal part of the j-th column */
  618. /* > of A. */
  619. /* > \endverbatim */
  620. /* > */
  621. /* > \param[out] INFO */
  622. /* > \verbatim */
  623. /* > INFO is INTEGER */
  624. /* > = 0: successful exit */
  625. /* > < 0: if INFO = -k, the k-th argument had an illegal value */
  626. /* > \endverbatim */
  627. /* Authors: */
  628. /* ======== */
  629. /* > \author Univ. of Tennessee */
  630. /* > \author Univ. of California Berkeley */
  631. /* > \author Univ. of Colorado Denver */
  632. /* > \author NAG Ltd. */
  633. /* > \date December 2016 */
  634. /* > \ingroup realOTHERauxiliary */
  635. /* > \par Further Details: */
  636. /* ===================== */
  637. /* > */
  638. /* > \verbatim */
  639. /* > */
  640. /* > A rough bound on x is computed; if that is less than overflow, STRSV */
  641. /* > is called, otherwise, specific code is used which checks for possible */
  642. /* > overflow or divide-by-zero at every operation. */
  643. /* > */
  644. /* > A columnwise scheme is used for solving A*x = b. The basic algorithm */
  645. /* > if A is lower triangular is */
  646. /* > */
  647. /* > x[1:n] := b[1:n] */
  648. /* > for j = 1, ..., n */
  649. /* > x(j) := x(j) / A(j,j) */
  650. /* > x[j+1:n] := x[j+1:n] - x(j) * A[j+1:n,j] */
  651. /* > end */
  652. /* > */
  653. /* > Define bounds on the components of x after j iterations of the loop: */
  654. /* > M(j) = bound on x[1:j] */
  655. /* > G(j) = bound on x[j+1:n] */
  656. /* > Initially, let M(0) = 0 and G(0) = f2cmax{x(i), i=1,...,n}. */
  657. /* > */
  658. /* > Then for iteration j+1 we have */
  659. /* > M(j+1) <= G(j) / | A(j+1,j+1) | */
  660. /* > G(j+1) <= G(j) + M(j+1) * | A[j+2:n,j+1] | */
  661. /* > <= G(j) ( 1 + CNORM(j+1) / | A(j+1,j+1) | ) */
  662. /* > */
  663. /* > where CNORM(j+1) is greater than or equal to the infinity-norm of */
  664. /* > column j+1 of A, not counting the diagonal. Hence */
  665. /* > */
  666. /* > G(j) <= G(0) product ( 1 + CNORM(i) / | A(i,i) | ) */
  667. /* > 1<=i<=j */
  668. /* > and */
  669. /* > */
  670. /* > |x(j)| <= ( G(0) / |A(j,j)| ) product ( 1 + CNORM(i) / |A(i,i)| ) */
  671. /* > 1<=i< j */
  672. /* > */
  673. /* > Since |x(j)| <= M(j), we use the Level 2 BLAS routine STRSV if the */
  674. /* > reciprocal of the largest M(j), j=1,..,n, is larger than */
  675. /* > f2cmax(underflow, 1/overflow). */
  676. /* > */
  677. /* > The bound on x(j) is also used to determine when a step in the */
  678. /* > columnwise method can be performed without fear of overflow. If */
  679. /* > the computed bound is greater than a large constant, x is scaled to */
  680. /* > prevent overflow, but if the bound overflows, x is set to 0, x(j) to */
  681. /* > 1, and scale to 0, and a non-trivial solution to A*x = 0 is found. */
  682. /* > */
  683. /* > Similarly, a row-wise scheme is used to solve A**T*x = b. The basic */
  684. /* > algorithm for A upper triangular is */
  685. /* > */
  686. /* > for j = 1, ..., n */
  687. /* > x(j) := ( b(j) - A[1:j-1,j]**T * x[1:j-1] ) / A(j,j) */
  688. /* > end */
  689. /* > */
  690. /* > We simultaneously compute two bounds */
  691. /* > G(j) = bound on ( b(i) - A[1:i-1,i]**T * x[1:i-1] ), 1<=i<=j */
  692. /* > M(j) = bound on x(i), 1<=i<=j */
  693. /* > */
  694. /* > The initial values are G(0) = 0, M(0) = f2cmax{b(i), i=1,..,n}, and we */
  695. /* > add the constraint G(j) >= G(j-1) and M(j) >= M(j-1) for j >= 1. */
  696. /* > Then the bound on x(j) is */
  697. /* > */
  698. /* > M(j) <= M(j-1) * ( 1 + CNORM(j) ) / | A(j,j) | */
  699. /* > */
  700. /* > <= M(0) * product ( ( 1 + CNORM(i) ) / |A(i,i)| ) */
  701. /* > 1<=i<=j */
  702. /* > */
  703. /* > and we can safely call STRSV if 1/M(n) and 1/G(n) are both greater */
  704. /* > than f2cmax(underflow, 1/overflow). */
  705. /* > \endverbatim */
  706. /* > */
  707. /* ===================================================================== */
  708. /* Subroutine */ void slatrs_(char *uplo, char *trans, char *diag, char *
  709. normin, integer *n, real *a, integer *lda, real *x, real *scale, real
  710. *cnorm, integer *info)
  711. {
  712. /* System generated locals */
  713. integer a_dim1, a_offset, i__1, i__2, i__3;
  714. real r__1, r__2, r__3;
  715. /* Local variables */
  716. integer jinc;
  717. real xbnd;
  718. integer imax;
  719. real tmax, tjjs;
  720. extern real sdot_(integer *, real *, integer *, real *, integer *);
  721. real xmax, grow, sumj;
  722. integer i__, j;
  723. extern logical lsame_(char *, char *);
  724. extern /* Subroutine */ void sscal_(integer *, real *, real *, integer *);
  725. real tscal, uscal;
  726. integer jlast;
  727. extern real sasum_(integer *, real *, integer *);
  728. logical upper;
  729. extern /* Subroutine */ void saxpy_(integer *, real *, real *, integer *,
  730. real *, integer *), strsv_(char *, char *, char *, integer *,
  731. real *, integer *, real *, integer *);
  732. real xj;
  733. extern real slamch_(char *);
  734. extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen);
  735. real bignum;
  736. extern integer isamax_(integer *, real *, integer *);
  737. logical notran;
  738. integer jfirst;
  739. real smlnum;
  740. logical nounit;
  741. real rec, tjj;
  742. /* -- LAPACK auxiliary routine (version 3.7.0) -- */
  743. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  744. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  745. /* December 2016 */
  746. /* ===================================================================== */
  747. /* Parameter adjustments */
  748. a_dim1 = *lda;
  749. a_offset = 1 + a_dim1 * 1;
  750. a -= a_offset;
  751. --x;
  752. --cnorm;
  753. /* Function Body */
  754. *info = 0;
  755. upper = lsame_(uplo, "U");
  756. notran = lsame_(trans, "N");
  757. nounit = lsame_(diag, "N");
  758. /* Test the input parameters. */
  759. if (! upper && ! lsame_(uplo, "L")) {
  760. *info = -1;
  761. } else if (! notran && ! lsame_(trans, "T") && !
  762. lsame_(trans, "C")) {
  763. *info = -2;
  764. } else if (! nounit && ! lsame_(diag, "U")) {
  765. *info = -3;
  766. } else if (! lsame_(normin, "Y") && ! lsame_(normin,
  767. "N")) {
  768. *info = -4;
  769. } else if (*n < 0) {
  770. *info = -5;
  771. } else if (*lda < f2cmax(1,*n)) {
  772. *info = -7;
  773. }
  774. if (*info != 0) {
  775. i__1 = -(*info);
  776. xerbla_("SLATRS", &i__1, (ftnlen)6);
  777. return;
  778. }
  779. /* Quick return if possible */
  780. if (*n == 0) {
  781. return;
  782. }
  783. /* Determine machine dependent parameters to control overflow. */
  784. smlnum = slamch_("Safe minimum") / slamch_("Precision");
  785. bignum = 1.f / smlnum;
  786. *scale = 1.f;
  787. if (lsame_(normin, "N")) {
  788. /* Compute the 1-norm of each column, not including the diagonal. */
  789. if (upper) {
  790. /* A is upper triangular. */
  791. i__1 = *n;
  792. for (j = 1; j <= i__1; ++j) {
  793. i__2 = j - 1;
  794. cnorm[j] = sasum_(&i__2, &a[j * a_dim1 + 1], &c__1);
  795. /* L10: */
  796. }
  797. } else {
  798. /* A is lower triangular. */
  799. i__1 = *n - 1;
  800. for (j = 1; j <= i__1; ++j) {
  801. i__2 = *n - j;
  802. cnorm[j] = sasum_(&i__2, &a[j + 1 + j * a_dim1], &c__1);
  803. /* L20: */
  804. }
  805. cnorm[*n] = 0.f;
  806. }
  807. }
  808. /* Scale the column norms by TSCAL if the maximum element in CNORM is */
  809. /* greater than BIGNUM. */
  810. imax = isamax_(n, &cnorm[1], &c__1);
  811. tmax = cnorm[imax];
  812. if (tmax <= bignum) {
  813. tscal = 1.f;
  814. } else {
  815. tscal = 1.f / (smlnum * tmax);
  816. sscal_(n, &tscal, &cnorm[1], &c__1);
  817. }
  818. /* Compute a bound on the computed solution vector to see if the */
  819. /* Level 2 BLAS routine STRSV can be used. */
  820. j = isamax_(n, &x[1], &c__1);
  821. xmax = (r__1 = x[j], abs(r__1));
  822. xbnd = xmax;
  823. if (notran) {
  824. /* Compute the growth in A * x = b. */
  825. if (upper) {
  826. jfirst = *n;
  827. jlast = 1;
  828. jinc = -1;
  829. } else {
  830. jfirst = 1;
  831. jlast = *n;
  832. jinc = 1;
  833. }
  834. if (tscal != 1.f) {
  835. grow = 0.f;
  836. goto L50;
  837. }
  838. if (nounit) {
  839. /* A is non-unit triangular. */
  840. /* Compute GROW = 1/G(j) and XBND = 1/M(j). */
  841. /* Initially, G(0) = f2cmax{x(i), i=1,...,n}. */
  842. grow = 1.f / f2cmax(xbnd,smlnum);
  843. xbnd = grow;
  844. i__1 = jlast;
  845. i__2 = jinc;
  846. for (j = jfirst; i__2 < 0 ? j >= i__1 : j <= i__1; j += i__2) {
  847. /* Exit the loop if the growth factor is too small. */
  848. if (grow <= smlnum) {
  849. goto L50;
  850. }
  851. /* M(j) = G(j-1) / abs(A(j,j)) */
  852. tjj = (r__1 = a[j + j * a_dim1], abs(r__1));
  853. /* Computing MIN */
  854. r__1 = xbnd, r__2 = f2cmin(1.f,tjj) * grow;
  855. xbnd = f2cmin(r__1,r__2);
  856. if (tjj + cnorm[j] >= smlnum) {
  857. /* G(j) = G(j-1)*( 1 + CNORM(j) / abs(A(j,j)) ) */
  858. grow *= tjj / (tjj + cnorm[j]);
  859. } else {
  860. /* G(j) could overflow, set GROW to 0. */
  861. grow = 0.f;
  862. }
  863. /* L30: */
  864. }
  865. grow = xbnd;
  866. } else {
  867. /* A is unit triangular. */
  868. /* Compute GROW = 1/G(j), where G(0) = f2cmax{x(i), i=1,...,n}. */
  869. /* Computing MIN */
  870. r__1 = 1.f, r__2 = 1.f / f2cmax(xbnd,smlnum);
  871. grow = f2cmin(r__1,r__2);
  872. i__2 = jlast;
  873. i__1 = jinc;
  874. for (j = jfirst; i__1 < 0 ? j >= i__2 : j <= i__2; j += i__1) {
  875. /* Exit the loop if the growth factor is too small. */
  876. if (grow <= smlnum) {
  877. goto L50;
  878. }
  879. /* G(j) = G(j-1)*( 1 + CNORM(j) ) */
  880. grow *= 1.f / (cnorm[j] + 1.f);
  881. /* L40: */
  882. }
  883. }
  884. L50:
  885. ;
  886. } else {
  887. /* Compute the growth in A**T * x = b. */
  888. if (upper) {
  889. jfirst = 1;
  890. jlast = *n;
  891. jinc = 1;
  892. } else {
  893. jfirst = *n;
  894. jlast = 1;
  895. jinc = -1;
  896. }
  897. if (tscal != 1.f) {
  898. grow = 0.f;
  899. goto L80;
  900. }
  901. if (nounit) {
  902. /* A is non-unit triangular. */
  903. /* Compute GROW = 1/G(j) and XBND = 1/M(j). */
  904. /* Initially, M(0) = f2cmax{x(i), i=1,...,n}. */
  905. grow = 1.f / f2cmax(xbnd,smlnum);
  906. xbnd = grow;
  907. i__1 = jlast;
  908. i__2 = jinc;
  909. for (j = jfirst; i__2 < 0 ? j >= i__1 : j <= i__1; j += i__2) {
  910. /* Exit the loop if the growth factor is too small. */
  911. if (grow <= smlnum) {
  912. goto L80;
  913. }
  914. /* G(j) = f2cmax( G(j-1), M(j-1)*( 1 + CNORM(j) ) ) */
  915. xj = cnorm[j] + 1.f;
  916. /* Computing MIN */
  917. r__1 = grow, r__2 = xbnd / xj;
  918. grow = f2cmin(r__1,r__2);
  919. /* M(j) = M(j-1)*( 1 + CNORM(j) ) / abs(A(j,j)) */
  920. tjj = (r__1 = a[j + j * a_dim1], abs(r__1));
  921. if (xj > tjj) {
  922. xbnd *= tjj / xj;
  923. }
  924. /* L60: */
  925. }
  926. grow = f2cmin(grow,xbnd);
  927. } else {
  928. /* A is unit triangular. */
  929. /* Compute GROW = 1/G(j), where G(0) = f2cmax{x(i), i=1,...,n}. */
  930. /* Computing MIN */
  931. r__1 = 1.f, r__2 = 1.f / f2cmax(xbnd,smlnum);
  932. grow = f2cmin(r__1,r__2);
  933. i__2 = jlast;
  934. i__1 = jinc;
  935. for (j = jfirst; i__1 < 0 ? j >= i__2 : j <= i__2; j += i__1) {
  936. /* Exit the loop if the growth factor is too small. */
  937. if (grow <= smlnum) {
  938. goto L80;
  939. }
  940. /* G(j) = ( 1 + CNORM(j) )*G(j-1) */
  941. xj = cnorm[j] + 1.f;
  942. grow /= xj;
  943. /* L70: */
  944. }
  945. }
  946. L80:
  947. ;
  948. }
  949. if (grow * tscal > smlnum) {
  950. /* Use the Level 2 BLAS solve if the reciprocal of the bound on */
  951. /* elements of X is not too small. */
  952. strsv_(uplo, trans, diag, n, &a[a_offset], lda, &x[1], &c__1);
  953. } else {
  954. /* Use a Level 1 BLAS solve, scaling intermediate results. */
  955. if (xmax > bignum) {
  956. /* Scale X so that its components are less than or equal to */
  957. /* BIGNUM in absolute value. */
  958. *scale = bignum / xmax;
  959. sscal_(n, scale, &x[1], &c__1);
  960. xmax = bignum;
  961. }
  962. if (notran) {
  963. /* Solve A * x = b */
  964. i__1 = jlast;
  965. i__2 = jinc;
  966. for (j = jfirst; i__2 < 0 ? j >= i__1 : j <= i__1; j += i__2) {
  967. /* Compute x(j) = b(j) / A(j,j), scaling x if necessary. */
  968. xj = (r__1 = x[j], abs(r__1));
  969. if (nounit) {
  970. tjjs = a[j + j * a_dim1] * tscal;
  971. } else {
  972. tjjs = tscal;
  973. if (tscal == 1.f) {
  974. goto L95;
  975. }
  976. }
  977. tjj = abs(tjjs);
  978. if (tjj > smlnum) {
  979. /* abs(A(j,j)) > SMLNUM: */
  980. if (tjj < 1.f) {
  981. if (xj > tjj * bignum) {
  982. /* Scale x by 1/b(j). */
  983. rec = 1.f / xj;
  984. sscal_(n, &rec, &x[1], &c__1);
  985. *scale *= rec;
  986. xmax *= rec;
  987. }
  988. }
  989. x[j] /= tjjs;
  990. xj = (r__1 = x[j], abs(r__1));
  991. } else if (tjj > 0.f) {
  992. /* 0 < abs(A(j,j)) <= SMLNUM: */
  993. if (xj > tjj * bignum) {
  994. /* Scale x by (1/abs(x(j)))*abs(A(j,j))*BIGNUM */
  995. /* to avoid overflow when dividing by A(j,j). */
  996. rec = tjj * bignum / xj;
  997. if (cnorm[j] > 1.f) {
  998. /* Scale by 1/CNORM(j) to avoid overflow when */
  999. /* multiplying x(j) times column j. */
  1000. rec /= cnorm[j];
  1001. }
  1002. sscal_(n, &rec, &x[1], &c__1);
  1003. *scale *= rec;
  1004. xmax *= rec;
  1005. }
  1006. x[j] /= tjjs;
  1007. xj = (r__1 = x[j], abs(r__1));
  1008. } else {
  1009. /* A(j,j) = 0: Set x(1:n) = 0, x(j) = 1, and */
  1010. /* scale = 0, and compute a solution to A*x = 0. */
  1011. i__3 = *n;
  1012. for (i__ = 1; i__ <= i__3; ++i__) {
  1013. x[i__] = 0.f;
  1014. /* L90: */
  1015. }
  1016. x[j] = 1.f;
  1017. xj = 1.f;
  1018. *scale = 0.f;
  1019. xmax = 0.f;
  1020. }
  1021. L95:
  1022. /* Scale x if necessary to avoid overflow when adding a */
  1023. /* multiple of column j of A. */
  1024. if (xj > 1.f) {
  1025. rec = 1.f / xj;
  1026. if (cnorm[j] > (bignum - xmax) * rec) {
  1027. /* Scale x by 1/(2*abs(x(j))). */
  1028. rec *= .5f;
  1029. sscal_(n, &rec, &x[1], &c__1);
  1030. *scale *= rec;
  1031. }
  1032. } else if (xj * cnorm[j] > bignum - xmax) {
  1033. /* Scale x by 1/2. */
  1034. sscal_(n, &c_b36, &x[1], &c__1);
  1035. *scale *= .5f;
  1036. }
  1037. if (upper) {
  1038. if (j > 1) {
  1039. /* Compute the update */
  1040. /* x(1:j-1) := x(1:j-1) - x(j) * A(1:j-1,j) */
  1041. i__3 = j - 1;
  1042. r__1 = -x[j] * tscal;
  1043. saxpy_(&i__3, &r__1, &a[j * a_dim1 + 1], &c__1, &x[1],
  1044. &c__1);
  1045. i__3 = j - 1;
  1046. i__ = isamax_(&i__3, &x[1], &c__1);
  1047. xmax = (r__1 = x[i__], abs(r__1));
  1048. }
  1049. } else {
  1050. if (j < *n) {
  1051. /* Compute the update */
  1052. /* x(j+1:n) := x(j+1:n) - x(j) * A(j+1:n,j) */
  1053. i__3 = *n - j;
  1054. r__1 = -x[j] * tscal;
  1055. saxpy_(&i__3, &r__1, &a[j + 1 + j * a_dim1], &c__1, &
  1056. x[j + 1], &c__1);
  1057. i__3 = *n - j;
  1058. i__ = j + isamax_(&i__3, &x[j + 1], &c__1);
  1059. xmax = (r__1 = x[i__], abs(r__1));
  1060. }
  1061. }
  1062. /* L100: */
  1063. }
  1064. } else {
  1065. /* Solve A**T * x = b */
  1066. i__2 = jlast;
  1067. i__1 = jinc;
  1068. for (j = jfirst; i__1 < 0 ? j >= i__2 : j <= i__2; j += i__1) {
  1069. /* Compute x(j) = b(j) - sum A(k,j)*x(k). */
  1070. /* k<>j */
  1071. xj = (r__1 = x[j], abs(r__1));
  1072. uscal = tscal;
  1073. rec = 1.f / f2cmax(xmax,1.f);
  1074. if (cnorm[j] > (bignum - xj) * rec) {
  1075. /* If x(j) could overflow, scale x by 1/(2*XMAX). */
  1076. rec *= .5f;
  1077. if (nounit) {
  1078. tjjs = a[j + j * a_dim1] * tscal;
  1079. } else {
  1080. tjjs = tscal;
  1081. }
  1082. tjj = abs(tjjs);
  1083. if (tjj > 1.f) {
  1084. /* Divide by A(j,j) when scaling x if A(j,j) > 1. */
  1085. /* Computing MIN */
  1086. r__1 = 1.f, r__2 = rec * tjj;
  1087. rec = f2cmin(r__1,r__2);
  1088. uscal /= tjjs;
  1089. }
  1090. if (rec < 1.f) {
  1091. sscal_(n, &rec, &x[1], &c__1);
  1092. *scale *= rec;
  1093. xmax *= rec;
  1094. }
  1095. }
  1096. sumj = 0.f;
  1097. if (uscal == 1.f) {
  1098. /* If the scaling needed for A in the dot product is 1, */
  1099. /* call SDOT to perform the dot product. */
  1100. if (upper) {
  1101. i__3 = j - 1;
  1102. sumj = sdot_(&i__3, &a[j * a_dim1 + 1], &c__1, &x[1],
  1103. &c__1);
  1104. } else if (j < *n) {
  1105. i__3 = *n - j;
  1106. sumj = sdot_(&i__3, &a[j + 1 + j * a_dim1], &c__1, &x[
  1107. j + 1], &c__1);
  1108. }
  1109. } else {
  1110. /* Otherwise, use in-line code for the dot product. */
  1111. if (upper) {
  1112. i__3 = j - 1;
  1113. for (i__ = 1; i__ <= i__3; ++i__) {
  1114. sumj += a[i__ + j * a_dim1] * uscal * x[i__];
  1115. /* L110: */
  1116. }
  1117. } else if (j < *n) {
  1118. i__3 = *n;
  1119. for (i__ = j + 1; i__ <= i__3; ++i__) {
  1120. sumj += a[i__ + j * a_dim1] * uscal * x[i__];
  1121. /* L120: */
  1122. }
  1123. }
  1124. }
  1125. if (uscal == tscal) {
  1126. /* Compute x(j) := ( x(j) - sumj ) / A(j,j) if 1/A(j,j) */
  1127. /* was not used to scale the dotproduct. */
  1128. x[j] -= sumj;
  1129. xj = (r__1 = x[j], abs(r__1));
  1130. if (nounit) {
  1131. tjjs = a[j + j * a_dim1] * tscal;
  1132. } else {
  1133. tjjs = tscal;
  1134. if (tscal == 1.f) {
  1135. goto L135;
  1136. }
  1137. }
  1138. /* Compute x(j) = x(j) / A(j,j), scaling if necessary. */
  1139. tjj = abs(tjjs);
  1140. if (tjj > smlnum) {
  1141. /* abs(A(j,j)) > SMLNUM: */
  1142. if (tjj < 1.f) {
  1143. if (xj > tjj * bignum) {
  1144. /* Scale X by 1/abs(x(j)). */
  1145. rec = 1.f / xj;
  1146. sscal_(n, &rec, &x[1], &c__1);
  1147. *scale *= rec;
  1148. xmax *= rec;
  1149. }
  1150. }
  1151. x[j] /= tjjs;
  1152. } else if (tjj > 0.f) {
  1153. /* 0 < abs(A(j,j)) <= SMLNUM: */
  1154. if (xj > tjj * bignum) {
  1155. /* Scale x by (1/abs(x(j)))*abs(A(j,j))*BIGNUM. */
  1156. rec = tjj * bignum / xj;
  1157. sscal_(n, &rec, &x[1], &c__1);
  1158. *scale *= rec;
  1159. xmax *= rec;
  1160. }
  1161. x[j] /= tjjs;
  1162. } else {
  1163. /* A(j,j) = 0: Set x(1:n) = 0, x(j) = 1, and */
  1164. /* scale = 0, and compute a solution to A**T*x = 0. */
  1165. i__3 = *n;
  1166. for (i__ = 1; i__ <= i__3; ++i__) {
  1167. x[i__] = 0.f;
  1168. /* L130: */
  1169. }
  1170. x[j] = 1.f;
  1171. *scale = 0.f;
  1172. xmax = 0.f;
  1173. }
  1174. L135:
  1175. ;
  1176. } else {
  1177. /* Compute x(j) := x(j) / A(j,j) - sumj if the dot */
  1178. /* product has already been divided by 1/A(j,j). */
  1179. x[j] = x[j] / tjjs - sumj;
  1180. }
  1181. /* Computing MAX */
  1182. r__2 = xmax, r__3 = (r__1 = x[j], abs(r__1));
  1183. xmax = f2cmax(r__2,r__3);
  1184. /* L140: */
  1185. }
  1186. }
  1187. *scale /= tscal;
  1188. }
  1189. /* Scale the column norms by 1/TSCAL for return. */
  1190. if (tscal != 1.f) {
  1191. r__1 = 1.f / tscal;
  1192. sscal_(n, &r__1, &cnorm[1], &c__1);
  1193. }
  1194. return;
  1195. /* End of SLATRS */
  1196. } /* slatrs_ */