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


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