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.

dhgeqz.c 61 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109
  1. #include <math.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <stdio.h>
  5. #include <complex.h>
  6. #ifdef complex
  7. #undef complex
  8. #endif
  9. #ifdef I
  10. #undef I
  11. #endif
  12. #if defined(_WIN64)
  13. typedef long long BLASLONG;
  14. typedef unsigned long long BLASULONG;
  15. #else
  16. typedef long BLASLONG;
  17. typedef unsigned long BLASULONG;
  18. #endif
  19. #ifdef LAPACK_ILP64
  20. typedef BLASLONG blasint;
  21. #if defined(_WIN64)
  22. #define blasabs(x) llabs(x)
  23. #else
  24. #define blasabs(x) labs(x)
  25. #endif
  26. #else
  27. typedef int blasint;
  28. #define blasabs(x) abs(x)
  29. #endif
  30. typedef blasint integer;
  31. typedef unsigned int uinteger;
  32. typedef char *address;
  33. typedef short int shortint;
  34. typedef float real;
  35. typedef double doublereal;
  36. typedef struct { real r, i; } complex;
  37. typedef struct { doublereal r, i; } doublecomplex;
  38. #ifdef _MSC_VER
  39. static inline _Fcomplex Cf(complex *z) {_Fcomplex zz={z->r , z->i}; return zz;}
  40. static inline _Dcomplex Cd(doublecomplex *z) {_Dcomplex zz={z->r , z->i};return zz;}
  41. static inline _Fcomplex * _pCf(complex *z) {return (_Fcomplex*)z;}
  42. static inline _Dcomplex * _pCd(doublecomplex *z) {return (_Dcomplex*)z;}
  43. #else
  44. static inline _Complex float Cf(complex *z) {return z->r + z->i*_Complex_I;}
  45. static inline _Complex double Cd(doublecomplex *z) {return z->r + z->i*_Complex_I;}
  46. static inline _Complex float * _pCf(complex *z) {return (_Complex float*)z;}
  47. static inline _Complex double * _pCd(doublecomplex *z) {return (_Complex double*)z;}
  48. #endif
  49. #define pCf(z) (*_pCf(z))
  50. #define pCd(z) (*_pCd(z))
  51. typedef blasint logical;
  52. typedef char logical1;
  53. typedef char integer1;
  54. #define TRUE_ (1)
  55. #define FALSE_ (0)
  56. /* Extern is for use with -E */
  57. #ifndef Extern
  58. #define Extern extern
  59. #endif
  60. /* I/O stuff */
  61. typedef int flag;
  62. typedef int ftnlen;
  63. typedef int ftnint;
  64. /*external read, write*/
  65. typedef struct
  66. { flag cierr;
  67. ftnint ciunit;
  68. flag ciend;
  69. char *cifmt;
  70. ftnint cirec;
  71. } cilist;
  72. /*internal read, write*/
  73. typedef struct
  74. { flag icierr;
  75. char *iciunit;
  76. flag iciend;
  77. char *icifmt;
  78. ftnint icirlen;
  79. ftnint icirnum;
  80. } icilist;
  81. /*open*/
  82. typedef struct
  83. { flag oerr;
  84. ftnint ounit;
  85. char *ofnm;
  86. ftnlen ofnmlen;
  87. char *osta;
  88. char *oacc;
  89. char *ofm;
  90. ftnint orl;
  91. char *oblnk;
  92. } olist;
  93. /*close*/
  94. typedef struct
  95. { flag cerr;
  96. ftnint cunit;
  97. char *csta;
  98. } cllist;
  99. /*rewind, backspace, endfile*/
  100. typedef struct
  101. { flag aerr;
  102. ftnint aunit;
  103. } alist;
  104. /* inquire */
  105. typedef struct
  106. { flag inerr;
  107. ftnint inunit;
  108. char *infile;
  109. ftnlen infilen;
  110. ftnint *inex; /*parameters in standard's order*/
  111. ftnint *inopen;
  112. ftnint *innum;
  113. ftnint *innamed;
  114. char *inname;
  115. ftnlen innamlen;
  116. char *inacc;
  117. ftnlen inacclen;
  118. char *inseq;
  119. ftnlen inseqlen;
  120. char *indir;
  121. ftnlen indirlen;
  122. char *infmt;
  123. ftnlen infmtlen;
  124. char *inform;
  125. ftnint informlen;
  126. char *inunf;
  127. ftnlen inunflen;
  128. ftnint *inrecl;
  129. ftnint *innrec;
  130. char *inblank;
  131. ftnlen inblanklen;
  132. } inlist;
  133. #define VOID void
  134. union Multitype { /* for multiple entry points */
  135. integer1 g;
  136. shortint h;
  137. integer i;
  138. /* longint j; */
  139. real r;
  140. doublereal d;
  141. complex c;
  142. doublecomplex z;
  143. };
  144. typedef union Multitype Multitype;
  145. struct Vardesc { /* for Namelist */
  146. char *name;
  147. char *addr;
  148. ftnlen *dims;
  149. int type;
  150. };
  151. typedef struct Vardesc Vardesc;
  152. struct Namelist {
  153. char *name;
  154. Vardesc **vars;
  155. int nvars;
  156. };
  157. typedef struct Namelist Namelist;
  158. #define abs(x) ((x) >= 0 ? (x) : -(x))
  159. #define dabs(x) (fabs(x))
  160. #define f2cmin(a,b) ((a) <= (b) ? (a) : (b))
  161. #define f2cmax(a,b) ((a) >= (b) ? (a) : (b))
  162. #define dmin(a,b) (f2cmin(a,b))
  163. #define dmax(a,b) (f2cmax(a,b))
  164. #define bit_test(a,b) ((a) >> (b) & 1)
  165. #define bit_clear(a,b) ((a) & ~((uinteger)1 << (b)))
  166. #define bit_set(a,b) ((a) | ((uinteger)1 << (b)))
  167. #define abort_() { sig_die("Fortran abort routine called", 1); }
  168. #define c_abs(z) (cabsf(Cf(z)))
  169. #define c_cos(R,Z) { pCf(R)=ccos(Cf(Z)); }
  170. #ifdef _MSC_VER
  171. #define c_div(c, a, b) {Cf(c)._Val[0] = (Cf(a)._Val[0]/Cf(b)._Val[0]); Cf(c)._Val[1]=(Cf(a)._Val[1]/Cf(b)._Val[1]);}
  172. #define z_div(c, a, b) {Cd(c)._Val[0] = (Cd(a)._Val[0]/Cd(b)._Val[0]); Cd(c)._Val[1]=(Cd(a)._Val[1]/df(b)._Val[1]);}
  173. #else
  174. #define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);}
  175. #define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);}
  176. #endif
  177. #define c_exp(R, Z) {pCf(R) = cexpf(Cf(Z));}
  178. #define c_log(R, Z) {pCf(R) = clogf(Cf(Z));}
  179. #define c_sin(R, Z) {pCf(R) = csinf(Cf(Z));}
  180. //#define c_sqrt(R, Z) {*(R) = csqrtf(Cf(Z));}
  181. #define c_sqrt(R, Z) {pCf(R) = csqrtf(Cf(Z));}
  182. #define d_abs(x) (fabs(*(x)))
  183. #define d_acos(x) (acos(*(x)))
  184. #define d_asin(x) (asin(*(x)))
  185. #define d_atan(x) (atan(*(x)))
  186. #define d_atn2(x, y) (atan2(*(x),*(y)))
  187. #define d_cnjg(R, Z) { pCd(R) = conj(Cd(Z)); }
  188. #define r_cnjg(R, Z) { pCf(R) = conjf(Cf(Z)); }
  189. #define d_cos(x) (cos(*(x)))
  190. #define d_cosh(x) (cosh(*(x)))
  191. #define d_dim(__a, __b) ( *(__a) > *(__b) ? *(__a) - *(__b) : 0.0 )
  192. #define d_exp(x) (exp(*(x)))
  193. #define d_imag(z) (cimag(Cd(z)))
  194. #define r_imag(z) (cimagf(Cf(z)))
  195. #define d_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  196. #define r_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  197. #define d_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  198. #define r_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  199. #define d_log(x) (log(*(x)))
  200. #define d_mod(x, y) (fmod(*(x), *(y)))
  201. #define u_nint(__x) ((__x)>=0 ? floor((__x) + .5) : -floor(.5 - (__x)))
  202. #define d_nint(x) u_nint(*(x))
  203. #define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a)))
  204. #define d_sign(a,b) u_sign(*(a),*(b))
  205. #define r_sign(a,b) u_sign(*(a),*(b))
  206. #define d_sin(x) (sin(*(x)))
  207. #define d_sinh(x) (sinh(*(x)))
  208. #define d_sqrt(x) (sqrt(*(x)))
  209. #define d_tan(x) (tan(*(x)))
  210. #define d_tanh(x) (tanh(*(x)))
  211. #define i_abs(x) abs(*(x))
  212. #define i_dnnt(x) ((integer)u_nint(*(x)))
  213. #define i_len(s, n) (n)
  214. #define i_nint(x) ((integer)u_nint(*(x)))
  215. #define i_sign(a,b) ((integer)u_sign((integer)*(a),(integer)*(b)))
  216. #define pow_dd(ap, bp) ( pow(*(ap), *(bp)))
  217. #define pow_si(B,E) spow_ui(*(B),*(E))
  218. #define pow_ri(B,E) spow_ui(*(B),*(E))
  219. #define pow_di(B,E) dpow_ui(*(B),*(E))
  220. #define pow_zi(p, a, b) {pCd(p) = zpow_ui(Cd(a), *(b));}
  221. #define pow_ci(p, a, b) {pCf(p) = cpow_ui(Cf(a), *(b));}
  222. #define pow_zz(R,A,B) {pCd(R) = cpow(Cd(A),*(B));}
  223. #define s_cat(lpp, rpp, rnp, np, llp) { ftnlen i, nc, ll; char *f__rp, *lp; ll = (llp); lp = (lpp); for(i=0; i < (int)*(np); ++i) { nc = ll; if((rnp)[i] < nc) nc = (rnp)[i]; ll -= nc; f__rp = (rpp)[i]; while(--nc >= 0) *lp++ = *(f__rp)++; } while(--ll >= 0) *lp++ = ' '; }
  224. #define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d))))
  225. #define s_copy(A,B,C,D) { int __i,__m; for (__i=0, __m=f2cmin((C),(D)); __i<__m && (B)[__i] != 0; ++__i) (A)[__i] = (B)[__i]; }
  226. #define sig_die(s, kill) { exit(1); }
  227. #define s_stop(s, n) {exit(0);}
  228. static char junk[] = "\n@(#)LIBF77 VERSION 19990503\n";
  229. #define z_abs(z) (cabs(Cd(z)))
  230. #define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));}
  231. #define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));}
  232. #define myexit_() break;
  233. #define mycycle() continue;
  234. #define myceiling(w) {ceil(w)}
  235. #define myhuge(w) {HUGE_VAL}
  236. //#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);}
  237. #define mymaxloc(w,s,e,n) {dmaxloc_(w,*(s),*(e),n)}
  238. /* procedure parameter types for -A and -C++ */
  239. #ifdef __cplusplus
  240. typedef logical (*L_fp)(...);
  241. #else
  242. typedef logical (*L_fp)();
  243. #endif
  244. static float spow_ui(float x, integer n) {
  245. float pow=1.0; unsigned long int u;
  246. if(n != 0) {
  247. if(n < 0) n = -n, x = 1/x;
  248. for(u = n; ; ) {
  249. if(u & 01) pow *= x;
  250. if(u >>= 1) x *= x;
  251. else break;
  252. }
  253. }
  254. return pow;
  255. }
  256. static double dpow_ui(double x, integer n) {
  257. double pow=1.0; unsigned long int u;
  258. if(n != 0) {
  259. if(n < 0) n = -n, x = 1/x;
  260. for(u = n; ; ) {
  261. if(u & 01) pow *= x;
  262. if(u >>= 1) x *= x;
  263. else break;
  264. }
  265. }
  266. return pow;
  267. }
  268. #ifdef _MSC_VER
  269. static _Fcomplex cpow_ui(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 doublereal c_b12 = 0.;
  485. static doublereal c_b13 = 1.;
  486. static integer c__1 = 1;
  487. static integer c__3 = 3;
  488. /* > \brief \b DHGEQZ */
  489. /* =========== DOCUMENTATION =========== */
  490. /* Online html documentation available at */
  491. /* http://www.netlib.org/lapack/explore-html/ */
  492. /* > \htmlonly */
  493. /* > Download DHGEQZ + dependencies */
  494. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dhgeqz.
  495. f"> */
  496. /* > [TGZ]</a> */
  497. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dhgeqz.
  498. f"> */
  499. /* > [ZIP]</a> */
  500. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dhgeqz.
  501. f"> */
  502. /* > [TXT]</a> */
  503. /* > \endhtmlonly */
  504. /* Definition: */
  505. /* =========== */
  506. /* SUBROUTINE DHGEQZ( JOB, COMPQ, COMPZ, N, ILO, IHI, H, LDH, T, LDT, */
  507. /* ALPHAR, ALPHAI, BETA, Q, LDQ, Z, LDZ, WORK, */
  508. /* LWORK, INFO ) */
  509. /* CHARACTER COMPQ, COMPZ, JOB */
  510. /* INTEGER IHI, ILO, INFO, LDH, LDQ, LDT, LDZ, LWORK, N */
  511. /* DOUBLE PRECISION ALPHAI( * ), ALPHAR( * ), BETA( * ), */
  512. /* $ H( LDH, * ), Q( LDQ, * ), T( LDT, * ), */
  513. /* $ WORK( * ), Z( LDZ, * ) */
  514. /* > \par Purpose: */
  515. /* ============= */
  516. /* > */
  517. /* > \verbatim */
  518. /* > */
  519. /* > DHGEQZ computes the eigenvalues of a real matrix pair (H,T), */
  520. /* > where H is an upper Hessenberg matrix and T is upper triangular, */
  521. /* > using the double-shift QZ method. */
  522. /* > Matrix pairs of this type are produced by the reduction to */
  523. /* > generalized upper Hessenberg form of a real matrix pair (A,B): */
  524. /* > */
  525. /* > A = Q1*H*Z1**T, B = Q1*T*Z1**T, */
  526. /* > */
  527. /* > as computed by DGGHRD. */
  528. /* > */
  529. /* > If JOB='S', then the Hessenberg-triangular pair (H,T) is */
  530. /* > also reduced to generalized Schur form, */
  531. /* > */
  532. /* > H = Q*S*Z**T, T = Q*P*Z**T, */
  533. /* > */
  534. /* > where Q and Z are orthogonal matrices, P is an upper triangular */
  535. /* > matrix, and S is a quasi-triangular matrix with 1-by-1 and 2-by-2 */
  536. /* > diagonal blocks. */
  537. /* > */
  538. /* > The 1-by-1 blocks correspond to real eigenvalues of the matrix pair */
  539. /* > (H,T) and the 2-by-2 blocks correspond to complex conjugate pairs of */
  540. /* > eigenvalues. */
  541. /* > */
  542. /* > Additionally, the 2-by-2 upper triangular diagonal blocks of P */
  543. /* > corresponding to 2-by-2 blocks of S are reduced to positive diagonal */
  544. /* > form, i.e., if S(j+1,j) is non-zero, then P(j+1,j) = P(j,j+1) = 0, */
  545. /* > P(j,j) > 0, and P(j+1,j+1) > 0. */
  546. /* > */
  547. /* > Optionally, the orthogonal matrix Q from the generalized Schur */
  548. /* > factorization may be postmultiplied into an input matrix Q1, and the */
  549. /* > orthogonal matrix Z may be postmultiplied into an input matrix Z1. */
  550. /* > If Q1 and Z1 are the orthogonal matrices from DGGHRD that reduced */
  551. /* > the matrix pair (A,B) to generalized upper Hessenberg form, then the */
  552. /* > output matrices Q1*Q and Z1*Z are the orthogonal factors from the */
  553. /* > generalized Schur factorization of (A,B): */
  554. /* > */
  555. /* > A = (Q1*Q)*S*(Z1*Z)**T, B = (Q1*Q)*P*(Z1*Z)**T. */
  556. /* > */
  557. /* > To avoid overflow, eigenvalues of the matrix pair (H,T) (equivalently, */
  558. /* > of (A,B)) are computed as a pair of values (alpha,beta), where alpha is */
  559. /* > complex and beta real. */
  560. /* > If beta is nonzero, lambda = alpha / beta is an eigenvalue of the */
  561. /* > generalized nonsymmetric eigenvalue problem (GNEP) */
  562. /* > A*x = lambda*B*x */
  563. /* > and if alpha is nonzero, mu = beta / alpha is an eigenvalue of the */
  564. /* > alternate form of the GNEP */
  565. /* > mu*A*y = B*y. */
  566. /* > Real eigenvalues can be read directly from the generalized Schur */
  567. /* > form: */
  568. /* > alpha = S(i,i), beta = P(i,i). */
  569. /* > */
  570. /* > Ref: C.B. Moler & G.W. Stewart, "An Algorithm for Generalized Matrix */
  571. /* > Eigenvalue Problems", SIAM J. Numer. Anal., 10(1973), */
  572. /* > pp. 241--256. */
  573. /* > \endverbatim */
  574. /* Arguments: */
  575. /* ========== */
  576. /* > \param[in] JOB */
  577. /* > \verbatim */
  578. /* > JOB is CHARACTER*1 */
  579. /* > = 'E': Compute eigenvalues only; */
  580. /* > = 'S': Compute eigenvalues and the Schur form. */
  581. /* > \endverbatim */
  582. /* > */
  583. /* > \param[in] COMPQ */
  584. /* > \verbatim */
  585. /* > COMPQ is CHARACTER*1 */
  586. /* > = 'N': Left Schur vectors (Q) are not computed; */
  587. /* > = 'I': Q is initialized to the unit matrix and the matrix Q */
  588. /* > of left Schur vectors of (H,T) is returned; */
  589. /* > = 'V': Q must contain an orthogonal matrix Q1 on entry and */
  590. /* > the product Q1*Q is returned. */
  591. /* > \endverbatim */
  592. /* > */
  593. /* > \param[in] COMPZ */
  594. /* > \verbatim */
  595. /* > COMPZ is CHARACTER*1 */
  596. /* > = 'N': Right Schur vectors (Z) are not computed; */
  597. /* > = 'I': Z is initialized to the unit matrix and the matrix Z */
  598. /* > of right Schur vectors of (H,T) is returned; */
  599. /* > = 'V': Z must contain an orthogonal matrix Z1 on entry and */
  600. /* > the product Z1*Z is returned. */
  601. /* > \endverbatim */
  602. /* > */
  603. /* > \param[in] N */
  604. /* > \verbatim */
  605. /* > N is INTEGER */
  606. /* > The order of the matrices H, T, Q, and Z. N >= 0. */
  607. /* > \endverbatim */
  608. /* > */
  609. /* > \param[in] ILO */
  610. /* > \verbatim */
  611. /* > ILO is INTEGER */
  612. /* > \endverbatim */
  613. /* > */
  614. /* > \param[in] IHI */
  615. /* > \verbatim */
  616. /* > IHI is INTEGER */
  617. /* > ILO and IHI mark the rows and columns of H which are in */
  618. /* > Hessenberg form. It is assumed that A is already upper */
  619. /* > triangular in rows and columns 1:ILO-1 and IHI+1:N. */
  620. /* > If N > 0, 1 <= ILO <= IHI <= N; if N = 0, ILO=1 and IHI=0. */
  621. /* > \endverbatim */
  622. /* > */
  623. /* > \param[in,out] H */
  624. /* > \verbatim */
  625. /* > H is DOUBLE PRECISION array, dimension (LDH, N) */
  626. /* > On entry, the N-by-N upper Hessenberg matrix H. */
  627. /* > On exit, if JOB = 'S', H contains the upper quasi-triangular */
  628. /* > matrix S from the generalized Schur factorization. */
  629. /* > If JOB = 'E', the diagonal blocks of H match those of S, but */
  630. /* > the rest of H is unspecified. */
  631. /* > \endverbatim */
  632. /* > */
  633. /* > \param[in] LDH */
  634. /* > \verbatim */
  635. /* > LDH is INTEGER */
  636. /* > The leading dimension of the array H. LDH >= f2cmax( 1, N ). */
  637. /* > \endverbatim */
  638. /* > */
  639. /* > \param[in,out] T */
  640. /* > \verbatim */
  641. /* > T is DOUBLE PRECISION array, dimension (LDT, N) */
  642. /* > On entry, the N-by-N upper triangular matrix T. */
  643. /* > On exit, if JOB = 'S', T contains the upper triangular */
  644. /* > matrix P from the generalized Schur factorization; */
  645. /* > 2-by-2 diagonal blocks of P corresponding to 2-by-2 blocks of S */
  646. /* > are reduced to positive diagonal form, i.e., if H(j+1,j) is */
  647. /* > non-zero, then T(j+1,j) = T(j,j+1) = 0, T(j,j) > 0, and */
  648. /* > T(j+1,j+1) > 0. */
  649. /* > If JOB = 'E', the diagonal blocks of T match those of P, but */
  650. /* > the rest of T is unspecified. */
  651. /* > \endverbatim */
  652. /* > */
  653. /* > \param[in] LDT */
  654. /* > \verbatim */
  655. /* > LDT is INTEGER */
  656. /* > The leading dimension of the array T. LDT >= f2cmax( 1, N ). */
  657. /* > \endverbatim */
  658. /* > */
  659. /* > \param[out] ALPHAR */
  660. /* > \verbatim */
  661. /* > ALPHAR is DOUBLE PRECISION array, dimension (N) */
  662. /* > The real parts of each scalar alpha defining an eigenvalue */
  663. /* > of GNEP. */
  664. /* > \endverbatim */
  665. /* > */
  666. /* > \param[out] ALPHAI */
  667. /* > \verbatim */
  668. /* > ALPHAI is DOUBLE PRECISION array, dimension (N) */
  669. /* > The imaginary parts of each scalar alpha defining an */
  670. /* > eigenvalue of GNEP. */
  671. /* > If ALPHAI(j) is zero, then the j-th eigenvalue is real; if */
  672. /* > positive, then the j-th and (j+1)-st eigenvalues are a */
  673. /* > complex conjugate pair, with ALPHAI(j+1) = -ALPHAI(j). */
  674. /* > \endverbatim */
  675. /* > */
  676. /* > \param[out] BETA */
  677. /* > \verbatim */
  678. /* > BETA is DOUBLE PRECISION array, dimension (N) */
  679. /* > The scalars beta that define the eigenvalues of GNEP. */
  680. /* > Together, the quantities alpha = (ALPHAR(j),ALPHAI(j)) and */
  681. /* > beta = BETA(j) represent the j-th eigenvalue of the matrix */
  682. /* > pair (A,B), in one of the forms lambda = alpha/beta or */
  683. /* > mu = beta/alpha. Since either lambda or mu may overflow, */
  684. /* > they should not, in general, be computed. */
  685. /* > \endverbatim */
  686. /* > */
  687. /* > \param[in,out] Q */
  688. /* > \verbatim */
  689. /* > Q is DOUBLE PRECISION array, dimension (LDQ, N) */
  690. /* > On entry, if COMPQ = 'V', the orthogonal matrix Q1 used in */
  691. /* > the reduction of (A,B) to generalized Hessenberg form. */
  692. /* > On exit, if COMPQ = 'I', the orthogonal matrix of left Schur */
  693. /* > vectors of (H,T), and if COMPQ = 'V', the orthogonal matrix */
  694. /* > of left Schur vectors of (A,B). */
  695. /* > Not referenced if COMPQ = 'N'. */
  696. /* > \endverbatim */
  697. /* > */
  698. /* > \param[in] LDQ */
  699. /* > \verbatim */
  700. /* > LDQ is INTEGER */
  701. /* > The leading dimension of the array Q. LDQ >= 1. */
  702. /* > If COMPQ='V' or 'I', then LDQ >= N. */
  703. /* > \endverbatim */
  704. /* > */
  705. /* > \param[in,out] Z */
  706. /* > \verbatim */
  707. /* > Z is DOUBLE PRECISION array, dimension (LDZ, N) */
  708. /* > On entry, if COMPZ = 'V', the orthogonal matrix Z1 used in */
  709. /* > the reduction of (A,B) to generalized Hessenberg form. */
  710. /* > On exit, if COMPZ = 'I', the orthogonal matrix of */
  711. /* > right Schur vectors of (H,T), and if COMPZ = 'V', the */
  712. /* > orthogonal matrix of right Schur vectors of (A,B). */
  713. /* > Not referenced if COMPZ = 'N'. */
  714. /* > \endverbatim */
  715. /* > */
  716. /* > \param[in] LDZ */
  717. /* > \verbatim */
  718. /* > LDZ is INTEGER */
  719. /* > The leading dimension of the array Z. LDZ >= 1. */
  720. /* > If COMPZ='V' or 'I', then LDZ >= N. */
  721. /* > \endverbatim */
  722. /* > */
  723. /* > \param[out] WORK */
  724. /* > \verbatim */
  725. /* > WORK is DOUBLE PRECISION array, dimension (MAX(1,LWORK)) */
  726. /* > On exit, if INFO >= 0, WORK(1) returns the optimal LWORK. */
  727. /* > \endverbatim */
  728. /* > */
  729. /* > \param[in] LWORK */
  730. /* > \verbatim */
  731. /* > LWORK is INTEGER */
  732. /* > The dimension of the array WORK. LWORK >= f2cmax(1,N). */
  733. /* > */
  734. /* > If LWORK = -1, then a workspace query is assumed; the routine */
  735. /* > only calculates the optimal size of the WORK array, returns */
  736. /* > this value as the first entry of the WORK array, and no error */
  737. /* > message related to LWORK is issued by XERBLA. */
  738. /* > \endverbatim */
  739. /* > */
  740. /* > \param[out] INFO */
  741. /* > \verbatim */
  742. /* > INFO is INTEGER */
  743. /* > = 0: successful exit */
  744. /* > < 0: if INFO = -i, the i-th argument had an illegal value */
  745. /* > = 1,...,N: the QZ iteration did not converge. (H,T) is not */
  746. /* > in Schur form, but ALPHAR(i), ALPHAI(i), and */
  747. /* > BETA(i), i=INFO+1,...,N should be correct. */
  748. /* > = N+1,...,2*N: the shift calculation failed. (H,T) is not */
  749. /* > in Schur form, but ALPHAR(i), ALPHAI(i), and */
  750. /* > BETA(i), i=INFO-N+1,...,N should be correct. */
  751. /* > \endverbatim */
  752. /* Authors: */
  753. /* ======== */
  754. /* > \author Univ. of Tennessee */
  755. /* > \author Univ. of California Berkeley */
  756. /* > \author Univ. of Colorado Denver */
  757. /* > \author NAG Ltd. */
  758. /* > \date June 2016 */
  759. /* > \ingroup doubleGEcomputational */
  760. /* > \par Further Details: */
  761. /* ===================== */
  762. /* > */
  763. /* > \verbatim */
  764. /* > */
  765. /* > Iteration counters: */
  766. /* > */
  767. /* > JITER -- counts iterations. */
  768. /* > IITER -- counts iterations run since ILAST was last */
  769. /* > changed. This is therefore reset only when a 1-by-1 or */
  770. /* > 2-by-2 block deflates off the bottom. */
  771. /* > \endverbatim */
  772. /* > */
  773. /* ===================================================================== */
  774. /* Subroutine */ void dhgeqz_(char *job, char *compq, char *compz, integer *n,
  775. integer *ilo, integer *ihi, doublereal *h__, integer *ldh, doublereal
  776. *t, integer *ldt, doublereal *alphar, doublereal *alphai, doublereal *
  777. beta, doublereal *q, integer *ldq, doublereal *z__, integer *ldz,
  778. doublereal *work, integer *lwork, integer *info)
  779. {
  780. /* System generated locals */
  781. integer h_dim1, h_offset, q_dim1, q_offset, t_dim1, t_offset, z_dim1,
  782. z_offset, i__1, i__2, i__3, i__4;
  783. doublereal d__1, d__2, d__3, d__4;
  784. /* Local variables */
  785. doublereal ad11l, ad12l, ad21l, ad22l, ad32l, wabs, atol, btol, temp;
  786. extern /* Subroutine */ void drot_(integer *, doublereal *, integer *,
  787. doublereal *, integer *, doublereal *, doublereal *), dlag2_(
  788. doublereal *, integer *, doublereal *, integer *, doublereal *,
  789. doublereal *, doublereal *, doublereal *, doublereal *,
  790. doublereal *);
  791. doublereal temp2, s1inv, c__;
  792. integer j;
  793. doublereal s, v[3], scale;
  794. extern logical lsame_(char *, char *);
  795. integer iiter, ilast, jiter;
  796. doublereal anorm, bnorm;
  797. integer maxit;
  798. doublereal tempi, tempr, s1, s2, t1, u1, u2;
  799. extern doublereal dlapy2_(doublereal *, doublereal *), dlapy3_(doublereal
  800. *, doublereal *, doublereal *);
  801. extern /* Subroutine */ void dlasv2_(doublereal *, doublereal *,
  802. doublereal *, doublereal *, doublereal *, doublereal *,
  803. doublereal *, doublereal *, doublereal *);
  804. logical ilazr2;
  805. doublereal a11, a12, a21, a22, b11, b22, c12, c21;
  806. integer jc;
  807. doublereal an, bn, cl, cq, cr;
  808. integer in;
  809. doublereal ascale, bscale, u12, w11;
  810. integer jr;
  811. doublereal cz, sl, w12, w21, w22, wi;
  812. extern doublereal dlamch_(char *);
  813. doublereal sr;
  814. extern /* Subroutine */ void dlarfg_(integer *, doublereal *, doublereal *,
  815. integer *, doublereal *);
  816. doublereal vs, wr;
  817. extern doublereal dlanhs_(char *, integer *, doublereal *, integer *,
  818. doublereal *);
  819. extern /* Subroutine */ void dlaset_(char *, integer *, integer *,
  820. doublereal *, doublereal *, doublereal *, integer *);
  821. doublereal safmin;
  822. extern /* Subroutine */ void dlartg_(doublereal *, doublereal *,
  823. doublereal *, doublereal *, doublereal *);
  824. doublereal safmax;
  825. extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen);
  826. doublereal eshift;
  827. logical ilschr;
  828. doublereal b1a, b2a;
  829. integer icompq, ilastm;
  830. doublereal a1i;
  831. integer ischur;
  832. doublereal a2i, b1i;
  833. logical ilazro;
  834. integer icompz, ifirst;
  835. doublereal b2i;
  836. integer ifrstm;
  837. doublereal a1r;
  838. integer istart;
  839. logical ilpivt;
  840. doublereal a2r, b1r, b2r;
  841. logical lquery;
  842. doublereal wr2, ad11, ad12, ad21, ad22, c11i, c22i;
  843. integer jch;
  844. doublereal c11r, c22r;
  845. logical ilq;
  846. doublereal u12l, tau, sqi;
  847. logical ilz;
  848. doublereal ulp, sqr, szi, szr;
  849. /* -- LAPACK computational routine (version 3.7.0) -- */
  850. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  851. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  852. /* June 2016 */
  853. /* ===================================================================== */
  854. /* $ SAFETY = 1.0E+0 ) */
  855. /* Decode JOB, COMPQ, COMPZ */
  856. /* Parameter adjustments */
  857. h_dim1 = *ldh;
  858. h_offset = 1 + h_dim1 * 1;
  859. h__ -= h_offset;
  860. t_dim1 = *ldt;
  861. t_offset = 1 + t_dim1 * 1;
  862. t -= t_offset;
  863. --alphar;
  864. --alphai;
  865. --beta;
  866. q_dim1 = *ldq;
  867. q_offset = 1 + q_dim1 * 1;
  868. q -= q_offset;
  869. z_dim1 = *ldz;
  870. z_offset = 1 + z_dim1 * 1;
  871. z__ -= z_offset;
  872. --work;
  873. /* Function Body */
  874. if (lsame_(job, "E")) {
  875. ilschr = FALSE_;
  876. ischur = 1;
  877. } else if (lsame_(job, "S")) {
  878. ilschr = TRUE_;
  879. ischur = 2;
  880. } else {
  881. ischur = 0;
  882. }
  883. if (lsame_(compq, "N")) {
  884. ilq = FALSE_;
  885. icompq = 1;
  886. } else if (lsame_(compq, "V")) {
  887. ilq = TRUE_;
  888. icompq = 2;
  889. } else if (lsame_(compq, "I")) {
  890. ilq = TRUE_;
  891. icompq = 3;
  892. } else {
  893. icompq = 0;
  894. }
  895. if (lsame_(compz, "N")) {
  896. ilz = FALSE_;
  897. icompz = 1;
  898. } else if (lsame_(compz, "V")) {
  899. ilz = TRUE_;
  900. icompz = 2;
  901. } else if (lsame_(compz, "I")) {
  902. ilz = TRUE_;
  903. icompz = 3;
  904. } else {
  905. icompz = 0;
  906. }
  907. /* Check Argument Values */
  908. *info = 0;
  909. work[1] = (doublereal) f2cmax(1,*n);
  910. lquery = *lwork == -1;
  911. if (ischur == 0) {
  912. *info = -1;
  913. } else if (icompq == 0) {
  914. *info = -2;
  915. } else if (icompz == 0) {
  916. *info = -3;
  917. } else if (*n < 0) {
  918. *info = -4;
  919. } else if (*ilo < 1) {
  920. *info = -5;
  921. } else if (*ihi > *n || *ihi < *ilo - 1) {
  922. *info = -6;
  923. } else if (*ldh < *n) {
  924. *info = -8;
  925. } else if (*ldt < *n) {
  926. *info = -10;
  927. } else if (*ldq < 1 || ilq && *ldq < *n) {
  928. *info = -15;
  929. } else if (*ldz < 1 || ilz && *ldz < *n) {
  930. *info = -17;
  931. } else if (*lwork < f2cmax(1,*n) && ! lquery) {
  932. *info = -19;
  933. }
  934. if (*info != 0) {
  935. i__1 = -(*info);
  936. xerbla_("DHGEQZ", &i__1, (ftnlen)6);
  937. return;
  938. } else if (lquery) {
  939. return;
  940. }
  941. /* Quick return if possible */
  942. if (*n <= 0) {
  943. work[1] = 1.;
  944. return;
  945. }
  946. /* Initialize Q and Z */
  947. if (icompq == 3) {
  948. dlaset_("Full", n, n, &c_b12, &c_b13, &q[q_offset], ldq);
  949. }
  950. if (icompz == 3) {
  951. dlaset_("Full", n, n, &c_b12, &c_b13, &z__[z_offset], ldz);
  952. }
  953. /* Machine Constants */
  954. in = *ihi + 1 - *ilo;
  955. safmin = dlamch_("S");
  956. safmax = 1. / safmin;
  957. ulp = dlamch_("E") * dlamch_("B");
  958. anorm = dlanhs_("F", &in, &h__[*ilo + *ilo * h_dim1], ldh, &work[1]);
  959. bnorm = dlanhs_("F", &in, &t[*ilo + *ilo * t_dim1], ldt, &work[1]);
  960. /* Computing MAX */
  961. d__1 = safmin, d__2 = ulp * anorm;
  962. atol = f2cmax(d__1,d__2);
  963. /* Computing MAX */
  964. d__1 = safmin, d__2 = ulp * bnorm;
  965. btol = f2cmax(d__1,d__2);
  966. ascale = 1. / f2cmax(safmin,anorm);
  967. bscale = 1. / f2cmax(safmin,bnorm);
  968. /* Set Eigenvalues IHI+1:N */
  969. i__1 = *n;
  970. for (j = *ihi + 1; j <= i__1; ++j) {
  971. if (t[j + j * t_dim1] < 0.) {
  972. if (ilschr) {
  973. i__2 = j;
  974. for (jr = 1; jr <= i__2; ++jr) {
  975. h__[jr + j * h_dim1] = -h__[jr + j * h_dim1];
  976. t[jr + j * t_dim1] = -t[jr + j * t_dim1];
  977. /* L10: */
  978. }
  979. } else {
  980. h__[j + j * h_dim1] = -h__[j + j * h_dim1];
  981. t[j + j * t_dim1] = -t[j + j * t_dim1];
  982. }
  983. if (ilz) {
  984. i__2 = *n;
  985. for (jr = 1; jr <= i__2; ++jr) {
  986. z__[jr + j * z_dim1] = -z__[jr + j * z_dim1];
  987. /* L20: */
  988. }
  989. }
  990. }
  991. alphar[j] = h__[j + j * h_dim1];
  992. alphai[j] = 0.;
  993. beta[j] = t[j + j * t_dim1];
  994. /* L30: */
  995. }
  996. /* If IHI < ILO, skip QZ steps */
  997. if (*ihi < *ilo) {
  998. goto L380;
  999. }
  1000. /* MAIN QZ ITERATION LOOP */
  1001. /* Initialize dynamic indices */
  1002. /* Eigenvalues ILAST+1:N have been found. */
  1003. /* Column operations modify rows IFRSTM:whatever. */
  1004. /* Row operations modify columns whatever:ILASTM. */
  1005. /* If only eigenvalues are being computed, then */
  1006. /* IFRSTM is the row of the last splitting row above row ILAST; */
  1007. /* this is always at least ILO. */
  1008. /* IITER counts iterations since the last eigenvalue was found, */
  1009. /* to tell when to use an extraordinary shift. */
  1010. /* MAXIT is the maximum number of QZ sweeps allowed. */
  1011. ilast = *ihi;
  1012. if (ilschr) {
  1013. ifrstm = 1;
  1014. ilastm = *n;
  1015. } else {
  1016. ifrstm = *ilo;
  1017. ilastm = *ihi;
  1018. }
  1019. iiter = 0;
  1020. eshift = 0.;
  1021. maxit = (*ihi - *ilo + 1) * 30;
  1022. i__1 = maxit;
  1023. for (jiter = 1; jiter <= i__1; ++jiter) {
  1024. /* Split the matrix if possible. */
  1025. /* Two tests: */
  1026. /* 1: H(j,j-1)=0 or j=ILO */
  1027. /* 2: T(j,j)=0 */
  1028. if (ilast == *ilo) {
  1029. /* Special case: j=ILAST */
  1030. goto L80;
  1031. } else {
  1032. if ((d__1 = h__[ilast + (ilast - 1) * h_dim1], abs(d__1)) <= atol)
  1033. {
  1034. h__[ilast + (ilast - 1) * h_dim1] = 0.;
  1035. goto L80;
  1036. }
  1037. }
  1038. if ((d__1 = t[ilast + ilast * t_dim1], abs(d__1)) <= btol) {
  1039. t[ilast + ilast * t_dim1] = 0.;
  1040. goto L70;
  1041. }
  1042. /* General case: j<ILAST */
  1043. i__2 = *ilo;
  1044. for (j = ilast - 1; j >= i__2; --j) {
  1045. /* Test 1: for H(j,j-1)=0 or j=ILO */
  1046. if (j == *ilo) {
  1047. ilazro = TRUE_;
  1048. } else {
  1049. if ((d__1 = h__[j + (j - 1) * h_dim1], abs(d__1)) <= atol) {
  1050. h__[j + (j - 1) * h_dim1] = 0.;
  1051. ilazro = TRUE_;
  1052. } else {
  1053. ilazro = FALSE_;
  1054. }
  1055. }
  1056. /* Test 2: for T(j,j)=0 */
  1057. if ((d__1 = t[j + j * t_dim1], abs(d__1)) < btol) {
  1058. t[j + j * t_dim1] = 0.;
  1059. /* Test 1a: Check for 2 consecutive small subdiagonals in A */
  1060. ilazr2 = FALSE_;
  1061. if (! ilazro) {
  1062. temp = (d__1 = h__[j + (j - 1) * h_dim1], abs(d__1));
  1063. temp2 = (d__1 = h__[j + j * h_dim1], abs(d__1));
  1064. tempr = f2cmax(temp,temp2);
  1065. if (tempr < 1. && tempr != 0.) {
  1066. temp /= tempr;
  1067. temp2 /= tempr;
  1068. }
  1069. if (temp * (ascale * (d__1 = h__[j + 1 + j * h_dim1], abs(
  1070. d__1))) <= temp2 * (ascale * atol)) {
  1071. ilazr2 = TRUE_;
  1072. }
  1073. }
  1074. /* If both tests pass (1 & 2), i.e., the leading diagonal */
  1075. /* element of B in the block is zero, split a 1x1 block off */
  1076. /* at the top. (I.e., at the J-th row/column) The leading */
  1077. /* diagonal element of the remainder can also be zero, so */
  1078. /* this may have to be done repeatedly. */
  1079. if (ilazro || ilazr2) {
  1080. i__3 = ilast - 1;
  1081. for (jch = j; jch <= i__3; ++jch) {
  1082. temp = h__[jch + jch * h_dim1];
  1083. dlartg_(&temp, &h__[jch + 1 + jch * h_dim1], &c__, &s,
  1084. &h__[jch + jch * h_dim1]);
  1085. h__[jch + 1 + jch * h_dim1] = 0.;
  1086. i__4 = ilastm - jch;
  1087. drot_(&i__4, &h__[jch + (jch + 1) * h_dim1], ldh, &
  1088. h__[jch + 1 + (jch + 1) * h_dim1], ldh, &c__,
  1089. &s);
  1090. i__4 = ilastm - jch;
  1091. drot_(&i__4, &t[jch + (jch + 1) * t_dim1], ldt, &t[
  1092. jch + 1 + (jch + 1) * t_dim1], ldt, &c__, &s);
  1093. if (ilq) {
  1094. drot_(n, &q[jch * q_dim1 + 1], &c__1, &q[(jch + 1)
  1095. * q_dim1 + 1], &c__1, &c__, &s);
  1096. }
  1097. if (ilazr2) {
  1098. h__[jch + (jch - 1) * h_dim1] *= c__;
  1099. }
  1100. ilazr2 = FALSE_;
  1101. if ((d__1 = t[jch + 1 + (jch + 1) * t_dim1], abs(d__1)
  1102. ) >= btol) {
  1103. if (jch + 1 >= ilast) {
  1104. goto L80;
  1105. } else {
  1106. ifirst = jch + 1;
  1107. goto L110;
  1108. }
  1109. }
  1110. t[jch + 1 + (jch + 1) * t_dim1] = 0.;
  1111. /* L40: */
  1112. }
  1113. goto L70;
  1114. } else {
  1115. /* Only test 2 passed -- chase the zero to T(ILAST,ILAST) */
  1116. /* Then process as in the case T(ILAST,ILAST)=0 */
  1117. i__3 = ilast - 1;
  1118. for (jch = j; jch <= i__3; ++jch) {
  1119. temp = t[jch + (jch + 1) * t_dim1];
  1120. dlartg_(&temp, &t[jch + 1 + (jch + 1) * t_dim1], &c__,
  1121. &s, &t[jch + (jch + 1) * t_dim1]);
  1122. t[jch + 1 + (jch + 1) * t_dim1] = 0.;
  1123. if (jch < ilastm - 1) {
  1124. i__4 = ilastm - jch - 1;
  1125. drot_(&i__4, &t[jch + (jch + 2) * t_dim1], ldt, &
  1126. t[jch + 1 + (jch + 2) * t_dim1], ldt, &
  1127. c__, &s);
  1128. }
  1129. i__4 = ilastm - jch + 2;
  1130. drot_(&i__4, &h__[jch + (jch - 1) * h_dim1], ldh, &
  1131. h__[jch + 1 + (jch - 1) * h_dim1], ldh, &c__,
  1132. &s);
  1133. if (ilq) {
  1134. drot_(n, &q[jch * q_dim1 + 1], &c__1, &q[(jch + 1)
  1135. * q_dim1 + 1], &c__1, &c__, &s);
  1136. }
  1137. temp = h__[jch + 1 + jch * h_dim1];
  1138. dlartg_(&temp, &h__[jch + 1 + (jch - 1) * h_dim1], &
  1139. c__, &s, &h__[jch + 1 + jch * h_dim1]);
  1140. h__[jch + 1 + (jch - 1) * h_dim1] = 0.;
  1141. i__4 = jch + 1 - ifrstm;
  1142. drot_(&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. drot_(&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. drot_(n, &z__[jch * z_dim1 + 1], &c__1, &z__[(jch
  1151. - 1) * z_dim1 + 1], &c__1, &c__, &s);
  1152. }
  1153. /* L50: */
  1154. }
  1155. goto L70;
  1156. }
  1157. } else if (ilazro) {
  1158. /* Only test 1 passed -- work on J:ILAST */
  1159. ifirst = j;
  1160. goto L110;
  1161. }
  1162. /* Neither test passed -- try next J */
  1163. /* L60: */
  1164. }
  1165. /* (Drop-through is "impossible") */
  1166. *info = *n + 1;
  1167. goto L420;
  1168. /* T(ILAST,ILAST)=0 -- clear H(ILAST,ILAST-1) to split off a */
  1169. /* 1x1 block. */
  1170. L70:
  1171. temp = h__[ilast + ilast * h_dim1];
  1172. dlartg_(&temp, &h__[ilast + (ilast - 1) * h_dim1], &c__, &s, &h__[
  1173. ilast + ilast * h_dim1]);
  1174. h__[ilast + (ilast - 1) * h_dim1] = 0.;
  1175. i__2 = ilast - ifrstm;
  1176. drot_(&i__2, &h__[ifrstm + ilast * h_dim1], &c__1, &h__[ifrstm + (
  1177. ilast - 1) * h_dim1], &c__1, &c__, &s);
  1178. i__2 = ilast - ifrstm;
  1179. drot_(&i__2, &t[ifrstm + ilast * t_dim1], &c__1, &t[ifrstm + (ilast -
  1180. 1) * t_dim1], &c__1, &c__, &s);
  1181. if (ilz) {
  1182. drot_(n, &z__[ilast * z_dim1 + 1], &c__1, &z__[(ilast - 1) *
  1183. z_dim1 + 1], &c__1, &c__, &s);
  1184. }
  1185. /* H(ILAST,ILAST-1)=0 -- Standardize B, set ALPHAR, ALPHAI, */
  1186. /* and BETA */
  1187. L80:
  1188. if (t[ilast + ilast * t_dim1] < 0.) {
  1189. if (ilschr) {
  1190. i__2 = ilast;
  1191. for (j = ifrstm; j <= i__2; ++j) {
  1192. h__[j + ilast * h_dim1] = -h__[j + ilast * h_dim1];
  1193. t[j + ilast * t_dim1] = -t[j + ilast * t_dim1];
  1194. /* L90: */
  1195. }
  1196. } else {
  1197. h__[ilast + ilast * h_dim1] = -h__[ilast + ilast * h_dim1];
  1198. t[ilast + ilast * t_dim1] = -t[ilast + ilast * t_dim1];
  1199. }
  1200. if (ilz) {
  1201. i__2 = *n;
  1202. for (j = 1; j <= i__2; ++j) {
  1203. z__[j + ilast * z_dim1] = -z__[j + ilast * z_dim1];
  1204. /* L100: */
  1205. }
  1206. }
  1207. }
  1208. alphar[ilast] = h__[ilast + ilast * h_dim1];
  1209. alphai[ilast] = 0.;
  1210. beta[ilast] = t[ilast + ilast * t_dim1];
  1211. /* Go to next block -- exit if finished. */
  1212. --ilast;
  1213. if (ilast < *ilo) {
  1214. goto L380;
  1215. }
  1216. /* Reset counters */
  1217. iiter = 0;
  1218. eshift = 0.;
  1219. if (! ilschr) {
  1220. ilastm = ilast;
  1221. if (ifrstm > ilast) {
  1222. ifrstm = *ilo;
  1223. }
  1224. }
  1225. goto L350;
  1226. /* QZ step */
  1227. /* This iteration only involves rows/columns IFIRST:ILAST. We */
  1228. /* assume IFIRST < ILAST, and that the diagonal of B is non-zero. */
  1229. L110:
  1230. ++iiter;
  1231. if (! ilschr) {
  1232. ifrstm = ifirst;
  1233. }
  1234. /* Compute single shifts. */
  1235. /* At this point, IFIRST < ILAST, and the diagonal elements of */
  1236. /* T(IFIRST:ILAST,IFIRST,ILAST) are larger than BTOL (in */
  1237. /* magnitude) */
  1238. if (iiter / 10 * 10 == iiter) {
  1239. /* Exceptional shift. Chosen for no particularly good reason. */
  1240. /* (Single shift only.) */
  1241. if ((doublereal) maxit * safmin * (d__1 = h__[ilast + (ilast - 1)
  1242. * h_dim1], abs(d__1)) < (d__2 = t[ilast - 1 + (ilast - 1)
  1243. * t_dim1], abs(d__2))) {
  1244. eshift = h__[ilast + (ilast - 1) * h_dim1] / t[ilast - 1 + (
  1245. ilast - 1) * t_dim1];
  1246. } else {
  1247. eshift += 1. / (safmin * (doublereal) maxit);
  1248. }
  1249. s1 = 1.;
  1250. wr = eshift;
  1251. } else {
  1252. /* Shifts based on the generalized eigenvalues of the */
  1253. /* bottom-right 2x2 block of A and B. The first eigenvalue */
  1254. /* returned by DLAG2 is the Wilkinson shift (AEP p.512), */
  1255. d__1 = safmin * 100.;
  1256. dlag2_(&h__[ilast - 1 + (ilast - 1) * h_dim1], ldh, &t[ilast - 1
  1257. + (ilast - 1) * t_dim1], ldt, &d__1, &s1, &s2, &wr, &wr2,
  1258. &wi);
  1259. if ((d__1 = wr / s1 * t[ilast + ilast * t_dim1] - h__[ilast +
  1260. ilast * h_dim1], abs(d__1)) > (d__2 = wr2 / s2 * t[ilast
  1261. + ilast * t_dim1] - h__[ilast + ilast * h_dim1], abs(d__2)
  1262. )) {
  1263. temp = wr;
  1264. wr = wr2;
  1265. wr2 = temp;
  1266. temp = s1;
  1267. s1 = s2;
  1268. s2 = temp;
  1269. }
  1270. /* Computing MAX */
  1271. /* Computing MAX */
  1272. d__3 = 1., d__4 = abs(wr), d__3 = f2cmax(d__3,d__4), d__4 = abs(wi);
  1273. d__1 = s1, d__2 = safmin * f2cmax(d__3,d__4);
  1274. temp = f2cmax(d__1,d__2);
  1275. if (wi != 0.) {
  1276. goto L200;
  1277. }
  1278. }
  1279. /* Fiddle with shift to avoid overflow */
  1280. temp = f2cmin(ascale,1.) * (safmax * .5);
  1281. if (s1 > temp) {
  1282. scale = temp / s1;
  1283. } else {
  1284. scale = 1.;
  1285. }
  1286. temp = f2cmin(bscale,1.) * (safmax * .5);
  1287. if (abs(wr) > temp) {
  1288. /* Computing MIN */
  1289. d__1 = scale, d__2 = temp / abs(wr);
  1290. scale = f2cmin(d__1,d__2);
  1291. }
  1292. s1 = scale * s1;
  1293. wr = scale * wr;
  1294. /* Now check for two consecutive small subdiagonals. */
  1295. i__2 = ifirst + 1;
  1296. for (j = ilast - 1; j >= i__2; --j) {
  1297. istart = j;
  1298. temp = (d__1 = s1 * h__[j + (j - 1) * h_dim1], abs(d__1));
  1299. temp2 = (d__1 = s1 * h__[j + j * h_dim1] - wr * t[j + j * t_dim1],
  1300. abs(d__1));
  1301. tempr = f2cmax(temp,temp2);
  1302. if (tempr < 1. && tempr != 0.) {
  1303. temp /= tempr;
  1304. temp2 /= tempr;
  1305. }
  1306. if ((d__1 = ascale * h__[j + 1 + j * h_dim1] * temp, abs(d__1)) <=
  1307. ascale * atol * temp2) {
  1308. goto L130;
  1309. }
  1310. /* L120: */
  1311. }
  1312. istart = ifirst;
  1313. L130:
  1314. /* Do an implicit single-shift QZ sweep. */
  1315. /* Initial Q */
  1316. temp = s1 * h__[istart + istart * h_dim1] - wr * t[istart + istart *
  1317. t_dim1];
  1318. temp2 = s1 * h__[istart + 1 + istart * h_dim1];
  1319. dlartg_(&temp, &temp2, &c__, &s, &tempr);
  1320. /* Sweep */
  1321. i__2 = ilast - 1;
  1322. for (j = istart; j <= i__2; ++j) {
  1323. if (j > istart) {
  1324. temp = h__[j + (j - 1) * h_dim1];
  1325. dlartg_(&temp, &h__[j + 1 + (j - 1) * h_dim1], &c__, &s, &h__[
  1326. j + (j - 1) * h_dim1]);
  1327. h__[j + 1 + (j - 1) * h_dim1] = 0.;
  1328. }
  1329. i__3 = ilastm;
  1330. for (jc = j; jc <= i__3; ++jc) {
  1331. temp = c__ * h__[j + jc * h_dim1] + s * h__[j + 1 + jc *
  1332. h_dim1];
  1333. h__[j + 1 + jc * h_dim1] = -s * h__[j + jc * h_dim1] + c__ *
  1334. h__[j + 1 + jc * h_dim1];
  1335. h__[j + jc * h_dim1] = temp;
  1336. temp2 = c__ * t[j + jc * t_dim1] + s * t[j + 1 + jc * t_dim1];
  1337. t[j + 1 + jc * t_dim1] = -s * t[j + jc * t_dim1] + c__ * t[j
  1338. + 1 + jc * t_dim1];
  1339. t[j + jc * t_dim1] = temp2;
  1340. /* L140: */
  1341. }
  1342. if (ilq) {
  1343. i__3 = *n;
  1344. for (jr = 1; jr <= i__3; ++jr) {
  1345. temp = c__ * q[jr + j * q_dim1] + s * q[jr + (j + 1) *
  1346. q_dim1];
  1347. q[jr + (j + 1) * q_dim1] = -s * q[jr + j * q_dim1] + c__ *
  1348. q[jr + (j + 1) * q_dim1];
  1349. q[jr + j * q_dim1] = temp;
  1350. /* L150: */
  1351. }
  1352. }
  1353. temp = t[j + 1 + (j + 1) * t_dim1];
  1354. dlartg_(&temp, &t[j + 1 + j * t_dim1], &c__, &s, &t[j + 1 + (j +
  1355. 1) * t_dim1]);
  1356. t[j + 1 + j * t_dim1] = 0.;
  1357. /* Computing MIN */
  1358. i__4 = j + 2;
  1359. i__3 = f2cmin(i__4,ilast);
  1360. for (jr = ifrstm; jr <= i__3; ++jr) {
  1361. temp = c__ * h__[jr + (j + 1) * h_dim1] + s * h__[jr + j *
  1362. h_dim1];
  1363. h__[jr + j * h_dim1] = -s * h__[jr + (j + 1) * h_dim1] + c__ *
  1364. h__[jr + j * h_dim1];
  1365. h__[jr + (j + 1) * h_dim1] = temp;
  1366. /* L160: */
  1367. }
  1368. i__3 = j;
  1369. for (jr = ifrstm; jr <= i__3; ++jr) {
  1370. temp = c__ * t[jr + (j + 1) * t_dim1] + s * t[jr + j * t_dim1]
  1371. ;
  1372. t[jr + j * t_dim1] = -s * t[jr + (j + 1) * t_dim1] + c__ * t[
  1373. jr + j * t_dim1];
  1374. t[jr + (j + 1) * t_dim1] = temp;
  1375. /* L170: */
  1376. }
  1377. if (ilz) {
  1378. i__3 = *n;
  1379. for (jr = 1; jr <= i__3; ++jr) {
  1380. temp = c__ * z__[jr + (j + 1) * z_dim1] + s * z__[jr + j *
  1381. z_dim1];
  1382. z__[jr + j * z_dim1] = -s * z__[jr + (j + 1) * z_dim1] +
  1383. c__ * z__[jr + j * z_dim1];
  1384. z__[jr + (j + 1) * z_dim1] = temp;
  1385. /* L180: */
  1386. }
  1387. }
  1388. /* L190: */
  1389. }
  1390. goto L350;
  1391. /* Use Francis double-shift */
  1392. /* Note: the Francis double-shift should work with real shifts, */
  1393. /* but only if the block is at least 3x3. */
  1394. /* This code may break if this point is reached with */
  1395. /* a 2x2 block with real eigenvalues. */
  1396. L200:
  1397. if (ifirst + 1 == ilast) {
  1398. /* Special case -- 2x2 block with complex eigenvectors */
  1399. /* Step 1: Standardize, that is, rotate so that */
  1400. /* ( B11 0 ) */
  1401. /* B = ( ) with B11 non-negative. */
  1402. /* ( 0 B22 ) */
  1403. dlasv2_(&t[ilast - 1 + (ilast - 1) * t_dim1], &t[ilast - 1 +
  1404. ilast * t_dim1], &t[ilast + ilast * t_dim1], &b22, &b11, &
  1405. sr, &cr, &sl, &cl);
  1406. if (b11 < 0.) {
  1407. cr = -cr;
  1408. sr = -sr;
  1409. b11 = -b11;
  1410. b22 = -b22;
  1411. }
  1412. i__2 = ilastm + 1 - ifirst;
  1413. drot_(&i__2, &h__[ilast - 1 + (ilast - 1) * h_dim1], ldh, &h__[
  1414. ilast + (ilast - 1) * h_dim1], ldh, &cl, &sl);
  1415. i__2 = ilast + 1 - ifrstm;
  1416. drot_(&i__2, &h__[ifrstm + (ilast - 1) * h_dim1], &c__1, &h__[
  1417. ifrstm + ilast * h_dim1], &c__1, &cr, &sr);
  1418. if (ilast < ilastm) {
  1419. i__2 = ilastm - ilast;
  1420. drot_(&i__2, &t[ilast - 1 + (ilast + 1) * t_dim1], ldt, &t[
  1421. ilast + (ilast + 1) * t_dim1], ldt, &cl, &sl);
  1422. }
  1423. if (ifrstm < ilast - 1) {
  1424. i__2 = ifirst - ifrstm;
  1425. drot_(&i__2, &t[ifrstm + (ilast - 1) * t_dim1], &c__1, &t[
  1426. ifrstm + ilast * t_dim1], &c__1, &cr, &sr);
  1427. }
  1428. if (ilq) {
  1429. drot_(n, &q[(ilast - 1) * q_dim1 + 1], &c__1, &q[ilast *
  1430. q_dim1 + 1], &c__1, &cl, &sl);
  1431. }
  1432. if (ilz) {
  1433. drot_(n, &z__[(ilast - 1) * z_dim1 + 1], &c__1, &z__[ilast *
  1434. z_dim1 + 1], &c__1, &cr, &sr);
  1435. }
  1436. t[ilast - 1 + (ilast - 1) * t_dim1] = b11;
  1437. t[ilast - 1 + ilast * t_dim1] = 0.;
  1438. t[ilast + (ilast - 1) * t_dim1] = 0.;
  1439. t[ilast + ilast * t_dim1] = b22;
  1440. /* If B22 is negative, negate column ILAST */
  1441. if (b22 < 0.) {
  1442. i__2 = ilast;
  1443. for (j = ifrstm; j <= i__2; ++j) {
  1444. h__[j + ilast * h_dim1] = -h__[j + ilast * h_dim1];
  1445. t[j + ilast * t_dim1] = -t[j + ilast * t_dim1];
  1446. /* L210: */
  1447. }
  1448. if (ilz) {
  1449. i__2 = *n;
  1450. for (j = 1; j <= i__2; ++j) {
  1451. z__[j + ilast * z_dim1] = -z__[j + ilast * z_dim1];
  1452. /* L220: */
  1453. }
  1454. }
  1455. b22 = -b22;
  1456. }
  1457. /* Step 2: Compute ALPHAR, ALPHAI, and BETA (see refs.) */
  1458. /* Recompute shift */
  1459. d__1 = safmin * 100.;
  1460. dlag2_(&h__[ilast - 1 + (ilast - 1) * h_dim1], ldh, &t[ilast - 1
  1461. + (ilast - 1) * t_dim1], ldt, &d__1, &s1, &temp, &wr, &
  1462. temp2, &wi);
  1463. /* If standardization has perturbed the shift onto real line, */
  1464. /* do another (real single-shift) QR step. */
  1465. if (wi == 0.) {
  1466. goto L350;
  1467. }
  1468. s1inv = 1. / s1;
  1469. /* Do EISPACK (QZVAL) computation of alpha and beta */
  1470. a11 = h__[ilast - 1 + (ilast - 1) * h_dim1];
  1471. a21 = h__[ilast + (ilast - 1) * h_dim1];
  1472. a12 = h__[ilast - 1 + ilast * h_dim1];
  1473. a22 = h__[ilast + ilast * h_dim1];
  1474. /* Compute complex Givens rotation on right */
  1475. /* (Assume some element of C = (sA - wB) > unfl ) */
  1476. /* __ */
  1477. /* (sA - wB) ( CZ -SZ ) */
  1478. /* ( SZ CZ ) */
  1479. c11r = s1 * a11 - wr * b11;
  1480. c11i = -wi * b11;
  1481. c12 = s1 * a12;
  1482. c21 = s1 * a21;
  1483. c22r = s1 * a22 - wr * b22;
  1484. c22i = -wi * b22;
  1485. if (abs(c11r) + abs(c11i) + abs(c12) > abs(c21) + abs(c22r) + abs(
  1486. c22i)) {
  1487. t1 = dlapy3_(&c12, &c11r, &c11i);
  1488. cz = c12 / t1;
  1489. szr = -c11r / t1;
  1490. szi = -c11i / t1;
  1491. } else {
  1492. cz = dlapy2_(&c22r, &c22i);
  1493. if (cz <= safmin) {
  1494. cz = 0.;
  1495. szr = 1.;
  1496. szi = 0.;
  1497. } else {
  1498. tempr = c22r / cz;
  1499. tempi = c22i / cz;
  1500. t1 = dlapy2_(&cz, &c21);
  1501. cz /= t1;
  1502. szr = -c21 * tempr / t1;
  1503. szi = c21 * tempi / t1;
  1504. }
  1505. }
  1506. /* Compute Givens rotation on left */
  1507. /* ( CQ SQ ) */
  1508. /* ( __ ) A or B */
  1509. /* ( -SQ CQ ) */
  1510. an = abs(a11) + abs(a12) + abs(a21) + abs(a22);
  1511. bn = abs(b11) + abs(b22);
  1512. wabs = abs(wr) + abs(wi);
  1513. if (s1 * an > wabs * bn) {
  1514. cq = cz * b11;
  1515. sqr = szr * b22;
  1516. sqi = -szi * b22;
  1517. } else {
  1518. a1r = cz * a11 + szr * a12;
  1519. a1i = szi * a12;
  1520. a2r = cz * a21 + szr * a22;
  1521. a2i = szi * a22;
  1522. cq = dlapy2_(&a1r, &a1i);
  1523. if (cq <= safmin) {
  1524. cq = 0.;
  1525. sqr = 1.;
  1526. sqi = 0.;
  1527. } else {
  1528. tempr = a1r / cq;
  1529. tempi = a1i / cq;
  1530. sqr = tempr * a2r + tempi * a2i;
  1531. sqi = tempi * a2r - tempr * a2i;
  1532. }
  1533. }
  1534. t1 = dlapy3_(&cq, &sqr, &sqi);
  1535. cq /= t1;
  1536. sqr /= t1;
  1537. sqi /= t1;
  1538. /* Compute diagonal elements of QBZ */
  1539. tempr = sqr * szr - sqi * szi;
  1540. tempi = sqr * szi + sqi * szr;
  1541. b1r = cq * cz * b11 + tempr * b22;
  1542. b1i = tempi * b22;
  1543. b1a = dlapy2_(&b1r, &b1i);
  1544. b2r = cq * cz * b22 + tempr * b11;
  1545. b2i = -tempi * b11;
  1546. b2a = dlapy2_(&b2r, &b2i);
  1547. /* Normalize so beta > 0, and Im( alpha1 ) > 0 */
  1548. beta[ilast - 1] = b1a;
  1549. beta[ilast] = b2a;
  1550. alphar[ilast - 1] = wr * b1a * s1inv;
  1551. alphai[ilast - 1] = wi * b1a * s1inv;
  1552. alphar[ilast] = wr * b2a * s1inv;
  1553. alphai[ilast] = -(wi * b2a) * s1inv;
  1554. /* Step 3: Go to next block -- exit if finished. */
  1555. ilast = ifirst - 1;
  1556. if (ilast < *ilo) {
  1557. goto L380;
  1558. }
  1559. /* Reset counters */
  1560. iiter = 0;
  1561. eshift = 0.;
  1562. if (! ilschr) {
  1563. ilastm = ilast;
  1564. if (ifrstm > ilast) {
  1565. ifrstm = *ilo;
  1566. }
  1567. }
  1568. goto L350;
  1569. } else {
  1570. /* Usual case: 3x3 or larger block, using Francis implicit */
  1571. /* double-shift */
  1572. /* 2 */
  1573. /* Eigenvalue equation is w - c w + d = 0, */
  1574. /* -1 2 -1 */
  1575. /* so compute 1st column of (A B ) - c A B + d */
  1576. /* using the formula in QZIT (from EISPACK) */
  1577. /* We assume that the block is at least 3x3 */
  1578. ad11 = ascale * h__[ilast - 1 + (ilast - 1) * h_dim1] / (bscale *
  1579. t[ilast - 1 + (ilast - 1) * t_dim1]);
  1580. ad21 = ascale * h__[ilast + (ilast - 1) * h_dim1] / (bscale * t[
  1581. ilast - 1 + (ilast - 1) * t_dim1]);
  1582. ad12 = ascale * h__[ilast - 1 + ilast * h_dim1] / (bscale * t[
  1583. ilast + ilast * t_dim1]);
  1584. ad22 = ascale * h__[ilast + ilast * h_dim1] / (bscale * t[ilast +
  1585. ilast * t_dim1]);
  1586. u12 = t[ilast - 1 + ilast * t_dim1] / t[ilast + ilast * t_dim1];
  1587. ad11l = ascale * h__[ifirst + ifirst * h_dim1] / (bscale * t[
  1588. ifirst + ifirst * t_dim1]);
  1589. ad21l = ascale * h__[ifirst + 1 + ifirst * h_dim1] / (bscale * t[
  1590. ifirst + ifirst * t_dim1]);
  1591. ad12l = ascale * h__[ifirst + (ifirst + 1) * h_dim1] / (bscale *
  1592. t[ifirst + 1 + (ifirst + 1) * t_dim1]);
  1593. ad22l = ascale * h__[ifirst + 1 + (ifirst + 1) * h_dim1] / (
  1594. bscale * t[ifirst + 1 + (ifirst + 1) * t_dim1]);
  1595. ad32l = ascale * h__[ifirst + 2 + (ifirst + 1) * h_dim1] / (
  1596. bscale * t[ifirst + 1 + (ifirst + 1) * t_dim1]);
  1597. u12l = t[ifirst + (ifirst + 1) * t_dim1] / t[ifirst + 1 + (ifirst
  1598. + 1) * t_dim1];
  1599. v[0] = (ad11 - ad11l) * (ad22 - ad11l) - ad12 * ad21 + ad21 * u12
  1600. * ad11l + (ad12l - ad11l * u12l) * ad21l;
  1601. v[1] = (ad22l - ad11l - ad21l * u12l - (ad11 - ad11l) - (ad22 -
  1602. ad11l) + ad21 * u12) * ad21l;
  1603. v[2] = ad32l * ad21l;
  1604. istart = ifirst;
  1605. dlarfg_(&c__3, v, &v[1], &c__1, &tau);
  1606. v[0] = 1.;
  1607. /* Sweep */
  1608. i__2 = ilast - 2;
  1609. for (j = istart; j <= i__2; ++j) {
  1610. /* All but last elements: use 3x3 Householder transforms. */
  1611. /* Zero (j-1)st column of A */
  1612. if (j > istart) {
  1613. v[0] = h__[j + (j - 1) * h_dim1];
  1614. v[1] = h__[j + 1 + (j - 1) * h_dim1];
  1615. v[2] = h__[j + 2 + (j - 1) * h_dim1];
  1616. dlarfg_(&c__3, &h__[j + (j - 1) * h_dim1], &v[1], &c__1, &
  1617. tau);
  1618. v[0] = 1.;
  1619. h__[j + 1 + (j - 1) * h_dim1] = 0.;
  1620. h__[j + 2 + (j - 1) * h_dim1] = 0.;
  1621. }
  1622. i__3 = ilastm;
  1623. for (jc = j; jc <= i__3; ++jc) {
  1624. temp = tau * (h__[j + jc * h_dim1] + v[1] * h__[j + 1 +
  1625. jc * h_dim1] + v[2] * h__[j + 2 + jc * h_dim1]);
  1626. h__[j + jc * h_dim1] -= temp;
  1627. h__[j + 1 + jc * h_dim1] -= temp * v[1];
  1628. h__[j + 2 + jc * h_dim1] -= temp * v[2];
  1629. temp2 = tau * (t[j + jc * t_dim1] + v[1] * t[j + 1 + jc *
  1630. t_dim1] + v[2] * t[j + 2 + jc * t_dim1]);
  1631. t[j + jc * t_dim1] -= temp2;
  1632. t[j + 1 + jc * t_dim1] -= temp2 * v[1];
  1633. t[j + 2 + jc * t_dim1] -= temp2 * v[2];
  1634. /* L230: */
  1635. }
  1636. if (ilq) {
  1637. i__3 = *n;
  1638. for (jr = 1; jr <= i__3; ++jr) {
  1639. temp = tau * (q[jr + j * q_dim1] + v[1] * q[jr + (j +
  1640. 1) * q_dim1] + v[2] * q[jr + (j + 2) * q_dim1]
  1641. );
  1642. q[jr + j * q_dim1] -= temp;
  1643. q[jr + (j + 1) * q_dim1] -= temp * v[1];
  1644. q[jr + (j + 2) * q_dim1] -= temp * v[2];
  1645. /* L240: */
  1646. }
  1647. }
  1648. /* Zero j-th column of B (see DLAGBC for details) */
  1649. /* Swap rows to pivot */
  1650. ilpivt = FALSE_;
  1651. /* Computing MAX */
  1652. d__3 = (d__1 = t[j + 1 + (j + 1) * t_dim1], abs(d__1)), d__4 =
  1653. (d__2 = t[j + 1 + (j + 2) * t_dim1], abs(d__2));
  1654. temp = f2cmax(d__3,d__4);
  1655. /* Computing MAX */
  1656. d__3 = (d__1 = t[j + 2 + (j + 1) * t_dim1], abs(d__1)), d__4 =
  1657. (d__2 = t[j + 2 + (j + 2) * t_dim1], abs(d__2));
  1658. temp2 = f2cmax(d__3,d__4);
  1659. if (f2cmax(temp,temp2) < safmin) {
  1660. scale = 0.;
  1661. u1 = 1.;
  1662. u2 = 0.;
  1663. goto L250;
  1664. } else if (temp >= temp2) {
  1665. w11 = t[j + 1 + (j + 1) * t_dim1];
  1666. w21 = t[j + 2 + (j + 1) * t_dim1];
  1667. w12 = t[j + 1 + (j + 2) * t_dim1];
  1668. w22 = t[j + 2 + (j + 2) * t_dim1];
  1669. u1 = t[j + 1 + j * t_dim1];
  1670. u2 = t[j + 2 + j * t_dim1];
  1671. } else {
  1672. w21 = t[j + 1 + (j + 1) * t_dim1];
  1673. w11 = t[j + 2 + (j + 1) * t_dim1];
  1674. w22 = t[j + 1 + (j + 2) * t_dim1];
  1675. w12 = t[j + 2 + (j + 2) * t_dim1];
  1676. u2 = t[j + 1 + j * t_dim1];
  1677. u1 = t[j + 2 + j * t_dim1];
  1678. }
  1679. /* Swap columns if nec. */
  1680. if (abs(w12) > abs(w11)) {
  1681. ilpivt = TRUE_;
  1682. temp = w12;
  1683. temp2 = w22;
  1684. w12 = w11;
  1685. w22 = w21;
  1686. w11 = temp;
  1687. w21 = temp2;
  1688. }
  1689. /* LU-factor */
  1690. temp = w21 / w11;
  1691. u2 -= temp * u1;
  1692. w22 -= temp * w12;
  1693. w21 = 0.;
  1694. /* Compute SCALE */
  1695. scale = 1.;
  1696. if (abs(w22) < safmin) {
  1697. scale = 0.;
  1698. u2 = 1.;
  1699. u1 = -w12 / w11;
  1700. goto L250;
  1701. }
  1702. if (abs(w22) < abs(u2)) {
  1703. scale = (d__1 = w22 / u2, abs(d__1));
  1704. }
  1705. if (abs(w11) < abs(u1)) {
  1706. /* Computing MIN */
  1707. d__2 = scale, d__3 = (d__1 = w11 / u1, abs(d__1));
  1708. scale = f2cmin(d__2,d__3);
  1709. }
  1710. /* Solve */
  1711. u2 = scale * u2 / w22;
  1712. u1 = (scale * u1 - w12 * u2) / w11;
  1713. L250:
  1714. if (ilpivt) {
  1715. temp = u2;
  1716. u2 = u1;
  1717. u1 = temp;
  1718. }
  1719. /* Compute Householder Vector */
  1720. /* Computing 2nd power */
  1721. d__1 = scale;
  1722. /* Computing 2nd power */
  1723. d__2 = u1;
  1724. /* Computing 2nd power */
  1725. d__3 = u2;
  1726. t1 = sqrt(d__1 * d__1 + d__2 * d__2 + d__3 * d__3);
  1727. tau = scale / t1 + 1.;
  1728. vs = -1. / (scale + t1);
  1729. v[0] = 1.;
  1730. v[1] = vs * u1;
  1731. v[2] = vs * u2;
  1732. /* Apply transformations from the right. */
  1733. /* Computing MIN */
  1734. i__4 = j + 3;
  1735. i__3 = f2cmin(i__4,ilast);
  1736. for (jr = ifrstm; jr <= i__3; ++jr) {
  1737. temp = tau * (h__[jr + j * h_dim1] + v[1] * h__[jr + (j +
  1738. 1) * h_dim1] + v[2] * h__[jr + (j + 2) * h_dim1]);
  1739. h__[jr + j * h_dim1] -= temp;
  1740. h__[jr + (j + 1) * h_dim1] -= temp * v[1];
  1741. h__[jr + (j + 2) * h_dim1] -= temp * v[2];
  1742. /* L260: */
  1743. }
  1744. i__3 = j + 2;
  1745. for (jr = ifrstm; jr <= i__3; ++jr) {
  1746. temp = tau * (t[jr + j * t_dim1] + v[1] * t[jr + (j + 1) *
  1747. t_dim1] + v[2] * t[jr + (j + 2) * t_dim1]);
  1748. t[jr + j * t_dim1] -= temp;
  1749. t[jr + (j + 1) * t_dim1] -= temp * v[1];
  1750. t[jr + (j + 2) * t_dim1] -= temp * v[2];
  1751. /* L270: */
  1752. }
  1753. if (ilz) {
  1754. i__3 = *n;
  1755. for (jr = 1; jr <= i__3; ++jr) {
  1756. temp = tau * (z__[jr + j * z_dim1] + v[1] * z__[jr + (
  1757. j + 1) * z_dim1] + v[2] * z__[jr + (j + 2) *
  1758. z_dim1]);
  1759. z__[jr + j * z_dim1] -= temp;
  1760. z__[jr + (j + 1) * z_dim1] -= temp * v[1];
  1761. z__[jr + (j + 2) * z_dim1] -= temp * v[2];
  1762. /* L280: */
  1763. }
  1764. }
  1765. t[j + 1 + j * t_dim1] = 0.;
  1766. t[j + 2 + j * t_dim1] = 0.;
  1767. /* L290: */
  1768. }
  1769. /* Last elements: Use Givens rotations */
  1770. /* Rotations from the left */
  1771. j = ilast - 1;
  1772. temp = h__[j + (j - 1) * h_dim1];
  1773. dlartg_(&temp, &h__[j + 1 + (j - 1) * h_dim1], &c__, &s, &h__[j +
  1774. (j - 1) * h_dim1]);
  1775. h__[j + 1 + (j - 1) * h_dim1] = 0.;
  1776. i__2 = ilastm;
  1777. for (jc = j; jc <= i__2; ++jc) {
  1778. temp = c__ * h__[j + jc * h_dim1] + s * h__[j + 1 + jc *
  1779. h_dim1];
  1780. h__[j + 1 + jc * h_dim1] = -s * h__[j + jc * h_dim1] + c__ *
  1781. h__[j + 1 + jc * h_dim1];
  1782. h__[j + jc * h_dim1] = temp;
  1783. temp2 = c__ * t[j + jc * t_dim1] + s * t[j + 1 + jc * t_dim1];
  1784. t[j + 1 + jc * t_dim1] = -s * t[j + jc * t_dim1] + c__ * t[j
  1785. + 1 + jc * t_dim1];
  1786. t[j + jc * t_dim1] = temp2;
  1787. /* L300: */
  1788. }
  1789. if (ilq) {
  1790. i__2 = *n;
  1791. for (jr = 1; jr <= i__2; ++jr) {
  1792. temp = c__ * q[jr + j * q_dim1] + s * q[jr + (j + 1) *
  1793. q_dim1];
  1794. q[jr + (j + 1) * q_dim1] = -s * q[jr + j * q_dim1] + c__ *
  1795. q[jr + (j + 1) * q_dim1];
  1796. q[jr + j * q_dim1] = temp;
  1797. /* L310: */
  1798. }
  1799. }
  1800. /* Rotations from the right. */
  1801. temp = t[j + 1 + (j + 1) * t_dim1];
  1802. dlartg_(&temp, &t[j + 1 + j * t_dim1], &c__, &s, &t[j + 1 + (j +
  1803. 1) * t_dim1]);
  1804. t[j + 1 + j * t_dim1] = 0.;
  1805. i__2 = ilast;
  1806. for (jr = ifrstm; jr <= i__2; ++jr) {
  1807. temp = c__ * h__[jr + (j + 1) * h_dim1] + s * h__[jr + j *
  1808. h_dim1];
  1809. h__[jr + j * h_dim1] = -s * h__[jr + (j + 1) * h_dim1] + c__ *
  1810. h__[jr + j * h_dim1];
  1811. h__[jr + (j + 1) * h_dim1] = temp;
  1812. /* L320: */
  1813. }
  1814. i__2 = ilast - 1;
  1815. for (jr = ifrstm; jr <= i__2; ++jr) {
  1816. temp = c__ * t[jr + (j + 1) * t_dim1] + s * t[jr + j * t_dim1]
  1817. ;
  1818. t[jr + j * t_dim1] = -s * t[jr + (j + 1) * t_dim1] + c__ * t[
  1819. jr + j * t_dim1];
  1820. t[jr + (j + 1) * t_dim1] = temp;
  1821. /* L330: */
  1822. }
  1823. if (ilz) {
  1824. i__2 = *n;
  1825. for (jr = 1; jr <= i__2; ++jr) {
  1826. temp = c__ * z__[jr + (j + 1) * z_dim1] + s * z__[jr + j *
  1827. z_dim1];
  1828. z__[jr + j * z_dim1] = -s * z__[jr + (j + 1) * z_dim1] +
  1829. c__ * z__[jr + j * z_dim1];
  1830. z__[jr + (j + 1) * z_dim1] = temp;
  1831. /* L340: */
  1832. }
  1833. }
  1834. /* End of Double-Shift code */
  1835. }
  1836. goto L350;
  1837. /* End of iteration loop */
  1838. L350:
  1839. /* L360: */
  1840. ;
  1841. }
  1842. /* Drop-through = non-convergence */
  1843. *info = ilast;
  1844. goto L420;
  1845. /* Successful completion of all QZ steps */
  1846. L380:
  1847. /* Set Eigenvalues 1:ILO-1 */
  1848. i__1 = *ilo - 1;
  1849. for (j = 1; j <= i__1; ++j) {
  1850. if (t[j + j * t_dim1] < 0.) {
  1851. if (ilschr) {
  1852. i__2 = j;
  1853. for (jr = 1; jr <= i__2; ++jr) {
  1854. h__[jr + j * h_dim1] = -h__[jr + j * h_dim1];
  1855. t[jr + j * t_dim1] = -t[jr + j * t_dim1];
  1856. /* L390: */
  1857. }
  1858. } else {
  1859. h__[j + j * h_dim1] = -h__[j + j * h_dim1];
  1860. t[j + j * t_dim1] = -t[j + j * t_dim1];
  1861. }
  1862. if (ilz) {
  1863. i__2 = *n;
  1864. for (jr = 1; jr <= i__2; ++jr) {
  1865. z__[jr + j * z_dim1] = -z__[jr + j * z_dim1];
  1866. /* L400: */
  1867. }
  1868. }
  1869. }
  1870. alphar[j] = h__[j + j * h_dim1];
  1871. alphai[j] = 0.;
  1872. beta[j] = t[j + j * t_dim1];
  1873. /* L410: */
  1874. }
  1875. /* Normal Termination */
  1876. *info = 0;
  1877. /* Exit (other than argument error) -- return optimal workspace size */
  1878. L420:
  1879. work[1] = (doublereal) (*n);
  1880. return;
  1881. /* End of DHGEQZ */
  1882. } /* dhgeqz_ */