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