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


swiftnav
Author(s):
autogenerated on Sat Jun 8 2019 18:56:08