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.

chetf2_rk.c 51 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742
  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. #if defined(_WIN64)
  18. typedef long long BLASLONG;
  19. typedef unsigned long long BLASULONG;
  20. #else
  21. typedef long BLASLONG;
  22. typedef unsigned long BLASULONG;
  23. #endif
  24. #ifdef LAPACK_ILP64
  25. typedef BLASLONG blasint;
  26. #if defined(_WIN64)
  27. #define blasabs(x) llabs(x)
  28. #else
  29. #define blasabs(x) labs(x)
  30. #endif
  31. #else
  32. typedef int blasint;
  33. #define blasabs(x) abs(x)
  34. #endif
  35. typedef blasint integer;
  36. typedef unsigned int uinteger;
  37. typedef char *address;
  38. typedef short int shortint;
  39. typedef float real;
  40. typedef double doublereal;
  41. typedef struct { real r, i; } complex;
  42. typedef struct { doublereal r, i; } doublecomplex;
  43. static inline _Complex float Cf(complex *z) {return z->r + z->i*_Complex_I;}
  44. static inline _Complex double Cd(doublecomplex *z) {return z->r + z->i*_Complex_I;}
  45. static inline _Complex float * _pCf(complex *z) {return (_Complex float*)z;}
  46. static inline _Complex double * _pCd(doublecomplex *z) {return (_Complex double*)z;}
  47. #define pCf(z) (*_pCf(z))
  48. #define pCd(z) (*_pCd(z))
  49. typedef int logical;
  50. typedef short int shortlogical;
  51. typedef char logical1;
  52. typedef char integer1;
  53. #define TRUE_ (1)
  54. #define FALSE_ (0)
  55. /* Extern is for use with -E */
  56. #ifndef Extern
  57. #define Extern extern
  58. #endif
  59. /* I/O stuff */
  60. typedef int flag;
  61. typedef int ftnlen;
  62. typedef int ftnint;
  63. /*external read, write*/
  64. typedef struct
  65. { flag cierr;
  66. ftnint ciunit;
  67. flag ciend;
  68. char *cifmt;
  69. ftnint cirec;
  70. } cilist;
  71. /*internal read, write*/
  72. typedef struct
  73. { flag icierr;
  74. char *iciunit;
  75. flag iciend;
  76. char *icifmt;
  77. ftnint icirlen;
  78. ftnint icirnum;
  79. } icilist;
  80. /*open*/
  81. typedef struct
  82. { flag oerr;
  83. ftnint ounit;
  84. char *ofnm;
  85. ftnlen ofnmlen;
  86. char *osta;
  87. char *oacc;
  88. char *ofm;
  89. ftnint orl;
  90. char *oblnk;
  91. } olist;
  92. /*close*/
  93. typedef struct
  94. { flag cerr;
  95. ftnint cunit;
  96. char *csta;
  97. } cllist;
  98. /*rewind, backspace, endfile*/
  99. typedef struct
  100. { flag aerr;
  101. ftnint aunit;
  102. } alist;
  103. /* inquire */
  104. typedef struct
  105. { flag inerr;
  106. ftnint inunit;
  107. char *infile;
  108. ftnlen infilen;
  109. ftnint *inex; /*parameters in standard's order*/
  110. ftnint *inopen;
  111. ftnint *innum;
  112. ftnint *innamed;
  113. char *inname;
  114. ftnlen innamlen;
  115. char *inacc;
  116. ftnlen inacclen;
  117. char *inseq;
  118. ftnlen inseqlen;
  119. char *indir;
  120. ftnlen indirlen;
  121. char *infmt;
  122. ftnlen infmtlen;
  123. char *inform;
  124. ftnint informlen;
  125. char *inunf;
  126. ftnlen inunflen;
  127. ftnint *inrecl;
  128. ftnint *innrec;
  129. char *inblank;
  130. ftnlen inblanklen;
  131. } inlist;
  132. #define VOID void
  133. union Multitype { /* for multiple entry points */
  134. integer1 g;
  135. shortint h;
  136. integer i;
  137. /* longint j; */
  138. real r;
  139. doublereal d;
  140. complex c;
  141. doublecomplex z;
  142. };
  143. typedef union Multitype Multitype;
  144. struct Vardesc { /* for Namelist */
  145. char *name;
  146. char *addr;
  147. ftnlen *dims;
  148. int type;
  149. };
  150. typedef struct Vardesc Vardesc;
  151. struct Namelist {
  152. char *name;
  153. Vardesc **vars;
  154. int nvars;
  155. };
  156. typedef struct Namelist Namelist;
  157. #define abs(x) ((x) >= 0 ? (x) : -(x))
  158. #define dabs(x) (fabs(x))
  159. #define f2cmin(a,b) ((a) <= (b) ? (a) : (b))
  160. #define f2cmax(a,b) ((a) >= (b) ? (a) : (b))
  161. #define dmin(a,b) (f2cmin(a,b))
  162. #define dmax(a,b) (f2cmax(a,b))
  163. #define bit_test(a,b) ((a) >> (b) & 1)
  164. #define bit_clear(a,b) ((a) & ~((uinteger)1 << (b)))
  165. #define bit_set(a,b) ((a) | ((uinteger)1 << (b)))
  166. #define abort_() { sig_die("Fortran abort routine called", 1); }
  167. #define c_abs(z) (cabsf(Cf(z)))
  168. #define c_cos(R,Z) { pCf(R)=ccos(Cf(Z)); }
  169. #define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);}
  170. #define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);}
  171. #define c_exp(R, Z) {pCf(R) = cexpf(Cf(Z));}
  172. #define c_log(R, Z) {pCf(R) = clogf(Cf(Z));}
  173. #define c_sin(R, Z) {pCf(R) = csinf(Cf(Z));}
  174. //#define c_sqrt(R, Z) {*(R) = csqrtf(Cf(Z));}
  175. #define c_sqrt(R, Z) {pCf(R) = csqrtf(Cf(Z));}
  176. #define d_abs(x) (fabs(*(x)))
  177. #define d_acos(x) (acos(*(x)))
  178. #define d_asin(x) (asin(*(x)))
  179. #define d_atan(x) (atan(*(x)))
  180. #define d_atn2(x, y) (atan2(*(x),*(y)))
  181. #define d_cnjg(R, Z) { pCd(R) = conj(Cd(Z)); }
  182. #define r_cnjg(R, Z) { pCf(R) = conj(Cf(Z)); }
  183. #define d_cos(x) (cos(*(x)))
  184. #define d_cosh(x) (cosh(*(x)))
  185. #define d_dim(__a, __b) ( *(__a) > *(__b) ? *(__a) - *(__b) : 0.0 )
  186. #define d_exp(x) (exp(*(x)))
  187. #define d_imag(z) (cimag(Cd(z)))
  188. #define r_imag(z) (cimag(Cf(z)))
  189. #define d_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  190. #define r_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  191. #define d_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  192. #define r_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  193. #define d_log(x) (log(*(x)))
  194. #define d_mod(x, y) (fmod(*(x), *(y)))
  195. #define u_nint(__x) ((__x)>=0 ? floor((__x) + .5) : -floor(.5 - (__x)))
  196. #define d_nint(x) u_nint(*(x))
  197. #define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a)))
  198. #define d_sign(a,b) u_sign(*(a),*(b))
  199. #define r_sign(a,b) u_sign(*(a),*(b))
  200. #define d_sin(x) (sin(*(x)))
  201. #define d_sinh(x) (sinh(*(x)))
  202. #define d_sqrt(x) (sqrt(*(x)))
  203. #define d_tan(x) (tan(*(x)))
  204. #define d_tanh(x) (tanh(*(x)))
  205. #define i_abs(x) abs(*(x))
  206. #define i_dnnt(x) ((integer)u_nint(*(x)))
  207. #define i_len(s, n) (n)
  208. #define i_nint(x) ((integer)u_nint(*(x)))
  209. #define i_sign(a,b) ((integer)u_sign((integer)*(a),(integer)*(b)))
  210. #define pow_dd(ap, bp) ( pow(*(ap), *(bp)))
  211. #define pow_si(B,E) spow_ui(*(B),*(E))
  212. #define pow_ri(B,E) spow_ui(*(B),*(E))
  213. #define pow_di(B,E) dpow_ui(*(B),*(E))
  214. #define pow_zi(p, a, b) {pCd(p) = zpow_ui(Cd(a), *(b));}
  215. #define pow_ci(p, a, b) {pCf(p) = cpow_ui(Cf(a), *(b));}
  216. #define pow_zz(R,A,B) {pCd(R) = cpow(Cd(A),*(B));}
  217. #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++ = ' '; }
  218. #define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d))))
  219. #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]; }
  220. #define sig_die(s, kill) { exit(1); }
  221. #define s_stop(s, n) {exit(0);}
  222. static char junk[] = "\n@(#)LIBF77 VERSION 19990503\n";
  223. #define z_abs(z) (cabs(Cd(z)))
  224. #define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));}
  225. #define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));}
  226. #define myexit_() break;
  227. #define mycycle() continue;
  228. #define myceiling(w) {ceil(w)}
  229. #define myhuge(w) {HUGE_VAL}
  230. //#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);}
  231. #define mymaxloc(w,s,e,n) {dmaxloc_(w,*(s),*(e),n)}
  232. /* procedure parameter types for -A and -C++ */
  233. #define F2C_proc_par_types 1
  234. #ifdef __cplusplus
  235. typedef logical (*L_fp)(...);
  236. #else
  237. typedef logical (*L_fp)();
  238. #endif
  239. static float spow_ui(float x, integer n) {
  240. float pow=1.0; unsigned long int u;
  241. if(n != 0) {
  242. if(n < 0) n = -n, x = 1/x;
  243. for(u = n; ; ) {
  244. if(u & 01) pow *= x;
  245. if(u >>= 1) x *= x;
  246. else break;
  247. }
  248. }
  249. return pow;
  250. }
  251. static double dpow_ui(double x, integer n) {
  252. double pow=1.0; unsigned long int u;
  253. if(n != 0) {
  254. if(n < 0) n = -n, x = 1/x;
  255. for(u = n; ; ) {
  256. if(u & 01) pow *= x;
  257. if(u >>= 1) x *= x;
  258. else break;
  259. }
  260. }
  261. return pow;
  262. }
  263. static _Complex float cpow_ui(_Complex float x, integer n) {
  264. _Complex float pow=1.0; unsigned long int u;
  265. if(n != 0) {
  266. if(n < 0) n = -n, x = 1/x;
  267. for(u = n; ; ) {
  268. if(u & 01) pow *= x;
  269. if(u >>= 1) x *= x;
  270. else break;
  271. }
  272. }
  273. return pow;
  274. }
  275. static _Complex double zpow_ui(_Complex double x, integer n) {
  276. _Complex double pow=1.0; unsigned long int u;
  277. if(n != 0) {
  278. if(n < 0) n = -n, x = 1/x;
  279. for(u = n; ; ) {
  280. if(u & 01) pow *= x;
  281. if(u >>= 1) x *= x;
  282. else break;
  283. }
  284. }
  285. return pow;
  286. }
  287. static integer pow_ii(integer x, integer n) {
  288. integer pow; unsigned long int u;
  289. if (n <= 0) {
  290. if (n == 0 || x == 1) pow = 1;
  291. else if (x != -1) pow = x == 0 ? 1/x : 0;
  292. else n = -n;
  293. }
  294. if ((n > 0) || !(n == 0 || x == 1 || x != -1)) {
  295. u = n;
  296. for(pow = 1; ; ) {
  297. if(u & 01) pow *= x;
  298. if(u >>= 1) x *= x;
  299. else break;
  300. }
  301. }
  302. return pow;
  303. }
  304. static integer dmaxloc_(double *w, integer s, integer e, integer *n)
  305. {
  306. double m; integer i, mi;
  307. for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
  308. if (w[i-1]>m) mi=i ,m=w[i-1];
  309. return mi-s+1;
  310. }
  311. static integer smaxloc_(float *w, integer s, integer e, integer *n)
  312. {
  313. float m; integer i, mi;
  314. for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
  315. if (w[i-1]>m) mi=i ,m=w[i-1];
  316. return mi-s+1;
  317. }
  318. static inline void cdotc_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
  319. integer n = *n_, incx = *incx_, incy = *incy_, i;
  320. _Complex float zdotc = 0.0;
  321. if (incx == 1 && incy == 1) {
  322. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  323. zdotc += conjf(Cf(&x[i])) * Cf(&y[i]);
  324. }
  325. } else {
  326. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  327. zdotc += conjf(Cf(&x[i*incx])) * Cf(&y[i*incy]);
  328. }
  329. }
  330. pCf(z) = zdotc;
  331. }
  332. static inline void zdotc_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
  333. integer n = *n_, incx = *incx_, incy = *incy_, i;
  334. _Complex double zdotc = 0.0;
  335. if (incx == 1 && incy == 1) {
  336. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  337. zdotc += conj(Cd(&x[i])) * Cd(&y[i]);
  338. }
  339. } else {
  340. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  341. zdotc += conj(Cd(&x[i*incx])) * Cd(&y[i*incy]);
  342. }
  343. }
  344. pCd(z) = zdotc;
  345. }
  346. static inline void cdotu_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
  347. integer n = *n_, incx = *incx_, incy = *incy_, i;
  348. _Complex float zdotc = 0.0;
  349. if (incx == 1 && incy == 1) {
  350. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  351. zdotc += Cf(&x[i]) * Cf(&y[i]);
  352. }
  353. } else {
  354. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  355. zdotc += Cf(&x[i*incx]) * Cf(&y[i*incy]);
  356. }
  357. }
  358. pCf(z) = zdotc;
  359. }
  360. static inline void zdotu_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
  361. integer n = *n_, incx = *incx_, incy = *incy_, i;
  362. _Complex double zdotc = 0.0;
  363. if (incx == 1 && incy == 1) {
  364. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  365. zdotc += Cd(&x[i]) * Cd(&y[i]);
  366. }
  367. } else {
  368. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  369. zdotc += Cd(&x[i*incx]) * Cd(&y[i*incy]);
  370. }
  371. }
  372. pCd(z) = zdotc;
  373. }
  374. #endif
  375. /* -- translated by f2c (version 20000121).
  376. You must link the resulting object file with the libraries:
  377. -lf2c -lm (in that order)
  378. */
  379. /* Table of constant values */
  380. static integer c__1 = 1;
  381. /* > \brief \b CHETF2_RK computes the factorization of a complex Hermitian indefinite matrix using the bounded
  382. Bunch-Kaufman (rook) diagonal pivoting method (BLAS2 unblocked algorithm). */
  383. /* =========== DOCUMENTATION =========== */
  384. /* Online html documentation available at */
  385. /* http://www.netlib.org/lapack/explore-html/ */
  386. /* > \htmlonly */
  387. /* > Download CHETF2_RK + dependencies */
  388. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/chetf2_
  389. rk.f"> */
  390. /* > [TGZ]</a> */
  391. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/chetf2_
  392. rk.f"> */
  393. /* > [ZIP]</a> */
  394. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/chetf2_
  395. rk.f"> */
  396. /* > [TXT]</a> */
  397. /* > \endhtmlonly */
  398. /* Definition: */
  399. /* =========== */
  400. /* SUBROUTINE CHETF2_RK( UPLO, N, A, LDA, E, IPIV, INFO ) */
  401. /* CHARACTER UPLO */
  402. /* INTEGER INFO, LDA, N */
  403. /* INTEGER IPIV( * ) */
  404. /* COMPLEX A( LDA, * ), E ( * ) */
  405. /* > \par Purpose: */
  406. /* ============= */
  407. /* > */
  408. /* > \verbatim */
  409. /* > CHETF2_RK computes the factorization of a complex Hermitian matrix A */
  410. /* > using the bounded Bunch-Kaufman (rook) diagonal pivoting method: */
  411. /* > */
  412. /* > A = P*U*D*(U**H)*(P**T) or A = P*L*D*(L**H)*(P**T), */
  413. /* > */
  414. /* > where U (or L) is unit upper (or lower) triangular matrix, */
  415. /* > U**H (or L**H) is the conjugate of U (or L), P is a permutation */
  416. /* > matrix, P**T is the transpose of P, and D is Hermitian and block */
  417. /* > diagonal with 1-by-1 and 2-by-2 diagonal blocks. */
  418. /* > */
  419. /* > This is the unblocked version of the algorithm, calling Level 2 BLAS. */
  420. /* > For more information see Further Details section. */
  421. /* > \endverbatim */
  422. /* Arguments: */
  423. /* ========== */
  424. /* > \param[in] UPLO */
  425. /* > \verbatim */
  426. /* > UPLO is CHARACTER*1 */
  427. /* > Specifies whether the upper or lower triangular part of the */
  428. /* > Hermitian matrix A is stored: */
  429. /* > = 'U': Upper triangular */
  430. /* > = 'L': Lower triangular */
  431. /* > \endverbatim */
  432. /* > */
  433. /* > \param[in] N */
  434. /* > \verbatim */
  435. /* > N is INTEGER */
  436. /* > The order of the matrix A. N >= 0. */
  437. /* > \endverbatim */
  438. /* > */
  439. /* > \param[in,out] A */
  440. /* > \verbatim */
  441. /* > A is COMPLEX array, dimension (LDA,N) */
  442. /* > On entry, the Hermitian matrix A. */
  443. /* > If UPLO = 'U': the leading N-by-N upper triangular part */
  444. /* > of A contains the upper triangular part of the matrix A, */
  445. /* > and the strictly lower triangular part of A is not */
  446. /* > referenced. */
  447. /* > */
  448. /* > If UPLO = 'L': the leading N-by-N lower triangular part */
  449. /* > of A contains the lower triangular part of the matrix A, */
  450. /* > and the strictly upper triangular part of A is not */
  451. /* > referenced. */
  452. /* > */
  453. /* > On exit, contains: */
  454. /* > a) ONLY diagonal elements of the Hermitian block diagonal */
  455. /* > matrix D on the diagonal of A, i.e. D(k,k) = A(k,k); */
  456. /* > (superdiagonal (or subdiagonal) elements of D */
  457. /* > are stored on exit in array E), and */
  458. /* > b) If UPLO = 'U': factor U in the superdiagonal part of A. */
  459. /* > If UPLO = 'L': factor L in the subdiagonal part of A. */
  460. /* > \endverbatim */
  461. /* > */
  462. /* > \param[in] LDA */
  463. /* > \verbatim */
  464. /* > LDA is INTEGER */
  465. /* > The leading dimension of the array A. LDA >= f2cmax(1,N). */
  466. /* > \endverbatim */
  467. /* > */
  468. /* > \param[out] E */
  469. /* > \verbatim */
  470. /* > E is COMPLEX array, dimension (N) */
  471. /* > On exit, contains the superdiagonal (or subdiagonal) */
  472. /* > elements of the Hermitian block diagonal matrix D */
  473. /* > with 1-by-1 or 2-by-2 diagonal blocks, where */
  474. /* > If UPLO = 'U': E(i) = D(i-1,i), i=2:N, E(1) is set to 0; */
  475. /* > If UPLO = 'L': E(i) = D(i+1,i), i=1:N-1, E(N) is set to 0. */
  476. /* > */
  477. /* > NOTE: For 1-by-1 diagonal block D(k), where */
  478. /* > 1 <= k <= N, the element E(k) is set to 0 in both */
  479. /* > UPLO = 'U' or UPLO = 'L' cases. */
  480. /* > \endverbatim */
  481. /* > */
  482. /* > \param[out] IPIV */
  483. /* > \verbatim */
  484. /* > IPIV is INTEGER array, dimension (N) */
  485. /* > IPIV describes the permutation matrix P in the factorization */
  486. /* > of matrix A as follows. The absolute value of IPIV(k) */
  487. /* > represents the index of row and column that were */
  488. /* > interchanged with the k-th row and column. The value of UPLO */
  489. /* > describes the order in which the interchanges were applied. */
  490. /* > Also, the sign of IPIV represents the block structure of */
  491. /* > the Hermitian block diagonal matrix D with 1-by-1 or 2-by-2 */
  492. /* > diagonal blocks which correspond to 1 or 2 interchanges */
  493. /* > at each factorization step. For more info see Further */
  494. /* > Details section. */
  495. /* > */
  496. /* > If UPLO = 'U', */
  497. /* > ( in factorization order, k decreases from N to 1 ): */
  498. /* > a) A single positive entry IPIV(k) > 0 means: */
  499. /* > D(k,k) is a 1-by-1 diagonal block. */
  500. /* > If IPIV(k) != k, rows and columns k and IPIV(k) were */
  501. /* > interchanged in the matrix A(1:N,1:N); */
  502. /* > If IPIV(k) = k, no interchange occurred. */
  503. /* > */
  504. /* > b) A pair of consecutive negative entries */
  505. /* > IPIV(k) < 0 and IPIV(k-1) < 0 means: */
  506. /* > D(k-1:k,k-1:k) is a 2-by-2 diagonal block. */
  507. /* > (NOTE: negative entries in IPIV appear ONLY in pairs). */
  508. /* > 1) If -IPIV(k) != k, rows and columns */
  509. /* > k and -IPIV(k) were interchanged */
  510. /* > in the matrix A(1:N,1:N). */
  511. /* > If -IPIV(k) = k, no interchange occurred. */
  512. /* > 2) If -IPIV(k-1) != k-1, rows and columns */
  513. /* > k-1 and -IPIV(k-1) were interchanged */
  514. /* > in the matrix A(1:N,1:N). */
  515. /* > If -IPIV(k-1) = k-1, no interchange occurred. */
  516. /* > */
  517. /* > c) In both cases a) and b), always ABS( IPIV(k) ) <= k. */
  518. /* > */
  519. /* > d) NOTE: Any entry IPIV(k) is always NONZERO on output. */
  520. /* > */
  521. /* > If UPLO = 'L', */
  522. /* > ( in factorization order, k increases from 1 to N ): */
  523. /* > a) A single positive entry IPIV(k) > 0 means: */
  524. /* > D(k,k) is a 1-by-1 diagonal block. */
  525. /* > If IPIV(k) != k, rows and columns k and IPIV(k) were */
  526. /* > interchanged in the matrix A(1:N,1:N). */
  527. /* > If IPIV(k) = k, no interchange occurred. */
  528. /* > */
  529. /* > b) A pair of consecutive negative entries */
  530. /* > IPIV(k) < 0 and IPIV(k+1) < 0 means: */
  531. /* > D(k:k+1,k:k+1) is a 2-by-2 diagonal block. */
  532. /* > (NOTE: negative entries in IPIV appear ONLY in pairs). */
  533. /* > 1) If -IPIV(k) != k, rows and columns */
  534. /* > k and -IPIV(k) were interchanged */
  535. /* > in the matrix A(1:N,1:N). */
  536. /* > If -IPIV(k) = k, no interchange occurred. */
  537. /* > 2) If -IPIV(k+1) != k+1, rows and columns */
  538. /* > k-1 and -IPIV(k-1) were interchanged */
  539. /* > in the matrix A(1:N,1:N). */
  540. /* > If -IPIV(k+1) = k+1, no interchange occurred. */
  541. /* > */
  542. /* > c) In both cases a) and b), always ABS( IPIV(k) ) >= k. */
  543. /* > */
  544. /* > d) NOTE: Any entry IPIV(k) is always NONZERO on output. */
  545. /* > \endverbatim */
  546. /* > */
  547. /* > \param[out] INFO */
  548. /* > \verbatim */
  549. /* > INFO is INTEGER */
  550. /* > = 0: successful exit */
  551. /* > */
  552. /* > < 0: If INFO = -k, the k-th argument had an illegal value */
  553. /* > */
  554. /* > > 0: If INFO = k, the matrix A is singular, because: */
  555. /* > If UPLO = 'U': column k in the upper */
  556. /* > triangular part of A contains all zeros. */
  557. /* > If UPLO = 'L': column k in the lower */
  558. /* > triangular part of A contains all zeros. */
  559. /* > */
  560. /* > Therefore D(k,k) is exactly zero, and superdiagonal */
  561. /* > elements of column k of U (or subdiagonal elements of */
  562. /* > column k of L ) are all zeros. The factorization has */
  563. /* > been completed, but the block diagonal matrix D is */
  564. /* > exactly singular, and division by zero will occur if */
  565. /* > it is used to solve a system of equations. */
  566. /* > */
  567. /* > NOTE: INFO only stores the first occurrence of */
  568. /* > a singularity, any subsequent occurrence of singularity */
  569. /* > is not stored in INFO even though the factorization */
  570. /* > always completes. */
  571. /* > \endverbatim */
  572. /* Authors: */
  573. /* ======== */
  574. /* > \author Univ. of Tennessee */
  575. /* > \author Univ. of California Berkeley */
  576. /* > \author Univ. of Colorado Denver */
  577. /* > \author NAG Ltd. */
  578. /* > \date December 2016 */
  579. /* > \ingroup complexHEcomputational */
  580. /* > \par Further Details: */
  581. /* ===================== */
  582. /* > */
  583. /* > \verbatim */
  584. /* > TODO: put further details */
  585. /* > \endverbatim */
  586. /* > \par Contributors: */
  587. /* ================== */
  588. /* > */
  589. /* > \verbatim */
  590. /* > */
  591. /* > December 2016, Igor Kozachenko, */
  592. /* > Computer Science Division, */
  593. /* > University of California, Berkeley */
  594. /* > */
  595. /* > September 2007, Sven Hammarling, Nicholas J. Higham, Craig Lucas, */
  596. /* > School of Mathematics, */
  597. /* > University of Manchester */
  598. /* > */
  599. /* > 01-01-96 - Based on modifications by */
  600. /* > J. Lewis, Boeing Computer Services Company */
  601. /* > A. Petitet, Computer Science Dept., */
  602. /* > Univ. of Tenn., Knoxville abd , USA */
  603. /* > \endverbatim */
  604. /* ===================================================================== */
  605. /* Subroutine */ int chetf2_rk_(char *uplo, integer *n, complex *a, integer *
  606. lda, complex *e, integer *ipiv, integer *info)
  607. {
  608. /* System generated locals */
  609. integer a_dim1, a_offset, i__1, i__2, i__3, i__4, i__5, i__6;
  610. real r__1, r__2;
  611. complex q__1, q__2, q__3, q__4, q__5, q__6, q__7, q__8;
  612. /* Local variables */
  613. extern /* Subroutine */ int cher_(char *, integer *, real *, complex *,
  614. integer *, complex *, integer *);
  615. logical done;
  616. integer imax, jmax;
  617. real d__;
  618. integer i__, j, k, p;
  619. complex t;
  620. real alpha;
  621. extern logical lsame_(char *, char *);
  622. real sfmin;
  623. extern /* Subroutine */ int cswap_(integer *, complex *, integer *,
  624. complex *, integer *);
  625. integer itemp, kstep;
  626. real stemp;
  627. logical upper;
  628. real r1, d11;
  629. complex d12;
  630. real d22;
  631. complex d21;
  632. extern real slapy2_(real *, real *);
  633. integer ii, kk, kp;
  634. real absakk;
  635. complex wk;
  636. extern integer icamax_(integer *, complex *, integer *);
  637. extern real slamch_(char *);
  638. real tt;
  639. extern /* Subroutine */ int csscal_(integer *, real *, complex *, integer
  640. *), xerbla_(char *, integer *, ftnlen);
  641. real colmax, rowmax;
  642. complex wkm1, wkp1;
  643. /* -- LAPACK computational routine (version 3.7.0) -- */
  644. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  645. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  646. /* December 2016 */
  647. /* ====================================================================== */
  648. /* Test the input parameters. */
  649. /* Parameter adjustments */
  650. a_dim1 = *lda;
  651. a_offset = 1 + a_dim1 * 1;
  652. a -= a_offset;
  653. --e;
  654. --ipiv;
  655. /* Function Body */
  656. *info = 0;
  657. upper = lsame_(uplo, "U");
  658. if (! upper && ! lsame_(uplo, "L")) {
  659. *info = -1;
  660. } else if (*n < 0) {
  661. *info = -2;
  662. } else if (*lda < f2cmax(1,*n)) {
  663. *info = -4;
  664. }
  665. if (*info != 0) {
  666. i__1 = -(*info);
  667. xerbla_("CHETF2_RK", &i__1, (ftnlen)9);
  668. return 0;
  669. }
  670. /* Initialize ALPHA for use in choosing pivot block size. */
  671. alpha = (sqrt(17.f) + 1.f) / 8.f;
  672. /* Compute machine safe minimum */
  673. sfmin = slamch_("S");
  674. if (upper) {
  675. /* Factorize A as U*D*U**H using the upper triangle of A */
  676. /* Initialize the first entry of array E, where superdiagonal */
  677. /* elements of D are stored */
  678. e[1].r = 0.f, e[1].i = 0.f;
  679. /* K is the main loop index, decreasing from N to 1 in steps of */
  680. /* 1 or 2 */
  681. k = *n;
  682. L10:
  683. /* If K < 1, exit from loop */
  684. if (k < 1) {
  685. goto L34;
  686. }
  687. kstep = 1;
  688. p = k;
  689. /* Determine rows and columns to be interchanged and whether */
  690. /* a 1-by-1 or 2-by-2 pivot block will be used */
  691. i__1 = k + k * a_dim1;
  692. absakk = (r__1 = a[i__1].r, abs(r__1));
  693. /* IMAX is the row-index of the largest off-diagonal element in */
  694. /* column K, and COLMAX is its absolute value. */
  695. /* Determine both COLMAX and IMAX. */
  696. if (k > 1) {
  697. i__1 = k - 1;
  698. imax = icamax_(&i__1, &a[k * a_dim1 + 1], &c__1);
  699. i__1 = imax + k * a_dim1;
  700. colmax = (r__1 = a[i__1].r, abs(r__1)) + (r__2 = r_imag(&a[imax +
  701. k * a_dim1]), abs(r__2));
  702. } else {
  703. colmax = 0.f;
  704. }
  705. if (f2cmax(absakk,colmax) == 0.f) {
  706. /* Column K is zero or underflow: set INFO and continue */
  707. if (*info == 0) {
  708. *info = k;
  709. }
  710. kp = k;
  711. i__1 = k + k * a_dim1;
  712. i__2 = k + k * a_dim1;
  713. r__1 = a[i__2].r;
  714. a[i__1].r = r__1, a[i__1].i = 0.f;
  715. /* Set E( K ) to zero */
  716. if (k > 1) {
  717. i__1 = k;
  718. e[i__1].r = 0.f, e[i__1].i = 0.f;
  719. }
  720. } else {
  721. /* ============================================================ */
  722. /* BEGIN pivot search */
  723. /* Case(1) */
  724. /* Equivalent to testing for ABSAKK.GE.ALPHA*COLMAX */
  725. /* (used to handle NaN and Inf) */
  726. if (! (absakk < alpha * colmax)) {
  727. /* no interchange, use 1-by-1 pivot block */
  728. kp = k;
  729. } else {
  730. done = FALSE_;
  731. /* Loop until pivot found */
  732. L12:
  733. /* BEGIN pivot search loop body */
  734. /* JMAX is the column-index of the largest off-diagonal */
  735. /* element in row IMAX, and ROWMAX is its absolute value. */
  736. /* Determine both ROWMAX and JMAX. */
  737. if (imax != k) {
  738. i__1 = k - imax;
  739. jmax = imax + icamax_(&i__1, &a[imax + (imax + 1) *
  740. a_dim1], lda);
  741. i__1 = imax + jmax * a_dim1;
  742. rowmax = (r__1 = a[i__1].r, abs(r__1)) + (r__2 = r_imag(&
  743. a[imax + jmax * a_dim1]), abs(r__2));
  744. } else {
  745. rowmax = 0.f;
  746. }
  747. if (imax > 1) {
  748. i__1 = imax - 1;
  749. itemp = icamax_(&i__1, &a[imax * a_dim1 + 1], &c__1);
  750. i__1 = itemp + imax * a_dim1;
  751. stemp = (r__1 = a[i__1].r, abs(r__1)) + (r__2 = r_imag(&a[
  752. itemp + imax * a_dim1]), abs(r__2));
  753. if (stemp > rowmax) {
  754. rowmax = stemp;
  755. jmax = itemp;
  756. }
  757. }
  758. /* Case(2) */
  759. /* Equivalent to testing for */
  760. /* ABS( REAL( W( IMAX,KW-1 ) ) ).GE.ALPHA*ROWMAX */
  761. /* (used to handle NaN and Inf) */
  762. i__1 = imax + imax * a_dim1;
  763. if (! ((r__1 = a[i__1].r, abs(r__1)) < alpha * rowmax)) {
  764. /* interchange rows and columns K and IMAX, */
  765. /* use 1-by-1 pivot block */
  766. kp = imax;
  767. done = TRUE_;
  768. /* Case(3) */
  769. /* Equivalent to testing for ROWMAX.EQ.COLMAX, */
  770. /* (used to handle NaN and Inf) */
  771. } else if (p == jmax || rowmax <= colmax) {
  772. /* interchange rows and columns K-1 and IMAX, */
  773. /* use 2-by-2 pivot block */
  774. kp = imax;
  775. kstep = 2;
  776. done = TRUE_;
  777. /* Case(4) */
  778. } else {
  779. /* Pivot not found: set params and repeat */
  780. p = imax;
  781. colmax = rowmax;
  782. imax = jmax;
  783. }
  784. /* END pivot search loop body */
  785. if (! done) {
  786. goto L12;
  787. }
  788. }
  789. /* END pivot search */
  790. /* ============================================================ */
  791. /* KK is the column of A where pivoting step stopped */
  792. kk = k - kstep + 1;
  793. /* For only a 2x2 pivot, interchange rows and columns K and P */
  794. /* in the leading submatrix A(1:k,1:k) */
  795. if (kstep == 2 && p != k) {
  796. /* (1) Swap columnar parts */
  797. if (p > 1) {
  798. i__1 = p - 1;
  799. cswap_(&i__1, &a[k * a_dim1 + 1], &c__1, &a[p * a_dim1 +
  800. 1], &c__1);
  801. }
  802. /* (2) Swap and conjugate middle parts */
  803. i__1 = k - 1;
  804. for (j = p + 1; j <= i__1; ++j) {
  805. r_cnjg(&q__1, &a[j + k * a_dim1]);
  806. t.r = q__1.r, t.i = q__1.i;
  807. i__2 = j + k * a_dim1;
  808. r_cnjg(&q__1, &a[p + j * a_dim1]);
  809. a[i__2].r = q__1.r, a[i__2].i = q__1.i;
  810. i__2 = p + j * a_dim1;
  811. a[i__2].r = t.r, a[i__2].i = t.i;
  812. /* L14: */
  813. }
  814. /* (3) Swap and conjugate corner elements at row-col interserction */
  815. i__1 = p + k * a_dim1;
  816. r_cnjg(&q__1, &a[p + k * a_dim1]);
  817. a[i__1].r = q__1.r, a[i__1].i = q__1.i;
  818. /* (4) Swap diagonal elements at row-col intersection */
  819. i__1 = k + k * a_dim1;
  820. r1 = a[i__1].r;
  821. i__1 = k + k * a_dim1;
  822. i__2 = p + p * a_dim1;
  823. r__1 = a[i__2].r;
  824. a[i__1].r = r__1, a[i__1].i = 0.f;
  825. i__1 = p + p * a_dim1;
  826. a[i__1].r = r1, a[i__1].i = 0.f;
  827. /* Convert upper triangle of A into U form by applying */
  828. /* the interchanges in columns k+1:N. */
  829. if (k < *n) {
  830. i__1 = *n - k;
  831. cswap_(&i__1, &a[k + (k + 1) * a_dim1], lda, &a[p + (k +
  832. 1) * a_dim1], lda);
  833. }
  834. }
  835. /* For both 1x1 and 2x2 pivots, interchange rows and */
  836. /* columns KK and KP in the leading submatrix A(1:k,1:k) */
  837. if (kp != kk) {
  838. /* (1) Swap columnar parts */
  839. if (kp > 1) {
  840. i__1 = kp - 1;
  841. cswap_(&i__1, &a[kk * a_dim1 + 1], &c__1, &a[kp * a_dim1
  842. + 1], &c__1);
  843. }
  844. /* (2) Swap and conjugate middle parts */
  845. i__1 = kk - 1;
  846. for (j = kp + 1; j <= i__1; ++j) {
  847. r_cnjg(&q__1, &a[j + kk * a_dim1]);
  848. t.r = q__1.r, t.i = q__1.i;
  849. i__2 = j + kk * a_dim1;
  850. r_cnjg(&q__1, &a[kp + j * a_dim1]);
  851. a[i__2].r = q__1.r, a[i__2].i = q__1.i;
  852. i__2 = kp + j * a_dim1;
  853. a[i__2].r = t.r, a[i__2].i = t.i;
  854. /* L15: */
  855. }
  856. /* (3) Swap and conjugate corner elements at row-col interserction */
  857. i__1 = kp + kk * a_dim1;
  858. r_cnjg(&q__1, &a[kp + kk * a_dim1]);
  859. a[i__1].r = q__1.r, a[i__1].i = q__1.i;
  860. /* (4) Swap diagonal elements at row-col intersection */
  861. i__1 = kk + kk * a_dim1;
  862. r1 = a[i__1].r;
  863. i__1 = kk + kk * a_dim1;
  864. i__2 = kp + kp * a_dim1;
  865. r__1 = a[i__2].r;
  866. a[i__1].r = r__1, a[i__1].i = 0.f;
  867. i__1 = kp + kp * a_dim1;
  868. a[i__1].r = r1, a[i__1].i = 0.f;
  869. if (kstep == 2) {
  870. /* (*) Make sure that diagonal element of pivot is real */
  871. i__1 = k + k * a_dim1;
  872. i__2 = k + k * a_dim1;
  873. r__1 = a[i__2].r;
  874. a[i__1].r = r__1, a[i__1].i = 0.f;
  875. /* (5) Swap row elements */
  876. i__1 = k - 1 + k * a_dim1;
  877. t.r = a[i__1].r, t.i = a[i__1].i;
  878. i__1 = k - 1 + k * a_dim1;
  879. i__2 = kp + k * a_dim1;
  880. a[i__1].r = a[i__2].r, a[i__1].i = a[i__2].i;
  881. i__1 = kp + k * a_dim1;
  882. a[i__1].r = t.r, a[i__1].i = t.i;
  883. }
  884. /* Convert upper triangle of A into U form by applying */
  885. /* the interchanges in columns k+1:N. */
  886. if (k < *n) {
  887. i__1 = *n - k;
  888. cswap_(&i__1, &a[kk + (k + 1) * a_dim1], lda, &a[kp + (k
  889. + 1) * a_dim1], lda);
  890. }
  891. } else {
  892. /* (*) Make sure that diagonal element of pivot is real */
  893. i__1 = k + k * a_dim1;
  894. i__2 = k + k * a_dim1;
  895. r__1 = a[i__2].r;
  896. a[i__1].r = r__1, a[i__1].i = 0.f;
  897. if (kstep == 2) {
  898. i__1 = k - 1 + (k - 1) * a_dim1;
  899. i__2 = k - 1 + (k - 1) * a_dim1;
  900. r__1 = a[i__2].r;
  901. a[i__1].r = r__1, a[i__1].i = 0.f;
  902. }
  903. }
  904. /* Update the leading submatrix */
  905. if (kstep == 1) {
  906. /* 1-by-1 pivot block D(k): column k now holds */
  907. /* W(k) = U(k)*D(k) */
  908. /* where U(k) is the k-th column of U */
  909. if (k > 1) {
  910. /* Perform a rank-1 update of A(1:k-1,1:k-1) and */
  911. /* store U(k) in column k */
  912. i__1 = k + k * a_dim1;
  913. if ((r__1 = a[i__1].r, abs(r__1)) >= sfmin) {
  914. /* Perform a rank-1 update of A(1:k-1,1:k-1) as */
  915. /* A := A - U(k)*D(k)*U(k)**T */
  916. /* = A - W(k)*1/D(k)*W(k)**T */
  917. i__1 = k + k * a_dim1;
  918. d11 = 1.f / a[i__1].r;
  919. i__1 = k - 1;
  920. r__1 = -d11;
  921. cher_(uplo, &i__1, &r__1, &a[k * a_dim1 + 1], &c__1, &
  922. a[a_offset], lda);
  923. /* Store U(k) in column k */
  924. i__1 = k - 1;
  925. csscal_(&i__1, &d11, &a[k * a_dim1 + 1], &c__1);
  926. } else {
  927. /* Store L(k) in column K */
  928. i__1 = k + k * a_dim1;
  929. d11 = a[i__1].r;
  930. i__1 = k - 1;
  931. for (ii = 1; ii <= i__1; ++ii) {
  932. i__2 = ii + k * a_dim1;
  933. i__3 = ii + k * a_dim1;
  934. q__1.r = a[i__3].r / d11, q__1.i = a[i__3].i /
  935. d11;
  936. a[i__2].r = q__1.r, a[i__2].i = q__1.i;
  937. /* L16: */
  938. }
  939. /* Perform a rank-1 update of A(k+1:n,k+1:n) as */
  940. /* A := A - U(k)*D(k)*U(k)**T */
  941. /* = A - W(k)*(1/D(k))*W(k)**T */
  942. /* = A - (W(k)/D(k))*(D(k))*(W(k)/D(K))**T */
  943. i__1 = k - 1;
  944. r__1 = -d11;
  945. cher_(uplo, &i__1, &r__1, &a[k * a_dim1 + 1], &c__1, &
  946. a[a_offset], lda);
  947. }
  948. /* Store the superdiagonal element of D in array E */
  949. i__1 = k;
  950. e[i__1].r = 0.f, e[i__1].i = 0.f;
  951. }
  952. } else {
  953. /* 2-by-2 pivot block D(k): columns k and k-1 now hold */
  954. /* ( W(k-1) W(k) ) = ( U(k-1) U(k) )*D(k) */
  955. /* where U(k) and U(k-1) are the k-th and (k-1)-th columns */
  956. /* of U */
  957. /* Perform a rank-2 update of A(1:k-2,1:k-2) as */
  958. /* A := A - ( U(k-1) U(k) )*D(k)*( U(k-1) U(k) )**T */
  959. /* = A - ( ( A(k-1)A(k) )*inv(D(k)) ) * ( A(k-1)A(k) )**T */
  960. /* and store L(k) and L(k+1) in columns k and k+1 */
  961. if (k > 2) {
  962. /* D = |A12| */
  963. i__1 = k - 1 + k * a_dim1;
  964. r__1 = a[i__1].r;
  965. r__2 = r_imag(&a[k - 1 + k * a_dim1]);
  966. d__ = slapy2_(&r__1, &r__2);
  967. i__1 = k + k * a_dim1;
  968. q__1.r = a[i__1].r / d__, q__1.i = a[i__1].i / d__;
  969. d11 = q__1.r;
  970. i__1 = k - 1 + (k - 1) * a_dim1;
  971. q__1.r = a[i__1].r / d__, q__1.i = a[i__1].i / d__;
  972. d22 = q__1.r;
  973. i__1 = k - 1 + k * a_dim1;
  974. q__1.r = a[i__1].r / d__, q__1.i = a[i__1].i / d__;
  975. d12.r = q__1.r, d12.i = q__1.i;
  976. tt = 1.f / (d11 * d22 - 1.f);
  977. for (j = k - 2; j >= 1; --j) {
  978. /* Compute D21 * ( W(k)W(k+1) ) * inv(D(k)) for row J */
  979. i__1 = j + (k - 1) * a_dim1;
  980. q__3.r = d11 * a[i__1].r, q__3.i = d11 * a[i__1].i;
  981. r_cnjg(&q__5, &d12);
  982. i__2 = j + k * a_dim1;
  983. q__4.r = q__5.r * a[i__2].r - q__5.i * a[i__2].i,
  984. q__4.i = q__5.r * a[i__2].i + q__5.i * a[i__2]
  985. .r;
  986. q__2.r = q__3.r - q__4.r, q__2.i = q__3.i - q__4.i;
  987. q__1.r = tt * q__2.r, q__1.i = tt * q__2.i;
  988. wkm1.r = q__1.r, wkm1.i = q__1.i;
  989. i__1 = j + k * a_dim1;
  990. q__3.r = d22 * a[i__1].r, q__3.i = d22 * a[i__1].i;
  991. i__2 = j + (k - 1) * a_dim1;
  992. q__4.r = d12.r * a[i__2].r - d12.i * a[i__2].i,
  993. q__4.i = d12.r * a[i__2].i + d12.i * a[i__2]
  994. .r;
  995. q__2.r = q__3.r - q__4.r, q__2.i = q__3.i - q__4.i;
  996. q__1.r = tt * q__2.r, q__1.i = tt * q__2.i;
  997. wk.r = q__1.r, wk.i = q__1.i;
  998. /* Perform a rank-2 update of A(1:k-2,1:k-2) */
  999. for (i__ = j; i__ >= 1; --i__) {
  1000. i__1 = i__ + j * a_dim1;
  1001. i__2 = i__ + j * a_dim1;
  1002. i__3 = i__ + k * a_dim1;
  1003. q__4.r = a[i__3].r / d__, q__4.i = a[i__3].i /
  1004. d__;
  1005. r_cnjg(&q__5, &wk);
  1006. q__3.r = q__4.r * q__5.r - q__4.i * q__5.i,
  1007. q__3.i = q__4.r * q__5.i + q__4.i *
  1008. q__5.r;
  1009. q__2.r = a[i__2].r - q__3.r, q__2.i = a[i__2].i -
  1010. q__3.i;
  1011. i__4 = i__ + (k - 1) * a_dim1;
  1012. q__7.r = a[i__4].r / d__, q__7.i = a[i__4].i /
  1013. d__;
  1014. r_cnjg(&q__8, &wkm1);
  1015. q__6.r = q__7.r * q__8.r - q__7.i * q__8.i,
  1016. q__6.i = q__7.r * q__8.i + q__7.i *
  1017. q__8.r;
  1018. q__1.r = q__2.r - q__6.r, q__1.i = q__2.i -
  1019. q__6.i;
  1020. a[i__1].r = q__1.r, a[i__1].i = q__1.i;
  1021. /* L20: */
  1022. }
  1023. /* Store U(k) and U(k-1) in cols k and k-1 for row J */
  1024. i__1 = j + k * a_dim1;
  1025. q__1.r = wk.r / d__, q__1.i = wk.i / d__;
  1026. a[i__1].r = q__1.r, a[i__1].i = q__1.i;
  1027. i__1 = j + (k - 1) * a_dim1;
  1028. q__1.r = wkm1.r / d__, q__1.i = wkm1.i / d__;
  1029. a[i__1].r = q__1.r, a[i__1].i = q__1.i;
  1030. /* (*) Make sure that diagonal element of pivot is real */
  1031. i__1 = j + j * a_dim1;
  1032. i__2 = j + j * a_dim1;
  1033. r__1 = a[i__2].r;
  1034. q__1.r = r__1, q__1.i = 0.f;
  1035. a[i__1].r = q__1.r, a[i__1].i = q__1.i;
  1036. /* L30: */
  1037. }
  1038. }
  1039. /* Copy superdiagonal elements of D(K) to E(K) and */
  1040. /* ZERO out superdiagonal entry of A */
  1041. i__1 = k;
  1042. i__2 = k - 1 + k * a_dim1;
  1043. e[i__1].r = a[i__2].r, e[i__1].i = a[i__2].i;
  1044. i__1 = k - 1;
  1045. e[i__1].r = 0.f, e[i__1].i = 0.f;
  1046. i__1 = k - 1 + k * a_dim1;
  1047. a[i__1].r = 0.f, a[i__1].i = 0.f;
  1048. }
  1049. /* End column K is nonsingular */
  1050. }
  1051. /* Store details of the interchanges in IPIV */
  1052. if (kstep == 1) {
  1053. ipiv[k] = kp;
  1054. } else {
  1055. ipiv[k] = -p;
  1056. ipiv[k - 1] = -kp;
  1057. }
  1058. /* Decrease K and return to the start of the main loop */
  1059. k -= kstep;
  1060. goto L10;
  1061. L34:
  1062. ;
  1063. } else {
  1064. /* Factorize A as L*D*L**H using the lower triangle of A */
  1065. /* Initialize the unused last entry of the subdiagonal array E. */
  1066. i__1 = *n;
  1067. e[i__1].r = 0.f, e[i__1].i = 0.f;
  1068. /* K is the main loop index, increasing from 1 to N in steps of */
  1069. /* 1 or 2 */
  1070. k = 1;
  1071. L40:
  1072. /* If K > N, exit from loop */
  1073. if (k > *n) {
  1074. goto L64;
  1075. }
  1076. kstep = 1;
  1077. p = k;
  1078. /* Determine rows and columns to be interchanged and whether */
  1079. /* a 1-by-1 or 2-by-2 pivot block will be used */
  1080. i__1 = k + k * a_dim1;
  1081. absakk = (r__1 = a[i__1].r, abs(r__1));
  1082. /* IMAX is the row-index of the largest off-diagonal element in */
  1083. /* column K, and COLMAX is its absolute value. */
  1084. /* Determine both COLMAX and IMAX. */
  1085. if (k < *n) {
  1086. i__1 = *n - k;
  1087. imax = k + icamax_(&i__1, &a[k + 1 + k * a_dim1], &c__1);
  1088. i__1 = imax + k * a_dim1;
  1089. colmax = (r__1 = a[i__1].r, abs(r__1)) + (r__2 = r_imag(&a[imax +
  1090. k * a_dim1]), abs(r__2));
  1091. } else {
  1092. colmax = 0.f;
  1093. }
  1094. if (f2cmax(absakk,colmax) == 0.f) {
  1095. /* Column K is zero or underflow: set INFO and continue */
  1096. if (*info == 0) {
  1097. *info = k;
  1098. }
  1099. kp = k;
  1100. i__1 = k + k * a_dim1;
  1101. i__2 = k + k * a_dim1;
  1102. r__1 = a[i__2].r;
  1103. a[i__1].r = r__1, a[i__1].i = 0.f;
  1104. /* Set E( K ) to zero */
  1105. if (k < *n) {
  1106. i__1 = k;
  1107. e[i__1].r = 0.f, e[i__1].i = 0.f;
  1108. }
  1109. } else {
  1110. /* ============================================================ */
  1111. /* BEGIN pivot search */
  1112. /* Case(1) */
  1113. /* Equivalent to testing for ABSAKK.GE.ALPHA*COLMAX */
  1114. /* (used to handle NaN and Inf) */
  1115. if (! (absakk < alpha * colmax)) {
  1116. /* no interchange, use 1-by-1 pivot block */
  1117. kp = k;
  1118. } else {
  1119. done = FALSE_;
  1120. /* Loop until pivot found */
  1121. L42:
  1122. /* BEGIN pivot search loop body */
  1123. /* JMAX is the column-index of the largest off-diagonal */
  1124. /* element in row IMAX, and ROWMAX is its absolute value. */
  1125. /* Determine both ROWMAX and JMAX. */
  1126. if (imax != k) {
  1127. i__1 = imax - k;
  1128. jmax = k - 1 + icamax_(&i__1, &a[imax + k * a_dim1], lda);
  1129. i__1 = imax + jmax * a_dim1;
  1130. rowmax = (r__1 = a[i__1].r, abs(r__1)) + (r__2 = r_imag(&
  1131. a[imax + jmax * a_dim1]), abs(r__2));
  1132. } else {
  1133. rowmax = 0.f;
  1134. }
  1135. if (imax < *n) {
  1136. i__1 = *n - imax;
  1137. itemp = imax + icamax_(&i__1, &a[imax + 1 + imax * a_dim1]
  1138. , &c__1);
  1139. i__1 = itemp + imax * a_dim1;
  1140. stemp = (r__1 = a[i__1].r, abs(r__1)) + (r__2 = r_imag(&a[
  1141. itemp + imax * a_dim1]), abs(r__2));
  1142. if (stemp > rowmax) {
  1143. rowmax = stemp;
  1144. jmax = itemp;
  1145. }
  1146. }
  1147. /* Case(2) */
  1148. /* Equivalent to testing for */
  1149. /* ABS( REAL( W( IMAX,KW-1 ) ) ).GE.ALPHA*ROWMAX */
  1150. /* (used to handle NaN and Inf) */
  1151. i__1 = imax + imax * a_dim1;
  1152. if (! ((r__1 = a[i__1].r, abs(r__1)) < alpha * rowmax)) {
  1153. /* interchange rows and columns K and IMAX, */
  1154. /* use 1-by-1 pivot block */
  1155. kp = imax;
  1156. done = TRUE_;
  1157. /* Case(3) */
  1158. /* Equivalent to testing for ROWMAX.EQ.COLMAX, */
  1159. /* (used to handle NaN and Inf) */
  1160. } else if (p == jmax || rowmax <= colmax) {
  1161. /* interchange rows and columns K+1 and IMAX, */
  1162. /* use 2-by-2 pivot block */
  1163. kp = imax;
  1164. kstep = 2;
  1165. done = TRUE_;
  1166. /* Case(4) */
  1167. } else {
  1168. /* Pivot not found: set params and repeat */
  1169. p = imax;
  1170. colmax = rowmax;
  1171. imax = jmax;
  1172. }
  1173. /* END pivot search loop body */
  1174. if (! done) {
  1175. goto L42;
  1176. }
  1177. }
  1178. /* END pivot search */
  1179. /* ============================================================ */
  1180. /* KK is the column of A where pivoting step stopped */
  1181. kk = k + kstep - 1;
  1182. /* For only a 2x2 pivot, interchange rows and columns K and P */
  1183. /* in the trailing submatrix A(k:n,k:n) */
  1184. if (kstep == 2 && p != k) {
  1185. /* (1) Swap columnar parts */
  1186. if (p < *n) {
  1187. i__1 = *n - p;
  1188. cswap_(&i__1, &a[p + 1 + k * a_dim1], &c__1, &a[p + 1 + p
  1189. * a_dim1], &c__1);
  1190. }
  1191. /* (2) Swap and conjugate middle parts */
  1192. i__1 = p - 1;
  1193. for (j = k + 1; j <= i__1; ++j) {
  1194. r_cnjg(&q__1, &a[j + k * a_dim1]);
  1195. t.r = q__1.r, t.i = q__1.i;
  1196. i__2 = j + k * a_dim1;
  1197. r_cnjg(&q__1, &a[p + j * a_dim1]);
  1198. a[i__2].r = q__1.r, a[i__2].i = q__1.i;
  1199. i__2 = p + j * a_dim1;
  1200. a[i__2].r = t.r, a[i__2].i = t.i;
  1201. /* L44: */
  1202. }
  1203. /* (3) Swap and conjugate corner elements at row-col interserction */
  1204. i__1 = p + k * a_dim1;
  1205. r_cnjg(&q__1, &a[p + k * a_dim1]);
  1206. a[i__1].r = q__1.r, a[i__1].i = q__1.i;
  1207. /* (4) Swap diagonal elements at row-col intersection */
  1208. i__1 = k + k * a_dim1;
  1209. r1 = a[i__1].r;
  1210. i__1 = k + k * a_dim1;
  1211. i__2 = p + p * a_dim1;
  1212. r__1 = a[i__2].r;
  1213. a[i__1].r = r__1, a[i__1].i = 0.f;
  1214. i__1 = p + p * a_dim1;
  1215. a[i__1].r = r1, a[i__1].i = 0.f;
  1216. /* Convert lower triangle of A into L form by applying */
  1217. /* the interchanges in columns 1:k-1. */
  1218. if (k > 1) {
  1219. i__1 = k - 1;
  1220. cswap_(&i__1, &a[k + a_dim1], lda, &a[p + a_dim1], lda);
  1221. }
  1222. }
  1223. /* For both 1x1 and 2x2 pivots, interchange rows and */
  1224. /* columns KK and KP in the trailing submatrix A(k:n,k:n) */
  1225. if (kp != kk) {
  1226. /* (1) Swap columnar parts */
  1227. if (kp < *n) {
  1228. i__1 = *n - kp;
  1229. cswap_(&i__1, &a[kp + 1 + kk * a_dim1], &c__1, &a[kp + 1
  1230. + kp * a_dim1], &c__1);
  1231. }
  1232. /* (2) Swap and conjugate middle parts */
  1233. i__1 = kp - 1;
  1234. for (j = kk + 1; j <= i__1; ++j) {
  1235. r_cnjg(&q__1, &a[j + kk * a_dim1]);
  1236. t.r = q__1.r, t.i = q__1.i;
  1237. i__2 = j + kk * a_dim1;
  1238. r_cnjg(&q__1, &a[kp + j * a_dim1]);
  1239. a[i__2].r = q__1.r, a[i__2].i = q__1.i;
  1240. i__2 = kp + j * a_dim1;
  1241. a[i__2].r = t.r, a[i__2].i = t.i;
  1242. /* L45: */
  1243. }
  1244. /* (3) Swap and conjugate corner elements at row-col interserction */
  1245. i__1 = kp + kk * a_dim1;
  1246. r_cnjg(&q__1, &a[kp + kk * a_dim1]);
  1247. a[i__1].r = q__1.r, a[i__1].i = q__1.i;
  1248. /* (4) Swap diagonal elements at row-col intersection */
  1249. i__1 = kk + kk * a_dim1;
  1250. r1 = a[i__1].r;
  1251. i__1 = kk + kk * a_dim1;
  1252. i__2 = kp + kp * a_dim1;
  1253. r__1 = a[i__2].r;
  1254. a[i__1].r = r__1, a[i__1].i = 0.f;
  1255. i__1 = kp + kp * a_dim1;
  1256. a[i__1].r = r1, a[i__1].i = 0.f;
  1257. if (kstep == 2) {
  1258. /* (*) Make sure that diagonal element of pivot is real */
  1259. i__1 = k + k * a_dim1;
  1260. i__2 = k + k * a_dim1;
  1261. r__1 = a[i__2].r;
  1262. a[i__1].r = r__1, a[i__1].i = 0.f;
  1263. /* (5) Swap row elements */
  1264. i__1 = k + 1 + k * a_dim1;
  1265. t.r = a[i__1].r, t.i = a[i__1].i;
  1266. i__1 = k + 1 + k * a_dim1;
  1267. i__2 = kp + k * a_dim1;
  1268. a[i__1].r = a[i__2].r, a[i__1].i = a[i__2].i;
  1269. i__1 = kp + k * a_dim1;
  1270. a[i__1].r = t.r, a[i__1].i = t.i;
  1271. }
  1272. /* Convert lower triangle of A into L form by applying */
  1273. /* the interchanges in columns 1:k-1. */
  1274. if (k > 1) {
  1275. i__1 = k - 1;
  1276. cswap_(&i__1, &a[kk + a_dim1], lda, &a[kp + a_dim1], lda);
  1277. }
  1278. } else {
  1279. /* (*) Make sure that diagonal element of pivot is real */
  1280. i__1 = k + k * a_dim1;
  1281. i__2 = k + k * a_dim1;
  1282. r__1 = a[i__2].r;
  1283. a[i__1].r = r__1, a[i__1].i = 0.f;
  1284. if (kstep == 2) {
  1285. i__1 = k + 1 + (k + 1) * a_dim1;
  1286. i__2 = k + 1 + (k + 1) * a_dim1;
  1287. r__1 = a[i__2].r;
  1288. a[i__1].r = r__1, a[i__1].i = 0.f;
  1289. }
  1290. }
  1291. /* Update the trailing submatrix */
  1292. if (kstep == 1) {
  1293. /* 1-by-1 pivot block D(k): column k of A now holds */
  1294. /* W(k) = L(k)*D(k), */
  1295. /* where L(k) is the k-th column of L */
  1296. if (k < *n) {
  1297. /* Perform a rank-1 update of A(k+1:n,k+1:n) and */
  1298. /* store L(k) in column k */
  1299. /* Handle division by a small number */
  1300. i__1 = k + k * a_dim1;
  1301. if ((r__1 = a[i__1].r, abs(r__1)) >= sfmin) {
  1302. /* Perform a rank-1 update of A(k+1:n,k+1:n) as */
  1303. /* A := A - L(k)*D(k)*L(k)**T */
  1304. /* = A - W(k)*(1/D(k))*W(k)**T */
  1305. i__1 = k + k * a_dim1;
  1306. d11 = 1.f / a[i__1].r;
  1307. i__1 = *n - k;
  1308. r__1 = -d11;
  1309. cher_(uplo, &i__1, &r__1, &a[k + 1 + k * a_dim1], &
  1310. c__1, &a[k + 1 + (k + 1) * a_dim1], lda);
  1311. /* Store L(k) in column k */
  1312. i__1 = *n - k;
  1313. csscal_(&i__1, &d11, &a[k + 1 + k * a_dim1], &c__1);
  1314. } else {
  1315. /* Store L(k) in column k */
  1316. i__1 = k + k * a_dim1;
  1317. d11 = a[i__1].r;
  1318. i__1 = *n;
  1319. for (ii = k + 1; ii <= i__1; ++ii) {
  1320. i__2 = ii + k * a_dim1;
  1321. i__3 = ii + k * a_dim1;
  1322. q__1.r = a[i__3].r / d11, q__1.i = a[i__3].i /
  1323. d11;
  1324. a[i__2].r = q__1.r, a[i__2].i = q__1.i;
  1325. /* L46: */
  1326. }
  1327. /* Perform a rank-1 update of A(k+1:n,k+1:n) as */
  1328. /* A := A - L(k)*D(k)*L(k)**T */
  1329. /* = A - W(k)*(1/D(k))*W(k)**T */
  1330. /* = A - (W(k)/D(k))*(D(k))*(W(k)/D(K))**T */
  1331. i__1 = *n - k;
  1332. r__1 = -d11;
  1333. cher_(uplo, &i__1, &r__1, &a[k + 1 + k * a_dim1], &
  1334. c__1, &a[k + 1 + (k + 1) * a_dim1], lda);
  1335. }
  1336. /* Store the subdiagonal element of D in array E */
  1337. i__1 = k;
  1338. e[i__1].r = 0.f, e[i__1].i = 0.f;
  1339. }
  1340. } else {
  1341. /* 2-by-2 pivot block D(k): columns k and k+1 now hold */
  1342. /* ( W(k) W(k+1) ) = ( L(k) L(k+1) )*D(k) */
  1343. /* where L(k) and L(k+1) are the k-th and (k+1)-th columns */
  1344. /* of L */
  1345. /* Perform a rank-2 update of A(k+2:n,k+2:n) as */
  1346. /* A := A - ( L(k) L(k+1) ) * D(k) * ( L(k) L(k+1) )**T */
  1347. /* = A - ( ( A(k)A(k+1) )*inv(D(k) ) * ( A(k)A(k+1) )**T */
  1348. /* and store L(k) and L(k+1) in columns k and k+1 */
  1349. if (k < *n - 1) {
  1350. /* D = |A21| */
  1351. i__1 = k + 1 + k * a_dim1;
  1352. r__1 = a[i__1].r;
  1353. r__2 = r_imag(&a[k + 1 + k * a_dim1]);
  1354. d__ = slapy2_(&r__1, &r__2);
  1355. i__1 = k + 1 + (k + 1) * a_dim1;
  1356. d11 = a[i__1].r / d__;
  1357. i__1 = k + k * a_dim1;
  1358. d22 = a[i__1].r / d__;
  1359. i__1 = k + 1 + k * a_dim1;
  1360. q__1.r = a[i__1].r / d__, q__1.i = a[i__1].i / d__;
  1361. d21.r = q__1.r, d21.i = q__1.i;
  1362. tt = 1.f / (d11 * d22 - 1.f);
  1363. i__1 = *n;
  1364. for (j = k + 2; j <= i__1; ++j) {
  1365. /* Compute D21 * ( W(k)W(k+1) ) * inv(D(k)) for row J */
  1366. i__2 = j + k * a_dim1;
  1367. q__3.r = d11 * a[i__2].r, q__3.i = d11 * a[i__2].i;
  1368. i__3 = j + (k + 1) * a_dim1;
  1369. q__4.r = d21.r * a[i__3].r - d21.i * a[i__3].i,
  1370. q__4.i = d21.r * a[i__3].i + d21.i * a[i__3]
  1371. .r;
  1372. q__2.r = q__3.r - q__4.r, q__2.i = q__3.i - q__4.i;
  1373. q__1.r = tt * q__2.r, q__1.i = tt * q__2.i;
  1374. wk.r = q__1.r, wk.i = q__1.i;
  1375. i__2 = j + (k + 1) * a_dim1;
  1376. q__3.r = d22 * a[i__2].r, q__3.i = d22 * a[i__2].i;
  1377. r_cnjg(&q__5, &d21);
  1378. i__3 = j + k * a_dim1;
  1379. q__4.r = q__5.r * a[i__3].r - q__5.i * a[i__3].i,
  1380. q__4.i = q__5.r * a[i__3].i + q__5.i * a[i__3]
  1381. .r;
  1382. q__2.r = q__3.r - q__4.r, q__2.i = q__3.i - q__4.i;
  1383. q__1.r = tt * q__2.r, q__1.i = tt * q__2.i;
  1384. wkp1.r = q__1.r, wkp1.i = q__1.i;
  1385. /* Perform a rank-2 update of A(k+2:n,k+2:n) */
  1386. i__2 = *n;
  1387. for (i__ = j; i__ <= i__2; ++i__) {
  1388. i__3 = i__ + j * a_dim1;
  1389. i__4 = i__ + j * a_dim1;
  1390. i__5 = i__ + k * a_dim1;
  1391. q__4.r = a[i__5].r / d__, q__4.i = a[i__5].i /
  1392. d__;
  1393. r_cnjg(&q__5, &wk);
  1394. q__3.r = q__4.r * q__5.r - q__4.i * q__5.i,
  1395. q__3.i = q__4.r * q__5.i + q__4.i *
  1396. q__5.r;
  1397. q__2.r = a[i__4].r - q__3.r, q__2.i = a[i__4].i -
  1398. q__3.i;
  1399. i__6 = i__ + (k + 1) * a_dim1;
  1400. q__7.r = a[i__6].r / d__, q__7.i = a[i__6].i /
  1401. d__;
  1402. r_cnjg(&q__8, &wkp1);
  1403. q__6.r = q__7.r * q__8.r - q__7.i * q__8.i,
  1404. q__6.i = q__7.r * q__8.i + q__7.i *
  1405. q__8.r;
  1406. q__1.r = q__2.r - q__6.r, q__1.i = q__2.i -
  1407. q__6.i;
  1408. a[i__3].r = q__1.r, a[i__3].i = q__1.i;
  1409. /* L50: */
  1410. }
  1411. /* Store L(k) and L(k+1) in cols k and k+1 for row J */
  1412. i__2 = j + k * a_dim1;
  1413. q__1.r = wk.r / d__, q__1.i = wk.i / d__;
  1414. a[i__2].r = q__1.r, a[i__2].i = q__1.i;
  1415. i__2 = j + (k + 1) * a_dim1;
  1416. q__1.r = wkp1.r / d__, q__1.i = wkp1.i / d__;
  1417. a[i__2].r = q__1.r, a[i__2].i = q__1.i;
  1418. /* (*) Make sure that diagonal element of pivot is real */
  1419. i__2 = j + j * a_dim1;
  1420. i__3 = j + j * a_dim1;
  1421. r__1 = a[i__3].r;
  1422. q__1.r = r__1, q__1.i = 0.f;
  1423. a[i__2].r = q__1.r, a[i__2].i = q__1.i;
  1424. /* L60: */
  1425. }
  1426. }
  1427. /* Copy subdiagonal elements of D(K) to E(K) and */
  1428. /* ZERO out subdiagonal entry of A */
  1429. i__1 = k;
  1430. i__2 = k + 1 + k * a_dim1;
  1431. e[i__1].r = a[i__2].r, e[i__1].i = a[i__2].i;
  1432. i__1 = k + 1;
  1433. e[i__1].r = 0.f, e[i__1].i = 0.f;
  1434. i__1 = k + 1 + k * a_dim1;
  1435. a[i__1].r = 0.f, a[i__1].i = 0.f;
  1436. }
  1437. /* End column K is nonsingular */
  1438. }
  1439. /* Store details of the interchanges in IPIV */
  1440. if (kstep == 1) {
  1441. ipiv[k] = kp;
  1442. } else {
  1443. ipiv[k] = -p;
  1444. ipiv[k + 1] = -kp;
  1445. }
  1446. /* Increase K and return to the start of the main loop */
  1447. k += kstep;
  1448. goto L40;
  1449. L64:
  1450. ;
  1451. }
  1452. return 0;
  1453. /* End of CHETF2_RK */
  1454. } /* chetf2_rk__ */