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.

zhetf2.c 36 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262
  1. /* f2c.h -- Standard Fortran to C header file */
  2. /** barf [ba:rf] 2. "He suggested using FORTRAN, and everybody barfed."
  3. - From The Shogakukan DICTIONARY OF NEW ENGLISH (Second edition) */
  4. #ifndef F2C_INCLUDE
  5. #define F2C_INCLUDE
  6. #include <math.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9. #include <stdio.h>
  10. #include <complex.h>
  11. #ifdef complex
  12. #undef complex
  13. #endif
  14. #ifdef I
  15. #undef I
  16. #endif
  17. typedef int integer;
  18. typedef unsigned int uinteger;
  19. typedef char *address;
  20. typedef short int shortint;
  21. typedef float real;
  22. typedef double doublereal;
  23. typedef struct { real r, i; } complex;
  24. typedef struct { doublereal r, i; } doublecomplex;
  25. static inline _Complex float Cf(complex *z) {return z->r + z->i*_Complex_I;}
  26. static inline _Complex double Cd(doublecomplex *z) {return z->r + z->i*_Complex_I;}
  27. static inline _Complex float * _pCf(complex *z) {return (_Complex float*)z;}
  28. static inline _Complex double * _pCd(doublecomplex *z) {return (_Complex double*)z;}
  29. #define pCf(z) (*_pCf(z))
  30. #define pCd(z) (*_pCd(z))
  31. typedef int logical;
  32. typedef short int shortlogical;
  33. typedef char logical1;
  34. typedef char integer1;
  35. #define TRUE_ (1)
  36. #define FALSE_ (0)
  37. /* Extern is for use with -E */
  38. #ifndef Extern
  39. #define Extern extern
  40. #endif
  41. /* I/O stuff */
  42. typedef int flag;
  43. typedef int ftnlen;
  44. typedef int ftnint;
  45. /*external read, write*/
  46. typedef struct
  47. { flag cierr;
  48. ftnint ciunit;
  49. flag ciend;
  50. char *cifmt;
  51. ftnint cirec;
  52. } cilist;
  53. /*internal read, write*/
  54. typedef struct
  55. { flag icierr;
  56. char *iciunit;
  57. flag iciend;
  58. char *icifmt;
  59. ftnint icirlen;
  60. ftnint icirnum;
  61. } icilist;
  62. /*open*/
  63. typedef struct
  64. { flag oerr;
  65. ftnint ounit;
  66. char *ofnm;
  67. ftnlen ofnmlen;
  68. char *osta;
  69. char *oacc;
  70. char *ofm;
  71. ftnint orl;
  72. char *oblnk;
  73. } olist;
  74. /*close*/
  75. typedef struct
  76. { flag cerr;
  77. ftnint cunit;
  78. char *csta;
  79. } cllist;
  80. /*rewind, backspace, endfile*/
  81. typedef struct
  82. { flag aerr;
  83. ftnint aunit;
  84. } alist;
  85. /* inquire */
  86. typedef struct
  87. { flag inerr;
  88. ftnint inunit;
  89. char *infile;
  90. ftnlen infilen;
  91. ftnint *inex; /*parameters in standard's order*/
  92. ftnint *inopen;
  93. ftnint *innum;
  94. ftnint *innamed;
  95. char *inname;
  96. ftnlen innamlen;
  97. char *inacc;
  98. ftnlen inacclen;
  99. char *inseq;
  100. ftnlen inseqlen;
  101. char *indir;
  102. ftnlen indirlen;
  103. char *infmt;
  104. ftnlen infmtlen;
  105. char *inform;
  106. ftnint informlen;
  107. char *inunf;
  108. ftnlen inunflen;
  109. ftnint *inrecl;
  110. ftnint *innrec;
  111. char *inblank;
  112. ftnlen inblanklen;
  113. } inlist;
  114. #define VOID void
  115. union Multitype { /* for multiple entry points */
  116. integer1 g;
  117. shortint h;
  118. integer i;
  119. /* longint j; */
  120. real r;
  121. doublereal d;
  122. complex c;
  123. doublecomplex z;
  124. };
  125. typedef union Multitype Multitype;
  126. struct Vardesc { /* for Namelist */
  127. char *name;
  128. char *addr;
  129. ftnlen *dims;
  130. int type;
  131. };
  132. typedef struct Vardesc Vardesc;
  133. struct Namelist {
  134. char *name;
  135. Vardesc **vars;
  136. int nvars;
  137. };
  138. typedef struct Namelist Namelist;
  139. #define abs(x) ((x) >= 0 ? (x) : -(x))
  140. #define dabs(x) (fabs(x))
  141. #define f2cmin(a,b) ((a) <= (b) ? (a) : (b))
  142. #define f2cmax(a,b) ((a) >= (b) ? (a) : (b))
  143. #define dmin(a,b) (f2cmin(a,b))
  144. #define dmax(a,b) (f2cmax(a,b))
  145. #define bit_test(a,b) ((a) >> (b) & 1)
  146. #define bit_clear(a,b) ((a) & ~((uinteger)1 << (b)))
  147. #define bit_set(a,b) ((a) | ((uinteger)1 << (b)))
  148. #define abort_() { sig_die("Fortran abort routine called", 1); }
  149. #define c_abs(z) (cabsf(Cf(z)))
  150. #define c_cos(R,Z) { pCf(R)=ccos(Cf(Z)); }
  151. #define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);}
  152. #define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);}
  153. #define c_exp(R, Z) {pCf(R) = cexpf(Cf(Z));}
  154. #define c_log(R, Z) {pCf(R) = clogf(Cf(Z));}
  155. #define c_sin(R, Z) {pCf(R) = csinf(Cf(Z));}
  156. //#define c_sqrt(R, Z) {*(R) = csqrtf(Cf(Z));}
  157. #define c_sqrt(R, Z) {pCf(R) = csqrtf(Cf(Z));}
  158. #define d_abs(x) (fabs(*(x)))
  159. #define d_acos(x) (acos(*(x)))
  160. #define d_asin(x) (asin(*(x)))
  161. #define d_atan(x) (atan(*(x)))
  162. #define d_atn2(x, y) (atan2(*(x),*(y)))
  163. #define d_cnjg(R, Z) { pCd(R) = conj(Cd(Z)); }
  164. #define r_cnjg(R, Z) { pCf(R) = conj(Cf(Z)); }
  165. #define d_cos(x) (cos(*(x)))
  166. #define d_cosh(x) (cosh(*(x)))
  167. #define d_dim(__a, __b) ( *(__a) > *(__b) ? *(__a) - *(__b) : 0.0 )
  168. #define d_exp(x) (exp(*(x)))
  169. #define d_imag(z) (cimag(Cd(z)))
  170. #define r_imag(z) (cimag(Cf(z)))
  171. #define d_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  172. #define r_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  173. #define d_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  174. #define r_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  175. #define d_log(x) (log(*(x)))
  176. #define d_mod(x, y) (fmod(*(x), *(y)))
  177. #define u_nint(__x) ((__x)>=0 ? floor((__x) + .5) : -floor(.5 - (__x)))
  178. #define d_nint(x) u_nint(*(x))
  179. #define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a)))
  180. #define d_sign(a,b) u_sign(*(a),*(b))
  181. #define r_sign(a,b) u_sign(*(a),*(b))
  182. #define d_sin(x) (sin(*(x)))
  183. #define d_sinh(x) (sinh(*(x)))
  184. #define d_sqrt(x) (sqrt(*(x)))
  185. #define d_tan(x) (tan(*(x)))
  186. #define d_tanh(x) (tanh(*(x)))
  187. #define i_abs(x) abs(*(x))
  188. #define i_dnnt(x) ((integer)u_nint(*(x)))
  189. #define i_len(s, n) (n)
  190. #define i_nint(x) ((integer)u_nint(*(x)))
  191. #define i_sign(a,b) ((integer)u_sign((integer)*(a),(integer)*(b)))
  192. #define pow_dd(ap, bp) ( pow(*(ap), *(bp)))
  193. #define pow_si(B,E) spow_ui(*(B),*(E))
  194. #define pow_ri(B,E) spow_ui(*(B),*(E))
  195. #define pow_di(B,E) dpow_ui(*(B),*(E))
  196. #define pow_zi(p, a, b) {pCd(p) = zpow_ui(Cd(a), *(b));}
  197. #define pow_ci(p, a, b) {pCf(p) = cpow_ui(Cf(a), *(b));}
  198. #define pow_zz(R,A,B) {pCd(R) = cpow(Cd(A),*(B));}
  199. #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++ = ' '; }
  200. #define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d))))
  201. #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]; }
  202. #define sig_die(s, kill) { exit(1); }
  203. #define s_stop(s, n) {exit(0);}
  204. static char junk[] = "\n@(#)LIBF77 VERSION 19990503\n";
  205. #define z_abs(z) (cabs(Cd(z)))
  206. #define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));}
  207. #define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));}
  208. #define myexit_() break;
  209. #define mycycle() continue;
  210. #define myceiling(w) {ceil(w)}
  211. #define myhuge(w) {HUGE_VAL}
  212. //#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);}
  213. #define mymaxloc(w,s,e,n) {dmaxloc_(w,*(s),*(e),n)}
  214. /* procedure parameter types for -A and -C++ */
  215. #define F2C_proc_par_types 1
  216. #ifdef __cplusplus
  217. typedef logical (*L_fp)(...);
  218. #else
  219. typedef logical (*L_fp)();
  220. #endif
  221. static float spow_ui(float x, integer n) {
  222. float pow=1.0; unsigned long int u;
  223. if(n != 0) {
  224. if(n < 0) n = -n, x = 1/x;
  225. for(u = n; ; ) {
  226. if(u & 01) pow *= x;
  227. if(u >>= 1) x *= x;
  228. else break;
  229. }
  230. }
  231. return pow;
  232. }
  233. static double dpow_ui(double x, integer n) {
  234. double pow=1.0; unsigned long int u;
  235. if(n != 0) {
  236. if(n < 0) n = -n, x = 1/x;
  237. for(u = n; ; ) {
  238. if(u & 01) pow *= x;
  239. if(u >>= 1) x *= x;
  240. else break;
  241. }
  242. }
  243. return pow;
  244. }
  245. static _Complex float cpow_ui(_Complex float x, integer n) {
  246. _Complex float pow=1.0; unsigned long int u;
  247. if(n != 0) {
  248. if(n < 0) n = -n, x = 1/x;
  249. for(u = n; ; ) {
  250. if(u & 01) pow *= x;
  251. if(u >>= 1) x *= x;
  252. else break;
  253. }
  254. }
  255. return pow;
  256. }
  257. static _Complex double zpow_ui(_Complex double x, integer n) {
  258. _Complex double pow=1.0; unsigned long int u;
  259. if(n != 0) {
  260. if(n < 0) n = -n, x = 1/x;
  261. for(u = n; ; ) {
  262. if(u & 01) pow *= x;
  263. if(u >>= 1) x *= x;
  264. else break;
  265. }
  266. }
  267. return pow;
  268. }
  269. static integer pow_ii(integer x, integer n) {
  270. integer pow; unsigned long int u;
  271. if (n <= 0) {
  272. if (n == 0 || x == 1) pow = 1;
  273. else if (x != -1) pow = x == 0 ? 1/x : 0;
  274. else n = -n;
  275. }
  276. if ((n > 0) || !(n == 0 || x == 1 || x != -1)) {
  277. u = n;
  278. for(pow = 1; ; ) {
  279. if(u & 01) pow *= x;
  280. if(u >>= 1) x *= x;
  281. else break;
  282. }
  283. }
  284. return pow;
  285. }
  286. static integer dmaxloc_(double *w, integer s, integer e, integer *n)
  287. {
  288. double m; integer i, mi;
  289. for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
  290. if (w[i-1]>m) mi=i ,m=w[i-1];
  291. return mi-s+1;
  292. }
  293. static integer smaxloc_(float *w, integer s, integer e, integer *n)
  294. {
  295. float m; integer i, mi;
  296. for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
  297. if (w[i-1]>m) mi=i ,m=w[i-1];
  298. return mi-s+1;
  299. }
  300. static inline void cdotc_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
  301. integer n = *n_, incx = *incx_, incy = *incy_, i;
  302. _Complex float zdotc = 0.0;
  303. if (incx == 1 && incy == 1) {
  304. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  305. zdotc += conjf(Cf(&x[i])) * Cf(&y[i]);
  306. }
  307. } else {
  308. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  309. zdotc += conjf(Cf(&x[i*incx])) * Cf(&y[i*incy]);
  310. }
  311. }
  312. pCf(z) = zdotc;
  313. }
  314. static inline void zdotc_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
  315. integer n = *n_, incx = *incx_, incy = *incy_, i;
  316. _Complex double zdotc = 0.0;
  317. if (incx == 1 && incy == 1) {
  318. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  319. zdotc += conj(Cd(&x[i])) * Cd(&y[i]);
  320. }
  321. } else {
  322. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  323. zdotc += conj(Cd(&x[i*incx])) * Cd(&y[i*incy]);
  324. }
  325. }
  326. pCd(z) = zdotc;
  327. }
  328. static inline void cdotu_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
  329. integer n = *n_, incx = *incx_, incy = *incy_, i;
  330. _Complex float zdotc = 0.0;
  331. if (incx == 1 && incy == 1) {
  332. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  333. zdotc += Cf(&x[i]) * Cf(&y[i]);
  334. }
  335. } else {
  336. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  337. zdotc += Cf(&x[i*incx]) * Cf(&y[i*incy]);
  338. }
  339. }
  340. pCf(z) = zdotc;
  341. }
  342. static inline void zdotu_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
  343. integer n = *n_, incx = *incx_, incy = *incy_, i;
  344. _Complex double zdotc = 0.0;
  345. if (incx == 1 && incy == 1) {
  346. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  347. zdotc += Cd(&x[i]) * Cd(&y[i]);
  348. }
  349. } else {
  350. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  351. zdotc += Cd(&x[i*incx]) * Cd(&y[i*incy]);
  352. }
  353. }
  354. pCd(z) = zdotc;
  355. }
  356. #endif
  357. /* -- translated by f2c (version 20000121).
  358. You must link the resulting object file with the libraries:
  359. -lf2c -lm (in that order)
  360. */
  361. /* Table of constant values */
  362. static integer c__1 = 1;
  363. /* > \brief \b ZHETF2 computes the factorization of a complex Hermitian matrix, using the diagonal pivoting me
  364. thod (unblocked algorithm, calling Level 2 BLAS). */
  365. /* =========== DOCUMENTATION =========== */
  366. /* Online html documentation available at */
  367. /* http://www.netlib.org/lapack/explore-html/ */
  368. /* > \htmlonly */
  369. /* > Download ZHETF2 + dependencies */
  370. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zhetf2.
  371. f"> */
  372. /* > [TGZ]</a> */
  373. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zhetf2.
  374. f"> */
  375. /* > [ZIP]</a> */
  376. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zhetf2.
  377. f"> */
  378. /* > [TXT]</a> */
  379. /* > \endhtmlonly */
  380. /* Definition: */
  381. /* =========== */
  382. /* SUBROUTINE ZHETF2( UPLO, N, A, LDA, IPIV, INFO ) */
  383. /* CHARACTER UPLO */
  384. /* INTEGER INFO, LDA, N */
  385. /* INTEGER IPIV( * ) */
  386. /* COMPLEX*16 A( LDA, * ) */
  387. /* > \par Purpose: */
  388. /* ============= */
  389. /* > */
  390. /* > \verbatim */
  391. /* > */
  392. /* > ZHETF2 computes the factorization of a complex Hermitian matrix A */
  393. /* > using the Bunch-Kaufman diagonal pivoting method: */
  394. /* > */
  395. /* > A = U*D*U**H or A = L*D*L**H */
  396. /* > */
  397. /* > where U (or L) is a product of permutation and unit upper (lower) */
  398. /* > triangular matrices, U**H is the conjugate transpose of U, and D is */
  399. /* > Hermitian and block diagonal with 1-by-1 and 2-by-2 diagonal blocks. */
  400. /* > */
  401. /* > This is the unblocked version of the algorithm, calling Level 2 BLAS. */
  402. /* > \endverbatim */
  403. /* Arguments: */
  404. /* ========== */
  405. /* > \param[in] UPLO */
  406. /* > \verbatim */
  407. /* > UPLO is CHARACTER*1 */
  408. /* > Specifies whether the upper or lower triangular part of the */
  409. /* > Hermitian matrix A is stored: */
  410. /* > = 'U': Upper triangular */
  411. /* > = 'L': Lower triangular */
  412. /* > \endverbatim */
  413. /* > */
  414. /* > \param[in] N */
  415. /* > \verbatim */
  416. /* > N is INTEGER */
  417. /* > The order of the matrix A. N >= 0. */
  418. /* > \endverbatim */
  419. /* > */
  420. /* > \param[in,out] A */
  421. /* > \verbatim */
  422. /* > A is COMPLEX*16 array, dimension (LDA,N) */
  423. /* > On entry, the Hermitian matrix A. If UPLO = 'U', the leading */
  424. /* > n-by-n upper triangular part of A contains the upper */
  425. /* > triangular part of the matrix A, and the strictly lower */
  426. /* > triangular part of A is not referenced. If UPLO = 'L', the */
  427. /* > leading n-by-n lower triangular part of A contains the lower */
  428. /* > triangular part of the matrix A, and the strictly upper */
  429. /* > triangular part of A is not referenced. */
  430. /* > */
  431. /* > On exit, the block diagonal matrix D and the multipliers used */
  432. /* > to obtain the factor U or L (see below for further details). */
  433. /* > \endverbatim */
  434. /* > */
  435. /* > \param[in] LDA */
  436. /* > \verbatim */
  437. /* > LDA is INTEGER */
  438. /* > The leading dimension of the array A. LDA >= f2cmax(1,N). */
  439. /* > \endverbatim */
  440. /* > */
  441. /* > \param[out] IPIV */
  442. /* > \verbatim */
  443. /* > IPIV is INTEGER array, dimension (N) */
  444. /* > Details of the interchanges and the block structure of D. */
  445. /* > */
  446. /* > If UPLO = 'U': */
  447. /* > If IPIV(k) > 0, then rows and columns k and IPIV(k) were */
  448. /* > interchanged and D(k,k) is a 1-by-1 diagonal block. */
  449. /* > */
  450. /* > If IPIV(k) = IPIV(k-1) < 0, then rows and columns */
  451. /* > k-1 and -IPIV(k) were interchanged and D(k-1:k,k-1:k) */
  452. /* > is a 2-by-2 diagonal block. */
  453. /* > */
  454. /* > If UPLO = 'L': */
  455. /* > If IPIV(k) > 0, then rows and columns k and IPIV(k) were */
  456. /* > interchanged and D(k,k) is a 1-by-1 diagonal block. */
  457. /* > */
  458. /* > If IPIV(k) = IPIV(k+1) < 0, then rows and columns */
  459. /* > k+1 and -IPIV(k) were interchanged and D(k:k+1,k:k+1) */
  460. /* > is a 2-by-2 diagonal block. */
  461. /* > \endverbatim */
  462. /* > */
  463. /* > \param[out] INFO */
  464. /* > \verbatim */
  465. /* > INFO is INTEGER */
  466. /* > = 0: successful exit */
  467. /* > < 0: if INFO = -k, the k-th argument had an illegal value */
  468. /* > > 0: if INFO = k, D(k,k) is exactly zero. The factorization */
  469. /* > has been completed, but the block diagonal matrix D is */
  470. /* > exactly singular, and division by zero will occur if it */
  471. /* > is used to solve a system of equations. */
  472. /* > \endverbatim */
  473. /* Authors: */
  474. /* ======== */
  475. /* > \author Univ. of Tennessee */
  476. /* > \author Univ. of California Berkeley */
  477. /* > \author Univ. of Colorado Denver */
  478. /* > \author NAG Ltd. */
  479. /* > \date November 2013 */
  480. /* > \ingroup complex16HEcomputational */
  481. /* > \par Further Details: */
  482. /* ===================== */
  483. /* > */
  484. /* > \verbatim */
  485. /* > */
  486. /* > If UPLO = 'U', then A = U*D*U**H, where */
  487. /* > U = P(n)*U(n)* ... *P(k)U(k)* ..., */
  488. /* > i.e., U is a product of terms P(k)*U(k), where k decreases from n to */
  489. /* > 1 in steps of 1 or 2, and D is a block diagonal matrix with 1-by-1 */
  490. /* > and 2-by-2 diagonal blocks D(k). P(k) is a permutation matrix as */
  491. /* > defined by IPIV(k), and U(k) is a unit upper triangular matrix, such */
  492. /* > that if the diagonal block D(k) is of order s (s = 1 or 2), then */
  493. /* > */
  494. /* > ( I v 0 ) k-s */
  495. /* > U(k) = ( 0 I 0 ) s */
  496. /* > ( 0 0 I ) n-k */
  497. /* > k-s s n-k */
  498. /* > */
  499. /* > If s = 1, D(k) overwrites A(k,k), and v overwrites A(1:k-1,k). */
  500. /* > If s = 2, the upper triangle of D(k) overwrites A(k-1,k-1), A(k-1,k), */
  501. /* > and A(k,k), and v overwrites A(1:k-2,k-1:k). */
  502. /* > */
  503. /* > If UPLO = 'L', then A = L*D*L**H, where */
  504. /* > L = P(1)*L(1)* ... *P(k)*L(k)* ..., */
  505. /* > i.e., L is a product of terms P(k)*L(k), where k increases from 1 to */
  506. /* > n in steps of 1 or 2, and D is a block diagonal matrix with 1-by-1 */
  507. /* > and 2-by-2 diagonal blocks D(k). P(k) is a permutation matrix as */
  508. /* > defined by IPIV(k), and L(k) is a unit lower triangular matrix, such */
  509. /* > that if the diagonal block D(k) is of order s (s = 1 or 2), then */
  510. /* > */
  511. /* > ( I 0 0 ) k-1 */
  512. /* > L(k) = ( 0 I 0 ) s */
  513. /* > ( 0 v I ) n-k-s+1 */
  514. /* > k-1 s n-k-s+1 */
  515. /* > */
  516. /* > If s = 1, D(k) overwrites A(k,k), and v overwrites A(k+1:n,k). */
  517. /* > If s = 2, the lower triangle of D(k) overwrites A(k,k), A(k+1,k), */
  518. /* > and A(k+1,k+1), and v overwrites A(k+2:n,k:k+1). */
  519. /* > \endverbatim */
  520. /* > \par Contributors: */
  521. /* ================== */
  522. /* > */
  523. /* > \verbatim */
  524. /* > 09-29-06 - patch from */
  525. /* > Bobby Cheng, MathWorks */
  526. /* > */
  527. /* > Replace l.210 and l.393 */
  528. /* > IF( MAX( ABSAKK, COLMAX ).EQ.ZERO ) THEN */
  529. /* > by */
  530. /* > IF( (MAX( ABSAKK, COLMAX ).EQ.ZERO) .OR. DISNAN(ABSAKK) ) THEN */
  531. /* > */
  532. /* > 01-01-96 - Based on modifications by */
  533. /* > J. Lewis, Boeing Computer Services Company */
  534. /* > A. Petitet, Computer Science Dept., Univ. of Tenn., Knoxville, USA */
  535. /* > \endverbatim */
  536. /* ===================================================================== */
  537. /* Subroutine */ int zhetf2_(char *uplo, integer *n, doublecomplex *a,
  538. integer *lda, integer *ipiv, integer *info)
  539. {
  540. /* System generated locals */
  541. integer a_dim1, a_offset, i__1, i__2, i__3, i__4, i__5, i__6;
  542. doublereal d__1, d__2, d__3, d__4;
  543. doublecomplex z__1, z__2, z__3, z__4, z__5, z__6;
  544. /* Local variables */
  545. integer imax, jmax;
  546. extern /* Subroutine */ int zher_(char *, integer *, doublereal *,
  547. doublecomplex *, integer *, doublecomplex *, integer *);
  548. doublereal d__;
  549. integer i__, j, k;
  550. doublecomplex t;
  551. doublereal alpha;
  552. extern logical lsame_(char *, char *);
  553. integer kstep;
  554. logical upper;
  555. doublereal r1;
  556. extern /* Subroutine */ int zswap_(integer *, doublecomplex *, integer *,
  557. doublecomplex *, integer *);
  558. extern doublereal dlapy2_(doublereal *, doublereal *);
  559. doublereal d11;
  560. doublecomplex d12;
  561. doublereal d22;
  562. doublecomplex d21;
  563. integer kk, kp;
  564. doublereal absakk;
  565. doublecomplex wk;
  566. doublereal tt;
  567. extern logical disnan_(doublereal *);
  568. extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen), zdscal_(
  569. integer *, doublereal *, doublecomplex *, integer *);
  570. doublereal colmax;
  571. extern integer izamax_(integer *, doublecomplex *, integer *);
  572. doublereal rowmax;
  573. doublecomplex wkm1, wkp1;
  574. /* -- LAPACK computational routine (version 3.5.0) -- */
  575. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  576. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  577. /* November 2013 */
  578. /* ===================================================================== */
  579. /* Test the input parameters. */
  580. /* Parameter adjustments */
  581. a_dim1 = *lda;
  582. a_offset = 1 + a_dim1 * 1;
  583. a -= a_offset;
  584. --ipiv;
  585. /* Function Body */
  586. *info = 0;
  587. upper = lsame_(uplo, "U");
  588. if (! upper && ! lsame_(uplo, "L")) {
  589. *info = -1;
  590. } else if (*n < 0) {
  591. *info = -2;
  592. } else if (*lda < f2cmax(1,*n)) {
  593. *info = -4;
  594. }
  595. if (*info != 0) {
  596. i__1 = -(*info);
  597. xerbla_("ZHETF2", &i__1, (ftnlen)6);
  598. return 0;
  599. }
  600. /* Initialize ALPHA for use in choosing pivot block size. */
  601. alpha = (sqrt(17.) + 1.) / 8.;
  602. if (upper) {
  603. /* Factorize A as U*D*U**H using the upper triangle of A */
  604. /* K is the main loop index, decreasing from N to 1 in steps of */
  605. /* 1 or 2 */
  606. k = *n;
  607. L10:
  608. /* If K < 1, exit from loop */
  609. if (k < 1) {
  610. goto L90;
  611. }
  612. kstep = 1;
  613. /* Determine rows and columns to be interchanged and whether */
  614. /* a 1-by-1 or 2-by-2 pivot block will be used */
  615. i__1 = k + k * a_dim1;
  616. absakk = (d__1 = a[i__1].r, abs(d__1));
  617. /* IMAX is the row-index of the largest off-diagonal element in */
  618. /* column K, and COLMAX is its absolute value. */
  619. /* Determine both COLMAX and IMAX. */
  620. if (k > 1) {
  621. i__1 = k - 1;
  622. imax = izamax_(&i__1, &a[k * a_dim1 + 1], &c__1);
  623. i__1 = imax + k * a_dim1;
  624. colmax = (d__1 = a[i__1].r, abs(d__1)) + (d__2 = d_imag(&a[imax +
  625. k * a_dim1]), abs(d__2));
  626. } else {
  627. colmax = 0.;
  628. }
  629. if (f2cmax(absakk,colmax) == 0. || disnan_(&absakk)) {
  630. /* Column K is zero or underflow, or contains a NaN: */
  631. /* set INFO and continue */
  632. if (*info == 0) {
  633. *info = k;
  634. }
  635. kp = k;
  636. i__1 = k + k * a_dim1;
  637. i__2 = k + k * a_dim1;
  638. d__1 = a[i__2].r;
  639. a[i__1].r = d__1, a[i__1].i = 0.;
  640. } else {
  641. /* ============================================================ */
  642. /* Test for interchange */
  643. if (absakk >= alpha * colmax) {
  644. /* no interchange, use 1-by-1 pivot block */
  645. kp = k;
  646. } else {
  647. /* JMAX is the column-index of the largest off-diagonal */
  648. /* element in row IMAX, and ROWMAX is its absolute value. */
  649. /* Determine only ROWMAX. */
  650. i__1 = k - imax;
  651. jmax = imax + izamax_(&i__1, &a[imax + (imax + 1) * a_dim1],
  652. lda);
  653. i__1 = imax + jmax * a_dim1;
  654. rowmax = (d__1 = a[i__1].r, abs(d__1)) + (d__2 = d_imag(&a[
  655. imax + jmax * a_dim1]), abs(d__2));
  656. if (imax > 1) {
  657. i__1 = imax - 1;
  658. jmax = izamax_(&i__1, &a[imax * a_dim1 + 1], &c__1);
  659. /* Computing MAX */
  660. i__1 = jmax + imax * a_dim1;
  661. d__3 = rowmax, d__4 = (d__1 = a[i__1].r, abs(d__1)) + (
  662. d__2 = d_imag(&a[jmax + imax * a_dim1]), abs(d__2)
  663. );
  664. rowmax = f2cmax(d__3,d__4);
  665. }
  666. if (absakk >= alpha * colmax * (colmax / rowmax)) {
  667. /* no interchange, use 1-by-1 pivot block */
  668. kp = k;
  669. } else /* if(complicated condition) */ {
  670. i__1 = imax + imax * a_dim1;
  671. if ((d__1 = a[i__1].r, abs(d__1)) >= alpha * rowmax) {
  672. /* interchange rows and columns K and IMAX, use 1-by-1 */
  673. /* pivot block */
  674. kp = imax;
  675. } else {
  676. /* interchange rows and columns K-1 and IMAX, use 2-by-2 */
  677. /* pivot block */
  678. kp = imax;
  679. kstep = 2;
  680. }
  681. }
  682. }
  683. /* ============================================================ */
  684. kk = k - kstep + 1;
  685. if (kp != kk) {
  686. /* Interchange rows and columns KK and KP in the leading */
  687. /* submatrix A(1:k,1:k) */
  688. i__1 = kp - 1;
  689. zswap_(&i__1, &a[kk * a_dim1 + 1], &c__1, &a[kp * a_dim1 + 1],
  690. &c__1);
  691. i__1 = kk - 1;
  692. for (j = kp + 1; j <= i__1; ++j) {
  693. d_cnjg(&z__1, &a[j + kk * a_dim1]);
  694. t.r = z__1.r, t.i = z__1.i;
  695. i__2 = j + kk * a_dim1;
  696. d_cnjg(&z__1, &a[kp + j * a_dim1]);
  697. a[i__2].r = z__1.r, a[i__2].i = z__1.i;
  698. i__2 = kp + j * a_dim1;
  699. a[i__2].r = t.r, a[i__2].i = t.i;
  700. /* L20: */
  701. }
  702. i__1 = kp + kk * a_dim1;
  703. d_cnjg(&z__1, &a[kp + kk * a_dim1]);
  704. a[i__1].r = z__1.r, a[i__1].i = z__1.i;
  705. i__1 = kk + kk * a_dim1;
  706. r1 = a[i__1].r;
  707. i__1 = kk + kk * a_dim1;
  708. i__2 = kp + kp * a_dim1;
  709. d__1 = a[i__2].r;
  710. a[i__1].r = d__1, a[i__1].i = 0.;
  711. i__1 = kp + kp * a_dim1;
  712. a[i__1].r = r1, a[i__1].i = 0.;
  713. if (kstep == 2) {
  714. i__1 = k + k * a_dim1;
  715. i__2 = k + k * a_dim1;
  716. d__1 = a[i__2].r;
  717. a[i__1].r = d__1, a[i__1].i = 0.;
  718. i__1 = k - 1 + k * a_dim1;
  719. t.r = a[i__1].r, t.i = a[i__1].i;
  720. i__1 = k - 1 + k * a_dim1;
  721. i__2 = kp + k * a_dim1;
  722. a[i__1].r = a[i__2].r, a[i__1].i = a[i__2].i;
  723. i__1 = kp + k * a_dim1;
  724. a[i__1].r = t.r, a[i__1].i = t.i;
  725. }
  726. } else {
  727. i__1 = k + k * a_dim1;
  728. i__2 = k + k * a_dim1;
  729. d__1 = a[i__2].r;
  730. a[i__1].r = d__1, a[i__1].i = 0.;
  731. if (kstep == 2) {
  732. i__1 = k - 1 + (k - 1) * a_dim1;
  733. i__2 = k - 1 + (k - 1) * a_dim1;
  734. d__1 = a[i__2].r;
  735. a[i__1].r = d__1, a[i__1].i = 0.;
  736. }
  737. }
  738. /* Update the leading submatrix */
  739. if (kstep == 1) {
  740. /* 1-by-1 pivot block D(k): column k now holds */
  741. /* W(k) = U(k)*D(k) */
  742. /* where U(k) is the k-th column of U */
  743. /* Perform a rank-1 update of A(1:k-1,1:k-1) as */
  744. /* A := A - U(k)*D(k)*U(k)**H = A - W(k)*1/D(k)*W(k)**H */
  745. i__1 = k + k * a_dim1;
  746. r1 = 1. / a[i__1].r;
  747. i__1 = k - 1;
  748. d__1 = -r1;
  749. zher_(uplo, &i__1, &d__1, &a[k * a_dim1 + 1], &c__1, &a[
  750. a_offset], lda);
  751. /* Store U(k) in column k */
  752. i__1 = k - 1;
  753. zdscal_(&i__1, &r1, &a[k * a_dim1 + 1], &c__1);
  754. } else {
  755. /* 2-by-2 pivot block D(k): columns k and k-1 now hold */
  756. /* ( W(k-1) W(k) ) = ( U(k-1) U(k) )*D(k) */
  757. /* where U(k) and U(k-1) are the k-th and (k-1)-th columns */
  758. /* of U */
  759. /* Perform a rank-2 update of A(1:k-2,1:k-2) as */
  760. /* A := A - ( U(k-1) U(k) )*D(k)*( U(k-1) U(k) )**H */
  761. /* = A - ( W(k-1) W(k) )*inv(D(k))*( W(k-1) W(k) )**H */
  762. if (k > 2) {
  763. i__1 = k - 1 + k * a_dim1;
  764. d__1 = a[i__1].r;
  765. d__2 = d_imag(&a[k - 1 + k * a_dim1]);
  766. d__ = dlapy2_(&d__1, &d__2);
  767. i__1 = k - 1 + (k - 1) * a_dim1;
  768. d22 = a[i__1].r / d__;
  769. i__1 = k + k * a_dim1;
  770. d11 = a[i__1].r / d__;
  771. tt = 1. / (d11 * d22 - 1.);
  772. i__1 = k - 1 + k * a_dim1;
  773. z__1.r = a[i__1].r / d__, z__1.i = a[i__1].i / d__;
  774. d12.r = z__1.r, d12.i = z__1.i;
  775. d__ = tt / d__;
  776. for (j = k - 2; j >= 1; --j) {
  777. i__1 = j + (k - 1) * a_dim1;
  778. z__3.r = d11 * a[i__1].r, z__3.i = d11 * a[i__1].i;
  779. d_cnjg(&z__5, &d12);
  780. i__2 = j + k * a_dim1;
  781. z__4.r = z__5.r * a[i__2].r - z__5.i * a[i__2].i,
  782. z__4.i = z__5.r * a[i__2].i + z__5.i * a[i__2]
  783. .r;
  784. z__2.r = z__3.r - z__4.r, z__2.i = z__3.i - z__4.i;
  785. z__1.r = d__ * z__2.r, z__1.i = d__ * z__2.i;
  786. wkm1.r = z__1.r, wkm1.i = z__1.i;
  787. i__1 = j + k * a_dim1;
  788. z__3.r = d22 * a[i__1].r, z__3.i = d22 * a[i__1].i;
  789. i__2 = j + (k - 1) * a_dim1;
  790. z__4.r = d12.r * a[i__2].r - d12.i * a[i__2].i,
  791. z__4.i = d12.r * a[i__2].i + d12.i * a[i__2]
  792. .r;
  793. z__2.r = z__3.r - z__4.r, z__2.i = z__3.i - z__4.i;
  794. z__1.r = d__ * z__2.r, z__1.i = d__ * z__2.i;
  795. wk.r = z__1.r, wk.i = z__1.i;
  796. for (i__ = j; i__ >= 1; --i__) {
  797. i__1 = i__ + j * a_dim1;
  798. i__2 = i__ + j * a_dim1;
  799. i__3 = i__ + k * a_dim1;
  800. d_cnjg(&z__4, &wk);
  801. z__3.r = a[i__3].r * z__4.r - a[i__3].i * z__4.i,
  802. z__3.i = a[i__3].r * z__4.i + a[i__3].i *
  803. z__4.r;
  804. z__2.r = a[i__2].r - z__3.r, z__2.i = a[i__2].i -
  805. z__3.i;
  806. i__4 = i__ + (k - 1) * a_dim1;
  807. d_cnjg(&z__6, &wkm1);
  808. z__5.r = a[i__4].r * z__6.r - a[i__4].i * z__6.i,
  809. z__5.i = a[i__4].r * z__6.i + a[i__4].i *
  810. z__6.r;
  811. z__1.r = z__2.r - z__5.r, z__1.i = z__2.i -
  812. z__5.i;
  813. a[i__1].r = z__1.r, a[i__1].i = z__1.i;
  814. /* L30: */
  815. }
  816. i__1 = j + k * a_dim1;
  817. a[i__1].r = wk.r, a[i__1].i = wk.i;
  818. i__1 = j + (k - 1) * a_dim1;
  819. a[i__1].r = wkm1.r, a[i__1].i = wkm1.i;
  820. i__1 = j + j * a_dim1;
  821. i__2 = j + j * a_dim1;
  822. d__1 = a[i__2].r;
  823. z__1.r = d__1, z__1.i = 0.;
  824. a[i__1].r = z__1.r, a[i__1].i = z__1.i;
  825. /* L40: */
  826. }
  827. }
  828. }
  829. }
  830. /* Store details of the interchanges in IPIV */
  831. if (kstep == 1) {
  832. ipiv[k] = kp;
  833. } else {
  834. ipiv[k] = -kp;
  835. ipiv[k - 1] = -kp;
  836. }
  837. /* Decrease K and return to the start of the main loop */
  838. k -= kstep;
  839. goto L10;
  840. } else {
  841. /* Factorize A as L*D*L**H using the lower triangle of A */
  842. /* K is the main loop index, increasing from 1 to N in steps of */
  843. /* 1 or 2 */
  844. k = 1;
  845. L50:
  846. /* If K > N, exit from loop */
  847. if (k > *n) {
  848. goto L90;
  849. }
  850. kstep = 1;
  851. /* Determine rows and columns to be interchanged and whether */
  852. /* a 1-by-1 or 2-by-2 pivot block will be used */
  853. i__1 = k + k * a_dim1;
  854. absakk = (d__1 = a[i__1].r, abs(d__1));
  855. /* IMAX is the row-index of the largest off-diagonal element in */
  856. /* column K, and COLMAX is its absolute value. */
  857. /* Determine both COLMAX and IMAX. */
  858. if (k < *n) {
  859. i__1 = *n - k;
  860. imax = k + izamax_(&i__1, &a[k + 1 + k * a_dim1], &c__1);
  861. i__1 = imax + k * a_dim1;
  862. colmax = (d__1 = a[i__1].r, abs(d__1)) + (d__2 = d_imag(&a[imax +
  863. k * a_dim1]), abs(d__2));
  864. } else {
  865. colmax = 0.;
  866. }
  867. if (f2cmax(absakk,colmax) == 0. || disnan_(&absakk)) {
  868. /* Column K is zero or underflow, or contains a NaN: */
  869. /* set INFO and continue */
  870. if (*info == 0) {
  871. *info = k;
  872. }
  873. kp = k;
  874. i__1 = k + k * a_dim1;
  875. i__2 = k + k * a_dim1;
  876. d__1 = a[i__2].r;
  877. a[i__1].r = d__1, a[i__1].i = 0.;
  878. } else {
  879. /* ============================================================ */
  880. /* Test for interchange */
  881. if (absakk >= alpha * colmax) {
  882. /* no interchange, use 1-by-1 pivot block */
  883. kp = k;
  884. } else {
  885. /* JMAX is the column-index of the largest off-diagonal */
  886. /* element in row IMAX, and ROWMAX is its absolute value. */
  887. /* Determine only ROWMAX. */
  888. i__1 = imax - k;
  889. jmax = k - 1 + izamax_(&i__1, &a[imax + k * a_dim1], lda);
  890. i__1 = imax + jmax * a_dim1;
  891. rowmax = (d__1 = a[i__1].r, abs(d__1)) + (d__2 = d_imag(&a[
  892. imax + jmax * a_dim1]), abs(d__2));
  893. if (imax < *n) {
  894. i__1 = *n - imax;
  895. jmax = imax + izamax_(&i__1, &a[imax + 1 + imax * a_dim1],
  896. &c__1);
  897. /* Computing MAX */
  898. i__1 = jmax + imax * a_dim1;
  899. d__3 = rowmax, d__4 = (d__1 = a[i__1].r, abs(d__1)) + (
  900. d__2 = d_imag(&a[jmax + imax * a_dim1]), abs(d__2)
  901. );
  902. rowmax = f2cmax(d__3,d__4);
  903. }
  904. if (absakk >= alpha * colmax * (colmax / rowmax)) {
  905. /* no interchange, use 1-by-1 pivot block */
  906. kp = k;
  907. } else /* if(complicated condition) */ {
  908. i__1 = imax + imax * a_dim1;
  909. if ((d__1 = a[i__1].r, abs(d__1)) >= alpha * rowmax) {
  910. /* interchange rows and columns K and IMAX, use 1-by-1 */
  911. /* pivot block */
  912. kp = imax;
  913. } else {
  914. /* interchange rows and columns K+1 and IMAX, use 2-by-2 */
  915. /* pivot block */
  916. kp = imax;
  917. kstep = 2;
  918. }
  919. }
  920. }
  921. /* ============================================================ */
  922. kk = k + kstep - 1;
  923. if (kp != kk) {
  924. /* Interchange rows and columns KK and KP in the trailing */
  925. /* submatrix A(k:n,k:n) */
  926. if (kp < *n) {
  927. i__1 = *n - kp;
  928. zswap_(&i__1, &a[kp + 1 + kk * a_dim1], &c__1, &a[kp + 1
  929. + kp * a_dim1], &c__1);
  930. }
  931. i__1 = kp - 1;
  932. for (j = kk + 1; j <= i__1; ++j) {
  933. d_cnjg(&z__1, &a[j + kk * a_dim1]);
  934. t.r = z__1.r, t.i = z__1.i;
  935. i__2 = j + kk * a_dim1;
  936. d_cnjg(&z__1, &a[kp + j * a_dim1]);
  937. a[i__2].r = z__1.r, a[i__2].i = z__1.i;
  938. i__2 = kp + j * a_dim1;
  939. a[i__2].r = t.r, a[i__2].i = t.i;
  940. /* L60: */
  941. }
  942. i__1 = kp + kk * a_dim1;
  943. d_cnjg(&z__1, &a[kp + kk * a_dim1]);
  944. a[i__1].r = z__1.r, a[i__1].i = z__1.i;
  945. i__1 = kk + kk * a_dim1;
  946. r1 = a[i__1].r;
  947. i__1 = kk + kk * a_dim1;
  948. i__2 = kp + kp * a_dim1;
  949. d__1 = a[i__2].r;
  950. a[i__1].r = d__1, a[i__1].i = 0.;
  951. i__1 = kp + kp * a_dim1;
  952. a[i__1].r = r1, a[i__1].i = 0.;
  953. if (kstep == 2) {
  954. i__1 = k + k * a_dim1;
  955. i__2 = k + k * a_dim1;
  956. d__1 = a[i__2].r;
  957. a[i__1].r = d__1, a[i__1].i = 0.;
  958. i__1 = k + 1 + k * a_dim1;
  959. t.r = a[i__1].r, t.i = a[i__1].i;
  960. i__1 = k + 1 + k * a_dim1;
  961. i__2 = kp + k * a_dim1;
  962. a[i__1].r = a[i__2].r, a[i__1].i = a[i__2].i;
  963. i__1 = kp + k * a_dim1;
  964. a[i__1].r = t.r, a[i__1].i = t.i;
  965. }
  966. } else {
  967. i__1 = k + k * a_dim1;
  968. i__2 = k + k * a_dim1;
  969. d__1 = a[i__2].r;
  970. a[i__1].r = d__1, a[i__1].i = 0.;
  971. if (kstep == 2) {
  972. i__1 = k + 1 + (k + 1) * a_dim1;
  973. i__2 = k + 1 + (k + 1) * a_dim1;
  974. d__1 = a[i__2].r;
  975. a[i__1].r = d__1, a[i__1].i = 0.;
  976. }
  977. }
  978. /* Update the trailing submatrix */
  979. if (kstep == 1) {
  980. /* 1-by-1 pivot block D(k): column k now holds */
  981. /* W(k) = L(k)*D(k) */
  982. /* where L(k) is the k-th column of L */
  983. if (k < *n) {
  984. /* Perform a rank-1 update of A(k+1:n,k+1:n) as */
  985. /* A := A - L(k)*D(k)*L(k)**H = A - W(k)*(1/D(k))*W(k)**H */
  986. i__1 = k + k * a_dim1;
  987. r1 = 1. / a[i__1].r;
  988. i__1 = *n - k;
  989. d__1 = -r1;
  990. zher_(uplo, &i__1, &d__1, &a[k + 1 + k * a_dim1], &c__1, &
  991. a[k + 1 + (k + 1) * a_dim1], lda);
  992. /* Store L(k) in column K */
  993. i__1 = *n - k;
  994. zdscal_(&i__1, &r1, &a[k + 1 + k * a_dim1], &c__1);
  995. }
  996. } else {
  997. /* 2-by-2 pivot block D(k) */
  998. if (k < *n - 1) {
  999. /* Perform a rank-2 update of A(k+2:n,k+2:n) as */
  1000. /* A := A - ( L(k) L(k+1) )*D(k)*( L(k) L(k+1) )**H */
  1001. /* = A - ( W(k) W(k+1) )*inv(D(k))*( W(k) W(k+1) )**H */
  1002. /* where L(k) and L(k+1) are the k-th and (k+1)-th */
  1003. /* columns of L */
  1004. i__1 = k + 1 + k * a_dim1;
  1005. d__1 = a[i__1].r;
  1006. d__2 = d_imag(&a[k + 1 + k * a_dim1]);
  1007. d__ = dlapy2_(&d__1, &d__2);
  1008. i__1 = k + 1 + (k + 1) * a_dim1;
  1009. d11 = a[i__1].r / d__;
  1010. i__1 = k + k * a_dim1;
  1011. d22 = a[i__1].r / d__;
  1012. tt = 1. / (d11 * d22 - 1.);
  1013. i__1 = k + 1 + k * a_dim1;
  1014. z__1.r = a[i__1].r / d__, z__1.i = a[i__1].i / d__;
  1015. d21.r = z__1.r, d21.i = z__1.i;
  1016. d__ = tt / d__;
  1017. i__1 = *n;
  1018. for (j = k + 2; j <= i__1; ++j) {
  1019. i__2 = j + k * a_dim1;
  1020. z__3.r = d11 * a[i__2].r, z__3.i = d11 * a[i__2].i;
  1021. i__3 = j + (k + 1) * a_dim1;
  1022. z__4.r = d21.r * a[i__3].r - d21.i * a[i__3].i,
  1023. z__4.i = d21.r * a[i__3].i + d21.i * a[i__3]
  1024. .r;
  1025. z__2.r = z__3.r - z__4.r, z__2.i = z__3.i - z__4.i;
  1026. z__1.r = d__ * z__2.r, z__1.i = d__ * z__2.i;
  1027. wk.r = z__1.r, wk.i = z__1.i;
  1028. i__2 = j + (k + 1) * a_dim1;
  1029. z__3.r = d22 * a[i__2].r, z__3.i = d22 * a[i__2].i;
  1030. d_cnjg(&z__5, &d21);
  1031. i__3 = j + k * a_dim1;
  1032. z__4.r = z__5.r * a[i__3].r - z__5.i * a[i__3].i,
  1033. z__4.i = z__5.r * a[i__3].i + z__5.i * a[i__3]
  1034. .r;
  1035. z__2.r = z__3.r - z__4.r, z__2.i = z__3.i - z__4.i;
  1036. z__1.r = d__ * z__2.r, z__1.i = d__ * z__2.i;
  1037. wkp1.r = z__1.r, wkp1.i = z__1.i;
  1038. i__2 = *n;
  1039. for (i__ = j; i__ <= i__2; ++i__) {
  1040. i__3 = i__ + j * a_dim1;
  1041. i__4 = i__ + j * a_dim1;
  1042. i__5 = i__ + k * a_dim1;
  1043. d_cnjg(&z__4, &wk);
  1044. z__3.r = a[i__5].r * z__4.r - a[i__5].i * z__4.i,
  1045. z__3.i = a[i__5].r * z__4.i + a[i__5].i *
  1046. z__4.r;
  1047. z__2.r = a[i__4].r - z__3.r, z__2.i = a[i__4].i -
  1048. z__3.i;
  1049. i__6 = i__ + (k + 1) * a_dim1;
  1050. d_cnjg(&z__6, &wkp1);
  1051. z__5.r = a[i__6].r * z__6.r - a[i__6].i * z__6.i,
  1052. z__5.i = a[i__6].r * z__6.i + a[i__6].i *
  1053. z__6.r;
  1054. z__1.r = z__2.r - z__5.r, z__1.i = z__2.i -
  1055. z__5.i;
  1056. a[i__3].r = z__1.r, a[i__3].i = z__1.i;
  1057. /* L70: */
  1058. }
  1059. i__2 = j + k * a_dim1;
  1060. a[i__2].r = wk.r, a[i__2].i = wk.i;
  1061. i__2 = j + (k + 1) * a_dim1;
  1062. a[i__2].r = wkp1.r, a[i__2].i = wkp1.i;
  1063. i__2 = j + j * a_dim1;
  1064. i__3 = j + j * a_dim1;
  1065. d__1 = a[i__3].r;
  1066. z__1.r = d__1, z__1.i = 0.;
  1067. a[i__2].r = z__1.r, a[i__2].i = z__1.i;
  1068. /* L80: */
  1069. }
  1070. }
  1071. }
  1072. }
  1073. /* Store details of the interchanges in IPIV */
  1074. if (kstep == 1) {
  1075. ipiv[k] = kp;
  1076. } else {
  1077. ipiv[k] = -kp;
  1078. ipiv[k + 1] = -kp;
  1079. }
  1080. /* Increase K and return to the start of the main loop */
  1081. k += kstep;
  1082. goto L50;
  1083. }
  1084. L90:
  1085. return 0;
  1086. /* End of ZHETF2 */
  1087. } /* zhetf2_ */