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.

clahqr.c 40 kB

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