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.

zlahqr.c 40 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326
  1. #include <math.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <stdio.h>
  5. #include <complex.h>
  6. #ifdef complex
  7. #undef complex
  8. #endif
  9. #ifdef I
  10. #undef I
  11. #endif
  12. #if defined(_WIN64)
  13. typedef long long BLASLONG;
  14. typedef unsigned long long BLASULONG;
  15. #else
  16. typedef long BLASLONG;
  17. typedef unsigned long BLASULONG;
  18. #endif
  19. #ifdef LAPACK_ILP64
  20. typedef BLASLONG blasint;
  21. #if defined(_WIN64)
  22. #define blasabs(x) llabs(x)
  23. #else
  24. #define blasabs(x) labs(x)
  25. #endif
  26. #else
  27. typedef int blasint;
  28. #define blasabs(x) abs(x)
  29. #endif
  30. typedef blasint integer;
  31. typedef unsigned int uinteger;
  32. typedef char *address;
  33. typedef short int shortint;
  34. typedef float real;
  35. typedef double doublereal;
  36. typedef struct { real r, i; } complex;
  37. typedef struct { doublereal r, i; } doublecomplex;
  38. #ifdef _MSC_VER
  39. static inline _Fcomplex Cf(complex *z) {_Fcomplex zz={z->r , z->i}; return zz;}
  40. static inline _Dcomplex Cd(doublecomplex *z) {_Dcomplex zz={z->r , z->i};return zz;}
  41. static inline _Fcomplex * _pCf(complex *z) {return (_Fcomplex*)z;}
  42. static inline _Dcomplex * _pCd(doublecomplex *z) {return (_Dcomplex*)z;}
  43. #else
  44. static inline _Complex float Cf(complex *z) {return z->r + z->i*_Complex_I;}
  45. static inline _Complex double Cd(doublecomplex *z) {return z->r + z->i*_Complex_I;}
  46. static inline _Complex float * _pCf(complex *z) {return (_Complex float*)z;}
  47. static inline _Complex double * _pCd(doublecomplex *z) {return (_Complex double*)z;}
  48. #endif
  49. #define pCf(z) (*_pCf(z))
  50. #define pCd(z) (*_pCd(z))
  51. typedef blasint logical;
  52. typedef char logical1;
  53. typedef char integer1;
  54. #define TRUE_ (1)
  55. #define FALSE_ (0)
  56. /* Extern is for use with -E */
  57. #ifndef Extern
  58. #define Extern extern
  59. #endif
  60. /* I/O stuff */
  61. typedef int flag;
  62. typedef int ftnlen;
  63. typedef int ftnint;
  64. /*external read, write*/
  65. typedef struct
  66. { flag cierr;
  67. ftnint ciunit;
  68. flag ciend;
  69. char *cifmt;
  70. ftnint cirec;
  71. } cilist;
  72. /*internal read, write*/
  73. typedef struct
  74. { flag icierr;
  75. char *iciunit;
  76. flag iciend;
  77. char *icifmt;
  78. ftnint icirlen;
  79. ftnint icirnum;
  80. } icilist;
  81. /*open*/
  82. typedef struct
  83. { flag oerr;
  84. ftnint ounit;
  85. char *ofnm;
  86. ftnlen ofnmlen;
  87. char *osta;
  88. char *oacc;
  89. char *ofm;
  90. ftnint orl;
  91. char *oblnk;
  92. } olist;
  93. /*close*/
  94. typedef struct
  95. { flag cerr;
  96. ftnint cunit;
  97. char *csta;
  98. } cllist;
  99. /*rewind, backspace, endfile*/
  100. typedef struct
  101. { flag aerr;
  102. ftnint aunit;
  103. } alist;
  104. /* inquire */
  105. typedef struct
  106. { flag inerr;
  107. ftnint inunit;
  108. char *infile;
  109. ftnlen infilen;
  110. ftnint *inex; /*parameters in standard's order*/
  111. ftnint *inopen;
  112. ftnint *innum;
  113. ftnint *innamed;
  114. char *inname;
  115. ftnlen innamlen;
  116. char *inacc;
  117. ftnlen inacclen;
  118. char *inseq;
  119. ftnlen inseqlen;
  120. char *indir;
  121. ftnlen indirlen;
  122. char *infmt;
  123. ftnlen infmtlen;
  124. char *inform;
  125. ftnint informlen;
  126. char *inunf;
  127. ftnlen inunflen;
  128. ftnint *inrecl;
  129. ftnint *innrec;
  130. char *inblank;
  131. ftnlen inblanklen;
  132. } inlist;
  133. #define VOID void
  134. union Multitype { /* for multiple entry points */
  135. integer1 g;
  136. shortint h;
  137. integer i;
  138. /* longint j; */
  139. real r;
  140. doublereal d;
  141. complex c;
  142. doublecomplex z;
  143. };
  144. typedef union Multitype Multitype;
  145. struct Vardesc { /* for Namelist */
  146. char *name;
  147. char *addr;
  148. ftnlen *dims;
  149. int type;
  150. };
  151. typedef struct Vardesc Vardesc;
  152. struct Namelist {
  153. char *name;
  154. Vardesc **vars;
  155. int nvars;
  156. };
  157. typedef struct Namelist Namelist;
  158. #define abs(x) ((x) >= 0 ? (x) : -(x))
  159. #define dabs(x) (fabs(x))
  160. #define f2cmin(a,b) ((a) <= (b) ? (a) : (b))
  161. #define f2cmax(a,b) ((a) >= (b) ? (a) : (b))
  162. #define dmin(a,b) (f2cmin(a,b))
  163. #define dmax(a,b) (f2cmax(a,b))
  164. #define bit_test(a,b) ((a) >> (b) & 1)
  165. #define bit_clear(a,b) ((a) & ~((uinteger)1 << (b)))
  166. #define bit_set(a,b) ((a) | ((uinteger)1 << (b)))
  167. #define abort_() { sig_die("Fortran abort routine called", 1); }
  168. #define c_abs(z) (cabsf(Cf(z)))
  169. #define c_cos(R,Z) { pCf(R)=ccos(Cf(Z)); }
  170. #ifdef _MSC_VER
  171. #define c_div(c, a, b) {Cf(c)._Val[0] = (Cf(a)._Val[0]/Cf(b)._Val[0]); Cf(c)._Val[1]=(Cf(a)._Val[1]/Cf(b)._Val[1]);}
  172. #define z_div(c, a, b) {Cd(c)._Val[0] = (Cd(a)._Val[0]/Cd(b)._Val[0]); Cd(c)._Val[1]=(Cd(a)._Val[1]/Cd(b)._Val[1]);}
  173. #else
  174. #define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);}
  175. #define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);}
  176. #endif
  177. #define c_exp(R, Z) {pCf(R) = cexpf(Cf(Z));}
  178. #define c_log(R, Z) {pCf(R) = clogf(Cf(Z));}
  179. #define c_sin(R, Z) {pCf(R) = csinf(Cf(Z));}
  180. //#define c_sqrt(R, Z) {*(R) = csqrtf(Cf(Z));}
  181. #define c_sqrt(R, Z) {pCf(R) = csqrtf(Cf(Z));}
  182. #define d_abs(x) (fabs(*(x)))
  183. #define d_acos(x) (acos(*(x)))
  184. #define d_asin(x) (asin(*(x)))
  185. #define d_atan(x) (atan(*(x)))
  186. #define d_atn2(x, y) (atan2(*(x),*(y)))
  187. #define d_cnjg(R, Z) { pCd(R) = conj(Cd(Z)); }
  188. #define r_cnjg(R, Z) { pCf(R) = conjf(Cf(Z)); }
  189. #define d_cos(x) (cos(*(x)))
  190. #define d_cosh(x) (cosh(*(x)))
  191. #define d_dim(__a, __b) ( *(__a) > *(__b) ? *(__a) - *(__b) : 0.0 )
  192. #define d_exp(x) (exp(*(x)))
  193. #define d_imag(z) (cimag(Cd(z)))
  194. #define r_imag(z) (cimagf(Cf(z)))
  195. #define d_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  196. #define r_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  197. #define d_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  198. #define r_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  199. #define d_log(x) (log(*(x)))
  200. #define d_mod(x, y) (fmod(*(x), *(y)))
  201. #define u_nint(__x) ((__x)>=0 ? floor((__x) + .5) : -floor(.5 - (__x)))
  202. #define d_nint(x) u_nint(*(x))
  203. #define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a)))
  204. #define d_sign(a,b) u_sign(*(a),*(b))
  205. #define r_sign(a,b) u_sign(*(a),*(b))
  206. #define d_sin(x) (sin(*(x)))
  207. #define d_sinh(x) (sinh(*(x)))
  208. #define d_sqrt(x) (sqrt(*(x)))
  209. #define d_tan(x) (tan(*(x)))
  210. #define d_tanh(x) (tanh(*(x)))
  211. #define i_abs(x) abs(*(x))
  212. #define i_dnnt(x) ((integer)u_nint(*(x)))
  213. #define i_len(s, n) (n)
  214. #define i_nint(x) ((integer)u_nint(*(x)))
  215. #define i_sign(a,b) ((integer)u_sign((integer)*(a),(integer)*(b)))
  216. #define pow_dd(ap, bp) ( pow(*(ap), *(bp)))
  217. #define pow_si(B,E) spow_ui(*(B),*(E))
  218. #define pow_ri(B,E) spow_ui(*(B),*(E))
  219. #define pow_di(B,E) dpow_ui(*(B),*(E))
  220. #define pow_zi(p, a, b) {pCd(p) = zpow_ui(Cd(a), *(b));}
  221. #define pow_ci(p, a, b) {pCf(p) = cpow_ui(Cf(a), *(b));}
  222. #define pow_zz(R,A,B) {pCd(R) = cpow(Cd(A),*(B));}
  223. #define s_cat(lpp, rpp, rnp, np, llp) { ftnlen i, nc, ll; char *f__rp, *lp; ll = (llp); lp = (lpp); for(i=0; i < (int)*(np); ++i) { nc = ll; if((rnp)[i] < nc) nc = (rnp)[i]; ll -= nc; f__rp = (rpp)[i]; while(--nc >= 0) *lp++ = *(f__rp)++; } while(--ll >= 0) *lp++ = ' '; }
  224. #define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d))))
  225. #define s_copy(A,B,C,D) { int __i,__m; for (__i=0, __m=f2cmin((C),(D)); __i<__m && (B)[__i] != 0; ++__i) (A)[__i] = (B)[__i]; }
  226. #define sig_die(s, kill) { exit(1); }
  227. #define s_stop(s, n) {exit(0);}
  228. static char junk[] = "\n@(#)LIBF77 VERSION 19990503\n";
  229. #define z_abs(z) (cabs(Cd(z)))
  230. #define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));}
  231. #define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));}
  232. #define myexit_() break;
  233. #define mycycle() continue;
  234. #define myceiling(w) {ceil(w)}
  235. #define myhuge(w) {HUGE_VAL}
  236. //#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);}
  237. #define mymaxloc(w,s,e,n) {dmaxloc_(w,*(s),*(e),n)}
  238. /* procedure parameter types for -A and -C++ */
  239. #ifdef __cplusplus
  240. typedef logical (*L_fp)(...);
  241. #else
  242. typedef logical (*L_fp)();
  243. #endif
  244. static float spow_ui(float x, integer n) {
  245. float pow=1.0; unsigned long int u;
  246. if(n != 0) {
  247. if(n < 0) n = -n, x = 1/x;
  248. for(u = n; ; ) {
  249. if(u & 01) pow *= x;
  250. if(u >>= 1) x *= x;
  251. else break;
  252. }
  253. }
  254. return pow;
  255. }
  256. static double dpow_ui(double x, integer n) {
  257. double pow=1.0; unsigned long int u;
  258. if(n != 0) {
  259. if(n < 0) n = -n, x = 1/x;
  260. for(u = n; ; ) {
  261. if(u & 01) pow *= x;
  262. if(u >>= 1) x *= x;
  263. else break;
  264. }
  265. }
  266. return pow;
  267. }
  268. #ifdef _MSC_VER
  269. static _Fcomplex cpow_ui(complex x, integer n) {
  270. complex pow={1.0,0.0}; unsigned long int u;
  271. if(n != 0) {
  272. if(n < 0) n = -n, x.r = 1/x.r, x.i=1/x.i;
  273. for(u = n; ; ) {
  274. if(u & 01) pow.r *= x.r, pow.i *= x.i;
  275. if(u >>= 1) x.r *= x.r, x.i *= x.i;
  276. else break;
  277. }
  278. }
  279. _Fcomplex p={pow.r, pow.i};
  280. return p;
  281. }
  282. #else
  283. static _Complex float cpow_ui(_Complex float x, integer n) {
  284. _Complex float pow=1.0; unsigned long int u;
  285. if(n != 0) {
  286. if(n < 0) n = -n, x = 1/x;
  287. for(u = n; ; ) {
  288. if(u & 01) pow *= x;
  289. if(u >>= 1) x *= x;
  290. else break;
  291. }
  292. }
  293. return pow;
  294. }
  295. #endif
  296. #ifdef _MSC_VER
  297. static _Dcomplex zpow_ui(_Dcomplex x, integer n) {
  298. _Dcomplex pow={1.0,0.0}; unsigned long int u;
  299. if(n != 0) {
  300. if(n < 0) n = -n, x._Val[0] = 1/x._Val[0], x._Val[1] =1/x._Val[1];
  301. for(u = n; ; ) {
  302. if(u & 01) pow._Val[0] *= x._Val[0], pow._Val[1] *= x._Val[1];
  303. if(u >>= 1) x._Val[0] *= x._Val[0], x._Val[1] *= x._Val[1];
  304. else break;
  305. }
  306. }
  307. _Dcomplex p = {pow._Val[0], pow._Val[1]};
  308. return p;
  309. }
  310. #else
  311. static _Complex double zpow_ui(_Complex double x, integer n) {
  312. _Complex double pow=1.0; unsigned long int u;
  313. if(n != 0) {
  314. if(n < 0) n = -n, x = 1/x;
  315. for(u = n; ; ) {
  316. if(u & 01) pow *= x;
  317. if(u >>= 1) x *= x;
  318. else break;
  319. }
  320. }
  321. return pow;
  322. }
  323. #endif
  324. static integer pow_ii(integer x, integer n) {
  325. integer pow; unsigned long int u;
  326. if (n <= 0) {
  327. if (n == 0 || x == 1) pow = 1;
  328. else if (x != -1) pow = x == 0 ? 1/x : 0;
  329. else n = -n;
  330. }
  331. if ((n > 0) || !(n == 0 || x == 1 || x != -1)) {
  332. u = n;
  333. for(pow = 1; ; ) {
  334. if(u & 01) pow *= x;
  335. if(u >>= 1) x *= x;
  336. else break;
  337. }
  338. }
  339. return pow;
  340. }
  341. static integer dmaxloc_(double *w, integer s, integer e, integer *n)
  342. {
  343. double m; integer i, mi;
  344. for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
  345. if (w[i-1]>m) mi=i ,m=w[i-1];
  346. return mi-s+1;
  347. }
  348. static integer smaxloc_(float *w, integer s, integer e, integer *n)
  349. {
  350. float m; integer i, mi;
  351. for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
  352. if (w[i-1]>m) mi=i ,m=w[i-1];
  353. return mi-s+1;
  354. }
  355. static inline void cdotc_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
  356. integer n = *n_, incx = *incx_, incy = *incy_, i;
  357. #ifdef _MSC_VER
  358. _Fcomplex zdotc = {0.0, 0.0};
  359. if (incx == 1 && incy == 1) {
  360. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  361. zdotc._Val[0] += conjf(Cf(&x[i]))._Val[0] * Cf(&y[i])._Val[0];
  362. zdotc._Val[1] += conjf(Cf(&x[i]))._Val[1] * Cf(&y[i])._Val[1];
  363. }
  364. } else {
  365. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  366. zdotc._Val[0] += conjf(Cf(&x[i*incx]))._Val[0] * Cf(&y[i*incy])._Val[0];
  367. zdotc._Val[1] += conjf(Cf(&x[i*incx]))._Val[1] * Cf(&y[i*incy])._Val[1];
  368. }
  369. }
  370. pCf(z) = zdotc;
  371. }
  372. #else
  373. _Complex float zdotc = 0.0;
  374. if (incx == 1 && incy == 1) {
  375. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  376. zdotc += conjf(Cf(&x[i])) * Cf(&y[i]);
  377. }
  378. } else {
  379. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  380. zdotc += conjf(Cf(&x[i*incx])) * Cf(&y[i*incy]);
  381. }
  382. }
  383. pCf(z) = zdotc;
  384. }
  385. #endif
  386. static inline void zdotc_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
  387. integer n = *n_, incx = *incx_, incy = *incy_, i;
  388. #ifdef _MSC_VER
  389. _Dcomplex zdotc = {0.0, 0.0};
  390. if (incx == 1 && incy == 1) {
  391. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  392. zdotc._Val[0] += conj(Cd(&x[i]))._Val[0] * Cd(&y[i])._Val[0];
  393. zdotc._Val[1] += conj(Cd(&x[i]))._Val[1] * Cd(&y[i])._Val[1];
  394. }
  395. } else {
  396. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  397. zdotc._Val[0] += conj(Cd(&x[i*incx]))._Val[0] * Cd(&y[i*incy])._Val[0];
  398. zdotc._Val[1] += conj(Cd(&x[i*incx]))._Val[1] * Cd(&y[i*incy])._Val[1];
  399. }
  400. }
  401. pCd(z) = zdotc;
  402. }
  403. #else
  404. _Complex double zdotc = 0.0;
  405. if (incx == 1 && incy == 1) {
  406. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  407. zdotc += conj(Cd(&x[i])) * Cd(&y[i]);
  408. }
  409. } else {
  410. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  411. zdotc += conj(Cd(&x[i*incx])) * Cd(&y[i*incy]);
  412. }
  413. }
  414. pCd(z) = zdotc;
  415. }
  416. #endif
  417. static inline void cdotu_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
  418. integer n = *n_, incx = *incx_, incy = *incy_, i;
  419. #ifdef _MSC_VER
  420. _Fcomplex zdotc = {0.0, 0.0};
  421. if (incx == 1 && incy == 1) {
  422. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  423. zdotc._Val[0] += Cf(&x[i])._Val[0] * Cf(&y[i])._Val[0];
  424. zdotc._Val[1] += Cf(&x[i])._Val[1] * Cf(&y[i])._Val[1];
  425. }
  426. } else {
  427. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  428. zdotc._Val[0] += Cf(&x[i*incx])._Val[0] * Cf(&y[i*incy])._Val[0];
  429. zdotc._Val[1] += Cf(&x[i*incx])._Val[1] * Cf(&y[i*incy])._Val[1];
  430. }
  431. }
  432. pCf(z) = zdotc;
  433. }
  434. #else
  435. _Complex float zdotc = 0.0;
  436. if (incx == 1 && incy == 1) {
  437. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  438. zdotc += Cf(&x[i]) * Cf(&y[i]);
  439. }
  440. } else {
  441. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  442. zdotc += Cf(&x[i*incx]) * Cf(&y[i*incy]);
  443. }
  444. }
  445. pCf(z) = zdotc;
  446. }
  447. #endif
  448. static inline void zdotu_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
  449. integer n = *n_, incx = *incx_, incy = *incy_, i;
  450. #ifdef _MSC_VER
  451. _Dcomplex zdotc = {0.0, 0.0};
  452. if (incx == 1 && incy == 1) {
  453. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  454. zdotc._Val[0] += Cd(&x[i])._Val[0] * Cd(&y[i])._Val[0];
  455. zdotc._Val[1] += Cd(&x[i])._Val[1] * Cd(&y[i])._Val[1];
  456. }
  457. } else {
  458. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  459. zdotc._Val[0] += Cd(&x[i*incx])._Val[0] * Cd(&y[i*incy])._Val[0];
  460. zdotc._Val[1] += Cd(&x[i*incx])._Val[1] * Cd(&y[i*incy])._Val[1];
  461. }
  462. }
  463. pCd(z) = zdotc;
  464. }
  465. #else
  466. _Complex double zdotc = 0.0;
  467. if (incx == 1 && incy == 1) {
  468. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  469. zdotc += Cd(&x[i]) * Cd(&y[i]);
  470. }
  471. } else {
  472. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  473. zdotc += Cd(&x[i*incx]) * Cd(&y[i*incy]);
  474. }
  475. }
  476. pCd(z) = zdotc;
  477. }
  478. #endif
  479. /* -- translated by f2c (version 20000121).
  480. You must link the resulting object file with the libraries:
  481. -lf2c -lm (in that order)
  482. */
  483. /* Table of constant values */
  484. static integer c__1 = 1;
  485. static integer c__2 = 2;
  486. /* > \brief \b ZLAHQR computes the eigenvalues and Schur factorization of an upper Hessenberg matrix, using th
  487. e double-shift/single-shift QR algorithm. */
  488. /* =========== DOCUMENTATION =========== */
  489. /* Online html documentation available at */
  490. /* http://www.netlib.org/lapack/explore-html/ */
  491. /* > \htmlonly */
  492. /* > Download ZLAHQR + dependencies */
  493. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zlahqr.
  494. f"> */
  495. /* > [TGZ]</a> */
  496. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zlahqr.
  497. f"> */
  498. /* > [ZIP]</a> */
  499. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zlahqr.
  500. f"> */
  501. /* > [TXT]</a> */
  502. /* > \endhtmlonly */
  503. /* Definition: */
  504. /* =========== */
  505. /* SUBROUTINE ZLAHQR( WANTT, WANTZ, N, ILO, IHI, H, LDH, W, ILOZ, */
  506. /* IHIZ, Z, LDZ, INFO ) */
  507. /* INTEGER IHI, IHIZ, ILO, ILOZ, INFO, LDH, LDZ, N */
  508. /* LOGICAL WANTT, WANTZ */
  509. /* COMPLEX*16 H( LDH, * ), W( * ), Z( LDZ, * ) */
  510. /* > \par Purpose: */
  511. /* ============= */
  512. /* > */
  513. /* > \verbatim */
  514. /* > */
  515. /* > ZLAHQR is an auxiliary routine called by CHSEQR to update the */
  516. /* > eigenvalues and Schur decomposition already computed by CHSEQR, by */
  517. /* > dealing with the Hessenberg submatrix in rows and columns ILO to */
  518. /* > IHI. */
  519. /* > \endverbatim */
  520. /* Arguments: */
  521. /* ========== */
  522. /* > \param[in] WANTT */
  523. /* > \verbatim */
  524. /* > WANTT is LOGICAL */
  525. /* > = .TRUE. : the full Schur form T is required; */
  526. /* > = .FALSE.: only eigenvalues are required. */
  527. /* > \endverbatim */
  528. /* > */
  529. /* > \param[in] WANTZ */
  530. /* > \verbatim */
  531. /* > WANTZ is LOGICAL */
  532. /* > = .TRUE. : the matrix of Schur vectors Z is required; */
  533. /* > = .FALSE.: Schur vectors are not required. */
  534. /* > \endverbatim */
  535. /* > */
  536. /* > \param[in] N */
  537. /* > \verbatim */
  538. /* > N is INTEGER */
  539. /* > The order of the matrix H. N >= 0. */
  540. /* > \endverbatim */
  541. /* > */
  542. /* > \param[in] ILO */
  543. /* > \verbatim */
  544. /* > ILO is INTEGER */
  545. /* > \endverbatim */
  546. /* > */
  547. /* > \param[in] IHI */
  548. /* > \verbatim */
  549. /* > IHI is INTEGER */
  550. /* > It is assumed that H is already upper triangular in rows and */
  551. /* > columns IHI+1:N, and that H(ILO,ILO-1) = 0 (unless ILO = 1). */
  552. /* > ZLAHQR works primarily with the Hessenberg submatrix in rows */
  553. /* > and columns ILO to IHI, but applies transformations to all of */
  554. /* > H if WANTT is .TRUE.. */
  555. /* > 1 <= ILO <= f2cmax(1,IHI); IHI <= N. */
  556. /* > \endverbatim */
  557. /* > */
  558. /* > \param[in,out] H */
  559. /* > \verbatim */
  560. /* > H is COMPLEX*16 array, dimension (LDH,N) */
  561. /* > On entry, the upper Hessenberg matrix H. */
  562. /* > On exit, if INFO is zero and if WANTT is .TRUE., then H */
  563. /* > is upper triangular in rows and columns ILO:IHI. If INFO */
  564. /* > is zero and if WANTT is .FALSE., then the contents of H */
  565. /* > are unspecified on exit. The output state of H in case */
  566. /* > INF is positive is below under the description of INFO. */
  567. /* > \endverbatim */
  568. /* > */
  569. /* > \param[in] LDH */
  570. /* > \verbatim */
  571. /* > LDH is INTEGER */
  572. /* > The leading dimension of the array H. LDH >= f2cmax(1,N). */
  573. /* > \endverbatim */
  574. /* > */
  575. /* > \param[out] W */
  576. /* > \verbatim */
  577. /* > W is COMPLEX*16 array, dimension (N) */
  578. /* > The computed eigenvalues ILO to IHI are stored in the */
  579. /* > corresponding elements of W. If WANTT is .TRUE., the */
  580. /* > eigenvalues are stored in the same order as on the diagonal */
  581. /* > of the Schur form returned in H, with W(i) = H(i,i). */
  582. /* > \endverbatim */
  583. /* > */
  584. /* > \param[in] ILOZ */
  585. /* > \verbatim */
  586. /* > ILOZ is INTEGER */
  587. /* > \endverbatim */
  588. /* > */
  589. /* > \param[in] IHIZ */
  590. /* > \verbatim */
  591. /* > IHIZ is INTEGER */
  592. /* > Specify the rows of Z to which transformations must be */
  593. /* > applied if WANTZ is .TRUE.. */
  594. /* > 1 <= ILOZ <= ILO; IHI <= IHIZ <= N. */
  595. /* > \endverbatim */
  596. /* > */
  597. /* > \param[in,out] Z */
  598. /* > \verbatim */
  599. /* > Z is COMPLEX*16 array, dimension (LDZ,N) */
  600. /* > If WANTZ is .TRUE., on entry Z must contain the current */
  601. /* > matrix Z of transformations accumulated by CHSEQR, and on */
  602. /* > exit Z has been updated; transformations are applied only to */
  603. /* > the submatrix Z(ILOZ:IHIZ,ILO:IHI). */
  604. /* > If WANTZ is .FALSE., Z is not referenced. */
  605. /* > \endverbatim */
  606. /* > */
  607. /* > \param[in] LDZ */
  608. /* > \verbatim */
  609. /* > LDZ is INTEGER */
  610. /* > The leading dimension of the array Z. LDZ >= f2cmax(1,N). */
  611. /* > \endverbatim */
  612. /* > */
  613. /* > \param[out] INFO */
  614. /* > \verbatim */
  615. /* > INFO is INTEGER */
  616. /* > = 0: successful exit */
  617. /* > > 0: if INFO = i, ZLAHQR failed to compute all the */
  618. /* > eigenvalues ILO to IHI in a total of 30 iterations */
  619. /* > per eigenvalue; elements i+1:ihi of W contain */
  620. /* > those eigenvalues which have been successfully */
  621. /* > computed. */
  622. /* > */
  623. /* > If INFO > 0 and WANTT is .FALSE., then on exit, */
  624. /* > the remaining unconverged eigenvalues are the */
  625. /* > eigenvalues of the upper Hessenberg matrix */
  626. /* > rows and columns ILO through INFO of the final, */
  627. /* > output value of H. */
  628. /* > */
  629. /* > If INFO > 0 and WANTT is .TRUE., then on exit */
  630. /* > (*) (initial value of H)*U = U*(final value of H) */
  631. /* > where U is an orthogonal matrix. The final */
  632. /* > value of H is upper Hessenberg and triangular in */
  633. /* > rows and columns INFO+1 through IHI. */
  634. /* > */
  635. /* > If INFO > 0 and WANTZ is .TRUE., then on exit */
  636. /* > (final value of Z) = (initial value of Z)*U */
  637. /* > where U is the orthogonal matrix in (*) */
  638. /* > (regardless of the value of WANTT.) */
  639. /* > \endverbatim */
  640. /* Authors: */
  641. /* ======== */
  642. /* > \author Univ. of Tennessee */
  643. /* > \author Univ. of California Berkeley */
  644. /* > \author Univ. of Colorado Denver */
  645. /* > \author NAG Ltd. */
  646. /* > \date December 2016 */
  647. /* > \ingroup complex16OTHERauxiliary */
  648. /* > \par Contributors: */
  649. /* ================== */
  650. /* > */
  651. /* > \verbatim */
  652. /* > */
  653. /* > 02-96 Based on modifications by */
  654. /* > David Day, Sandia National Laboratory, USA */
  655. /* > */
  656. /* > 12-04 Further modifications by */
  657. /* > Ralph Byers, University of Kansas, USA */
  658. /* > This is a modified version of ZLAHQR from LAPACK version 3.0. */
  659. /* > It is (1) more robust against overflow and underflow and */
  660. /* > (2) adopts the more conservative Ahues & Tisseur stopping */
  661. /* > criterion (LAWN 122, 1997). */
  662. /* > \endverbatim */
  663. /* > */
  664. /* ===================================================================== */
  665. /* Subroutine */ void zlahqr_(logical *wantt, logical *wantz, integer *n,
  666. integer *ilo, integer *ihi, doublecomplex *h__, integer *ldh,
  667. doublecomplex *w, integer *iloz, integer *ihiz, doublecomplex *z__,
  668. integer *ldz, integer *info)
  669. {
  670. /* System generated locals */
  671. integer h_dim1, h_offset, z_dim1, z_offset, i__1, i__2, i__3, i__4, i__5;
  672. doublereal d__1, d__2, d__3, d__4, d__5, d__6;
  673. doublecomplex z__1, z__2, z__3, z__4, z__5, z__6, z__7;
  674. /* Local variables */
  675. doublecomplex temp;
  676. integer i__, j, k, l, m;
  677. doublereal s;
  678. doublecomplex t, u, v[2], x, y;
  679. extern /* Subroutine */ void zscal_(integer *, doublecomplex *,
  680. doublecomplex *, integer *);
  681. integer itmax;
  682. doublereal rtemp;
  683. integer i1, i2;
  684. extern /* Subroutine */ void zcopy_(integer *, doublecomplex *, integer *,
  685. doublecomplex *, integer *);
  686. doublecomplex t1;
  687. doublereal t2;
  688. doublecomplex v2;
  689. doublereal aa, ab, ba, bb;
  690. extern /* Subroutine */ void dlabad_(doublereal *, doublereal *);
  691. doublereal h10;
  692. doublecomplex h11;
  693. doublereal h21;
  694. doublecomplex h22, sc;
  695. integer nh;
  696. extern doublereal dlamch_(char *);
  697. integer nz;
  698. doublereal sx, safmin, safmax;
  699. extern /* Subroutine */ void zlarfg_(integer *, doublecomplex *,
  700. doublecomplex *, integer *, doublecomplex *);
  701. extern /* Double Complex */ VOID zladiv_(doublecomplex *, doublecomplex *,
  702. doublecomplex *);
  703. doublereal smlnum;
  704. integer jhi;
  705. doublecomplex h11s;
  706. integer jlo, its;
  707. doublereal ulp;
  708. doublecomplex sum;
  709. doublereal tst;
  710. /* -- LAPACK auxiliary routine (version 3.7.0) -- */
  711. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  712. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  713. /* December 2016 */
  714. /* ========================================================= */
  715. /* Parameter adjustments */
  716. h_dim1 = *ldh;
  717. h_offset = 1 + h_dim1 * 1;
  718. h__ -= h_offset;
  719. --w;
  720. z_dim1 = *ldz;
  721. z_offset = 1 + z_dim1 * 1;
  722. z__ -= z_offset;
  723. /* Function Body */
  724. *info = 0;
  725. /* Quick return if possible */
  726. if (*n == 0) {
  727. return;
  728. }
  729. if (*ilo == *ihi) {
  730. i__1 = *ilo;
  731. i__2 = *ilo + *ilo * h_dim1;
  732. w[i__1].r = h__[i__2].r, w[i__1].i = h__[i__2].i;
  733. return;
  734. }
  735. /* ==== clear out the trash ==== */
  736. i__1 = *ihi - 3;
  737. for (j = *ilo; j <= i__1; ++j) {
  738. i__2 = j + 2 + j * h_dim1;
  739. h__[i__2].r = 0., h__[i__2].i = 0.;
  740. i__2 = j + 3 + j * h_dim1;
  741. h__[i__2].r = 0., h__[i__2].i = 0.;
  742. /* L10: */
  743. }
  744. if (*ilo <= *ihi - 2) {
  745. i__1 = *ihi + (*ihi - 2) * h_dim1;
  746. h__[i__1].r = 0., h__[i__1].i = 0.;
  747. }
  748. /* ==== ensure that subdiagonal entries are real ==== */
  749. if (*wantt) {
  750. jlo = 1;
  751. jhi = *n;
  752. } else {
  753. jlo = *ilo;
  754. jhi = *ihi;
  755. }
  756. i__1 = *ihi;
  757. for (i__ = *ilo + 1; i__ <= i__1; ++i__) {
  758. if (d_imag(&h__[i__ + (i__ - 1) * h_dim1]) != 0.) {
  759. /* ==== The following redundant normalization */
  760. /* . avoids problems with both gradual and */
  761. /* . sudden underflow in ABS(H(I,I-1)) ==== */
  762. i__2 = i__ + (i__ - 1) * h_dim1;
  763. i__3 = i__ + (i__ - 1) * h_dim1;
  764. d__3 = (d__1 = h__[i__3].r, abs(d__1)) + (d__2 = d_imag(&h__[i__
  765. + (i__ - 1) * h_dim1]), abs(d__2));
  766. z__1.r = h__[i__2].r / d__3, z__1.i = h__[i__2].i / d__3;
  767. sc.r = z__1.r, sc.i = z__1.i;
  768. d_cnjg(&z__2, &sc);
  769. d__1 = z_abs(&sc);
  770. z__1.r = z__2.r / d__1, z__1.i = z__2.i / d__1;
  771. sc.r = z__1.r, sc.i = z__1.i;
  772. i__2 = i__ + (i__ - 1) * h_dim1;
  773. d__1 = z_abs(&h__[i__ + (i__ - 1) * h_dim1]);
  774. h__[i__2].r = d__1, h__[i__2].i = 0.;
  775. i__2 = jhi - i__ + 1;
  776. zscal_(&i__2, &sc, &h__[i__ + i__ * h_dim1], ldh);
  777. /* Computing MIN */
  778. i__3 = jhi, i__4 = i__ + 1;
  779. i__2 = f2cmin(i__3,i__4) - jlo + 1;
  780. d_cnjg(&z__1, &sc);
  781. zscal_(&i__2, &z__1, &h__[jlo + i__ * h_dim1], &c__1);
  782. if (*wantz) {
  783. i__2 = *ihiz - *iloz + 1;
  784. d_cnjg(&z__1, &sc);
  785. zscal_(&i__2, &z__1, &z__[*iloz + i__ * z_dim1], &c__1);
  786. }
  787. }
  788. /* L20: */
  789. }
  790. nh = *ihi - *ilo + 1;
  791. nz = *ihiz - *iloz + 1;
  792. /* Set machine-dependent constants for the stopping criterion. */
  793. safmin = dlamch_("SAFE MINIMUM");
  794. safmax = 1. / safmin;
  795. dlabad_(&safmin, &safmax);
  796. ulp = dlamch_("PRECISION");
  797. smlnum = safmin * ((doublereal) nh / ulp);
  798. /* I1 and I2 are the indices of the first row and last column of H */
  799. /* to which transformations must be applied. If eigenvalues only are */
  800. /* being computed, I1 and I2 are set inside the main loop. */
  801. if (*wantt) {
  802. i1 = 1;
  803. i2 = *n;
  804. }
  805. /* ITMAX is the total number of QR iterations allowed. */
  806. itmax = f2cmax(10,nh) * 30;
  807. /* The main loop begins here. I is the loop index and decreases from */
  808. /* IHI to ILO in steps of 1. Each iteration of the loop works */
  809. /* with the active submatrix in rows and columns L to I. */
  810. /* Eigenvalues I+1 to IHI have already converged. Either L = ILO, or */
  811. /* H(L,L-1) is negligible so that the matrix splits. */
  812. i__ = *ihi;
  813. L30:
  814. if (i__ < *ilo) {
  815. goto L150;
  816. }
  817. /* Perform QR iterations on rows and columns ILO to I until a */
  818. /* submatrix of order 1 splits off at the bottom because a */
  819. /* subdiagonal element has become negligible. */
  820. l = *ilo;
  821. i__1 = itmax;
  822. for (its = 0; its <= i__1; ++its) {
  823. /* Look for a single small subdiagonal element. */
  824. i__2 = l + 1;
  825. for (k = i__; k >= i__2; --k) {
  826. i__3 = k + (k - 1) * h_dim1;
  827. if ((d__1 = h__[i__3].r, abs(d__1)) + (d__2 = d_imag(&h__[k + (k
  828. - 1) * h_dim1]), abs(d__2)) <= smlnum) {
  829. goto L50;
  830. }
  831. i__3 = k - 1 + (k - 1) * h_dim1;
  832. i__4 = k + k * h_dim1;
  833. tst = (d__1 = h__[i__3].r, abs(d__1)) + (d__2 = d_imag(&h__[k - 1
  834. + (k - 1) * h_dim1]), abs(d__2)) + ((d__3 = h__[i__4].r,
  835. abs(d__3)) + (d__4 = d_imag(&h__[k + k * h_dim1]), abs(
  836. d__4)));
  837. if (tst == 0.) {
  838. if (k - 2 >= *ilo) {
  839. i__3 = k - 1 + (k - 2) * h_dim1;
  840. tst += (d__1 = h__[i__3].r, abs(d__1));
  841. }
  842. if (k + 1 <= *ihi) {
  843. i__3 = k + 1 + k * h_dim1;
  844. tst += (d__1 = h__[i__3].r, abs(d__1));
  845. }
  846. }
  847. /* ==== The following is a conservative small subdiagonal */
  848. /* . deflation criterion due to Ahues & Tisseur (LAWN 122, */
  849. /* . 1997). It has better mathematical foundation and */
  850. /* . improves accuracy in some examples. ==== */
  851. i__3 = k + (k - 1) * h_dim1;
  852. if ((d__1 = h__[i__3].r, abs(d__1)) <= ulp * tst) {
  853. /* Computing MAX */
  854. i__3 = k + (k - 1) * h_dim1;
  855. i__4 = k - 1 + k * h_dim1;
  856. d__5 = (d__1 = h__[i__3].r, abs(d__1)) + (d__2 = d_imag(&h__[
  857. k + (k - 1) * h_dim1]), abs(d__2)), d__6 = (d__3 =
  858. h__[i__4].r, abs(d__3)) + (d__4 = d_imag(&h__[k - 1 +
  859. k * h_dim1]), abs(d__4));
  860. ab = f2cmax(d__5,d__6);
  861. /* Computing MIN */
  862. i__3 = k + (k - 1) * h_dim1;
  863. i__4 = k - 1 + k * h_dim1;
  864. d__5 = (d__1 = h__[i__3].r, abs(d__1)) + (d__2 = d_imag(&h__[
  865. k + (k - 1) * h_dim1]), abs(d__2)), d__6 = (d__3 =
  866. h__[i__4].r, abs(d__3)) + (d__4 = d_imag(&h__[k - 1 +
  867. k * h_dim1]), abs(d__4));
  868. ba = f2cmin(d__5,d__6);
  869. i__3 = k - 1 + (k - 1) * h_dim1;
  870. i__4 = k + k * h_dim1;
  871. z__2.r = h__[i__3].r - h__[i__4].r, z__2.i = h__[i__3].i -
  872. h__[i__4].i;
  873. z__1.r = z__2.r, z__1.i = z__2.i;
  874. /* Computing MAX */
  875. i__5 = k + k * h_dim1;
  876. d__5 = (d__1 = h__[i__5].r, abs(d__1)) + (d__2 = d_imag(&h__[
  877. k + k * h_dim1]), abs(d__2)), d__6 = (d__3 = z__1.r,
  878. abs(d__3)) + (d__4 = d_imag(&z__1), abs(d__4));
  879. aa = f2cmax(d__5,d__6);
  880. i__3 = k - 1 + (k - 1) * h_dim1;
  881. i__4 = k + k * h_dim1;
  882. z__2.r = h__[i__3].r - h__[i__4].r, z__2.i = h__[i__3].i -
  883. h__[i__4].i;
  884. z__1.r = z__2.r, z__1.i = z__2.i;
  885. /* Computing MIN */
  886. i__5 = k + k * h_dim1;
  887. d__5 = (d__1 = h__[i__5].r, abs(d__1)) + (d__2 = d_imag(&h__[
  888. k + k * h_dim1]), abs(d__2)), d__6 = (d__3 = z__1.r,
  889. abs(d__3)) + (d__4 = d_imag(&z__1), abs(d__4));
  890. bb = f2cmin(d__5,d__6);
  891. s = aa + ab;
  892. /* Computing MAX */
  893. d__1 = smlnum, d__2 = ulp * (bb * (aa / s));
  894. if (ba * (ab / s) <= f2cmax(d__1,d__2)) {
  895. goto L50;
  896. }
  897. }
  898. /* L40: */
  899. }
  900. L50:
  901. l = k;
  902. if (l > *ilo) {
  903. /* H(L,L-1) is negligible */
  904. i__2 = l + (l - 1) * h_dim1;
  905. h__[i__2].r = 0., h__[i__2].i = 0.;
  906. }
  907. /* Exit from loop if a submatrix of order 1 has split off. */
  908. if (l >= i__) {
  909. goto L140;
  910. }
  911. /* Now the active submatrix is in rows and columns L to I. If */
  912. /* eigenvalues only are being computed, only the active submatrix */
  913. /* need be transformed. */
  914. if (! (*wantt)) {
  915. i1 = l;
  916. i2 = i__;
  917. }
  918. if (its == 10) {
  919. /* Exceptional shift. */
  920. i__2 = l + 1 + l * h_dim1;
  921. s = (d__1 = h__[i__2].r, abs(d__1)) * .75;
  922. i__2 = l + l * h_dim1;
  923. z__1.r = s + h__[i__2].r, z__1.i = h__[i__2].i;
  924. t.r = z__1.r, t.i = z__1.i;
  925. } else if (its == 20) {
  926. /* Exceptional shift. */
  927. i__2 = i__ + (i__ - 1) * h_dim1;
  928. s = (d__1 = h__[i__2].r, abs(d__1)) * .75;
  929. i__2 = i__ + i__ * h_dim1;
  930. z__1.r = s + h__[i__2].r, z__1.i = h__[i__2].i;
  931. t.r = z__1.r, t.i = z__1.i;
  932. } else {
  933. /* Wilkinson's shift. */
  934. i__2 = i__ + i__ * h_dim1;
  935. t.r = h__[i__2].r, t.i = h__[i__2].i;
  936. z_sqrt(&z__2, &h__[i__ - 1 + i__ * h_dim1]);
  937. z_sqrt(&z__3, &h__[i__ + (i__ - 1) * h_dim1]);
  938. z__1.r = z__2.r * z__3.r - z__2.i * z__3.i, z__1.i = z__2.r *
  939. z__3.i + z__2.i * z__3.r;
  940. u.r = z__1.r, u.i = z__1.i;
  941. s = (d__1 = u.r, abs(d__1)) + (d__2 = d_imag(&u), abs(d__2));
  942. if (s != 0.) {
  943. i__2 = i__ - 1 + (i__ - 1) * h_dim1;
  944. z__2.r = h__[i__2].r - t.r, z__2.i = h__[i__2].i - t.i;
  945. z__1.r = z__2.r * .5, z__1.i = z__2.i * .5;
  946. x.r = z__1.r, x.i = z__1.i;
  947. sx = (d__1 = x.r, abs(d__1)) + (d__2 = d_imag(&x), abs(d__2));
  948. /* Computing MAX */
  949. d__3 = s, d__4 = (d__1 = x.r, abs(d__1)) + (d__2 = d_imag(&x),
  950. abs(d__2));
  951. s = f2cmax(d__3,d__4);
  952. z__5.r = x.r / s, z__5.i = x.i / s;
  953. pow_zi(&z__4, &z__5, &c__2);
  954. z__7.r = u.r / s, z__7.i = u.i / s;
  955. pow_zi(&z__6, &z__7, &c__2);
  956. z__3.r = z__4.r + z__6.r, z__3.i = z__4.i + z__6.i;
  957. z_sqrt(&z__2, &z__3);
  958. z__1.r = s * z__2.r, z__1.i = s * z__2.i;
  959. y.r = z__1.r, y.i = z__1.i;
  960. if (sx > 0.) {
  961. z__1.r = x.r / sx, z__1.i = x.i / sx;
  962. z__2.r = x.r / sx, z__2.i = x.i / sx;
  963. if (z__1.r * y.r + d_imag(&z__2) * d_imag(&y) < 0.) {
  964. z__3.r = -y.r, z__3.i = -y.i;
  965. y.r = z__3.r, y.i = z__3.i;
  966. }
  967. }
  968. z__4.r = x.r + y.r, z__4.i = x.i + y.i;
  969. zladiv_(&z__3, &u, &z__4);
  970. z__2.r = u.r * z__3.r - u.i * z__3.i, z__2.i = u.r * z__3.i +
  971. u.i * z__3.r;
  972. z__1.r = t.r - z__2.r, z__1.i = t.i - z__2.i;
  973. t.r = z__1.r, t.i = z__1.i;
  974. }
  975. }
  976. /* Look for two consecutive small subdiagonal elements. */
  977. i__2 = l + 1;
  978. for (m = i__ - 1; m >= i__2; --m) {
  979. /* Determine the effect of starting the single-shift QR */
  980. /* iteration at row M, and see if this would make H(M,M-1) */
  981. /* negligible. */
  982. i__3 = m + m * h_dim1;
  983. h11.r = h__[i__3].r, h11.i = h__[i__3].i;
  984. i__3 = m + 1 + (m + 1) * h_dim1;
  985. h22.r = h__[i__3].r, h22.i = h__[i__3].i;
  986. z__1.r = h11.r - t.r, z__1.i = h11.i - t.i;
  987. h11s.r = z__1.r, h11s.i = z__1.i;
  988. i__3 = m + 1 + m * h_dim1;
  989. h21 = h__[i__3].r;
  990. s = (d__1 = h11s.r, abs(d__1)) + (d__2 = d_imag(&h11s), abs(d__2))
  991. + abs(h21);
  992. z__1.r = h11s.r / s, z__1.i = h11s.i / s;
  993. h11s.r = z__1.r, h11s.i = z__1.i;
  994. h21 /= s;
  995. v[0].r = h11s.r, v[0].i = h11s.i;
  996. v[1].r = h21, v[1].i = 0.;
  997. i__3 = m + (m - 1) * h_dim1;
  998. h10 = h__[i__3].r;
  999. if (abs(h10) * abs(h21) <= ulp * (((d__1 = h11s.r, abs(d__1)) + (
  1000. d__2 = d_imag(&h11s), abs(d__2))) * ((d__3 = h11.r, abs(
  1001. d__3)) + (d__4 = d_imag(&h11), abs(d__4)) + ((d__5 =
  1002. h22.r, abs(d__5)) + (d__6 = d_imag(&h22), abs(d__6)))))) {
  1003. goto L70;
  1004. }
  1005. /* L60: */
  1006. }
  1007. i__2 = l + l * h_dim1;
  1008. h11.r = h__[i__2].r, h11.i = h__[i__2].i;
  1009. i__2 = l + 1 + (l + 1) * h_dim1;
  1010. h22.r = h__[i__2].r, h22.i = h__[i__2].i;
  1011. z__1.r = h11.r - t.r, z__1.i = h11.i - t.i;
  1012. h11s.r = z__1.r, h11s.i = z__1.i;
  1013. i__2 = l + 1 + l * h_dim1;
  1014. h21 = h__[i__2].r;
  1015. s = (d__1 = h11s.r, abs(d__1)) + (d__2 = d_imag(&h11s), abs(d__2)) +
  1016. abs(h21);
  1017. z__1.r = h11s.r / s, z__1.i = h11s.i / s;
  1018. h11s.r = z__1.r, h11s.i = z__1.i;
  1019. h21 /= s;
  1020. v[0].r = h11s.r, v[0].i = h11s.i;
  1021. v[1].r = h21, v[1].i = 0.;
  1022. L70:
  1023. /* Single-shift QR step */
  1024. i__2 = i__ - 1;
  1025. for (k = m; k <= i__2; ++k) {
  1026. /* The first iteration of this loop determines a reflection G */
  1027. /* from the vector V and applies it from left and right to H, */
  1028. /* thus creating a nonzero bulge below the subdiagonal. */
  1029. /* Each subsequent iteration determines a reflection G to */
  1030. /* restore the Hessenberg form in the (K-1)th column, and thus */
  1031. /* chases the bulge one step toward the bottom of the active */
  1032. /* submatrix. */
  1033. /* V(2) is always real before the call to ZLARFG, and hence */
  1034. /* after the call T2 ( = T1*V(2) ) is also real. */
  1035. if (k > m) {
  1036. zcopy_(&c__2, &h__[k + (k - 1) * h_dim1], &c__1, v, &c__1);
  1037. }
  1038. zlarfg_(&c__2, v, &v[1], &c__1, &t1);
  1039. if (k > m) {
  1040. i__3 = k + (k - 1) * h_dim1;
  1041. h__[i__3].r = v[0].r, h__[i__3].i = v[0].i;
  1042. i__3 = k + 1 + (k - 1) * h_dim1;
  1043. h__[i__3].r = 0., h__[i__3].i = 0.;
  1044. }
  1045. v2.r = v[1].r, v2.i = v[1].i;
  1046. z__1.r = t1.r * v2.r - t1.i * v2.i, z__1.i = t1.r * v2.i + t1.i *
  1047. v2.r;
  1048. t2 = z__1.r;
  1049. /* Apply G from the left to transform the rows of the matrix */
  1050. /* in columns K to I2. */
  1051. i__3 = i2;
  1052. for (j = k; j <= i__3; ++j) {
  1053. d_cnjg(&z__3, &t1);
  1054. i__4 = k + j * h_dim1;
  1055. z__2.r = z__3.r * h__[i__4].r - z__3.i * h__[i__4].i, z__2.i =
  1056. z__3.r * h__[i__4].i + z__3.i * h__[i__4].r;
  1057. i__5 = k + 1 + j * h_dim1;
  1058. z__4.r = t2 * h__[i__5].r, z__4.i = t2 * h__[i__5].i;
  1059. z__1.r = z__2.r + z__4.r, z__1.i = z__2.i + z__4.i;
  1060. sum.r = z__1.r, sum.i = z__1.i;
  1061. i__4 = k + j * h_dim1;
  1062. i__5 = k + j * h_dim1;
  1063. z__1.r = h__[i__5].r - sum.r, z__1.i = h__[i__5].i - sum.i;
  1064. h__[i__4].r = z__1.r, h__[i__4].i = z__1.i;
  1065. i__4 = k + 1 + j * h_dim1;
  1066. i__5 = k + 1 + j * h_dim1;
  1067. z__2.r = sum.r * v2.r - sum.i * v2.i, z__2.i = sum.r * v2.i +
  1068. sum.i * v2.r;
  1069. z__1.r = h__[i__5].r - z__2.r, z__1.i = h__[i__5].i - z__2.i;
  1070. h__[i__4].r = z__1.r, h__[i__4].i = z__1.i;
  1071. /* L80: */
  1072. }
  1073. /* Apply G from the right to transform the columns of the */
  1074. /* matrix in rows I1 to f2cmin(K+2,I). */
  1075. /* Computing MIN */
  1076. i__4 = k + 2;
  1077. i__3 = f2cmin(i__4,i__);
  1078. for (j = i1; j <= i__3; ++j) {
  1079. i__4 = j + k * h_dim1;
  1080. z__2.r = t1.r * h__[i__4].r - t1.i * h__[i__4].i, z__2.i =
  1081. t1.r * h__[i__4].i + t1.i * h__[i__4].r;
  1082. i__5 = j + (k + 1) * h_dim1;
  1083. z__3.r = t2 * h__[i__5].r, z__3.i = t2 * h__[i__5].i;
  1084. z__1.r = z__2.r + z__3.r, z__1.i = z__2.i + z__3.i;
  1085. sum.r = z__1.r, sum.i = z__1.i;
  1086. i__4 = j + k * h_dim1;
  1087. i__5 = j + k * h_dim1;
  1088. z__1.r = h__[i__5].r - sum.r, z__1.i = h__[i__5].i - sum.i;
  1089. h__[i__4].r = z__1.r, h__[i__4].i = z__1.i;
  1090. i__4 = j + (k + 1) * h_dim1;
  1091. i__5 = j + (k + 1) * h_dim1;
  1092. d_cnjg(&z__3, &v2);
  1093. z__2.r = sum.r * z__3.r - sum.i * z__3.i, z__2.i = sum.r *
  1094. z__3.i + sum.i * z__3.r;
  1095. z__1.r = h__[i__5].r - z__2.r, z__1.i = h__[i__5].i - z__2.i;
  1096. h__[i__4].r = z__1.r, h__[i__4].i = z__1.i;
  1097. /* L90: */
  1098. }
  1099. if (*wantz) {
  1100. /* Accumulate transformations in the matrix Z */
  1101. i__3 = *ihiz;
  1102. for (j = *iloz; j <= i__3; ++j) {
  1103. i__4 = j + k * z_dim1;
  1104. z__2.r = t1.r * z__[i__4].r - t1.i * z__[i__4].i, z__2.i =
  1105. t1.r * z__[i__4].i + t1.i * z__[i__4].r;
  1106. i__5 = j + (k + 1) * z_dim1;
  1107. z__3.r = t2 * z__[i__5].r, z__3.i = t2 * z__[i__5].i;
  1108. z__1.r = z__2.r + z__3.r, z__1.i = z__2.i + z__3.i;
  1109. sum.r = z__1.r, sum.i = z__1.i;
  1110. i__4 = j + k * z_dim1;
  1111. i__5 = j + k * z_dim1;
  1112. z__1.r = z__[i__5].r - sum.r, z__1.i = z__[i__5].i -
  1113. sum.i;
  1114. z__[i__4].r = z__1.r, z__[i__4].i = z__1.i;
  1115. i__4 = j + (k + 1) * z_dim1;
  1116. i__5 = j + (k + 1) * z_dim1;
  1117. d_cnjg(&z__3, &v2);
  1118. z__2.r = sum.r * z__3.r - sum.i * z__3.i, z__2.i = sum.r *
  1119. z__3.i + sum.i * z__3.r;
  1120. z__1.r = z__[i__5].r - z__2.r, z__1.i = z__[i__5].i -
  1121. z__2.i;
  1122. z__[i__4].r = z__1.r, z__[i__4].i = z__1.i;
  1123. /* L100: */
  1124. }
  1125. }
  1126. if (k == m && m > l) {
  1127. /* If the QR step was started at row M > L because two */
  1128. /* consecutive small subdiagonals were found, then extra */
  1129. /* scaling must be performed to ensure that H(M,M-1) remains */
  1130. /* real. */
  1131. z__1.r = 1. - t1.r, z__1.i = 0. - t1.i;
  1132. temp.r = z__1.r, temp.i = z__1.i;
  1133. d__1 = z_abs(&temp);
  1134. z__1.r = temp.r / d__1, z__1.i = temp.i / d__1;
  1135. temp.r = z__1.r, temp.i = z__1.i;
  1136. i__3 = m + 1 + m * h_dim1;
  1137. i__4 = m + 1 + m * h_dim1;
  1138. d_cnjg(&z__2, &temp);
  1139. z__1.r = h__[i__4].r * z__2.r - h__[i__4].i * z__2.i, z__1.i =
  1140. h__[i__4].r * z__2.i + h__[i__4].i * z__2.r;
  1141. h__[i__3].r = z__1.r, h__[i__3].i = z__1.i;
  1142. if (m + 2 <= i__) {
  1143. i__3 = m + 2 + (m + 1) * h_dim1;
  1144. i__4 = m + 2 + (m + 1) * h_dim1;
  1145. z__1.r = h__[i__4].r * temp.r - h__[i__4].i * temp.i,
  1146. z__1.i = h__[i__4].r * temp.i + h__[i__4].i *
  1147. temp.r;
  1148. h__[i__3].r = z__1.r, h__[i__3].i = z__1.i;
  1149. }
  1150. i__3 = i__;
  1151. for (j = m; j <= i__3; ++j) {
  1152. if (j != m + 1) {
  1153. if (i2 > j) {
  1154. i__4 = i2 - j;
  1155. zscal_(&i__4, &temp, &h__[j + (j + 1) * h_dim1],
  1156. ldh);
  1157. }
  1158. i__4 = j - i1;
  1159. d_cnjg(&z__1, &temp);
  1160. zscal_(&i__4, &z__1, &h__[i1 + j * h_dim1], &c__1);
  1161. if (*wantz) {
  1162. d_cnjg(&z__1, &temp);
  1163. zscal_(&nz, &z__1, &z__[*iloz + j * z_dim1], &
  1164. c__1);
  1165. }
  1166. }
  1167. /* L110: */
  1168. }
  1169. }
  1170. /* L120: */
  1171. }
  1172. /* Ensure that H(I,I-1) is real. */
  1173. i__2 = i__ + (i__ - 1) * h_dim1;
  1174. temp.r = h__[i__2].r, temp.i = h__[i__2].i;
  1175. if (d_imag(&temp) != 0.) {
  1176. rtemp = z_abs(&temp);
  1177. i__2 = i__ + (i__ - 1) * h_dim1;
  1178. h__[i__2].r = rtemp, h__[i__2].i = 0.;
  1179. z__1.r = temp.r / rtemp, z__1.i = temp.i / rtemp;
  1180. temp.r = z__1.r, temp.i = z__1.i;
  1181. if (i2 > i__) {
  1182. i__2 = i2 - i__;
  1183. d_cnjg(&z__1, &temp);
  1184. zscal_(&i__2, &z__1, &h__[i__ + (i__ + 1) * h_dim1], ldh);
  1185. }
  1186. i__2 = i__ - i1;
  1187. zscal_(&i__2, &temp, &h__[i1 + i__ * h_dim1], &c__1);
  1188. if (*wantz) {
  1189. zscal_(&nz, &temp, &z__[*iloz + i__ * z_dim1], &c__1);
  1190. }
  1191. }
  1192. /* L130: */
  1193. }
  1194. /* Failure to converge in remaining number of iterations */
  1195. *info = i__;
  1196. return;
  1197. L140:
  1198. /* H(I,I-1) is negligible: one eigenvalue has converged. */
  1199. i__1 = i__;
  1200. i__2 = i__ + i__ * h_dim1;
  1201. w[i__1].r = h__[i__2].r, w[i__1].i = h__[i__2].i;
  1202. /* return to start of the main loop with new value of I. */
  1203. i__ = l - 1;
  1204. goto L30;
  1205. L150:
  1206. return;
  1207. /* End of ZLAHQR */
  1208. } /* zlahqr_ */