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.

chgeqz.c 54 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750
  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}; complex tmp; 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 = _Cmulcc(pow,x);
  302. if(u >>= 1) x = _Cmulcc(x,x);
  303. else break;
  304. }
  305. }
  306. return pow;
  307. }
  308. #else
  309. static _Complex double zpow_ui(_Complex double x, integer n) {
  310. _Complex double pow=1.0; unsigned long int u;
  311. if(n != 0) {
  312. if(n < 0) n = -n, x = 1/x;
  313. for(u = n; ; ) {
  314. if(u & 01) pow *= x;
  315. if(u >>= 1) x *= x;
  316. else break;
  317. }
  318. }
  319. return pow;
  320. }
  321. #endif
  322. static integer pow_ii(integer x, integer n) {
  323. integer pow; unsigned long int u;
  324. if (n <= 0) {
  325. if (n == 0 || x == 1) pow = 1;
  326. else if (x != -1) pow = x == 0 ? 1/x : 0;
  327. else n = -n;
  328. }
  329. if ((n > 0) || !(n == 0 || x == 1 || x != -1)) {
  330. u = n;
  331. for(pow = 1; ; ) {
  332. if(u & 01) pow *= x;
  333. if(u >>= 1) x *= x;
  334. else break;
  335. }
  336. }
  337. return pow;
  338. }
  339. static integer dmaxloc_(double *w, integer s, integer e, integer *n)
  340. {
  341. double m; integer i, mi;
  342. for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
  343. if (w[i-1]>m) mi=i ,m=w[i-1];
  344. return mi-s+1;
  345. }
  346. static integer smaxloc_(float *w, integer s, integer e, integer *n)
  347. {
  348. float m; integer i, mi;
  349. for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
  350. if (w[i-1]>m) mi=i ,m=w[i-1];
  351. return mi-s+1;
  352. }
  353. static inline void cdotc_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
  354. integer n = *n_, incx = *incx_, incy = *incy_, i;
  355. #ifdef _MSC_VER
  356. _Fcomplex zdotc = {0.0, 0.0};
  357. if (incx == 1 && incy == 1) {
  358. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  359. zdotc._Val[0] += conjf(Cf(&x[i]))._Val[0] * Cf(&y[i])._Val[0];
  360. zdotc._Val[1] += conjf(Cf(&x[i]))._Val[1] * Cf(&y[i])._Val[1];
  361. }
  362. } else {
  363. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  364. zdotc._Val[0] += conjf(Cf(&x[i*incx]))._Val[0] * Cf(&y[i*incy])._Val[0];
  365. zdotc._Val[1] += conjf(Cf(&x[i*incx]))._Val[1] * Cf(&y[i*incy])._Val[1];
  366. }
  367. }
  368. pCf(z) = zdotc;
  369. }
  370. #else
  371. _Complex float zdotc = 0.0;
  372. if (incx == 1 && incy == 1) {
  373. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  374. zdotc += conjf(Cf(&x[i])) * Cf(&y[i]);
  375. }
  376. } else {
  377. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  378. zdotc += conjf(Cf(&x[i*incx])) * Cf(&y[i*incy]);
  379. }
  380. }
  381. pCf(z) = zdotc;
  382. }
  383. #endif
  384. static inline void zdotc_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
  385. integer n = *n_, incx = *incx_, incy = *incy_, i;
  386. #ifdef _MSC_VER
  387. _Dcomplex zdotc = {0.0, 0.0};
  388. if (incx == 1 && incy == 1) {
  389. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  390. zdotc._Val[0] += conj(Cd(&x[i]))._Val[0] * Cd(&y[i])._Val[0];
  391. zdotc._Val[1] += conj(Cd(&x[i]))._Val[1] * Cd(&y[i])._Val[1];
  392. }
  393. } else {
  394. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  395. zdotc._Val[0] += conj(Cd(&x[i*incx]))._Val[0] * Cd(&y[i*incy])._Val[0];
  396. zdotc._Val[1] += conj(Cd(&x[i*incx]))._Val[1] * Cd(&y[i*incy])._Val[1];
  397. }
  398. }
  399. pCd(z) = zdotc;
  400. }
  401. #else
  402. _Complex double zdotc = 0.0;
  403. if (incx == 1 && incy == 1) {
  404. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  405. zdotc += conj(Cd(&x[i])) * Cd(&y[i]);
  406. }
  407. } else {
  408. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  409. zdotc += conj(Cd(&x[i*incx])) * Cd(&y[i*incy]);
  410. }
  411. }
  412. pCd(z) = zdotc;
  413. }
  414. #endif
  415. static inline void cdotu_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
  416. integer n = *n_, incx = *incx_, incy = *incy_, i;
  417. #ifdef _MSC_VER
  418. _Fcomplex zdotc = {0.0, 0.0};
  419. if (incx == 1 && incy == 1) {
  420. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  421. zdotc._Val[0] += Cf(&x[i])._Val[0] * Cf(&y[i])._Val[0];
  422. zdotc._Val[1] += Cf(&x[i])._Val[1] * Cf(&y[i])._Val[1];
  423. }
  424. } else {
  425. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  426. zdotc._Val[0] += Cf(&x[i*incx])._Val[0] * Cf(&y[i*incy])._Val[0];
  427. zdotc._Val[1] += Cf(&x[i*incx])._Val[1] * Cf(&y[i*incy])._Val[1];
  428. }
  429. }
  430. pCf(z) = zdotc;
  431. }
  432. #else
  433. _Complex float zdotc = 0.0;
  434. if (incx == 1 && incy == 1) {
  435. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  436. zdotc += Cf(&x[i]) * Cf(&y[i]);
  437. }
  438. } else {
  439. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  440. zdotc += Cf(&x[i*incx]) * Cf(&y[i*incy]);
  441. }
  442. }
  443. pCf(z) = zdotc;
  444. }
  445. #endif
  446. static inline void zdotu_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
  447. integer n = *n_, incx = *incx_, incy = *incy_, i;
  448. #ifdef _MSC_VER
  449. _Dcomplex zdotc = {0.0, 0.0};
  450. if (incx == 1 && incy == 1) {
  451. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  452. zdotc._Val[0] += Cd(&x[i])._Val[0] * Cd(&y[i])._Val[0];
  453. zdotc._Val[1] += Cd(&x[i])._Val[1] * Cd(&y[i])._Val[1];
  454. }
  455. } else {
  456. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  457. zdotc._Val[0] += Cd(&x[i*incx])._Val[0] * Cd(&y[i*incy])._Val[0];
  458. zdotc._Val[1] += Cd(&x[i*incx])._Val[1] * Cd(&y[i*incy])._Val[1];
  459. }
  460. }
  461. pCd(z) = zdotc;
  462. }
  463. #else
  464. _Complex double zdotc = 0.0;
  465. if (incx == 1 && incy == 1) {
  466. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  467. zdotc += Cd(&x[i]) * Cd(&y[i]);
  468. }
  469. } else {
  470. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  471. zdotc += Cd(&x[i*incx]) * Cd(&y[i*incy]);
  472. }
  473. }
  474. pCd(z) = zdotc;
  475. }
  476. #endif
  477. /* -- translated by f2c (version 20000121).
  478. You must link the resulting object file with the libraries:
  479. -lf2c -lm (in that order)
  480. */
  481. /* Table of constant values */
  482. static complex c_b1 = {0.f,0.f};
  483. static complex c_b2 = {1.f,0.f};
  484. static integer c__1 = 1;
  485. static integer c__2 = 2;
  486. /* > \brief \b CHGEQZ */
  487. /* =========== DOCUMENTATION =========== */
  488. /* Online html documentation available at */
  489. /* http://www.netlib.org/lapack/explore-html/ */
  490. /* > \htmlonly */
  491. /* > Download CHGEQZ + dependencies */
  492. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/chgeqz.
  493. f"> */
  494. /* > [TGZ]</a> */
  495. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/chgeqz.
  496. f"> */
  497. /* > [ZIP]</a> */
  498. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/chgeqz.
  499. f"> */
  500. /* > [TXT]</a> */
  501. /* > \endhtmlonly */
  502. /* Definition: */
  503. /* =========== */
  504. /* SUBROUTINE CHGEQZ( JOB, COMPQ, COMPZ, N, ILO, IHI, H, LDH, T, LDT, */
  505. /* ALPHA, BETA, Q, LDQ, Z, LDZ, WORK, LWORK, */
  506. /* RWORK, INFO ) */
  507. /* CHARACTER COMPQ, COMPZ, JOB */
  508. /* INTEGER IHI, ILO, INFO, LDH, LDQ, LDT, LDZ, LWORK, N */
  509. /* REAL RWORK( * ) */
  510. /* COMPLEX ALPHA( * ), BETA( * ), H( LDH, * ), */
  511. /* $ Q( LDQ, * ), T( LDT, * ), WORK( * ), */
  512. /* $ Z( LDZ, * ) */
  513. /* > \par Purpose: */
  514. /* ============= */
  515. /* > */
  516. /* > \verbatim */
  517. /* > */
  518. /* > CHGEQZ computes the eigenvalues of a complex matrix pair (H,T), */
  519. /* > where H is an upper Hessenberg matrix and T is upper triangular, */
  520. /* > using the single-shift QZ method. */
  521. /* > Matrix pairs of this type are produced by the reduction to */
  522. /* > generalized upper Hessenberg form of a complex matrix pair (A,B): */
  523. /* > */
  524. /* > A = Q1*H*Z1**H, B = Q1*T*Z1**H, */
  525. /* > */
  526. /* > as computed by CGGHRD. */
  527. /* > */
  528. /* > If JOB='S', then the Hessenberg-triangular pair (H,T) is */
  529. /* > also reduced to generalized Schur form, */
  530. /* > */
  531. /* > H = Q*S*Z**H, T = Q*P*Z**H, */
  532. /* > */
  533. /* > where Q and Z are unitary matrices and S and P are upper triangular. */
  534. /* > */
  535. /* > Optionally, the unitary matrix Q from the generalized Schur */
  536. /* > factorization may be postmultiplied into an input matrix Q1, and the */
  537. /* > unitary matrix Z may be postmultiplied into an input matrix Z1. */
  538. /* > If Q1 and Z1 are the unitary matrices from CGGHRD that reduced */
  539. /* > the matrix pair (A,B) to generalized Hessenberg form, then the output */
  540. /* > matrices Q1*Q and Z1*Z are the unitary factors from the generalized */
  541. /* > Schur factorization of (A,B): */
  542. /* > */
  543. /* > A = (Q1*Q)*S*(Z1*Z)**H, B = (Q1*Q)*P*(Z1*Z)**H. */
  544. /* > */
  545. /* > To avoid overflow, eigenvalues of the matrix pair (H,T) */
  546. /* > (equivalently, of (A,B)) are computed as a pair of complex values */
  547. /* > (alpha,beta). If beta is nonzero, lambda = alpha / beta is an */
  548. /* > eigenvalue of the generalized nonsymmetric eigenvalue problem (GNEP) */
  549. /* > A*x = lambda*B*x */
  550. /* > and if alpha is nonzero, mu = beta / alpha is an eigenvalue of the */
  551. /* > alternate form of the GNEP */
  552. /* > mu*A*y = B*y. */
  553. /* > The values of alpha and beta for the i-th eigenvalue can be read */
  554. /* > directly from the generalized Schur form: alpha = S(i,i), */
  555. /* > beta = P(i,i). */
  556. /* > */
  557. /* > Ref: C.B. Moler & G.W. Stewart, "An Algorithm for Generalized Matrix */
  558. /* > Eigenvalue Problems", SIAM J. Numer. Anal., 10(1973), */
  559. /* > pp. 241--256. */
  560. /* > \endverbatim */
  561. /* Arguments: */
  562. /* ========== */
  563. /* > \param[in] JOB */
  564. /* > \verbatim */
  565. /* > JOB is CHARACTER*1 */
  566. /* > = 'E': Compute eigenvalues only; */
  567. /* > = 'S': Computer eigenvalues and the Schur form. */
  568. /* > \endverbatim */
  569. /* > */
  570. /* > \param[in] COMPQ */
  571. /* > \verbatim */
  572. /* > COMPQ is CHARACTER*1 */
  573. /* > = 'N': Left Schur vectors (Q) are not computed; */
  574. /* > = 'I': Q is initialized to the unit matrix and the matrix Q */
  575. /* > of left Schur vectors of (H,T) is returned; */
  576. /* > = 'V': Q must contain a unitary matrix Q1 on entry and */
  577. /* > the product Q1*Q is returned. */
  578. /* > \endverbatim */
  579. /* > */
  580. /* > \param[in] COMPZ */
  581. /* > \verbatim */
  582. /* > COMPZ is CHARACTER*1 */
  583. /* > = 'N': Right Schur vectors (Z) are not computed; */
  584. /* > = 'I': Q is initialized to the unit matrix and the matrix Z */
  585. /* > of right Schur vectors of (H,T) is returned; */
  586. /* > = 'V': Z must contain a unitary matrix Z1 on entry and */
  587. /* > the product Z1*Z is returned. */
  588. /* > \endverbatim */
  589. /* > */
  590. /* > \param[in] N */
  591. /* > \verbatim */
  592. /* > N is INTEGER */
  593. /* > The order of the matrices H, T, Q, and Z. N >= 0. */
  594. /* > \endverbatim */
  595. /* > */
  596. /* > \param[in] ILO */
  597. /* > \verbatim */
  598. /* > ILO is INTEGER */
  599. /* > \endverbatim */
  600. /* > */
  601. /* > \param[in] IHI */
  602. /* > \verbatim */
  603. /* > IHI is INTEGER */
  604. /* > ILO and IHI mark the rows and columns of H which are in */
  605. /* > Hessenberg form. It is assumed that A is already upper */
  606. /* > triangular in rows and columns 1:ILO-1 and IHI+1:N. */
  607. /* > If N > 0, 1 <= ILO <= IHI <= N; if N = 0, ILO=1 and IHI=0. */
  608. /* > \endverbatim */
  609. /* > */
  610. /* > \param[in,out] H */
  611. /* > \verbatim */
  612. /* > H is COMPLEX array, dimension (LDH, N) */
  613. /* > On entry, the N-by-N upper Hessenberg matrix H. */
  614. /* > On exit, if JOB = 'S', H contains the upper triangular */
  615. /* > matrix S from the generalized Schur factorization. */
  616. /* > If JOB = 'E', the diagonal of H matches that of S, but */
  617. /* > the rest of H is unspecified. */
  618. /* > \endverbatim */
  619. /* > */
  620. /* > \param[in] LDH */
  621. /* > \verbatim */
  622. /* > LDH is INTEGER */
  623. /* > The leading dimension of the array H. LDH >= f2cmax( 1, N ). */
  624. /* > \endverbatim */
  625. /* > */
  626. /* > \param[in,out] T */
  627. /* > \verbatim */
  628. /* > T is COMPLEX array, dimension (LDT, N) */
  629. /* > On entry, the N-by-N upper triangular matrix T. */
  630. /* > On exit, if JOB = 'S', T contains the upper triangular */
  631. /* > matrix P from the generalized Schur factorization. */
  632. /* > If JOB = 'E', the diagonal of T matches that of P, but */
  633. /* > the rest of T is unspecified. */
  634. /* > \endverbatim */
  635. /* > */
  636. /* > \param[in] LDT */
  637. /* > \verbatim */
  638. /* > LDT is INTEGER */
  639. /* > The leading dimension of the array T. LDT >= f2cmax( 1, N ). */
  640. /* > \endverbatim */
  641. /* > */
  642. /* > \param[out] ALPHA */
  643. /* > \verbatim */
  644. /* > ALPHA is COMPLEX array, dimension (N) */
  645. /* > The complex scalars alpha that define the eigenvalues of */
  646. /* > GNEP. ALPHA(i) = S(i,i) in the generalized Schur */
  647. /* > factorization. */
  648. /* > \endverbatim */
  649. /* > */
  650. /* > \param[out] BETA */
  651. /* > \verbatim */
  652. /* > BETA is COMPLEX array, dimension (N) */
  653. /* > The real non-negative scalars beta that define the */
  654. /* > eigenvalues of GNEP. BETA(i) = P(i,i) in the generalized */
  655. /* > Schur factorization. */
  656. /* > */
  657. /* > Together, the quantities alpha = ALPHA(j) and beta = BETA(j) */
  658. /* > represent the j-th eigenvalue of the matrix pair (A,B), in */
  659. /* > one of the forms lambda = alpha/beta or mu = beta/alpha. */
  660. /* > Since either lambda or mu may overflow, they should not, */
  661. /* > in general, be computed. */
  662. /* > \endverbatim */
  663. /* > */
  664. /* > \param[in,out] Q */
  665. /* > \verbatim */
  666. /* > Q is COMPLEX array, dimension (LDQ, N) */
  667. /* > On entry, if COMPQ = 'V', the unitary matrix Q1 used in the */
  668. /* > reduction of (A,B) to generalized Hessenberg form. */
  669. /* > On exit, if COMPQ = 'I', the unitary matrix of left Schur */
  670. /* > vectors of (H,T), and if COMPQ = 'V', the unitary matrix of */
  671. /* > left Schur vectors of (A,B). */
  672. /* > Not referenced if COMPQ = 'N'. */
  673. /* > \endverbatim */
  674. /* > */
  675. /* > \param[in] LDQ */
  676. /* > \verbatim */
  677. /* > LDQ is INTEGER */
  678. /* > The leading dimension of the array Q. LDQ >= 1. */
  679. /* > If COMPQ='V' or 'I', then LDQ >= N. */
  680. /* > \endverbatim */
  681. /* > */
  682. /* > \param[in,out] Z */
  683. /* > \verbatim */
  684. /* > Z is COMPLEX array, dimension (LDZ, N) */
  685. /* > On entry, if COMPZ = 'V', the unitary matrix Z1 used in the */
  686. /* > reduction of (A,B) to generalized Hessenberg form. */
  687. /* > On exit, if COMPZ = 'I', the unitary matrix of right Schur */
  688. /* > vectors of (H,T), and if COMPZ = 'V', the unitary matrix of */
  689. /* > right Schur vectors of (A,B). */
  690. /* > Not referenced if COMPZ = 'N'. */
  691. /* > \endverbatim */
  692. /* > */
  693. /* > \param[in] LDZ */
  694. /* > \verbatim */
  695. /* > LDZ is INTEGER */
  696. /* > The leading dimension of the array Z. LDZ >= 1. */
  697. /* > If COMPZ='V' or 'I', then LDZ >= N. */
  698. /* > \endverbatim */
  699. /* > */
  700. /* > \param[out] WORK */
  701. /* > \verbatim */
  702. /* > WORK is COMPLEX array, dimension (MAX(1,LWORK)) */
  703. /* > On exit, if INFO >= 0, WORK(1) returns the optimal LWORK. */
  704. /* > \endverbatim */
  705. /* > */
  706. /* > \param[in] LWORK */
  707. /* > \verbatim */
  708. /* > LWORK is INTEGER */
  709. /* > The dimension of the array WORK. LWORK >= f2cmax(1,N). */
  710. /* > */
  711. /* > If LWORK = -1, then a workspace query is assumed; the routine */
  712. /* > only calculates the optimal size of the WORK array, returns */
  713. /* > this value as the first entry of the WORK array, and no error */
  714. /* > message related to LWORK is issued by XERBLA. */
  715. /* > \endverbatim */
  716. /* > */
  717. /* > \param[out] RWORK */
  718. /* > \verbatim */
  719. /* > RWORK is REAL array, dimension (N) */
  720. /* > \endverbatim */
  721. /* > */
  722. /* > \param[out] INFO */
  723. /* > \verbatim */
  724. /* > INFO is INTEGER */
  725. /* > = 0: successful exit */
  726. /* > < 0: if INFO = -i, the i-th argument had an illegal value */
  727. /* > = 1,...,N: the QZ iteration did not converge. (H,T) is not */
  728. /* > in Schur form, but ALPHA(i) and BETA(i), */
  729. /* > i=INFO+1,...,N should be correct. */
  730. /* > = N+1,...,2*N: the shift calculation failed. (H,T) is not */
  731. /* > in Schur form, but ALPHA(i) and BETA(i), */
  732. /* > i=INFO-N+1,...,N should be correct. */
  733. /* > \endverbatim */
  734. /* Authors: */
  735. /* ======== */
  736. /* > \author Univ. of Tennessee */
  737. /* > \author Univ. of California Berkeley */
  738. /* > \author Univ. of Colorado Denver */
  739. /* > \author NAG Ltd. */
  740. /* > \date April 2012 */
  741. /* > \ingroup complexGEcomputational */
  742. /* > \par Further Details: */
  743. /* ===================== */
  744. /* > */
  745. /* > \verbatim */
  746. /* > */
  747. /* > We assume that complex ABS works as long as its value is less than */
  748. /* > overflow. */
  749. /* > \endverbatim */
  750. /* > */
  751. /* ===================================================================== */
  752. /* Subroutine */ void chgeqz_(char *job, char *compq, char *compz, integer *n,
  753. integer *ilo, integer *ihi, complex *h__, integer *ldh, complex *t,
  754. integer *ldt, complex *alpha, complex *beta, complex *q, integer *ldq,
  755. complex *z__, integer *ldz, complex *work, integer *lwork, real *
  756. rwork, integer *info)
  757. {
  758. /* System generated locals */
  759. integer h_dim1, h_offset, q_dim1, q_offset, t_dim1, t_offset, z_dim1,
  760. z_offset, i__1, i__2, i__3, i__4, i__5, i__6;
  761. real r__1, r__2, r__3, r__4, r__5, r__6;
  762. complex q__1, q__2, q__3, q__4, q__5, q__6, q__7;
  763. /* Local variables */
  764. real absb, atol, btol, temp;
  765. extern /* Subroutine */ void crot_(integer *, complex *, integer *,
  766. complex *, integer *, real *, complex *);
  767. real temp2, c__;
  768. integer j;
  769. complex s;
  770. extern /* Subroutine */ void cscal_(integer *, complex *, complex *,
  771. integer *);
  772. complex x, y;
  773. extern logical lsame_(char *, char *);
  774. complex ctemp;
  775. integer iiter, ilast, jiter;
  776. real anorm, bnorm;
  777. integer maxit;
  778. complex shift;
  779. real tempr;
  780. complex ctemp2, ctemp3;
  781. logical ilazr2;
  782. integer jc, in;
  783. real ascale, bscale;
  784. complex u12;
  785. integer jr;
  786. extern /* Complex */ VOID cladiv_(complex *, complex *, complex *);
  787. complex signbc;
  788. extern real slamch_(char *), clanhs_(char *, integer *, complex *,
  789. integer *, real *);
  790. extern /* Subroutine */ void claset_(char *, integer *, integer *, complex
  791. *, complex *, complex *, integer *), clartg_(complex *,
  792. complex *, real *, complex *, complex *);
  793. real safmin;
  794. extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen);
  795. complex eshift;
  796. logical ilschr;
  797. integer icompq, ilastm, ischur;
  798. logical ilazro;
  799. integer icompz, ifirst, ifrstm, istart;
  800. logical lquery;
  801. complex ad11, ad12, ad21, ad22;
  802. integer jch;
  803. logical ilq, ilz;
  804. real ulp;
  805. complex abi12, abi22;
  806. /* -- LAPACK computational routine (version 3.7.0) -- */
  807. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  808. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  809. /* April 2012 */
  810. /* ===================================================================== */
  811. /* Decode JOB, COMPQ, COMPZ */
  812. /* Parameter adjustments */
  813. h_dim1 = *ldh;
  814. h_offset = 1 + h_dim1 * 1;
  815. h__ -= h_offset;
  816. t_dim1 = *ldt;
  817. t_offset = 1 + t_dim1 * 1;
  818. t -= t_offset;
  819. --alpha;
  820. --beta;
  821. q_dim1 = *ldq;
  822. q_offset = 1 + q_dim1 * 1;
  823. q -= q_offset;
  824. z_dim1 = *ldz;
  825. z_offset = 1 + z_dim1 * 1;
  826. z__ -= z_offset;
  827. --work;
  828. --rwork;
  829. /* Function Body */
  830. if (lsame_(job, "E")) {
  831. ilschr = FALSE_;
  832. ischur = 1;
  833. } else if (lsame_(job, "S")) {
  834. ilschr = TRUE_;
  835. ischur = 2;
  836. } else {
  837. ilschr = TRUE_;
  838. ischur = 0;
  839. }
  840. if (lsame_(compq, "N")) {
  841. ilq = FALSE_;
  842. icompq = 1;
  843. } else if (lsame_(compq, "V")) {
  844. ilq = TRUE_;
  845. icompq = 2;
  846. } else if (lsame_(compq, "I")) {
  847. ilq = TRUE_;
  848. icompq = 3;
  849. } else {
  850. ilq = TRUE_;
  851. icompq = 0;
  852. }
  853. if (lsame_(compz, "N")) {
  854. ilz = FALSE_;
  855. icompz = 1;
  856. } else if (lsame_(compz, "V")) {
  857. ilz = TRUE_;
  858. icompz = 2;
  859. } else if (lsame_(compz, "I")) {
  860. ilz = TRUE_;
  861. icompz = 3;
  862. } else {
  863. ilz = TRUE_;
  864. icompz = 0;
  865. }
  866. /* Check Argument Values */
  867. *info = 0;
  868. i__1 = f2cmax(1,*n);
  869. work[1].r = (real) i__1, work[1].i = 0.f;
  870. lquery = *lwork == -1;
  871. if (ischur == 0) {
  872. *info = -1;
  873. } else if (icompq == 0) {
  874. *info = -2;
  875. } else if (icompz == 0) {
  876. *info = -3;
  877. } else if (*n < 0) {
  878. *info = -4;
  879. } else if (*ilo < 1) {
  880. *info = -5;
  881. } else if (*ihi > *n || *ihi < *ilo - 1) {
  882. *info = -6;
  883. } else if (*ldh < *n) {
  884. *info = -8;
  885. } else if (*ldt < *n) {
  886. *info = -10;
  887. } else if (*ldq < 1 || ilq && *ldq < *n) {
  888. *info = -14;
  889. } else if (*ldz < 1 || ilz && *ldz < *n) {
  890. *info = -16;
  891. } else if (*lwork < f2cmax(1,*n) && ! lquery) {
  892. *info = -18;
  893. }
  894. if (*info != 0) {
  895. i__1 = -(*info);
  896. xerbla_("CHGEQZ", &i__1, (ftnlen)6);
  897. return;
  898. } else if (lquery) {
  899. return;
  900. }
  901. /* Quick return if possible */
  902. /* WORK( 1 ) = CMPLX( 1 ) */
  903. if (*n <= 0) {
  904. work[1].r = 1.f, work[1].i = 0.f;
  905. return;
  906. }
  907. /* Initialize Q and Z */
  908. if (icompq == 3) {
  909. claset_("Full", n, n, &c_b1, &c_b2, &q[q_offset], ldq);
  910. }
  911. if (icompz == 3) {
  912. claset_("Full", n, n, &c_b1, &c_b2, &z__[z_offset], ldz);
  913. }
  914. /* Machine Constants */
  915. in = *ihi + 1 - *ilo;
  916. safmin = slamch_("S");
  917. ulp = slamch_("E") * slamch_("B");
  918. anorm = clanhs_("F", &in, &h__[*ilo + *ilo * h_dim1], ldh, &rwork[1]);
  919. bnorm = clanhs_("F", &in, &t[*ilo + *ilo * t_dim1], ldt, &rwork[1]);
  920. /* Computing MAX */
  921. r__1 = safmin, r__2 = ulp * anorm;
  922. atol = f2cmax(r__1,r__2);
  923. /* Computing MAX */
  924. r__1 = safmin, r__2 = ulp * bnorm;
  925. btol = f2cmax(r__1,r__2);
  926. ascale = 1.f / f2cmax(safmin,anorm);
  927. bscale = 1.f / f2cmax(safmin,bnorm);
  928. /* Set Eigenvalues IHI+1:N */
  929. i__1 = *n;
  930. for (j = *ihi + 1; j <= i__1; ++j) {
  931. absb = c_abs(&t[j + j * t_dim1]);
  932. if (absb > safmin) {
  933. i__2 = j + j * t_dim1;
  934. q__2.r = t[i__2].r / absb, q__2.i = t[i__2].i / absb;
  935. r_cnjg(&q__1, &q__2);
  936. signbc.r = q__1.r, signbc.i = q__1.i;
  937. i__2 = j + j * t_dim1;
  938. t[i__2].r = absb, t[i__2].i = 0.f;
  939. if (ilschr) {
  940. i__2 = j - 1;
  941. cscal_(&i__2, &signbc, &t[j * t_dim1 + 1], &c__1);
  942. cscal_(&j, &signbc, &h__[j * h_dim1 + 1], &c__1);
  943. } else {
  944. cscal_(&c__1, &signbc, &h__[j + j * h_dim1], &c__1);
  945. }
  946. if (ilz) {
  947. cscal_(n, &signbc, &z__[j * z_dim1 + 1], &c__1);
  948. }
  949. } else {
  950. i__2 = j + j * t_dim1;
  951. t[i__2].r = 0.f, t[i__2].i = 0.f;
  952. }
  953. i__2 = j;
  954. i__3 = j + j * h_dim1;
  955. alpha[i__2].r = h__[i__3].r, alpha[i__2].i = h__[i__3].i;
  956. i__2 = j;
  957. i__3 = j + j * t_dim1;
  958. beta[i__2].r = t[i__3].r, beta[i__2].i = t[i__3].i;
  959. /* L10: */
  960. }
  961. /* If IHI < ILO, skip QZ steps */
  962. if (*ihi < *ilo) {
  963. goto L190;
  964. }
  965. /* MAIN QZ ITERATION LOOP */
  966. /* Initialize dynamic indices */
  967. /* Eigenvalues ILAST+1:N have been found. */
  968. /* Column operations modify rows IFRSTM:whatever */
  969. /* Row operations modify columns whatever:ILASTM */
  970. /* If only eigenvalues are being computed, then */
  971. /* IFRSTM is the row of the last splitting row above row ILAST; */
  972. /* this is always at least ILO. */
  973. /* IITER counts iterations since the last eigenvalue was found, */
  974. /* to tell when to use an extraordinary shift. */
  975. /* MAXIT is the maximum number of QZ sweeps allowed. */
  976. ilast = *ihi;
  977. if (ilschr) {
  978. ifrstm = 1;
  979. ilastm = *n;
  980. } else {
  981. ifrstm = *ilo;
  982. ilastm = *ihi;
  983. }
  984. iiter = 0;
  985. eshift.r = 0.f, eshift.i = 0.f;
  986. maxit = (*ihi - *ilo + 1) * 30;
  987. i__1 = maxit;
  988. for (jiter = 1; jiter <= i__1; ++jiter) {
  989. /* Check for too many iterations. */
  990. if (jiter > maxit) {
  991. goto L180;
  992. }
  993. /* Split the matrix if possible. */
  994. /* Two tests: */
  995. /* 1: H(j,j-1)=0 or j=ILO */
  996. /* 2: T(j,j)=0 */
  997. /* Special case: j=ILAST */
  998. if (ilast == *ilo) {
  999. goto L60;
  1000. } else {
  1001. i__2 = ilast + (ilast - 1) * h_dim1;
  1002. if ((r__1 = h__[i__2].r, abs(r__1)) + (r__2 = r_imag(&h__[ilast +
  1003. (ilast - 1) * h_dim1]), abs(r__2)) <= atol) {
  1004. i__2 = ilast + (ilast - 1) * h_dim1;
  1005. h__[i__2].r = 0.f, h__[i__2].i = 0.f;
  1006. goto L60;
  1007. }
  1008. }
  1009. if (c_abs(&t[ilast + ilast * t_dim1]) <= btol) {
  1010. i__2 = ilast + ilast * t_dim1;
  1011. t[i__2].r = 0.f, t[i__2].i = 0.f;
  1012. goto L50;
  1013. }
  1014. /* General case: j<ILAST */
  1015. i__2 = *ilo;
  1016. for (j = ilast - 1; j >= i__2; --j) {
  1017. /* Test 1: for H(j,j-1)=0 or j=ILO */
  1018. if (j == *ilo) {
  1019. ilazro = TRUE_;
  1020. } else {
  1021. i__3 = j + (j - 1) * h_dim1;
  1022. if ((r__1 = h__[i__3].r, abs(r__1)) + (r__2 = r_imag(&h__[j +
  1023. (j - 1) * h_dim1]), abs(r__2)) <= atol) {
  1024. i__3 = j + (j - 1) * h_dim1;
  1025. h__[i__3].r = 0.f, h__[i__3].i = 0.f;
  1026. ilazro = TRUE_;
  1027. } else {
  1028. ilazro = FALSE_;
  1029. }
  1030. }
  1031. /* Test 2: for T(j,j)=0 */
  1032. if (c_abs(&t[j + j * t_dim1]) < btol) {
  1033. i__3 = j + j * t_dim1;
  1034. t[i__3].r = 0.f, t[i__3].i = 0.f;
  1035. /* Test 1a: Check for 2 consecutive small subdiagonals in A */
  1036. ilazr2 = FALSE_;
  1037. if (! ilazro) {
  1038. i__3 = j + (j - 1) * h_dim1;
  1039. i__4 = j + 1 + j * h_dim1;
  1040. i__5 = j + j * h_dim1;
  1041. if (((r__1 = h__[i__3].r, abs(r__1)) + (r__2 = r_imag(&
  1042. h__[j + (j - 1) * h_dim1]), abs(r__2))) * (ascale
  1043. * ((r__3 = h__[i__4].r, abs(r__3)) + (r__4 =
  1044. r_imag(&h__[j + 1 + j * h_dim1]), abs(r__4)))) <=
  1045. ((r__5 = h__[i__5].r, abs(r__5)) + (r__6 = r_imag(
  1046. &h__[j + j * h_dim1]), abs(r__6))) * (ascale *
  1047. atol)) {
  1048. ilazr2 = TRUE_;
  1049. }
  1050. }
  1051. /* If both tests pass (1 & 2), i.e., the leading diagonal */
  1052. /* element of B in the block is zero, split a 1x1 block off */
  1053. /* at the top. (I.e., at the J-th row/column) The leading */
  1054. /* diagonal element of the remainder can also be zero, so */
  1055. /* this may have to be done repeatedly. */
  1056. if (ilazro || ilazr2) {
  1057. i__3 = ilast - 1;
  1058. for (jch = j; jch <= i__3; ++jch) {
  1059. i__4 = jch + jch * h_dim1;
  1060. ctemp.r = h__[i__4].r, ctemp.i = h__[i__4].i;
  1061. clartg_(&ctemp, &h__[jch + 1 + jch * h_dim1], &c__, &
  1062. s, &h__[jch + jch * h_dim1]);
  1063. i__4 = jch + 1 + jch * h_dim1;
  1064. h__[i__4].r = 0.f, h__[i__4].i = 0.f;
  1065. i__4 = ilastm - jch;
  1066. crot_(&i__4, &h__[jch + (jch + 1) * h_dim1], ldh, &
  1067. h__[jch + 1 + (jch + 1) * h_dim1], ldh, &c__,
  1068. &s);
  1069. i__4 = ilastm - jch;
  1070. crot_(&i__4, &t[jch + (jch + 1) * t_dim1], ldt, &t[
  1071. jch + 1 + (jch + 1) * t_dim1], ldt, &c__, &s);
  1072. if (ilq) {
  1073. r_cnjg(&q__1, &s);
  1074. crot_(n, &q[jch * q_dim1 + 1], &c__1, &q[(jch + 1)
  1075. * q_dim1 + 1], &c__1, &c__, &q__1);
  1076. }
  1077. if (ilazr2) {
  1078. i__4 = jch + (jch - 1) * h_dim1;
  1079. i__5 = jch + (jch - 1) * h_dim1;
  1080. q__1.r = c__ * h__[i__5].r, q__1.i = c__ * h__[
  1081. i__5].i;
  1082. h__[i__4].r = q__1.r, h__[i__4].i = q__1.i;
  1083. }
  1084. ilazr2 = FALSE_;
  1085. i__4 = jch + 1 + (jch + 1) * t_dim1;
  1086. if ((r__1 = t[i__4].r, abs(r__1)) + (r__2 = r_imag(&t[
  1087. jch + 1 + (jch + 1) * t_dim1]), abs(r__2)) >=
  1088. btol) {
  1089. if (jch + 1 >= ilast) {
  1090. goto L60;
  1091. } else {
  1092. ifirst = jch + 1;
  1093. goto L70;
  1094. }
  1095. }
  1096. i__4 = jch + 1 + (jch + 1) * t_dim1;
  1097. t[i__4].r = 0.f, t[i__4].i = 0.f;
  1098. /* L20: */
  1099. }
  1100. goto L50;
  1101. } else {
  1102. /* Only test 2 passed -- chase the zero to T(ILAST,ILAST) */
  1103. /* Then process as in the case T(ILAST,ILAST)=0 */
  1104. i__3 = ilast - 1;
  1105. for (jch = j; jch <= i__3; ++jch) {
  1106. i__4 = jch + (jch + 1) * t_dim1;
  1107. ctemp.r = t[i__4].r, ctemp.i = t[i__4].i;
  1108. clartg_(&ctemp, &t[jch + 1 + (jch + 1) * t_dim1], &
  1109. c__, &s, &t[jch + (jch + 1) * t_dim1]);
  1110. i__4 = jch + 1 + (jch + 1) * t_dim1;
  1111. t[i__4].r = 0.f, t[i__4].i = 0.f;
  1112. if (jch < ilastm - 1) {
  1113. i__4 = ilastm - jch - 1;
  1114. crot_(&i__4, &t[jch + (jch + 2) * t_dim1], ldt, &
  1115. t[jch + 1 + (jch + 2) * t_dim1], ldt, &
  1116. c__, &s);
  1117. }
  1118. i__4 = ilastm - jch + 2;
  1119. crot_(&i__4, &h__[jch + (jch - 1) * h_dim1], ldh, &
  1120. h__[jch + 1 + (jch - 1) * h_dim1], ldh, &c__,
  1121. &s);
  1122. if (ilq) {
  1123. r_cnjg(&q__1, &s);
  1124. crot_(n, &q[jch * q_dim1 + 1], &c__1, &q[(jch + 1)
  1125. * q_dim1 + 1], &c__1, &c__, &q__1);
  1126. }
  1127. i__4 = jch + 1 + jch * h_dim1;
  1128. ctemp.r = h__[i__4].r, ctemp.i = h__[i__4].i;
  1129. clartg_(&ctemp, &h__[jch + 1 + (jch - 1) * h_dim1], &
  1130. c__, &s, &h__[jch + 1 + jch * h_dim1]);
  1131. i__4 = jch + 1 + (jch - 1) * h_dim1;
  1132. h__[i__4].r = 0.f, h__[i__4].i = 0.f;
  1133. i__4 = jch + 1 - ifrstm;
  1134. crot_(&i__4, &h__[ifrstm + jch * h_dim1], &c__1, &h__[
  1135. ifrstm + (jch - 1) * h_dim1], &c__1, &c__, &s)
  1136. ;
  1137. i__4 = jch - ifrstm;
  1138. crot_(&i__4, &t[ifrstm + jch * t_dim1], &c__1, &t[
  1139. ifrstm + (jch - 1) * t_dim1], &c__1, &c__, &s)
  1140. ;
  1141. if (ilz) {
  1142. crot_(n, &z__[jch * z_dim1 + 1], &c__1, &z__[(jch
  1143. - 1) * z_dim1 + 1], &c__1, &c__, &s);
  1144. }
  1145. /* L30: */
  1146. }
  1147. goto L50;
  1148. }
  1149. } else if (ilazro) {
  1150. /* Only test 1 passed -- work on J:ILAST */
  1151. ifirst = j;
  1152. goto L70;
  1153. }
  1154. /* Neither test passed -- try next J */
  1155. /* L40: */
  1156. }
  1157. /* (Drop-through is "impossible") */
  1158. *info = (*n << 1) + 1;
  1159. goto L210;
  1160. /* T(ILAST,ILAST)=0 -- clear H(ILAST,ILAST-1) to split off a */
  1161. /* 1x1 block. */
  1162. L50:
  1163. i__2 = ilast + ilast * h_dim1;
  1164. ctemp.r = h__[i__2].r, ctemp.i = h__[i__2].i;
  1165. clartg_(&ctemp, &h__[ilast + (ilast - 1) * h_dim1], &c__, &s, &h__[
  1166. ilast + ilast * h_dim1]);
  1167. i__2 = ilast + (ilast - 1) * h_dim1;
  1168. h__[i__2].r = 0.f, h__[i__2].i = 0.f;
  1169. i__2 = ilast - ifrstm;
  1170. crot_(&i__2, &h__[ifrstm + ilast * h_dim1], &c__1, &h__[ifrstm + (
  1171. ilast - 1) * h_dim1], &c__1, &c__, &s);
  1172. i__2 = ilast - ifrstm;
  1173. crot_(&i__2, &t[ifrstm + ilast * t_dim1], &c__1, &t[ifrstm + (ilast -
  1174. 1) * t_dim1], &c__1, &c__, &s);
  1175. if (ilz) {
  1176. crot_(n, &z__[ilast * z_dim1 + 1], &c__1, &z__[(ilast - 1) *
  1177. z_dim1 + 1], &c__1, &c__, &s);
  1178. }
  1179. /* H(ILAST,ILAST-1)=0 -- Standardize B, set ALPHA and BETA */
  1180. L60:
  1181. absb = c_abs(&t[ilast + ilast * t_dim1]);
  1182. if (absb > safmin) {
  1183. i__2 = ilast + ilast * t_dim1;
  1184. q__2.r = t[i__2].r / absb, q__2.i = t[i__2].i / absb;
  1185. r_cnjg(&q__1, &q__2);
  1186. signbc.r = q__1.r, signbc.i = q__1.i;
  1187. i__2 = ilast + ilast * t_dim1;
  1188. t[i__2].r = absb, t[i__2].i = 0.f;
  1189. if (ilschr) {
  1190. i__2 = ilast - ifrstm;
  1191. cscal_(&i__2, &signbc, &t[ifrstm + ilast * t_dim1], &c__1);
  1192. i__2 = ilast + 1 - ifrstm;
  1193. cscal_(&i__2, &signbc, &h__[ifrstm + ilast * h_dim1], &c__1);
  1194. } else {
  1195. cscal_(&c__1, &signbc, &h__[ilast + ilast * h_dim1], &c__1);
  1196. }
  1197. if (ilz) {
  1198. cscal_(n, &signbc, &z__[ilast * z_dim1 + 1], &c__1);
  1199. }
  1200. } else {
  1201. i__2 = ilast + ilast * t_dim1;
  1202. t[i__2].r = 0.f, t[i__2].i = 0.f;
  1203. }
  1204. i__2 = ilast;
  1205. i__3 = ilast + ilast * h_dim1;
  1206. alpha[i__2].r = h__[i__3].r, alpha[i__2].i = h__[i__3].i;
  1207. i__2 = ilast;
  1208. i__3 = ilast + ilast * t_dim1;
  1209. beta[i__2].r = t[i__3].r, beta[i__2].i = t[i__3].i;
  1210. /* Go to next block -- exit if finished. */
  1211. --ilast;
  1212. if (ilast < *ilo) {
  1213. goto L190;
  1214. }
  1215. /* Reset counters */
  1216. iiter = 0;
  1217. eshift.r = 0.f, eshift.i = 0.f;
  1218. if (! ilschr) {
  1219. ilastm = ilast;
  1220. if (ifrstm > ilast) {
  1221. ifrstm = *ilo;
  1222. }
  1223. }
  1224. goto L160;
  1225. /* QZ step */
  1226. /* This iteration only involves rows/columns IFIRST:ILAST. We */
  1227. /* assume IFIRST < ILAST, and that the diagonal of B is non-zero. */
  1228. L70:
  1229. ++iiter;
  1230. if (! ilschr) {
  1231. ifrstm = ifirst;
  1232. }
  1233. /* Compute the Shift. */
  1234. /* At this point, IFIRST < ILAST, and the diagonal elements of */
  1235. /* T(IFIRST:ILAST,IFIRST,ILAST) are larger than BTOL (in */
  1236. /* magnitude) */
  1237. if (iiter / 10 * 10 != iiter) {
  1238. /* The Wilkinson shift (AEP p.512), i.e., the eigenvalue of */
  1239. /* the bottom-right 2x2 block of A inv(B) which is nearest to */
  1240. /* the bottom-right element. */
  1241. /* We factor B as U*D, where U has unit diagonals, and */
  1242. /* compute (A*inv(D))*inv(U). */
  1243. i__2 = ilast - 1 + ilast * t_dim1;
  1244. q__2.r = bscale * t[i__2].r, q__2.i = bscale * t[i__2].i;
  1245. i__3 = ilast + ilast * t_dim1;
  1246. q__3.r = bscale * t[i__3].r, q__3.i = bscale * t[i__3].i;
  1247. c_div(&q__1, &q__2, &q__3);
  1248. u12.r = q__1.r, u12.i = q__1.i;
  1249. i__2 = ilast - 1 + (ilast - 1) * h_dim1;
  1250. q__2.r = ascale * h__[i__2].r, q__2.i = ascale * h__[i__2].i;
  1251. i__3 = ilast - 1 + (ilast - 1) * t_dim1;
  1252. q__3.r = bscale * t[i__3].r, q__3.i = bscale * t[i__3].i;
  1253. c_div(&q__1, &q__2, &q__3);
  1254. ad11.r = q__1.r, ad11.i = q__1.i;
  1255. i__2 = ilast + (ilast - 1) * h_dim1;
  1256. q__2.r = ascale * h__[i__2].r, q__2.i = ascale * h__[i__2].i;
  1257. i__3 = ilast - 1 + (ilast - 1) * t_dim1;
  1258. q__3.r = bscale * t[i__3].r, q__3.i = bscale * t[i__3].i;
  1259. c_div(&q__1, &q__2, &q__3);
  1260. ad21.r = q__1.r, ad21.i = q__1.i;
  1261. i__2 = ilast - 1 + ilast * h_dim1;
  1262. q__2.r = ascale * h__[i__2].r, q__2.i = ascale * h__[i__2].i;
  1263. i__3 = ilast + ilast * t_dim1;
  1264. q__3.r = bscale * t[i__3].r, q__3.i = bscale * t[i__3].i;
  1265. c_div(&q__1, &q__2, &q__3);
  1266. ad12.r = q__1.r, ad12.i = q__1.i;
  1267. i__2 = ilast + ilast * h_dim1;
  1268. q__2.r = ascale * h__[i__2].r, q__2.i = ascale * h__[i__2].i;
  1269. i__3 = ilast + ilast * t_dim1;
  1270. q__3.r = bscale * t[i__3].r, q__3.i = bscale * t[i__3].i;
  1271. c_div(&q__1, &q__2, &q__3);
  1272. ad22.r = q__1.r, ad22.i = q__1.i;
  1273. q__2.r = u12.r * ad21.r - u12.i * ad21.i, q__2.i = u12.r * ad21.i
  1274. + u12.i * ad21.r;
  1275. q__1.r = ad22.r - q__2.r, q__1.i = ad22.i - q__2.i;
  1276. abi22.r = q__1.r, abi22.i = q__1.i;
  1277. q__2.r = u12.r * ad11.r - u12.i * ad11.i, q__2.i = u12.r * ad11.i
  1278. + u12.i * ad11.r;
  1279. q__1.r = ad12.r - q__2.r, q__1.i = ad12.i - q__2.i;
  1280. abi12.r = q__1.r, abi12.i = q__1.i;
  1281. shift.r = abi22.r, shift.i = abi22.i;
  1282. c_sqrt(&q__2, &abi12);
  1283. c_sqrt(&q__3, &ad21);
  1284. q__1.r = q__2.r * q__3.r - q__2.i * q__3.i, q__1.i = q__2.r *
  1285. q__3.i + q__2.i * q__3.r;
  1286. ctemp.r = q__1.r, ctemp.i = q__1.i;
  1287. temp = (r__1 = ctemp.r, abs(r__1)) + (r__2 = r_imag(&ctemp), abs(
  1288. r__2));
  1289. if (ctemp.r != 0.f || ctemp.i != 0.f) {
  1290. q__2.r = ad11.r - shift.r, q__2.i = ad11.i - shift.i;
  1291. q__1.r = q__2.r * .5f, q__1.i = q__2.i * .5f;
  1292. x.r = q__1.r, x.i = q__1.i;
  1293. temp2 = (r__1 = x.r, abs(r__1)) + (r__2 = r_imag(&x), abs(
  1294. r__2));
  1295. /* Computing MAX */
  1296. r__3 = temp, r__4 = (r__1 = x.r, abs(r__1)) + (r__2 = r_imag(&
  1297. x), abs(r__2));
  1298. temp = f2cmax(r__3,r__4);
  1299. q__5.r = x.r / temp, q__5.i = x.i / temp;
  1300. pow_ci(&q__4, &q__5, &c__2);
  1301. q__7.r = ctemp.r / temp, q__7.i = ctemp.i / temp;
  1302. pow_ci(&q__6, &q__7, &c__2);
  1303. q__3.r = q__4.r + q__6.r, q__3.i = q__4.i + q__6.i;
  1304. c_sqrt(&q__2, &q__3);
  1305. q__1.r = temp * q__2.r, q__1.i = temp * q__2.i;
  1306. y.r = q__1.r, y.i = q__1.i;
  1307. if (temp2 > 0.f) {
  1308. q__1.r = x.r / temp2, q__1.i = x.i / temp2;
  1309. q__2.r = x.r / temp2, q__2.i = x.i / temp2;
  1310. if (q__1.r * y.r + r_imag(&q__2) * r_imag(&y) < 0.f) {
  1311. q__3.r = -y.r, q__3.i = -y.i;
  1312. y.r = q__3.r, y.i = q__3.i;
  1313. }
  1314. }
  1315. q__4.r = x.r + y.r, q__4.i = x.i + y.i;
  1316. cladiv_(&q__3, &ctemp, &q__4);
  1317. q__2.r = ctemp.r * q__3.r - ctemp.i * q__3.i, q__2.i =
  1318. ctemp.r * q__3.i + ctemp.i * q__3.r;
  1319. q__1.r = shift.r - q__2.r, q__1.i = shift.i - q__2.i;
  1320. shift.r = q__1.r, shift.i = q__1.i;
  1321. }
  1322. } else {
  1323. /* Exceptional shift. Chosen for no particularly good reason. */
  1324. i__2 = ilast + ilast * t_dim1;
  1325. if (iiter / 20 * 20 == iiter && bscale * ((r__1 = t[i__2].r, abs(
  1326. r__1)) + (r__2 = r_imag(&t[ilast + ilast * t_dim1]), abs(
  1327. r__2))) > safmin) {
  1328. i__2 = ilast + ilast * h_dim1;
  1329. q__3.r = ascale * h__[i__2].r, q__3.i = ascale * h__[i__2].i;
  1330. i__3 = ilast + ilast * t_dim1;
  1331. q__4.r = bscale * t[i__3].r, q__4.i = bscale * t[i__3].i;
  1332. c_div(&q__2, &q__3, &q__4);
  1333. q__1.r = eshift.r + q__2.r, q__1.i = eshift.i + q__2.i;
  1334. eshift.r = q__1.r, eshift.i = q__1.i;
  1335. } else {
  1336. i__2 = ilast + (ilast - 1) * h_dim1;
  1337. q__3.r = ascale * h__[i__2].r, q__3.i = ascale * h__[i__2].i;
  1338. i__3 = ilast - 1 + (ilast - 1) * t_dim1;
  1339. q__4.r = bscale * t[i__3].r, q__4.i = bscale * t[i__3].i;
  1340. c_div(&q__2, &q__3, &q__4);
  1341. q__1.r = eshift.r + q__2.r, q__1.i = eshift.i + q__2.i;
  1342. eshift.r = q__1.r, eshift.i = q__1.i;
  1343. }
  1344. shift.r = eshift.r, shift.i = eshift.i;
  1345. }
  1346. /* Now check for two consecutive small subdiagonals. */
  1347. i__2 = ifirst + 1;
  1348. for (j = ilast - 1; j >= i__2; --j) {
  1349. istart = j;
  1350. i__3 = j + j * h_dim1;
  1351. q__2.r = ascale * h__[i__3].r, q__2.i = ascale * h__[i__3].i;
  1352. i__4 = j + j * t_dim1;
  1353. q__4.r = bscale * t[i__4].r, q__4.i = bscale * t[i__4].i;
  1354. q__3.r = shift.r * q__4.r - shift.i * q__4.i, q__3.i = shift.r *
  1355. q__4.i + shift.i * q__4.r;
  1356. q__1.r = q__2.r - q__3.r, q__1.i = q__2.i - q__3.i;
  1357. ctemp.r = q__1.r, ctemp.i = q__1.i;
  1358. temp = (r__1 = ctemp.r, abs(r__1)) + (r__2 = r_imag(&ctemp), abs(
  1359. r__2));
  1360. i__3 = j + 1 + j * h_dim1;
  1361. temp2 = ascale * ((r__1 = h__[i__3].r, abs(r__1)) + (r__2 =
  1362. r_imag(&h__[j + 1 + j * h_dim1]), abs(r__2)));
  1363. tempr = f2cmax(temp,temp2);
  1364. if (tempr < 1.f && tempr != 0.f) {
  1365. temp /= tempr;
  1366. temp2 /= tempr;
  1367. }
  1368. i__3 = j + (j - 1) * h_dim1;
  1369. if (((r__1 = h__[i__3].r, abs(r__1)) + (r__2 = r_imag(&h__[j + (j
  1370. - 1) * h_dim1]), abs(r__2))) * temp2 <= temp * atol) {
  1371. goto L90;
  1372. }
  1373. /* L80: */
  1374. }
  1375. istart = ifirst;
  1376. i__2 = ifirst + ifirst * h_dim1;
  1377. q__2.r = ascale * h__[i__2].r, q__2.i = ascale * h__[i__2].i;
  1378. i__3 = ifirst + ifirst * t_dim1;
  1379. q__4.r = bscale * t[i__3].r, q__4.i = bscale * t[i__3].i;
  1380. q__3.r = shift.r * q__4.r - shift.i * q__4.i, q__3.i = shift.r *
  1381. q__4.i + shift.i * q__4.r;
  1382. q__1.r = q__2.r - q__3.r, q__1.i = q__2.i - q__3.i;
  1383. ctemp.r = q__1.r, ctemp.i = q__1.i;
  1384. L90:
  1385. /* Do an implicit-shift QZ sweep. */
  1386. /* Initial Q */
  1387. i__2 = istart + 1 + istart * h_dim1;
  1388. q__1.r = ascale * h__[i__2].r, q__1.i = ascale * h__[i__2].i;
  1389. ctemp2.r = q__1.r, ctemp2.i = q__1.i;
  1390. clartg_(&ctemp, &ctemp2, &c__, &s, &ctemp3);
  1391. /* Sweep */
  1392. i__2 = ilast - 1;
  1393. for (j = istart; j <= i__2; ++j) {
  1394. if (j > istart) {
  1395. i__3 = j + (j - 1) * h_dim1;
  1396. ctemp.r = h__[i__3].r, ctemp.i = h__[i__3].i;
  1397. clartg_(&ctemp, &h__[j + 1 + (j - 1) * h_dim1], &c__, &s, &
  1398. h__[j + (j - 1) * h_dim1]);
  1399. i__3 = j + 1 + (j - 1) * h_dim1;
  1400. h__[i__3].r = 0.f, h__[i__3].i = 0.f;
  1401. }
  1402. i__3 = ilastm;
  1403. for (jc = j; jc <= i__3; ++jc) {
  1404. i__4 = j + jc * h_dim1;
  1405. q__2.r = c__ * h__[i__4].r, q__2.i = c__ * h__[i__4].i;
  1406. i__5 = j + 1 + jc * h_dim1;
  1407. q__3.r = s.r * h__[i__5].r - s.i * h__[i__5].i, q__3.i = s.r *
  1408. h__[i__5].i + s.i * h__[i__5].r;
  1409. q__1.r = q__2.r + q__3.r, q__1.i = q__2.i + q__3.i;
  1410. ctemp.r = q__1.r, ctemp.i = q__1.i;
  1411. i__4 = j + 1 + jc * h_dim1;
  1412. r_cnjg(&q__4, &s);
  1413. q__3.r = -q__4.r, q__3.i = -q__4.i;
  1414. i__5 = j + jc * h_dim1;
  1415. q__2.r = q__3.r * h__[i__5].r - q__3.i * h__[i__5].i, q__2.i =
  1416. q__3.r * h__[i__5].i + q__3.i * h__[i__5].r;
  1417. i__6 = j + 1 + jc * h_dim1;
  1418. q__5.r = c__ * h__[i__6].r, q__5.i = c__ * h__[i__6].i;
  1419. q__1.r = q__2.r + q__5.r, q__1.i = q__2.i + q__5.i;
  1420. h__[i__4].r = q__1.r, h__[i__4].i = q__1.i;
  1421. i__4 = j + jc * h_dim1;
  1422. h__[i__4].r = ctemp.r, h__[i__4].i = ctemp.i;
  1423. i__4 = j + jc * t_dim1;
  1424. q__2.r = c__ * t[i__4].r, q__2.i = c__ * t[i__4].i;
  1425. i__5 = j + 1 + jc * t_dim1;
  1426. q__3.r = s.r * t[i__5].r - s.i * t[i__5].i, q__3.i = s.r * t[
  1427. i__5].i + s.i * t[i__5].r;
  1428. q__1.r = q__2.r + q__3.r, q__1.i = q__2.i + q__3.i;
  1429. ctemp2.r = q__1.r, ctemp2.i = q__1.i;
  1430. i__4 = j + 1 + jc * t_dim1;
  1431. r_cnjg(&q__4, &s);
  1432. q__3.r = -q__4.r, q__3.i = -q__4.i;
  1433. i__5 = j + jc * t_dim1;
  1434. q__2.r = q__3.r * t[i__5].r - q__3.i * t[i__5].i, q__2.i =
  1435. q__3.r * t[i__5].i + q__3.i * t[i__5].r;
  1436. i__6 = j + 1 + jc * t_dim1;
  1437. q__5.r = c__ * t[i__6].r, q__5.i = c__ * t[i__6].i;
  1438. q__1.r = q__2.r + q__5.r, q__1.i = q__2.i + q__5.i;
  1439. t[i__4].r = q__1.r, t[i__4].i = q__1.i;
  1440. i__4 = j + jc * t_dim1;
  1441. t[i__4].r = ctemp2.r, t[i__4].i = ctemp2.i;
  1442. /* L100: */
  1443. }
  1444. if (ilq) {
  1445. i__3 = *n;
  1446. for (jr = 1; jr <= i__3; ++jr) {
  1447. i__4 = jr + j * q_dim1;
  1448. q__2.r = c__ * q[i__4].r, q__2.i = c__ * q[i__4].i;
  1449. r_cnjg(&q__4, &s);
  1450. i__5 = jr + (j + 1) * q_dim1;
  1451. q__3.r = q__4.r * q[i__5].r - q__4.i * q[i__5].i, q__3.i =
  1452. q__4.r * q[i__5].i + q__4.i * q[i__5].r;
  1453. q__1.r = q__2.r + q__3.r, q__1.i = q__2.i + q__3.i;
  1454. ctemp.r = q__1.r, ctemp.i = q__1.i;
  1455. i__4 = jr + (j + 1) * q_dim1;
  1456. q__3.r = -s.r, q__3.i = -s.i;
  1457. i__5 = jr + j * q_dim1;
  1458. q__2.r = q__3.r * q[i__5].r - q__3.i * q[i__5].i, q__2.i =
  1459. q__3.r * q[i__5].i + q__3.i * q[i__5].r;
  1460. i__6 = jr + (j + 1) * q_dim1;
  1461. q__4.r = c__ * q[i__6].r, q__4.i = c__ * q[i__6].i;
  1462. q__1.r = q__2.r + q__4.r, q__1.i = q__2.i + q__4.i;
  1463. q[i__4].r = q__1.r, q[i__4].i = q__1.i;
  1464. i__4 = jr + j * q_dim1;
  1465. q[i__4].r = ctemp.r, q[i__4].i = ctemp.i;
  1466. /* L110: */
  1467. }
  1468. }
  1469. i__3 = j + 1 + (j + 1) * t_dim1;
  1470. ctemp.r = t[i__3].r, ctemp.i = t[i__3].i;
  1471. clartg_(&ctemp, &t[j + 1 + j * t_dim1], &c__, &s, &t[j + 1 + (j +
  1472. 1) * t_dim1]);
  1473. i__3 = j + 1 + j * t_dim1;
  1474. t[i__3].r = 0.f, t[i__3].i = 0.f;
  1475. /* Computing MIN */
  1476. i__4 = j + 2;
  1477. i__3 = f2cmin(i__4,ilast);
  1478. for (jr = ifrstm; jr <= i__3; ++jr) {
  1479. i__4 = jr + (j + 1) * h_dim1;
  1480. q__2.r = c__ * h__[i__4].r, q__2.i = c__ * h__[i__4].i;
  1481. i__5 = jr + j * h_dim1;
  1482. q__3.r = s.r * h__[i__5].r - s.i * h__[i__5].i, q__3.i = s.r *
  1483. h__[i__5].i + s.i * h__[i__5].r;
  1484. q__1.r = q__2.r + q__3.r, q__1.i = q__2.i + q__3.i;
  1485. ctemp.r = q__1.r, ctemp.i = q__1.i;
  1486. i__4 = jr + j * h_dim1;
  1487. r_cnjg(&q__4, &s);
  1488. q__3.r = -q__4.r, q__3.i = -q__4.i;
  1489. i__5 = jr + (j + 1) * h_dim1;
  1490. q__2.r = q__3.r * h__[i__5].r - q__3.i * h__[i__5].i, q__2.i =
  1491. q__3.r * h__[i__5].i + q__3.i * h__[i__5].r;
  1492. i__6 = jr + j * h_dim1;
  1493. q__5.r = c__ * h__[i__6].r, q__5.i = c__ * h__[i__6].i;
  1494. q__1.r = q__2.r + q__5.r, q__1.i = q__2.i + q__5.i;
  1495. h__[i__4].r = q__1.r, h__[i__4].i = q__1.i;
  1496. i__4 = jr + (j + 1) * h_dim1;
  1497. h__[i__4].r = ctemp.r, h__[i__4].i = ctemp.i;
  1498. /* L120: */
  1499. }
  1500. i__3 = j;
  1501. for (jr = ifrstm; jr <= i__3; ++jr) {
  1502. i__4 = jr + (j + 1) * t_dim1;
  1503. q__2.r = c__ * t[i__4].r, q__2.i = c__ * t[i__4].i;
  1504. i__5 = jr + j * t_dim1;
  1505. q__3.r = s.r * t[i__5].r - s.i * t[i__5].i, q__3.i = s.r * t[
  1506. i__5].i + s.i * t[i__5].r;
  1507. q__1.r = q__2.r + q__3.r, q__1.i = q__2.i + q__3.i;
  1508. ctemp.r = q__1.r, ctemp.i = q__1.i;
  1509. i__4 = jr + j * t_dim1;
  1510. r_cnjg(&q__4, &s);
  1511. q__3.r = -q__4.r, q__3.i = -q__4.i;
  1512. i__5 = jr + (j + 1) * t_dim1;
  1513. q__2.r = q__3.r * t[i__5].r - q__3.i * t[i__5].i, q__2.i =
  1514. q__3.r * t[i__5].i + q__3.i * t[i__5].r;
  1515. i__6 = jr + j * t_dim1;
  1516. q__5.r = c__ * t[i__6].r, q__5.i = c__ * t[i__6].i;
  1517. q__1.r = q__2.r + q__5.r, q__1.i = q__2.i + q__5.i;
  1518. t[i__4].r = q__1.r, t[i__4].i = q__1.i;
  1519. i__4 = jr + (j + 1) * t_dim1;
  1520. t[i__4].r = ctemp.r, t[i__4].i = ctemp.i;
  1521. /* L130: */
  1522. }
  1523. if (ilz) {
  1524. i__3 = *n;
  1525. for (jr = 1; jr <= i__3; ++jr) {
  1526. i__4 = jr + (j + 1) * z_dim1;
  1527. q__2.r = c__ * z__[i__4].r, q__2.i = c__ * z__[i__4].i;
  1528. i__5 = jr + j * z_dim1;
  1529. q__3.r = s.r * z__[i__5].r - s.i * z__[i__5].i, q__3.i =
  1530. s.r * z__[i__5].i + s.i * z__[i__5].r;
  1531. q__1.r = q__2.r + q__3.r, q__1.i = q__2.i + q__3.i;
  1532. ctemp.r = q__1.r, ctemp.i = q__1.i;
  1533. i__4 = jr + j * z_dim1;
  1534. r_cnjg(&q__4, &s);
  1535. q__3.r = -q__4.r, q__3.i = -q__4.i;
  1536. i__5 = jr + (j + 1) * z_dim1;
  1537. q__2.r = q__3.r * z__[i__5].r - q__3.i * z__[i__5].i,
  1538. q__2.i = q__3.r * z__[i__5].i + q__3.i * z__[i__5]
  1539. .r;
  1540. i__6 = jr + j * z_dim1;
  1541. q__5.r = c__ * z__[i__6].r, q__5.i = c__ * z__[i__6].i;
  1542. q__1.r = q__2.r + q__5.r, q__1.i = q__2.i + q__5.i;
  1543. z__[i__4].r = q__1.r, z__[i__4].i = q__1.i;
  1544. i__4 = jr + (j + 1) * z_dim1;
  1545. z__[i__4].r = ctemp.r, z__[i__4].i = ctemp.i;
  1546. /* L140: */
  1547. }
  1548. }
  1549. /* L150: */
  1550. }
  1551. L160:
  1552. /* L170: */
  1553. ;
  1554. }
  1555. /* Drop-through = non-convergence */
  1556. L180:
  1557. *info = ilast;
  1558. goto L210;
  1559. /* Successful completion of all QZ steps */
  1560. L190:
  1561. /* Set Eigenvalues 1:ILO-1 */
  1562. i__1 = *ilo - 1;
  1563. for (j = 1; j <= i__1; ++j) {
  1564. absb = c_abs(&t[j + j * t_dim1]);
  1565. if (absb > safmin) {
  1566. i__2 = j + j * t_dim1;
  1567. q__2.r = t[i__2].r / absb, q__2.i = t[i__2].i / absb;
  1568. r_cnjg(&q__1, &q__2);
  1569. signbc.r = q__1.r, signbc.i = q__1.i;
  1570. i__2 = j + j * t_dim1;
  1571. t[i__2].r = absb, t[i__2].i = 0.f;
  1572. if (ilschr) {
  1573. i__2 = j - 1;
  1574. cscal_(&i__2, &signbc, &t[j * t_dim1 + 1], &c__1);
  1575. cscal_(&j, &signbc, &h__[j * h_dim1 + 1], &c__1);
  1576. } else {
  1577. cscal_(&c__1, &signbc, &h__[j + j * h_dim1], &c__1);
  1578. }
  1579. if (ilz) {
  1580. cscal_(n, &signbc, &z__[j * z_dim1 + 1], &c__1);
  1581. }
  1582. } else {
  1583. i__2 = j + j * t_dim1;
  1584. t[i__2].r = 0.f, t[i__2].i = 0.f;
  1585. }
  1586. i__2 = j;
  1587. i__3 = j + j * h_dim1;
  1588. alpha[i__2].r = h__[i__3].r, alpha[i__2].i = h__[i__3].i;
  1589. i__2 = j;
  1590. i__3 = j + j * t_dim1;
  1591. beta[i__2].r = t[i__3].r, beta[i__2].i = t[i__3].i;
  1592. /* L200: */
  1593. }
  1594. /* Normal Termination */
  1595. *info = 0;
  1596. /* Exit (other than argument error) -- return optimal workspace size */
  1597. L210:
  1598. q__1.r = (real) (*n), q__1.i = 0.f;
  1599. work[1].r = q__1.r, work[1].i = q__1.i;
  1600. return;
  1601. /* End of CHGEQZ */
  1602. } /* chgeqz_ */