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.

clatrs3.c 40 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282
  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 int logical;
  52. typedef short int shortlogical;
  53. typedef char logical1;
  54. typedef char integer1;
  55. #define TRUE_ (1)
  56. #define FALSE_ (0)
  57. /* Extern is for use with -E */
  58. #ifndef Extern
  59. #define Extern extern
  60. #endif
  61. /* I/O stuff */
  62. typedef int flag;
  63. typedef int ftnlen;
  64. typedef int ftnint;
  65. /*external read, write*/
  66. typedef struct
  67. { flag cierr;
  68. ftnint ciunit;
  69. flag ciend;
  70. char *cifmt;
  71. ftnint cirec;
  72. } cilist;
  73. /*internal read, write*/
  74. typedef struct
  75. { flag icierr;
  76. char *iciunit;
  77. flag iciend;
  78. char *icifmt;
  79. ftnint icirlen;
  80. ftnint icirnum;
  81. } icilist;
  82. /*open*/
  83. typedef struct
  84. { flag oerr;
  85. ftnint ounit;
  86. char *ofnm;
  87. ftnlen ofnmlen;
  88. char *osta;
  89. char *oacc;
  90. char *ofm;
  91. ftnint orl;
  92. char *oblnk;
  93. } olist;
  94. /*close*/
  95. typedef struct
  96. { flag cerr;
  97. ftnint cunit;
  98. char *csta;
  99. } cllist;
  100. /*rewind, backspace, endfile*/
  101. typedef struct
  102. { flag aerr;
  103. ftnint aunit;
  104. } alist;
  105. /* inquire */
  106. typedef struct
  107. { flag inerr;
  108. ftnint inunit;
  109. char *infile;
  110. ftnlen infilen;
  111. ftnint *inex; /*parameters in standard's order*/
  112. ftnint *inopen;
  113. ftnint *innum;
  114. ftnint *innamed;
  115. char *inname;
  116. ftnlen innamlen;
  117. char *inacc;
  118. ftnlen inacclen;
  119. char *inseq;
  120. ftnlen inseqlen;
  121. char *indir;
  122. ftnlen indirlen;
  123. char *infmt;
  124. ftnlen infmtlen;
  125. char *inform;
  126. ftnint informlen;
  127. char *inunf;
  128. ftnlen inunflen;
  129. ftnint *inrecl;
  130. ftnint *innrec;
  131. char *inblank;
  132. ftnlen inblanklen;
  133. } inlist;
  134. #define VOID void
  135. union Multitype { /* for multiple entry points */
  136. integer1 g;
  137. shortint h;
  138. integer i;
  139. /* longint j; */
  140. real r;
  141. doublereal d;
  142. complex c;
  143. doublecomplex z;
  144. };
  145. typedef union Multitype Multitype;
  146. struct Vardesc { /* for Namelist */
  147. char *name;
  148. char *addr;
  149. ftnlen *dims;
  150. int type;
  151. };
  152. typedef struct Vardesc Vardesc;
  153. struct Namelist {
  154. char *name;
  155. Vardesc **vars;
  156. int nvars;
  157. };
  158. typedef struct Namelist Namelist;
  159. #define abs(x) ((x) >= 0 ? (x) : -(x))
  160. #define dabs(x) (fabs(x))
  161. #define f2cmin(a,b) ((a) <= (b) ? (a) : (b))
  162. #define f2cmax(a,b) ((a) >= (b) ? (a) : (b))
  163. #define dmin(a,b) (f2cmin(a,b))
  164. #define dmax(a,b) (f2cmax(a,b))
  165. #define bit_test(a,b) ((a) >> (b) & 1)
  166. #define bit_clear(a,b) ((a) & ~((uinteger)1 << (b)))
  167. #define bit_set(a,b) ((a) | ((uinteger)1 << (b)))
  168. #define abort_() { sig_die("Fortran abort routine called", 1); }
  169. #define c_abs(z) (cabsf(Cf(z)))
  170. #define c_cos(R,Z) { pCf(R)=ccos(Cf(Z)); }
  171. #ifdef _MSC_VER
  172. #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]);}
  173. #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]);}
  174. #else
  175. #define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);}
  176. #define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);}
  177. #endif
  178. #define c_exp(R, Z) {pCf(R) = cexpf(Cf(Z));}
  179. #define c_log(R, Z) {pCf(R) = clogf(Cf(Z));}
  180. #define c_sin(R, Z) {pCf(R) = csinf(Cf(Z));}
  181. //#define c_sqrt(R, Z) {*(R) = csqrtf(Cf(Z));}
  182. #define c_sqrt(R, Z) {pCf(R) = csqrtf(Cf(Z));}
  183. #define d_abs(x) (fabs(*(x)))
  184. #define d_acos(x) (acos(*(x)))
  185. #define d_asin(x) (asin(*(x)))
  186. #define d_atan(x) (atan(*(x)))
  187. #define d_atn2(x, y) (atan2(*(x),*(y)))
  188. #define d_cnjg(R, Z) { pCd(R) = conj(Cd(Z)); }
  189. #define r_cnjg(R, Z) { pCf(R) = conjf(Cf(Z)); }
  190. #define d_cos(x) (cos(*(x)))
  191. #define d_cosh(x) (cosh(*(x)))
  192. #define d_dim(__a, __b) ( *(__a) > *(__b) ? *(__a) - *(__b) : 0.0 )
  193. #define d_exp(x) (exp(*(x)))
  194. #define d_imag(z) (cimag(Cd(z)))
  195. #define r_imag(z) (cimagf(Cf(z)))
  196. #define d_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  197. #define r_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  198. #define d_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  199. #define r_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  200. #define d_log(x) (log(*(x)))
  201. #define d_mod(x, y) (fmod(*(x), *(y)))
  202. #define u_nint(__x) ((__x)>=0 ? floor((__x) + .5) : -floor(.5 - (__x)))
  203. #define d_nint(x) u_nint(*(x))
  204. #define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a)))
  205. #define d_sign(a,b) u_sign(*(a),*(b))
  206. #define r_sign(a,b) u_sign(*(a),*(b))
  207. #define d_sin(x) (sin(*(x)))
  208. #define d_sinh(x) (sinh(*(x)))
  209. #define d_sqrt(x) (sqrt(*(x)))
  210. #define d_tan(x) (tan(*(x)))
  211. #define d_tanh(x) (tanh(*(x)))
  212. #define i_abs(x) abs(*(x))
  213. #define i_dnnt(x) ((integer)u_nint(*(x)))
  214. #define i_len(s, n) (n)
  215. #define i_nint(x) ((integer)u_nint(*(x)))
  216. #define i_sign(a,b) ((integer)u_sign((integer)*(a),(integer)*(b)))
  217. #define pow_dd(ap, bp) ( pow(*(ap), *(bp)))
  218. #define pow_si(B,E) spow_ui(*(B),*(E))
  219. #define pow_ri(B,E) spow_ui(*(B),*(E))
  220. #define pow_di(B,E) dpow_ui(*(B),*(E))
  221. #define pow_zi(p, a, b) {pCd(p) = zpow_ui(Cd(a), *(b));}
  222. #define pow_ci(p, a, b) {pCf(p) = cpow_ui(Cf(a), *(b));}
  223. #define pow_zz(R,A,B) {pCd(R) = cpow(Cd(A),*(B));}
  224. #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++ = ' '; }
  225. #define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d))))
  226. #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]; }
  227. #define sig_die(s, kill) { exit(1); }
  228. #define s_stop(s, n) {exit(0);}
  229. static char junk[] = "\n@(#)LIBF77 VERSION 19990503\n";
  230. #define z_abs(z) (cabs(Cd(z)))
  231. #define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));}
  232. #define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));}
  233. #define myexit_() break;
  234. #define mycycle_() continue;
  235. #define myceiling_(w) {ceil(w)}
  236. #define myhuge_(w) {HUGE_VAL}
  237. //#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);}
  238. #define mymaxloc_(w,s,e,n) dmaxloc_(w,*(s),*(e),n)
  239. #define myexp_(w) my_expfunc(w)
  240. static int my_expfunc(float *x) {int e; (void)frexpf(*x,&e); return e;}
  241. /* procedure parameter types for -A and -C++ */
  242. #define F2C_proc_par_types 1
  243. #ifdef __cplusplus
  244. typedef logical (*L_fp)(...);
  245. #else
  246. typedef logical (*L_fp)();
  247. #endif
  248. static float spow_ui(float x, integer n) {
  249. float pow=1.0; unsigned long int u;
  250. if(n != 0) {
  251. if(n < 0) n = -n, x = 1/x;
  252. for(u = n; ; ) {
  253. if(u & 01) pow *= x;
  254. if(u >>= 1) x *= x;
  255. else break;
  256. }
  257. }
  258. return pow;
  259. }
  260. static double dpow_ui(double x, integer n) {
  261. double pow=1.0; unsigned long int u;
  262. if(n != 0) {
  263. if(n < 0) n = -n, x = 1/x;
  264. for(u = n; ; ) {
  265. if(u & 01) pow *= x;
  266. if(u >>= 1) x *= x;
  267. else break;
  268. }
  269. }
  270. return pow;
  271. }
  272. #ifdef _MSC_VER
  273. static _Fcomplex cpow_ui(complex x, integer n) {
  274. complex pow={1.0,0.0}; unsigned long int u;
  275. if(n != 0) {
  276. if(n < 0) n = -n, x.r = 1/x.r, x.i=1/x.i;
  277. for(u = n; ; ) {
  278. if(u & 01) pow.r *= x.r, pow.i *= x.i;
  279. if(u >>= 1) x.r *= x.r, x.i *= x.i;
  280. else break;
  281. }
  282. }
  283. _Fcomplex p={pow.r, pow.i};
  284. return p;
  285. }
  286. #else
  287. static _Complex float cpow_ui(_Complex float x, integer n) {
  288. _Complex float pow=1.0; unsigned long int u;
  289. if(n != 0) {
  290. if(n < 0) n = -n, x = 1/x;
  291. for(u = n; ; ) {
  292. if(u & 01) pow *= x;
  293. if(u >>= 1) x *= x;
  294. else break;
  295. }
  296. }
  297. return pow;
  298. }
  299. #endif
  300. #ifdef _MSC_VER
  301. static _Dcomplex zpow_ui(_Dcomplex x, integer n) {
  302. _Dcomplex pow={1.0,0.0}; unsigned long int u;
  303. if(n != 0) {
  304. if(n < 0) n = -n, x._Val[0] = 1/x._Val[0], x._Val[1] =1/x._Val[1];
  305. for(u = n; ; ) {
  306. if(u & 01) pow._Val[0] *= x._Val[0], pow._Val[1] *= x._Val[1];
  307. if(u >>= 1) x._Val[0] *= x._Val[0], x._Val[1] *= x._Val[1];
  308. else break;
  309. }
  310. }
  311. _Dcomplex p = {pow._Val[0], pow._Val[1]};
  312. return p;
  313. }
  314. #else
  315. static _Complex double zpow_ui(_Complex double x, integer n) {
  316. _Complex double pow=1.0; unsigned long int u;
  317. if(n != 0) {
  318. if(n < 0) n = -n, x = 1/x;
  319. for(u = n; ; ) {
  320. if(u & 01) pow *= x;
  321. if(u >>= 1) x *= x;
  322. else break;
  323. }
  324. }
  325. return pow;
  326. }
  327. #endif
  328. static integer pow_ii(integer x, integer n) {
  329. integer pow; unsigned long int u;
  330. if (n <= 0) {
  331. if (n == 0 || x == 1) pow = 1;
  332. else if (x != -1) pow = x == 0 ? 1/x : 0;
  333. else n = -n;
  334. }
  335. if ((n > 0) || !(n == 0 || x == 1 || x != -1)) {
  336. u = n;
  337. for(pow = 1; ; ) {
  338. if(u & 01) pow *= x;
  339. if(u >>= 1) x *= x;
  340. else break;
  341. }
  342. }
  343. return pow;
  344. }
  345. static integer dmaxloc_(double *w, integer s, integer e, integer *n)
  346. {
  347. double m; integer i, mi;
  348. for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
  349. if (w[i-1]>m) mi=i ,m=w[i-1];
  350. return mi-s+1;
  351. }
  352. static integer smaxloc_(float *w, integer s, integer e, integer *n)
  353. {
  354. float m; integer i, mi;
  355. for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
  356. if (w[i-1]>m) mi=i ,m=w[i-1];
  357. return mi-s+1;
  358. }
  359. static inline void cdotc_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
  360. integer n = *n_, incx = *incx_, incy = *incy_, i;
  361. #ifdef _MSC_VER
  362. _Fcomplex zdotc = {0.0, 0.0};
  363. if (incx == 1 && incy == 1) {
  364. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  365. zdotc._Val[0] += conjf(Cf(&x[i]))._Val[0] * Cf(&y[i])._Val[0];
  366. zdotc._Val[1] += conjf(Cf(&x[i]))._Val[1] * Cf(&y[i])._Val[1];
  367. }
  368. } else {
  369. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  370. zdotc._Val[0] += conjf(Cf(&x[i*incx]))._Val[0] * Cf(&y[i*incy])._Val[0];
  371. zdotc._Val[1] += conjf(Cf(&x[i*incx]))._Val[1] * Cf(&y[i*incy])._Val[1];
  372. }
  373. }
  374. pCf(z) = zdotc;
  375. }
  376. #else
  377. _Complex float zdotc = 0.0;
  378. if (incx == 1 && incy == 1) {
  379. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  380. zdotc += conjf(Cf(&x[i])) * Cf(&y[i]);
  381. }
  382. } else {
  383. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  384. zdotc += conjf(Cf(&x[i*incx])) * Cf(&y[i*incy]);
  385. }
  386. }
  387. pCf(z) = zdotc;
  388. }
  389. #endif
  390. static inline void zdotc_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
  391. integer n = *n_, incx = *incx_, incy = *incy_, i;
  392. #ifdef _MSC_VER
  393. _Dcomplex zdotc = {0.0, 0.0};
  394. if (incx == 1 && incy == 1) {
  395. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  396. zdotc._Val[0] += conj(Cd(&x[i]))._Val[0] * Cd(&y[i])._Val[0];
  397. zdotc._Val[1] += conj(Cd(&x[i]))._Val[1] * Cd(&y[i])._Val[1];
  398. }
  399. } else {
  400. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  401. zdotc._Val[0] += conj(Cd(&x[i*incx]))._Val[0] * Cd(&y[i*incy])._Val[0];
  402. zdotc._Val[1] += conj(Cd(&x[i*incx]))._Val[1] * Cd(&y[i*incy])._Val[1];
  403. }
  404. }
  405. pCd(z) = zdotc;
  406. }
  407. #else
  408. _Complex double zdotc = 0.0;
  409. if (incx == 1 && incy == 1) {
  410. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  411. zdotc += conj(Cd(&x[i])) * Cd(&y[i]);
  412. }
  413. } else {
  414. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  415. zdotc += conj(Cd(&x[i*incx])) * Cd(&y[i*incy]);
  416. }
  417. }
  418. pCd(z) = zdotc;
  419. }
  420. #endif
  421. static inline void cdotu_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
  422. integer n = *n_, incx = *incx_, incy = *incy_, i;
  423. #ifdef _MSC_VER
  424. _Fcomplex zdotc = {0.0, 0.0};
  425. if (incx == 1 && incy == 1) {
  426. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  427. zdotc._Val[0] += Cf(&x[i])._Val[0] * Cf(&y[i])._Val[0];
  428. zdotc._Val[1] += Cf(&x[i])._Val[1] * Cf(&y[i])._Val[1];
  429. }
  430. } else {
  431. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  432. zdotc._Val[0] += Cf(&x[i*incx])._Val[0] * Cf(&y[i*incy])._Val[0];
  433. zdotc._Val[1] += Cf(&x[i*incx])._Val[1] * Cf(&y[i*incy])._Val[1];
  434. }
  435. }
  436. pCf(z) = zdotc;
  437. }
  438. #else
  439. _Complex float zdotc = 0.0;
  440. if (incx == 1 && incy == 1) {
  441. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  442. zdotc += Cf(&x[i]) * Cf(&y[i]);
  443. }
  444. } else {
  445. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  446. zdotc += Cf(&x[i*incx]) * Cf(&y[i*incy]);
  447. }
  448. }
  449. pCf(z) = zdotc;
  450. }
  451. #endif
  452. static inline void zdotu_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
  453. integer n = *n_, incx = *incx_, incy = *incy_, i;
  454. #ifdef _MSC_VER
  455. _Dcomplex zdotc = {0.0, 0.0};
  456. if (incx == 1 && incy == 1) {
  457. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  458. zdotc._Val[0] += Cd(&x[i])._Val[0] * Cd(&y[i])._Val[0];
  459. zdotc._Val[1] += Cd(&x[i])._Val[1] * Cd(&y[i])._Val[1];
  460. }
  461. } else {
  462. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  463. zdotc._Val[0] += Cd(&x[i*incx])._Val[0] * Cd(&y[i*incy])._Val[0];
  464. zdotc._Val[1] += Cd(&x[i*incx])._Val[1] * Cd(&y[i*incy])._Val[1];
  465. }
  466. }
  467. pCd(z) = zdotc;
  468. }
  469. #else
  470. _Complex double zdotc = 0.0;
  471. if (incx == 1 && incy == 1) {
  472. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  473. zdotc += Cd(&x[i]) * Cd(&y[i]);
  474. }
  475. } else {
  476. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  477. zdotc += Cd(&x[i*incx]) * Cd(&y[i*incy]);
  478. }
  479. }
  480. pCd(z) = zdotc;
  481. }
  482. #endif
  483. /* -- translated by f2c (version 20000121).
  484. You must link the resulting object file with the libraries:
  485. -lf2c -lm (in that order)
  486. */
  487. /* Table of constant values */
  488. static complex c_b2 = {1.f,0.f};
  489. static integer c__1 = 1;
  490. static integer c_n1 = -1;
  491. /* > \brief \b CLATRS3 solves a triangular system of equations with the scale factors set to prevent overflow.
  492. */
  493. /* Definition: */
  494. /* =========== */
  495. /* SUBROUTINE CLATRS3( UPLO, TRANS, DIAG, NORMIN, N, NRHS, A, LDA, */
  496. /* X, LDX, SCALE, CNORM, WORK, LWORK, INFO ) */
  497. /* CHARACTER DIAG, NORMIN, TRANS, UPLO */
  498. /* INTEGER INFO, LDA, LWORK, LDX, N, NRHS */
  499. /* REAL CNORM( * ), SCALE( * ), WORK( * ) */
  500. /* COMPLEX A( LDA, * ), X( LDX, * ) */
  501. /* > \par Purpose: */
  502. /* ============= */
  503. /* > */
  504. /* > \verbatim */
  505. /* > */
  506. /* > CLATRS3 solves one of the triangular systems */
  507. /* > */
  508. /* > A * X = B * diag(scale), A**T * X = B * diag(scale), or */
  509. /* > A**H * X = B * diag(scale) */
  510. /* > */
  511. /* > with scaling to prevent overflow. Here A is an upper or lower */
  512. /* > triangular matrix, A**T denotes the transpose of A, A**H denotes the */
  513. /* > conjugate transpose of A. X and B are n-by-nrhs matrices and scale */
  514. /* > is an nrhs-element vector of scaling factors. A scaling factor scale(j) */
  515. /* > is usually less than or equal to 1, chosen such that X(:,j) is less */
  516. /* > than the overflow threshold. If the matrix A is singular (A(j,j) = 0 */
  517. /* > for some j), then a non-trivial solution to A*X = 0 is returned. If */
  518. /* > the system is so badly scaled that the solution cannot be represented */
  519. /* > as (1/scale(k))*X(:,k), then x(:,k) = 0 and scale(k) is returned. */
  520. /* > */
  521. /* > This is a BLAS-3 version of LATRS for solving several right */
  522. /* > hand sides simultaneously. */
  523. /* > */
  524. /* > \endverbatim */
  525. /* Arguments: */
  526. /* ========== */
  527. /* > \param[in] UPLO */
  528. /* > \verbatim */
  529. /* > UPLO is CHARACTER*1 */
  530. /* > Specifies whether the matrix A is upper or lower triangular. */
  531. /* > = 'U': Upper triangular */
  532. /* > = 'L': Lower triangular */
  533. /* > \endverbatim */
  534. /* > */
  535. /* > \param[in] TRANS */
  536. /* > \verbatim */
  537. /* > TRANS is CHARACTER*1 */
  538. /* > Specifies the operation applied to A. */
  539. /* > = 'N': Solve A * x = s*b (No transpose) */
  540. /* > = 'T': Solve A**T* x = s*b (Transpose) */
  541. /* > = 'C': Solve A**T* x = s*b (Conjugate transpose) */
  542. /* > \endverbatim */
  543. /* > */
  544. /* > \param[in] DIAG */
  545. /* > \verbatim */
  546. /* > DIAG is CHARACTER*1 */
  547. /* > Specifies whether or not the matrix A is unit triangular. */
  548. /* > = 'N': Non-unit triangular */
  549. /* > = 'U': Unit triangular */
  550. /* > \endverbatim */
  551. /* > */
  552. /* > \param[in] NORMIN */
  553. /* > \verbatim */
  554. /* > NORMIN is CHARACTER*1 */
  555. /* > Specifies whether CNORM has been set or not. */
  556. /* > = 'Y': CNORM contains the column norms on entry */
  557. /* > = 'N': CNORM is not set on entry. On exit, the norms will */
  558. /* > be computed and stored in CNORM. */
  559. /* > \endverbatim */
  560. /* > */
  561. /* > \param[in] N */
  562. /* > \verbatim */
  563. /* > N is INTEGER */
  564. /* > The order of the matrix A. N >= 0. */
  565. /* > \endverbatim */
  566. /* > */
  567. /* > \param[in] NRHS */
  568. /* > \verbatim */
  569. /* > NRHS is INTEGER */
  570. /* > The number of columns of X. NRHS >= 0. */
  571. /* > \endverbatim */
  572. /* > */
  573. /* > \param[in] A */
  574. /* > \verbatim */
  575. /* > A is COMPLEX array, dimension (LDA,N) */
  576. /* > The triangular matrix A. If UPLO = 'U', the leading n by n */
  577. /* > upper triangular part of the array A contains the upper */
  578. /* > triangular matrix, and the strictly lower triangular part of */
  579. /* > A is not referenced. If UPLO = 'L', the leading n by n lower */
  580. /* > triangular part of the array A contains the lower triangular */
  581. /* > matrix, and the strictly upper triangular part of A is not */
  582. /* > referenced. If DIAG = 'U', the diagonal elements of A are */
  583. /* > also not referenced and are assumed to be 1. */
  584. /* > \endverbatim */
  585. /* > */
  586. /* > \param[in] LDA */
  587. /* > \verbatim */
  588. /* > LDA is INTEGER */
  589. /* > The leading dimension of the array A. LDA >= f2cmax (1,N). */
  590. /* > \endverbatim */
  591. /* > */
  592. /* > \param[in,out] X */
  593. /* > \verbatim */
  594. /* > X is COMPLEX array, dimension (LDX,NRHS) */
  595. /* > On entry, the right hand side B of the triangular system. */
  596. /* > On exit, X is overwritten by the solution matrix X. */
  597. /* > \endverbatim */
  598. /* > */
  599. /* > \param[in] LDX */
  600. /* > \verbatim */
  601. /* > LDX is INTEGER */
  602. /* > The leading dimension of the array X. LDX >= f2cmax (1,N). */
  603. /* > \endverbatim */
  604. /* > */
  605. /* > \param[out] SCALE */
  606. /* > \verbatim */
  607. /* > SCALE is REAL array, dimension (NRHS) */
  608. /* > The scaling factor s(k) is for the triangular system */
  609. /* > A * x(:,k) = s(k)*b(:,k) or A**T* x(:,k) = s(k)*b(:,k). */
  610. /* > If SCALE = 0, the matrix A is singular or badly scaled. */
  611. /* > If A(j,j) = 0 is encountered, a non-trivial vector x(:,k) */
  612. /* > that is an exact or approximate solution to A*x(:,k) = 0 */
  613. /* > is returned. If the system so badly scaled that solution */
  614. /* > cannot be presented as x(:,k) * 1/s(k), then x(:,k) = 0 */
  615. /* > is returned. */
  616. /* > \endverbatim */
  617. /* > */
  618. /* > \param[in,out] CNORM */
  619. /* > \verbatim */
  620. /* > CNORM is REAL array, dimension (N) */
  621. /* > */
  622. /* > If NORMIN = 'Y', CNORM is an input argument and CNORM(j) */
  623. /* > contains the norm of the off-diagonal part of the j-th column */
  624. /* > of A. If TRANS = 'N', CNORM(j) must be greater than or equal */
  625. /* > to the infinity-norm, and if TRANS = 'T' or 'C', CNORM(j) */
  626. /* > must be greater than or equal to the 1-norm. */
  627. /* > */
  628. /* > If NORMIN = 'N', CNORM is an output argument and CNORM(j) */
  629. /* > returns the 1-norm of the offdiagonal part of the j-th column */
  630. /* > of A. */
  631. /* > \endverbatim */
  632. /* > */
  633. /* > \param[out] WORK */
  634. /* > \verbatim */
  635. /* > WORK is REAL array, dimension (LWORK). */
  636. /* > On exit, if INFO = 0, WORK(1) returns the optimal size of */
  637. /* > WORK. */
  638. /* > \endverbatim */
  639. /* > */
  640. /* > \param[in] LWORK */
  641. /* > LWORK is INTEGER */
  642. /* > LWORK >= MAX(1, 2*NBA * MAX(NBA, MIN(NRHS, 32)), where */
  643. /* > NBA = (N + NB - 1)/NB and NB is the optimal block size. */
  644. /* > */
  645. /* > If LWORK = -1, then a workspace query is assumed; the routine */
  646. /* > only calculates the optimal dimensions of the WORK array, returns */
  647. /* > this value as the first entry of the WORK array, and no error */
  648. /* > message related to LWORK is issued by XERBLA. */
  649. /* > */
  650. /* > \param[out] INFO */
  651. /* > \verbatim */
  652. /* > INFO is INTEGER */
  653. /* > = 0: successful exit */
  654. /* > < 0: if INFO = -k, the k-th argument had an illegal value */
  655. /* > \endverbatim */
  656. /* Authors: */
  657. /* ======== */
  658. /* > \author Univ. of Tennessee */
  659. /* > \author Univ. of California Berkeley */
  660. /* > \author Univ. of Colorado Denver */
  661. /* > \author NAG Ltd. */
  662. /* > \ingroup doubleOTHERauxiliary */
  663. /* > \par Further Details: */
  664. /* ===================== */
  665. /* \verbatim */
  666. /* The algorithm follows the structure of a block triangular solve. */
  667. /* The diagonal block is solved with a call to the robust the triangular */
  668. /* solver LATRS for every right-hand side RHS = 1, ..., NRHS */
  669. /* op(A( J, J )) * x( J, RHS ) = SCALOC * b( J, RHS ), */
  670. /* where op( A ) = A or op( A ) = A**T or op( A ) = A**H. */
  671. /* The linear block updates operate on block columns of X, */
  672. /* B( I, K ) - op(A( I, J )) * X( J, K ) */
  673. /* and use GEMM. To avoid overflow in the linear block update, the worst case */
  674. /* growth is estimated. For every RHS, a scale factor s <= 1.0 is computed */
  675. /* such that */
  676. /* || s * B( I, RHS )||_oo */
  677. /* + || op(A( I, J )) ||_oo * || s * X( J, RHS ) ||_oo <= Overflow threshold */
  678. /* Once all columns of a block column have been rescaled (BLAS-1), the linear */
  679. /* update is executed with GEMM without overflow. */
  680. /* To limit rescaling, local scale factors track the scaling of column segments. */
  681. /* There is one local scale factor s( I, RHS ) per block row I = 1, ..., NBA */
  682. /* per right-hand side column RHS = 1, ..., NRHS. The global scale factor */
  683. /* SCALE( RHS ) is chosen as the smallest local scale factor s( I, RHS ) */
  684. /* I = 1, ..., NBA. */
  685. /* A triangular solve op(A( J, J )) * x( J, RHS ) = SCALOC * b( J, RHS ) */
  686. /* updates the local scale factor s( J, RHS ) := s( J, RHS ) * SCALOC. The */
  687. /* linear update of potentially inconsistently scaled vector segments */
  688. /* s( I, RHS ) * b( I, RHS ) - op(A( I, J )) * ( s( J, RHS )* x( J, RHS ) ) */
  689. /* computes a consistent scaling SCAMIN = MIN( s(I, RHS ), s(J, RHS) ) and, */
  690. /* if necessary, rescales the blocks prior to calling GEMM. */
  691. /* \endverbatim */
  692. /* ===================================================================== */
  693. /* References: */
  694. /* C. C. Kjelgaard Mikkelsen, A. B. Schwarz and L. Karlsson (2019). */
  695. /* Parallel robust solution of triangular linear systems. Concurrency */
  696. /* and Computation: Practice and Experience, 31(19), e5064. */
  697. /* Contributor: */
  698. /* Angelika Schwarz, Umea University, Sweden. */
  699. /* ===================================================================== */
  700. /* Subroutine */ int clatrs3_(char *uplo, char *trans, char *diag, char *
  701. normin, integer *n, integer *nrhs, complex *a, integer *lda, complex *
  702. x, integer *ldx, real *scale, real *cnorm, real *work, integer *lwork,
  703. integer *info)
  704. {
  705. /* System generated locals */
  706. integer a_dim1, a_offset, x_dim1, x_offset, i__1, i__2, i__3, i__4, i__5,
  707. i__6, i__7, i__8;
  708. real r__1, r__2;
  709. complex q__1;
  710. /* Local variables */
  711. integer iinc, jinc;
  712. real scal, anrm, bnrm;
  713. integer awrk;
  714. real tmax, xnrm[32];
  715. integer i__, j, k;
  716. real w[64];
  717. extern /* Subroutine */ int cgemm_(char *, char *, integer *, integer *,
  718. integer *, complex *, complex *, integer *, complex *, integer *,
  719. complex *, complex *, integer *);
  720. extern logical lsame_(char *, char *);
  721. real rscal;
  722. integer lanrm, ilast, jlast, i1;
  723. logical upper;
  724. integer i2, j1, j2, k1, k2, nb, ii, kk;
  725. extern real clange_(char *, integer *, integer *, complex *, integer *,
  726. real *);
  727. integer lscale;
  728. real scaloc;
  729. extern real slamch_(char *);
  730. extern /* Subroutine */ int csscal_(integer *, real *, complex *, integer
  731. *);
  732. real scamin;
  733. extern /* Subroutine */ int xerbla_(char *, integer *);
  734. extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
  735. integer *, integer *, ftnlen, ftnlen);
  736. real bignum;
  737. extern /* Subroutine */ int clatrs_(char *, char *, char *, char *,
  738. integer *, complex *, integer *, complex *, real *, real *,
  739. integer *);
  740. extern real slarmm_(real *, real *, real *);
  741. integer ifirst;
  742. logical notran;
  743. integer jfirst;
  744. real smlnum;
  745. logical nounit, lquery;
  746. integer nba, lds, nbx, rhs;
  747. /* ===================================================================== */
  748. /* Parameter adjustments */
  749. a_dim1 = *lda;
  750. a_offset = 1 + a_dim1 * 1;
  751. a -= a_offset;
  752. x_dim1 = *ldx;
  753. x_offset = 1 + x_dim1 * 1;
  754. x -= x_offset;
  755. --scale;
  756. --cnorm;
  757. --work;
  758. /* Function Body */
  759. *info = 0;
  760. upper = lsame_(uplo, "U");
  761. notran = lsame_(trans, "N");
  762. nounit = lsame_(diag, "N");
  763. lquery = *lwork == -1;
  764. /* Partition A and X into blocks. */
  765. /* Computing MAX */
  766. i__1 = 8, i__2 = ilaenv_(&c__1, "CLATRS", "", n, n, &c_n1, &c_n1, (ftnlen)
  767. 6, (ftnlen)0);
  768. nb = f2cmax(i__1,i__2);
  769. nb = f2cmin(64,nb);
  770. /* Computing MAX */
  771. i__1 = 1, i__2 = (*n + nb - 1) / nb;
  772. nba = f2cmax(i__1,i__2);
  773. /* Computing MAX */
  774. i__1 = 1, i__2 = (*nrhs + 31) / 32;
  775. nbx = f2cmax(i__1,i__2);
  776. /* Compute the workspace */
  777. /* The workspace comprises two parts. */
  778. /* The first part stores the local scale factors. Each simultaneously */
  779. /* computed right-hand side requires one local scale factor per block */
  780. /* row. WORK( I + KK * LDS ) is the scale factor of the vector */
  781. /* segment associated with the I-th block row and the KK-th vector */
  782. /* in the block column. */
  783. /* Computing MAX */
  784. i__1 = nba, i__2 = f2cmin(*nrhs,32);
  785. lscale = nba * f2cmax(i__1,i__2);
  786. lds = nba;
  787. /* The second part stores upper bounds of the triangular A. There are */
  788. /* a total of NBA x NBA blocks, of which only the upper triangular */
  789. /* part or the lower triangular part is referenced. The upper bound of */
  790. /* the block A( I, J ) is stored as WORK( AWRK + I + J * NBA ). */
  791. lanrm = nba * nba;
  792. awrk = lscale;
  793. work[1] = (real) (lscale + lanrm);
  794. /* Test the input parameters. */
  795. if (! upper && ! lsame_(uplo, "L")) {
  796. *info = -1;
  797. } else if (! notran && ! lsame_(trans, "T") && !
  798. lsame_(trans, "C")) {
  799. *info = -2;
  800. } else if (! nounit && ! lsame_(diag, "U")) {
  801. *info = -3;
  802. } else if (! lsame_(normin, "Y") && ! lsame_(normin,
  803. "N")) {
  804. *info = -4;
  805. } else if (*n < 0) {
  806. *info = -5;
  807. } else if (*nrhs < 0) {
  808. *info = -6;
  809. } else if (*lda < f2cmax(1,*n)) {
  810. *info = -8;
  811. } else if (*ldx < f2cmax(1,*n)) {
  812. *info = -10;
  813. } else if (! lquery && (real) (*lwork) < work[1]) {
  814. *info = -14;
  815. }
  816. if (*info != 0) {
  817. i__1 = -(*info);
  818. xerbla_("CLATRS3", &i__1);
  819. return 0;
  820. } else if (lquery) {
  821. return 0;
  822. }
  823. /* Initialize scaling factors */
  824. i__1 = *nrhs;
  825. for (kk = 1; kk <= i__1; ++kk) {
  826. scale[kk] = 1.f;
  827. }
  828. /* Quick return if possible */
  829. if (f2cmin(*n,*nrhs) == 0) {
  830. return 0;
  831. }
  832. /* Determine machine dependent constant to control overflow. */
  833. bignum = slamch_("Overflow");
  834. smlnum = slamch_("Safe Minimum");
  835. /* Use unblocked code for small problems */
  836. if (*nrhs < 2) {
  837. clatrs_(uplo, trans, diag, normin, n, &a[a_offset], lda, &x[x_dim1 +
  838. 1], &scale[1], &cnorm[1], info);
  839. i__1 = *nrhs;
  840. for (k = 2; k <= i__1; ++k) {
  841. clatrs_(uplo, trans, diag, "Y", n, &a[a_offset], lda, &x[k *
  842. x_dim1 + 1], &scale[k], &cnorm[1], info);
  843. }
  844. return 0;
  845. }
  846. /* Compute norms of blocks of A excluding diagonal blocks and find */
  847. /* the block with the largest norm TMAX. */
  848. tmax = 0.f;
  849. i__1 = nba;
  850. for (j = 1; j <= i__1; ++j) {
  851. j1 = (j - 1) * nb + 1;
  852. /* Computing MIN */
  853. i__2 = j * nb;
  854. j2 = f2cmin(i__2,*n) + 1;
  855. if (upper) {
  856. ifirst = 1;
  857. ilast = j - 1;
  858. } else {
  859. ifirst = j + 1;
  860. ilast = nba;
  861. }
  862. i__2 = ilast;
  863. for (i__ = ifirst; i__ <= i__2; ++i__) {
  864. i1 = (i__ - 1) * nb + 1;
  865. /* Computing MIN */
  866. i__3 = i__ * nb;
  867. i2 = f2cmin(i__3,*n) + 1;
  868. /* Compute upper bound of A( I1:I2-1, J1:J2-1 ). */
  869. if (notran) {
  870. i__3 = i2 - i1;
  871. i__4 = j2 - j1;
  872. anrm = clange_("I", &i__3, &i__4, &a[i1 + j1 * a_dim1], lda,
  873. w);
  874. work[awrk + i__ + (j - 1) * nba] = anrm;
  875. } else {
  876. i__3 = i2 - i1;
  877. i__4 = j2 - j1;
  878. anrm = clange_("1", &i__3, &i__4, &a[i1 + j1 * a_dim1], lda,
  879. w);
  880. work[awrk + j + (i__ - 1) * nba] = anrm;
  881. }
  882. tmax = f2cmax(tmax,anrm);
  883. }
  884. }
  885. if (! (tmax <= slamch_("Overflow"))) {
  886. /* Some matrix entries have huge absolute value. At least one upper */
  887. /* bound norm( A(I1:I2-1, J1:J2-1), 'I') is not a valid floating-point */
  888. /* number, either due to overflow in LANGE or due to Inf in A. */
  889. /* Fall back to LATRS. Set normin = 'N' for every right-hand side to */
  890. /* force computation of TSCAL in LATRS to avoid the likely overflow */
  891. /* in the computation of the column norms CNORM. */
  892. i__1 = *nrhs;
  893. for (k = 1; k <= i__1; ++k) {
  894. clatrs_(uplo, trans, diag, "N", n, &a[a_offset], lda, &x[k *
  895. x_dim1 + 1], &scale[k], &cnorm[1], info);
  896. }
  897. return 0;
  898. }
  899. /* Every right-hand side requires workspace to store NBA local scale */
  900. /* factors. To save workspace, X is computed successively in block columns */
  901. /* of width NBRHS, requiring a total of NBA x NBRHS space. If sufficient */
  902. /* workspace is available, larger values of NBRHS or NBRHS = NRHS are viable. */
  903. i__1 = nbx;
  904. for (k = 1; k <= i__1; ++k) {
  905. /* Loop over block columns (index = K) of X and, for column-wise scalings, */
  906. /* over individual columns (index = KK). */
  907. /* K1: column index of the first column in X( J, K ) */
  908. /* K2: column index of the first column in X( J, K+1 ) */
  909. /* so the K2 - K1 is the column count of the block X( J, K ) */
  910. k1 = (k - 1 << 5) + 1;
  911. /* Computing MIN */
  912. i__2 = k << 5;
  913. k2 = f2cmin(i__2,*nrhs) + 1;
  914. /* Initialize local scaling factors of current block column X( J, K ) */
  915. i__2 = k2 - k1;
  916. for (kk = 1; kk <= i__2; ++kk) {
  917. i__3 = nba;
  918. for (i__ = 1; i__ <= i__3; ++i__) {
  919. work[i__ + kk * lds] = 1.f;
  920. }
  921. }
  922. if (notran) {
  923. /* Solve A * X(:, K1:K2-1) = B * diag(scale(K1:K2-1)) */
  924. if (upper) {
  925. jfirst = nba;
  926. jlast = 1;
  927. jinc = -1;
  928. } else {
  929. jfirst = 1;
  930. jlast = nba;
  931. jinc = 1;
  932. }
  933. } else {
  934. /* Solve op(A) * X(:, K1:K2-1) = B * diag(scale(K1:K2-1)) */
  935. /* where op(A) = A**T or op(A) = A**H */
  936. if (upper) {
  937. jfirst = 1;
  938. jlast = nba;
  939. jinc = 1;
  940. } else {
  941. jfirst = nba;
  942. jlast = 1;
  943. jinc = -1;
  944. }
  945. }
  946. i__2 = jlast;
  947. i__3 = jinc;
  948. for (j = jfirst; i__3 < 0 ? j >= i__2 : j <= i__2; j += i__3) {
  949. /* J1: row index of the first row in A( J, J ) */
  950. /* J2: row index of the first row in A( J+1, J+1 ) */
  951. /* so that J2 - J1 is the row count of the block A( J, J ) */
  952. j1 = (j - 1) * nb + 1;
  953. /* Computing MIN */
  954. i__4 = j * nb;
  955. j2 = f2cmin(i__4,*n) + 1;
  956. /* Solve op(A( J, J )) * X( J, RHS ) = SCALOC * B( J, RHS ) */
  957. i__4 = k2 - k1;
  958. for (kk = 1; kk <= i__4; ++kk) {
  959. rhs = k1 + kk - 1;
  960. if (kk == 1) {
  961. i__5 = j2 - j1;
  962. clatrs_(uplo, trans, diag, "N", &i__5, &a[j1 + j1 *
  963. a_dim1], lda, &x[j1 + rhs * x_dim1], &scaloc, &
  964. cnorm[1], info);
  965. } else {
  966. i__5 = j2 - j1;
  967. clatrs_(uplo, trans, diag, "Y", &i__5, &a[j1 + j1 *
  968. a_dim1], lda, &x[j1 + rhs * x_dim1], &scaloc, &
  969. cnorm[1], info);
  970. }
  971. /* Find largest absolute value entry in the vector segment */
  972. /* X( J1:J2-1, RHS ) as an upper bound for the worst case */
  973. /* growth in the linear updates. */
  974. i__5 = j2 - j1;
  975. xnrm[kk - 1] = clange_("I", &i__5, &c__1, &x[j1 + rhs *
  976. x_dim1], ldx, w);
  977. if (scaloc == 0.f) {
  978. /* LATRS found that A is singular through A(j,j) = 0. */
  979. /* Reset the computation x(1:n) = 0, x(j) = 1, SCALE = 0 */
  980. /* and compute op(A)*x = 0. Note that X(J1:J2-1, KK) is */
  981. /* set by LATRS. */
  982. scale[rhs] = 0.f;
  983. i__5 = j1 - 1;
  984. for (ii = 1; ii <= i__5; ++ii) {
  985. i__6 = ii + kk * x_dim1;
  986. x[i__6].r = 0.f, x[i__6].i = 0.f;
  987. }
  988. i__5 = *n;
  989. for (ii = j2; ii <= i__5; ++ii) {
  990. i__6 = ii + kk * x_dim1;
  991. x[i__6].r = 0.f, x[i__6].i = 0.f;
  992. }
  993. /* Discard the local scale factors. */
  994. i__5 = nba;
  995. for (ii = 1; ii <= i__5; ++ii) {
  996. work[ii + kk * lds] = 1.f;
  997. }
  998. scaloc = 1.f;
  999. } else if (scaloc * work[j + kk * lds] == 0.f) {
  1000. /* LATRS computed a valid scale factor, but combined with */
  1001. /* the current scaling the solution does not have a */
  1002. /* scale factor > 0. */
  1003. /* Set WORK( J+KK*LDS ) to smallest valid scale */
  1004. /* factor and increase SCALOC accordingly. */
  1005. scal = work[j + kk * lds] / smlnum;
  1006. scaloc *= scal;
  1007. work[j + kk * lds] = smlnum;
  1008. /* If LATRS overestimated the growth, x may be */
  1009. /* rescaled to preserve a valid combined scale */
  1010. /* factor WORK( J, KK ) > 0. */
  1011. rscal = 1.f / scaloc;
  1012. if (xnrm[kk - 1] * rscal <= bignum) {
  1013. xnrm[kk - 1] *= rscal;
  1014. i__5 = j2 - j1;
  1015. csscal_(&i__5, &rscal, &x[j1 + rhs * x_dim1], &c__1);
  1016. scaloc = 1.f;
  1017. } else {
  1018. /* The system op(A) * x = b is badly scaled and its */
  1019. /* solution cannot be represented as (1/scale) * x. */
  1020. /* Set x to zero. This approach deviates from LATRS */
  1021. /* where a completely meaningless non-zero vector */
  1022. /* is returned that is not a solution to op(A) * x = b. */
  1023. scale[rhs] = 0.f;
  1024. i__5 = *n;
  1025. for (ii = 1; ii <= i__5; ++ii) {
  1026. i__6 = ii + kk * x_dim1;
  1027. x[i__6].r = 0.f, x[i__6].i = 0.f;
  1028. }
  1029. /* Discard the local scale factors. */
  1030. i__5 = nba;
  1031. for (ii = 1; ii <= i__5; ++ii) {
  1032. work[ii + kk * lds] = 1.f;
  1033. }
  1034. scaloc = 1.f;
  1035. }
  1036. }
  1037. scaloc *= work[j + kk * lds];
  1038. work[j + kk * lds] = scaloc;
  1039. }
  1040. /* Linear block updates */
  1041. if (notran) {
  1042. if (upper) {
  1043. ifirst = j - 1;
  1044. ilast = 1;
  1045. iinc = -1;
  1046. } else {
  1047. ifirst = j + 1;
  1048. ilast = nba;
  1049. iinc = 1;
  1050. }
  1051. } else {
  1052. if (upper) {
  1053. ifirst = j + 1;
  1054. ilast = nba;
  1055. iinc = 1;
  1056. } else {
  1057. ifirst = j - 1;
  1058. ilast = 1;
  1059. iinc = -1;
  1060. }
  1061. }
  1062. i__4 = ilast;
  1063. i__5 = iinc;
  1064. for (i__ = ifirst; i__5 < 0 ? i__ >= i__4 : i__ <= i__4; i__ +=
  1065. i__5) {
  1066. /* I1: row index of the first column in X( I, K ) */
  1067. /* I2: row index of the first column in X( I+1, K ) */
  1068. /* so the I2 - I1 is the row count of the block X( I, K ) */
  1069. i1 = (i__ - 1) * nb + 1;
  1070. /* Computing MIN */
  1071. i__6 = i__ * nb;
  1072. i2 = f2cmin(i__6,*n) + 1;
  1073. /* Prepare the linear update to be executed with GEMM. */
  1074. /* For each column, compute a consistent scaling, a */
  1075. /* scaling factor to survive the linear update, and */
  1076. /* rescale the column segments, if necesssary. Then */
  1077. /* the linear update is safely executed. */
  1078. i__6 = k2 - k1;
  1079. for (kk = 1; kk <= i__6; ++kk) {
  1080. rhs = k1 + kk - 1;
  1081. /* Compute consistent scaling */
  1082. /* Computing MIN */
  1083. r__1 = work[i__ + kk * lds], r__2 = work[j + kk * lds];
  1084. scamin = f2cmin(r__1,r__2);
  1085. /* Compute scaling factor to survive the linear update */
  1086. /* simulating consistent scaling. */
  1087. i__7 = i2 - i1;
  1088. bnrm = clange_("I", &i__7, &c__1, &x[i1 + rhs * x_dim1],
  1089. ldx, w);
  1090. bnrm *= scamin / work[i__ + kk * lds];
  1091. xnrm[kk - 1] *= scamin / work[j + kk * lds];
  1092. anrm = work[awrk + i__ + (j - 1) * nba];
  1093. scaloc = slarmm_(&anrm, &xnrm[kk - 1], &bnrm);
  1094. /* Simultaneously apply the robust update factor and the */
  1095. /* consistency scaling factor to X( I, KK ) and X( J, KK ). */
  1096. scal = scamin / work[i__ + kk * lds] * scaloc;
  1097. if (scal != 1.f) {
  1098. i__7 = i2 - i1;
  1099. csscal_(&i__7, &scal, &x[i1 + rhs * x_dim1], &c__1);
  1100. work[i__ + kk * lds] = scamin * scaloc;
  1101. }
  1102. scal = scamin / work[j + kk * lds] * scaloc;
  1103. if (scal != 1.f) {
  1104. i__7 = j2 - j1;
  1105. csscal_(&i__7, &scal, &x[j1 + rhs * x_dim1], &c__1);
  1106. work[j + kk * lds] = scamin * scaloc;
  1107. }
  1108. }
  1109. if (notran) {
  1110. /* B( I, K ) := B( I, K ) - A( I, J ) * X( J, K ) */
  1111. i__6 = i2 - i1;
  1112. i__7 = k2 - k1;
  1113. i__8 = j2 - j1;
  1114. q__1.r = -1.f, q__1.i = 0.f;
  1115. cgemm_("N", "N", &i__6, &i__7, &i__8, &q__1, &a[i1 + j1 *
  1116. a_dim1], lda, &x[j1 + k1 * x_dim1], ldx, &c_b2, &
  1117. x[i1 + k1 * x_dim1], ldx);
  1118. } else if (lsame_(trans, "T")) {
  1119. /* B( I, K ) := B( I, K ) - A( I, J )**T * X( J, K ) */
  1120. i__6 = i2 - i1;
  1121. i__7 = k2 - k1;
  1122. i__8 = j2 - j1;
  1123. q__1.r = -1.f, q__1.i = 0.f;
  1124. cgemm_("T", "N", &i__6, &i__7, &i__8, &q__1, &a[j1 + i1 *
  1125. a_dim1], lda, &x[j1 + k1 * x_dim1], ldx, &c_b2, &
  1126. x[i1 + k1 * x_dim1], ldx);
  1127. } else {
  1128. /* B( I, K ) := B( I, K ) - A( I, J )**H * X( J, K ) */
  1129. i__6 = i2 - i1;
  1130. i__7 = k2 - k1;
  1131. i__8 = j2 - j1;
  1132. q__1.r = -1.f, q__1.i = 0.f;
  1133. cgemm_("C", "N", &i__6, &i__7, &i__8, &q__1, &a[j1 + i1 *
  1134. a_dim1], lda, &x[j1 + k1 * x_dim1], ldx, &c_b2, &
  1135. x[i1 + k1 * x_dim1], ldx);
  1136. }
  1137. }
  1138. }
  1139. /* Reduce local scaling factors */
  1140. i__3 = k2 - k1;
  1141. for (kk = 1; kk <= i__3; ++kk) {
  1142. rhs = k1 + kk - 1;
  1143. i__2 = nba;
  1144. for (i__ = 1; i__ <= i__2; ++i__) {
  1145. /* Computing MIN */
  1146. r__1 = scale[rhs], r__2 = work[i__ + kk * lds];
  1147. scale[rhs] = f2cmin(r__1,r__2);
  1148. }
  1149. }
  1150. /* Realize consistent scaling */
  1151. i__3 = k2 - k1;
  1152. for (kk = 1; kk <= i__3; ++kk) {
  1153. rhs = k1 + kk - 1;
  1154. if (scale[rhs] != 1.f && scale[rhs] != 0.f) {
  1155. i__2 = nba;
  1156. for (i__ = 1; i__ <= i__2; ++i__) {
  1157. i1 = (i__ - 1) * nb + 1;
  1158. /* Computing MIN */
  1159. i__5 = i__ * nb;
  1160. i2 = f2cmin(i__5,*n) + 1;
  1161. scal = scale[rhs] / work[i__ + kk * lds];
  1162. if (scal != 1.f) {
  1163. i__5 = i2 - i1;
  1164. csscal_(&i__5, &scal, &x[i1 + rhs * x_dim1], &c__1);
  1165. }
  1166. }
  1167. }
  1168. }
  1169. }
  1170. return 0;
  1171. /* End of CLATRS3 */
  1172. } /* clatrs3_ */