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


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