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.

shgeqz.c 53 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847
  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 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++ = ' '; }
  217. #define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d))))
  218. #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]; }
  219. #define sig_die(s, kill) { exit(1); }
  220. #define s_stop(s, n) {exit(0);}
  221. #define z_abs(z) (cabs(Cd(z)))
  222. #define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));}
  223. #define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));}
  224. #define myexit_() break;
  225. #define mycycle() continue;
  226. #define myceiling(w) {ceil(w)}
  227. #define myhuge(w) {HUGE_VAL}
  228. //#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);}
  229. #define mymaxloc(w,s,e,n) {dmaxloc_(w,*(s),*(e),n)}
  230. /* -- translated by f2c (version 20000121).
  231. You must link the resulting object file with the libraries:
  232. -lf2c -lm (in that order)
  233. */
  234. /* Table of constant values */
  235. static real c_b12 = 0.f;
  236. static real c_b13 = 1.f;
  237. static integer c__1 = 1;
  238. static integer c__3 = 3;
  239. /* > \brief \b SHGEQZ */
  240. /* =========== DOCUMENTATION =========== */
  241. /* Online html documentation available at */
  242. /* http://www.netlib.org/lapack/explore-html/ */
  243. /* > \htmlonly */
  244. /* > Download SHGEQZ + dependencies */
  245. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/shgeqz.
  246. f"> */
  247. /* > [TGZ]</a> */
  248. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/shgeqz.
  249. f"> */
  250. /* > [ZIP]</a> */
  251. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/shgeqz.
  252. f"> */
  253. /* > [TXT]</a> */
  254. /* > \endhtmlonly */
  255. /* Definition: */
  256. /* =========== */
  257. /* SUBROUTINE SHGEQZ( JOB, COMPQ, COMPZ, N, ILO, IHI, H, LDH, T, LDT, */
  258. /* ALPHAR, ALPHAI, BETA, Q, LDQ, Z, LDZ, WORK, */
  259. /* LWORK, INFO ) */
  260. /* CHARACTER COMPQ, COMPZ, JOB */
  261. /* INTEGER IHI, ILO, INFO, LDH, LDQ, LDT, LDZ, LWORK, N */
  262. /* REAL ALPHAI( * ), ALPHAR( * ), BETA( * ), */
  263. /* $ H( LDH, * ), Q( LDQ, * ), T( LDT, * ), */
  264. /* $ WORK( * ), Z( LDZ, * ) */
  265. /* > \par Purpose: */
  266. /* ============= */
  267. /* > */
  268. /* > \verbatim */
  269. /* > */
  270. /* > SHGEQZ computes the eigenvalues of a real matrix pair (H,T), */
  271. /* > where H is an upper Hessenberg matrix and T is upper triangular, */
  272. /* > using the double-shift QZ method. */
  273. /* > Matrix pairs of this type are produced by the reduction to */
  274. /* > generalized upper Hessenberg form of a real matrix pair (A,B): */
  275. /* > */
  276. /* > A = Q1*H*Z1**T, B = Q1*T*Z1**T, */
  277. /* > */
  278. /* > as computed by SGGHRD. */
  279. /* > */
  280. /* > If JOB='S', then the Hessenberg-triangular pair (H,T) is */
  281. /* > also reduced to generalized Schur form, */
  282. /* > */
  283. /* > H = Q*S*Z**T, T = Q*P*Z**T, */
  284. /* > */
  285. /* > where Q and Z are orthogonal matrices, P is an upper triangular */
  286. /* > matrix, and S is a quasi-triangular matrix with 1-by-1 and 2-by-2 */
  287. /* > diagonal blocks. */
  288. /* > */
  289. /* > The 1-by-1 blocks correspond to real eigenvalues of the matrix pair */
  290. /* > (H,T) and the 2-by-2 blocks correspond to complex conjugate pairs of */
  291. /* > eigenvalues. */
  292. /* > */
  293. /* > Additionally, the 2-by-2 upper triangular diagonal blocks of P */
  294. /* > corresponding to 2-by-2 blocks of S are reduced to positive diagonal */
  295. /* > form, i.e., if S(j+1,j) is non-zero, then P(j+1,j) = P(j,j+1) = 0, */
  296. /* > P(j,j) > 0, and P(j+1,j+1) > 0. */
  297. /* > */
  298. /* > Optionally, the orthogonal matrix Q from the generalized Schur */
  299. /* > factorization may be postmultiplied into an input matrix Q1, and the */
  300. /* > orthogonal matrix Z may be postmultiplied into an input matrix Z1. */
  301. /* > If Q1 and Z1 are the orthogonal matrices from SGGHRD that reduced */
  302. /* > the matrix pair (A,B) to generalized upper Hessenberg form, then the */
  303. /* > output matrices Q1*Q and Z1*Z are the orthogonal factors from the */
  304. /* > generalized Schur factorization of (A,B): */
  305. /* > */
  306. /* > A = (Q1*Q)*S*(Z1*Z)**T, B = (Q1*Q)*P*(Z1*Z)**T. */
  307. /* > */
  308. /* > To avoid overflow, eigenvalues of the matrix pair (H,T) (equivalently, */
  309. /* > of (A,B)) are computed as a pair of values (alpha,beta), where alpha is */
  310. /* > complex and beta real. */
  311. /* > If beta is nonzero, lambda = alpha / beta is an eigenvalue of the */
  312. /* > generalized nonsymmetric eigenvalue problem (GNEP) */
  313. /* > A*x = lambda*B*x */
  314. /* > and if alpha is nonzero, mu = beta / alpha is an eigenvalue of the */
  315. /* > alternate form of the GNEP */
  316. /* > mu*A*y = B*y. */
  317. /* > Real eigenvalues can be read directly from the generalized Schur */
  318. /* > form: */
  319. /* > alpha = S(i,i), beta = P(i,i). */
  320. /* > */
  321. /* > Ref: C.B. Moler & G.W. Stewart, "An Algorithm for Generalized Matrix */
  322. /* > Eigenvalue Problems", SIAM J. Numer. Anal., 10(1973), */
  323. /* > pp. 241--256. */
  324. /* > \endverbatim */
  325. /* Arguments: */
  326. /* ========== */
  327. /* > \param[in] JOB */
  328. /* > \verbatim */
  329. /* > JOB is CHARACTER*1 */
  330. /* > = 'E': Compute eigenvalues only; */
  331. /* > = 'S': Compute eigenvalues and the Schur form. */
  332. /* > \endverbatim */
  333. /* > */
  334. /* > \param[in] COMPQ */
  335. /* > \verbatim */
  336. /* > COMPQ is CHARACTER*1 */
  337. /* > = 'N': Left Schur vectors (Q) are not computed; */
  338. /* > = 'I': Q is initialized to the unit matrix and the matrix Q */
  339. /* > of left Schur vectors of (H,T) is returned; */
  340. /* > = 'V': Q must contain an orthogonal matrix Q1 on entry and */
  341. /* > the product Q1*Q is returned. */
  342. /* > \endverbatim */
  343. /* > */
  344. /* > \param[in] COMPZ */
  345. /* > \verbatim */
  346. /* > COMPZ is CHARACTER*1 */
  347. /* > = 'N': Right Schur vectors (Z) are not computed; */
  348. /* > = 'I': Z is initialized to the unit matrix and the matrix Z */
  349. /* > of right Schur vectors of (H,T) is returned; */
  350. /* > = 'V': Z must contain an orthogonal matrix Z1 on entry and */
  351. /* > the product Z1*Z is returned. */
  352. /* > \endverbatim */
  353. /* > */
  354. /* > \param[in] N */
  355. /* > \verbatim */
  356. /* > N is INTEGER */
  357. /* > The order of the matrices H, T, Q, and Z. N >= 0. */
  358. /* > \endverbatim */
  359. /* > */
  360. /* > \param[in] ILO */
  361. /* > \verbatim */
  362. /* > ILO is INTEGER */
  363. /* > \endverbatim */
  364. /* > */
  365. /* > \param[in] IHI */
  366. /* > \verbatim */
  367. /* > IHI is INTEGER */
  368. /* > ILO and IHI mark the rows and columns of H which are in */
  369. /* > Hessenberg form. It is assumed that A is already upper */
  370. /* > triangular in rows and columns 1:ILO-1 and IHI+1:N. */
  371. /* > If N > 0, 1 <= ILO <= IHI <= N; if N = 0, ILO=1 and IHI=0. */
  372. /* > \endverbatim */
  373. /* > */
  374. /* > \param[in,out] H */
  375. /* > \verbatim */
  376. /* > H is REAL array, dimension (LDH, N) */
  377. /* > On entry, the N-by-N upper Hessenberg matrix H. */
  378. /* > On exit, if JOB = 'S', H contains the upper quasi-triangular */
  379. /* > matrix S from the generalized Schur factorization. */
  380. /* > If JOB = 'E', the diagonal blocks of H match those of S, but */
  381. /* > the rest of H is unspecified. */
  382. /* > \endverbatim */
  383. /* > */
  384. /* > \param[in] LDH */
  385. /* > \verbatim */
  386. /* > LDH is INTEGER */
  387. /* > The leading dimension of the array H. LDH >= f2cmax( 1, N ). */
  388. /* > \endverbatim */
  389. /* > */
  390. /* > \param[in,out] T */
  391. /* > \verbatim */
  392. /* > T is REAL array, dimension (LDT, N) */
  393. /* > On entry, the N-by-N upper triangular matrix T. */
  394. /* > On exit, if JOB = 'S', T contains the upper triangular */
  395. /* > matrix P from the generalized Schur factorization; */
  396. /* > 2-by-2 diagonal blocks of P corresponding to 2-by-2 blocks of S */
  397. /* > are reduced to positive diagonal form, i.e., if H(j+1,j) is */
  398. /* > non-zero, then T(j+1,j) = T(j,j+1) = 0, T(j,j) > 0, and */
  399. /* > T(j+1,j+1) > 0. */
  400. /* > If JOB = 'E', the diagonal blocks of T match those of P, but */
  401. /* > the rest of T is unspecified. */
  402. /* > \endverbatim */
  403. /* > */
  404. /* > \param[in] LDT */
  405. /* > \verbatim */
  406. /* > LDT is INTEGER */
  407. /* > The leading dimension of the array T. LDT >= f2cmax( 1, N ). */
  408. /* > \endverbatim */
  409. /* > */
  410. /* > \param[out] ALPHAR */
  411. /* > \verbatim */
  412. /* > ALPHAR is REAL array, dimension (N) */
  413. /* > The real parts of each scalar alpha defining an eigenvalue */
  414. /* > of GNEP. */
  415. /* > \endverbatim */
  416. /* > */
  417. /* > \param[out] ALPHAI */
  418. /* > \verbatim */
  419. /* > ALPHAI is REAL array, dimension (N) */
  420. /* > The imaginary parts of each scalar alpha defining an */
  421. /* > eigenvalue of GNEP. */
  422. /* > If ALPHAI(j) is zero, then the j-th eigenvalue is real; if */
  423. /* > positive, then the j-th and (j+1)-st eigenvalues are a */
  424. /* > complex conjugate pair, with ALPHAI(j+1) = -ALPHAI(j). */
  425. /* > \endverbatim */
  426. /* > */
  427. /* > \param[out] BETA */
  428. /* > \verbatim */
  429. /* > BETA is REAL array, dimension (N) */
  430. /* > The scalars beta that define the eigenvalues of GNEP. */
  431. /* > Together, the quantities alpha = (ALPHAR(j),ALPHAI(j)) and */
  432. /* > beta = BETA(j) represent the j-th eigenvalue of the matrix */
  433. /* > pair (A,B), in one of the forms lambda = alpha/beta or */
  434. /* > mu = beta/alpha. Since either lambda or mu may overflow, */
  435. /* > they should not, in general, be computed. */
  436. /* > \endverbatim */
  437. /* > */
  438. /* > \param[in,out] Q */
  439. /* > \verbatim */
  440. /* > Q is REAL array, dimension (LDQ, N) */
  441. /* > On entry, if COMPQ = 'V', the orthogonal matrix Q1 used in */
  442. /* > the reduction of (A,B) to generalized Hessenberg form. */
  443. /* > On exit, if COMPQ = 'I', the orthogonal matrix of left Schur */
  444. /* > vectors of (H,T), and if COMPQ = 'V', the orthogonal matrix */
  445. /* > of left Schur vectors of (A,B). */
  446. /* > Not referenced if COMPQ = 'N'. */
  447. /* > \endverbatim */
  448. /* > */
  449. /* > \param[in] LDQ */
  450. /* > \verbatim */
  451. /* > LDQ is INTEGER */
  452. /* > The leading dimension of the array Q. LDQ >= 1. */
  453. /* > If COMPQ='V' or 'I', then LDQ >= N. */
  454. /* > \endverbatim */
  455. /* > */
  456. /* > \param[in,out] Z */
  457. /* > \verbatim */
  458. /* > Z is REAL array, dimension (LDZ, N) */
  459. /* > On entry, if COMPZ = 'V', the orthogonal matrix Z1 used in */
  460. /* > the reduction of (A,B) to generalized Hessenberg form. */
  461. /* > On exit, if COMPZ = 'I', the orthogonal matrix of */
  462. /* > right Schur vectors of (H,T), and if COMPZ = 'V', the */
  463. /* > orthogonal matrix of right Schur vectors of (A,B). */
  464. /* > Not referenced if COMPZ = 'N'. */
  465. /* > \endverbatim */
  466. /* > */
  467. /* > \param[in] LDZ */
  468. /* > \verbatim */
  469. /* > LDZ is INTEGER */
  470. /* > The leading dimension of the array Z. LDZ >= 1. */
  471. /* > If COMPZ='V' or 'I', then LDZ >= N. */
  472. /* > \endverbatim */
  473. /* > */
  474. /* > \param[out] WORK */
  475. /* > \verbatim */
  476. /* > WORK is REAL array, dimension (MAX(1,LWORK)) */
  477. /* > On exit, if INFO >= 0, WORK(1) returns the optimal LWORK. */
  478. /* > \endverbatim */
  479. /* > */
  480. /* > \param[in] LWORK */
  481. /* > \verbatim */
  482. /* > LWORK is INTEGER */
  483. /* > The dimension of the array WORK. LWORK >= f2cmax(1,N). */
  484. /* > */
  485. /* > If LWORK = -1, then a workspace query is assumed; the routine */
  486. /* > only calculates the optimal size of the WORK array, returns */
  487. /* > this value as the first entry of the WORK array, and no error */
  488. /* > message related to LWORK is issued by XERBLA. */
  489. /* > \endverbatim */
  490. /* > */
  491. /* > \param[out] INFO */
  492. /* > \verbatim */
  493. /* > INFO is INTEGER */
  494. /* > = 0: successful exit */
  495. /* > < 0: if INFO = -i, the i-th argument had an illegal value */
  496. /* > = 1,...,N: the QZ iteration did not converge. (H,T) is not */
  497. /* > in Schur form, but ALPHAR(i), ALPHAI(i), and */
  498. /* > BETA(i), i=INFO+1,...,N should be correct. */
  499. /* > = N+1,...,2*N: the shift calculation failed. (H,T) is not */
  500. /* > in Schur form, but ALPHAR(i), ALPHAI(i), and */
  501. /* > BETA(i), i=INFO-N+1,...,N should be correct. */
  502. /* > \endverbatim */
  503. /* Authors: */
  504. /* ======== */
  505. /* > \author Univ. of Tennessee */
  506. /* > \author Univ. of California Berkeley */
  507. /* > \author Univ. of Colorado Denver */
  508. /* > \author NAG Ltd. */
  509. /* > \date June 2016 */
  510. /* > \ingroup realGEcomputational */
  511. /* > \par Further Details: */
  512. /* ===================== */
  513. /* > */
  514. /* > \verbatim */
  515. /* > */
  516. /* > Iteration counters: */
  517. /* > */
  518. /* > JITER -- counts iterations. */
  519. /* > IITER -- counts iterations run since ILAST was last */
  520. /* > changed. This is therefore reset only when a 1-by-1 or */
  521. /* > 2-by-2 block deflates off the bottom. */
  522. /* > \endverbatim */
  523. /* > */
  524. /* ===================================================================== */
  525. /* Subroutine */ void shgeqz_(char *job, char *compq, char *compz, integer *n,
  526. integer *ilo, integer *ihi, real *h__, integer *ldh, real *t, integer
  527. *ldt, real *alphar, real *alphai, real *beta, real *q, integer *ldq,
  528. real *z__, integer *ldz, real *work, integer *lwork, integer *info)
  529. {
  530. /* System generated locals */
  531. integer h_dim1, h_offset, q_dim1, q_offset, t_dim1, t_offset, z_dim1,
  532. z_offset, i__1, i__2, i__3, i__4;
  533. real r__1, r__2, r__3, r__4;
  534. /* Local variables */
  535. real ad11l, ad12l, ad21l, ad22l, ad32l, wabs, atol, btol, temp;
  536. extern /* Subroutine */ void srot_(integer *, real *, integer *, real *,
  537. integer *, real *, real *), slag2_(real *, integer *, real *,
  538. integer *, real *, real *, real *, real *, real *, real *);
  539. real temp2, s1inv, c__;
  540. integer j;
  541. real s, v[3], scale;
  542. extern logical lsame_(char *, char *);
  543. integer iiter, ilast, jiter;
  544. real anorm, bnorm;
  545. integer maxit;
  546. real tempi, tempr, s1, s2, t1, u1, u2;
  547. logical ilazr2;
  548. real a11, a12, a21, a22, b11, b22, c12, c21;
  549. extern real slapy2_(real *, real *);
  550. integer jc;
  551. extern real slapy3_(real *, real *, real *);
  552. real an, bn, cl;
  553. extern /* Subroutine */ void slasv2_(real *, real *, real *, real *, real *
  554. , real *, real *, real *, real *);
  555. real cq, cr;
  556. integer in;
  557. real ascale, bscale, u12, w11;
  558. integer jr;
  559. real cz, sl, w12, w21, w22, wi, sr;
  560. extern real slamch_(char *);
  561. real vs, wr, safmin;
  562. extern /* Subroutine */ void slarfg_(integer *, real *, real *, integer *,
  563. real *);
  564. real safmax;
  565. extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen);
  566. real eshift;
  567. logical ilschr;
  568. real b1a, b2a;
  569. integer icompq, ilastm;
  570. extern real slanhs_(char *, integer *, real *, integer *, real *);
  571. real a1i;
  572. integer ischur;
  573. real a2i, b1i;
  574. logical ilazro;
  575. integer icompz, ifirst, ifrstm;
  576. real a1r;
  577. integer istart;
  578. logical ilpivt;
  579. real a2r, b1r, b2i, b2r;
  580. extern /* Subroutine */ void slartg_(real *, real *, real *, real *, real *
  581. ), slaset_(char *, integer *, integer *, real *, real *, real *,
  582. integer *);
  583. logical lquery;
  584. real wr2, ad11, ad12, ad21, ad22, c11i, c22i;
  585. integer jch;
  586. real c11r, c22r;
  587. logical ilq;
  588. real u12l, tau, sqi;
  589. logical ilz;
  590. real ulp, sqr, szi, szr;
  591. /* -- LAPACK computational routine (version 3.7.0) -- */
  592. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  593. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  594. /* June 2016 */
  595. /* ===================================================================== */
  596. /* $ SAFETY = 1.0E+0 ) */
  597. /* Decode JOB, COMPQ, COMPZ */
  598. /* Parameter adjustments */
  599. h_dim1 = *ldh;
  600. h_offset = 1 + h_dim1 * 1;
  601. h__ -= h_offset;
  602. t_dim1 = *ldt;
  603. t_offset = 1 + t_dim1 * 1;
  604. t -= t_offset;
  605. --alphar;
  606. --alphai;
  607. --beta;
  608. q_dim1 = *ldq;
  609. q_offset = 1 + q_dim1 * 1;
  610. q -= q_offset;
  611. z_dim1 = *ldz;
  612. z_offset = 1 + z_dim1 * 1;
  613. z__ -= z_offset;
  614. --work;
  615. /* Function Body */
  616. if (lsame_(job, "E")) {
  617. ilschr = FALSE_;
  618. ischur = 1;
  619. } else if (lsame_(job, "S")) {
  620. ilschr = TRUE_;
  621. ischur = 2;
  622. } else {
  623. ischur = 0;
  624. }
  625. if (lsame_(compq, "N")) {
  626. ilq = FALSE_;
  627. icompq = 1;
  628. } else if (lsame_(compq, "V")) {
  629. ilq = TRUE_;
  630. icompq = 2;
  631. } else if (lsame_(compq, "I")) {
  632. ilq = TRUE_;
  633. icompq = 3;
  634. } else {
  635. icompq = 0;
  636. }
  637. if (lsame_(compz, "N")) {
  638. ilz = FALSE_;
  639. icompz = 1;
  640. } else if (lsame_(compz, "V")) {
  641. ilz = TRUE_;
  642. icompz = 2;
  643. } else if (lsame_(compz, "I")) {
  644. ilz = TRUE_;
  645. icompz = 3;
  646. } else {
  647. icompz = 0;
  648. }
  649. /* Check Argument Values */
  650. *info = 0;
  651. work[1] = (real) f2cmax(1,*n);
  652. lquery = *lwork == -1;
  653. if (ischur == 0) {
  654. *info = -1;
  655. } else if (icompq == 0) {
  656. *info = -2;
  657. } else if (icompz == 0) {
  658. *info = -3;
  659. } else if (*n < 0) {
  660. *info = -4;
  661. } else if (*ilo < 1) {
  662. *info = -5;
  663. } else if (*ihi > *n || *ihi < *ilo - 1) {
  664. *info = -6;
  665. } else if (*ldh < *n) {
  666. *info = -8;
  667. } else if (*ldt < *n) {
  668. *info = -10;
  669. } else if (*ldq < 1 || ilq && *ldq < *n) {
  670. *info = -15;
  671. } else if (*ldz < 1 || ilz && *ldz < *n) {
  672. *info = -17;
  673. } else if (*lwork < f2cmax(1,*n) && ! lquery) {
  674. *info = -19;
  675. }
  676. if (*info != 0) {
  677. i__1 = -(*info);
  678. xerbla_("SHGEQZ", &i__1, (ftnlen)6);
  679. return;
  680. } else if (lquery) {
  681. return;
  682. }
  683. /* Quick return if possible */
  684. if (*n <= 0) {
  685. work[1] = 1.f;
  686. return;
  687. }
  688. /* Initialize Q and Z */
  689. if (icompq == 3) {
  690. slaset_("Full", n, n, &c_b12, &c_b13, &q[q_offset], ldq);
  691. }
  692. if (icompz == 3) {
  693. slaset_("Full", n, n, &c_b12, &c_b13, &z__[z_offset], ldz);
  694. }
  695. /* Machine Constants */
  696. in = *ihi + 1 - *ilo;
  697. safmin = slamch_("S");
  698. safmax = 1.f / safmin;
  699. ulp = slamch_("E") * slamch_("B");
  700. anorm = slanhs_("F", &in, &h__[*ilo + *ilo * h_dim1], ldh, &work[1]);
  701. bnorm = slanhs_("F", &in, &t[*ilo + *ilo * t_dim1], ldt, &work[1]);
  702. /* Computing MAX */
  703. r__1 = safmin, r__2 = ulp * anorm;
  704. atol = f2cmax(r__1,r__2);
  705. /* Computing MAX */
  706. r__1 = safmin, r__2 = ulp * bnorm;
  707. btol = f2cmax(r__1,r__2);
  708. ascale = 1.f / f2cmax(safmin,anorm);
  709. bscale = 1.f / f2cmax(safmin,bnorm);
  710. /* Set Eigenvalues IHI+1:N */
  711. i__1 = *n;
  712. for (j = *ihi + 1; j <= i__1; ++j) {
  713. if (t[j + j * t_dim1] < 0.f) {
  714. if (ilschr) {
  715. i__2 = j;
  716. for (jr = 1; jr <= i__2; ++jr) {
  717. h__[jr + j * h_dim1] = -h__[jr + j * h_dim1];
  718. t[jr + j * t_dim1] = -t[jr + j * t_dim1];
  719. /* L10: */
  720. }
  721. } else {
  722. h__[j + j * h_dim1] = -h__[j + j * h_dim1];
  723. t[j + j * t_dim1] = -t[j + j * t_dim1];
  724. }
  725. if (ilz) {
  726. i__2 = *n;
  727. for (jr = 1; jr <= i__2; ++jr) {
  728. z__[jr + j * z_dim1] = -z__[jr + j * z_dim1];
  729. /* L20: */
  730. }
  731. }
  732. }
  733. alphar[j] = h__[j + j * h_dim1];
  734. alphai[j] = 0.f;
  735. beta[j] = t[j + j * t_dim1];
  736. /* L30: */
  737. }
  738. /* If IHI < ILO, skip QZ steps */
  739. if (*ihi < *ilo) {
  740. goto L380;
  741. }
  742. /* MAIN QZ ITERATION LOOP */
  743. /* Initialize dynamic indices */
  744. /* Eigenvalues ILAST+1:N have been found. */
  745. /* Column operations modify rows IFRSTM:whatever. */
  746. /* Row operations modify columns whatever:ILASTM. */
  747. /* If only eigenvalues are being computed, then */
  748. /* IFRSTM is the row of the last splitting row above row ILAST; */
  749. /* this is always at least ILO. */
  750. /* IITER counts iterations since the last eigenvalue was found, */
  751. /* to tell when to use an extraordinary shift. */
  752. /* MAXIT is the maximum number of QZ sweeps allowed. */
  753. ilast = *ihi;
  754. if (ilschr) {
  755. ifrstm = 1;
  756. ilastm = *n;
  757. } else {
  758. ifrstm = *ilo;
  759. ilastm = *ihi;
  760. }
  761. iiter = 0;
  762. eshift = 0.f;
  763. maxit = (*ihi - *ilo + 1) * 30;
  764. i__1 = maxit;
  765. for (jiter = 1; jiter <= i__1; ++jiter) {
  766. /* Split the matrix if possible. */
  767. /* Two tests: */
  768. /* 1: H(j,j-1)=0 or j=ILO */
  769. /* 2: T(j,j)=0 */
  770. if (ilast == *ilo) {
  771. /* Special case: j=ILAST */
  772. goto L80;
  773. } else {
  774. if ((r__1 = h__[ilast + (ilast - 1) * h_dim1], abs(r__1)) <= atol)
  775. {
  776. h__[ilast + (ilast - 1) * h_dim1] = 0.f;
  777. goto L80;
  778. }
  779. }
  780. if ((r__1 = t[ilast + ilast * t_dim1], abs(r__1)) <= btol) {
  781. t[ilast + ilast * t_dim1] = 0.f;
  782. goto L70;
  783. }
  784. /* General case: j<ILAST */
  785. i__2 = *ilo;
  786. for (j = ilast - 1; j >= i__2; --j) {
  787. /* Test 1: for H(j,j-1)=0 or j=ILO */
  788. if (j == *ilo) {
  789. ilazro = TRUE_;
  790. } else {
  791. if ((r__1 = h__[j + (j - 1) * h_dim1], abs(r__1)) <= atol) {
  792. h__[j + (j - 1) * h_dim1] = 0.f;
  793. ilazro = TRUE_;
  794. } else {
  795. ilazro = FALSE_;
  796. }
  797. }
  798. /* Test 2: for T(j,j)=0 */
  799. if ((r__1 = t[j + j * t_dim1], abs(r__1)) < btol) {
  800. t[j + j * t_dim1] = 0.f;
  801. /* Test 1a: Check for 2 consecutive small subdiagonals in A */
  802. ilazr2 = FALSE_;
  803. if (! ilazro) {
  804. temp = (r__1 = h__[j + (j - 1) * h_dim1], abs(r__1));
  805. temp2 = (r__1 = h__[j + j * h_dim1], abs(r__1));
  806. tempr = f2cmax(temp,temp2);
  807. if (tempr < 1.f && tempr != 0.f) {
  808. temp /= tempr;
  809. temp2 /= tempr;
  810. }
  811. if (temp * (ascale * (r__1 = h__[j + 1 + j * h_dim1], abs(
  812. r__1))) <= temp2 * (ascale * atol)) {
  813. ilazr2 = TRUE_;
  814. }
  815. }
  816. /* If both tests pass (1 & 2), i.e., the leading diagonal */
  817. /* element of B in the block is zero, split a 1x1 block off */
  818. /* at the top. (I.e., at the J-th row/column) The leading */
  819. /* diagonal element of the remainder can also be zero, so */
  820. /* this may have to be done repeatedly. */
  821. if (ilazro || ilazr2) {
  822. i__3 = ilast - 1;
  823. for (jch = j; jch <= i__3; ++jch) {
  824. temp = h__[jch + jch * h_dim1];
  825. slartg_(&temp, &h__[jch + 1 + jch * h_dim1], &c__, &s,
  826. &h__[jch + jch * h_dim1]);
  827. h__[jch + 1 + jch * h_dim1] = 0.f;
  828. i__4 = ilastm - jch;
  829. srot_(&i__4, &h__[jch + (jch + 1) * h_dim1], ldh, &
  830. h__[jch + 1 + (jch + 1) * h_dim1], ldh, &c__,
  831. &s);
  832. i__4 = ilastm - jch;
  833. srot_(&i__4, &t[jch + (jch + 1) * t_dim1], ldt, &t[
  834. jch + 1 + (jch + 1) * t_dim1], ldt, &c__, &s);
  835. if (ilq) {
  836. srot_(n, &q[jch * q_dim1 + 1], &c__1, &q[(jch + 1)
  837. * q_dim1 + 1], &c__1, &c__, &s);
  838. }
  839. if (ilazr2) {
  840. h__[jch + (jch - 1) * h_dim1] *= c__;
  841. }
  842. ilazr2 = FALSE_;
  843. if ((r__1 = t[jch + 1 + (jch + 1) * t_dim1], abs(r__1)
  844. ) >= btol) {
  845. if (jch + 1 >= ilast) {
  846. goto L80;
  847. } else {
  848. ifirst = jch + 1;
  849. goto L110;
  850. }
  851. }
  852. t[jch + 1 + (jch + 1) * t_dim1] = 0.f;
  853. /* L40: */
  854. }
  855. goto L70;
  856. } else {
  857. /* Only test 2 passed -- chase the zero to T(ILAST,ILAST) */
  858. /* Then process as in the case T(ILAST,ILAST)=0 */
  859. i__3 = ilast - 1;
  860. for (jch = j; jch <= i__3; ++jch) {
  861. temp = t[jch + (jch + 1) * t_dim1];
  862. slartg_(&temp, &t[jch + 1 + (jch + 1) * t_dim1], &c__,
  863. &s, &t[jch + (jch + 1) * t_dim1]);
  864. t[jch + 1 + (jch + 1) * t_dim1] = 0.f;
  865. if (jch < ilastm - 1) {
  866. i__4 = ilastm - jch - 1;
  867. srot_(&i__4, &t[jch + (jch + 2) * t_dim1], ldt, &
  868. t[jch + 1 + (jch + 2) * t_dim1], ldt, &
  869. c__, &s);
  870. }
  871. i__4 = ilastm - jch + 2;
  872. srot_(&i__4, &h__[jch + (jch - 1) * h_dim1], ldh, &
  873. h__[jch + 1 + (jch - 1) * h_dim1], ldh, &c__,
  874. &s);
  875. if (ilq) {
  876. srot_(n, &q[jch * q_dim1 + 1], &c__1, &q[(jch + 1)
  877. * q_dim1 + 1], &c__1, &c__, &s);
  878. }
  879. temp = h__[jch + 1 + jch * h_dim1];
  880. slartg_(&temp, &h__[jch + 1 + (jch - 1) * h_dim1], &
  881. c__, &s, &h__[jch + 1 + jch * h_dim1]);
  882. h__[jch + 1 + (jch - 1) * h_dim1] = 0.f;
  883. i__4 = jch + 1 - ifrstm;
  884. srot_(&i__4, &h__[ifrstm + jch * h_dim1], &c__1, &h__[
  885. ifrstm + (jch - 1) * h_dim1], &c__1, &c__, &s)
  886. ;
  887. i__4 = jch - ifrstm;
  888. srot_(&i__4, &t[ifrstm + jch * t_dim1], &c__1, &t[
  889. ifrstm + (jch - 1) * t_dim1], &c__1, &c__, &s)
  890. ;
  891. if (ilz) {
  892. srot_(n, &z__[jch * z_dim1 + 1], &c__1, &z__[(jch
  893. - 1) * z_dim1 + 1], &c__1, &c__, &s);
  894. }
  895. /* L50: */
  896. }
  897. goto L70;
  898. }
  899. } else if (ilazro) {
  900. /* Only test 1 passed -- work on J:ILAST */
  901. ifirst = j;
  902. goto L110;
  903. }
  904. /* Neither test passed -- try next J */
  905. /* L60: */
  906. }
  907. /* (Drop-through is "impossible") */
  908. *info = *n + 1;
  909. goto L420;
  910. /* T(ILAST,ILAST)=0 -- clear H(ILAST,ILAST-1) to split off a */
  911. /* 1x1 block. */
  912. L70:
  913. temp = h__[ilast + ilast * h_dim1];
  914. slartg_(&temp, &h__[ilast + (ilast - 1) * h_dim1], &c__, &s, &h__[
  915. ilast + ilast * h_dim1]);
  916. h__[ilast + (ilast - 1) * h_dim1] = 0.f;
  917. i__2 = ilast - ifrstm;
  918. srot_(&i__2, &h__[ifrstm + ilast * h_dim1], &c__1, &h__[ifrstm + (
  919. ilast - 1) * h_dim1], &c__1, &c__, &s);
  920. i__2 = ilast - ifrstm;
  921. srot_(&i__2, &t[ifrstm + ilast * t_dim1], &c__1, &t[ifrstm + (ilast -
  922. 1) * t_dim1], &c__1, &c__, &s);
  923. if (ilz) {
  924. srot_(n, &z__[ilast * z_dim1 + 1], &c__1, &z__[(ilast - 1) *
  925. z_dim1 + 1], &c__1, &c__, &s);
  926. }
  927. /* H(ILAST,ILAST-1)=0 -- Standardize B, set ALPHAR, ALPHAI, */
  928. /* and BETA */
  929. L80:
  930. if (t[ilast + ilast * t_dim1] < 0.f) {
  931. if (ilschr) {
  932. i__2 = ilast;
  933. for (j = ifrstm; j <= i__2; ++j) {
  934. h__[j + ilast * h_dim1] = -h__[j + ilast * h_dim1];
  935. t[j + ilast * t_dim1] = -t[j + ilast * t_dim1];
  936. /* L90: */
  937. }
  938. } else {
  939. h__[ilast + ilast * h_dim1] = -h__[ilast + ilast * h_dim1];
  940. t[ilast + ilast * t_dim1] = -t[ilast + ilast * t_dim1];
  941. }
  942. if (ilz) {
  943. i__2 = *n;
  944. for (j = 1; j <= i__2; ++j) {
  945. z__[j + ilast * z_dim1] = -z__[j + ilast * z_dim1];
  946. /* L100: */
  947. }
  948. }
  949. }
  950. alphar[ilast] = h__[ilast + ilast * h_dim1];
  951. alphai[ilast] = 0.f;
  952. beta[ilast] = t[ilast + ilast * t_dim1];
  953. /* Go to next block -- exit if finished. */
  954. --ilast;
  955. if (ilast < *ilo) {
  956. goto L380;
  957. }
  958. /* Reset counters */
  959. iiter = 0;
  960. eshift = 0.f;
  961. if (! ilschr) {
  962. ilastm = ilast;
  963. if (ifrstm > ilast) {
  964. ifrstm = *ilo;
  965. }
  966. }
  967. goto L350;
  968. /* QZ step */
  969. /* This iteration only involves rows/columns IFIRST:ILAST. We */
  970. /* assume IFIRST < ILAST, and that the diagonal of B is non-zero. */
  971. L110:
  972. ++iiter;
  973. if (! ilschr) {
  974. ifrstm = ifirst;
  975. }
  976. /* Compute single shifts. */
  977. /* At this point, IFIRST < ILAST, and the diagonal elements of */
  978. /* T(IFIRST:ILAST,IFIRST,ILAST) are larger than BTOL (in */
  979. /* magnitude) */
  980. if (iiter / 10 * 10 == iiter) {
  981. /* Exceptional shift. Chosen for no particularly good reason. */
  982. /* (Single shift only.) */
  983. if ((real) maxit * safmin * (r__1 = h__[ilast + (ilast - 1) *
  984. h_dim1], abs(r__1)) < (r__2 = t[ilast - 1 + (ilast - 1) *
  985. t_dim1], abs(r__2))) {
  986. eshift = h__[ilast + (ilast - 1) * h_dim1] / t[ilast - 1 + (
  987. ilast - 1) * t_dim1];
  988. } else {
  989. eshift += 1.f / (safmin * (real) maxit);
  990. }
  991. s1 = 1.f;
  992. wr = eshift;
  993. } else {
  994. /* Shifts based on the generalized eigenvalues of the */
  995. /* bottom-right 2x2 block of A and B. The first eigenvalue */
  996. /* returned by SLAG2 is the Wilkinson shift (AEP p.512), */
  997. r__1 = safmin * 100.f;
  998. slag2_(&h__[ilast - 1 + (ilast - 1) * h_dim1], ldh, &t[ilast - 1
  999. + (ilast - 1) * t_dim1], ldt, &r__1, &s1, &s2, &wr, &wr2,
  1000. &wi);
  1001. if ((r__1 = wr / s1 * t[ilast + ilast * t_dim1] - h__[ilast +
  1002. ilast * h_dim1], abs(r__1)) > (r__2 = wr2 / s2 * t[ilast
  1003. + ilast * t_dim1] - h__[ilast + ilast * h_dim1], abs(r__2)
  1004. )) {
  1005. temp = wr;
  1006. wr = wr2;
  1007. wr2 = temp;
  1008. temp = s1;
  1009. s1 = s2;
  1010. s2 = temp;
  1011. }
  1012. /* Computing MAX */
  1013. /* Computing MAX */
  1014. r__3 = 1.f, r__4 = abs(wr), r__3 = f2cmax(r__3,r__4), r__4 = abs(wi);
  1015. r__1 = s1, r__2 = safmin * f2cmax(r__3,r__4);
  1016. temp = f2cmax(r__1,r__2);
  1017. if (wi != 0.f) {
  1018. goto L200;
  1019. }
  1020. }
  1021. /* Fiddle with shift to avoid overflow */
  1022. temp = f2cmin(ascale,1.f) * (safmax * .5f);
  1023. if (s1 > temp) {
  1024. scale = temp / s1;
  1025. } else {
  1026. scale = 1.f;
  1027. }
  1028. temp = f2cmin(bscale,1.f) * (safmax * .5f);
  1029. if (abs(wr) > temp) {
  1030. /* Computing MIN */
  1031. r__1 = scale, r__2 = temp / abs(wr);
  1032. scale = f2cmin(r__1,r__2);
  1033. }
  1034. s1 = scale * s1;
  1035. wr = scale * wr;
  1036. /* Now check for two consecutive small subdiagonals. */
  1037. i__2 = ifirst + 1;
  1038. for (j = ilast - 1; j >= i__2; --j) {
  1039. istart = j;
  1040. temp = (r__1 = s1 * h__[j + (j - 1) * h_dim1], abs(r__1));
  1041. temp2 = (r__1 = s1 * h__[j + j * h_dim1] - wr * t[j + j * t_dim1],
  1042. abs(r__1));
  1043. tempr = f2cmax(temp,temp2);
  1044. if (tempr < 1.f && tempr != 0.f) {
  1045. temp /= tempr;
  1046. temp2 /= tempr;
  1047. }
  1048. if ((r__1 = ascale * h__[j + 1 + j * h_dim1] * temp, abs(r__1)) <=
  1049. ascale * atol * temp2) {
  1050. goto L130;
  1051. }
  1052. /* L120: */
  1053. }
  1054. istart = ifirst;
  1055. L130:
  1056. /* Do an implicit single-shift QZ sweep. */
  1057. /* Initial Q */
  1058. temp = s1 * h__[istart + istart * h_dim1] - wr * t[istart + istart *
  1059. t_dim1];
  1060. temp2 = s1 * h__[istart + 1 + istart * h_dim1];
  1061. slartg_(&temp, &temp2, &c__, &s, &tempr);
  1062. /* Sweep */
  1063. i__2 = ilast - 1;
  1064. for (j = istart; j <= i__2; ++j) {
  1065. if (j > istart) {
  1066. temp = h__[j + (j - 1) * h_dim1];
  1067. slartg_(&temp, &h__[j + 1 + (j - 1) * h_dim1], &c__, &s, &h__[
  1068. j + (j - 1) * h_dim1]);
  1069. h__[j + 1 + (j - 1) * h_dim1] = 0.f;
  1070. }
  1071. i__3 = ilastm;
  1072. for (jc = j; jc <= i__3; ++jc) {
  1073. temp = c__ * h__[j + jc * h_dim1] + s * h__[j + 1 + jc *
  1074. h_dim1];
  1075. h__[j + 1 + jc * h_dim1] = -s * h__[j + jc * h_dim1] + c__ *
  1076. h__[j + 1 + jc * h_dim1];
  1077. h__[j + jc * h_dim1] = temp;
  1078. temp2 = c__ * t[j + jc * t_dim1] + s * t[j + 1 + jc * t_dim1];
  1079. t[j + 1 + jc * t_dim1] = -s * t[j + jc * t_dim1] + c__ * t[j
  1080. + 1 + jc * t_dim1];
  1081. t[j + jc * t_dim1] = temp2;
  1082. /* L140: */
  1083. }
  1084. if (ilq) {
  1085. i__3 = *n;
  1086. for (jr = 1; jr <= i__3; ++jr) {
  1087. temp = c__ * q[jr + j * q_dim1] + s * q[jr + (j + 1) *
  1088. q_dim1];
  1089. q[jr + (j + 1) * q_dim1] = -s * q[jr + j * q_dim1] + c__ *
  1090. q[jr + (j + 1) * q_dim1];
  1091. q[jr + j * q_dim1] = temp;
  1092. /* L150: */
  1093. }
  1094. }
  1095. temp = t[j + 1 + (j + 1) * t_dim1];
  1096. slartg_(&temp, &t[j + 1 + j * t_dim1], &c__, &s, &t[j + 1 + (j +
  1097. 1) * t_dim1]);
  1098. t[j + 1 + j * t_dim1] = 0.f;
  1099. /* Computing MIN */
  1100. i__4 = j + 2;
  1101. i__3 = f2cmin(i__4,ilast);
  1102. for (jr = ifrstm; jr <= i__3; ++jr) {
  1103. temp = c__ * h__[jr + (j + 1) * h_dim1] + s * h__[jr + j *
  1104. h_dim1];
  1105. h__[jr + j * h_dim1] = -s * h__[jr + (j + 1) * h_dim1] + c__ *
  1106. h__[jr + j * h_dim1];
  1107. h__[jr + (j + 1) * h_dim1] = temp;
  1108. /* L160: */
  1109. }
  1110. i__3 = j;
  1111. for (jr = ifrstm; jr <= i__3; ++jr) {
  1112. temp = c__ * t[jr + (j + 1) * t_dim1] + s * t[jr + j * t_dim1]
  1113. ;
  1114. t[jr + j * t_dim1] = -s * t[jr + (j + 1) * t_dim1] + c__ * t[
  1115. jr + j * t_dim1];
  1116. t[jr + (j + 1) * t_dim1] = temp;
  1117. /* L170: */
  1118. }
  1119. if (ilz) {
  1120. i__3 = *n;
  1121. for (jr = 1; jr <= i__3; ++jr) {
  1122. temp = c__ * z__[jr + (j + 1) * z_dim1] + s * z__[jr + j *
  1123. z_dim1];
  1124. z__[jr + j * z_dim1] = -s * z__[jr + (j + 1) * z_dim1] +
  1125. c__ * z__[jr + j * z_dim1];
  1126. z__[jr + (j + 1) * z_dim1] = temp;
  1127. /* L180: */
  1128. }
  1129. }
  1130. /* L190: */
  1131. }
  1132. goto L350;
  1133. /* Use Francis double-shift */
  1134. /* Note: the Francis double-shift should work with real shifts, */
  1135. /* but only if the block is at least 3x3. */
  1136. /* This code may break if this point is reached with */
  1137. /* a 2x2 block with real eigenvalues. */
  1138. L200:
  1139. if (ifirst + 1 == ilast) {
  1140. /* Special case -- 2x2 block with complex eigenvectors */
  1141. /* Step 1: Standardize, that is, rotate so that */
  1142. /* ( B11 0 ) */
  1143. /* B = ( ) with B11 non-negative. */
  1144. /* ( 0 B22 ) */
  1145. slasv2_(&t[ilast - 1 + (ilast - 1) * t_dim1], &t[ilast - 1 +
  1146. ilast * t_dim1], &t[ilast + ilast * t_dim1], &b22, &b11, &
  1147. sr, &cr, &sl, &cl);
  1148. if (b11 < 0.f) {
  1149. cr = -cr;
  1150. sr = -sr;
  1151. b11 = -b11;
  1152. b22 = -b22;
  1153. }
  1154. i__2 = ilastm + 1 - ifirst;
  1155. srot_(&i__2, &h__[ilast - 1 + (ilast - 1) * h_dim1], ldh, &h__[
  1156. ilast + (ilast - 1) * h_dim1], ldh, &cl, &sl);
  1157. i__2 = ilast + 1 - ifrstm;
  1158. srot_(&i__2, &h__[ifrstm + (ilast - 1) * h_dim1], &c__1, &h__[
  1159. ifrstm + ilast * h_dim1], &c__1, &cr, &sr);
  1160. if (ilast < ilastm) {
  1161. i__2 = ilastm - ilast;
  1162. srot_(&i__2, &t[ilast - 1 + (ilast + 1) * t_dim1], ldt, &t[
  1163. ilast + (ilast + 1) * t_dim1], ldt, &cl, &sl);
  1164. }
  1165. if (ifrstm < ilast - 1) {
  1166. i__2 = ifirst - ifrstm;
  1167. srot_(&i__2, &t[ifrstm + (ilast - 1) * t_dim1], &c__1, &t[
  1168. ifrstm + ilast * t_dim1], &c__1, &cr, &sr);
  1169. }
  1170. if (ilq) {
  1171. srot_(n, &q[(ilast - 1) * q_dim1 + 1], &c__1, &q[ilast *
  1172. q_dim1 + 1], &c__1, &cl, &sl);
  1173. }
  1174. if (ilz) {
  1175. srot_(n, &z__[(ilast - 1) * z_dim1 + 1], &c__1, &z__[ilast *
  1176. z_dim1 + 1], &c__1, &cr, &sr);
  1177. }
  1178. t[ilast - 1 + (ilast - 1) * t_dim1] = b11;
  1179. t[ilast - 1 + ilast * t_dim1] = 0.f;
  1180. t[ilast + (ilast - 1) * t_dim1] = 0.f;
  1181. t[ilast + ilast * t_dim1] = b22;
  1182. /* If B22 is negative, negate column ILAST */
  1183. if (b22 < 0.f) {
  1184. i__2 = ilast;
  1185. for (j = ifrstm; j <= i__2; ++j) {
  1186. h__[j + ilast * h_dim1] = -h__[j + ilast * h_dim1];
  1187. t[j + ilast * t_dim1] = -t[j + ilast * t_dim1];
  1188. /* L210: */
  1189. }
  1190. if (ilz) {
  1191. i__2 = *n;
  1192. for (j = 1; j <= i__2; ++j) {
  1193. z__[j + ilast * z_dim1] = -z__[j + ilast * z_dim1];
  1194. /* L220: */
  1195. }
  1196. }
  1197. b22 = -b22;
  1198. }
  1199. /* Step 2: Compute ALPHAR, ALPHAI, and BETA (see refs.) */
  1200. /* Recompute shift */
  1201. r__1 = safmin * 100.f;
  1202. slag2_(&h__[ilast - 1 + (ilast - 1) * h_dim1], ldh, &t[ilast - 1
  1203. + (ilast - 1) * t_dim1], ldt, &r__1, &s1, &temp, &wr, &
  1204. temp2, &wi);
  1205. /* If standardization has perturbed the shift onto real line, */
  1206. /* do another (real single-shift) QR step. */
  1207. if (wi == 0.f) {
  1208. goto L350;
  1209. }
  1210. s1inv = 1.f / s1;
  1211. /* Do EISPACK (QZVAL) computation of alpha and beta */
  1212. a11 = h__[ilast - 1 + (ilast - 1) * h_dim1];
  1213. a21 = h__[ilast + (ilast - 1) * h_dim1];
  1214. a12 = h__[ilast - 1 + ilast * h_dim1];
  1215. a22 = h__[ilast + ilast * h_dim1];
  1216. /* Compute complex Givens rotation on right */
  1217. /* (Assume some element of C = (sA - wB) > unfl ) */
  1218. /* __ */
  1219. /* (sA - wB) ( CZ -SZ ) */
  1220. /* ( SZ CZ ) */
  1221. c11r = s1 * a11 - wr * b11;
  1222. c11i = -wi * b11;
  1223. c12 = s1 * a12;
  1224. c21 = s1 * a21;
  1225. c22r = s1 * a22 - wr * b22;
  1226. c22i = -wi * b22;
  1227. if (abs(c11r) + abs(c11i) + abs(c12) > abs(c21) + abs(c22r) + abs(
  1228. c22i)) {
  1229. t1 = slapy3_(&c12, &c11r, &c11i);
  1230. cz = c12 / t1;
  1231. szr = -c11r / t1;
  1232. szi = -c11i / t1;
  1233. } else {
  1234. cz = slapy2_(&c22r, &c22i);
  1235. if (cz <= safmin) {
  1236. cz = 0.f;
  1237. szr = 1.f;
  1238. szi = 0.f;
  1239. } else {
  1240. tempr = c22r / cz;
  1241. tempi = c22i / cz;
  1242. t1 = slapy2_(&cz, &c21);
  1243. cz /= t1;
  1244. szr = -c21 * tempr / t1;
  1245. szi = c21 * tempi / t1;
  1246. }
  1247. }
  1248. /* Compute Givens rotation on left */
  1249. /* ( CQ SQ ) */
  1250. /* ( __ ) A or B */
  1251. /* ( -SQ CQ ) */
  1252. an = abs(a11) + abs(a12) + abs(a21) + abs(a22);
  1253. bn = abs(b11) + abs(b22);
  1254. wabs = abs(wr) + abs(wi);
  1255. if (s1 * an > wabs * bn) {
  1256. cq = cz * b11;
  1257. sqr = szr * b22;
  1258. sqi = -szi * b22;
  1259. } else {
  1260. a1r = cz * a11 + szr * a12;
  1261. a1i = szi * a12;
  1262. a2r = cz * a21 + szr * a22;
  1263. a2i = szi * a22;
  1264. cq = slapy2_(&a1r, &a1i);
  1265. if (cq <= safmin) {
  1266. cq = 0.f;
  1267. sqr = 1.f;
  1268. sqi = 0.f;
  1269. } else {
  1270. tempr = a1r / cq;
  1271. tempi = a1i / cq;
  1272. sqr = tempr * a2r + tempi * a2i;
  1273. sqi = tempi * a2r - tempr * a2i;
  1274. }
  1275. }
  1276. t1 = slapy3_(&cq, &sqr, &sqi);
  1277. cq /= t1;
  1278. sqr /= t1;
  1279. sqi /= t1;
  1280. /* Compute diagonal elements of QBZ */
  1281. tempr = sqr * szr - sqi * szi;
  1282. tempi = sqr * szi + sqi * szr;
  1283. b1r = cq * cz * b11 + tempr * b22;
  1284. b1i = tempi * b22;
  1285. b1a = slapy2_(&b1r, &b1i);
  1286. b2r = cq * cz * b22 + tempr * b11;
  1287. b2i = -tempi * b11;
  1288. b2a = slapy2_(&b2r, &b2i);
  1289. /* Normalize so beta > 0, and Im( alpha1 ) > 0 */
  1290. beta[ilast - 1] = b1a;
  1291. beta[ilast] = b2a;
  1292. alphar[ilast - 1] = wr * b1a * s1inv;
  1293. alphai[ilast - 1] = wi * b1a * s1inv;
  1294. alphar[ilast] = wr * b2a * s1inv;
  1295. alphai[ilast] = -(wi * b2a) * s1inv;
  1296. /* Step 3: Go to next block -- exit if finished. */
  1297. ilast = ifirst - 1;
  1298. if (ilast < *ilo) {
  1299. goto L380;
  1300. }
  1301. /* Reset counters */
  1302. iiter = 0;
  1303. eshift = 0.f;
  1304. if (! ilschr) {
  1305. ilastm = ilast;
  1306. if (ifrstm > ilast) {
  1307. ifrstm = *ilo;
  1308. }
  1309. }
  1310. goto L350;
  1311. } else {
  1312. /* Usual case: 3x3 or larger block, using Francis implicit */
  1313. /* double-shift */
  1314. /* 2 */
  1315. /* Eigenvalue equation is w - c w + d = 0, */
  1316. /* -1 2 -1 */
  1317. /* so compute 1st column of (A B ) - c A B + d */
  1318. /* using the formula in QZIT (from EISPACK) */
  1319. /* We assume that the block is at least 3x3 */
  1320. ad11 = ascale * h__[ilast - 1 + (ilast - 1) * h_dim1] / (bscale *
  1321. t[ilast - 1 + (ilast - 1) * t_dim1]);
  1322. ad21 = ascale * h__[ilast + (ilast - 1) * h_dim1] / (bscale * t[
  1323. ilast - 1 + (ilast - 1) * t_dim1]);
  1324. ad12 = ascale * h__[ilast - 1 + ilast * h_dim1] / (bscale * t[
  1325. ilast + ilast * t_dim1]);
  1326. ad22 = ascale * h__[ilast + ilast * h_dim1] / (bscale * t[ilast +
  1327. ilast * t_dim1]);
  1328. u12 = t[ilast - 1 + ilast * t_dim1] / t[ilast + ilast * t_dim1];
  1329. ad11l = ascale * h__[ifirst + ifirst * h_dim1] / (bscale * t[
  1330. ifirst + ifirst * t_dim1]);
  1331. ad21l = ascale * h__[ifirst + 1 + ifirst * h_dim1] / (bscale * t[
  1332. ifirst + ifirst * t_dim1]);
  1333. ad12l = ascale * h__[ifirst + (ifirst + 1) * h_dim1] / (bscale *
  1334. t[ifirst + 1 + (ifirst + 1) * t_dim1]);
  1335. ad22l = ascale * h__[ifirst + 1 + (ifirst + 1) * h_dim1] / (
  1336. bscale * t[ifirst + 1 + (ifirst + 1) * t_dim1]);
  1337. ad32l = ascale * h__[ifirst + 2 + (ifirst + 1) * h_dim1] / (
  1338. bscale * t[ifirst + 1 + (ifirst + 1) * t_dim1]);
  1339. u12l = t[ifirst + (ifirst + 1) * t_dim1] / t[ifirst + 1 + (ifirst
  1340. + 1) * t_dim1];
  1341. v[0] = (ad11 - ad11l) * (ad22 - ad11l) - ad12 * ad21 + ad21 * u12
  1342. * ad11l + (ad12l - ad11l * u12l) * ad21l;
  1343. v[1] = (ad22l - ad11l - ad21l * u12l - (ad11 - ad11l) - (ad22 -
  1344. ad11l) + ad21 * u12) * ad21l;
  1345. v[2] = ad32l * ad21l;
  1346. istart = ifirst;
  1347. slarfg_(&c__3, v, &v[1], &c__1, &tau);
  1348. v[0] = 1.f;
  1349. /* Sweep */
  1350. i__2 = ilast - 2;
  1351. for (j = istart; j <= i__2; ++j) {
  1352. /* All but last elements: use 3x3 Householder transforms. */
  1353. /* Zero (j-1)st column of A */
  1354. if (j > istart) {
  1355. v[0] = h__[j + (j - 1) * h_dim1];
  1356. v[1] = h__[j + 1 + (j - 1) * h_dim1];
  1357. v[2] = h__[j + 2 + (j - 1) * h_dim1];
  1358. slarfg_(&c__3, &h__[j + (j - 1) * h_dim1], &v[1], &c__1, &
  1359. tau);
  1360. v[0] = 1.f;
  1361. h__[j + 1 + (j - 1) * h_dim1] = 0.f;
  1362. h__[j + 2 + (j - 1) * h_dim1] = 0.f;
  1363. }
  1364. i__3 = ilastm;
  1365. for (jc = j; jc <= i__3; ++jc) {
  1366. temp = tau * (h__[j + jc * h_dim1] + v[1] * h__[j + 1 +
  1367. jc * h_dim1] + v[2] * h__[j + 2 + jc * h_dim1]);
  1368. h__[j + jc * h_dim1] -= temp;
  1369. h__[j + 1 + jc * h_dim1] -= temp * v[1];
  1370. h__[j + 2 + jc * h_dim1] -= temp * v[2];
  1371. temp2 = tau * (t[j + jc * t_dim1] + v[1] * t[j + 1 + jc *
  1372. t_dim1] + v[2] * t[j + 2 + jc * t_dim1]);
  1373. t[j + jc * t_dim1] -= temp2;
  1374. t[j + 1 + jc * t_dim1] -= temp2 * v[1];
  1375. t[j + 2 + jc * t_dim1] -= temp2 * v[2];
  1376. /* L230: */
  1377. }
  1378. if (ilq) {
  1379. i__3 = *n;
  1380. for (jr = 1; jr <= i__3; ++jr) {
  1381. temp = tau * (q[jr + j * q_dim1] + v[1] * q[jr + (j +
  1382. 1) * q_dim1] + v[2] * q[jr + (j + 2) * q_dim1]
  1383. );
  1384. q[jr + j * q_dim1] -= temp;
  1385. q[jr + (j + 1) * q_dim1] -= temp * v[1];
  1386. q[jr + (j + 2) * q_dim1] -= temp * v[2];
  1387. /* L240: */
  1388. }
  1389. }
  1390. /* Zero j-th column of B (see SLAGBC for details) */
  1391. /* Swap rows to pivot */
  1392. ilpivt = FALSE_;
  1393. /* Computing MAX */
  1394. r__3 = (r__1 = t[j + 1 + (j + 1) * t_dim1], abs(r__1)), r__4 =
  1395. (r__2 = t[j + 1 + (j + 2) * t_dim1], abs(r__2));
  1396. temp = f2cmax(r__3,r__4);
  1397. /* Computing MAX */
  1398. r__3 = (r__1 = t[j + 2 + (j + 1) * t_dim1], abs(r__1)), r__4 =
  1399. (r__2 = t[j + 2 + (j + 2) * t_dim1], abs(r__2));
  1400. temp2 = f2cmax(r__3,r__4);
  1401. if (f2cmax(temp,temp2) < safmin) {
  1402. scale = 0.f;
  1403. u1 = 1.f;
  1404. u2 = 0.f;
  1405. goto L250;
  1406. } else if (temp >= temp2) {
  1407. w11 = t[j + 1 + (j + 1) * t_dim1];
  1408. w21 = t[j + 2 + (j + 1) * t_dim1];
  1409. w12 = t[j + 1 + (j + 2) * t_dim1];
  1410. w22 = t[j + 2 + (j + 2) * t_dim1];
  1411. u1 = t[j + 1 + j * t_dim1];
  1412. u2 = t[j + 2 + j * t_dim1];
  1413. } else {
  1414. w21 = t[j + 1 + (j + 1) * t_dim1];
  1415. w11 = t[j + 2 + (j + 1) * t_dim1];
  1416. w22 = t[j + 1 + (j + 2) * t_dim1];
  1417. w12 = t[j + 2 + (j + 2) * t_dim1];
  1418. u2 = t[j + 1 + j * t_dim1];
  1419. u1 = t[j + 2 + j * t_dim1];
  1420. }
  1421. /* Swap columns if nec. */
  1422. if (abs(w12) > abs(w11)) {
  1423. ilpivt = TRUE_;
  1424. temp = w12;
  1425. temp2 = w22;
  1426. w12 = w11;
  1427. w22 = w21;
  1428. w11 = temp;
  1429. w21 = temp2;
  1430. }
  1431. /* LU-factor */
  1432. temp = w21 / w11;
  1433. u2 -= temp * u1;
  1434. w22 -= temp * w12;
  1435. w21 = 0.f;
  1436. /* Compute SCALE */
  1437. scale = 1.f;
  1438. if (abs(w22) < safmin) {
  1439. scale = 0.f;
  1440. u2 = 1.f;
  1441. u1 = -w12 / w11;
  1442. goto L250;
  1443. }
  1444. if (abs(w22) < abs(u2)) {
  1445. scale = (r__1 = w22 / u2, abs(r__1));
  1446. }
  1447. if (abs(w11) < abs(u1)) {
  1448. /* Computing MIN */
  1449. r__2 = scale, r__3 = (r__1 = w11 / u1, abs(r__1));
  1450. scale = f2cmin(r__2,r__3);
  1451. }
  1452. /* Solve */
  1453. u2 = scale * u2 / w22;
  1454. u1 = (scale * u1 - w12 * u2) / w11;
  1455. L250:
  1456. if (ilpivt) {
  1457. temp = u2;
  1458. u2 = u1;
  1459. u1 = temp;
  1460. }
  1461. /* Compute Householder Vector */
  1462. /* Computing 2nd power */
  1463. r__1 = scale;
  1464. /* Computing 2nd power */
  1465. r__2 = u1;
  1466. /* Computing 2nd power */
  1467. r__3 = u2;
  1468. t1 = sqrt(r__1 * r__1 + r__2 * r__2 + r__3 * r__3);
  1469. tau = scale / t1 + 1.f;
  1470. vs = -1.f / (scale + t1);
  1471. v[0] = 1.f;
  1472. v[1] = vs * u1;
  1473. v[2] = vs * u2;
  1474. /* Apply transformations from the right. */
  1475. /* Computing MIN */
  1476. i__4 = j + 3;
  1477. i__3 = f2cmin(i__4,ilast);
  1478. for (jr = ifrstm; jr <= i__3; ++jr) {
  1479. temp = tau * (h__[jr + j * h_dim1] + v[1] * h__[jr + (j +
  1480. 1) * h_dim1] + v[2] * h__[jr + (j + 2) * h_dim1]);
  1481. h__[jr + j * h_dim1] -= temp;
  1482. h__[jr + (j + 1) * h_dim1] -= temp * v[1];
  1483. h__[jr + (j + 2) * h_dim1] -= temp * v[2];
  1484. /* L260: */
  1485. }
  1486. i__3 = j + 2;
  1487. for (jr = ifrstm; jr <= i__3; ++jr) {
  1488. temp = tau * (t[jr + j * t_dim1] + v[1] * t[jr + (j + 1) *
  1489. t_dim1] + v[2] * t[jr + (j + 2) * t_dim1]);
  1490. t[jr + j * t_dim1] -= temp;
  1491. t[jr + (j + 1) * t_dim1] -= temp * v[1];
  1492. t[jr + (j + 2) * t_dim1] -= temp * v[2];
  1493. /* L270: */
  1494. }
  1495. if (ilz) {
  1496. i__3 = *n;
  1497. for (jr = 1; jr <= i__3; ++jr) {
  1498. temp = tau * (z__[jr + j * z_dim1] + v[1] * z__[jr + (
  1499. j + 1) * z_dim1] + v[2] * z__[jr + (j + 2) *
  1500. z_dim1]);
  1501. z__[jr + j * z_dim1] -= temp;
  1502. z__[jr + (j + 1) * z_dim1] -= temp * v[1];
  1503. z__[jr + (j + 2) * z_dim1] -= temp * v[2];
  1504. /* L280: */
  1505. }
  1506. }
  1507. t[j + 1 + j * t_dim1] = 0.f;
  1508. t[j + 2 + j * t_dim1] = 0.f;
  1509. /* L290: */
  1510. }
  1511. /* Last elements: Use Givens rotations */
  1512. /* Rotations from the left */
  1513. j = ilast - 1;
  1514. temp = h__[j + (j - 1) * h_dim1];
  1515. slartg_(&temp, &h__[j + 1 + (j - 1) * h_dim1], &c__, &s, &h__[j +
  1516. (j - 1) * h_dim1]);
  1517. h__[j + 1 + (j - 1) * h_dim1] = 0.f;
  1518. i__2 = ilastm;
  1519. for (jc = j; jc <= i__2; ++jc) {
  1520. temp = c__ * h__[j + jc * h_dim1] + s * h__[j + 1 + jc *
  1521. h_dim1];
  1522. h__[j + 1 + jc * h_dim1] = -s * h__[j + jc * h_dim1] + c__ *
  1523. h__[j + 1 + jc * h_dim1];
  1524. h__[j + jc * h_dim1] = temp;
  1525. temp2 = c__ * t[j + jc * t_dim1] + s * t[j + 1 + jc * t_dim1];
  1526. t[j + 1 + jc * t_dim1] = -s * t[j + jc * t_dim1] + c__ * t[j
  1527. + 1 + jc * t_dim1];
  1528. t[j + jc * t_dim1] = temp2;
  1529. /* L300: */
  1530. }
  1531. if (ilq) {
  1532. i__2 = *n;
  1533. for (jr = 1; jr <= i__2; ++jr) {
  1534. temp = c__ * q[jr + j * q_dim1] + s * q[jr + (j + 1) *
  1535. q_dim1];
  1536. q[jr + (j + 1) * q_dim1] = -s * q[jr + j * q_dim1] + c__ *
  1537. q[jr + (j + 1) * q_dim1];
  1538. q[jr + j * q_dim1] = temp;
  1539. /* L310: */
  1540. }
  1541. }
  1542. /* Rotations from the right. */
  1543. temp = t[j + 1 + (j + 1) * t_dim1];
  1544. slartg_(&temp, &t[j + 1 + j * t_dim1], &c__, &s, &t[j + 1 + (j +
  1545. 1) * t_dim1]);
  1546. t[j + 1 + j * t_dim1] = 0.f;
  1547. i__2 = ilast;
  1548. for (jr = ifrstm; jr <= i__2; ++jr) {
  1549. temp = c__ * h__[jr + (j + 1) * h_dim1] + s * h__[jr + j *
  1550. h_dim1];
  1551. h__[jr + j * h_dim1] = -s * h__[jr + (j + 1) * h_dim1] + c__ *
  1552. h__[jr + j * h_dim1];
  1553. h__[jr + (j + 1) * h_dim1] = temp;
  1554. /* L320: */
  1555. }
  1556. i__2 = ilast - 1;
  1557. for (jr = ifrstm; jr <= i__2; ++jr) {
  1558. temp = c__ * t[jr + (j + 1) * t_dim1] + s * t[jr + j * t_dim1]
  1559. ;
  1560. t[jr + j * t_dim1] = -s * t[jr + (j + 1) * t_dim1] + c__ * t[
  1561. jr + j * t_dim1];
  1562. t[jr + (j + 1) * t_dim1] = temp;
  1563. /* L330: */
  1564. }
  1565. if (ilz) {
  1566. i__2 = *n;
  1567. for (jr = 1; jr <= i__2; ++jr) {
  1568. temp = c__ * z__[jr + (j + 1) * z_dim1] + s * z__[jr + j *
  1569. z_dim1];
  1570. z__[jr + j * z_dim1] = -s * z__[jr + (j + 1) * z_dim1] +
  1571. c__ * z__[jr + j * z_dim1];
  1572. z__[jr + (j + 1) * z_dim1] = temp;
  1573. /* L340: */
  1574. }
  1575. }
  1576. /* End of Double-Shift code */
  1577. }
  1578. goto L350;
  1579. /* End of iteration loop */
  1580. L350:
  1581. /* L360: */
  1582. ;
  1583. }
  1584. /* Drop-through = non-convergence */
  1585. *info = ilast;
  1586. goto L420;
  1587. /* Successful completion of all QZ steps */
  1588. L380:
  1589. /* Set Eigenvalues 1:ILO-1 */
  1590. i__1 = *ilo - 1;
  1591. for (j = 1; j <= i__1; ++j) {
  1592. if (t[j + j * t_dim1] < 0.f) {
  1593. if (ilschr) {
  1594. i__2 = j;
  1595. for (jr = 1; jr <= i__2; ++jr) {
  1596. h__[jr + j * h_dim1] = -h__[jr + j * h_dim1];
  1597. t[jr + j * t_dim1] = -t[jr + j * t_dim1];
  1598. /* L390: */
  1599. }
  1600. } else {
  1601. h__[j + j * h_dim1] = -h__[j + j * h_dim1];
  1602. t[j + j * t_dim1] = -t[j + j * t_dim1];
  1603. }
  1604. if (ilz) {
  1605. i__2 = *n;
  1606. for (jr = 1; jr <= i__2; ++jr) {
  1607. z__[jr + j * z_dim1] = -z__[jr + j * z_dim1];
  1608. /* L400: */
  1609. }
  1610. }
  1611. }
  1612. alphar[j] = h__[j + j * h_dim1];
  1613. alphai[j] = 0.f;
  1614. beta[j] = t[j + j * t_dim1];
  1615. /* L410: */
  1616. }
  1617. /* Normal Termination */
  1618. *info = 0;
  1619. /* Exit (other than argument error) -- return optimal workspace size */
  1620. L420:
  1621. work[1] = (real) (*n);
  1622. return;
  1623. /* End of SHGEQZ */
  1624. } /* shgeqz_ */