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