dggevx.c
Go to the documentation of this file.
00001 /* dggevx.f -- translated by f2c (version 20061008).
00002    You must link the resulting object file with libf2c:
00003         on Microsoft Windows system, link with libf2c.lib;
00004         on Linux or Unix systems, link with .../path/to/libf2c.a -lm
00005         or, if you install libf2c.a in a standard place, with -lf2c -lm
00006         -- in that order, at the end of the command line, as in
00007                 cc *.o -lf2c -lm
00008         Source for libf2c is in /netlib/f2c/libf2c.zip, e.g.,
00009 
00010                 http://www.netlib.org/f2c/libf2c.zip
00011 */
00012 
00013 #include "f2c.h"
00014 #include "blaswrap.h"
00015 
00016 /* Table of constant values */
00017 
00018 static integer c__1 = 1;
00019 static integer c__0 = 0;
00020 static doublereal c_b59 = 0.;
00021 static doublereal c_b60 = 1.;
00022 
00023 /* Subroutine */ int dggevx_(char *balanc, char *jobvl, char *jobvr, char *
00024         sense, integer *n, doublereal *a, integer *lda, doublereal *b, 
00025         integer *ldb, doublereal *alphar, doublereal *alphai, doublereal *
00026         beta, doublereal *vl, integer *ldvl, doublereal *vr, integer *ldvr, 
00027         integer *ilo, integer *ihi, doublereal *lscale, doublereal *rscale, 
00028         doublereal *abnrm, doublereal *bbnrm, doublereal *rconde, doublereal *
00029         rcondv, doublereal *work, integer *lwork, integer *iwork, logical *
00030         bwork, integer *info)
00031 {
00032     /* System generated locals */
00033     integer a_dim1, a_offset, b_dim1, b_offset, vl_dim1, vl_offset, vr_dim1, 
00034             vr_offset, i__1, i__2;
00035     doublereal d__1, d__2, d__3, d__4;
00036 
00037     /* Builtin functions */
00038     double sqrt(doublereal);
00039 
00040     /* Local variables */
00041     integer i__, j, m, jc, in, mm, jr;
00042     doublereal eps;
00043     logical ilv, pair;
00044     doublereal anrm, bnrm;
00045     integer ierr, itau;
00046     doublereal temp;
00047     logical ilvl, ilvr;
00048     integer iwrk, iwrk1;
00049     extern logical lsame_(char *, char *);
00050     integer icols;
00051     logical noscl;
00052     integer irows;
00053     extern /* Subroutine */ int dlabad_(doublereal *, doublereal *), dggbak_(
00054             char *, char *, integer *, integer *, integer *, doublereal *, 
00055             doublereal *, integer *, doublereal *, integer *, integer *), dggbal_(char *, integer *, doublereal *, integer 
00056             *, doublereal *, integer *, integer *, integer *, doublereal *, 
00057             doublereal *, doublereal *, integer *);
00058     extern doublereal dlamch_(char *), dlange_(char *, integer *, 
00059             integer *, doublereal *, integer *, doublereal *);
00060     extern /* Subroutine */ int dgghrd_(char *, char *, integer *, integer *, 
00061             integer *, doublereal *, integer *, doublereal *, integer *, 
00062             doublereal *, integer *, doublereal *, integer *, integer *), dlascl_(char *, integer *, integer *, doublereal 
00063             *, doublereal *, integer *, integer *, doublereal *, integer *, 
00064             integer *);
00065     logical ilascl, ilbscl;
00066     extern /* Subroutine */ int dgeqrf_(integer *, integer *, doublereal *, 
00067             integer *, doublereal *, doublereal *, integer *, integer *), 
00068             dlacpy_(char *, integer *, integer *, doublereal *, integer *, 
00069             doublereal *, integer *), dlaset_(char *, integer *, 
00070             integer *, doublereal *, doublereal *, doublereal *, integer *);
00071     logical ldumma[1];
00072     char chtemp[1];
00073     doublereal bignum;
00074     extern /* Subroutine */ int dhgeqz_(char *, char *, char *, integer *, 
00075             integer *, integer *, doublereal *, integer *, doublereal *, 
00076             integer *, doublereal *, doublereal *, doublereal *, doublereal *, 
00077              integer *, doublereal *, integer *, doublereal *, integer *, 
00078             integer *), dtgevc_(char *, char *, 
00079             logical *, integer *, doublereal *, integer *, doublereal *, 
00080             integer *, doublereal *, integer *, doublereal *, integer *, 
00081             integer *, integer *, doublereal *, integer *);
00082     integer ijobvl;
00083     extern /* Subroutine */ int dtgsna_(char *, char *, logical *, integer *, 
00084             doublereal *, integer *, doublereal *, integer *, doublereal *, 
00085             integer *, doublereal *, integer *, doublereal *, doublereal *, 
00086             integer *, integer *, doublereal *, integer *, integer *, integer 
00087             *), xerbla_(char *, integer *);
00088     extern integer ilaenv_(integer *, char *, char *, integer *, integer *, 
00089             integer *, integer *);
00090     integer ijobvr;
00091     logical wantsb;
00092     extern /* Subroutine */ int dorgqr_(integer *, integer *, integer *, 
00093             doublereal *, integer *, doublereal *, doublereal *, integer *, 
00094             integer *);
00095     doublereal anrmto;
00096     logical wantse;
00097     doublereal bnrmto;
00098     extern /* Subroutine */ int dormqr_(char *, char *, integer *, integer *, 
00099             integer *, doublereal *, integer *, doublereal *, doublereal *, 
00100             integer *, doublereal *, integer *, integer *);
00101     integer minwrk, maxwrk;
00102     logical wantsn;
00103     doublereal smlnum;
00104     logical lquery, wantsv;
00105 
00106 
00107 /*  -- LAPACK driver routine (version 3.2) -- */
00108 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00109 /*     November 2006 */
00110 
00111 /*     .. Scalar Arguments .. */
00112 /*     .. */
00113 /*     .. Array Arguments .. */
00114 /*     .. */
00115 
00116 /*  Purpose */
00117 /*  ======= */
00118 
00119 /*  DGGEVX computes for a pair of N-by-N real nonsymmetric matrices (A,B) */
00120 /*  the generalized eigenvalues, and optionally, the left and/or right */
00121 /*  generalized eigenvectors. */
00122 
00123 /*  Optionally also, it computes a balancing transformation to improve */
00124 /*  the conditioning of the eigenvalues and eigenvectors (ILO, IHI, */
00125 /*  LSCALE, RSCALE, ABNRM, and BBNRM), reciprocal condition numbers for */
00126 /*  the eigenvalues (RCONDE), and reciprocal condition numbers for the */
00127 /*  right eigenvectors (RCONDV). */
00128 
00129 /*  A generalized eigenvalue for a pair of matrices (A,B) is a scalar */
00130 /*  lambda or a ratio alpha/beta = lambda, such that A - lambda*B is */
00131 /*  singular. It is usually represented as the pair (alpha,beta), as */
00132 /*  there is a reasonable interpretation for beta=0, and even for both */
00133 /*  being zero. */
00134 
00135 /*  The right eigenvector v(j) corresponding to the eigenvalue lambda(j) */
00136 /*  of (A,B) satisfies */
00137 
00138 /*                   A * v(j) = lambda(j) * B * v(j) . */
00139 
00140 /*  The left eigenvector u(j) corresponding to the eigenvalue lambda(j) */
00141 /*  of (A,B) satisfies */
00142 
00143 /*                   u(j)**H * A  = lambda(j) * u(j)**H * B. */
00144 
00145 /*  where u(j)**H is the conjugate-transpose of u(j). */
00146 
00147 
00148 /*  Arguments */
00149 /*  ========= */
00150 
00151 /*  BALANC  (input) CHARACTER*1 */
00152 /*          Specifies the balance option to be performed. */
00153 /*          = 'N':  do not diagonally scale or permute; */
00154 /*          = 'P':  permute only; */
00155 /*          = 'S':  scale only; */
00156 /*          = 'B':  both permute and scale. */
00157 /*          Computed reciprocal condition numbers will be for the */
00158 /*          matrices after permuting and/or balancing. Permuting does */
00159 /*          not change condition numbers (in exact arithmetic), but */
00160 /*          balancing does. */
00161 
00162 /*  JOBVL   (input) CHARACTER*1 */
00163 /*          = 'N':  do not compute the left generalized eigenvectors; */
00164 /*          = 'V':  compute the left generalized eigenvectors. */
00165 
00166 /*  JOBVR   (input) CHARACTER*1 */
00167 /*          = 'N':  do not compute the right generalized eigenvectors; */
00168 /*          = 'V':  compute the right generalized eigenvectors. */
00169 
00170 /*  SENSE   (input) CHARACTER*1 */
00171 /*          Determines which reciprocal condition numbers are computed. */
00172 /*          = 'N': none are computed; */
00173 /*          = 'E': computed for eigenvalues only; */
00174 /*          = 'V': computed for eigenvectors only; */
00175 /*          = 'B': computed for eigenvalues and eigenvectors. */
00176 
00177 /*  N       (input) INTEGER */
00178 /*          The order of the matrices A, B, VL, and VR.  N >= 0. */
00179 
00180 /*  A       (input/output) DOUBLE PRECISION array, dimension (LDA, N) */
00181 /*          On entry, the matrix A in the pair (A,B). */
00182 /*          On exit, A has been overwritten. If JOBVL='V' or JOBVR='V' */
00183 /*          or both, then A contains the first part of the real Schur */
00184 /*          form of the "balanced" versions of the input A and B. */
00185 
00186 /*  LDA     (input) INTEGER */
00187 /*          The leading dimension of A.  LDA >= max(1,N). */
00188 
00189 /*  B       (input/output) DOUBLE PRECISION array, dimension (LDB, N) */
00190 /*          On entry, the matrix B in the pair (A,B). */
00191 /*          On exit, B has been overwritten. If JOBVL='V' or JOBVR='V' */
00192 /*          or both, then B contains the second part of the real Schur */
00193 /*          form of the "balanced" versions of the input A and B. */
00194 
00195 /*  LDB     (input) INTEGER */
00196 /*          The leading dimension of B.  LDB >= max(1,N). */
00197 
00198 /*  ALPHAR  (output) DOUBLE PRECISION array, dimension (N) */
00199 /*  ALPHAI  (output) DOUBLE PRECISION array, dimension (N) */
00200 /*  BETA    (output) DOUBLE PRECISION array, dimension (N) */
00201 /*          On exit, (ALPHAR(j) + ALPHAI(j)*i)/BETA(j), j=1,...,N, will */
00202 /*          be the generalized eigenvalues.  If ALPHAI(j) is zero, then */
00203 /*          the j-th eigenvalue is real; if positive, then the j-th and */
00204 /*          (j+1)-st eigenvalues are a complex conjugate pair, with */
00205 /*          ALPHAI(j+1) negative. */
00206 
00207 /*          Note: the quotients ALPHAR(j)/BETA(j) and ALPHAI(j)/BETA(j) */
00208 /*          may easily over- or underflow, and BETA(j) may even be zero. */
00209 /*          Thus, the user should avoid naively computing the ratio */
00210 /*          ALPHA/BETA. However, ALPHAR and ALPHAI will be always less */
00211 /*          than and usually comparable with norm(A) in magnitude, and */
00212 /*          BETA always less than and usually comparable with norm(B). */
00213 
00214 /*  VL      (output) DOUBLE PRECISION array, dimension (LDVL,N) */
00215 /*          If JOBVL = 'V', the left eigenvectors u(j) are stored one */
00216 /*          after another in the columns of VL, in the same order as */
00217 /*          their eigenvalues. If the j-th eigenvalue is real, then */
00218 /*          u(j) = VL(:,j), the j-th column of VL. If the j-th and */
00219 /*          (j+1)-th eigenvalues form a complex conjugate pair, then */
00220 /*          u(j) = VL(:,j)+i*VL(:,j+1) and u(j+1) = VL(:,j)-i*VL(:,j+1). */
00221 /*          Each eigenvector will be scaled so the largest component have */
00222 /*          abs(real part) + abs(imag. part) = 1. */
00223 /*          Not referenced if JOBVL = 'N'. */
00224 
00225 /*  LDVL    (input) INTEGER */
00226 /*          The leading dimension of the matrix VL. LDVL >= 1, and */
00227 /*          if JOBVL = 'V', LDVL >= N. */
00228 
00229 /*  VR      (output) DOUBLE PRECISION array, dimension (LDVR,N) */
00230 /*          If JOBVR = 'V', the right eigenvectors v(j) are stored one */
00231 /*          after another in the columns of VR, in the same order as */
00232 /*          their eigenvalues. If the j-th eigenvalue is real, then */
00233 /*          v(j) = VR(:,j), the j-th column of VR. If the j-th and */
00234 /*          (j+1)-th eigenvalues form a complex conjugate pair, then */
00235 /*          v(j) = VR(:,j)+i*VR(:,j+1) and v(j+1) = VR(:,j)-i*VR(:,j+1). */
00236 /*          Each eigenvector will be scaled so the largest component have */
00237 /*          abs(real part) + abs(imag. part) = 1. */
00238 /*          Not referenced if JOBVR = 'N'. */
00239 
00240 /*  LDVR    (input) INTEGER */
00241 /*          The leading dimension of the matrix VR. LDVR >= 1, and */
00242 /*          if JOBVR = 'V', LDVR >= N. */
00243 
00244 /*  ILO     (output) INTEGER */
00245 /*  IHI     (output) INTEGER */
00246 /*          ILO and IHI are integer values such that on exit */
00247 /*          A(i,j) = 0 and B(i,j) = 0 if i > j and */
00248 /*          j = 1,...,ILO-1 or i = IHI+1,...,N. */
00249 /*          If BALANC = 'N' or 'S', ILO = 1 and IHI = N. */
00250 
00251 /*  LSCALE  (output) DOUBLE PRECISION array, dimension (N) */
00252 /*          Details of the permutations and scaling factors applied */
00253 /*          to the left side of A and B.  If PL(j) is the index of the */
00254 /*          row interchanged with row j, and DL(j) is the scaling */
00255 /*          factor applied to row j, then */
00256 /*            LSCALE(j) = PL(j)  for j = 1,...,ILO-1 */
00257 /*                      = DL(j)  for j = ILO,...,IHI */
00258 /*                      = PL(j)  for j = IHI+1,...,N. */
00259 /*          The order in which the interchanges are made is N to IHI+1, */
00260 /*          then 1 to ILO-1. */
00261 
00262 /*  RSCALE  (output) DOUBLE PRECISION array, dimension (N) */
00263 /*          Details of the permutations and scaling factors applied */
00264 /*          to the right side of A and B.  If PR(j) is the index of the */
00265 /*          column interchanged with column j, and DR(j) is the scaling */
00266 /*          factor applied to column j, then */
00267 /*            RSCALE(j) = PR(j)  for j = 1,...,ILO-1 */
00268 /*                      = DR(j)  for j = ILO,...,IHI */
00269 /*                      = PR(j)  for j = IHI+1,...,N */
00270 /*          The order in which the interchanges are made is N to IHI+1, */
00271 /*          then 1 to ILO-1. */
00272 
00273 /*  ABNRM   (output) DOUBLE PRECISION */
00274 /*          The one-norm of the balanced matrix A. */
00275 
00276 /*  BBNRM   (output) DOUBLE PRECISION */
00277 /*          The one-norm of the balanced matrix B. */
00278 
00279 /*  RCONDE  (output) DOUBLE PRECISION array, dimension (N) */
00280 /*          If SENSE = 'E' or 'B', the reciprocal condition numbers of */
00281 /*          the eigenvalues, stored in consecutive elements of the array. */
00282 /*          For a complex conjugate pair of eigenvalues two consecutive */
00283 /*          elements of RCONDE are set to the same value. Thus RCONDE(j), */
00284 /*          RCONDV(j), and the j-th columns of VL and VR all correspond */
00285 /*          to the j-th eigenpair. */
00286 /*          If SENSE = 'N or 'V', RCONDE is not referenced. */
00287 
00288 /*  RCONDV  (output) DOUBLE PRECISION array, dimension (N) */
00289 /*          If SENSE = 'V' or 'B', the estimated reciprocal condition */
00290 /*          numbers of the eigenvectors, stored in consecutive elements */
00291 /*          of the array. For a complex eigenvector two consecutive */
00292 /*          elements of RCONDV are set to the same value. If the */
00293 /*          eigenvalues cannot be reordered to compute RCONDV(j), */
00294 /*          RCONDV(j) is set to 0; this can only occur when the true */
00295 /*          value would be very small anyway. */
00296 /*          If SENSE = 'N' or 'E', RCONDV is not referenced. */
00297 
00298 /*  WORK    (workspace/output) DOUBLE PRECISION array, dimension (MAX(1,LWORK)) */
00299 /*          On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
00300 
00301 /*  LWORK   (input) INTEGER */
00302 /*          The dimension of the array WORK. LWORK >= max(1,2*N). */
00303 /*          If BALANC = 'S' or 'B', or JOBVL = 'V', or JOBVR = 'V', */
00304 /*          LWORK >= max(1,6*N). */
00305 /*          If SENSE = 'E' or 'B', LWORK >= max(1,10*N). */
00306 /*          If SENSE = 'V' or 'B', LWORK >= 2*N*N+8*N+16. */
00307 
00308 /*          If LWORK = -1, then a workspace query is assumed; the routine */
00309 /*          only calculates the optimal size of the WORK array, returns */
00310 /*          this value as the first entry of the WORK array, and no error */
00311 /*          message related to LWORK is issued by XERBLA. */
00312 
00313 /*  IWORK   (workspace) INTEGER array, dimension (N+6) */
00314 /*          If SENSE = 'E', IWORK is not referenced. */
00315 
00316 /*  BWORK   (workspace) LOGICAL array, dimension (N) */
00317 /*          If SENSE = 'N', BWORK is not referenced. */
00318 
00319 /*  INFO    (output) INTEGER */
00320 /*          = 0:  successful exit */
00321 /*          < 0:  if INFO = -i, the i-th argument had an illegal value. */
00322 /*          = 1,...,N: */
00323 /*                The QZ iteration failed.  No eigenvectors have been */
00324 /*                calculated, but ALPHAR(j), ALPHAI(j), and BETA(j) */
00325 /*                should be correct for j=INFO+1,...,N. */
00326 /*          > N:  =N+1: other than QZ iteration failed in DHGEQZ. */
00327 /*                =N+2: error return from DTGEVC. */
00328 
00329 /*  Further Details */
00330 /*  =============== */
00331 
00332 /*  Balancing a matrix pair (A,B) includes, first, permuting rows and */
00333 /*  columns to isolate eigenvalues, second, applying diagonal similarity */
00334 /*  transformation to the rows and columns to make the rows and columns */
00335 /*  as close in norm as possible. The computed reciprocal condition */
00336 /*  numbers correspond to the balanced matrix. Permuting rows and columns */
00337 /*  will not change the condition numbers (in exact arithmetic) but */
00338 /*  diagonal scaling will.  For further explanation of balancing, see */
00339 /*  section 4.11.1.2 of LAPACK Users' Guide. */
00340 
00341 /*  An approximate error bound on the chordal distance between the i-th */
00342 /*  computed generalized eigenvalue w and the corresponding exact */
00343 /*  eigenvalue lambda is */
00344 
00345 /*       chord(w, lambda) <= EPS * norm(ABNRM, BBNRM) / RCONDE(I) */
00346 
00347 /*  An approximate error bound for the angle between the i-th computed */
00348 /*  eigenvector VL(i) or VR(i) is given by */
00349 
00350 /*       EPS * norm(ABNRM, BBNRM) / DIF(i). */
00351 
00352 /*  For further explanation of the reciprocal condition numbers RCONDE */
00353 /*  and RCONDV, see section 4.11 of LAPACK User's Guide. */
00354 
00355 /*  ===================================================================== */
00356 
00357 /*     .. Parameters .. */
00358 /*     .. */
00359 /*     .. Local Scalars .. */
00360 /*     .. */
00361 /*     .. Local Arrays .. */
00362 /*     .. */
00363 /*     .. External Subroutines .. */
00364 /*     .. */
00365 /*     .. External Functions .. */
00366 /*     .. */
00367 /*     .. Intrinsic Functions .. */
00368 /*     .. */
00369 /*     .. Executable Statements .. */
00370 
00371 /*     Decode the input arguments */
00372 
00373     /* Parameter adjustments */
00374     a_dim1 = *lda;
00375     a_offset = 1 + a_dim1;
00376     a -= a_offset;
00377     b_dim1 = *ldb;
00378     b_offset = 1 + b_dim1;
00379     b -= b_offset;
00380     --alphar;
00381     --alphai;
00382     --beta;
00383     vl_dim1 = *ldvl;
00384     vl_offset = 1 + vl_dim1;
00385     vl -= vl_offset;
00386     vr_dim1 = *ldvr;
00387     vr_offset = 1 + vr_dim1;
00388     vr -= vr_offset;
00389     --lscale;
00390     --rscale;
00391     --rconde;
00392     --rcondv;
00393     --work;
00394     --iwork;
00395     --bwork;
00396 
00397     /* Function Body */
00398     if (lsame_(jobvl, "N")) {
00399         ijobvl = 1;
00400         ilvl = FALSE_;
00401     } else if (lsame_(jobvl, "V")) {
00402         ijobvl = 2;
00403         ilvl = TRUE_;
00404     } else {
00405         ijobvl = -1;
00406         ilvl = FALSE_;
00407     }
00408 
00409     if (lsame_(jobvr, "N")) {
00410         ijobvr = 1;
00411         ilvr = FALSE_;
00412     } else if (lsame_(jobvr, "V")) {
00413         ijobvr = 2;
00414         ilvr = TRUE_;
00415     } else {
00416         ijobvr = -1;
00417         ilvr = FALSE_;
00418     }
00419     ilv = ilvl || ilvr;
00420 
00421     noscl = lsame_(balanc, "N") || lsame_(balanc, "P");
00422     wantsn = lsame_(sense, "N");
00423     wantse = lsame_(sense, "E");
00424     wantsv = lsame_(sense, "V");
00425     wantsb = lsame_(sense, "B");
00426 
00427 /*     Test the input arguments */
00428 
00429     *info = 0;
00430     lquery = *lwork == -1;
00431     if (! (lsame_(balanc, "N") || lsame_(balanc, "S") || lsame_(balanc, "P") 
00432             || lsame_(balanc, "B"))) {
00433         *info = -1;
00434     } else if (ijobvl <= 0) {
00435         *info = -2;
00436     } else if (ijobvr <= 0) {
00437         *info = -3;
00438     } else if (! (wantsn || wantse || wantsb || wantsv)) {
00439         *info = -4;
00440     } else if (*n < 0) {
00441         *info = -5;
00442     } else if (*lda < max(1,*n)) {
00443         *info = -7;
00444     } else if (*ldb < max(1,*n)) {
00445         *info = -9;
00446     } else if (*ldvl < 1 || ilvl && *ldvl < *n) {
00447         *info = -14;
00448     } else if (*ldvr < 1 || ilvr && *ldvr < *n) {
00449         *info = -16;
00450     }
00451 
00452 /*     Compute workspace */
00453 /*      (Note: Comments in the code beginning "Workspace:" describe the */
00454 /*       minimal amount of workspace needed at that point in the code, */
00455 /*       as well as the preferred amount for good performance. */
00456 /*       NB refers to the optimal block size for the immediately */
00457 /*       following subroutine, as returned by ILAENV. The workspace is */
00458 /*       computed assuming ILO = 1 and IHI = N, the worst case.) */
00459 
00460     if (*info == 0) {
00461         if (*n == 0) {
00462             minwrk = 1;
00463             maxwrk = 1;
00464         } else {
00465             if (noscl && ! ilv) {
00466                 minwrk = *n << 1;
00467             } else {
00468                 minwrk = *n * 6;
00469             }
00470             if (wantse || wantsb) {
00471                 minwrk = *n * 10;
00472             }
00473             if (wantsv || wantsb) {
00474 /* Computing MAX */
00475                 i__1 = minwrk, i__2 = (*n << 1) * (*n + 4) + 16;
00476                 minwrk = max(i__1,i__2);
00477             }
00478             maxwrk = minwrk;
00479 /* Computing MAX */
00480             i__1 = maxwrk, i__2 = *n + *n * ilaenv_(&c__1, "DGEQRF", " ", n, &
00481                     c__1, n, &c__0);
00482             maxwrk = max(i__1,i__2);
00483 /* Computing MAX */
00484             i__1 = maxwrk, i__2 = *n + *n * ilaenv_(&c__1, "DORMQR", " ", n, &
00485                     c__1, n, &c__0);
00486             maxwrk = max(i__1,i__2);
00487             if (ilvl) {
00488 /* Computing MAX */
00489                 i__1 = maxwrk, i__2 = *n + *n * ilaenv_(&c__1, "DORGQR", 
00490                         " ", n, &c__1, n, &c__0);
00491                 maxwrk = max(i__1,i__2);
00492             }
00493         }
00494         work[1] = (doublereal) maxwrk;
00495 
00496         if (*lwork < minwrk && ! lquery) {
00497             *info = -26;
00498         }
00499     }
00500 
00501     if (*info != 0) {
00502         i__1 = -(*info);
00503         xerbla_("DGGEVX", &i__1);
00504         return 0;
00505     } else if (lquery) {
00506         return 0;
00507     }
00508 
00509 /*     Quick return if possible */
00510 
00511     if (*n == 0) {
00512         return 0;
00513     }
00514 
00515 
00516 /*     Get machine constants */
00517 
00518     eps = dlamch_("P");
00519     smlnum = dlamch_("S");
00520     bignum = 1. / smlnum;
00521     dlabad_(&smlnum, &bignum);
00522     smlnum = sqrt(smlnum) / eps;
00523     bignum = 1. / smlnum;
00524 
00525 /*     Scale A if max element outside range [SMLNUM,BIGNUM] */
00526 
00527     anrm = dlange_("M", n, n, &a[a_offset], lda, &work[1]);
00528     ilascl = FALSE_;
00529     if (anrm > 0. && anrm < smlnum) {
00530         anrmto = smlnum;
00531         ilascl = TRUE_;
00532     } else if (anrm > bignum) {
00533         anrmto = bignum;
00534         ilascl = TRUE_;
00535     }
00536     if (ilascl) {
00537         dlascl_("G", &c__0, &c__0, &anrm, &anrmto, n, n, &a[a_offset], lda, &
00538                 ierr);
00539     }
00540 
00541 /*     Scale B if max element outside range [SMLNUM,BIGNUM] */
00542 
00543     bnrm = dlange_("M", n, n, &b[b_offset], ldb, &work[1]);
00544     ilbscl = FALSE_;
00545     if (bnrm > 0. && bnrm < smlnum) {
00546         bnrmto = smlnum;
00547         ilbscl = TRUE_;
00548     } else if (bnrm > bignum) {
00549         bnrmto = bignum;
00550         ilbscl = TRUE_;
00551     }
00552     if (ilbscl) {
00553         dlascl_("G", &c__0, &c__0, &bnrm, &bnrmto, n, n, &b[b_offset], ldb, &
00554                 ierr);
00555     }
00556 
00557 /*     Permute and/or balance the matrix pair (A,B) */
00558 /*     (Workspace: need 6*N if BALANC = 'S' or 'B', 1 otherwise) */
00559 
00560     dggbal_(balanc, n, &a[a_offset], lda, &b[b_offset], ldb, ilo, ihi, &
00561             lscale[1], &rscale[1], &work[1], &ierr);
00562 
00563 /*     Compute ABNRM and BBNRM */
00564 
00565     *abnrm = dlange_("1", n, n, &a[a_offset], lda, &work[1]);
00566     if (ilascl) {
00567         work[1] = *abnrm;
00568         dlascl_("G", &c__0, &c__0, &anrmto, &anrm, &c__1, &c__1, &work[1], &
00569                 c__1, &ierr);
00570         *abnrm = work[1];
00571     }
00572 
00573     *bbnrm = dlange_("1", n, n, &b[b_offset], ldb, &work[1]);
00574     if (ilbscl) {
00575         work[1] = *bbnrm;
00576         dlascl_("G", &c__0, &c__0, &bnrmto, &bnrm, &c__1, &c__1, &work[1], &
00577                 c__1, &ierr);
00578         *bbnrm = work[1];
00579     }
00580 
00581 /*     Reduce B to triangular form (QR decomposition of B) */
00582 /*     (Workspace: need N, prefer N*NB ) */
00583 
00584     irows = *ihi + 1 - *ilo;
00585     if (ilv || ! wantsn) {
00586         icols = *n + 1 - *ilo;
00587     } else {
00588         icols = irows;
00589     }
00590     itau = 1;
00591     iwrk = itau + irows;
00592     i__1 = *lwork + 1 - iwrk;
00593     dgeqrf_(&irows, &icols, &b[*ilo + *ilo * b_dim1], ldb, &work[itau], &work[
00594             iwrk], &i__1, &ierr);
00595 
00596 /*     Apply the orthogonal transformation to A */
00597 /*     (Workspace: need N, prefer N*NB) */
00598 
00599     i__1 = *lwork + 1 - iwrk;
00600     dormqr_("L", "T", &irows, &icols, &irows, &b[*ilo + *ilo * b_dim1], ldb, &
00601             work[itau], &a[*ilo + *ilo * a_dim1], lda, &work[iwrk], &i__1, &
00602             ierr);
00603 
00604 /*     Initialize VL and/or VR */
00605 /*     (Workspace: need N, prefer N*NB) */
00606 
00607     if (ilvl) {
00608         dlaset_("Full", n, n, &c_b59, &c_b60, &vl[vl_offset], ldvl)
00609                 ;
00610         if (irows > 1) {
00611             i__1 = irows - 1;
00612             i__2 = irows - 1;
00613             dlacpy_("L", &i__1, &i__2, &b[*ilo + 1 + *ilo * b_dim1], ldb, &vl[
00614                     *ilo + 1 + *ilo * vl_dim1], ldvl);
00615         }
00616         i__1 = *lwork + 1 - iwrk;
00617         dorgqr_(&irows, &irows, &irows, &vl[*ilo + *ilo * vl_dim1], ldvl, &
00618                 work[itau], &work[iwrk], &i__1, &ierr);
00619     }
00620 
00621     if (ilvr) {
00622         dlaset_("Full", n, n, &c_b59, &c_b60, &vr[vr_offset], ldvr)
00623                 ;
00624     }
00625 
00626 /*     Reduce to generalized Hessenberg form */
00627 /*     (Workspace: none needed) */
00628 
00629     if (ilv || ! wantsn) {
00630 
00631 /*        Eigenvectors requested -- work on whole matrix. */
00632 
00633         dgghrd_(jobvl, jobvr, n, ilo, ihi, &a[a_offset], lda, &b[b_offset], 
00634                 ldb, &vl[vl_offset], ldvl, &vr[vr_offset], ldvr, &ierr);
00635     } else {
00636         dgghrd_("N", "N", &irows, &c__1, &irows, &a[*ilo + *ilo * a_dim1], 
00637                 lda, &b[*ilo + *ilo * b_dim1], ldb, &vl[vl_offset], ldvl, &vr[
00638                 vr_offset], ldvr, &ierr);
00639     }
00640 
00641 /*     Perform QZ algorithm (Compute eigenvalues, and optionally, the */
00642 /*     Schur forms and Schur vectors) */
00643 /*     (Workspace: need N) */
00644 
00645     if (ilv || ! wantsn) {
00646         *(unsigned char *)chtemp = 'S';
00647     } else {
00648         *(unsigned char *)chtemp = 'E';
00649     }
00650 
00651     dhgeqz_(chtemp, jobvl, jobvr, n, ilo, ihi, &a[a_offset], lda, &b[b_offset]
00652 , ldb, &alphar[1], &alphai[1], &beta[1], &vl[vl_offset], ldvl, &
00653             vr[vr_offset], ldvr, &work[1], lwork, &ierr);
00654     if (ierr != 0) {
00655         if (ierr > 0 && ierr <= *n) {
00656             *info = ierr;
00657         } else if (ierr > *n && ierr <= *n << 1) {
00658             *info = ierr - *n;
00659         } else {
00660             *info = *n + 1;
00661         }
00662         goto L130;
00663     }
00664 
00665 /*     Compute Eigenvectors and estimate condition numbers if desired */
00666 /*     (Workspace: DTGEVC: need 6*N */
00667 /*                 DTGSNA: need 2*N*(N+2)+16 if SENSE = 'V' or 'B', */
00668 /*                         need N otherwise ) */
00669 
00670     if (ilv || ! wantsn) {
00671         if (ilv) {
00672             if (ilvl) {
00673                 if (ilvr) {
00674                     *(unsigned char *)chtemp = 'B';
00675                 } else {
00676                     *(unsigned char *)chtemp = 'L';
00677                 }
00678             } else {
00679                 *(unsigned char *)chtemp = 'R';
00680             }
00681 
00682             dtgevc_(chtemp, "B", ldumma, n, &a[a_offset], lda, &b[b_offset], 
00683                     ldb, &vl[vl_offset], ldvl, &vr[vr_offset], ldvr, n, &in, &
00684                     work[1], &ierr);
00685             if (ierr != 0) {
00686                 *info = *n + 2;
00687                 goto L130;
00688             }
00689         }
00690 
00691         if (! wantsn) {
00692 
00693 /*           compute eigenvectors (DTGEVC) and estimate condition */
00694 /*           numbers (DTGSNA). Note that the definition of the condition */
00695 /*           number is not invariant under transformation (u,v) to */
00696 /*           (Q*u, Z*v), where (u,v) are eigenvectors of the generalized */
00697 /*           Schur form (S,T), Q and Z are orthogonal matrices. In order */
00698 /*           to avoid using extra 2*N*N workspace, we have to recalculate */
00699 /*           eigenvectors and estimate one condition numbers at a time. */
00700 
00701             pair = FALSE_;
00702             i__1 = *n;
00703             for (i__ = 1; i__ <= i__1; ++i__) {
00704 
00705                 if (pair) {
00706                     pair = FALSE_;
00707                     goto L20;
00708                 }
00709                 mm = 1;
00710                 if (i__ < *n) {
00711                     if (a[i__ + 1 + i__ * a_dim1] != 0.) {
00712                         pair = TRUE_;
00713                         mm = 2;
00714                     }
00715                 }
00716 
00717                 i__2 = *n;
00718                 for (j = 1; j <= i__2; ++j) {
00719                     bwork[j] = FALSE_;
00720 /* L10: */
00721                 }
00722                 if (mm == 1) {
00723                     bwork[i__] = TRUE_;
00724                 } else if (mm == 2) {
00725                     bwork[i__] = TRUE_;
00726                     bwork[i__ + 1] = TRUE_;
00727                 }
00728 
00729                 iwrk = mm * *n + 1;
00730                 iwrk1 = iwrk + mm * *n;
00731 
00732 /*              Compute a pair of left and right eigenvectors. */
00733 /*              (compute workspace: need up to 4*N + 6*N) */
00734 
00735                 if (wantse || wantsb) {
00736                     dtgevc_("B", "S", &bwork[1], n, &a[a_offset], lda, &b[
00737                             b_offset], ldb, &work[1], n, &work[iwrk], n, &mm, 
00738                             &m, &work[iwrk1], &ierr);
00739                     if (ierr != 0) {
00740                         *info = *n + 2;
00741                         goto L130;
00742                     }
00743                 }
00744 
00745                 i__2 = *lwork - iwrk1 + 1;
00746                 dtgsna_(sense, "S", &bwork[1], n, &a[a_offset], lda, &b[
00747                         b_offset], ldb, &work[1], n, &work[iwrk], n, &rconde[
00748                         i__], &rcondv[i__], &mm, &m, &work[iwrk1], &i__2, &
00749                         iwork[1], &ierr);
00750 
00751 L20:
00752                 ;
00753             }
00754         }
00755     }
00756 
00757 /*     Undo balancing on VL and VR and normalization */
00758 /*     (Workspace: none needed) */
00759 
00760     if (ilvl) {
00761         dggbak_(balanc, "L", n, ilo, ihi, &lscale[1], &rscale[1], n, &vl[
00762                 vl_offset], ldvl, &ierr);
00763 
00764         i__1 = *n;
00765         for (jc = 1; jc <= i__1; ++jc) {
00766             if (alphai[jc] < 0.) {
00767                 goto L70;
00768             }
00769             temp = 0.;
00770             if (alphai[jc] == 0.) {
00771                 i__2 = *n;
00772                 for (jr = 1; jr <= i__2; ++jr) {
00773 /* Computing MAX */
00774                     d__2 = temp, d__3 = (d__1 = vl[jr + jc * vl_dim1], abs(
00775                             d__1));
00776                     temp = max(d__2,d__3);
00777 /* L30: */
00778                 }
00779             } else {
00780                 i__2 = *n;
00781                 for (jr = 1; jr <= i__2; ++jr) {
00782 /* Computing MAX */
00783                     d__3 = temp, d__4 = (d__1 = vl[jr + jc * vl_dim1], abs(
00784                             d__1)) + (d__2 = vl[jr + (jc + 1) * vl_dim1], abs(
00785                             d__2));
00786                     temp = max(d__3,d__4);
00787 /* L40: */
00788                 }
00789             }
00790             if (temp < smlnum) {
00791                 goto L70;
00792             }
00793             temp = 1. / temp;
00794             if (alphai[jc] == 0.) {
00795                 i__2 = *n;
00796                 for (jr = 1; jr <= i__2; ++jr) {
00797                     vl[jr + jc * vl_dim1] *= temp;
00798 /* L50: */
00799                 }
00800             } else {
00801                 i__2 = *n;
00802                 for (jr = 1; jr <= i__2; ++jr) {
00803                     vl[jr + jc * vl_dim1] *= temp;
00804                     vl[jr + (jc + 1) * vl_dim1] *= temp;
00805 /* L60: */
00806                 }
00807             }
00808 L70:
00809             ;
00810         }
00811     }
00812     if (ilvr) {
00813         dggbak_(balanc, "R", n, ilo, ihi, &lscale[1], &rscale[1], n, &vr[
00814                 vr_offset], ldvr, &ierr);
00815         i__1 = *n;
00816         for (jc = 1; jc <= i__1; ++jc) {
00817             if (alphai[jc] < 0.) {
00818                 goto L120;
00819             }
00820             temp = 0.;
00821             if (alphai[jc] == 0.) {
00822                 i__2 = *n;
00823                 for (jr = 1; jr <= i__2; ++jr) {
00824 /* Computing MAX */
00825                     d__2 = temp, d__3 = (d__1 = vr[jr + jc * vr_dim1], abs(
00826                             d__1));
00827                     temp = max(d__2,d__3);
00828 /* L80: */
00829                 }
00830             } else {
00831                 i__2 = *n;
00832                 for (jr = 1; jr <= i__2; ++jr) {
00833 /* Computing MAX */
00834                     d__3 = temp, d__4 = (d__1 = vr[jr + jc * vr_dim1], abs(
00835                             d__1)) + (d__2 = vr[jr + (jc + 1) * vr_dim1], abs(
00836                             d__2));
00837                     temp = max(d__3,d__4);
00838 /* L90: */
00839                 }
00840             }
00841             if (temp < smlnum) {
00842                 goto L120;
00843             }
00844             temp = 1. / temp;
00845             if (alphai[jc] == 0.) {
00846                 i__2 = *n;
00847                 for (jr = 1; jr <= i__2; ++jr) {
00848                     vr[jr + jc * vr_dim1] *= temp;
00849 /* L100: */
00850                 }
00851             } else {
00852                 i__2 = *n;
00853                 for (jr = 1; jr <= i__2; ++jr) {
00854                     vr[jr + jc * vr_dim1] *= temp;
00855                     vr[jr + (jc + 1) * vr_dim1] *= temp;
00856 /* L110: */
00857                 }
00858             }
00859 L120:
00860             ;
00861         }
00862     }
00863 
00864 /*     Undo scaling if necessary */
00865 
00866     if (ilascl) {
00867         dlascl_("G", &c__0, &c__0, &anrmto, &anrm, n, &c__1, &alphar[1], n, &
00868                 ierr);
00869         dlascl_("G", &c__0, &c__0, &anrmto, &anrm, n, &c__1, &alphai[1], n, &
00870                 ierr);
00871     }
00872 
00873     if (ilbscl) {
00874         dlascl_("G", &c__0, &c__0, &bnrmto, &bnrm, n, &c__1, &beta[1], n, &
00875                 ierr);
00876     }
00877 
00878 L130:
00879     work[1] = (doublereal) maxwrk;
00880 
00881     return 0;
00882 
00883 /*     End of DGGEVX */
00884 
00885 } /* dggevx_ */


swiftnav
Author(s):
autogenerated on Sat Jun 8 2019 18:55:45