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.

cla_porfsx_extended.c 40 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230
  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]/df(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. /* procedure parameter types for -A and -C++ */
  240. #define F2C_proc_par_types 1
  241. #ifdef __cplusplus
  242. typedef logical (*L_fp)(...);
  243. #else
  244. typedef logical (*L_fp)();
  245. #endif
  246. static float spow_ui(float x, integer n) {
  247. float pow=1.0; unsigned long int u;
  248. if(n != 0) {
  249. if(n < 0) n = -n, x = 1/x;
  250. for(u = n; ; ) {
  251. if(u & 01) pow *= x;
  252. if(u >>= 1) x *= x;
  253. else break;
  254. }
  255. }
  256. return pow;
  257. }
  258. static double dpow_ui(double x, integer n) {
  259. double pow=1.0; unsigned long int u;
  260. if(n != 0) {
  261. if(n < 0) n = -n, x = 1/x;
  262. for(u = n; ; ) {
  263. if(u & 01) pow *= x;
  264. if(u >>= 1) x *= x;
  265. else break;
  266. }
  267. }
  268. return pow;
  269. }
  270. #ifdef _MSC_VER
  271. static _Fcomplex cpow_ui(complex x, integer n) {
  272. complex pow={1.0,0.0}; unsigned long int u;
  273. if(n != 0) {
  274. if(n < 0) n = -n, x.r = 1/x.r, x.i=1/x.i;
  275. for(u = n; ; ) {
  276. if(u & 01) pow.r *= x.r, pow.i *= x.i;
  277. if(u >>= 1) x.r *= x.r, x.i *= x.i;
  278. else break;
  279. }
  280. }
  281. _Fcomplex p={pow.r, pow.i};
  282. return p;
  283. }
  284. #else
  285. static _Complex float cpow_ui(_Complex float x, integer n) {
  286. _Complex float pow=1.0; unsigned long int u;
  287. if(n != 0) {
  288. if(n < 0) n = -n, x = 1/x;
  289. for(u = n; ; ) {
  290. if(u & 01) pow *= x;
  291. if(u >>= 1) x *= x;
  292. else break;
  293. }
  294. }
  295. return pow;
  296. }
  297. #endif
  298. #ifdef _MSC_VER
  299. static _Dcomplex zpow_ui(_Dcomplex x, integer n) {
  300. _Dcomplex pow={1.0,0.0}; unsigned long int u;
  301. if(n != 0) {
  302. if(n < 0) n = -n, x._Val[0] = 1/x._Val[0], x._Val[1] =1/x._Val[1];
  303. for(u = n; ; ) {
  304. if(u & 01) pow._Val[0] *= x._Val[0], pow._Val[1] *= x._Val[1];
  305. if(u >>= 1) x._Val[0] *= x._Val[0], x._Val[1] *= x._Val[1];
  306. else break;
  307. }
  308. }
  309. _Dcomplex p = {pow._Val[0], pow._Val[1]};
  310. return p;
  311. }
  312. #else
  313. static _Complex double zpow_ui(_Complex double x, integer n) {
  314. _Complex double pow=1.0; unsigned long int u;
  315. if(n != 0) {
  316. if(n < 0) n = -n, x = 1/x;
  317. for(u = n; ; ) {
  318. if(u & 01) pow *= x;
  319. if(u >>= 1) x *= x;
  320. else break;
  321. }
  322. }
  323. return pow;
  324. }
  325. #endif
  326. static integer pow_ii(integer x, integer n) {
  327. integer pow; unsigned long int u;
  328. if (n <= 0) {
  329. if (n == 0 || x == 1) pow = 1;
  330. else if (x != -1) pow = x == 0 ? 1/x : 0;
  331. else n = -n;
  332. }
  333. if ((n > 0) || !(n == 0 || x == 1 || x != -1)) {
  334. u = n;
  335. for(pow = 1; ; ) {
  336. if(u & 01) pow *= x;
  337. if(u >>= 1) x *= x;
  338. else break;
  339. }
  340. }
  341. return pow;
  342. }
  343. static integer dmaxloc_(double *w, integer s, integer e, integer *n)
  344. {
  345. double m; integer i, mi;
  346. for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
  347. if (w[i-1]>m) mi=i ,m=w[i-1];
  348. return mi-s+1;
  349. }
  350. static integer smaxloc_(float *w, integer s, integer e, integer *n)
  351. {
  352. float m; integer i, mi;
  353. for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
  354. if (w[i-1]>m) mi=i ,m=w[i-1];
  355. return mi-s+1;
  356. }
  357. static inline void cdotc_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
  358. integer n = *n_, incx = *incx_, incy = *incy_, i;
  359. #ifdef _MSC_VER
  360. _Fcomplex zdotc = {0.0, 0.0};
  361. if (incx == 1 && incy == 1) {
  362. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  363. zdotc._Val[0] += conjf(Cf(&x[i]))._Val[0] * Cf(&y[i])._Val[0];
  364. zdotc._Val[1] += conjf(Cf(&x[i]))._Val[1] * Cf(&y[i])._Val[1];
  365. }
  366. } else {
  367. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  368. zdotc._Val[0] += conjf(Cf(&x[i*incx]))._Val[0] * Cf(&y[i*incy])._Val[0];
  369. zdotc._Val[1] += conjf(Cf(&x[i*incx]))._Val[1] * Cf(&y[i*incy])._Val[1];
  370. }
  371. }
  372. pCf(z) = zdotc;
  373. }
  374. #else
  375. _Complex float zdotc = 0.0;
  376. if (incx == 1 && incy == 1) {
  377. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  378. zdotc += conjf(Cf(&x[i])) * Cf(&y[i]);
  379. }
  380. } else {
  381. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  382. zdotc += conjf(Cf(&x[i*incx])) * Cf(&y[i*incy]);
  383. }
  384. }
  385. pCf(z) = zdotc;
  386. }
  387. #endif
  388. static inline void zdotc_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
  389. integer n = *n_, incx = *incx_, incy = *incy_, i;
  390. #ifdef _MSC_VER
  391. _Dcomplex zdotc = {0.0, 0.0};
  392. if (incx == 1 && incy == 1) {
  393. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  394. zdotc._Val[0] += conj(Cd(&x[i]))._Val[0] * Cd(&y[i])._Val[0];
  395. zdotc._Val[1] += conj(Cd(&x[i]))._Val[1] * Cd(&y[i])._Val[1];
  396. }
  397. } else {
  398. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  399. zdotc._Val[0] += conj(Cd(&x[i*incx]))._Val[0] * Cd(&y[i*incy])._Val[0];
  400. zdotc._Val[1] += conj(Cd(&x[i*incx]))._Val[1] * Cd(&y[i*incy])._Val[1];
  401. }
  402. }
  403. pCd(z) = zdotc;
  404. }
  405. #else
  406. _Complex double zdotc = 0.0;
  407. if (incx == 1 && incy == 1) {
  408. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  409. zdotc += conj(Cd(&x[i])) * Cd(&y[i]);
  410. }
  411. } else {
  412. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  413. zdotc += conj(Cd(&x[i*incx])) * Cd(&y[i*incy]);
  414. }
  415. }
  416. pCd(z) = zdotc;
  417. }
  418. #endif
  419. static inline void cdotu_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
  420. integer n = *n_, incx = *incx_, incy = *incy_, i;
  421. #ifdef _MSC_VER
  422. _Fcomplex zdotc = {0.0, 0.0};
  423. if (incx == 1 && incy == 1) {
  424. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  425. zdotc._Val[0] += Cf(&x[i])._Val[0] * Cf(&y[i])._Val[0];
  426. zdotc._Val[1] += Cf(&x[i])._Val[1] * Cf(&y[i])._Val[1];
  427. }
  428. } else {
  429. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  430. zdotc._Val[0] += Cf(&x[i*incx])._Val[0] * Cf(&y[i*incy])._Val[0];
  431. zdotc._Val[1] += Cf(&x[i*incx])._Val[1] * Cf(&y[i*incy])._Val[1];
  432. }
  433. }
  434. pCf(z) = zdotc;
  435. }
  436. #else
  437. _Complex float zdotc = 0.0;
  438. if (incx == 1 && incy == 1) {
  439. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  440. zdotc += Cf(&x[i]) * Cf(&y[i]);
  441. }
  442. } else {
  443. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  444. zdotc += Cf(&x[i*incx]) * Cf(&y[i*incy]);
  445. }
  446. }
  447. pCf(z) = zdotc;
  448. }
  449. #endif
  450. static inline void zdotu_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
  451. integer n = *n_, incx = *incx_, incy = *incy_, i;
  452. #ifdef _MSC_VER
  453. _Dcomplex zdotc = {0.0, 0.0};
  454. if (incx == 1 && incy == 1) {
  455. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  456. zdotc._Val[0] += Cd(&x[i])._Val[0] * Cd(&y[i])._Val[0];
  457. zdotc._Val[1] += Cd(&x[i])._Val[1] * Cd(&y[i])._Val[1];
  458. }
  459. } else {
  460. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  461. zdotc._Val[0] += Cd(&x[i*incx])._Val[0] * Cd(&y[i*incy])._Val[0];
  462. zdotc._Val[1] += Cd(&x[i*incx])._Val[1] * Cd(&y[i*incy])._Val[1];
  463. }
  464. }
  465. pCd(z) = zdotc;
  466. }
  467. #else
  468. _Complex double zdotc = 0.0;
  469. if (incx == 1 && incy == 1) {
  470. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  471. zdotc += Cd(&x[i]) * Cd(&y[i]);
  472. }
  473. } else {
  474. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  475. zdotc += Cd(&x[i*incx]) * Cd(&y[i*incy]);
  476. }
  477. }
  478. pCd(z) = zdotc;
  479. }
  480. #endif
  481. /* -- translated by f2c (version 20000121).
  482. You must link the resulting object file with the libraries:
  483. -lf2c -lm (in that order)
  484. */
  485. /* Table of constant values */
  486. static integer c__1 = 1;
  487. static complex c_b11 = {-1.f,0.f};
  488. static complex c_b12 = {1.f,0.f};
  489. static real c_b34 = 1.f;
  490. /* > \brief \b CLA_PORFSX_EXTENDED improves the computed solution to a system of linear equations for symmetri
  491. c or Hermitian positive-definite matrices by performing extra-precise iterative refinement and provide
  492. s error bounds and backward error estimates fo */
  493. /* r the solution. */
  494. /* =========== DOCUMENTATION =========== */
  495. /* Online html documentation available at */
  496. /* http://www.netlib.org/lapack/explore-html/ */
  497. /* > \htmlonly */
  498. /* > Download CLA_PORFSX_EXTENDED + dependencies */
  499. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/cla_por
  500. fsx_extended.f"> */
  501. /* > [TGZ]</a> */
  502. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/cla_por
  503. fsx_extended.f"> */
  504. /* > [ZIP]</a> */
  505. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/cla_por
  506. fsx_extended.f"> */
  507. /* > [TXT]</a> */
  508. /* > \endhtmlonly */
  509. /* Definition: */
  510. /* =========== */
  511. /* SUBROUTINE CLA_PORFSX_EXTENDED( PREC_TYPE, UPLO, N, NRHS, A, LDA, */
  512. /* AF, LDAF, COLEQU, C, B, LDB, Y, */
  513. /* LDY, BERR_OUT, N_NORMS, */
  514. /* ERR_BNDS_NORM, ERR_BNDS_COMP, RES, */
  515. /* AYB, DY, Y_TAIL, RCOND, ITHRESH, */
  516. /* RTHRESH, DZ_UB, IGNORE_CWISE, */
  517. /* INFO ) */
  518. /* INTEGER INFO, LDA, LDAF, LDB, LDY, N, NRHS, PREC_TYPE, */
  519. /* $ N_NORMS, ITHRESH */
  520. /* CHARACTER UPLO */
  521. /* LOGICAL COLEQU, IGNORE_CWISE */
  522. /* REAL RTHRESH, DZ_UB */
  523. /* COMPLEX A( LDA, * ), AF( LDAF, * ), B( LDB, * ), */
  524. /* $ Y( LDY, * ), RES( * ), DY( * ), Y_TAIL( * ) */
  525. /* REAL C( * ), AYB( * ), RCOND, BERR_OUT( * ), */
  526. /* $ ERR_BNDS_NORM( NRHS, * ), */
  527. /* $ ERR_BNDS_COMP( NRHS, * ) */
  528. /* > \par Purpose: */
  529. /* ============= */
  530. /* > */
  531. /* > \verbatim */
  532. /* > */
  533. /* > CLA_PORFSX_EXTENDED improves the computed solution to a system of */
  534. /* > linear equations by performing extra-precise iterative refinement */
  535. /* > and provides error bounds and backward error estimates for the solution. */
  536. /* > This subroutine is called by CPORFSX to perform iterative refinement. */
  537. /* > In addition to normwise error bound, the code provides maximum */
  538. /* > componentwise error bound if possible. See comments for ERR_BNDS_NORM */
  539. /* > and ERR_BNDS_COMP for details of the error bounds. Note that this */
  540. /* > subroutine is only resonsible for setting the second fields of */
  541. /* > ERR_BNDS_NORM and ERR_BNDS_COMP. */
  542. /* > \endverbatim */
  543. /* Arguments: */
  544. /* ========== */
  545. /* > \param[in] PREC_TYPE */
  546. /* > \verbatim */
  547. /* > PREC_TYPE is INTEGER */
  548. /* > Specifies the intermediate precision to be used in refinement. */
  549. /* > The value is defined by ILAPREC(P) where P is a CHARACTER and P */
  550. /* > = 'S': Single */
  551. /* > = 'D': Double */
  552. /* > = 'I': Indigenous */
  553. /* > = 'X' or 'E': Extra */
  554. /* > \endverbatim */
  555. /* > */
  556. /* > \param[in] UPLO */
  557. /* > \verbatim */
  558. /* > UPLO is CHARACTER*1 */
  559. /* > = 'U': Upper triangle of A is stored; */
  560. /* > = 'L': Lower triangle of A is stored. */
  561. /* > \endverbatim */
  562. /* > */
  563. /* > \param[in] N */
  564. /* > \verbatim */
  565. /* > N is INTEGER */
  566. /* > The number of linear equations, i.e., the order of the */
  567. /* > matrix A. N >= 0. */
  568. /* > \endverbatim */
  569. /* > */
  570. /* > \param[in] NRHS */
  571. /* > \verbatim */
  572. /* > NRHS is INTEGER */
  573. /* > The number of right-hand-sides, i.e., the number of columns of the */
  574. /* > matrix B. */
  575. /* > \endverbatim */
  576. /* > */
  577. /* > \param[in] A */
  578. /* > \verbatim */
  579. /* > A is COMPLEX array, dimension (LDA,N) */
  580. /* > On entry, the N-by-N matrix A. */
  581. /* > \endverbatim */
  582. /* > */
  583. /* > \param[in] LDA */
  584. /* > \verbatim */
  585. /* > LDA is INTEGER */
  586. /* > The leading dimension of the array A. LDA >= f2cmax(1,N). */
  587. /* > \endverbatim */
  588. /* > */
  589. /* > \param[in] AF */
  590. /* > \verbatim */
  591. /* > AF is COMPLEX array, dimension (LDAF,N) */
  592. /* > The triangular factor U or L from the Cholesky factorization */
  593. /* > A = U**T*U or A = L*L**T, as computed by CPOTRF. */
  594. /* > \endverbatim */
  595. /* > */
  596. /* > \param[in] LDAF */
  597. /* > \verbatim */
  598. /* > LDAF is INTEGER */
  599. /* > The leading dimension of the array AF. LDAF >= f2cmax(1,N). */
  600. /* > \endverbatim */
  601. /* > */
  602. /* > \param[in] COLEQU */
  603. /* > \verbatim */
  604. /* > COLEQU is LOGICAL */
  605. /* > If .TRUE. then column equilibration was done to A before calling */
  606. /* > this routine. This is needed to compute the solution and error */
  607. /* > bounds correctly. */
  608. /* > \endverbatim */
  609. /* > */
  610. /* > \param[in] C */
  611. /* > \verbatim */
  612. /* > C is REAL array, dimension (N) */
  613. /* > The column scale factors for A. If COLEQU = .FALSE., C */
  614. /* > is not accessed. If C is input, each element of C should be a power */
  615. /* > of the radix to ensure a reliable solution and error estimates. */
  616. /* > Scaling by powers of the radix does not cause rounding errors unless */
  617. /* > the result underflows or overflows. Rounding errors during scaling */
  618. /* > lead to refining with a matrix that is not equivalent to the */
  619. /* > input matrix, producing error estimates that may not be */
  620. /* > reliable. */
  621. /* > \endverbatim */
  622. /* > */
  623. /* > \param[in] B */
  624. /* > \verbatim */
  625. /* > B is COMPLEX array, dimension (LDB,NRHS) */
  626. /* > The right-hand-side matrix B. */
  627. /* > \endverbatim */
  628. /* > */
  629. /* > \param[in] LDB */
  630. /* > \verbatim */
  631. /* > LDB is INTEGER */
  632. /* > The leading dimension of the array B. LDB >= f2cmax(1,N). */
  633. /* > \endverbatim */
  634. /* > */
  635. /* > \param[in,out] Y */
  636. /* > \verbatim */
  637. /* > Y is COMPLEX array, dimension (LDY,NRHS) */
  638. /* > On entry, the solution matrix X, as computed by CPOTRS. */
  639. /* > On exit, the improved solution matrix Y. */
  640. /* > \endverbatim */
  641. /* > */
  642. /* > \param[in] LDY */
  643. /* > \verbatim */
  644. /* > LDY is INTEGER */
  645. /* > The leading dimension of the array Y. LDY >= f2cmax(1,N). */
  646. /* > \endverbatim */
  647. /* > */
  648. /* > \param[out] BERR_OUT */
  649. /* > \verbatim */
  650. /* > BERR_OUT is REAL array, dimension (NRHS) */
  651. /* > On exit, BERR_OUT(j) contains the componentwise relative backward */
  652. /* > error for right-hand-side j from the formula */
  653. /* > f2cmax(i) ( abs(RES(i)) / ( abs(op(A_s))*abs(Y) + abs(B_s) )(i) ) */
  654. /* > where abs(Z) is the componentwise absolute value of the matrix */
  655. /* > or vector Z. This is computed by CLA_LIN_BERR. */
  656. /* > \endverbatim */
  657. /* > */
  658. /* > \param[in] N_NORMS */
  659. /* > \verbatim */
  660. /* > N_NORMS is INTEGER */
  661. /* > Determines which error bounds to return (see ERR_BNDS_NORM */
  662. /* > and ERR_BNDS_COMP). */
  663. /* > If N_NORMS >= 1 return normwise error bounds. */
  664. /* > If N_NORMS >= 2 return componentwise error bounds. */
  665. /* > \endverbatim */
  666. /* > */
  667. /* > \param[in,out] ERR_BNDS_NORM */
  668. /* > \verbatim */
  669. /* > ERR_BNDS_NORM is REAL array, dimension (NRHS, N_ERR_BNDS) */
  670. /* > For each right-hand side, this array contains information about */
  671. /* > various error bounds and condition numbers corresponding to the */
  672. /* > normwise relative error, which is defined as follows: */
  673. /* > */
  674. /* > Normwise relative error in the ith solution vector: */
  675. /* > max_j (abs(XTRUE(j,i) - X(j,i))) */
  676. /* > ------------------------------ */
  677. /* > max_j abs(X(j,i)) */
  678. /* > */
  679. /* > The array is indexed by the type of error information as described */
  680. /* > below. There currently are up to three pieces of information */
  681. /* > returned. */
  682. /* > */
  683. /* > The first index in ERR_BNDS_NORM(i,:) corresponds to the ith */
  684. /* > right-hand side. */
  685. /* > */
  686. /* > The second index in ERR_BNDS_NORM(:,err) contains the following */
  687. /* > three fields: */
  688. /* > err = 1 "Trust/don't trust" boolean. Trust the answer if the */
  689. /* > reciprocal condition number is less than the threshold */
  690. /* > sqrt(n) * slamch('Epsilon'). */
  691. /* > */
  692. /* > err = 2 "Guaranteed" error bound: The estimated forward error, */
  693. /* > almost certainly within a factor of 10 of the true error */
  694. /* > so long as the next entry is greater than the threshold */
  695. /* > sqrt(n) * slamch('Epsilon'). This error bound should only */
  696. /* > be trusted if the previous boolean is true. */
  697. /* > */
  698. /* > err = 3 Reciprocal condition number: Estimated normwise */
  699. /* > reciprocal condition number. Compared with the threshold */
  700. /* > sqrt(n) * slamch('Epsilon') to determine if the error */
  701. /* > estimate is "guaranteed". These reciprocal condition */
  702. /* > numbers are 1 / (norm(Z^{-1},inf) * norm(Z,inf)) for some */
  703. /* > appropriately scaled matrix Z. */
  704. /* > Let Z = S*A, where S scales each row by a power of the */
  705. /* > radix so all absolute row sums of Z are approximately 1. */
  706. /* > */
  707. /* > This subroutine is only responsible for setting the second field */
  708. /* > above. */
  709. /* > See Lapack Working Note 165 for further details and extra */
  710. /* > cautions. */
  711. /* > \endverbatim */
  712. /* > */
  713. /* > \param[in,out] ERR_BNDS_COMP */
  714. /* > \verbatim */
  715. /* > ERR_BNDS_COMP is REAL array, dimension (NRHS, N_ERR_BNDS) */
  716. /* > For each right-hand side, this array contains information about */
  717. /* > various error bounds and condition numbers corresponding to the */
  718. /* > componentwise relative error, which is defined as follows: */
  719. /* > */
  720. /* > Componentwise relative error in the ith solution vector: */
  721. /* > abs(XTRUE(j,i) - X(j,i)) */
  722. /* > max_j ---------------------- */
  723. /* > abs(X(j,i)) */
  724. /* > */
  725. /* > The array is indexed by the right-hand side i (on which the */
  726. /* > componentwise relative error depends), and the type of error */
  727. /* > information as described below. There currently are up to three */
  728. /* > pieces of information returned for each right-hand side. If */
  729. /* > componentwise accuracy is not requested (PARAMS(3) = 0.0), then */
  730. /* > ERR_BNDS_COMP is not accessed. If N_ERR_BNDS < 3, then at most */
  731. /* > the first (:,N_ERR_BNDS) entries are returned. */
  732. /* > */
  733. /* > The first index in ERR_BNDS_COMP(i,:) corresponds to the ith */
  734. /* > right-hand side. */
  735. /* > */
  736. /* > The second index in ERR_BNDS_COMP(:,err) contains the following */
  737. /* > three fields: */
  738. /* > err = 1 "Trust/don't trust" boolean. Trust the answer if the */
  739. /* > reciprocal condition number is less than the threshold */
  740. /* > sqrt(n) * slamch('Epsilon'). */
  741. /* > */
  742. /* > err = 2 "Guaranteed" error bound: The estimated forward error, */
  743. /* > almost certainly within a factor of 10 of the true error */
  744. /* > so long as the next entry is greater than the threshold */
  745. /* > sqrt(n) * slamch('Epsilon'). This error bound should only */
  746. /* > be trusted if the previous boolean is true. */
  747. /* > */
  748. /* > err = 3 Reciprocal condition number: Estimated componentwise */
  749. /* > reciprocal condition number. Compared with the threshold */
  750. /* > sqrt(n) * slamch('Epsilon') to determine if the error */
  751. /* > estimate is "guaranteed". These reciprocal condition */
  752. /* > numbers are 1 / (norm(Z^{-1},inf) * norm(Z,inf)) for some */
  753. /* > appropriately scaled matrix Z. */
  754. /* > Let Z = S*(A*diag(x)), where x is the solution for the */
  755. /* > current right-hand side and S scales each row of */
  756. /* > A*diag(x) by a power of the radix so all absolute row */
  757. /* > sums of Z are approximately 1. */
  758. /* > */
  759. /* > This subroutine is only responsible for setting the second field */
  760. /* > above. */
  761. /* > See Lapack Working Note 165 for further details and extra */
  762. /* > cautions. */
  763. /* > \endverbatim */
  764. /* > */
  765. /* > \param[in] RES */
  766. /* > \verbatim */
  767. /* > RES is COMPLEX array, dimension (N) */
  768. /* > Workspace to hold the intermediate residual. */
  769. /* > \endverbatim */
  770. /* > */
  771. /* > \param[in] AYB */
  772. /* > \verbatim */
  773. /* > AYB is REAL array, dimension (N) */
  774. /* > Workspace. */
  775. /* > \endverbatim */
  776. /* > */
  777. /* > \param[in] DY */
  778. /* > \verbatim */
  779. /* > DY is COMPLEX array, dimension (N) */
  780. /* > Workspace to hold the intermediate solution. */
  781. /* > \endverbatim */
  782. /* > */
  783. /* > \param[in] Y_TAIL */
  784. /* > \verbatim */
  785. /* > Y_TAIL is COMPLEX array, dimension (N) */
  786. /* > Workspace to hold the trailing bits of the intermediate solution. */
  787. /* > \endverbatim */
  788. /* > */
  789. /* > \param[in] RCOND */
  790. /* > \verbatim */
  791. /* > RCOND is REAL */
  792. /* > Reciprocal scaled condition number. This is an estimate of the */
  793. /* > reciprocal Skeel condition number of the matrix A after */
  794. /* > equilibration (if done). If this is less than the machine */
  795. /* > precision (in particular, if it is zero), the matrix is singular */
  796. /* > to working precision. Note that the error may still be small even */
  797. /* > if this number is very small and the matrix appears ill- */
  798. /* > conditioned. */
  799. /* > \endverbatim */
  800. /* > */
  801. /* > \param[in] ITHRESH */
  802. /* > \verbatim */
  803. /* > ITHRESH is INTEGER */
  804. /* > The maximum number of residual computations allowed for */
  805. /* > refinement. The default is 10. For 'aggressive' set to 100 to */
  806. /* > permit convergence using approximate factorizations or */
  807. /* > factorizations other than LU. If the factorization uses a */
  808. /* > technique other than Gaussian elimination, the guarantees in */
  809. /* > ERR_BNDS_NORM and ERR_BNDS_COMP may no longer be trustworthy. */
  810. /* > \endverbatim */
  811. /* > */
  812. /* > \param[in] RTHRESH */
  813. /* > \verbatim */
  814. /* > RTHRESH is REAL */
  815. /* > Determines when to stop refinement if the error estimate stops */
  816. /* > decreasing. Refinement will stop when the next solution no longer */
  817. /* > satisfies norm(dx_{i+1}) < RTHRESH * norm(dx_i) where norm(Z) is */
  818. /* > the infinity norm of Z. RTHRESH satisfies 0 < RTHRESH <= 1. The */
  819. /* > default value is 0.5. For 'aggressive' set to 0.9 to permit */
  820. /* > convergence on extremely ill-conditioned matrices. See LAWN 165 */
  821. /* > for more details. */
  822. /* > \endverbatim */
  823. /* > */
  824. /* > \param[in] DZ_UB */
  825. /* > \verbatim */
  826. /* > DZ_UB is REAL */
  827. /* > Determines when to start considering componentwise convergence. */
  828. /* > Componentwise convergence is only considered after each component */
  829. /* > of the solution Y is stable, which we definte as the relative */
  830. /* > change in each component being less than DZ_UB. The default value */
  831. /* > is 0.25, requiring the first bit to be stable. See LAWN 165 for */
  832. /* > more details. */
  833. /* > \endverbatim */
  834. /* > */
  835. /* > \param[in] IGNORE_CWISE */
  836. /* > \verbatim */
  837. /* > IGNORE_CWISE is LOGICAL */
  838. /* > If .TRUE. then ignore componentwise convergence. Default value */
  839. /* > is .FALSE.. */
  840. /* > \endverbatim */
  841. /* > */
  842. /* > \param[out] INFO */
  843. /* > \verbatim */
  844. /* > INFO is INTEGER */
  845. /* > = 0: Successful exit. */
  846. /* > < 0: if INFO = -i, the ith argument to CPOTRS had an illegal */
  847. /* > value */
  848. /* > \endverbatim */
  849. /* Authors: */
  850. /* ======== */
  851. /* > \author Univ. of Tennessee */
  852. /* > \author Univ. of California Berkeley */
  853. /* > \author Univ. of Colorado Denver */
  854. /* > \author NAG Ltd. */
  855. /* > \date June 2017 */
  856. /* > \ingroup complexPOcomputational */
  857. /* ===================================================================== */
  858. /* Subroutine */ void cla_porfsx_extended_(integer *prec_type__, char *uplo,
  859. integer *n, integer *nrhs, complex *a, integer *lda, complex *af,
  860. integer *ldaf, logical *colequ, real *c__, complex *b, integer *ldb,
  861. complex *y, integer *ldy, real *berr_out__, integer *n_norms__, real *
  862. err_bnds_norm__, real *err_bnds_comp__, complex *res, real *ayb,
  863. complex *dy, complex *y_tail__, real *rcond, integer *ithresh, real *
  864. rthresh, real *dz_ub__, logical *ignore_cwise__, integer *info)
  865. {
  866. /* System generated locals */
  867. integer a_dim1, a_offset, af_dim1, af_offset, b_dim1, b_offset, y_dim1,
  868. y_offset, err_bnds_norm_dim1, err_bnds_norm_offset,
  869. err_bnds_comp_dim1, err_bnds_comp_offset, i__1, i__2, i__3, i__4;
  870. real r__1, r__2;
  871. /* Local variables */
  872. real dx_x__, dz_z__;
  873. extern /* Subroutine */ void cla_lin_berr_(integer *, integer *, integer *
  874. , complex *, real *, real *);
  875. real ymin;
  876. extern /* Subroutine */ void blas_chemv_x_(integer *, integer *, complex *
  877. , complex *, integer *, complex *, integer *, complex *, complex *
  878. , integer *, integer *);
  879. real dxratmax, dzratmax;
  880. integer y_prec_state__, uplo2, i__, j;
  881. extern /* Subroutine */ void blas_chemv2_x_(integer *, integer *, complex
  882. *, complex *, integer *, complex *, complex *, integer *, complex
  883. *, complex *, integer *, integer *), cla_heamv_(integer *,
  884. integer *, real *, complex *, integer *, complex *, integer *,
  885. real *, real *, integer *);
  886. extern logical lsame_(char *, char *);
  887. extern /* Subroutine */ void chemv_(char *, integer *, complex *, complex *
  888. , integer *, complex *, integer *, complex *, complex *, integer *
  889. ), ccopy_(integer *, complex *, integer *, complex *,
  890. integer *);
  891. real dxrat;
  892. logical incr_prec__;
  893. real dzrat;
  894. extern /* Subroutine */ void caxpy_(integer *, complex *, complex *,
  895. integer *, complex *, integer *);
  896. real normx, normy, myhugeval, prev_dz_z__, yk;
  897. extern real slamch_(char *);
  898. real final_dx_x__;
  899. extern /* Subroutine */ void cla_wwaddw_(integer *, complex *, complex *,
  900. complex *);
  901. real final_dz_z__, normdx;
  902. extern /* Subroutine */ void cpotrs_(char *, integer *, integer *, complex
  903. *, integer *, complex *, integer *, integer *);
  904. real prevnormdx;
  905. integer cnt;
  906. real dyk, eps;
  907. extern integer ilauplo_(char *);
  908. integer x_state__, z_state__;
  909. real incr_thresh__;
  910. /* -- LAPACK computational routine (version 3.7.1) -- */
  911. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  912. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  913. /* June 2017 */
  914. /* ===================================================================== */
  915. /* Parameter adjustments */
  916. err_bnds_comp_dim1 = *nrhs;
  917. err_bnds_comp_offset = 1 + err_bnds_comp_dim1 * 1;
  918. err_bnds_comp__ -= err_bnds_comp_offset;
  919. err_bnds_norm_dim1 = *nrhs;
  920. err_bnds_norm_offset = 1 + err_bnds_norm_dim1 * 1;
  921. err_bnds_norm__ -= err_bnds_norm_offset;
  922. a_dim1 = *lda;
  923. a_offset = 1 + a_dim1 * 1;
  924. a -= a_offset;
  925. af_dim1 = *ldaf;
  926. af_offset = 1 + af_dim1 * 1;
  927. af -= af_offset;
  928. --c__;
  929. b_dim1 = *ldb;
  930. b_offset = 1 + b_dim1 * 1;
  931. b -= b_offset;
  932. y_dim1 = *ldy;
  933. y_offset = 1 + y_dim1 * 1;
  934. y -= y_offset;
  935. --berr_out__;
  936. --res;
  937. --ayb;
  938. --dy;
  939. --y_tail__;
  940. /* Function Body */
  941. if (*info != 0) {
  942. return;
  943. }
  944. eps = slamch_("Epsilon");
  945. myhugeval = slamch_("Overflow");
  946. /* Force MYHUGEVAL to Inf */
  947. myhugeval *= myhugeval;
  948. /* Using MYHUGEVAL may lead to spurious underflows. */
  949. incr_thresh__ = (real) (*n) * eps;
  950. if (lsame_(uplo, "L")) {
  951. uplo2 = ilauplo_("L");
  952. } else {
  953. uplo2 = ilauplo_("U");
  954. }
  955. i__1 = *nrhs;
  956. for (j = 1; j <= i__1; ++j) {
  957. y_prec_state__ = 1;
  958. if (y_prec_state__ == 2) {
  959. i__2 = *n;
  960. for (i__ = 1; i__ <= i__2; ++i__) {
  961. i__3 = i__;
  962. y_tail__[i__3].r = 0.f, y_tail__[i__3].i = 0.f;
  963. }
  964. }
  965. dxrat = 0.f;
  966. dxratmax = 0.f;
  967. dzrat = 0.f;
  968. dzratmax = 0.f;
  969. final_dx_x__ = myhugeval;
  970. final_dz_z__ = myhugeval;
  971. prevnormdx = myhugeval;
  972. prev_dz_z__ = myhugeval;
  973. dz_z__ = myhugeval;
  974. dx_x__ = myhugeval;
  975. x_state__ = 1;
  976. z_state__ = 0;
  977. incr_prec__ = FALSE_;
  978. i__2 = *ithresh;
  979. for (cnt = 1; cnt <= i__2; ++cnt) {
  980. /* Compute residual RES = B_s - op(A_s) * Y, */
  981. /* op(A) = A, A**T, or A**H depending on TRANS (and type). */
  982. ccopy_(n, &b[j * b_dim1 + 1], &c__1, &res[1], &c__1);
  983. if (y_prec_state__ == 0) {
  984. chemv_(uplo, n, &c_b11, &a[a_offset], lda, &y[j * y_dim1 + 1],
  985. &c__1, &c_b12, &res[1], &c__1);
  986. } else if (y_prec_state__ == 1) {
  987. blas_chemv_x__(&uplo2, n, &c_b11, &a[a_offset], lda, &y[j *
  988. y_dim1 + 1], &c__1, &c_b12, &res[1], &c__1,
  989. prec_type__);
  990. } else {
  991. blas_chemv2_x__(&uplo2, n, &c_b11, &a[a_offset], lda, &y[j *
  992. y_dim1 + 1], &y_tail__[1], &c__1, &c_b12, &res[1], &
  993. c__1, prec_type__);
  994. }
  995. /* XXX: RES is no longer needed. */
  996. ccopy_(n, &res[1], &c__1, &dy[1], &c__1);
  997. cpotrs_(uplo, n, &c__1, &af[af_offset], ldaf, &dy[1], n, info);
  998. /* Calculate relative changes DX_X, DZ_Z and ratios DXRAT, DZRAT. */
  999. normx = 0.f;
  1000. normy = 0.f;
  1001. normdx = 0.f;
  1002. dz_z__ = 0.f;
  1003. ymin = myhugeval;
  1004. i__3 = *n;
  1005. for (i__ = 1; i__ <= i__3; ++i__) {
  1006. i__4 = i__ + j * y_dim1;
  1007. yk = (r__1 = y[i__4].r, abs(r__1)) + (r__2 = r_imag(&y[i__ +
  1008. j * y_dim1]), abs(r__2));
  1009. i__4 = i__;
  1010. dyk = (r__1 = dy[i__4].r, abs(r__1)) + (r__2 = r_imag(&dy[i__]
  1011. ), abs(r__2));
  1012. if (yk != 0.f) {
  1013. /* Computing MAX */
  1014. r__1 = dz_z__, r__2 = dyk / yk;
  1015. dz_z__ = f2cmax(r__1,r__2);
  1016. } else if (dyk != 0.f) {
  1017. dz_z__ = myhugeval;
  1018. }
  1019. ymin = f2cmin(ymin,yk);
  1020. normy = f2cmax(normy,yk);
  1021. if (*colequ) {
  1022. /* Computing MAX */
  1023. r__1 = normx, r__2 = yk * c__[i__];
  1024. normx = f2cmax(r__1,r__2);
  1025. /* Computing MAX */
  1026. r__1 = normdx, r__2 = dyk * c__[i__];
  1027. normdx = f2cmax(r__1,r__2);
  1028. } else {
  1029. normx = normy;
  1030. normdx = f2cmax(normdx,dyk);
  1031. }
  1032. }
  1033. if (normx != 0.f) {
  1034. dx_x__ = normdx / normx;
  1035. } else if (normdx == 0.f) {
  1036. dx_x__ = 0.f;
  1037. } else {
  1038. dx_x__ = myhugeval;
  1039. }
  1040. dxrat = normdx / prevnormdx;
  1041. dzrat = dz_z__ / prev_dz_z__;
  1042. /* Check termination criteria. */
  1043. if (ymin * *rcond < incr_thresh__ * normy && y_prec_state__ < 2) {
  1044. incr_prec__ = TRUE_;
  1045. }
  1046. if (x_state__ == 3 && dxrat <= *rthresh) {
  1047. x_state__ = 1;
  1048. }
  1049. if (x_state__ == 1) {
  1050. if (dx_x__ <= eps) {
  1051. x_state__ = 2;
  1052. } else if (dxrat > *rthresh) {
  1053. if (y_prec_state__ != 2) {
  1054. incr_prec__ = TRUE_;
  1055. } else {
  1056. x_state__ = 3;
  1057. }
  1058. } else {
  1059. if (dxrat > dxratmax) {
  1060. dxratmax = dxrat;
  1061. }
  1062. }
  1063. if (x_state__ > 1) {
  1064. final_dx_x__ = dx_x__;
  1065. }
  1066. }
  1067. if (z_state__ == 0 && dz_z__ <= *dz_ub__) {
  1068. z_state__ = 1;
  1069. }
  1070. if (z_state__ == 3 && dzrat <= *rthresh) {
  1071. z_state__ = 1;
  1072. }
  1073. if (z_state__ == 1) {
  1074. if (dz_z__ <= eps) {
  1075. z_state__ = 2;
  1076. } else if (dz_z__ > *dz_ub__) {
  1077. z_state__ = 0;
  1078. dzratmax = 0.f;
  1079. final_dz_z__ = myhugeval;
  1080. } else if (dzrat > *rthresh) {
  1081. if (y_prec_state__ != 2) {
  1082. incr_prec__ = TRUE_;
  1083. } else {
  1084. z_state__ = 3;
  1085. }
  1086. } else {
  1087. if (dzrat > dzratmax) {
  1088. dzratmax = dzrat;
  1089. }
  1090. }
  1091. if (z_state__ > 1) {
  1092. final_dz_z__ = dz_z__;
  1093. }
  1094. }
  1095. if (x_state__ != 1 && (*ignore_cwise__ || z_state__ != 1)) {
  1096. goto L666;
  1097. }
  1098. if (incr_prec__) {
  1099. incr_prec__ = FALSE_;
  1100. ++y_prec_state__;
  1101. i__3 = *n;
  1102. for (i__ = 1; i__ <= i__3; ++i__) {
  1103. i__4 = i__;
  1104. y_tail__[i__4].r = 0.f, y_tail__[i__4].i = 0.f;
  1105. }
  1106. }
  1107. prevnormdx = normdx;
  1108. prev_dz_z__ = dz_z__;
  1109. /* Update soluton. */
  1110. if (y_prec_state__ < 2) {
  1111. caxpy_(n, &c_b12, &dy[1], &c__1, &y[j * y_dim1 + 1], &c__1);
  1112. } else {
  1113. cla_wwaddw_(n, &y[j * y_dim1 + 1], &y_tail__[1], &dy[1]);
  1114. }
  1115. }
  1116. /* Target of "IF (Z_STOP .AND. X_STOP)". Sun's f77 won't CALL MYEXIT. */
  1117. L666:
  1118. /* Set final_* when cnt hits ithresh. */
  1119. if (x_state__ == 1) {
  1120. final_dx_x__ = dx_x__;
  1121. }
  1122. if (z_state__ == 1) {
  1123. final_dz_z__ = dz_z__;
  1124. }
  1125. /* Compute error bounds. */
  1126. if (*n_norms__ >= 1) {
  1127. err_bnds_norm__[j + (err_bnds_norm_dim1 << 1)] = final_dx_x__ / (
  1128. 1 - dxratmax);
  1129. }
  1130. if (*n_norms__ >= 2) {
  1131. err_bnds_comp__[j + (err_bnds_comp_dim1 << 1)] = final_dz_z__ / (
  1132. 1 - dzratmax);
  1133. }
  1134. /* Compute componentwise relative backward error from formula */
  1135. /* f2cmax(i) ( abs(R(i)) / ( abs(op(A_s))*abs(Y) + abs(B_s) )(i) ) */
  1136. /* where abs(Z) is the componentwise absolute value of the matrix */
  1137. /* or vector Z. */
  1138. /* Compute residual RES = B_s - op(A_s) * Y, */
  1139. /* op(A) = A, A**T, or A**H depending on TRANS (and type). */
  1140. ccopy_(n, &b[j * b_dim1 + 1], &c__1, &res[1], &c__1);
  1141. chemv_(uplo, n, &c_b11, &a[a_offset], lda, &y[j * y_dim1 + 1], &c__1,
  1142. &c_b12, &res[1], &c__1);
  1143. i__2 = *n;
  1144. for (i__ = 1; i__ <= i__2; ++i__) {
  1145. i__3 = i__ + j * b_dim1;
  1146. ayb[i__] = (r__1 = b[i__3].r, abs(r__1)) + (r__2 = r_imag(&b[i__
  1147. + j * b_dim1]), abs(r__2));
  1148. }
  1149. /* Compute abs(op(A_s))*abs(Y) + abs(B_s). */
  1150. cla_heamv_(&uplo2, n, &c_b34, &a[a_offset], lda, &y[j * y_dim1 + 1],
  1151. &c__1, &c_b34, &ayb[1], &c__1);
  1152. cla_lin_berr_(n, n, &c__1, &res[1], &ayb[1], &berr_out__[j]);
  1153. /* End of loop for each RHS. */
  1154. }
  1155. return;
  1156. } /* cla_porfsx_extended__ */