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


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