dgegv.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843
  1. /* dgegv.f -- translated by f2c (version 20061008).
  2. You must link the resulting object file with libf2c:
  3. on Microsoft Windows system, link with libf2c.lib;
  4. on Linux or Unix systems, link with .../path/to/libf2c.a -lm
  5. or, if you install libf2c.a in a standard place, with -lf2c -lm
  6. -- in that order, at the end of the command line, as in
  7. cc *.o -lf2c -lm
  8. Source for libf2c is in /netlib/f2c/libf2c.zip, e.g.,
  9. http://www.netlib.org/f2c/libf2c.zip
  10. */
  11. #include "f2c.h"
  12. #include "blaswrap.h"
  13. /* Table of constant values */
  14. static integer c__1 = 1;
  15. static integer c_n1 = -1;
  16. static doublereal c_b27 = 1.;
  17. static doublereal c_b38 = 0.;
  18. /* Subroutine */ int dgegv_(char *jobvl, char *jobvr, integer *n, doublereal *
  19. a, integer *lda, doublereal *b, integer *ldb, doublereal *alphar,
  20. doublereal *alphai, doublereal *beta, doublereal *vl, integer *ldvl,
  21. doublereal *vr, integer *ldvr, doublereal *work, integer *lwork,
  22. integer *info)
  23. {
  24. /* System generated locals */
  25. integer a_dim1, a_offset, b_dim1, b_offset, vl_dim1, vl_offset, vr_dim1,
  26. vr_offset, i__1, i__2;
  27. doublereal d__1, d__2, d__3, d__4;
  28. /* Local variables */
  29. integer jc, nb, in, jr, nb1, nb2, nb3, ihi, ilo;
  30. doublereal eps;
  31. logical ilv;
  32. doublereal absb, anrm, bnrm;
  33. integer itau;
  34. doublereal temp;
  35. logical ilvl, ilvr;
  36. integer lopt;
  37. doublereal anrm1, anrm2, bnrm1, bnrm2, absai, scale, absar, sbeta;
  38. extern logical lsame_(char *, char *);
  39. integer ileft, iinfo, icols, iwork, irows;
  40. extern /* Subroutine */ int dggbak_(char *, char *, integer *, integer *,
  41. integer *, doublereal *, doublereal *, integer *, doublereal *,
  42. integer *, integer *), dggbal_(char *, integer *,
  43. doublereal *, integer *, doublereal *, integer *, integer *,
  44. integer *, doublereal *, doublereal *, doublereal *, integer *);
  45. extern doublereal dlamch_(char *), dlange_(char *, integer *,
  46. integer *, doublereal *, integer *, doublereal *);
  47. doublereal salfai;
  48. extern /* Subroutine */ int dgghrd_(char *, char *, integer *, integer *,
  49. integer *, doublereal *, integer *, doublereal *, integer *,
  50. doublereal *, integer *, doublereal *, integer *, integer *), dlascl_(char *, integer *, integer *, doublereal
  51. *, doublereal *, integer *, integer *, doublereal *, integer *,
  52. integer *);
  53. doublereal salfar;
  54. extern /* Subroutine */ int dgeqrf_(integer *, integer *, doublereal *,
  55. integer *, doublereal *, doublereal *, integer *, integer *),
  56. dlacpy_(char *, integer *, integer *, doublereal *, integer *,
  57. doublereal *, integer *);
  58. doublereal safmin;
  59. extern /* Subroutine */ int dlaset_(char *, integer *, integer *,
  60. doublereal *, doublereal *, doublereal *, integer *);
  61. doublereal safmax;
  62. char chtemp[1];
  63. logical ldumma[1];
  64. extern /* Subroutine */ int dhgeqz_(char *, char *, char *, integer *,
  65. integer *, integer *, doublereal *, integer *, doublereal *,
  66. integer *, doublereal *, doublereal *, doublereal *, doublereal *,
  67. integer *, doublereal *, integer *, doublereal *, integer *,
  68. integer *), dtgevc_(char *, char *,
  69. logical *, integer *, doublereal *, integer *, doublereal *,
  70. integer *, doublereal *, integer *, doublereal *, integer *,
  71. integer *, integer *, doublereal *, integer *),
  72. xerbla_(char *, integer *);
  73. integer ijobvl, iright;
  74. logical ilimit;
  75. extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
  76. integer *, integer *);
  77. integer ijobvr;
  78. extern /* Subroutine */ int dorgqr_(integer *, integer *, integer *,
  79. doublereal *, integer *, doublereal *, doublereal *, integer *,
  80. integer *);
  81. doublereal onepls;
  82. integer lwkmin;
  83. extern /* Subroutine */ int dormqr_(char *, char *, integer *, integer *,
  84. integer *, doublereal *, integer *, doublereal *, doublereal *,
  85. integer *, doublereal *, integer *, integer *);
  86. integer lwkopt;
  87. logical lquery;
  88. /* -- LAPACK driver routine (version 3.2) -- */
  89. /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
  90. /* November 2006 */
  91. /* .. Scalar Arguments .. */
  92. /* .. */
  93. /* .. Array Arguments .. */
  94. /* .. */
  95. /* Purpose */
  96. /* ======= */
  97. /* This routine is deprecated and has been replaced by routine DGGEV. */
  98. /* DGEGV computes the eigenvalues and, optionally, the left and/or right */
  99. /* eigenvectors of a real matrix pair (A,B). */
  100. /* Given two square matrices A and B, */
  101. /* the generalized nonsymmetric eigenvalue problem (GNEP) is to find the */
  102. /* eigenvalues lambda and corresponding (non-zero) eigenvectors x such */
  103. /* that */
  104. /* A*x = lambda*B*x. */
  105. /* An alternate form is to find the eigenvalues mu and corresponding */
  106. /* eigenvectors y such that */
  107. /* mu*A*y = B*y. */
  108. /* These two forms are equivalent with mu = 1/lambda and x = y if */
  109. /* neither lambda nor mu is zero. In order to deal with the case that */
  110. /* lambda or mu is zero or small, two values alpha and beta are returned */
  111. /* for each eigenvalue, such that lambda = alpha/beta and */
  112. /* mu = beta/alpha. */
  113. /* The vectors x and y in the above equations are right eigenvectors of */
  114. /* the matrix pair (A,B). Vectors u and v satisfying */
  115. /* u**H*A = lambda*u**H*B or mu*v**H*A = v**H*B */
  116. /* are left eigenvectors of (A,B). */
  117. /* Note: this routine performs "full balancing" on A and B -- see */
  118. /* "Further Details", below. */
  119. /* Arguments */
  120. /* ========= */
  121. /* JOBVL (input) CHARACTER*1 */
  122. /* = 'N': do not compute the left generalized eigenvectors; */
  123. /* = 'V': compute the left generalized eigenvectors (returned */
  124. /* in VL). */
  125. /* JOBVR (input) CHARACTER*1 */
  126. /* = 'N': do not compute the right generalized eigenvectors; */
  127. /* = 'V': compute the right generalized eigenvectors (returned */
  128. /* in VR). */
  129. /* N (input) INTEGER */
  130. /* The order of the matrices A, B, VL, and VR. N >= 0. */
  131. /* A (input/output) DOUBLE PRECISION array, dimension (LDA, N) */
  132. /* On entry, the matrix A. */
  133. /* If JOBVL = 'V' or JOBVR = 'V', then on exit A */
  134. /* contains the real Schur form of A from the generalized Schur */
  135. /* factorization of the pair (A,B) after balancing. */
  136. /* If no eigenvectors were computed, then only the diagonal */
  137. /* blocks from the Schur form will be correct. See DGGHRD and */
  138. /* DHGEQZ for details. */
  139. /* LDA (input) INTEGER */
  140. /* The leading dimension of A. LDA >= max(1,N). */
  141. /* B (input/output) DOUBLE PRECISION array, dimension (LDB, N) */
  142. /* On entry, the matrix B. */
  143. /* If JOBVL = 'V' or JOBVR = 'V', then on exit B contains the */
  144. /* upper triangular matrix obtained from B in the generalized */
  145. /* Schur factorization of the pair (A,B) after balancing. */
  146. /* If no eigenvectors were computed, then only those elements of */
  147. /* B corresponding to the diagonal blocks from the Schur form of */
  148. /* A will be correct. See DGGHRD and DHGEQZ for details. */
  149. /* LDB (input) INTEGER */
  150. /* The leading dimension of B. LDB >= max(1,N). */
  151. /* ALPHAR (output) DOUBLE PRECISION array, dimension (N) */
  152. /* The real parts of each scalar alpha defining an eigenvalue of */
  153. /* GNEP. */
  154. /* ALPHAI (output) DOUBLE PRECISION array, dimension (N) */
  155. /* The imaginary parts of each scalar alpha defining an */
  156. /* eigenvalue of GNEP. If ALPHAI(j) is zero, then the j-th */
  157. /* eigenvalue is real; if positive, then the j-th and */
  158. /* (j+1)-st eigenvalues are a complex conjugate pair, with */
  159. /* ALPHAI(j+1) = -ALPHAI(j). */
  160. /* BETA (output) DOUBLE PRECISION array, dimension (N) */
  161. /* The scalars beta that define the eigenvalues of GNEP. */
  162. /* Together, the quantities alpha = (ALPHAR(j),ALPHAI(j)) and */
  163. /* beta = BETA(j) represent the j-th eigenvalue of the matrix */
  164. /* pair (A,B), in one of the forms lambda = alpha/beta or */
  165. /* mu = beta/alpha. Since either lambda or mu may overflow, */
  166. /* they should not, in general, be computed. */
  167. /* VL (output) DOUBLE PRECISION array, dimension (LDVL,N) */
  168. /* If JOBVL = 'V', the left eigenvectors u(j) are stored */
  169. /* in the columns of VL, in the same order as their eigenvalues. */
  170. /* If the j-th eigenvalue is real, then u(j) = VL(:,j). */
  171. /* If the j-th and (j+1)-st eigenvalues form a complex conjugate */
  172. /* pair, then */
  173. /* u(j) = VL(:,j) + i*VL(:,j+1) */
  174. /* and */
  175. /* u(j+1) = VL(:,j) - i*VL(:,j+1). */
  176. /* Each eigenvector is scaled so that its largest component has */
  177. /* abs(real part) + abs(imag. part) = 1, except for eigenvectors */
  178. /* corresponding to an eigenvalue with alpha = beta = 0, which */
  179. /* are set to zero. */
  180. /* Not referenced if JOBVL = 'N'. */
  181. /* LDVL (input) INTEGER */
  182. /* The leading dimension of the matrix VL. LDVL >= 1, and */
  183. /* if JOBVL = 'V', LDVL >= N. */
  184. /* VR (output) DOUBLE PRECISION array, dimension (LDVR,N) */
  185. /* If JOBVR = 'V', the right eigenvectors x(j) are stored */
  186. /* in the columns of VR, in the same order as their eigenvalues. */
  187. /* If the j-th eigenvalue is real, then x(j) = VR(:,j). */
  188. /* If the j-th and (j+1)-st eigenvalues form a complex conjugate */
  189. /* pair, then */
  190. /* x(j) = VR(:,j) + i*VR(:,j+1) */
  191. /* and */
  192. /* x(j+1) = VR(:,j) - i*VR(:,j+1). */
  193. /* Each eigenvector is scaled so that its largest component has */
  194. /* abs(real part) + abs(imag. part) = 1, except for eigenvalues */
  195. /* corresponding to an eigenvalue with alpha = beta = 0, which */
  196. /* are set to zero. */
  197. /* Not referenced if JOBVR = 'N'. */
  198. /* LDVR (input) INTEGER */
  199. /* The leading dimension of the matrix VR. LDVR >= 1, and */
  200. /* if JOBVR = 'V', LDVR >= N. */
  201. /* WORK (workspace/output) DOUBLE PRECISION array, dimension (MAX(1,LWORK)) */
  202. /* On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
  203. /* LWORK (input) INTEGER */
  204. /* The dimension of the array WORK. LWORK >= max(1,8*N). */
  205. /* For good performance, LWORK must generally be larger. */
  206. /* To compute the optimal value of LWORK, call ILAENV to get */
  207. /* blocksizes (for DGEQRF, DORMQR, and DORGQR.) Then compute: */
  208. /* NB -- MAX of the blocksizes for DGEQRF, DORMQR, and DORGQR; */
  209. /* The optimal LWORK is: */
  210. /* 2*N + MAX( 6*N, N*(NB+1) ). */
  211. /* If LWORK = -1, then a workspace query is assumed; the routine */
  212. /* only calculates the optimal size of the WORK array, returns */
  213. /* this value as the first entry of the WORK array, and no error */
  214. /* message related to LWORK is issued by XERBLA. */
  215. /* INFO (output) INTEGER */
  216. /* = 0: successful exit */
  217. /* < 0: if INFO = -i, the i-th argument had an illegal value. */
  218. /* = 1,...,N: */
  219. /* The QZ iteration failed. No eigenvectors have been */
  220. /* calculated, but ALPHAR(j), ALPHAI(j), and BETA(j) */
  221. /* should be correct for j=INFO+1,...,N. */
  222. /* > N: errors that usually indicate LAPACK problems: */
  223. /* =N+1: error return from DGGBAL */
  224. /* =N+2: error return from DGEQRF */
  225. /* =N+3: error return from DORMQR */
  226. /* =N+4: error return from DORGQR */
  227. /* =N+5: error return from DGGHRD */
  228. /* =N+6: error return from DHGEQZ (other than failed */
  229. /* iteration) */
  230. /* =N+7: error return from DTGEVC */
  231. /* =N+8: error return from DGGBAK (computing VL) */
  232. /* =N+9: error return from DGGBAK (computing VR) */
  233. /* =N+10: error return from DLASCL (various calls) */
  234. /* Further Details */
  235. /* =============== */
  236. /* Balancing */
  237. /* --------- */
  238. /* This driver calls DGGBAL to both permute and scale rows and columns */
  239. /* of A and B. The permutations PL and PR are chosen so that PL*A*PR */
  240. /* and PL*B*R will be upper triangular except for the diagonal blocks */
  241. /* A(i:j,i:j) and B(i:j,i:j), with i and j as close together as */
  242. /* possible. The diagonal scaling matrices DL and DR are chosen so */
  243. /* that the pair DL*PL*A*PR*DR, DL*PL*B*PR*DR have elements close to */
  244. /* one (except for the elements that start out zero.) */
  245. /* After the eigenvalues and eigenvectors of the balanced matrices */
  246. /* have been computed, DGGBAK transforms the eigenvectors back to what */
  247. /* they would have been (in perfect arithmetic) if they had not been */
  248. /* balanced. */
  249. /* Contents of A and B on Exit */
  250. /* -------- -- - --- - -- ---- */
  251. /* If any eigenvectors are computed (either JOBVL='V' or JOBVR='V' or */
  252. /* both), then on exit the arrays A and B will contain the real Schur */
  253. /* form[*] of the "balanced" versions of A and B. If no eigenvectors */
  254. /* are computed, then only the diagonal blocks will be correct. */
  255. /* [*] See DHGEQZ, DGEGS, or read the book "Matrix Computations", */
  256. /* by Golub & van Loan, pub. by Johns Hopkins U. Press. */
  257. /* ===================================================================== */
  258. /* .. Parameters .. */
  259. /* .. */
  260. /* .. Local Scalars .. */
  261. /* .. */
  262. /* .. Local Arrays .. */
  263. /* .. */
  264. /* .. External Subroutines .. */
  265. /* .. */
  266. /* .. External Functions .. */
  267. /* .. */
  268. /* .. Intrinsic Functions .. */
  269. /* .. */
  270. /* .. Executable Statements .. */
  271. /* Decode the input arguments */
  272. /* Parameter adjustments */
  273. a_dim1 = *lda;
  274. a_offset = 1 + a_dim1;
  275. a -= a_offset;
  276. b_dim1 = *ldb;
  277. b_offset = 1 + b_dim1;
  278. b -= b_offset;
  279. --alphar;
  280. --alphai;
  281. --beta;
  282. vl_dim1 = *ldvl;
  283. vl_offset = 1 + vl_dim1;
  284. vl -= vl_offset;
  285. vr_dim1 = *ldvr;
  286. vr_offset = 1 + vr_dim1;
  287. vr -= vr_offset;
  288. --work;
  289. /* Function Body */
  290. if (lsame_(jobvl, "N")) {
  291. ijobvl = 1;
  292. ilvl = FALSE_;
  293. } else if (lsame_(jobvl, "V")) {
  294. ijobvl = 2;
  295. ilvl = TRUE_;
  296. } else {
  297. ijobvl = -1;
  298. ilvl = FALSE_;
  299. }
  300. if (lsame_(jobvr, "N")) {
  301. ijobvr = 1;
  302. ilvr = FALSE_;
  303. } else if (lsame_(jobvr, "V")) {
  304. ijobvr = 2;
  305. ilvr = TRUE_;
  306. } else {
  307. ijobvr = -1;
  308. ilvr = FALSE_;
  309. }
  310. ilv = ilvl || ilvr;
  311. /* Test the input arguments */
  312. /* Computing MAX */
  313. i__1 = *n << 3;
  314. lwkmin = max(i__1,1);
  315. lwkopt = lwkmin;
  316. work[1] = (doublereal) lwkopt;
  317. lquery = *lwork == -1;
  318. *info = 0;
  319. if (ijobvl <= 0) {
  320. *info = -1;
  321. } else if (ijobvr <= 0) {
  322. *info = -2;
  323. } else if (*n < 0) {
  324. *info = -3;
  325. } else if (*lda < max(1,*n)) {
  326. *info = -5;
  327. } else if (*ldb < max(1,*n)) {
  328. *info = -7;
  329. } else if (*ldvl < 1 || ilvl && *ldvl < *n) {
  330. *info = -12;
  331. } else if (*ldvr < 1 || ilvr && *ldvr < *n) {
  332. *info = -14;
  333. } else if (*lwork < lwkmin && ! lquery) {
  334. *info = -16;
  335. }
  336. if (*info == 0) {
  337. nb1 = ilaenv_(&c__1, "DGEQRF", " ", n, n, &c_n1, &c_n1);
  338. nb2 = ilaenv_(&c__1, "DORMQR", " ", n, n, n, &c_n1);
  339. nb3 = ilaenv_(&c__1, "DORGQR", " ", n, n, n, &c_n1);
  340. /* Computing MAX */
  341. i__1 = max(nb1,nb2);
  342. nb = max(i__1,nb3);
  343. /* Computing MAX */
  344. i__1 = *n * 6, i__2 = *n * (nb + 1);
  345. lopt = (*n << 1) + max(i__1,i__2);
  346. work[1] = (doublereal) lopt;
  347. }
  348. if (*info != 0) {
  349. i__1 = -(*info);
  350. xerbla_("DGEGV ", &i__1);
  351. return 0;
  352. } else if (lquery) {
  353. return 0;
  354. }
  355. /* Quick return if possible */
  356. if (*n == 0) {
  357. return 0;
  358. }
  359. /* Get machine constants */
  360. eps = dlamch_("E") * dlamch_("B");
  361. safmin = dlamch_("S");
  362. safmin += safmin;
  363. safmax = 1. / safmin;
  364. onepls = eps * 4 + 1.;
  365. /* Scale A */
  366. anrm = dlange_("M", n, n, &a[a_offset], lda, &work[1]);
  367. anrm1 = anrm;
  368. anrm2 = 1.;
  369. if (anrm < 1.) {
  370. if (safmax * anrm < 1.) {
  371. anrm1 = safmin;
  372. anrm2 = safmax * anrm;
  373. }
  374. }
  375. if (anrm > 0.) {
  376. dlascl_("G", &c_n1, &c_n1, &anrm, &c_b27, n, n, &a[a_offset], lda, &
  377. iinfo);
  378. if (iinfo != 0) {
  379. *info = *n + 10;
  380. return 0;
  381. }
  382. }
  383. /* Scale B */
  384. bnrm = dlange_("M", n, n, &b[b_offset], ldb, &work[1]);
  385. bnrm1 = bnrm;
  386. bnrm2 = 1.;
  387. if (bnrm < 1.) {
  388. if (safmax * bnrm < 1.) {
  389. bnrm1 = safmin;
  390. bnrm2 = safmax * bnrm;
  391. }
  392. }
  393. if (bnrm > 0.) {
  394. dlascl_("G", &c_n1, &c_n1, &bnrm, &c_b27, n, n, &b[b_offset], ldb, &
  395. iinfo);
  396. if (iinfo != 0) {
  397. *info = *n + 10;
  398. return 0;
  399. }
  400. }
  401. /* Permute the matrix to make it more nearly triangular */
  402. /* Workspace layout: (8*N words -- "work" requires 6*N words) */
  403. /* left_permutation, right_permutation, work... */
  404. ileft = 1;
  405. iright = *n + 1;
  406. iwork = iright + *n;
  407. dggbal_("P", n, &a[a_offset], lda, &b[b_offset], ldb, &ilo, &ihi, &work[
  408. ileft], &work[iright], &work[iwork], &iinfo);
  409. if (iinfo != 0) {
  410. *info = *n + 1;
  411. goto L120;
  412. }
  413. /* Reduce B to triangular form, and initialize VL and/or VR */
  414. /* Workspace layout: ("work..." must have at least N words) */
  415. /* left_permutation, right_permutation, tau, work... */
  416. irows = ihi + 1 - ilo;
  417. if (ilv) {
  418. icols = *n + 1 - ilo;
  419. } else {
  420. icols = irows;
  421. }
  422. itau = iwork;
  423. iwork = itau + irows;
  424. i__1 = *lwork + 1 - iwork;
  425. dgeqrf_(&irows, &icols, &b[ilo + ilo * b_dim1], ldb, &work[itau], &work[
  426. iwork], &i__1, &iinfo);
  427. if (iinfo >= 0) {
  428. /* Computing MAX */
  429. i__1 = lwkopt, i__2 = (integer) work[iwork] + iwork - 1;
  430. lwkopt = max(i__1,i__2);
  431. }
  432. if (iinfo != 0) {
  433. *info = *n + 2;
  434. goto L120;
  435. }
  436. i__1 = *lwork + 1 - iwork;
  437. dormqr_("L", "T", &irows, &icols, &irows, &b[ilo + ilo * b_dim1], ldb, &
  438. work[itau], &a[ilo + ilo * a_dim1], lda, &work[iwork], &i__1, &
  439. iinfo);
  440. if (iinfo >= 0) {
  441. /* Computing MAX */
  442. i__1 = lwkopt, i__2 = (integer) work[iwork] + iwork - 1;
  443. lwkopt = max(i__1,i__2);
  444. }
  445. if (iinfo != 0) {
  446. *info = *n + 3;
  447. goto L120;
  448. }
  449. if (ilvl) {
  450. dlaset_("Full", n, n, &c_b38, &c_b27, &vl[vl_offset], ldvl)
  451. ;
  452. i__1 = irows - 1;
  453. i__2 = irows - 1;
  454. dlacpy_("L", &i__1, &i__2, &b[ilo + 1 + ilo * b_dim1], ldb, &vl[ilo +
  455. 1 + ilo * vl_dim1], ldvl);
  456. i__1 = *lwork + 1 - iwork;
  457. dorgqr_(&irows, &irows, &irows, &vl[ilo + ilo * vl_dim1], ldvl, &work[
  458. itau], &work[iwork], &i__1, &iinfo);
  459. if (iinfo >= 0) {
  460. /* Computing MAX */
  461. i__1 = lwkopt, i__2 = (integer) work[iwork] + iwork - 1;
  462. lwkopt = max(i__1,i__2);
  463. }
  464. if (iinfo != 0) {
  465. *info = *n + 4;
  466. goto L120;
  467. }
  468. }
  469. if (ilvr) {
  470. dlaset_("Full", n, n, &c_b38, &c_b27, &vr[vr_offset], ldvr)
  471. ;
  472. }
  473. /* Reduce to generalized Hessenberg form */
  474. if (ilv) {
  475. /* Eigenvectors requested -- work on whole matrix. */
  476. dgghrd_(jobvl, jobvr, n, &ilo, &ihi, &a[a_offset], lda, &b[b_offset],
  477. ldb, &vl[vl_offset], ldvl, &vr[vr_offset], ldvr, &iinfo);
  478. } else {
  479. dgghrd_("N", "N", &irows, &c__1, &irows, &a[ilo + ilo * a_dim1], lda,
  480. &b[ilo + ilo * b_dim1], ldb, &vl[vl_offset], ldvl, &vr[
  481. vr_offset], ldvr, &iinfo);
  482. }
  483. if (iinfo != 0) {
  484. *info = *n + 5;
  485. goto L120;
  486. }
  487. /* Perform QZ algorithm */
  488. /* Workspace layout: ("work..." must have at least 1 word) */
  489. /* left_permutation, right_permutation, work... */
  490. iwork = itau;
  491. if (ilv) {
  492. *(unsigned char *)chtemp = 'S';
  493. } else {
  494. *(unsigned char *)chtemp = 'E';
  495. }
  496. i__1 = *lwork + 1 - iwork;
  497. dhgeqz_(chtemp, jobvl, jobvr, n, &ilo, &ihi, &a[a_offset], lda, &b[
  498. b_offset], ldb, &alphar[1], &alphai[1], &beta[1], &vl[vl_offset],
  499. ldvl, &vr[vr_offset], ldvr, &work[iwork], &i__1, &iinfo);
  500. if (iinfo >= 0) {
  501. /* Computing MAX */
  502. i__1 = lwkopt, i__2 = (integer) work[iwork] + iwork - 1;
  503. lwkopt = max(i__1,i__2);
  504. }
  505. if (iinfo != 0) {
  506. if (iinfo > 0 && iinfo <= *n) {
  507. *info = iinfo;
  508. } else if (iinfo > *n && iinfo <= *n << 1) {
  509. *info = iinfo - *n;
  510. } else {
  511. *info = *n + 6;
  512. }
  513. goto L120;
  514. }
  515. if (ilv) {
  516. /* Compute Eigenvectors (DTGEVC requires 6*N words of workspace) */
  517. if (ilvl) {
  518. if (ilvr) {
  519. *(unsigned char *)chtemp = 'B';
  520. } else {
  521. *(unsigned char *)chtemp = 'L';
  522. }
  523. } else {
  524. *(unsigned char *)chtemp = 'R';
  525. }
  526. dtgevc_(chtemp, "B", ldumma, n, &a[a_offset], lda, &b[b_offset], ldb,
  527. &vl[vl_offset], ldvl, &vr[vr_offset], ldvr, n, &in, &work[
  528. iwork], &iinfo);
  529. if (iinfo != 0) {
  530. *info = *n + 7;
  531. goto L120;
  532. }
  533. /* Undo balancing on VL and VR, rescale */
  534. if (ilvl) {
  535. dggbak_("P", "L", n, &ilo, &ihi, &work[ileft], &work[iright], n, &
  536. vl[vl_offset], ldvl, &iinfo);
  537. if (iinfo != 0) {
  538. *info = *n + 8;
  539. goto L120;
  540. }
  541. i__1 = *n;
  542. for (jc = 1; jc <= i__1; ++jc) {
  543. if (alphai[jc] < 0.) {
  544. goto L50;
  545. }
  546. temp = 0.;
  547. if (alphai[jc] == 0.) {
  548. i__2 = *n;
  549. for (jr = 1; jr <= i__2; ++jr) {
  550. /* Computing MAX */
  551. d__2 = temp, d__3 = (d__1 = vl[jr + jc * vl_dim1],
  552. abs(d__1));
  553. temp = max(d__2,d__3);
  554. /* L10: */
  555. }
  556. } else {
  557. i__2 = *n;
  558. for (jr = 1; jr <= i__2; ++jr) {
  559. /* Computing MAX */
  560. d__3 = temp, d__4 = (d__1 = vl[jr + jc * vl_dim1],
  561. abs(d__1)) + (d__2 = vl[jr + (jc + 1) *
  562. vl_dim1], abs(d__2));
  563. temp = max(d__3,d__4);
  564. /* L20: */
  565. }
  566. }
  567. if (temp < safmin) {
  568. goto L50;
  569. }
  570. temp = 1. / temp;
  571. if (alphai[jc] == 0.) {
  572. i__2 = *n;
  573. for (jr = 1; jr <= i__2; ++jr) {
  574. vl[jr + jc * vl_dim1] *= temp;
  575. /* L30: */
  576. }
  577. } else {
  578. i__2 = *n;
  579. for (jr = 1; jr <= i__2; ++jr) {
  580. vl[jr + jc * vl_dim1] *= temp;
  581. vl[jr + (jc + 1) * vl_dim1] *= temp;
  582. /* L40: */
  583. }
  584. }
  585. L50:
  586. ;
  587. }
  588. }
  589. if (ilvr) {
  590. dggbak_("P", "R", n, &ilo, &ihi, &work[ileft], &work[iright], n, &
  591. vr[vr_offset], ldvr, &iinfo);
  592. if (iinfo != 0) {
  593. *info = *n + 9;
  594. goto L120;
  595. }
  596. i__1 = *n;
  597. for (jc = 1; jc <= i__1; ++jc) {
  598. if (alphai[jc] < 0.) {
  599. goto L100;
  600. }
  601. temp = 0.;
  602. if (alphai[jc] == 0.) {
  603. i__2 = *n;
  604. for (jr = 1; jr <= i__2; ++jr) {
  605. /* Computing MAX */
  606. d__2 = temp, d__3 = (d__1 = vr[jr + jc * vr_dim1],
  607. abs(d__1));
  608. temp = max(d__2,d__3);
  609. /* L60: */
  610. }
  611. } else {
  612. i__2 = *n;
  613. for (jr = 1; jr <= i__2; ++jr) {
  614. /* Computing MAX */
  615. d__3 = temp, d__4 = (d__1 = vr[jr + jc * vr_dim1],
  616. abs(d__1)) + (d__2 = vr[jr + (jc + 1) *
  617. vr_dim1], abs(d__2));
  618. temp = max(d__3,d__4);
  619. /* L70: */
  620. }
  621. }
  622. if (temp < safmin) {
  623. goto L100;
  624. }
  625. temp = 1. / temp;
  626. if (alphai[jc] == 0.) {
  627. i__2 = *n;
  628. for (jr = 1; jr <= i__2; ++jr) {
  629. vr[jr + jc * vr_dim1] *= temp;
  630. /* L80: */
  631. }
  632. } else {
  633. i__2 = *n;
  634. for (jr = 1; jr <= i__2; ++jr) {
  635. vr[jr + jc * vr_dim1] *= temp;
  636. vr[jr + (jc + 1) * vr_dim1] *= temp;
  637. /* L90: */
  638. }
  639. }
  640. L100:
  641. ;
  642. }
  643. }
  644. /* End of eigenvector calculation */
  645. }
  646. /* Undo scaling in alpha, beta */
  647. /* Note: this does not give the alpha and beta for the unscaled */
  648. /* problem. */
  649. /* Un-scaling is limited to avoid underflow in alpha and beta */
  650. /* if they are significant. */
  651. i__1 = *n;
  652. for (jc = 1; jc <= i__1; ++jc) {
  653. absar = (d__1 = alphar[jc], abs(d__1));
  654. absai = (d__1 = alphai[jc], abs(d__1));
  655. absb = (d__1 = beta[jc], abs(d__1));
  656. salfar = anrm * alphar[jc];
  657. salfai = anrm * alphai[jc];
  658. sbeta = bnrm * beta[jc];
  659. ilimit = FALSE_;
  660. scale = 1.;
  661. /* Check for significant underflow in ALPHAI */
  662. /* Computing MAX */
  663. d__1 = safmin, d__2 = eps * absar, d__1 = max(d__1,d__2), d__2 = eps *
  664. absb;
  665. if (abs(salfai) < safmin && absai >= max(d__1,d__2)) {
  666. ilimit = TRUE_;
  667. /* Computing MAX */
  668. d__1 = onepls * safmin, d__2 = anrm2 * absai;
  669. scale = onepls * safmin / anrm1 / max(d__1,d__2);
  670. } else if (salfai == 0.) {
  671. /* If insignificant underflow in ALPHAI, then make the */
  672. /* conjugate eigenvalue real. */
  673. if (alphai[jc] < 0. && jc > 1) {
  674. alphai[jc - 1] = 0.;
  675. } else if (alphai[jc] > 0. && jc < *n) {
  676. alphai[jc + 1] = 0.;
  677. }
  678. }
  679. /* Check for significant underflow in ALPHAR */
  680. /* Computing MAX */
  681. d__1 = safmin, d__2 = eps * absai, d__1 = max(d__1,d__2), d__2 = eps *
  682. absb;
  683. if (abs(salfar) < safmin && absar >= max(d__1,d__2)) {
  684. ilimit = TRUE_;
  685. /* Computing MAX */
  686. /* Computing MAX */
  687. d__3 = onepls * safmin, d__4 = anrm2 * absar;
  688. d__1 = scale, d__2 = onepls * safmin / anrm1 / max(d__3,d__4);
  689. scale = max(d__1,d__2);
  690. }
  691. /* Check for significant underflow in BETA */
  692. /* Computing MAX */
  693. d__1 = safmin, d__2 = eps * absar, d__1 = max(d__1,d__2), d__2 = eps *
  694. absai;
  695. if (abs(sbeta) < safmin && absb >= max(d__1,d__2)) {
  696. ilimit = TRUE_;
  697. /* Computing MAX */
  698. /* Computing MAX */
  699. d__3 = onepls * safmin, d__4 = bnrm2 * absb;
  700. d__1 = scale, d__2 = onepls * safmin / bnrm1 / max(d__3,d__4);
  701. scale = max(d__1,d__2);
  702. }
  703. /* Check for possible overflow when limiting scaling */
  704. if (ilimit) {
  705. /* Computing MAX */
  706. d__1 = abs(salfar), d__2 = abs(salfai), d__1 = max(d__1,d__2),
  707. d__2 = abs(sbeta);
  708. temp = scale * safmin * max(d__1,d__2);
  709. if (temp > 1.) {
  710. scale /= temp;
  711. }
  712. if (scale < 1.) {
  713. ilimit = FALSE_;
  714. }
  715. }
  716. /* Recompute un-scaled ALPHAR, ALPHAI, BETA if necessary. */
  717. if (ilimit) {
  718. salfar = scale * alphar[jc] * anrm;
  719. salfai = scale * alphai[jc] * anrm;
  720. sbeta = scale * beta[jc] * bnrm;
  721. }
  722. alphar[jc] = salfar;
  723. alphai[jc] = salfai;
  724. beta[jc] = sbeta;
  725. /* L110: */
  726. }
  727. L120:
  728. work[1] = (doublereal) lwkopt;
  729. return 0;
  730. /* End of DGEGV */
  731. } /* dgegv_ */