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