PageRenderTime 220ms CodeModel.GetById 36ms RepoModel.GetById 2ms app.codeStats 0ms

/src/libsesctherm/CLAPACK/SRC/dggevx.c

https://bitbucket.org/spramod/sesc-recvf
C | 843 lines | 462 code | 67 blank | 314 comment | 139 complexity | 022a21feccb9e65cff46d1967accdcc1 MD5 | raw file
Possible License(s): GPL-2.0
  1. #include "blaswrap.h"
  2. #include "f2c.h"
  3. /* Subroutine */ int dggevx_(char *balanc, char *jobvl, char *jobvr, char *
  4. sense, integer *n, doublereal *a, integer *lda, doublereal *b,
  5. integer *ldb, doublereal *alphar, doublereal *alphai, doublereal *
  6. beta, doublereal *vl, integer *ldvl, doublereal *vr, integer *ldvr,
  7. integer *ilo, integer *ihi, doublereal *lscale, doublereal *rscale,
  8. doublereal *abnrm, doublereal *bbnrm, doublereal *rconde, doublereal *
  9. rcondv, doublereal *work, integer *lwork, integer *iwork, logical *
  10. bwork, integer *info)
  11. {
  12. /* -- LAPACK driver routine (version 3.0) --
  13. Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd.,
  14. Courant Institute, Argonne National Lab, and Rice University
  15. June 30, 1999
  16. Purpose
  17. =======
  18. DGGEVX computes for a pair of N-by-N real nonsymmetric matrices (A,B)
  19. the generalized eigenvalues, and optionally, the left and/or right
  20. generalized eigenvectors.
  21. Optionally also, it computes a balancing transformation to improve
  22. the conditioning of the eigenvalues and eigenvectors (ILO, IHI,
  23. LSCALE, RSCALE, ABNRM, and BBNRM), reciprocal condition numbers for
  24. the eigenvalues (RCONDE), and reciprocal condition numbers for the
  25. right eigenvectors (RCONDV).
  26. A generalized eigenvalue for a pair of matrices (A,B) is a scalar
  27. lambda or a ratio alpha/beta = lambda, such that A - lambda*B is
  28. singular. It is usually represented as the pair (alpha,beta), as
  29. there is a reasonable interpretation for beta=0, and even for both
  30. being zero.
  31. The right eigenvector v(j) corresponding to the eigenvalue lambda(j)
  32. of (A,B) satisfies
  33. A * v(j) = lambda(j) * B * v(j) .
  34. The left eigenvector u(j) corresponding to the eigenvalue lambda(j)
  35. of (A,B) satisfies
  36. u(j)**H * A = lambda(j) * u(j)**H * B.
  37. where u(j)**H is the conjugate-transpose of u(j).
  38. Arguments
  39. =========
  40. BALANC (input) CHARACTER*1
  41. Specifies the balance option to be performed.
  42. = 'N': do not diagonally scale or permute;
  43. = 'P': permute only;
  44. = 'S': scale only;
  45. = 'B': both permute and scale.
  46. Computed reciprocal condition numbers will be for the
  47. matrices after permuting and/or balancing. Permuting does
  48. not change condition numbers (in exact arithmetic), but
  49. balancing does.
  50. JOBVL (input) CHARACTER*1
  51. = 'N': do not compute the left generalized eigenvectors;
  52. = 'V': compute the left generalized eigenvectors.
  53. JOBVR (input) CHARACTER*1
  54. = 'N': do not compute the right generalized eigenvectors;
  55. = 'V': compute the right generalized eigenvectors.
  56. SENSE (input) CHARACTER*1
  57. Determines which reciprocal condition numbers are computed.
  58. = 'N': none are computed;
  59. = 'E': computed for eigenvalues only;
  60. = 'V': computed for eigenvectors only;
  61. = 'B': computed for eigenvalues and eigenvectors.
  62. N (input) INTEGER
  63. The order of the matrices A, B, VL, and VR. N >= 0.
  64. A (input/output) DOUBLE PRECISION array, dimension (LDA, N)
  65. On entry, the matrix A in the pair (A,B).
  66. On exit, A has been overwritten. If JOBVL='V' or JOBVR='V'
  67. or both, then A contains the first part of the real Schur
  68. form of the "balanced" versions of the input A and B.
  69. LDA (input) INTEGER
  70. The leading dimension of A. LDA >= max(1,N).
  71. B (input/output) DOUBLE PRECISION array, dimension (LDB, N)
  72. On entry, the matrix B in the pair (A,B).
  73. On exit, B has been overwritten. If JOBVL='V' or JOBVR='V'
  74. or both, then B contains the second part of the real Schur
  75. form of the "balanced" versions of the input A and B.
  76. LDB (input) INTEGER
  77. The leading dimension of B. LDB >= max(1,N).
  78. ALPHAR (output) DOUBLE PRECISION array, dimension (N)
  79. ALPHAI (output) DOUBLE PRECISION array, dimension (N)
  80. BETA (output) DOUBLE PRECISION array, dimension (N)
  81. On exit, (ALPHAR(j) + ALPHAI(j)*i)/BETA(j), j=1,...,N, will
  82. be the generalized eigenvalues. If ALPHAI(j) is zero, then
  83. the j-th eigenvalue is real; if positive, then the j-th and
  84. (j+1)-st eigenvalues are a complex conjugate pair, with
  85. ALPHAI(j+1) negative.
  86. Note: the quotients ALPHAR(j)/BETA(j) and ALPHAI(j)/BETA(j)
  87. may easily over- or underflow, and BETA(j) may even be zero.
  88. Thus, the user should avoid naively computing the ratio
  89. ALPHA/BETA. However, ALPHAR and ALPHAI will be always less
  90. than and usually comparable with norm(A) in magnitude, and
  91. BETA always less than and usually comparable with norm(B).
  92. VL (output) DOUBLE PRECISION array, dimension (LDVL,N)
  93. If JOBVL = 'V', the left eigenvectors u(j) are stored one
  94. after another in the columns of VL, in the same order as
  95. their eigenvalues. If the j-th eigenvalue is real, then
  96. u(j) = VL(:,j), the j-th column of VL. If the j-th and
  97. (j+1)-th eigenvalues form a complex conjugate pair, then
  98. u(j) = VL(:,j)+i*VL(:,j+1) and u(j+1) = VL(:,j)-i*VL(:,j+1).
  99. Each eigenvector will be scaled so the largest component have
  100. abs(real part) + abs(imag. part) = 1.
  101. Not referenced if JOBVL = 'N'.
  102. LDVL (input) INTEGER
  103. The leading dimension of the matrix VL. LDVL >= 1, and
  104. if JOBVL = 'V', LDVL >= N.
  105. VR (output) DOUBLE PRECISION array, dimension (LDVR,N)
  106. If JOBVR = 'V', the right eigenvectors v(j) are stored one
  107. after another in the columns of VR, in the same order as
  108. their eigenvalues. If the j-th eigenvalue is real, then
  109. v(j) = VR(:,j), the j-th column of VR. If the j-th and
  110. (j+1)-th eigenvalues form a complex conjugate pair, then
  111. v(j) = VR(:,j)+i*VR(:,j+1) and v(j+1) = VR(:,j)-i*VR(:,j+1).
  112. Each eigenvector will be scaled so the largest component have
  113. abs(real part) + abs(imag. part) = 1.
  114. Not referenced if JOBVR = 'N'.
  115. LDVR (input) INTEGER
  116. The leading dimension of the matrix VR. LDVR >= 1, and
  117. if JOBVR = 'V', LDVR >= N.
  118. ILO,IHI (output) INTEGER
  119. ILO and IHI are integer values such that on exit
  120. A(i,j) = 0 and B(i,j) = 0 if i > j and
  121. j = 1,...,ILO-1 or i = IHI+1,...,N.
  122. If BALANC = 'N' or 'S', ILO = 1 and IHI = N.
  123. LSCALE (output) DOUBLE PRECISION array, dimension (N)
  124. Details of the permutations and scaling factors applied
  125. to the left side of A and B. If PL(j) is the index of the
  126. row interchanged with row j, and DL(j) is the scaling
  127. factor applied to row j, then
  128. LSCALE(j) = PL(j) for j = 1,...,ILO-1
  129. = DL(j) for j = ILO,...,IHI
  130. = PL(j) for j = IHI+1,...,N.
  131. The order in which the interchanges are made is N to IHI+1,
  132. then 1 to ILO-1.
  133. RSCALE (output) DOUBLE PRECISION array, dimension (N)
  134. Details of the permutations and scaling factors applied
  135. to the right side of A and B. If PR(j) is the index of the
  136. column interchanged with column j, and DR(j) is the scaling
  137. factor applied to column j, then
  138. RSCALE(j) = PR(j) for j = 1,...,ILO-1
  139. = DR(j) for j = ILO,...,IHI
  140. = PR(j) for j = IHI+1,...,N
  141. The order in which the interchanges are made is N to IHI+1,
  142. then 1 to ILO-1.
  143. ABNRM (output) DOUBLE PRECISION
  144. The one-norm of the balanced matrix A.
  145. BBNRM (output) DOUBLE PRECISION
  146. The one-norm of the balanced matrix B.
  147. RCONDE (output) DOUBLE PRECISION array, dimension (N)
  148. If SENSE = 'E' or 'B', the reciprocal condition numbers of
  149. the selected eigenvalues, stored in consecutive elements of
  150. the array. For a complex conjugate pair of eigenvalues two
  151. consecutive elements of RCONDE are set to the same value.
  152. Thus RCONDE(j), RCONDV(j), and the j-th columns of VL and VR
  153. all correspond to the same eigenpair (but not in general the
  154. j-th eigenpair, unless all eigenpairs are selected).
  155. If SENSE = 'V', RCONDE is not referenced.
  156. RCONDV (output) DOUBLE PRECISION array, dimension (N)
  157. If SENSE = 'V' or 'B', the estimated reciprocal condition
  158. numbers of the selected eigenvectors, stored in consecutive
  159. elements of the array. For a complex eigenvector two
  160. consecutive elements of RCONDV are set to the same value. If
  161. the eigenvalues cannot be reordered to compute RCONDV(j),
  162. RCONDV(j) is set to 0; this can only occur when the true
  163. value would be very small anyway.
  164. If SENSE = 'E', RCONDV is not referenced.
  165. WORK (workspace/output) DOUBLE PRECISION array, dimension (LWORK)
  166. On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
  167. LWORK (input) INTEGER
  168. The dimension of the array WORK. LWORK >= max(1,6*N).
  169. If SENSE = 'E', LWORK >= 12*N.
  170. If SENSE = 'V' or 'B', LWORK >= 2*N*N+12*N+16.
  171. If LWORK = -1, then a workspace query is assumed; the routine
  172. only calculates the optimal size of the WORK array, returns
  173. this value as the first entry of the WORK array, and no error
  174. message related to LWORK is issued by XERBLA.
  175. IWORK (workspace) INTEGER array, dimension (N+6)
  176. If SENSE = 'E', IWORK is not referenced.
  177. BWORK (workspace) LOGICAL array, dimension (N)
  178. If SENSE = 'N', BWORK is not referenced.
  179. INFO (output) INTEGER
  180. = 0: successful exit
  181. < 0: if INFO = -i, the i-th argument had an illegal value.
  182. = 1,...,N:
  183. The QZ iteration failed. No eigenvectors have been
  184. calculated, but ALPHAR(j), ALPHAI(j), and BETA(j)
  185. should be correct for j=INFO+1,...,N.
  186. > N: =N+1: other than QZ iteration failed in DHGEQZ.
  187. =N+2: error return from DTGEVC.
  188. Further Details
  189. ===============
  190. Balancing a matrix pair (A,B) includes, first, permuting rows and
  191. columns to isolate eigenvalues, second, applying diagonal similarity
  192. transformation to the rows and columns to make the rows and columns
  193. as close in norm as possible. The computed reciprocal condition
  194. numbers correspond to the balanced matrix. Permuting rows and columns
  195. will not change the condition numbers (in exact arithmetic) but
  196. diagonal scaling will. For further explanation of balancing, see
  197. section 4.11.1.2 of LAPACK Users' Guide.
  198. An approximate error bound on the chordal distance between the i-th
  199. computed generalized eigenvalue w and the corresponding exact
  200. eigenvalue lambda is
  201. chord(w, lambda) <= EPS * norm(ABNRM, BBNRM) / RCONDE(I)
  202. An approximate error bound for the angle between the i-th computed
  203. eigenvector VL(i) or VR(i) is given by
  204. EPS * norm(ABNRM, BBNRM) / DIF(i).
  205. For further explanation of the reciprocal condition numbers RCONDE
  206. and RCONDV, see section 4.11 of LAPACK User's Guide.
  207. =====================================================================
  208. Decode the input arguments
  209. Parameter adjustments */
  210. /* Table of constant values */
  211. static integer c__1 = 1;
  212. static integer c__0 = 0;
  213. static doublereal c_b47 = 0.;
  214. static doublereal c_b48 = 1.;
  215. /* System generated locals */
  216. integer a_dim1, a_offset, b_dim1, b_offset, vl_dim1, vl_offset, vr_dim1,
  217. vr_offset, i__1, i__2;
  218. doublereal d__1, d__2, d__3, d__4;
  219. /* Builtin functions */
  220. double sqrt(doublereal);
  221. /* Local variables */
  222. static logical pair;
  223. static doublereal anrm, bnrm;
  224. static integer ierr, itau;
  225. static doublereal temp;
  226. static logical ilvl, ilvr;
  227. static integer iwrk, iwrk1, i__, j, m;
  228. extern logical lsame_(char *, char *);
  229. static integer icols, irows;
  230. extern /* Subroutine */ int dlabad_(doublereal *, doublereal *);
  231. static integer jc;
  232. extern /* Subroutine */ int dggbak_(char *, char *, integer *, integer *,
  233. integer *, doublereal *, doublereal *, integer *, doublereal *,
  234. integer *, integer *), dggbal_(char *, integer *,
  235. doublereal *, integer *, doublereal *, integer *, integer *,
  236. integer *, doublereal *, doublereal *, doublereal *, integer *);
  237. static integer in;
  238. extern doublereal dlamch_(char *);
  239. static integer mm;
  240. extern doublereal dlange_(char *, integer *, integer *, doublereal *,
  241. integer *, doublereal *);
  242. static integer jr;
  243. extern /* Subroutine */ int dgghrd_(char *, char *, integer *, integer *,
  244. integer *, doublereal *, integer *, doublereal *, integer *,
  245. doublereal *, integer *, doublereal *, integer *, integer *), dlascl_(char *, integer *, integer *, doublereal
  246. *, doublereal *, integer *, integer *, doublereal *, integer *,
  247. integer *);
  248. static logical ilascl, ilbscl;
  249. extern /* Subroutine */ int dgeqrf_(integer *, integer *, doublereal *,
  250. integer *, doublereal *, doublereal *, integer *, integer *),
  251. dlacpy_(char *, integer *, integer *, doublereal *, integer *,
  252. doublereal *, integer *);
  253. static logical ldumma[1];
  254. static char chtemp[1];
  255. static doublereal bignum;
  256. extern /* Subroutine */ int dhgeqz_(char *, char *, char *, integer *,
  257. integer *, integer *, doublereal *, integer *, doublereal *,
  258. integer *, doublereal *, doublereal *, doublereal *, doublereal *,
  259. integer *, doublereal *, integer *, doublereal *, integer *,
  260. integer *), dlaset_(char *, integer *,
  261. integer *, doublereal *, doublereal *, doublereal *, integer *);
  262. static integer ijobvl;
  263. extern /* Subroutine */ int dtgevc_(char *, char *, logical *, integer *,
  264. doublereal *, integer *, doublereal *, integer *, doublereal *,
  265. integer *, doublereal *, integer *, integer *, integer *,
  266. doublereal *, integer *), dtgsna_(char *, char *,
  267. logical *, integer *, doublereal *, integer *, doublereal *,
  268. integer *, doublereal *, integer *, doublereal *, integer *,
  269. doublereal *, doublereal *, integer *, integer *, doublereal *,
  270. integer *, integer *, integer *), xerbla_(char *,
  271. integer *);
  272. extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
  273. integer *, integer *, ftnlen, ftnlen);
  274. static integer ijobvr;
  275. static logical wantsb;
  276. extern /* Subroutine */ int dorgqr_(integer *, integer *, integer *,
  277. doublereal *, integer *, doublereal *, doublereal *, integer *,
  278. integer *);
  279. static doublereal anrmto;
  280. static logical wantse;
  281. static doublereal bnrmto;
  282. extern /* Subroutine */ int dormqr_(char *, char *, integer *, integer *,
  283. integer *, doublereal *, integer *, doublereal *, doublereal *,
  284. integer *, doublereal *, integer *, integer *);
  285. static integer minwrk, maxwrk;
  286. static logical wantsn;
  287. static doublereal smlnum;
  288. static logical lquery, wantsv;
  289. static doublereal eps;
  290. static logical ilv;
  291. #define a_ref(a_1,a_2) a[(a_2)*a_dim1 + a_1]
  292. #define b_ref(a_1,a_2) b[(a_2)*b_dim1 + a_1]
  293. #define vl_ref(a_1,a_2) vl[(a_2)*vl_dim1 + a_1]
  294. #define vr_ref(a_1,a_2) vr[(a_2)*vr_dim1 + a_1]
  295. a_dim1 = *lda;
  296. a_offset = 1 + a_dim1 * 1;
  297. a -= a_offset;
  298. b_dim1 = *ldb;
  299. b_offset = 1 + b_dim1 * 1;
  300. b -= b_offset;
  301. --alphar;
  302. --alphai;
  303. --beta;
  304. vl_dim1 = *ldvl;
  305. vl_offset = 1 + vl_dim1 * 1;
  306. vl -= vl_offset;
  307. vr_dim1 = *ldvr;
  308. vr_offset = 1 + vr_dim1 * 1;
  309. vr -= vr_offset;
  310. --lscale;
  311. --rscale;
  312. --rconde;
  313. --rcondv;
  314. --work;
  315. --iwork;
  316. --bwork;
  317. /* Function Body */
  318. if (lsame_(jobvl, "N")) {
  319. ijobvl = 1;
  320. ilvl = FALSE_;
  321. } else if (lsame_(jobvl, "V")) {
  322. ijobvl = 2;
  323. ilvl = TRUE_;
  324. } else {
  325. ijobvl = -1;
  326. ilvl = FALSE_;
  327. }
  328. if (lsame_(jobvr, "N")) {
  329. ijobvr = 1;
  330. ilvr = FALSE_;
  331. } else if (lsame_(jobvr, "V")) {
  332. ijobvr = 2;
  333. ilvr = TRUE_;
  334. } else {
  335. ijobvr = -1;
  336. ilvr = FALSE_;
  337. }
  338. ilv = ilvl || ilvr;
  339. wantsn = lsame_(sense, "N");
  340. wantse = lsame_(sense, "E");
  341. wantsv = lsame_(sense, "V");
  342. wantsb = lsame_(sense, "B");
  343. /* Test the input arguments */
  344. *info = 0;
  345. lquery = *lwork == -1;
  346. if (! (lsame_(balanc, "N") || lsame_(balanc, "S") || lsame_(balanc, "P")
  347. || lsame_(balanc, "B"))) {
  348. *info = -1;
  349. } else if (ijobvl <= 0) {
  350. *info = -2;
  351. } else if (ijobvr <= 0) {
  352. *info = -3;
  353. } else if (! (wantsn || wantse || wantsb || wantsv)) {
  354. *info = -4;
  355. } else if (*n < 0) {
  356. *info = -5;
  357. } else if (*lda < max(1,*n)) {
  358. *info = -7;
  359. } else if (*ldb < max(1,*n)) {
  360. *info = -9;
  361. } else if (*ldvl < 1 || ilvl && *ldvl < *n) {
  362. *info = -14;
  363. } else if (*ldvr < 1 || ilvr && *ldvr < *n) {
  364. *info = -16;
  365. }
  366. /* Compute workspace
  367. (Note: Comments in the code beginning "Workspace:" describe the
  368. minimal amount of workspace needed at that point in the code,
  369. as well as the preferred amount for good performance.
  370. NB refers to the optimal block size for the immediately
  371. following subroutine, as returned by ILAENV. The workspace is
  372. computed assuming ILO = 1 and IHI = N, the worst case.) */
  373. minwrk = 1;
  374. if (*info == 0 && (*lwork >= 1 || lquery)) {
  375. maxwrk = *n * 5 + *n * ilaenv_(&c__1, "DGEQRF", " ", n, &c__1, n, &
  376. c__0, (ftnlen)6, (ftnlen)1);
  377. /* Computing MAX */
  378. i__1 = 1, i__2 = *n * 6;
  379. minwrk = max(i__1,i__2);
  380. if (wantse) {
  381. /* Computing MAX */
  382. i__1 = 1, i__2 = *n * 12;
  383. minwrk = max(i__1,i__2);
  384. } else if (wantsv || wantsb) {
  385. minwrk = (*n << 1) * *n + *n * 12 + 16;
  386. /* Computing MAX */
  387. i__1 = maxwrk, i__2 = (*n << 1) * *n + *n * 12 + 16;
  388. maxwrk = max(i__1,i__2);
  389. }
  390. work[1] = (doublereal) maxwrk;
  391. }
  392. if (*lwork < minwrk && ! lquery) {
  393. *info = -26;
  394. }
  395. if (*info != 0) {
  396. i__1 = -(*info);
  397. xerbla_("DGGEVX", &i__1);
  398. return 0;
  399. } else if (lquery) {
  400. return 0;
  401. }
  402. /* Quick return if possible */
  403. if (*n == 0) {
  404. return 0;
  405. }
  406. /* Get machine constants */
  407. eps = dlamch_("P");
  408. smlnum = dlamch_("S");
  409. bignum = 1. / smlnum;
  410. dlabad_(&smlnum, &bignum);
  411. smlnum = sqrt(smlnum) / eps;
  412. bignum = 1. / smlnum;
  413. /* Scale A if max element outside range [SMLNUM,BIGNUM] */
  414. anrm = dlange_("M", n, n, &a[a_offset], lda, &work[1]);
  415. ilascl = FALSE_;
  416. if (anrm > 0. && anrm < smlnum) {
  417. anrmto = smlnum;
  418. ilascl = TRUE_;
  419. } else if (anrm > bignum) {
  420. anrmto = bignum;
  421. ilascl = TRUE_;
  422. }
  423. if (ilascl) {
  424. dlascl_("G", &c__0, &c__0, &anrm, &anrmto, n, n, &a[a_offset], lda, &
  425. ierr);
  426. }
  427. /* Scale B if max element outside range [SMLNUM,BIGNUM] */
  428. bnrm = dlange_("M", n, n, &b[b_offset], ldb, &work[1]);
  429. ilbscl = FALSE_;
  430. if (bnrm > 0. && bnrm < smlnum) {
  431. bnrmto = smlnum;
  432. ilbscl = TRUE_;
  433. } else if (bnrm > bignum) {
  434. bnrmto = bignum;
  435. ilbscl = TRUE_;
  436. }
  437. if (ilbscl) {
  438. dlascl_("G", &c__0, &c__0, &bnrm, &bnrmto, n, n, &b[b_offset], ldb, &
  439. ierr);
  440. }
  441. /* Permute and/or balance the matrix pair (A,B)
  442. (Workspace: need 6*N) */
  443. dggbal_(balanc, n, &a[a_offset], lda, &b[b_offset], ldb, ilo, ihi, &
  444. lscale[1], &rscale[1], &work[1], &ierr);
  445. /* Compute ABNRM and BBNRM */
  446. *abnrm = dlange_("1", n, n, &a[a_offset], lda, &work[1]);
  447. if (ilascl) {
  448. work[1] = *abnrm;
  449. dlascl_("G", &c__0, &c__0, &anrmto, &anrm, &c__1, &c__1, &work[1], &
  450. c__1, &ierr);
  451. *abnrm = work[1];
  452. }
  453. *bbnrm = dlange_("1", n, n, &b[b_offset], ldb, &work[1]);
  454. if (ilbscl) {
  455. work[1] = *bbnrm;
  456. dlascl_("G", &c__0, &c__0, &bnrmto, &bnrm, &c__1, &c__1, &work[1], &
  457. c__1, &ierr);
  458. *bbnrm = work[1];
  459. }
  460. /* Reduce B to triangular form (QR decomposition of B)
  461. (Workspace: need N, prefer N*NB ) */
  462. irows = *ihi + 1 - *ilo;
  463. if (ilv || ! wantsn) {
  464. icols = *n + 1 - *ilo;
  465. } else {
  466. icols = irows;
  467. }
  468. itau = 1;
  469. iwrk = itau + irows;
  470. i__1 = *lwork + 1 - iwrk;
  471. dgeqrf_(&irows, &icols, &b_ref(*ilo, *ilo), ldb, &work[itau], &work[iwrk],
  472. &i__1, &ierr);
  473. /* Apply the orthogonal transformation to A
  474. (Workspace: need N, prefer N*NB) */
  475. i__1 = *lwork + 1 - iwrk;
  476. dormqr_("L", "T", &irows, &icols, &irows, &b_ref(*ilo, *ilo), ldb, &work[
  477. itau], &a_ref(*ilo, *ilo), lda, &work[iwrk], &i__1, &ierr);
  478. /* Initialize VL and/or VR
  479. (Workspace: need N, prefer N*NB) */
  480. if (ilvl) {
  481. dlaset_("Full", n, n, &c_b47, &c_b48, &vl[vl_offset], ldvl)
  482. ;
  483. i__1 = irows - 1;
  484. i__2 = irows - 1;
  485. dlacpy_("L", &i__1, &i__2, &b_ref(*ilo + 1, *ilo), ldb, &vl_ref(*ilo
  486. + 1, *ilo), ldvl);
  487. i__1 = *lwork + 1 - iwrk;
  488. dorgqr_(&irows, &irows, &irows, &vl_ref(*ilo, *ilo), ldvl, &work[itau]
  489. , &work[iwrk], &i__1, &ierr);
  490. }
  491. if (ilvr) {
  492. dlaset_("Full", n, n, &c_b47, &c_b48, &vr[vr_offset], ldvr)
  493. ;
  494. }
  495. /* Reduce to generalized Hessenberg form
  496. (Workspace: none needed) */
  497. if (ilv || ! wantsn) {
  498. /* Eigenvectors requested -- work on whole matrix. */
  499. dgghrd_(jobvl, jobvr, n, ilo, ihi, &a[a_offset], lda, &b[b_offset],
  500. ldb, &vl[vl_offset], ldvl, &vr[vr_offset], ldvr, &ierr);
  501. } else {
  502. dgghrd_("N", "N", &irows, &c__1, &irows, &a_ref(*ilo, *ilo), lda, &
  503. b_ref(*ilo, *ilo), ldb, &vl[vl_offset], ldvl, &vr[vr_offset],
  504. ldvr, &ierr);
  505. }
  506. /* Perform QZ algorithm (Compute eigenvalues, and optionally, the
  507. Schur forms and Schur vectors)
  508. (Workspace: need N) */
  509. if (ilv || ! wantsn) {
  510. *(unsigned char *)chtemp = 'S';
  511. } else {
  512. *(unsigned char *)chtemp = 'E';
  513. }
  514. dhgeqz_(chtemp, jobvl, jobvr, n, ilo, ihi, &a[a_offset], lda, &b[b_offset]
  515. , ldb, &alphar[1], &alphai[1], &beta[1], &vl[vl_offset], ldvl, &
  516. vr[vr_offset], ldvr, &work[1], lwork, &ierr);
  517. if (ierr != 0) {
  518. if (ierr > 0 && ierr <= *n) {
  519. *info = ierr;
  520. } else if (ierr > *n && ierr <= *n << 1) {
  521. *info = ierr - *n;
  522. } else {
  523. *info = *n + 1;
  524. }
  525. goto L130;
  526. }
  527. /* Compute Eigenvectors and estimate condition numbers if desired
  528. (Workspace: DTGEVC: need 6*N
  529. DTGSNA: need 2*N*(N+2)+16 if SENSE = 'V' or 'B',
  530. need N otherwise ) */
  531. if (ilv || ! wantsn) {
  532. if (ilv) {
  533. if (ilvl) {
  534. if (ilvr) {
  535. *(unsigned char *)chtemp = 'B';
  536. } else {
  537. *(unsigned char *)chtemp = 'L';
  538. }
  539. } else {
  540. *(unsigned char *)chtemp = 'R';
  541. }
  542. dtgevc_(chtemp, "B", ldumma, n, &a[a_offset], lda, &b[b_offset],
  543. ldb, &vl[vl_offset], ldvl, &vr[vr_offset], ldvr, n, &in, &
  544. work[1], &ierr);
  545. if (ierr != 0) {
  546. *info = *n + 2;
  547. goto L130;
  548. }
  549. }
  550. if (! wantsn) {
  551. /* compute eigenvectors (DTGEVC) and estimate condition
  552. numbers (DTGSNA). Note that the definition of the condition
  553. number is not invariant under transformation (u,v) to
  554. (Q*u, Z*v), where (u,v) are eigenvectors of the generalized
  555. Schur form (S,T), Q and Z are orthogonal matrices. In order
  556. to avoid using extra 2*N*N workspace, we have to recalculate
  557. eigenvectors and estimate one condition numbers at a time. */
  558. pair = FALSE_;
  559. i__1 = *n;
  560. for (i__ = 1; i__ <= i__1; ++i__) {
  561. if (pair) {
  562. pair = FALSE_;
  563. goto L20;
  564. }
  565. mm = 1;
  566. if (i__ < *n) {
  567. if (a_ref(i__ + 1, i__) != 0.) {
  568. pair = TRUE_;
  569. mm = 2;
  570. }
  571. }
  572. i__2 = *n;
  573. for (j = 1; j <= i__2; ++j) {
  574. bwork[j] = FALSE_;
  575. /* L10: */
  576. }
  577. if (mm == 1) {
  578. bwork[i__] = TRUE_;
  579. } else if (mm == 2) {
  580. bwork[i__] = TRUE_;
  581. bwork[i__ + 1] = TRUE_;
  582. }
  583. iwrk = mm * *n + 1;
  584. iwrk1 = iwrk + mm * *n;
  585. /* Compute a pair of left and right eigenvectors.
  586. (compute workspace: need up to 4*N + 6*N) */
  587. if (wantse || wantsb) {
  588. dtgevc_("B", "S", &bwork[1], n, &a[a_offset], lda, &b[
  589. b_offset], ldb, &work[1], n, &work[iwrk], n, &mm,
  590. &m, &work[iwrk1], &ierr);
  591. if (ierr != 0) {
  592. *info = *n + 2;
  593. goto L130;
  594. }
  595. }
  596. i__2 = *lwork - iwrk1 + 1;
  597. dtgsna_(sense, "S", &bwork[1], n, &a[a_offset], lda, &b[
  598. b_offset], ldb, &work[1], n, &work[iwrk], n, &rconde[
  599. i__], &rcondv[i__], &mm, &m, &work[iwrk1], &i__2, &
  600. iwork[1], &ierr);
  601. L20:
  602. ;
  603. }
  604. }
  605. }
  606. /* Undo balancing on VL and VR and normalization
  607. (Workspace: none needed) */
  608. if (ilvl) {
  609. dggbak_(balanc, "L", n, ilo, ihi, &lscale[1], &rscale[1], n, &vl[
  610. vl_offset], ldvl, &ierr);
  611. i__1 = *n;
  612. for (jc = 1; jc <= i__1; ++jc) {
  613. if (alphai[jc] < 0.) {
  614. goto L70;
  615. }
  616. temp = 0.;
  617. if (alphai[jc] == 0.) {
  618. i__2 = *n;
  619. for (jr = 1; jr <= i__2; ++jr) {
  620. /* Computing MAX */
  621. d__2 = temp, d__3 = (d__1 = vl_ref(jr, jc), abs(d__1));
  622. temp = max(d__2,d__3);
  623. /* L30: */
  624. }
  625. } else {
  626. i__2 = *n;
  627. for (jr = 1; jr <= i__2; ++jr) {
  628. /* Computing MAX */
  629. d__3 = temp, d__4 = (d__1 = vl_ref(jr, jc), abs(d__1)) + (
  630. d__2 = vl_ref(jr, jc + 1), abs(d__2));
  631. temp = max(d__3,d__4);
  632. /* L40: */
  633. }
  634. }
  635. if (temp < smlnum) {
  636. goto L70;
  637. }
  638. temp = 1. / temp;
  639. if (alphai[jc] == 0.) {
  640. i__2 = *n;
  641. for (jr = 1; jr <= i__2; ++jr) {
  642. vl_ref(jr, jc) = vl_ref(jr, jc) * temp;
  643. /* L50: */
  644. }
  645. } else {
  646. i__2 = *n;
  647. for (jr = 1; jr <= i__2; ++jr) {
  648. vl_ref(jr, jc) = vl_ref(jr, jc) * temp;
  649. vl_ref(jr, jc + 1) = vl_ref(jr, jc + 1) * temp;
  650. /* L60: */
  651. }
  652. }
  653. L70:
  654. ;
  655. }
  656. }
  657. if (ilvr) {
  658. dggbak_(balanc, "R", n, ilo, ihi, &lscale[1], &rscale[1], n, &vr[
  659. vr_offset], ldvr, &ierr);
  660. i__1 = *n;
  661. for (jc = 1; jc <= i__1; ++jc) {
  662. if (alphai[jc] < 0.) {
  663. goto L120;
  664. }
  665. temp = 0.;
  666. if (alphai[jc] == 0.) {
  667. i__2 = *n;
  668. for (jr = 1; jr <= i__2; ++jr) {
  669. /* Computing MAX */
  670. d__2 = temp, d__3 = (d__1 = vr_ref(jr, jc), abs(d__1));
  671. temp = max(d__2,d__3);
  672. /* L80: */
  673. }
  674. } else {
  675. i__2 = *n;
  676. for (jr = 1; jr <= i__2; ++jr) {
  677. /* Computing MAX */
  678. d__3 = temp, d__4 = (d__1 = vr_ref(jr, jc), abs(d__1)) + (
  679. d__2 = vr_ref(jr, jc + 1), abs(d__2));
  680. temp = max(d__3,d__4);
  681. /* L90: */
  682. }
  683. }
  684. if (temp < smlnum) {
  685. goto L120;
  686. }
  687. temp = 1. / temp;
  688. if (alphai[jc] == 0.) {
  689. i__2 = *n;
  690. for (jr = 1; jr <= i__2; ++jr) {
  691. vr_ref(jr, jc) = vr_ref(jr, jc) * temp;
  692. /* L100: */
  693. }
  694. } else {
  695. i__2 = *n;
  696. for (jr = 1; jr <= i__2; ++jr) {
  697. vr_ref(jr, jc) = vr_ref(jr, jc) * temp;
  698. vr_ref(jr, jc + 1) = vr_ref(jr, jc + 1) * temp;
  699. /* L110: */
  700. }
  701. }
  702. L120:
  703. ;
  704. }
  705. }
  706. /* Undo scaling if necessary */
  707. if (ilascl) {
  708. dlascl_("G", &c__0, &c__0, &anrmto, &anrm, n, &c__1, &alphar[1], n, &
  709. ierr);
  710. dlascl_("G", &c__0, &c__0, &anrmto, &anrm, n, &c__1, &alphai[1], n, &
  711. ierr);
  712. }
  713. if (ilbscl) {
  714. dlascl_("G", &c__0, &c__0, &bnrmto, &bnrm, n, &c__1, &beta[1], n, &
  715. ierr);
  716. }
  717. L130:
  718. work[1] = (doublereal) maxwrk;
  719. return 0;
  720. /* End of DGGEVX */
  721. } /* dggevx_ */
  722. #undef vr_ref
  723. #undef vl_ref
  724. #undef b_ref
  725. #undef a_ref