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


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