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.

zhgeqz.c 54 kB

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