cgeesx.c
Go to the documentation of this file.
00001 /* cgeesx.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 
00022 /* Subroutine */ int cgeesx_(char *jobvs, char *sort, L_fp select, char *
00023         sense, integer *n, complex *a, integer *lda, integer *sdim, complex *
00024         w, complex *vs, integer *ldvs, real *rconde, real *rcondv, complex *
00025         work, integer *lwork, real *rwork, logical *bwork, integer *info)
00026 {
00027     /* System generated locals */
00028     integer a_dim1, a_offset, vs_dim1, vs_offset, i__1, i__2;
00029 
00030     /* Builtin functions */
00031     double sqrt(doublereal);
00032 
00033     /* Local variables */
00034     integer i__, ihi, ilo;
00035     real dum[1], eps;
00036     integer ibal;
00037     real anrm;
00038     integer ierr, itau, iwrk, lwrk, icond, ieval;
00039     extern logical lsame_(char *, char *);
00040     extern /* Subroutine */ int ccopy_(integer *, complex *, integer *, 
00041             complex *, integer *), cgebak_(char *, char *, integer *, integer 
00042             *, integer *, real *, integer *, complex *, integer *, integer *), cgebal_(char *, integer *, complex *, integer *, 
00043             integer *, integer *, real *, integer *), slabad_(real *, 
00044             real *);
00045     logical scalea;
00046     extern doublereal clange_(char *, integer *, integer *, complex *, 
00047             integer *, real *);
00048     real cscale;
00049     extern /* Subroutine */ int cgehrd_(integer *, integer *, integer *, 
00050             complex *, integer *, complex *, complex *, integer *, integer *),
00051              clascl_(char *, integer *, integer *, real *, real *, integer *, 
00052             integer *, complex *, integer *, integer *);
00053     extern doublereal slamch_(char *);
00054     extern /* Subroutine */ int clacpy_(char *, integer *, integer *, complex 
00055             *, integer *, complex *, integer *), xerbla_(char *, 
00056             integer *);
00057     extern integer ilaenv_(integer *, char *, char *, integer *, integer *, 
00058             integer *, integer *);
00059     real bignum;
00060     extern /* Subroutine */ int slascl_(char *, integer *, integer *, real *, 
00061             real *, integer *, integer *, real *, integer *, integer *), chseqr_(char *, char *, integer *, integer *, integer *, 
00062             complex *, integer *, complex *, complex *, integer *, complex *, 
00063             integer *, integer *), cunghr_(integer *, integer 
00064             *, integer *, complex *, integer *, complex *, complex *, integer 
00065             *, integer *);
00066     logical wantsb;
00067     extern /* Subroutine */ int ctrsen_(char *, char *, logical *, integer *, 
00068             complex *, integer *, complex *, integer *, complex *, integer *, 
00069             real *, real *, complex *, integer *, integer *);
00070     logical wantse;
00071     integer minwrk, maxwrk;
00072     logical wantsn;
00073     real smlnum;
00074     integer hswork;
00075     logical wantst, wantsv, wantvs;
00076 
00077 
00078 /*  -- LAPACK driver routine (version 3.2) -- */
00079 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00080 /*     November 2006 */
00081 
00082 /*     .. Scalar Arguments .. */
00083 /*     .. */
00084 /*     .. Array Arguments .. */
00085 /*     .. */
00086 /*     .. Function Arguments .. */
00087 /*     .. */
00088 
00089 /*  Purpose */
00090 /*  ======= */
00091 
00092 /*  CGEESX computes for an N-by-N complex nonsymmetric matrix A, the */
00093 /*  eigenvalues, the Schur form T, and, optionally, the matrix of Schur */
00094 /*  vectors Z.  This gives the Schur factorization A = Z*T*(Z**H). */
00095 
00096 /*  Optionally, it also orders the eigenvalues on the diagonal of the */
00097 /*  Schur form so that selected eigenvalues are at the top left; */
00098 /*  computes a reciprocal condition number for the average of the */
00099 /*  selected eigenvalues (RCONDE); and computes a reciprocal condition */
00100 /*  number for the right invariant subspace corresponding to the */
00101 /*  selected eigenvalues (RCONDV).  The leading columns of Z form an */
00102 /*  orthonormal basis for this invariant subspace. */
00103 
00104 /*  For further explanation of the reciprocal condition numbers RCONDE */
00105 /*  and RCONDV, see Section 4.10 of the LAPACK Users' Guide (where */
00106 /*  these quantities are called s and sep respectively). */
00107 
00108 /*  A complex matrix is in Schur form if it is upper triangular. */
00109 
00110 /*  Arguments */
00111 /*  ========= */
00112 
00113 /*  JOBVS   (input) CHARACTER*1 */
00114 /*          = 'N': Schur vectors are not computed; */
00115 /*          = 'V': Schur vectors are computed. */
00116 
00117 /*  SORT    (input) CHARACTER*1 */
00118 /*          Specifies whether or not to order the eigenvalues on the */
00119 /*          diagonal of the Schur form. */
00120 /*          = 'N': Eigenvalues are not ordered; */
00121 /*          = 'S': Eigenvalues are ordered (see SELECT). */
00122 
00123 /*  SELECT  (external procedure) LOGICAL FUNCTION of one COMPLEX argument */
00124 /*          SELECT must be declared EXTERNAL in the calling subroutine. */
00125 /*          If SORT = 'S', SELECT is used to select eigenvalues to order */
00126 /*          to the top left of the Schur form. */
00127 /*          If SORT = 'N', SELECT is not referenced. */
00128 /*          An eigenvalue W(j) is selected if SELECT(W(j)) is true. */
00129 
00130 /*  SENSE   (input) CHARACTER*1 */
00131 /*          Determines which reciprocal condition numbers are computed. */
00132 /*          = 'N': None are computed; */
00133 /*          = 'E': Computed for average of selected eigenvalues only; */
00134 /*          = 'V': Computed for selected right invariant subspace only; */
00135 /*          = 'B': Computed for both. */
00136 /*          If SENSE = 'E', 'V' or 'B', SORT must equal 'S'. */
00137 
00138 /*  N       (input) INTEGER */
00139 /*          The order of the matrix A. N >= 0. */
00140 
00141 /*  A       (input/output) COMPLEX array, dimension (LDA, N) */
00142 /*          On entry, the N-by-N matrix A. */
00143 /*          On exit, A is overwritten by its Schur form T. */
00144 
00145 /*  LDA     (input) INTEGER */
00146 /*          The leading dimension of the array A.  LDA >= max(1,N). */
00147 
00148 /*  SDIM    (output) INTEGER */
00149 /*          If SORT = 'N', SDIM = 0. */
00150 /*          If SORT = 'S', SDIM = number of eigenvalues for which */
00151 /*                         SELECT is true. */
00152 
00153 /*  W       (output) COMPLEX array, dimension (N) */
00154 /*          W contains the computed eigenvalues, in the same order */
00155 /*          that they appear on the diagonal of the output Schur form T. */
00156 
00157 /*  VS      (output) COMPLEX array, dimension (LDVS,N) */
00158 /*          If JOBVS = 'V', VS contains the unitary matrix Z of Schur */
00159 /*          vectors. */
00160 /*          If JOBVS = 'N', VS is not referenced. */
00161 
00162 /*  LDVS    (input) INTEGER */
00163 /*          The leading dimension of the array VS.  LDVS >= 1, and if */
00164 /*          JOBVS = 'V', LDVS >= N. */
00165 
00166 /*  RCONDE  (output) REAL */
00167 /*          If SENSE = 'E' or 'B', RCONDE contains the reciprocal */
00168 /*          condition number for the average of the selected eigenvalues. */
00169 /*          Not referenced if SENSE = 'N' or 'V'. */
00170 
00171 /*  RCONDV  (output) REAL */
00172 /*          If SENSE = 'V' or 'B', RCONDV contains the reciprocal */
00173 /*          condition number for the selected right invariant subspace. */
00174 /*          Not referenced if SENSE = 'N' or 'E'. */
00175 
00176 /*  WORK    (workspace/output) COMPLEX array, dimension (MAX(1,LWORK)) */
00177 /*          On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
00178 
00179 /*  LWORK   (input) INTEGER */
00180 /*          The dimension of the array WORK.  LWORK >= max(1,2*N). */
00181 /*          Also, if SENSE = 'E' or 'V' or 'B', LWORK >= 2*SDIM*(N-SDIM), */
00182 /*          where SDIM is the number of selected eigenvalues computed by */
00183 /*          this routine.  Note that 2*SDIM*(N-SDIM) <= N*N/2. Note also */
00184 /*          that an error is only returned if LWORK < max(1,2*N), but if */
00185 /*          SENSE = 'E' or 'V' or 'B' this may not be large enough. */
00186 /*          For good performance, LWORK must generally be larger. */
00187 
00188 /*          If LWORK = -1, then a workspace query is assumed; the routine */
00189 /*          only calculates upper bound on the optimal size of the */
00190 /*          array WORK, returns this value as the first entry of the WORK */
00191 /*          array, and no error message related to LWORK is issued by */
00192 /*          XERBLA. */
00193 
00194 /*  RWORK   (workspace) REAL array, dimension (N) */
00195 
00196 /*  BWORK   (workspace) LOGICAL array, dimension (N) */
00197 /*          Not referenced if SORT = 'N'. */
00198 
00199 /*  INFO    (output) INTEGER */
00200 /*          = 0: successful exit */
00201 /*          < 0: if INFO = -i, the i-th argument had an illegal value. */
00202 /*          > 0: if INFO = i, and i is */
00203 /*             <= N: the QR algorithm failed to compute all the */
00204 /*                   eigenvalues; elements 1:ILO-1 and i+1:N of W */
00205 /*                   contain those eigenvalues which have converged; if */
00206 /*                   JOBVS = 'V', VS contains the transformation which */
00207 /*                   reduces A to its partially converged Schur form. */
00208 /*             = N+1: the eigenvalues could not be reordered because some */
00209 /*                   eigenvalues were too close to separate (the problem */
00210 /*                   is very ill-conditioned); */
00211 /*             = N+2: after reordering, roundoff changed values of some */
00212 /*                   complex eigenvalues so that leading eigenvalues in */
00213 /*                   the Schur form no longer satisfy SELECT=.TRUE.  This */
00214 /*                   could also be caused by underflow due to scaling. */
00215 
00216 /*  ===================================================================== */
00217 
00218 /*     .. Parameters .. */
00219 /*     .. */
00220 /*     .. Local Scalars .. */
00221 /*     .. */
00222 /*     .. Local Arrays .. */
00223 /*     .. */
00224 /*     .. External Subroutines .. */
00225 /*     .. */
00226 /*     .. External Functions .. */
00227 /*     .. */
00228 /*     .. Intrinsic Functions .. */
00229 /*     .. */
00230 /*     .. Executable Statements .. */
00231 
00232 /*     Test the input arguments */
00233 
00234     /* Parameter adjustments */
00235     a_dim1 = *lda;
00236     a_offset = 1 + a_dim1;
00237     a -= a_offset;
00238     --w;
00239     vs_dim1 = *ldvs;
00240     vs_offset = 1 + vs_dim1;
00241     vs -= vs_offset;
00242     --work;
00243     --rwork;
00244     --bwork;
00245 
00246     /* Function Body */
00247     *info = 0;
00248     wantvs = lsame_(jobvs, "V");
00249     wantst = lsame_(sort, "S");
00250     wantsn = lsame_(sense, "N");
00251     wantse = lsame_(sense, "E");
00252     wantsv = lsame_(sense, "V");
00253     wantsb = lsame_(sense, "B");
00254     if (! wantvs && ! lsame_(jobvs, "N")) {
00255         *info = -1;
00256     } else if (! wantst && ! lsame_(sort, "N")) {
00257         *info = -2;
00258     } else if (! (wantsn || wantse || wantsv || wantsb) || ! wantst && ! 
00259             wantsn) {
00260         *info = -4;
00261     } else if (*n < 0) {
00262         *info = -5;
00263     } else if (*lda < max(1,*n)) {
00264         *info = -7;
00265     } else if (*ldvs < 1 || wantvs && *ldvs < *n) {
00266         *info = -11;
00267     }
00268 
00269 /*     Compute workspace */
00270 /*      (Note: Comments in the code beginning "Workspace:" describe the */
00271 /*       minimal amount of real workspace needed at that point in the */
00272 /*       code, as well as the preferred amount for good performance. */
00273 /*       CWorkspace refers to complex workspace, and RWorkspace to real */
00274 /*       workspace. NB refers to the optimal block size for the */
00275 /*       immediately following subroutine, as returned by ILAENV. */
00276 /*       HSWORK refers to the workspace preferred by CHSEQR, as */
00277 /*       calculated below. HSWORK is computed assuming ILO=1 and IHI=N, */
00278 /*       the worst case. */
00279 /*       If SENSE = 'E', 'V' or 'B', then the amount of workspace needed */
00280 /*       depends on SDIM, which is computed by the routine CTRSEN later */
00281 /*       in the code.) */
00282 
00283     if (*info == 0) {
00284         if (*n == 0) {
00285             minwrk = 1;
00286             lwrk = 1;
00287         } else {
00288             maxwrk = *n + *n * ilaenv_(&c__1, "CGEHRD", " ", n, &c__1, n, &
00289                     c__0);
00290             minwrk = *n << 1;
00291 
00292             chseqr_("S", jobvs, n, &c__1, n, &a[a_offset], lda, &w[1], &vs[
00293                     vs_offset], ldvs, &work[1], &c_n1, &ieval);
00294             hswork = work[1].r;
00295 
00296             if (! wantvs) {
00297                 maxwrk = max(maxwrk,hswork);
00298             } else {
00299 /* Computing MAX */
00300                 i__1 = maxwrk, i__2 = *n + (*n - 1) * ilaenv_(&c__1, "CUNGHR", 
00301                          " ", n, &c__1, n, &c_n1);
00302                 maxwrk = max(i__1,i__2);
00303                 maxwrk = max(maxwrk,hswork);
00304             }
00305             lwrk = maxwrk;
00306             if (! wantsn) {
00307 /* Computing MAX */
00308                 i__1 = lwrk, i__2 = *n * *n / 2;
00309                 lwrk = max(i__1,i__2);
00310             }
00311         }
00312         work[1].r = (real) lwrk, work[1].i = 0.f;
00313 
00314         if (*lwork < minwrk) {
00315             *info = -15;
00316         }
00317     }
00318 
00319     if (*info != 0) {
00320         i__1 = -(*info);
00321         xerbla_("CGEESX", &i__1);
00322         return 0;
00323     }
00324 
00325 /*     Quick return if possible */
00326 
00327     if (*n == 0) {
00328         *sdim = 0;
00329         return 0;
00330     }
00331 
00332 /*     Get machine constants */
00333 
00334     eps = slamch_("P");
00335     smlnum = slamch_("S");
00336     bignum = 1.f / smlnum;
00337     slabad_(&smlnum, &bignum);
00338     smlnum = sqrt(smlnum) / eps;
00339     bignum = 1.f / smlnum;
00340 
00341 /*     Scale A if max element outside range [SMLNUM,BIGNUM] */
00342 
00343     anrm = clange_("M", n, n, &a[a_offset], lda, dum);
00344     scalea = FALSE_;
00345     if (anrm > 0.f && anrm < smlnum) {
00346         scalea = TRUE_;
00347         cscale = smlnum;
00348     } else if (anrm > bignum) {
00349         scalea = TRUE_;
00350         cscale = bignum;
00351     }
00352     if (scalea) {
00353         clascl_("G", &c__0, &c__0, &anrm, &cscale, n, n, &a[a_offset], lda, &
00354                 ierr);
00355     }
00356 
00357 
00358 /*     Permute the matrix to make it more nearly triangular */
00359 /*     (CWorkspace: none) */
00360 /*     (RWorkspace: need N) */
00361 
00362     ibal = 1;
00363     cgebal_("P", n, &a[a_offset], lda, &ilo, &ihi, &rwork[ibal], &ierr);
00364 
00365 /*     Reduce to upper Hessenberg form */
00366 /*     (CWorkspace: need 2*N, prefer N+N*NB) */
00367 /*     (RWorkspace: none) */
00368 
00369     itau = 1;
00370     iwrk = *n + itau;
00371     i__1 = *lwork - iwrk + 1;
00372     cgehrd_(n, &ilo, &ihi, &a[a_offset], lda, &work[itau], &work[iwrk], &i__1, 
00373              &ierr);
00374 
00375     if (wantvs) {
00376 
00377 /*        Copy Householder vectors to VS */
00378 
00379         clacpy_("L", n, n, &a[a_offset], lda, &vs[vs_offset], ldvs)
00380                 ;
00381 
00382 /*        Generate unitary matrix in VS */
00383 /*        (CWorkspace: need 2*N-1, prefer N+(N-1)*NB) */
00384 /*        (RWorkspace: none) */
00385 
00386         i__1 = *lwork - iwrk + 1;
00387         cunghr_(n, &ilo, &ihi, &vs[vs_offset], ldvs, &work[itau], &work[iwrk], 
00388                  &i__1, &ierr);
00389     }
00390 
00391     *sdim = 0;
00392 
00393 /*     Perform QR iteration, accumulating Schur vectors in VS if desired */
00394 /*     (CWorkspace: need 1, prefer HSWORK (see comments) ) */
00395 /*     (RWorkspace: none) */
00396 
00397     iwrk = itau;
00398     i__1 = *lwork - iwrk + 1;
00399     chseqr_("S", jobvs, n, &ilo, &ihi, &a[a_offset], lda, &w[1], &vs[
00400             vs_offset], ldvs, &work[iwrk], &i__1, &ieval);
00401     if (ieval > 0) {
00402         *info = ieval;
00403     }
00404 
00405 /*     Sort eigenvalues if desired */
00406 
00407     if (wantst && *info == 0) {
00408         if (scalea) {
00409             clascl_("G", &c__0, &c__0, &cscale, &anrm, n, &c__1, &w[1], n, &
00410                     ierr);
00411         }
00412         i__1 = *n;
00413         for (i__ = 1; i__ <= i__1; ++i__) {
00414             bwork[i__] = (*select)(&w[i__]);
00415 /* L10: */
00416         }
00417 
00418 /*        Reorder eigenvalues, transform Schur vectors, and compute */
00419 /*        reciprocal condition numbers */
00420 /*        (CWorkspace: if SENSE is not 'N', need 2*SDIM*(N-SDIM) */
00421 /*                     otherwise, need none ) */
00422 /*        (RWorkspace: none) */
00423 
00424         i__1 = *lwork - iwrk + 1;
00425         ctrsen_(sense, jobvs, &bwork[1], n, &a[a_offset], lda, &vs[vs_offset], 
00426                  ldvs, &w[1], sdim, rconde, rcondv, &work[iwrk], &i__1, &
00427                 icond);
00428         if (! wantsn) {
00429 /* Computing MAX */
00430             i__1 = maxwrk, i__2 = (*sdim << 1) * (*n - *sdim);
00431             maxwrk = max(i__1,i__2);
00432         }
00433         if (icond == -14) {
00434 
00435 /*           Not enough complex workspace */
00436 
00437             *info = -15;
00438         }
00439     }
00440 
00441     if (wantvs) {
00442 
00443 /*        Undo balancing */
00444 /*        (CWorkspace: none) */
00445 /*        (RWorkspace: need N) */
00446 
00447         cgebak_("P", "R", n, &ilo, &ihi, &rwork[ibal], n, &vs[vs_offset], 
00448                 ldvs, &ierr);
00449     }
00450 
00451     if (scalea) {
00452 
00453 /*        Undo scaling for the Schur form of A */
00454 
00455         clascl_("U", &c__0, &c__0, &cscale, &anrm, n, n, &a[a_offset], lda, &
00456                 ierr);
00457         i__1 = *lda + 1;
00458         ccopy_(n, &a[a_offset], &i__1, &w[1], &c__1);
00459         if ((wantsv || wantsb) && *info == 0) {
00460             dum[0] = *rcondv;
00461             slascl_("G", &c__0, &c__0, &cscale, &anrm, &c__1, &c__1, dum, &
00462                     c__1, &ierr);
00463             *rcondv = dum[0];
00464         }
00465     }
00466 
00467     work[1].r = (real) maxwrk, work[1].i = 0.f;
00468     return 0;
00469 
00470 /*     End of CGEESX */
00471 
00472 } /* cgeesx_ */


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