dggesx.c
Go to the documentation of this file.
00001 /* dggesx.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 integer c_n1 = -1;
00021 static doublereal c_b42 = 0.;
00022 static doublereal c_b43 = 1.;
00023 
00024 /* Subroutine */ int dggesx_(char *jobvsl, char *jobvsr, char *sort, L_fp 
00025         selctg, char *sense, integer *n, doublereal *a, integer *lda, 
00026         doublereal *b, integer *ldb, integer *sdim, doublereal *alphar, 
00027         doublereal *alphai, doublereal *beta, doublereal *vsl, integer *ldvsl, 
00028          doublereal *vsr, integer *ldvsr, doublereal *rconde, doublereal *
00029         rcondv, doublereal *work, integer *lwork, integer *iwork, integer *
00030         liwork, logical *bwork, integer *info)
00031 {
00032     /* System generated locals */
00033     integer a_dim1, a_offset, b_dim1, b_offset, vsl_dim1, vsl_offset, 
00034             vsr_dim1, vsr_offset, i__1, i__2;
00035     doublereal d__1;
00036 
00037     /* Builtin functions */
00038     double sqrt(doublereal);
00039 
00040     /* Local variables */
00041     integer i__, ip;
00042     doublereal pl, pr, dif[2];
00043     integer ihi, ilo;
00044     doublereal eps;
00045     integer ijob;
00046     doublereal anrm, bnrm;
00047     integer ierr, itau, iwrk, lwrk;
00048     extern logical lsame_(char *, char *);
00049     integer ileft, icols;
00050     logical cursl, ilvsl, ilvsr;
00051     integer irows;
00052     extern /* Subroutine */ int dlabad_(doublereal *, doublereal *), dggbak_(
00053             char *, char *, integer *, integer *, integer *, doublereal *, 
00054             doublereal *, integer *, doublereal *, integer *, integer *), dggbal_(char *, integer *, doublereal *, integer 
00055             *, doublereal *, integer *, integer *, integer *, doublereal *, 
00056             doublereal *, doublereal *, integer *);
00057     logical lst2sl;
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 *);
00070     doublereal safmin;
00071     extern /* Subroutine */ int dlaset_(char *, integer *, integer *, 
00072             doublereal *, doublereal *, doublereal *, integer *);
00073     doublereal safmax;
00074     extern /* Subroutine */ int xerbla_(char *, integer *);
00075     doublereal bignum;
00076     extern /* Subroutine */ int dhgeqz_(char *, char *, char *, integer *, 
00077             integer *, integer *, doublereal *, integer *, doublereal *, 
00078             integer *, doublereal *, doublereal *, doublereal *, doublereal *, 
00079              integer *, doublereal *, integer *, doublereal *, integer *, 
00080             integer *);
00081     integer ijobvl, iright;
00082     extern /* Subroutine */ int dtgsen_(integer *, logical *, logical *, 
00083             logical *, integer *, doublereal *, integer *, doublereal *, 
00084             integer *, doublereal *, doublereal *, doublereal *, doublereal *, 
00085              integer *, doublereal *, integer *, integer *, doublereal *, 
00086             doublereal *, doublereal *, doublereal *, integer *, integer *, 
00087             integer *, integer *);
00088     extern integer ilaenv_(integer *, char *, char *, integer *, integer *, 
00089             integer *, integer *);
00090     integer ijobvr;
00091     logical wantsb;
00092     integer liwmin;
00093     logical wantse, lastsl;
00094     doublereal anrmto, bnrmto;
00095     extern /* Subroutine */ int dorgqr_(integer *, integer *, integer *, 
00096             doublereal *, integer *, doublereal *, doublereal *, integer *, 
00097             integer *);
00098     integer minwrk, maxwrk;
00099     logical wantsn;
00100     doublereal smlnum;
00101     extern /* Subroutine */ int dormqr_(char *, char *, integer *, integer *, 
00102             integer *, doublereal *, integer *, doublereal *, doublereal *, 
00103             integer *, doublereal *, integer *, integer *);
00104     logical wantst, 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 /*     .. Function Arguments .. */
00116 /*     .. */
00117 
00118 /*  Purpose */
00119 /*  ======= */
00120 
00121 /*  DGGESX computes for a pair of N-by-N real nonsymmetric matrices */
00122 /*  (A,B), the generalized eigenvalues, the real Schur form (S,T), and, */
00123 /*  optionally, the left and/or right matrices of Schur vectors (VSL and */
00124 /*  VSR).  This gives the generalized Schur factorization */
00125 
00126 /*       (A,B) = ( (VSL) S (VSR)**T, (VSL) T (VSR)**T ) */
00127 
00128 /*  Optionally, it also orders the eigenvalues so that a selected cluster */
00129 /*  of eigenvalues appears in the leading diagonal blocks of the upper */
00130 /*  quasi-triangular matrix S and the upper triangular matrix T; computes */
00131 /*  a reciprocal condition number for the average of the selected */
00132 /*  eigenvalues (RCONDE); and computes a reciprocal condition number for */
00133 /*  the right and left deflating subspaces corresponding to the selected */
00134 /*  eigenvalues (RCONDV). The leading columns of VSL and VSR then form */
00135 /*  an orthonormal basis for the corresponding left and right eigenspaces */
00136 /*  (deflating subspaces). */
00137 
00138 /*  A generalized eigenvalue for a pair of matrices (A,B) is a scalar w */
00139 /*  or a ratio alpha/beta = w, such that  A - w*B is singular.  It is */
00140 /*  usually represented as the pair (alpha,beta), as there is a */
00141 /*  reasonable interpretation for beta=0 or for both being zero. */
00142 
00143 /*  A pair of matrices (S,T) is in generalized real Schur form if T is */
00144 /*  upper triangular with non-negative diagonal and S is block upper */
00145 /*  triangular with 1-by-1 and 2-by-2 blocks.  1-by-1 blocks correspond */
00146 /*  to real generalized eigenvalues, while 2-by-2 blocks of S will be */
00147 /*  "standardized" by making the corresponding elements of T have the */
00148 /*  form: */
00149 /*          [  a  0  ] */
00150 /*          [  0  b  ] */
00151 
00152 /*  and the pair of corresponding 2-by-2 blocks in S and T will have a */
00153 /*  complex conjugate pair of generalized eigenvalues. */
00154 
00155 
00156 /*  Arguments */
00157 /*  ========= */
00158 
00159 /*  JOBVSL  (input) CHARACTER*1 */
00160 /*          = 'N':  do not compute the left Schur vectors; */
00161 /*          = 'V':  compute the left Schur vectors. */
00162 
00163 /*  JOBVSR  (input) CHARACTER*1 */
00164 /*          = 'N':  do not compute the right Schur vectors; */
00165 /*          = 'V':  compute the right Schur vectors. */
00166 
00167 /*  SORT    (input) CHARACTER*1 */
00168 /*          Specifies whether or not to order the eigenvalues on the */
00169 /*          diagonal of the generalized Schur form. */
00170 /*          = 'N':  Eigenvalues are not ordered; */
00171 /*          = 'S':  Eigenvalues are ordered (see SELCTG). */
00172 
00173 /*  SELCTG  (external procedure) LOGICAL FUNCTION of three DOUBLE PRECISION arguments */
00174 /*          SELCTG must be declared EXTERNAL in the calling subroutine. */
00175 /*          If SORT = 'N', SELCTG is not referenced. */
00176 /*          If SORT = 'S', SELCTG is used to select eigenvalues to sort */
00177 /*          to the top left of the Schur form. */
00178 /*          An eigenvalue (ALPHAR(j)+ALPHAI(j))/BETA(j) is selected if */
00179 /*          SELCTG(ALPHAR(j),ALPHAI(j),BETA(j)) is true; i.e. if either */
00180 /*          one of a complex conjugate pair of eigenvalues is selected, */
00181 /*          then both complex eigenvalues are selected. */
00182 /*          Note that a selected complex eigenvalue may no longer satisfy */
00183 /*          SELCTG(ALPHAR(j),ALPHAI(j),BETA(j)) = .TRUE. after ordering, */
00184 /*          since ordering may change the value of complex eigenvalues */
00185 /*          (especially if the eigenvalue is ill-conditioned), in this */
00186 /*          case INFO is set to N+3. */
00187 
00188 /*  SENSE   (input) CHARACTER*1 */
00189 /*          Determines which reciprocal condition numbers are computed. */
00190 /*          = 'N' : None are computed; */
00191 /*          = 'E' : Computed for average of selected eigenvalues only; */
00192 /*          = 'V' : Computed for selected deflating subspaces only; */
00193 /*          = 'B' : Computed for both. */
00194 /*          If SENSE = 'E', 'V', or 'B', SORT must equal 'S'. */
00195 
00196 /*  N       (input) INTEGER */
00197 /*          The order of the matrices A, B, VSL, and VSR.  N >= 0. */
00198 
00199 /*  A       (input/output) DOUBLE PRECISION array, dimension (LDA, N) */
00200 /*          On entry, the first of the pair of matrices. */
00201 /*          On exit, A has been overwritten by its generalized Schur */
00202 /*          form S. */
00203 
00204 /*  LDA     (input) INTEGER */
00205 /*          The leading dimension of A.  LDA >= max(1,N). */
00206 
00207 /*  B       (input/output) DOUBLE PRECISION array, dimension (LDB, N) */
00208 /*          On entry, the second of the pair of matrices. */
00209 /*          On exit, B has been overwritten by its generalized Schur */
00210 /*          form T. */
00211 
00212 /*  LDB     (input) INTEGER */
00213 /*          The leading dimension of B.  LDB >= max(1,N). */
00214 
00215 /*  SDIM    (output) INTEGER */
00216 /*          If SORT = 'N', SDIM = 0. */
00217 /*          If SORT = 'S', SDIM = number of eigenvalues (after sorting) */
00218 /*          for which SELCTG is true.  (Complex conjugate pairs for which */
00219 /*          SELCTG is true for either eigenvalue count as 2.) */
00220 
00221 /*  ALPHAR  (output) DOUBLE PRECISION array, dimension (N) */
00222 /*  ALPHAI  (output) DOUBLE PRECISION array, dimension (N) */
00223 /*  BETA    (output) DOUBLE PRECISION array, dimension (N) */
00224 /*          On exit, (ALPHAR(j) + ALPHAI(j)*i)/BETA(j), j=1,...,N, will */
00225 /*          be the generalized eigenvalues.  ALPHAR(j) + ALPHAI(j)*i */
00226 /*          and BETA(j),j=1,...,N  are the diagonals of the complex Schur */
00227 /*          form (S,T) that would result if the 2-by-2 diagonal blocks of */
00228 /*          the real Schur form of (A,B) were further reduced to */
00229 /*          triangular form using 2-by-2 complex unitary transformations. */
00230 /*          If ALPHAI(j) is zero, then the j-th eigenvalue is real; if */
00231 /*          positive, then the j-th and (j+1)-st eigenvalues are a */
00232 /*          complex conjugate pair, with ALPHAI(j+1) negative. */
00233 
00234 /*          Note: the quotients ALPHAR(j)/BETA(j) and ALPHAI(j)/BETA(j) */
00235 /*          may easily over- or underflow, and BETA(j) may even be zero. */
00236 /*          Thus, the user should avoid naively computing the ratio. */
00237 /*          However, ALPHAR and ALPHAI will be always less than and */
00238 /*          usually comparable with norm(A) in magnitude, and BETA always */
00239 /*          less than and usually comparable with norm(B). */
00240 
00241 /*  VSL     (output) DOUBLE PRECISION array, dimension (LDVSL,N) */
00242 /*          If JOBVSL = 'V', VSL will contain the left Schur vectors. */
00243 /*          Not referenced if JOBVSL = 'N'. */
00244 
00245 /*  LDVSL   (input) INTEGER */
00246 /*          The leading dimension of the matrix VSL. LDVSL >=1, and */
00247 /*          if JOBVSL = 'V', LDVSL >= N. */
00248 
00249 /*  VSR     (output) DOUBLE PRECISION array, dimension (LDVSR,N) */
00250 /*          If JOBVSR = 'V', VSR will contain the right Schur vectors. */
00251 /*          Not referenced if JOBVSR = 'N'. */
00252 
00253 /*  LDVSR   (input) INTEGER */
00254 /*          The leading dimension of the matrix VSR. LDVSR >= 1, and */
00255 /*          if JOBVSR = 'V', LDVSR >= N. */
00256 
00257 /*  RCONDE  (output) DOUBLE PRECISION array, dimension ( 2 ) */
00258 /*          If SENSE = 'E' or 'B', RCONDE(1) and RCONDE(2) contain the */
00259 /*          reciprocal condition numbers for the average of the selected */
00260 /*          eigenvalues. */
00261 /*          Not referenced if SENSE = 'N' or 'V'. */
00262 
00263 /*  RCONDV  (output) DOUBLE PRECISION array, dimension ( 2 ) */
00264 /*          If SENSE = 'V' or 'B', RCONDV(1) and RCONDV(2) contain the */
00265 /*          reciprocal condition numbers for the selected deflating */
00266 /*          subspaces. */
00267 /*          Not referenced if SENSE = 'N' or 'E'. */
00268 
00269 /*  WORK    (workspace/output) DOUBLE PRECISION array, dimension (MAX(1,LWORK)) */
00270 /*          On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
00271 
00272 /*  LWORK   (input) INTEGER */
00273 /*          The dimension of the array WORK. */
00274 /*          If N = 0, LWORK >= 1, else if SENSE = 'E', 'V', or 'B', */
00275 /*          LWORK >= max( 8*N, 6*N+16, 2*SDIM*(N-SDIM) ), else */
00276 /*          LWORK >= max( 8*N, 6*N+16 ). */
00277 /*          Note that 2*SDIM*(N-SDIM) <= N*N/2. */
00278 /*          Note also that an error is only returned if */
00279 /*          LWORK < max( 8*N, 6*N+16), but if SENSE = 'E' or 'V' or 'B' */
00280 /*          this may not be large enough. */
00281 
00282 /*          If LWORK = -1, then a workspace query is assumed; the routine */
00283 /*          only calculates the bound on the optimal size of the WORK */
00284 /*          array and the minimum size of the IWORK array, returns these */
00285 /*          values as the first entries of the WORK and IWORK arrays, and */
00286 /*          no error message related to LWORK or LIWORK is issued by */
00287 /*          XERBLA. */
00288 
00289 /*  IWORK   (workspace) INTEGER array, dimension (MAX(1,LIWORK)) */
00290 /*          On exit, if INFO = 0, IWORK(1) returns the minimum LIWORK. */
00291 
00292 /*  LIWORK  (input) INTEGER */
00293 /*          The dimension of the array IWORK. */
00294 /*          If SENSE = 'N' or N = 0, LIWORK >= 1, otherwise */
00295 /*          LIWORK >= N+6. */
00296 
00297 /*          If LIWORK = -1, then a workspace query is assumed; the */
00298 /*          routine only calculates the bound on the optimal size of the */
00299 /*          WORK array and the minimum size of the IWORK array, returns */
00300 /*          these values as the first entries of the WORK and IWORK */
00301 /*          arrays, and no error message related to LWORK or LIWORK is */
00302 /*          issued by XERBLA. */
00303 
00304 /*  BWORK   (workspace) LOGICAL array, dimension (N) */
00305 /*          Not referenced if SORT = 'N'. */
00306 
00307 /*  INFO    (output) INTEGER */
00308 /*          = 0:  successful exit */
00309 /*          < 0:  if INFO = -i, the i-th argument had an illegal value. */
00310 /*          = 1,...,N: */
00311 /*                The QZ iteration failed.  (A,B) are not in Schur */
00312 /*                form, but ALPHAR(j), ALPHAI(j), and BETA(j) should */
00313 /*                be correct for j=INFO+1,...,N. */
00314 /*          > N:  =N+1: other than QZ iteration failed in DHGEQZ */
00315 /*                =N+2: after reordering, roundoff changed values of */
00316 /*                      some complex eigenvalues so that leading */
00317 /*                      eigenvalues in the Generalized Schur form no */
00318 /*                      longer satisfy SELCTG=.TRUE.  This could also */
00319 /*                      be caused due to scaling. */
00320 /*                =N+3: reordering failed in DTGSEN. */
00321 
00322 /*  Further details */
00323 /*  =============== */
00324 
00325 /*  An approximate (asymptotic) bound on the average absolute error of */
00326 /*  the selected eigenvalues is */
00327 
00328 /*       EPS * norm((A, B)) / RCONDE( 1 ). */
00329 
00330 /*  An approximate (asymptotic) bound on the maximum angular error in */
00331 /*  the computed deflating subspaces is */
00332 
00333 /*       EPS * norm((A, B)) / RCONDV( 2 ). */
00334 
00335 /*  See LAPACK User's Guide, section 4.11 for more information. */
00336 
00337 /*  ===================================================================== */
00338 
00339 /*     .. Parameters .. */
00340 /*     .. */
00341 /*     .. Local Scalars .. */
00342 /*     .. */
00343 /*     .. Local Arrays .. */
00344 /*     .. */
00345 /*     .. External Subroutines .. */
00346 /*     .. */
00347 /*     .. External Functions .. */
00348 /*     .. */
00349 /*     .. Intrinsic Functions .. */
00350 /*     .. */
00351 /*     .. Executable Statements .. */
00352 
00353 /*     Decode the input arguments */
00354 
00355     /* Parameter adjustments */
00356     a_dim1 = *lda;
00357     a_offset = 1 + a_dim1;
00358     a -= a_offset;
00359     b_dim1 = *ldb;
00360     b_offset = 1 + b_dim1;
00361     b -= b_offset;
00362     --alphar;
00363     --alphai;
00364     --beta;
00365     vsl_dim1 = *ldvsl;
00366     vsl_offset = 1 + vsl_dim1;
00367     vsl -= vsl_offset;
00368     vsr_dim1 = *ldvsr;
00369     vsr_offset = 1 + vsr_dim1;
00370     vsr -= vsr_offset;
00371     --rconde;
00372     --rcondv;
00373     --work;
00374     --iwork;
00375     --bwork;
00376 
00377     /* Function Body */
00378     if (lsame_(jobvsl, "N")) {
00379         ijobvl = 1;
00380         ilvsl = FALSE_;
00381     } else if (lsame_(jobvsl, "V")) {
00382         ijobvl = 2;
00383         ilvsl = TRUE_;
00384     } else {
00385         ijobvl = -1;
00386         ilvsl = FALSE_;
00387     }
00388 
00389     if (lsame_(jobvsr, "N")) {
00390         ijobvr = 1;
00391         ilvsr = FALSE_;
00392     } else if (lsame_(jobvsr, "V")) {
00393         ijobvr = 2;
00394         ilvsr = TRUE_;
00395     } else {
00396         ijobvr = -1;
00397         ilvsr = FALSE_;
00398     }
00399 
00400     wantst = lsame_(sort, "S");
00401     wantsn = lsame_(sense, "N");
00402     wantse = lsame_(sense, "E");
00403     wantsv = lsame_(sense, "V");
00404     wantsb = lsame_(sense, "B");
00405     lquery = *lwork == -1 || *liwork == -1;
00406     if (wantsn) {
00407         ijob = 0;
00408     } else if (wantse) {
00409         ijob = 1;
00410     } else if (wantsv) {
00411         ijob = 2;
00412     } else if (wantsb) {
00413         ijob = 4;
00414     }
00415 
00416 /*     Test the input arguments */
00417 
00418     *info = 0;
00419     if (ijobvl <= 0) {
00420         *info = -1;
00421     } else if (ijobvr <= 0) {
00422         *info = -2;
00423     } else if (! wantst && ! lsame_(sort, "N")) {
00424         *info = -3;
00425     } else if (! (wantsn || wantse || wantsv || wantsb) || ! wantst && ! 
00426             wantsn) {
00427         *info = -5;
00428     } else if (*n < 0) {
00429         *info = -6;
00430     } else if (*lda < max(1,*n)) {
00431         *info = -8;
00432     } else if (*ldb < max(1,*n)) {
00433         *info = -10;
00434     } else if (*ldvsl < 1 || ilvsl && *ldvsl < *n) {
00435         *info = -16;
00436     } else if (*ldvsr < 1 || ilvsr && *ldvsr < *n) {
00437         *info = -18;
00438     }
00439 
00440 /*     Compute workspace */
00441 /*      (Note: Comments in the code beginning "Workspace:" describe the */
00442 /*       minimal amount of workspace needed at that point in the code, */
00443 /*       as well as the preferred amount for good performance. */
00444 /*       NB refers to the optimal block size for the immediately */
00445 /*       following subroutine, as returned by ILAENV.) */
00446 
00447     if (*info == 0) {
00448         if (*n > 0) {
00449 /* Computing MAX */
00450             i__1 = *n << 3, i__2 = *n * 6 + 16;
00451             minwrk = max(i__1,i__2);
00452             maxwrk = minwrk - *n + *n * ilaenv_(&c__1, "DGEQRF", " ", n, &
00453                     c__1, n, &c__0);
00454 /* Computing MAX */
00455             i__1 = maxwrk, i__2 = minwrk - *n + *n * ilaenv_(&c__1, "DORMQR", 
00456                     " ", n, &c__1, n, &c_n1);
00457             maxwrk = max(i__1,i__2);
00458             if (ilvsl) {
00459 /* Computing MAX */
00460                 i__1 = maxwrk, i__2 = minwrk - *n + *n * ilaenv_(&c__1, "DOR"
00461                         "GQR", " ", n, &c__1, n, &c_n1);
00462                 maxwrk = max(i__1,i__2);
00463             }
00464             lwrk = maxwrk;
00465             if (ijob >= 1) {
00466 /* Computing MAX */
00467                 i__1 = lwrk, i__2 = *n * *n / 2;
00468                 lwrk = max(i__1,i__2);
00469             }
00470         } else {
00471             minwrk = 1;
00472             maxwrk = 1;
00473             lwrk = 1;
00474         }
00475         work[1] = (doublereal) lwrk;
00476         if (wantsn || *n == 0) {
00477             liwmin = 1;
00478         } else {
00479             liwmin = *n + 6;
00480         }
00481         iwork[1] = liwmin;
00482 
00483         if (*lwork < minwrk && ! lquery) {
00484             *info = -22;
00485         } else if (*liwork < liwmin && ! lquery) {
00486             *info = -24;
00487         }
00488     }
00489 
00490     if (*info != 0) {
00491         i__1 = -(*info);
00492         xerbla_("DGGESX", &i__1);
00493         return 0;
00494     } else if (lquery) {
00495         return 0;
00496     }
00497 
00498 /*     Quick return if possible */
00499 
00500     if (*n == 0) {
00501         *sdim = 0;
00502         return 0;
00503     }
00504 
00505 /*     Get machine constants */
00506 
00507     eps = dlamch_("P");
00508     safmin = dlamch_("S");
00509     safmax = 1. / safmin;
00510     dlabad_(&safmin, &safmax);
00511     smlnum = sqrt(safmin) / eps;
00512     bignum = 1. / smlnum;
00513 
00514 /*     Scale A if max element outside range [SMLNUM,BIGNUM] */
00515 
00516     anrm = dlange_("M", n, n, &a[a_offset], lda, &work[1]);
00517     ilascl = FALSE_;
00518     if (anrm > 0. && anrm < smlnum) {
00519         anrmto = smlnum;
00520         ilascl = TRUE_;
00521     } else if (anrm > bignum) {
00522         anrmto = bignum;
00523         ilascl = TRUE_;
00524     }
00525     if (ilascl) {
00526         dlascl_("G", &c__0, &c__0, &anrm, &anrmto, n, n, &a[a_offset], lda, &
00527                 ierr);
00528     }
00529 
00530 /*     Scale B if max element outside range [SMLNUM,BIGNUM] */
00531 
00532     bnrm = dlange_("M", n, n, &b[b_offset], ldb, &work[1]);
00533     ilbscl = FALSE_;
00534     if (bnrm > 0. && bnrm < smlnum) {
00535         bnrmto = smlnum;
00536         ilbscl = TRUE_;
00537     } else if (bnrm > bignum) {
00538         bnrmto = bignum;
00539         ilbscl = TRUE_;
00540     }
00541     if (ilbscl) {
00542         dlascl_("G", &c__0, &c__0, &bnrm, &bnrmto, n, n, &b[b_offset], ldb, &
00543                 ierr);
00544     }
00545 
00546 /*     Permute the matrix to make it more nearly triangular */
00547 /*     (Workspace: need 6*N + 2*N for permutation parameters) */
00548 
00549     ileft = 1;
00550     iright = *n + 1;
00551     iwrk = iright + *n;
00552     dggbal_("P", n, &a[a_offset], lda, &b[b_offset], ldb, &ilo, &ihi, &work[
00553             ileft], &work[iright], &work[iwrk], &ierr);
00554 
00555 /*     Reduce B to triangular form (QR decomposition of B) */
00556 /*     (Workspace: need N, prefer N*NB) */
00557 
00558     irows = ihi + 1 - ilo;
00559     icols = *n + 1 - ilo;
00560     itau = iwrk;
00561     iwrk = itau + irows;
00562     i__1 = *lwork + 1 - iwrk;
00563     dgeqrf_(&irows, &icols, &b[ilo + ilo * b_dim1], ldb, &work[itau], &work[
00564             iwrk], &i__1, &ierr);
00565 
00566 /*     Apply the orthogonal transformation to matrix A */
00567 /*     (Workspace: need N, prefer N*NB) */
00568 
00569     i__1 = *lwork + 1 - iwrk;
00570     dormqr_("L", "T", &irows, &icols, &irows, &b[ilo + ilo * b_dim1], ldb, &
00571             work[itau], &a[ilo + ilo * a_dim1], lda, &work[iwrk], &i__1, &
00572             ierr);
00573 
00574 /*     Initialize VSL */
00575 /*     (Workspace: need N, prefer N*NB) */
00576 
00577     if (ilvsl) {
00578         dlaset_("Full", n, n, &c_b42, &c_b43, &vsl[vsl_offset], ldvsl);
00579         if (irows > 1) {
00580             i__1 = irows - 1;
00581             i__2 = irows - 1;
00582             dlacpy_("L", &i__1, &i__2, &b[ilo + 1 + ilo * b_dim1], ldb, &vsl[
00583                     ilo + 1 + ilo * vsl_dim1], ldvsl);
00584         }
00585         i__1 = *lwork + 1 - iwrk;
00586         dorgqr_(&irows, &irows, &irows, &vsl[ilo + ilo * vsl_dim1], ldvsl, &
00587                 work[itau], &work[iwrk], &i__1, &ierr);
00588     }
00589 
00590 /*     Initialize VSR */
00591 
00592     if (ilvsr) {
00593         dlaset_("Full", n, n, &c_b42, &c_b43, &vsr[vsr_offset], ldvsr);
00594     }
00595 
00596 /*     Reduce to generalized Hessenberg form */
00597 /*     (Workspace: none needed) */
00598 
00599     dgghrd_(jobvsl, jobvsr, n, &ilo, &ihi, &a[a_offset], lda, &b[b_offset], 
00600             ldb, &vsl[vsl_offset], ldvsl, &vsr[vsr_offset], ldvsr, &ierr);
00601 
00602     *sdim = 0;
00603 
00604 /*     Perform QZ algorithm, computing Schur vectors if desired */
00605 /*     (Workspace: need N) */
00606 
00607     iwrk = itau;
00608     i__1 = *lwork + 1 - iwrk;
00609     dhgeqz_("S", jobvsl, jobvsr, n, &ilo, &ihi, &a[a_offset], lda, &b[
00610             b_offset], ldb, &alphar[1], &alphai[1], &beta[1], &vsl[vsl_offset]
00611 , ldvsl, &vsr[vsr_offset], ldvsr, &work[iwrk], &i__1, &ierr);
00612     if (ierr != 0) {
00613         if (ierr > 0 && ierr <= *n) {
00614             *info = ierr;
00615         } else if (ierr > *n && ierr <= *n << 1) {
00616             *info = ierr - *n;
00617         } else {
00618             *info = *n + 1;
00619         }
00620         goto L60;
00621     }
00622 
00623 /*     Sort eigenvalues ALPHA/BETA and compute the reciprocal of */
00624 /*     condition number(s) */
00625 /*     (Workspace: If IJOB >= 1, need MAX( 8*(N+1), 2*SDIM*(N-SDIM) ) */
00626 /*                 otherwise, need 8*(N+1) ) */
00627 
00628     if (wantst) {
00629 
00630 /*        Undo scaling on eigenvalues before SELCTGing */
00631 
00632         if (ilascl) {
00633             dlascl_("G", &c__0, &c__0, &anrmto, &anrm, n, &c__1, &alphar[1], 
00634                     n, &ierr);
00635             dlascl_("G", &c__0, &c__0, &anrmto, &anrm, n, &c__1, &alphai[1], 
00636                     n, &ierr);
00637         }
00638         if (ilbscl) {
00639             dlascl_("G", &c__0, &c__0, &bnrmto, &bnrm, n, &c__1, &beta[1], n, 
00640                     &ierr);
00641         }
00642 
00643 /*        Select eigenvalues */
00644 
00645         i__1 = *n;
00646         for (i__ = 1; i__ <= i__1; ++i__) {
00647             bwork[i__] = (*selctg)(&alphar[i__], &alphai[i__], &beta[i__]);
00648 /* L10: */
00649         }
00650 
00651 /*        Reorder eigenvalues, transform Generalized Schur vectors, and */
00652 /*        compute reciprocal condition numbers */
00653 
00654         i__1 = *lwork - iwrk + 1;
00655         dtgsen_(&ijob, &ilvsl, &ilvsr, &bwork[1], n, &a[a_offset], lda, &b[
00656                 b_offset], ldb, &alphar[1], &alphai[1], &beta[1], &vsl[
00657                 vsl_offset], ldvsl, &vsr[vsr_offset], ldvsr, sdim, &pl, &pr, 
00658                 dif, &work[iwrk], &i__1, &iwork[1], liwork, &ierr);
00659 
00660         if (ijob >= 1) {
00661 /* Computing MAX */
00662             i__1 = maxwrk, i__2 = (*sdim << 1) * (*n - *sdim);
00663             maxwrk = max(i__1,i__2);
00664         }
00665         if (ierr == -22) {
00666 
00667 /*            not enough real workspace */
00668 
00669             *info = -22;
00670         } else {
00671             if (ijob == 1 || ijob == 4) {
00672                 rconde[1] = pl;
00673                 rconde[2] = pr;
00674             }
00675             if (ijob == 2 || ijob == 4) {
00676                 rcondv[1] = dif[0];
00677                 rcondv[2] = dif[1];
00678             }
00679             if (ierr == 1) {
00680                 *info = *n + 3;
00681             }
00682         }
00683 
00684     }
00685 
00686 /*     Apply permutation to VSL and VSR */
00687 /*     (Workspace: none needed) */
00688 
00689     if (ilvsl) {
00690         dggbak_("P", "L", n, &ilo, &ihi, &work[ileft], &work[iright], n, &vsl[
00691                 vsl_offset], ldvsl, &ierr);
00692     }
00693 
00694     if (ilvsr) {
00695         dggbak_("P", "R", n, &ilo, &ihi, &work[ileft], &work[iright], n, &vsr[
00696                 vsr_offset], ldvsr, &ierr);
00697     }
00698 
00699 /*     Check if unscaling would cause over/underflow, if so, rescale */
00700 /*     (ALPHAR(I),ALPHAI(I),BETA(I)) so BETA(I) is on the order of */
00701 /*     B(I,I) and ALPHAR(I) and ALPHAI(I) are on the order of A(I,I) */
00702 
00703     if (ilascl) {
00704         i__1 = *n;
00705         for (i__ = 1; i__ <= i__1; ++i__) {
00706             if (alphai[i__] != 0.) {
00707                 if (alphar[i__] / safmax > anrmto / anrm || safmin / alphar[
00708                         i__] > anrm / anrmto) {
00709                     work[1] = (d__1 = a[i__ + i__ * a_dim1] / alphar[i__], 
00710                             abs(d__1));
00711                     beta[i__] *= work[1];
00712                     alphar[i__] *= work[1];
00713                     alphai[i__] *= work[1];
00714                 } else if (alphai[i__] / safmax > anrmto / anrm || safmin / 
00715                         alphai[i__] > anrm / anrmto) {
00716                     work[1] = (d__1 = a[i__ + (i__ + 1) * a_dim1] / alphai[
00717                             i__], abs(d__1));
00718                     beta[i__] *= work[1];
00719                     alphar[i__] *= work[1];
00720                     alphai[i__] *= work[1];
00721                 }
00722             }
00723 /* L20: */
00724         }
00725     }
00726 
00727     if (ilbscl) {
00728         i__1 = *n;
00729         for (i__ = 1; i__ <= i__1; ++i__) {
00730             if (alphai[i__] != 0.) {
00731                 if (beta[i__] / safmax > bnrmto / bnrm || safmin / beta[i__] 
00732                         > bnrm / bnrmto) {
00733                     work[1] = (d__1 = b[i__ + i__ * b_dim1] / beta[i__], abs(
00734                             d__1));
00735                     beta[i__] *= work[1];
00736                     alphar[i__] *= work[1];
00737                     alphai[i__] *= work[1];
00738                 }
00739             }
00740 /* L30: */
00741         }
00742     }
00743 
00744 /*     Undo scaling */
00745 
00746     if (ilascl) {
00747         dlascl_("H", &c__0, &c__0, &anrmto, &anrm, n, n, &a[a_offset], lda, &
00748                 ierr);
00749         dlascl_("G", &c__0, &c__0, &anrmto, &anrm, n, &c__1, &alphar[1], n, &
00750                 ierr);
00751         dlascl_("G", &c__0, &c__0, &anrmto, &anrm, n, &c__1, &alphai[1], n, &
00752                 ierr);
00753     }
00754 
00755     if (ilbscl) {
00756         dlascl_("U", &c__0, &c__0, &bnrmto, &bnrm, n, n, &b[b_offset], ldb, &
00757                 ierr);
00758         dlascl_("G", &c__0, &c__0, &bnrmto, &bnrm, n, &c__1, &beta[1], n, &
00759                 ierr);
00760     }
00761 
00762     if (wantst) {
00763 
00764 /*        Check if reordering is correct */
00765 
00766         lastsl = TRUE_;
00767         lst2sl = TRUE_;
00768         *sdim = 0;
00769         ip = 0;
00770         i__1 = *n;
00771         for (i__ = 1; i__ <= i__1; ++i__) {
00772             cursl = (*selctg)(&alphar[i__], &alphai[i__], &beta[i__]);
00773             if (alphai[i__] == 0.) {
00774                 if (cursl) {
00775                     ++(*sdim);
00776                 }
00777                 ip = 0;
00778                 if (cursl && ! lastsl) {
00779                     *info = *n + 2;
00780                 }
00781             } else {
00782                 if (ip == 1) {
00783 
00784 /*                 Last eigenvalue of conjugate pair */
00785 
00786                     cursl = cursl || lastsl;
00787                     lastsl = cursl;
00788                     if (cursl) {
00789                         *sdim += 2;
00790                     }
00791                     ip = -1;
00792                     if (cursl && ! lst2sl) {
00793                         *info = *n + 2;
00794                     }
00795                 } else {
00796 
00797 /*                 First eigenvalue of conjugate pair */
00798 
00799                     ip = 1;
00800                 }
00801             }
00802             lst2sl = lastsl;
00803             lastsl = cursl;
00804 /* L50: */
00805         }
00806 
00807     }
00808 
00809 L60:
00810 
00811     work[1] = (doublereal) maxwrk;
00812     iwork[1] = liwmin;
00813 
00814     return 0;
00815 
00816 /*     End of DGGESX */
00817 
00818 } /* dggesx_ */


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