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