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.

chetri_3x.c 42 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434
  1. #include <math.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <stdio.h>
  5. #include <complex.h>
  6. #ifdef complex
  7. #undef complex
  8. #endif
  9. #ifdef I
  10. #undef I
  11. #endif
  12. #if defined(_WIN64)
  13. typedef long long BLASLONG;
  14. typedef unsigned long long BLASULONG;
  15. #else
  16. typedef long BLASLONG;
  17. typedef unsigned long BLASULONG;
  18. #endif
  19. #ifdef LAPACK_ILP64
  20. typedef BLASLONG blasint;
  21. #if defined(_WIN64)
  22. #define blasabs(x) llabs(x)
  23. #else
  24. #define blasabs(x) labs(x)
  25. #endif
  26. #else
  27. typedef int blasint;
  28. #define blasabs(x) abs(x)
  29. #endif
  30. typedef blasint integer;
  31. typedef unsigned int uinteger;
  32. typedef char *address;
  33. typedef short int shortint;
  34. typedef float real;
  35. typedef double doublereal;
  36. typedef struct { real r, i; } complex;
  37. typedef struct { doublereal r, i; } doublecomplex;
  38. #ifdef _MSC_VER
  39. static inline _Fcomplex Cf(complex *z) {_Fcomplex zz={z->r , z->i}; return zz;}
  40. static inline _Dcomplex Cd(doublecomplex *z) {_Dcomplex zz={z->r , z->i};return zz;}
  41. static inline _Fcomplex * _pCf(complex *z) {return (_Fcomplex*)z;}
  42. static inline _Dcomplex * _pCd(doublecomplex *z) {return (_Dcomplex*)z;}
  43. #else
  44. static inline _Complex float Cf(complex *z) {return z->r + z->i*_Complex_I;}
  45. static inline _Complex double Cd(doublecomplex *z) {return z->r + z->i*_Complex_I;}
  46. static inline _Complex float * _pCf(complex *z) {return (_Complex float*)z;}
  47. static inline _Complex double * _pCd(doublecomplex *z) {return (_Complex double*)z;}
  48. #endif
  49. #define pCf(z) (*_pCf(z))
  50. #define pCd(z) (*_pCd(z))
  51. typedef blasint logical;
  52. typedef char logical1;
  53. typedef char integer1;
  54. #define TRUE_ (1)
  55. #define FALSE_ (0)
  56. /* Extern is for use with -E */
  57. #ifndef Extern
  58. #define Extern extern
  59. #endif
  60. /* I/O stuff */
  61. typedef int flag;
  62. typedef int ftnlen;
  63. typedef int ftnint;
  64. /*external read, write*/
  65. typedef struct
  66. { flag cierr;
  67. ftnint ciunit;
  68. flag ciend;
  69. char *cifmt;
  70. ftnint cirec;
  71. } cilist;
  72. /*internal read, write*/
  73. typedef struct
  74. { flag icierr;
  75. char *iciunit;
  76. flag iciend;
  77. char *icifmt;
  78. ftnint icirlen;
  79. ftnint icirnum;
  80. } icilist;
  81. /*open*/
  82. typedef struct
  83. { flag oerr;
  84. ftnint ounit;
  85. char *ofnm;
  86. ftnlen ofnmlen;
  87. char *osta;
  88. char *oacc;
  89. char *ofm;
  90. ftnint orl;
  91. char *oblnk;
  92. } olist;
  93. /*close*/
  94. typedef struct
  95. { flag cerr;
  96. ftnint cunit;
  97. char *csta;
  98. } cllist;
  99. /*rewind, backspace, endfile*/
  100. typedef struct
  101. { flag aerr;
  102. ftnint aunit;
  103. } alist;
  104. /* inquire */
  105. typedef struct
  106. { flag inerr;
  107. ftnint inunit;
  108. char *infile;
  109. ftnlen infilen;
  110. ftnint *inex; /*parameters in standard's order*/
  111. ftnint *inopen;
  112. ftnint *innum;
  113. ftnint *innamed;
  114. char *inname;
  115. ftnlen innamlen;
  116. char *inacc;
  117. ftnlen inacclen;
  118. char *inseq;
  119. ftnlen inseqlen;
  120. char *indir;
  121. ftnlen indirlen;
  122. char *infmt;
  123. ftnlen infmtlen;
  124. char *inform;
  125. ftnint informlen;
  126. char *inunf;
  127. ftnlen inunflen;
  128. ftnint *inrecl;
  129. ftnint *innrec;
  130. char *inblank;
  131. ftnlen inblanklen;
  132. } inlist;
  133. #define VOID void
  134. union Multitype { /* for multiple entry points */
  135. integer1 g;
  136. shortint h;
  137. integer i;
  138. /* longint j; */
  139. real r;
  140. doublereal d;
  141. complex c;
  142. doublecomplex z;
  143. };
  144. typedef union Multitype Multitype;
  145. struct Vardesc { /* for Namelist */
  146. char *name;
  147. char *addr;
  148. ftnlen *dims;
  149. int type;
  150. };
  151. typedef struct Vardesc Vardesc;
  152. struct Namelist {
  153. char *name;
  154. Vardesc **vars;
  155. int nvars;
  156. };
  157. typedef struct Namelist Namelist;
  158. #define abs(x) ((x) >= 0 ? (x) : -(x))
  159. #define dabs(x) (fabs(x))
  160. #define f2cmin(a,b) ((a) <= (b) ? (a) : (b))
  161. #define f2cmax(a,b) ((a) >= (b) ? (a) : (b))
  162. #define dmin(a,b) (f2cmin(a,b))
  163. #define dmax(a,b) (f2cmax(a,b))
  164. #define bit_test(a,b) ((a) >> (b) & 1)
  165. #define bit_clear(a,b) ((a) & ~((uinteger)1 << (b)))
  166. #define bit_set(a,b) ((a) | ((uinteger)1 << (b)))
  167. #define abort_() { sig_die("Fortran abort routine called", 1); }
  168. #define c_abs(z) (cabsf(Cf(z)))
  169. #define c_cos(R,Z) { pCf(R)=ccos(Cf(Z)); }
  170. #ifdef _MSC_VER
  171. #define c_div(c, a, b) {Cf(c)._Val[0] = (Cf(a)._Val[0]/Cf(b)._Val[0]); Cf(c)._Val[1]=(Cf(a)._Val[1]/Cf(b)._Val[1]);}
  172. #define z_div(c, a, b) {Cd(c)._Val[0] = (Cd(a)._Val[0]/Cd(b)._Val[0]); Cd(c)._Val[1]=(Cd(a)._Val[1]/df(b)._Val[1]);}
  173. #else
  174. #define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);}
  175. #define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);}
  176. #endif
  177. #define c_exp(R, Z) {pCf(R) = cexpf(Cf(Z));}
  178. #define c_log(R, Z) {pCf(R) = clogf(Cf(Z));}
  179. #define c_sin(R, Z) {pCf(R) = csinf(Cf(Z));}
  180. //#define c_sqrt(R, Z) {*(R) = csqrtf(Cf(Z));}
  181. #define c_sqrt(R, Z) {pCf(R) = csqrtf(Cf(Z));}
  182. #define d_abs(x) (fabs(*(x)))
  183. #define d_acos(x) (acos(*(x)))
  184. #define d_asin(x) (asin(*(x)))
  185. #define d_atan(x) (atan(*(x)))
  186. #define d_atn2(x, y) (atan2(*(x),*(y)))
  187. #define d_cnjg(R, Z) { pCd(R) = conj(Cd(Z)); }
  188. #define r_cnjg(R, Z) { pCf(R) = conjf(Cf(Z)); }
  189. #define d_cos(x) (cos(*(x)))
  190. #define d_cosh(x) (cosh(*(x)))
  191. #define d_dim(__a, __b) ( *(__a) > *(__b) ? *(__a) - *(__b) : 0.0 )
  192. #define d_exp(x) (exp(*(x)))
  193. #define d_imag(z) (cimag(Cd(z)))
  194. #define r_imag(z) (cimagf(Cf(z)))
  195. #define d_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  196. #define r_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  197. #define d_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  198. #define r_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  199. #define d_log(x) (log(*(x)))
  200. #define d_mod(x, y) (fmod(*(x), *(y)))
  201. #define u_nint(__x) ((__x)>=0 ? floor((__x) + .5) : -floor(.5 - (__x)))
  202. #define d_nint(x) u_nint(*(x))
  203. #define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a)))
  204. #define d_sign(a,b) u_sign(*(a),*(b))
  205. #define r_sign(a,b) u_sign(*(a),*(b))
  206. #define d_sin(x) (sin(*(x)))
  207. #define d_sinh(x) (sinh(*(x)))
  208. #define d_sqrt(x) (sqrt(*(x)))
  209. #define d_tan(x) (tan(*(x)))
  210. #define d_tanh(x) (tanh(*(x)))
  211. #define i_abs(x) abs(*(x))
  212. #define i_dnnt(x) ((integer)u_nint(*(x)))
  213. #define i_len(s, n) (n)
  214. #define i_nint(x) ((integer)u_nint(*(x)))
  215. #define i_sign(a,b) ((integer)u_sign((integer)*(a),(integer)*(b)))
  216. #define pow_dd(ap, bp) ( pow(*(ap), *(bp)))
  217. #define pow_si(B,E) spow_ui(*(B),*(E))
  218. #define pow_ri(B,E) spow_ui(*(B),*(E))
  219. #define pow_di(B,E) dpow_ui(*(B),*(E))
  220. #define pow_zi(p, a, b) {pCd(p) = zpow_ui(Cd(a), *(b));}
  221. #define pow_ci(p, a, b) {pCf(p) = cpow_ui(Cf(a), *(b));}
  222. #define pow_zz(R,A,B) {pCd(R) = cpow(Cd(A),*(B));}
  223. #define s_cat(lpp, rpp, rnp, np, llp) { ftnlen i, nc, ll; char *f__rp, *lp; ll = (llp); lp = (lpp); for(i=0; i < (int)*(np); ++i) { nc = ll; if((rnp)[i] < nc) nc = (rnp)[i]; ll -= nc; f__rp = (rpp)[i]; while(--nc >= 0) *lp++ = *(f__rp)++; } while(--ll >= 0) *lp++ = ' '; }
  224. #define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d))))
  225. #define s_copy(A,B,C,D) { int __i,__m; for (__i=0, __m=f2cmin((C),(D)); __i<__m && (B)[__i] != 0; ++__i) (A)[__i] = (B)[__i]; }
  226. #define sig_die(s, kill) { exit(1); }
  227. #define s_stop(s, n) {exit(0);}
  228. static char junk[] = "\n@(#)LIBF77 VERSION 19990503\n";
  229. #define z_abs(z) (cabs(Cd(z)))
  230. #define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));}
  231. #define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));}
  232. #define myexit_() break;
  233. #define mycycle() continue;
  234. #define myceiling(w) {ceil(w)}
  235. #define myhuge(w) {HUGE_VAL}
  236. //#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);}
  237. #define mymaxloc(w,s,e,n) {dmaxloc_(w,*(s),*(e),n)}
  238. /* procedure parameter types for -A and -C++ */
  239. #ifdef __cplusplus
  240. typedef logical (*L_fp)(...);
  241. #else
  242. typedef logical (*L_fp)();
  243. #endif
  244. static float spow_ui(float x, integer n) {
  245. float pow=1.0; unsigned long int u;
  246. if(n != 0) {
  247. if(n < 0) n = -n, x = 1/x;
  248. for(u = n; ; ) {
  249. if(u & 01) pow *= x;
  250. if(u >>= 1) x *= x;
  251. else break;
  252. }
  253. }
  254. return pow;
  255. }
  256. static double dpow_ui(double x, integer n) {
  257. double pow=1.0; unsigned long int u;
  258. if(n != 0) {
  259. if(n < 0) n = -n, x = 1/x;
  260. for(u = n; ; ) {
  261. if(u & 01) pow *= x;
  262. if(u >>= 1) x *= x;
  263. else break;
  264. }
  265. }
  266. return pow;
  267. }
  268. #ifdef _MSC_VER
  269. static _Fcomplex cpow_ui(complex x, integer n) {
  270. complex pow={1.0,0.0}; unsigned long int u;
  271. if(n != 0) {
  272. if(n < 0) n = -n, x.r = 1/x.r, x.i=1/x.i;
  273. for(u = n; ; ) {
  274. if(u & 01) pow.r *= x.r, pow.i *= x.i;
  275. if(u >>= 1) x.r *= x.r, x.i *= x.i;
  276. else break;
  277. }
  278. }
  279. _Fcomplex p={pow.r, pow.i};
  280. return p;
  281. }
  282. #else
  283. static _Complex float cpow_ui(_Complex float x, integer n) {
  284. _Complex float pow=1.0; unsigned long int u;
  285. if(n != 0) {
  286. if(n < 0) n = -n, x = 1/x;
  287. for(u = n; ; ) {
  288. if(u & 01) pow *= x;
  289. if(u >>= 1) x *= x;
  290. else break;
  291. }
  292. }
  293. return pow;
  294. }
  295. #endif
  296. #ifdef _MSC_VER
  297. static _Dcomplex zpow_ui(_Dcomplex x, integer n) {
  298. _Dcomplex pow={1.0,0.0}; unsigned long int u;
  299. if(n != 0) {
  300. if(n < 0) n = -n, x._Val[0] = 1/x._Val[0], x._Val[1] =1/x._Val[1];
  301. for(u = n; ; ) {
  302. if(u & 01) pow._Val[0] *= x._Val[0], pow._Val[1] *= x._Val[1];
  303. if(u >>= 1) x._Val[0] *= x._Val[0], x._Val[1] *= x._Val[1];
  304. else break;
  305. }
  306. }
  307. _Dcomplex p = {pow._Val[0], pow._Val[1]};
  308. return p;
  309. }
  310. #else
  311. static _Complex double zpow_ui(_Complex double x, integer n) {
  312. _Complex double pow=1.0; unsigned long int u;
  313. if(n != 0) {
  314. if(n < 0) n = -n, x = 1/x;
  315. for(u = n; ; ) {
  316. if(u & 01) pow *= x;
  317. if(u >>= 1) x *= x;
  318. else break;
  319. }
  320. }
  321. return pow;
  322. }
  323. #endif
  324. static integer pow_ii(integer x, integer n) {
  325. integer pow; unsigned long int u;
  326. if (n <= 0) {
  327. if (n == 0 || x == 1) pow = 1;
  328. else if (x != -1) pow = x == 0 ? 1/x : 0;
  329. else n = -n;
  330. }
  331. if ((n > 0) || !(n == 0 || x == 1 || x != -1)) {
  332. u = n;
  333. for(pow = 1; ; ) {
  334. if(u & 01) pow *= x;
  335. if(u >>= 1) x *= x;
  336. else break;
  337. }
  338. }
  339. return pow;
  340. }
  341. static integer dmaxloc_(double *w, integer s, integer e, integer *n)
  342. {
  343. double m; integer i, mi;
  344. for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
  345. if (w[i-1]>m) mi=i ,m=w[i-1];
  346. return mi-s+1;
  347. }
  348. static integer smaxloc_(float *w, integer s, integer e, integer *n)
  349. {
  350. float m; integer i, mi;
  351. for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
  352. if (w[i-1]>m) mi=i ,m=w[i-1];
  353. return mi-s+1;
  354. }
  355. static inline void cdotc_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
  356. integer n = *n_, incx = *incx_, incy = *incy_, i;
  357. #ifdef _MSC_VER
  358. _Fcomplex zdotc = {0.0, 0.0};
  359. if (incx == 1 && incy == 1) {
  360. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  361. zdotc._Val[0] += conjf(Cf(&x[i]))._Val[0] * Cf(&y[i])._Val[0];
  362. zdotc._Val[1] += conjf(Cf(&x[i]))._Val[1] * Cf(&y[i])._Val[1];
  363. }
  364. } else {
  365. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  366. zdotc._Val[0] += conjf(Cf(&x[i*incx]))._Val[0] * Cf(&y[i*incy])._Val[0];
  367. zdotc._Val[1] += conjf(Cf(&x[i*incx]))._Val[1] * Cf(&y[i*incy])._Val[1];
  368. }
  369. }
  370. pCf(z) = zdotc;
  371. }
  372. #else
  373. _Complex float zdotc = 0.0;
  374. if (incx == 1 && incy == 1) {
  375. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  376. zdotc += conjf(Cf(&x[i])) * Cf(&y[i]);
  377. }
  378. } else {
  379. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  380. zdotc += conjf(Cf(&x[i*incx])) * Cf(&y[i*incy]);
  381. }
  382. }
  383. pCf(z) = zdotc;
  384. }
  385. #endif
  386. static inline void zdotc_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
  387. integer n = *n_, incx = *incx_, incy = *incy_, i;
  388. #ifdef _MSC_VER
  389. _Dcomplex zdotc = {0.0, 0.0};
  390. if (incx == 1 && incy == 1) {
  391. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  392. zdotc._Val[0] += conj(Cd(&x[i]))._Val[0] * Cd(&y[i])._Val[0];
  393. zdotc._Val[1] += conj(Cd(&x[i]))._Val[1] * Cd(&y[i])._Val[1];
  394. }
  395. } else {
  396. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  397. zdotc._Val[0] += conj(Cd(&x[i*incx]))._Val[0] * Cd(&y[i*incy])._Val[0];
  398. zdotc._Val[1] += conj(Cd(&x[i*incx]))._Val[1] * Cd(&y[i*incy])._Val[1];
  399. }
  400. }
  401. pCd(z) = zdotc;
  402. }
  403. #else
  404. _Complex double zdotc = 0.0;
  405. if (incx == 1 && incy == 1) {
  406. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  407. zdotc += conj(Cd(&x[i])) * Cd(&y[i]);
  408. }
  409. } else {
  410. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  411. zdotc += conj(Cd(&x[i*incx])) * Cd(&y[i*incy]);
  412. }
  413. }
  414. pCd(z) = zdotc;
  415. }
  416. #endif
  417. static inline void cdotu_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
  418. integer n = *n_, incx = *incx_, incy = *incy_, i;
  419. #ifdef _MSC_VER
  420. _Fcomplex zdotc = {0.0, 0.0};
  421. if (incx == 1 && incy == 1) {
  422. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  423. zdotc._Val[0] += Cf(&x[i])._Val[0] * Cf(&y[i])._Val[0];
  424. zdotc._Val[1] += Cf(&x[i])._Val[1] * Cf(&y[i])._Val[1];
  425. }
  426. } else {
  427. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  428. zdotc._Val[0] += Cf(&x[i*incx])._Val[0] * Cf(&y[i*incy])._Val[0];
  429. zdotc._Val[1] += Cf(&x[i*incx])._Val[1] * Cf(&y[i*incy])._Val[1];
  430. }
  431. }
  432. pCf(z) = zdotc;
  433. }
  434. #else
  435. _Complex float zdotc = 0.0;
  436. if (incx == 1 && incy == 1) {
  437. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  438. zdotc += Cf(&x[i]) * Cf(&y[i]);
  439. }
  440. } else {
  441. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  442. zdotc += Cf(&x[i*incx]) * Cf(&y[i*incy]);
  443. }
  444. }
  445. pCf(z) = zdotc;
  446. }
  447. #endif
  448. static inline void zdotu_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
  449. integer n = *n_, incx = *incx_, incy = *incy_, i;
  450. #ifdef _MSC_VER
  451. _Dcomplex zdotc = {0.0, 0.0};
  452. if (incx == 1 && incy == 1) {
  453. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  454. zdotc._Val[0] += Cd(&x[i])._Val[0] * Cd(&y[i])._Val[0];
  455. zdotc._Val[1] += Cd(&x[i])._Val[1] * Cd(&y[i])._Val[1];
  456. }
  457. } else {
  458. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  459. zdotc._Val[0] += Cd(&x[i*incx])._Val[0] * Cd(&y[i*incy])._Val[0];
  460. zdotc._Val[1] += Cd(&x[i*incx])._Val[1] * Cd(&y[i*incy])._Val[1];
  461. }
  462. }
  463. pCd(z) = zdotc;
  464. }
  465. #else
  466. _Complex double zdotc = 0.0;
  467. if (incx == 1 && incy == 1) {
  468. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  469. zdotc += Cd(&x[i]) * Cd(&y[i]);
  470. }
  471. } else {
  472. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  473. zdotc += Cd(&x[i*incx]) * Cd(&y[i*incy]);
  474. }
  475. }
  476. pCd(z) = zdotc;
  477. }
  478. #endif
  479. /* -- translated by f2c (version 20000121).
  480. You must link the resulting object file with the libraries:
  481. -lf2c -lm (in that order)
  482. */
  483. /* Table of constant values */
  484. static complex c_b1 = {1.f,0.f};
  485. static complex c_b2 = {0.f,0.f};
  486. /* > \brief \b CHETRI_3X */
  487. /* =========== DOCUMENTATION =========== */
  488. /* Online html documentation available at */
  489. /* http://www.netlib.org/lapack/explore-html/ */
  490. /* > \htmlonly */
  491. /* > Download CHETRI_3X + dependencies */
  492. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/chetri_
  493. 3x.f"> */
  494. /* > [TGZ]</a> */
  495. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/chetri_
  496. 3x.f"> */
  497. /* > [ZIP]</a> */
  498. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/chetri_
  499. 3x.f"> */
  500. /* > [TXT]</a> */
  501. /* > \endhtmlonly */
  502. /* Definition: */
  503. /* =========== */
  504. /* SUBROUTINE CHETRI_3X( UPLO, N, A, LDA, E, IPIV, WORK, NB, INFO ) */
  505. /* CHARACTER UPLO */
  506. /* INTEGER INFO, LDA, N, NB */
  507. /* INTEGER IPIV( * ) */
  508. /* COMPLEX A( LDA, * ), E( * ), WORK( N+NB+1, * ) */
  509. /* > \par Purpose: */
  510. /* ============= */
  511. /* > */
  512. /* > \verbatim */
  513. /* > CHETRI_3X computes the inverse of a complex Hermitian indefinite */
  514. /* > matrix A using the factorization computed by CHETRF_RK or CHETRF_BK: */
  515. /* > */
  516. /* > A = P*U*D*(U**H)*(P**T) or A = P*L*D*(L**H)*(P**T), */
  517. /* > */
  518. /* > where U (or L) is unit upper (or lower) triangular matrix, */
  519. /* > U**H (or L**H) is the conjugate of U (or L), P is a permutation */
  520. /* > matrix, P**T is the transpose of P, and D is Hermitian and block */
  521. /* > diagonal with 1-by-1 and 2-by-2 diagonal blocks. */
  522. /* > */
  523. /* > This is the blocked version of the algorithm, calling Level 3 BLAS. */
  524. /* > \endverbatim */
  525. /* Arguments: */
  526. /* ========== */
  527. /* > \param[in] UPLO */
  528. /* > \verbatim */
  529. /* > UPLO is CHARACTER*1 */
  530. /* > Specifies whether the details of the factorization are */
  531. /* > stored as an upper or lower triangular matrix. */
  532. /* > = 'U': Upper triangle of A is stored; */
  533. /* > = 'L': Lower triangle of A is stored. */
  534. /* > \endverbatim */
  535. /* > */
  536. /* > \param[in] N */
  537. /* > \verbatim */
  538. /* > N is INTEGER */
  539. /* > The order of the matrix A. N >= 0. */
  540. /* > \endverbatim */
  541. /* > */
  542. /* > \param[in,out] A */
  543. /* > \verbatim */
  544. /* > A is COMPLEX array, dimension (LDA,N) */
  545. /* > On entry, diagonal of the block diagonal matrix D and */
  546. /* > factors U or L as computed by CHETRF_RK and CHETRF_BK: */
  547. /* > a) ONLY diagonal elements of the Hermitian block diagonal */
  548. /* > matrix D on the diagonal of A, i.e. D(k,k) = A(k,k); */
  549. /* > (superdiagonal (or subdiagonal) elements of D */
  550. /* > should be provided on entry in array E), and */
  551. /* > b) If UPLO = 'U': factor U in the superdiagonal part of A. */
  552. /* > If UPLO = 'L': factor L in the subdiagonal part of A. */
  553. /* > */
  554. /* > On exit, if INFO = 0, the Hermitian inverse of the original */
  555. /* > matrix. */
  556. /* > If UPLO = 'U': the upper triangular part of the inverse */
  557. /* > is formed and the part of A below the diagonal is not */
  558. /* > referenced; */
  559. /* > If UPLO = 'L': the lower triangular part of the inverse */
  560. /* > is formed and the part of A above the diagonal is not */
  561. /* > referenced. */
  562. /* > \endverbatim */
  563. /* > */
  564. /* > \param[in] LDA */
  565. /* > \verbatim */
  566. /* > LDA is INTEGER */
  567. /* > The leading dimension of the array A. LDA >= f2cmax(1,N). */
  568. /* > \endverbatim */
  569. /* > */
  570. /* > \param[in] E */
  571. /* > \verbatim */
  572. /* > E is COMPLEX array, dimension (N) */
  573. /* > On entry, contains the superdiagonal (or subdiagonal) */
  574. /* > elements of the Hermitian block diagonal matrix D */
  575. /* > with 1-by-1 or 2-by-2 diagonal blocks, where */
  576. /* > If UPLO = 'U': E(i) = D(i-1,i), i=2:N, E(1) not referenced; */
  577. /* > If UPLO = 'L': E(i) = D(i+1,i), i=1:N-1, E(N) not referenced. */
  578. /* > */
  579. /* > NOTE: For 1-by-1 diagonal block D(k), where */
  580. /* > 1 <= k <= N, the element E(k) is not referenced in both */
  581. /* > UPLO = 'U' or UPLO = 'L' cases. */
  582. /* > \endverbatim */
  583. /* > */
  584. /* > \param[in] IPIV */
  585. /* > \verbatim */
  586. /* > IPIV is INTEGER array, dimension (N) */
  587. /* > Details of the interchanges and the block structure of D */
  588. /* > as determined by CHETRF_RK or CHETRF_BK. */
  589. /* > \endverbatim */
  590. /* > */
  591. /* > \param[out] WORK */
  592. /* > \verbatim */
  593. /* > WORK is COMPLEX array, dimension (N+NB+1,NB+3). */
  594. /* > \endverbatim */
  595. /* > */
  596. /* > \param[in] NB */
  597. /* > \verbatim */
  598. /* > NB is INTEGER */
  599. /* > Block size. */
  600. /* > \endverbatim */
  601. /* > */
  602. /* > \param[out] INFO */
  603. /* > \verbatim */
  604. /* > INFO is INTEGER */
  605. /* > = 0: successful exit */
  606. /* > < 0: if INFO = -i, the i-th argument had an illegal value */
  607. /* > > 0: if INFO = i, D(i,i) = 0; the matrix is singular and its */
  608. /* > inverse could not be computed. */
  609. /* > \endverbatim */
  610. /* Authors: */
  611. /* ======== */
  612. /* > \author Univ. of Tennessee */
  613. /* > \author Univ. of California Berkeley */
  614. /* > \author Univ. of Colorado Denver */
  615. /* > \author NAG Ltd. */
  616. /* > \date June 2017 */
  617. /* > \ingroup complexHEcomputational */
  618. /* > \par Contributors: */
  619. /* ================== */
  620. /* > \verbatim */
  621. /* > */
  622. /* > June 2017, Igor Kozachenko, */
  623. /* > Computer Science Division, */
  624. /* > University of California, Berkeley */
  625. /* > */
  626. /* > \endverbatim */
  627. /* ===================================================================== */
  628. /* Subroutine */ void chetri_3x_(char *uplo, integer *n, complex *a, integer *
  629. lda, complex *e, integer *ipiv, complex *work, integer *nb, integer *
  630. info)
  631. {
  632. /* System generated locals */
  633. integer a_dim1, a_offset, work_dim1, work_offset, i__1, i__2, i__3, i__4,
  634. i__5, i__6;
  635. real r__1;
  636. complex q__1, q__2, q__3;
  637. /* Local variables */
  638. integer invd;
  639. extern /* Subroutine */ void cheswapr_(char *, integer *, complex *,
  640. integer *, integer *, integer *);
  641. complex akkp1, d__;
  642. integer i__, j, k;
  643. real t;
  644. extern /* Subroutine */ void cgemm_(char *, char *, integer *, integer *,
  645. integer *, complex *, complex *, integer *, complex *, integer *,
  646. complex *, complex *, integer *);
  647. extern logical lsame_(char *, char *);
  648. extern /* Subroutine */ void ctrmm_(char *, char *, char *, char *,
  649. integer *, integer *, complex *, complex *, integer *, complex *,
  650. integer *);
  651. logical upper;
  652. real ak;
  653. complex u01_i_j__;
  654. integer u11;
  655. complex u11_i_j__;
  656. integer ip;
  657. extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen);
  658. integer icount;
  659. extern /* Subroutine */ int ctrtri_(char *, char *, integer *, complex *,
  660. integer *, integer *);
  661. integer nnb, cut;
  662. real akp1;
  663. complex u01_ip1_j__, u11_ip1_j__;
  664. /* -- LAPACK computational routine (version 3.7.1) -- */
  665. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  666. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  667. /* June 2017 */
  668. /* ===================================================================== */
  669. /* Test the input parameters. */
  670. /* Parameter adjustments */
  671. a_dim1 = *lda;
  672. a_offset = 1 + a_dim1 * 1;
  673. a -= a_offset;
  674. --e;
  675. --ipiv;
  676. work_dim1 = *n + *nb + 1;
  677. work_offset = 1 + work_dim1 * 1;
  678. work -= work_offset;
  679. /* Function Body */
  680. *info = 0;
  681. upper = lsame_(uplo, "U");
  682. if (! upper && ! lsame_(uplo, "L")) {
  683. *info = -1;
  684. } else if (*n < 0) {
  685. *info = -2;
  686. } else if (*lda < f2cmax(1,*n)) {
  687. *info = -4;
  688. }
  689. /* Quick return if possible */
  690. if (*info != 0) {
  691. i__1 = -(*info);
  692. xerbla_("CHETRI_3X", &i__1, (ftnlen)9);
  693. return;
  694. }
  695. if (*n == 0) {
  696. return;
  697. }
  698. /* Workspace got Non-diag elements of D */
  699. i__1 = *n;
  700. for (k = 1; k <= i__1; ++k) {
  701. i__2 = k + work_dim1;
  702. i__3 = k;
  703. work[i__2].r = e[i__3].r, work[i__2].i = e[i__3].i;
  704. }
  705. /* Check that the diagonal matrix D is nonsingular. */
  706. if (upper) {
  707. /* Upper triangular storage: examine D from bottom to top */
  708. for (*info = *n; *info >= 1; --(*info)) {
  709. i__1 = *info + *info * a_dim1;
  710. if (ipiv[*info] > 0 && (a[i__1].r == 0.f && a[i__1].i == 0.f)) {
  711. return;
  712. }
  713. }
  714. } else {
  715. /* Lower triangular storage: examine D from top to bottom. */
  716. i__1 = *n;
  717. for (*info = 1; *info <= i__1; ++(*info)) {
  718. i__2 = *info + *info * a_dim1;
  719. if (ipiv[*info] > 0 && (a[i__2].r == 0.f && a[i__2].i == 0.f)) {
  720. return;
  721. }
  722. }
  723. }
  724. *info = 0;
  725. /* Splitting Workspace */
  726. /* U01 is a block ( N, NB+1 ) */
  727. /* The first element of U01 is in WORK( 1, 1 ) */
  728. /* U11 is a block ( NB+1, NB+1 ) */
  729. /* The first element of U11 is in WORK( N+1, 1 ) */
  730. u11 = *n;
  731. /* INVD is a block ( N, 2 ) */
  732. /* The first element of INVD is in WORK( 1, INVD ) */
  733. invd = *nb + 2;
  734. if (upper) {
  735. /* Begin Upper */
  736. /* invA = P * inv(U**H) * inv(D) * inv(U) * P**T. */
  737. ctrtri_(uplo, "U", n, &a[a_offset], lda, info);
  738. /* inv(D) and inv(D) * inv(U) */
  739. k = 1;
  740. while(k <= *n) {
  741. if (ipiv[k] > 0) {
  742. /* 1 x 1 diagonal NNB */
  743. i__1 = k + invd * work_dim1;
  744. i__2 = k + k * a_dim1;
  745. r__1 = 1.f / a[i__2].r;
  746. work[i__1].r = r__1, work[i__1].i = 0.f;
  747. i__1 = k + (invd + 1) * work_dim1;
  748. work[i__1].r = 0.f, work[i__1].i = 0.f;
  749. } else {
  750. /* 2 x 2 diagonal NNB */
  751. t = c_abs(&work[k + 1 + work_dim1]);
  752. i__1 = k + k * a_dim1;
  753. ak = a[i__1].r / t;
  754. i__1 = k + 1 + (k + 1) * a_dim1;
  755. akp1 = a[i__1].r / t;
  756. i__1 = k + 1 + work_dim1;
  757. q__1.r = work[i__1].r / t, q__1.i = work[i__1].i / t;
  758. akkp1.r = q__1.r, akkp1.i = q__1.i;
  759. r__1 = ak * akp1;
  760. q__2.r = r__1 - 1.f, q__2.i = 0.f;
  761. q__1.r = t * q__2.r, q__1.i = t * q__2.i;
  762. d__.r = q__1.r, d__.i = q__1.i;
  763. i__1 = k + invd * work_dim1;
  764. q__2.r = akp1, q__2.i = 0.f;
  765. c_div(&q__1, &q__2, &d__);
  766. work[i__1].r = q__1.r, work[i__1].i = q__1.i;
  767. i__1 = k + 1 + (invd + 1) * work_dim1;
  768. q__2.r = ak, q__2.i = 0.f;
  769. c_div(&q__1, &q__2, &d__);
  770. work[i__1].r = q__1.r, work[i__1].i = q__1.i;
  771. i__1 = k + (invd + 1) * work_dim1;
  772. q__2.r = -akkp1.r, q__2.i = -akkp1.i;
  773. c_div(&q__1, &q__2, &d__);
  774. work[i__1].r = q__1.r, work[i__1].i = q__1.i;
  775. i__1 = k + 1 + invd * work_dim1;
  776. r_cnjg(&q__1, &work[k + (invd + 1) * work_dim1]);
  777. work[i__1].r = q__1.r, work[i__1].i = q__1.i;
  778. ++k;
  779. }
  780. ++k;
  781. }
  782. /* inv(U**H) = (inv(U))**H */
  783. /* inv(U**H) * inv(D) * inv(U) */
  784. cut = *n;
  785. while(cut > 0) {
  786. nnb = *nb;
  787. if (cut <= nnb) {
  788. nnb = cut;
  789. } else {
  790. icount = 0;
  791. /* count negative elements, */
  792. i__1 = cut;
  793. for (i__ = cut + 1 - nnb; i__ <= i__1; ++i__) {
  794. if (ipiv[i__] < 0) {
  795. ++icount;
  796. }
  797. }
  798. /* need a even number for a clear cut */
  799. if (icount % 2 == 1) {
  800. ++nnb;
  801. }
  802. }
  803. cut -= nnb;
  804. /* U01 Block */
  805. i__1 = cut;
  806. for (i__ = 1; i__ <= i__1; ++i__) {
  807. i__2 = nnb;
  808. for (j = 1; j <= i__2; ++j) {
  809. i__3 = i__ + j * work_dim1;
  810. i__4 = i__ + (cut + j) * a_dim1;
  811. work[i__3].r = a[i__4].r, work[i__3].i = a[i__4].i;
  812. }
  813. }
  814. /* U11 Block */
  815. i__1 = nnb;
  816. for (i__ = 1; i__ <= i__1; ++i__) {
  817. i__2 = u11 + i__ + i__ * work_dim1;
  818. work[i__2].r = 1.f, work[i__2].i = 0.f;
  819. i__2 = i__ - 1;
  820. for (j = 1; j <= i__2; ++j) {
  821. i__3 = u11 + i__ + j * work_dim1;
  822. work[i__3].r = 0.f, work[i__3].i = 0.f;
  823. }
  824. i__2 = nnb;
  825. for (j = i__ + 1; j <= i__2; ++j) {
  826. i__3 = u11 + i__ + j * work_dim1;
  827. i__4 = cut + i__ + (cut + j) * a_dim1;
  828. work[i__3].r = a[i__4].r, work[i__3].i = a[i__4].i;
  829. }
  830. }
  831. /* invD * U01 */
  832. i__ = 1;
  833. while(i__ <= cut) {
  834. if (ipiv[i__] > 0) {
  835. i__1 = nnb;
  836. for (j = 1; j <= i__1; ++j) {
  837. i__2 = i__ + j * work_dim1;
  838. i__3 = i__ + invd * work_dim1;
  839. i__4 = i__ + j * work_dim1;
  840. q__1.r = work[i__3].r * work[i__4].r - work[i__3].i *
  841. work[i__4].i, q__1.i = work[i__3].r * work[
  842. i__4].i + work[i__3].i * work[i__4].r;
  843. work[i__2].r = q__1.r, work[i__2].i = q__1.i;
  844. }
  845. } else {
  846. i__1 = nnb;
  847. for (j = 1; j <= i__1; ++j) {
  848. i__2 = i__ + j * work_dim1;
  849. u01_i_j__.r = work[i__2].r, u01_i_j__.i = work[i__2]
  850. .i;
  851. i__2 = i__ + 1 + j * work_dim1;
  852. u01_ip1_j__.r = work[i__2].r, u01_ip1_j__.i = work[
  853. i__2].i;
  854. i__2 = i__ + j * work_dim1;
  855. i__3 = i__ + invd * work_dim1;
  856. q__2.r = work[i__3].r * u01_i_j__.r - work[i__3].i *
  857. u01_i_j__.i, q__2.i = work[i__3].r *
  858. u01_i_j__.i + work[i__3].i * u01_i_j__.r;
  859. i__4 = i__ + (invd + 1) * work_dim1;
  860. q__3.r = work[i__4].r * u01_ip1_j__.r - work[i__4].i *
  861. u01_ip1_j__.i, q__3.i = work[i__4].r *
  862. u01_ip1_j__.i + work[i__4].i * u01_ip1_j__.r;
  863. q__1.r = q__2.r + q__3.r, q__1.i = q__2.i + q__3.i;
  864. work[i__2].r = q__1.r, work[i__2].i = q__1.i;
  865. i__2 = i__ + 1 + j * work_dim1;
  866. i__3 = i__ + 1 + invd * work_dim1;
  867. q__2.r = work[i__3].r * u01_i_j__.r - work[i__3].i *
  868. u01_i_j__.i, q__2.i = work[i__3].r *
  869. u01_i_j__.i + work[i__3].i * u01_i_j__.r;
  870. i__4 = i__ + 1 + (invd + 1) * work_dim1;
  871. q__3.r = work[i__4].r * u01_ip1_j__.r - work[i__4].i *
  872. u01_ip1_j__.i, q__3.i = work[i__4].r *
  873. u01_ip1_j__.i + work[i__4].i * u01_ip1_j__.r;
  874. q__1.r = q__2.r + q__3.r, q__1.i = q__2.i + q__3.i;
  875. work[i__2].r = q__1.r, work[i__2].i = q__1.i;
  876. }
  877. ++i__;
  878. }
  879. ++i__;
  880. }
  881. /* invD1 * U11 */
  882. i__ = 1;
  883. while(i__ <= nnb) {
  884. if (ipiv[cut + i__] > 0) {
  885. i__1 = nnb;
  886. for (j = i__; j <= i__1; ++j) {
  887. i__2 = u11 + i__ + j * work_dim1;
  888. i__3 = cut + i__ + invd * work_dim1;
  889. i__4 = u11 + i__ + j * work_dim1;
  890. q__1.r = work[i__3].r * work[i__4].r - work[i__3].i *
  891. work[i__4].i, q__1.i = work[i__3].r * work[
  892. i__4].i + work[i__3].i * work[i__4].r;
  893. work[i__2].r = q__1.r, work[i__2].i = q__1.i;
  894. }
  895. } else {
  896. i__1 = nnb;
  897. for (j = i__; j <= i__1; ++j) {
  898. i__2 = u11 + i__ + j * work_dim1;
  899. u11_i_j__.r = work[i__2].r, u11_i_j__.i = work[i__2]
  900. .i;
  901. i__2 = u11 + i__ + 1 + j * work_dim1;
  902. u11_ip1_j__.r = work[i__2].r, u11_ip1_j__.i = work[
  903. i__2].i;
  904. i__2 = u11 + i__ + j * work_dim1;
  905. i__3 = cut + i__ + invd * work_dim1;
  906. i__4 = u11 + i__ + j * work_dim1;
  907. q__2.r = work[i__3].r * work[i__4].r - work[i__3].i *
  908. work[i__4].i, q__2.i = work[i__3].r * work[
  909. i__4].i + work[i__3].i * work[i__4].r;
  910. i__5 = cut + i__ + (invd + 1) * work_dim1;
  911. i__6 = u11 + i__ + 1 + j * work_dim1;
  912. q__3.r = work[i__5].r * work[i__6].r - work[i__5].i *
  913. work[i__6].i, q__3.i = work[i__5].r * work[
  914. i__6].i + work[i__5].i * work[i__6].r;
  915. q__1.r = q__2.r + q__3.r, q__1.i = q__2.i + q__3.i;
  916. work[i__2].r = q__1.r, work[i__2].i = q__1.i;
  917. i__2 = u11 + i__ + 1 + j * work_dim1;
  918. i__3 = cut + i__ + 1 + invd * work_dim1;
  919. q__2.r = work[i__3].r * u11_i_j__.r - work[i__3].i *
  920. u11_i_j__.i, q__2.i = work[i__3].r *
  921. u11_i_j__.i + work[i__3].i * u11_i_j__.r;
  922. i__4 = cut + i__ + 1 + (invd + 1) * work_dim1;
  923. q__3.r = work[i__4].r * u11_ip1_j__.r - work[i__4].i *
  924. u11_ip1_j__.i, q__3.i = work[i__4].r *
  925. u11_ip1_j__.i + work[i__4].i * u11_ip1_j__.r;
  926. q__1.r = q__2.r + q__3.r, q__1.i = q__2.i + q__3.i;
  927. work[i__2].r = q__1.r, work[i__2].i = q__1.i;
  928. }
  929. ++i__;
  930. }
  931. ++i__;
  932. }
  933. /* U11**H * invD1 * U11 -> U11 */
  934. i__1 = *n + *nb + 1;
  935. ctrmm_("L", "U", "C", "U", &nnb, &nnb, &c_b1, &a[cut + 1 + (cut +
  936. 1) * a_dim1], lda, &work[u11 + 1 + work_dim1], &i__1);
  937. i__1 = nnb;
  938. for (i__ = 1; i__ <= i__1; ++i__) {
  939. i__2 = nnb;
  940. for (j = i__; j <= i__2; ++j) {
  941. i__3 = cut + i__ + (cut + j) * a_dim1;
  942. i__4 = u11 + i__ + j * work_dim1;
  943. a[i__3].r = work[i__4].r, a[i__3].i = work[i__4].i;
  944. }
  945. }
  946. /* U01**H * invD * U01 -> A( CUT+I, CUT+J ) */
  947. i__1 = *n + *nb + 1;
  948. i__2 = *n + *nb + 1;
  949. cgemm_("C", "N", &nnb, &nnb, &cut, &c_b1, &a[(cut + 1) * a_dim1 +
  950. 1], lda, &work[work_offset], &i__1, &c_b2, &work[u11 + 1
  951. + work_dim1], &i__2);
  952. /* U11 = U11**H * invD1 * U11 + U01**H * invD * U01 */
  953. i__1 = nnb;
  954. for (i__ = 1; i__ <= i__1; ++i__) {
  955. i__2 = nnb;
  956. for (j = i__; j <= i__2; ++j) {
  957. i__3 = cut + i__ + (cut + j) * a_dim1;
  958. i__4 = cut + i__ + (cut + j) * a_dim1;
  959. i__5 = u11 + i__ + j * work_dim1;
  960. q__1.r = a[i__4].r + work[i__5].r, q__1.i = a[i__4].i +
  961. work[i__5].i;
  962. a[i__3].r = q__1.r, a[i__3].i = q__1.i;
  963. }
  964. }
  965. /* U01 = U00**H * invD0 * U01 */
  966. i__1 = *n + *nb + 1;
  967. ctrmm_("L", uplo, "C", "U", &cut, &nnb, &c_b1, &a[a_offset], lda,
  968. &work[work_offset], &i__1);
  969. /* Update U01 */
  970. i__1 = cut;
  971. for (i__ = 1; i__ <= i__1; ++i__) {
  972. i__2 = nnb;
  973. for (j = 1; j <= i__2; ++j) {
  974. i__3 = i__ + (cut + j) * a_dim1;
  975. i__4 = i__ + j * work_dim1;
  976. a[i__3].r = work[i__4].r, a[i__3].i = work[i__4].i;
  977. }
  978. }
  979. /* Next Block */
  980. }
  981. /* Apply PERMUTATIONS P and P**T: */
  982. /* P * inv(U**H) * inv(D) * inv(U) * P**T. */
  983. /* Interchange rows and columns I and IPIV(I) in reverse order */
  984. /* from the formation order of IPIV vector for Upper case. */
  985. /* ( We can use a loop over IPIV with increment 1, */
  986. /* since the ABS value of IPIV(I) represents the row (column) */
  987. /* index of the interchange with row (column) i in both 1x1 */
  988. /* and 2x2 pivot cases, i.e. we don't need separate code branches */
  989. /* for 1x1 and 2x2 pivot cases ) */
  990. i__1 = *n;
  991. for (i__ = 1; i__ <= i__1; ++i__) {
  992. ip = (i__2 = ipiv[i__], abs(i__2));
  993. if (ip != i__) {
  994. if (i__ < ip) {
  995. cheswapr_(uplo, n, &a[a_offset], lda, &i__, &ip);
  996. }
  997. if (i__ > ip) {
  998. cheswapr_(uplo, n, &a[a_offset], lda, &ip, &i__);
  999. }
  1000. }
  1001. }
  1002. } else {
  1003. /* Begin Lower */
  1004. /* inv A = P * inv(L**H) * inv(D) * inv(L) * P**T. */
  1005. ctrtri_(uplo, "U", n, &a[a_offset], lda, info);
  1006. /* inv(D) and inv(D) * inv(L) */
  1007. k = *n;
  1008. while(k >= 1) {
  1009. if (ipiv[k] > 0) {
  1010. /* 1 x 1 diagonal NNB */
  1011. i__1 = k + invd * work_dim1;
  1012. i__2 = k + k * a_dim1;
  1013. r__1 = 1.f / a[i__2].r;
  1014. work[i__1].r = r__1, work[i__1].i = 0.f;
  1015. i__1 = k + (invd + 1) * work_dim1;
  1016. work[i__1].r = 0.f, work[i__1].i = 0.f;
  1017. } else {
  1018. /* 2 x 2 diagonal NNB */
  1019. t = c_abs(&work[k - 1 + work_dim1]);
  1020. i__1 = k - 1 + (k - 1) * a_dim1;
  1021. ak = a[i__1].r / t;
  1022. i__1 = k + k * a_dim1;
  1023. akp1 = a[i__1].r / t;
  1024. i__1 = k - 1 + work_dim1;
  1025. q__1.r = work[i__1].r / t, q__1.i = work[i__1].i / t;
  1026. akkp1.r = q__1.r, akkp1.i = q__1.i;
  1027. r__1 = ak * akp1;
  1028. q__2.r = r__1 - 1.f, q__2.i = 0.f;
  1029. q__1.r = t * q__2.r, q__1.i = t * q__2.i;
  1030. d__.r = q__1.r, d__.i = q__1.i;
  1031. i__1 = k - 1 + invd * work_dim1;
  1032. q__2.r = akp1, q__2.i = 0.f;
  1033. c_div(&q__1, &q__2, &d__);
  1034. work[i__1].r = q__1.r, work[i__1].i = q__1.i;
  1035. i__1 = k + invd * work_dim1;
  1036. q__2.r = ak, q__2.i = 0.f;
  1037. c_div(&q__1, &q__2, &d__);
  1038. work[i__1].r = q__1.r, work[i__1].i = q__1.i;
  1039. i__1 = k + (invd + 1) * work_dim1;
  1040. q__2.r = -akkp1.r, q__2.i = -akkp1.i;
  1041. c_div(&q__1, &q__2, &d__);
  1042. work[i__1].r = q__1.r, work[i__1].i = q__1.i;
  1043. i__1 = k - 1 + (invd + 1) * work_dim1;
  1044. r_cnjg(&q__1, &work[k + (invd + 1) * work_dim1]);
  1045. work[i__1].r = q__1.r, work[i__1].i = q__1.i;
  1046. --k;
  1047. }
  1048. --k;
  1049. }
  1050. /* inv(L**H) = (inv(L))**H */
  1051. /* inv(L**H) * inv(D) * inv(L) */
  1052. cut = 0;
  1053. while(cut < *n) {
  1054. nnb = *nb;
  1055. if (cut + nnb > *n) {
  1056. nnb = *n - cut;
  1057. } else {
  1058. icount = 0;
  1059. /* count negative elements, */
  1060. i__1 = cut + nnb;
  1061. for (i__ = cut + 1; i__ <= i__1; ++i__) {
  1062. if (ipiv[i__] < 0) {
  1063. ++icount;
  1064. }
  1065. }
  1066. /* need a even number for a clear cut */
  1067. if (icount % 2 == 1) {
  1068. ++nnb;
  1069. }
  1070. }
  1071. /* L21 Block */
  1072. i__1 = *n - cut - nnb;
  1073. for (i__ = 1; i__ <= i__1; ++i__) {
  1074. i__2 = nnb;
  1075. for (j = 1; j <= i__2; ++j) {
  1076. i__3 = i__ + j * work_dim1;
  1077. i__4 = cut + nnb + i__ + (cut + j) * a_dim1;
  1078. work[i__3].r = a[i__4].r, work[i__3].i = a[i__4].i;
  1079. }
  1080. }
  1081. /* L11 Block */
  1082. i__1 = nnb;
  1083. for (i__ = 1; i__ <= i__1; ++i__) {
  1084. i__2 = u11 + i__ + i__ * work_dim1;
  1085. work[i__2].r = 1.f, work[i__2].i = 0.f;
  1086. i__2 = nnb;
  1087. for (j = i__ + 1; j <= i__2; ++j) {
  1088. i__3 = u11 + i__ + j * work_dim1;
  1089. work[i__3].r = 0.f, work[i__3].i = 0.f;
  1090. }
  1091. i__2 = i__ - 1;
  1092. for (j = 1; j <= i__2; ++j) {
  1093. i__3 = u11 + i__ + j * work_dim1;
  1094. i__4 = cut + i__ + (cut + j) * a_dim1;
  1095. work[i__3].r = a[i__4].r, work[i__3].i = a[i__4].i;
  1096. }
  1097. }
  1098. /* invD*L21 */
  1099. i__ = *n - cut - nnb;
  1100. while(i__ >= 1) {
  1101. if (ipiv[cut + nnb + i__] > 0) {
  1102. i__1 = nnb;
  1103. for (j = 1; j <= i__1; ++j) {
  1104. i__2 = i__ + j * work_dim1;
  1105. i__3 = cut + nnb + i__ + invd * work_dim1;
  1106. i__4 = i__ + j * work_dim1;
  1107. q__1.r = work[i__3].r * work[i__4].r - work[i__3].i *
  1108. work[i__4].i, q__1.i = work[i__3].r * work[
  1109. i__4].i + work[i__3].i * work[i__4].r;
  1110. work[i__2].r = q__1.r, work[i__2].i = q__1.i;
  1111. }
  1112. } else {
  1113. i__1 = nnb;
  1114. for (j = 1; j <= i__1; ++j) {
  1115. i__2 = i__ + j * work_dim1;
  1116. u01_i_j__.r = work[i__2].r, u01_i_j__.i = work[i__2]
  1117. .i;
  1118. i__2 = i__ - 1 + j * work_dim1;
  1119. u01_ip1_j__.r = work[i__2].r, u01_ip1_j__.i = work[
  1120. i__2].i;
  1121. i__2 = i__ + j * work_dim1;
  1122. i__3 = cut + nnb + i__ + invd * work_dim1;
  1123. q__2.r = work[i__3].r * u01_i_j__.r - work[i__3].i *
  1124. u01_i_j__.i, q__2.i = work[i__3].r *
  1125. u01_i_j__.i + work[i__3].i * u01_i_j__.r;
  1126. i__4 = cut + nnb + i__ + (invd + 1) * work_dim1;
  1127. q__3.r = work[i__4].r * u01_ip1_j__.r - work[i__4].i *
  1128. u01_ip1_j__.i, q__3.i = work[i__4].r *
  1129. u01_ip1_j__.i + work[i__4].i * u01_ip1_j__.r;
  1130. q__1.r = q__2.r + q__3.r, q__1.i = q__2.i + q__3.i;
  1131. work[i__2].r = q__1.r, work[i__2].i = q__1.i;
  1132. i__2 = i__ - 1 + j * work_dim1;
  1133. i__3 = cut + nnb + i__ - 1 + (invd + 1) * work_dim1;
  1134. q__2.r = work[i__3].r * u01_i_j__.r - work[i__3].i *
  1135. u01_i_j__.i, q__2.i = work[i__3].r *
  1136. u01_i_j__.i + work[i__3].i * u01_i_j__.r;
  1137. i__4 = cut + nnb + i__ - 1 + invd * work_dim1;
  1138. q__3.r = work[i__4].r * u01_ip1_j__.r - work[i__4].i *
  1139. u01_ip1_j__.i, q__3.i = work[i__4].r *
  1140. u01_ip1_j__.i + work[i__4].i * u01_ip1_j__.r;
  1141. q__1.r = q__2.r + q__3.r, q__1.i = q__2.i + q__3.i;
  1142. work[i__2].r = q__1.r, work[i__2].i = q__1.i;
  1143. }
  1144. --i__;
  1145. }
  1146. --i__;
  1147. }
  1148. /* invD1*L11 */
  1149. i__ = nnb;
  1150. while(i__ >= 1) {
  1151. if (ipiv[cut + i__] > 0) {
  1152. i__1 = nnb;
  1153. for (j = 1; j <= i__1; ++j) {
  1154. i__2 = u11 + i__ + j * work_dim1;
  1155. i__3 = cut + i__ + invd * work_dim1;
  1156. i__4 = u11 + i__ + j * work_dim1;
  1157. q__1.r = work[i__3].r * work[i__4].r - work[i__3].i *
  1158. work[i__4].i, q__1.i = work[i__3].r * work[
  1159. i__4].i + work[i__3].i * work[i__4].r;
  1160. work[i__2].r = q__1.r, work[i__2].i = q__1.i;
  1161. }
  1162. } else {
  1163. i__1 = nnb;
  1164. for (j = 1; j <= i__1; ++j) {
  1165. i__2 = u11 + i__ + j * work_dim1;
  1166. u11_i_j__.r = work[i__2].r, u11_i_j__.i = work[i__2]
  1167. .i;
  1168. i__2 = u11 + i__ - 1 + j * work_dim1;
  1169. u11_ip1_j__.r = work[i__2].r, u11_ip1_j__.i = work[
  1170. i__2].i;
  1171. i__2 = u11 + i__ + j * work_dim1;
  1172. i__3 = cut + i__ + invd * work_dim1;
  1173. i__4 = u11 + i__ + j * work_dim1;
  1174. q__2.r = work[i__3].r * work[i__4].r - work[i__3].i *
  1175. work[i__4].i, q__2.i = work[i__3].r * work[
  1176. i__4].i + work[i__3].i * work[i__4].r;
  1177. i__5 = cut + i__ + (invd + 1) * work_dim1;
  1178. q__3.r = work[i__5].r * u11_ip1_j__.r - work[i__5].i *
  1179. u11_ip1_j__.i, q__3.i = work[i__5].r *
  1180. u11_ip1_j__.i + work[i__5].i * u11_ip1_j__.r;
  1181. q__1.r = q__2.r + q__3.r, q__1.i = q__2.i + q__3.i;
  1182. work[i__2].r = q__1.r, work[i__2].i = q__1.i;
  1183. i__2 = u11 + i__ - 1 + j * work_dim1;
  1184. i__3 = cut + i__ - 1 + (invd + 1) * work_dim1;
  1185. q__2.r = work[i__3].r * u11_i_j__.r - work[i__3].i *
  1186. u11_i_j__.i, q__2.i = work[i__3].r *
  1187. u11_i_j__.i + work[i__3].i * u11_i_j__.r;
  1188. i__4 = cut + i__ - 1 + invd * work_dim1;
  1189. q__3.r = work[i__4].r * u11_ip1_j__.r - work[i__4].i *
  1190. u11_ip1_j__.i, q__3.i = work[i__4].r *
  1191. u11_ip1_j__.i + work[i__4].i * u11_ip1_j__.r;
  1192. q__1.r = q__2.r + q__3.r, q__1.i = q__2.i + q__3.i;
  1193. work[i__2].r = q__1.r, work[i__2].i = q__1.i;
  1194. }
  1195. --i__;
  1196. }
  1197. --i__;
  1198. }
  1199. /* L11**H * invD1 * L11 -> L11 */
  1200. i__1 = *n + *nb + 1;
  1201. ctrmm_("L", uplo, "C", "U", &nnb, &nnb, &c_b1, &a[cut + 1 + (cut
  1202. + 1) * a_dim1], lda, &work[u11 + 1 + work_dim1], &i__1);
  1203. i__1 = nnb;
  1204. for (i__ = 1; i__ <= i__1; ++i__) {
  1205. i__2 = i__;
  1206. for (j = 1; j <= i__2; ++j) {
  1207. i__3 = cut + i__ + (cut + j) * a_dim1;
  1208. i__4 = u11 + i__ + j * work_dim1;
  1209. a[i__3].r = work[i__4].r, a[i__3].i = work[i__4].i;
  1210. }
  1211. }
  1212. if (cut + nnb < *n) {
  1213. /* L21**H * invD2*L21 -> A( CUT+I, CUT+J ) */
  1214. i__1 = *n - nnb - cut;
  1215. i__2 = *n + *nb + 1;
  1216. i__3 = *n + *nb + 1;
  1217. cgemm_("C", "N", &nnb, &nnb, &i__1, &c_b1, &a[cut + nnb + 1 +
  1218. (cut + 1) * a_dim1], lda, &work[work_offset], &i__2, &
  1219. c_b2, &work[u11 + 1 + work_dim1], &i__3);
  1220. /* L11 = L11**H * invD1 * L11 + U01**H * invD * U01 */
  1221. i__1 = nnb;
  1222. for (i__ = 1; i__ <= i__1; ++i__) {
  1223. i__2 = i__;
  1224. for (j = 1; j <= i__2; ++j) {
  1225. i__3 = cut + i__ + (cut + j) * a_dim1;
  1226. i__4 = cut + i__ + (cut + j) * a_dim1;
  1227. i__5 = u11 + i__ + j * work_dim1;
  1228. q__1.r = a[i__4].r + work[i__5].r, q__1.i = a[i__4].i
  1229. + work[i__5].i;
  1230. a[i__3].r = q__1.r, a[i__3].i = q__1.i;
  1231. }
  1232. }
  1233. /* L01 = L22**H * invD2 * L21 */
  1234. i__1 = *n - nnb - cut;
  1235. i__2 = *n + *nb + 1;
  1236. ctrmm_("L", uplo, "C", "U", &i__1, &nnb, &c_b1, &a[cut + nnb
  1237. + 1 + (cut + nnb + 1) * a_dim1], lda, &work[
  1238. work_offset], &i__2);
  1239. /* Update L21 */
  1240. i__1 = *n - cut - nnb;
  1241. for (i__ = 1; i__ <= i__1; ++i__) {
  1242. i__2 = nnb;
  1243. for (j = 1; j <= i__2; ++j) {
  1244. i__3 = cut + nnb + i__ + (cut + j) * a_dim1;
  1245. i__4 = i__ + j * work_dim1;
  1246. a[i__3].r = work[i__4].r, a[i__3].i = work[i__4].i;
  1247. }
  1248. }
  1249. } else {
  1250. /* L11 = L11**H * invD1 * L11 */
  1251. i__1 = nnb;
  1252. for (i__ = 1; i__ <= i__1; ++i__) {
  1253. i__2 = i__;
  1254. for (j = 1; j <= i__2; ++j) {
  1255. i__3 = cut + i__ + (cut + j) * a_dim1;
  1256. i__4 = u11 + i__ + j * work_dim1;
  1257. a[i__3].r = work[i__4].r, a[i__3].i = work[i__4].i;
  1258. }
  1259. }
  1260. }
  1261. /* Next Block */
  1262. cut += nnb;
  1263. }
  1264. /* Apply PERMUTATIONS P and P**T: */
  1265. /* P * inv(L**H) * inv(D) * inv(L) * P**T. */
  1266. /* Interchange rows and columns I and IPIV(I) in reverse order */
  1267. /* from the formation order of IPIV vector for Lower case. */
  1268. /* ( We can use a loop over IPIV with increment -1, */
  1269. /* since the ABS value of IPIV(I) represents the row (column) */
  1270. /* index of the interchange with row (column) i in both 1x1 */
  1271. /* and 2x2 pivot cases, i.e. we don't need separate code branches */
  1272. /* for 1x1 and 2x2 pivot cases ) */
  1273. for (i__ = *n; i__ >= 1; --i__) {
  1274. ip = (i__1 = ipiv[i__], abs(i__1));
  1275. if (ip != i__) {
  1276. if (i__ < ip) {
  1277. cheswapr_(uplo, n, &a[a_offset], lda, &i__, &ip);
  1278. }
  1279. if (i__ > ip) {
  1280. cheswapr_(uplo, n, &a[a_offset], lda, &ip, &i__);
  1281. }
  1282. }
  1283. }
  1284. }
  1285. return;
  1286. /* End of CHETRI_3X */
  1287. } /* chetri_3x__ */