cgegs.c
Go to the documentation of this file.
00001 /* cgegs.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_n1 = -1;
00022 
00023 /* Subroutine */ int cgegs_(char *jobvsl, char *jobvsr, integer *n, complex *
00024         a, integer *lda, complex *b, integer *ldb, complex *alpha, complex *
00025         beta, complex *vsl, integer *ldvsl, complex *vsr, integer *ldvsr, 
00026         complex *work, integer *lwork, real *rwork, integer *info)
00027 {
00028     /* System generated locals */
00029     integer a_dim1, a_offset, b_dim1, b_offset, vsl_dim1, vsl_offset, 
00030             vsr_dim1, vsr_offset, i__1, i__2, i__3;
00031 
00032     /* Local variables */
00033     integer nb, nb1, nb2, nb3, ihi, ilo;
00034     real eps, anrm, bnrm;
00035     integer itau, lopt;
00036     extern logical lsame_(char *, char *);
00037     integer ileft, iinfo, icols;
00038     logical ilvsl;
00039     integer iwork;
00040     logical ilvsr;
00041     integer irows;
00042     extern /* Subroutine */ int cggbak_(char *, char *, integer *, integer *, 
00043             integer *, real *, real *, integer *, complex *, integer *, 
00044             integer *), cggbal_(char *, integer *, complex *, 
00045             integer *, complex *, integer *, integer *, integer *, real *, 
00046             real *, real *, integer *);
00047     extern doublereal clange_(char *, integer *, integer *, complex *, 
00048             integer *, real *);
00049     extern /* Subroutine */ int cgghrd_(char *, char *, integer *, integer *, 
00050             integer *, complex *, integer *, complex *, integer *, complex *, 
00051             integer *, complex *, integer *, integer *), 
00052             clascl_(char *, integer *, integer *, real *, real *, integer *, 
00053             integer *, complex *, integer *, integer *);
00054     logical ilascl, ilbscl;
00055     extern /* Subroutine */ int cgeqrf_(integer *, integer *, complex *, 
00056             integer *, complex *, complex *, integer *, integer *);
00057     extern doublereal slamch_(char *);
00058     extern /* Subroutine */ int clacpy_(char *, integer *, integer *, complex 
00059             *, integer *, complex *, integer *), claset_(char *, 
00060             integer *, integer *, complex *, complex *, complex *, integer *);
00061     real safmin;
00062     extern /* Subroutine */ int xerbla_(char *, integer *);
00063     extern integer ilaenv_(integer *, char *, char *, integer *, integer *, 
00064             integer *, integer *);
00065     real bignum;
00066     extern /* Subroutine */ int chgeqz_(char *, char *, char *, integer *, 
00067             integer *, integer *, complex *, integer *, complex *, integer *, 
00068             complex *, complex *, complex *, integer *, complex *, integer *, 
00069             complex *, integer *, real *, integer *);
00070     integer ijobvl, iright, ijobvr;
00071     real anrmto;
00072     integer lwkmin;
00073     real bnrmto;
00074     extern /* Subroutine */ int cungqr_(integer *, integer *, integer *, 
00075             complex *, integer *, complex *, complex *, integer *, integer *),
00076              cunmqr_(char *, char *, integer *, integer *, integer *, complex 
00077             *, integer *, complex *, complex *, integer *, complex *, integer 
00078             *, integer *);
00079     real smlnum;
00080     integer irwork, lwkopt;
00081     logical lquery;
00082 
00083 
00084 /*  -- LAPACK driver routine (version 3.2) -- */
00085 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00086 /*     November 2006 */
00087 
00088 /*     .. Scalar Arguments .. */
00089 /*     .. */
00090 /*     .. Array Arguments .. */
00091 /*     .. */
00092 
00093 /*  Purpose */
00094 /*  ======= */
00095 
00096 /*  This routine is deprecated and has been replaced by routine CGGES. */
00097 
00098 /*  CGEGS computes the eigenvalues, Schur form, and, optionally, the */
00099 /*  left and or/right Schur vectors of a complex matrix pair (A,B). */
00100 /*  Given two square matrices A and B, the generalized Schur */
00101 /*  factorization has the form */
00102 
00103 /*     A = Q*S*Z**H,  B = Q*T*Z**H */
00104 
00105 /*  where Q and Z are unitary matrices and S and T are upper triangular. */
00106 /*  The columns of Q are the left Schur vectors */
00107 /*  and the columns of Z are the right Schur vectors. */
00108 
00109 /*  If only the eigenvalues of (A,B) are needed, the driver routine */
00110 /*  CGEGV should be used instead.  See CGEGV for a description of the */
00111 /*  eigenvalues of the generalized nonsymmetric eigenvalue problem */
00112 /*  (GNEP). */
00113 
00114 /*  Arguments */
00115 /*  ========= */
00116 
00117 /*  JOBVSL   (input) CHARACTER*1 */
00118 /*          = 'N':  do not compute the left Schur vectors; */
00119 /*          = 'V':  compute the left Schur vectors (returned in VSL). */
00120 
00121 /*  JOBVSR   (input) CHARACTER*1 */
00122 /*          = 'N':  do not compute the right Schur vectors; */
00123 /*          = 'V':  compute the right Schur vectors (returned in VSR). */
00124 
00125 /*  N       (input) INTEGER */
00126 /*          The order of the matrices A, B, VSL, and VSR.  N >= 0. */
00127 
00128 /*  A       (input/output) COMPLEX array, dimension (LDA, N) */
00129 /*          On entry, the matrix A. */
00130 /*          On exit, the upper triangular matrix S from the generalized */
00131 /*          Schur factorization. */
00132 
00133 /*  LDA     (input) INTEGER */
00134 /*          The leading dimension of A.  LDA >= max(1,N). */
00135 
00136 /*  B       (input/output) COMPLEX array, dimension (LDB, N) */
00137 /*          On entry, the matrix B. */
00138 /*          On exit, the upper triangular matrix T from the generalized */
00139 /*          Schur factorization. */
00140 
00141 /*  LDB     (input) INTEGER */
00142 /*          The leading dimension of B.  LDB >= max(1,N). */
00143 
00144 /*  ALPHA   (output) COMPLEX array, dimension (N) */
00145 /*          The complex scalars alpha that define the eigenvalues of */
00146 /*          GNEP.  ALPHA(j) = S(j,j), the diagonal element of the Schur */
00147 /*          form of A. */
00148 
00149 /*  BETA    (output) COMPLEX array, dimension (N) */
00150 /*          The non-negative real scalars beta that define the */
00151 /*          eigenvalues of GNEP.  BETA(j) = T(j,j), the diagonal element */
00152 /*          of the triangular factor T. */
00153 
00154 /*          Together, the quantities alpha = ALPHA(j) and beta = BETA(j) */
00155 /*          represent the j-th eigenvalue of the matrix pair (A,B), in */
00156 /*          one of the forms lambda = alpha/beta or mu = beta/alpha. */
00157 /*          Since either lambda or mu may overflow, they should not, */
00158 /*          in general, be computed. */
00159 
00160 /*  VSL     (output) COMPLEX array, dimension (LDVSL,N) */
00161 /*          If JOBVSL = 'V', the matrix of left Schur vectors Q. */
00162 /*          Not referenced if JOBVSL = 'N'. */
00163 
00164 /*  LDVSL   (input) INTEGER */
00165 /*          The leading dimension of the matrix VSL. LDVSL >= 1, and */
00166 /*          if JOBVSL = 'V', LDVSL >= N. */
00167 
00168 /*  VSR     (output) COMPLEX array, dimension (LDVSR,N) */
00169 /*          If JOBVSR = 'V', the matrix of right Schur vectors Z. */
00170 /*          Not referenced if JOBVSR = 'N'. */
00171 
00172 /*  LDVSR   (input) INTEGER */
00173 /*          The leading dimension of the matrix VSR. LDVSR >= 1, and */
00174 /*          if JOBVSR = 'V', LDVSR >= N. */
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 /*          For good performance, LWORK must generally be larger. */
00182 /*          To compute the optimal value of LWORK, call ILAENV to get */
00183 /*          blocksizes (for CGEQRF, CUNMQR, and CUNGQR.)  Then compute: */
00184 /*          NB  -- MAX of the blocksizes for CGEQRF, CUNMQR, and CUNGQR; */
00185 /*          the optimal LWORK is N*(NB+1). */
00186 
00187 /*          If LWORK = -1, then a workspace query is assumed; the routine */
00188 /*          only calculates the optimal size of the WORK array, returns */
00189 /*          this value as the first entry of the WORK array, and no error */
00190 /*          message related to LWORK is issued by XERBLA. */
00191 
00192 /*  RWORK   (workspace) REAL array, dimension (3*N) */
00193 
00194 /*  INFO    (output) INTEGER */
00195 /*          = 0:  successful exit */
00196 /*          < 0:  if INFO = -i, the i-th argument had an illegal value. */
00197 /*          =1,...,N: */
00198 /*                The QZ iteration failed.  (A,B) are not in Schur */
00199 /*                form, but ALPHA(j) and BETA(j) should be correct for */
00200 /*                j=INFO+1,...,N. */
00201 /*          > N:  errors that usually indicate LAPACK problems: */
00202 /*                =N+1: error return from CGGBAL */
00203 /*                =N+2: error return from CGEQRF */
00204 /*                =N+3: error return from CUNMQR */
00205 /*                =N+4: error return from CUNGQR */
00206 /*                =N+5: error return from CGGHRD */
00207 /*                =N+6: error return from CHGEQZ (other than failed */
00208 /*                                               iteration) */
00209 /*                =N+7: error return from CGGBAK (computing VSL) */
00210 /*                =N+8: error return from CGGBAK (computing VSR) */
00211 /*                =N+9: error return from CLASCL (various places) */
00212 
00213 /*  ===================================================================== */
00214 
00215 /*     .. Parameters .. */
00216 /*     .. */
00217 /*     .. Local Scalars .. */
00218 /*     .. */
00219 /*     .. External Subroutines .. */
00220 /*     .. */
00221 /*     .. External Functions .. */
00222 /*     .. */
00223 /*     .. Intrinsic Functions .. */
00224 /*     .. */
00225 /*     .. Executable Statements .. */
00226 
00227 /*     Decode the input arguments */
00228 
00229     /* Parameter adjustments */
00230     a_dim1 = *lda;
00231     a_offset = 1 + a_dim1;
00232     a -= a_offset;
00233     b_dim1 = *ldb;
00234     b_offset = 1 + b_dim1;
00235     b -= b_offset;
00236     --alpha;
00237     --beta;
00238     vsl_dim1 = *ldvsl;
00239     vsl_offset = 1 + vsl_dim1;
00240     vsl -= vsl_offset;
00241     vsr_dim1 = *ldvsr;
00242     vsr_offset = 1 + vsr_dim1;
00243     vsr -= vsr_offset;
00244     --work;
00245     --rwork;
00246 
00247     /* Function Body */
00248     if (lsame_(jobvsl, "N")) {
00249         ijobvl = 1;
00250         ilvsl = FALSE_;
00251     } else if (lsame_(jobvsl, "V")) {
00252         ijobvl = 2;
00253         ilvsl = TRUE_;
00254     } else {
00255         ijobvl = -1;
00256         ilvsl = FALSE_;
00257     }
00258 
00259     if (lsame_(jobvsr, "N")) {
00260         ijobvr = 1;
00261         ilvsr = FALSE_;
00262     } else if (lsame_(jobvsr, "V")) {
00263         ijobvr = 2;
00264         ilvsr = TRUE_;
00265     } else {
00266         ijobvr = -1;
00267         ilvsr = FALSE_;
00268     }
00269 
00270 /*     Test the input arguments */
00271 
00272 /* Computing MAX */
00273     i__1 = *n << 1;
00274     lwkmin = max(i__1,1);
00275     lwkopt = lwkmin;
00276     work[1].r = (real) lwkopt, work[1].i = 0.f;
00277     lquery = *lwork == -1;
00278     *info = 0;
00279     if (ijobvl <= 0) {
00280         *info = -1;
00281     } else if (ijobvr <= 0) {
00282         *info = -2;
00283     } else if (*n < 0) {
00284         *info = -3;
00285     } else if (*lda < max(1,*n)) {
00286         *info = -5;
00287     } else if (*ldb < max(1,*n)) {
00288         *info = -7;
00289     } else if (*ldvsl < 1 || ilvsl && *ldvsl < *n) {
00290         *info = -11;
00291     } else if (*ldvsr < 1 || ilvsr && *ldvsr < *n) {
00292         *info = -13;
00293     } else if (*lwork < lwkmin && ! lquery) {
00294         *info = -15;
00295     }
00296 
00297     if (*info == 0) {
00298         nb1 = ilaenv_(&c__1, "CGEQRF", " ", n, n, &c_n1, &c_n1);
00299         nb2 = ilaenv_(&c__1, "CUNMQR", " ", n, n, n, &c_n1);
00300         nb3 = ilaenv_(&c__1, "CUNGQR", " ", n, n, n, &c_n1);
00301 /* Computing MAX */
00302         i__1 = max(nb1,nb2);
00303         nb = max(i__1,nb3);
00304         lopt = *n * (nb + 1);
00305         work[1].r = (real) lopt, work[1].i = 0.f;
00306     }
00307 
00308     if (*info != 0) {
00309         i__1 = -(*info);
00310         xerbla_("CGEGS ", &i__1);
00311         return 0;
00312     } else if (lquery) {
00313         return 0;
00314     }
00315 
00316 /*     Quick return if possible */
00317 
00318     if (*n == 0) {
00319         return 0;
00320     }
00321 
00322 /*     Get machine constants */
00323 
00324     eps = slamch_("E") * slamch_("B");
00325     safmin = slamch_("S");
00326     smlnum = *n * safmin / eps;
00327     bignum = 1.f / smlnum;
00328 
00329 /*     Scale A if max element outside range [SMLNUM,BIGNUM] */
00330 
00331     anrm = clange_("M", n, n, &a[a_offset], lda, &rwork[1]);
00332     ilascl = FALSE_;
00333     if (anrm > 0.f && anrm < smlnum) {
00334         anrmto = smlnum;
00335         ilascl = TRUE_;
00336     } else if (anrm > bignum) {
00337         anrmto = bignum;
00338         ilascl = TRUE_;
00339     }
00340 
00341     if (ilascl) {
00342         clascl_("G", &c_n1, &c_n1, &anrm, &anrmto, n, n, &a[a_offset], lda, &
00343                 iinfo);
00344         if (iinfo != 0) {
00345             *info = *n + 9;
00346             return 0;
00347         }
00348     }
00349 
00350 /*     Scale B if max element outside range [SMLNUM,BIGNUM] */
00351 
00352     bnrm = clange_("M", n, n, &b[b_offset], ldb, &rwork[1]);
00353     ilbscl = FALSE_;
00354     if (bnrm > 0.f && bnrm < smlnum) {
00355         bnrmto = smlnum;
00356         ilbscl = TRUE_;
00357     } else if (bnrm > bignum) {
00358         bnrmto = bignum;
00359         ilbscl = TRUE_;
00360     }
00361 
00362     if (ilbscl) {
00363         clascl_("G", &c_n1, &c_n1, &bnrm, &bnrmto, n, n, &b[b_offset], ldb, &
00364                 iinfo);
00365         if (iinfo != 0) {
00366             *info = *n + 9;
00367             return 0;
00368         }
00369     }
00370 
00371 /*     Permute the matrix to make it more nearly triangular */
00372 
00373     ileft = 1;
00374     iright = *n + 1;
00375     irwork = iright + *n;
00376     iwork = 1;
00377     cggbal_("P", n, &a[a_offset], lda, &b[b_offset], ldb, &ilo, &ihi, &rwork[
00378             ileft], &rwork[iright], &rwork[irwork], &iinfo);
00379     if (iinfo != 0) {
00380         *info = *n + 1;
00381         goto L10;
00382     }
00383 
00384 /*     Reduce B to triangular form, and initialize VSL and/or VSR */
00385 
00386     irows = ihi + 1 - ilo;
00387     icols = *n + 1 - ilo;
00388     itau = iwork;
00389     iwork = itau + irows;
00390     i__1 = *lwork + 1 - iwork;
00391     cgeqrf_(&irows, &icols, &b[ilo + ilo * b_dim1], ldb, &work[itau], &work[
00392             iwork], &i__1, &iinfo);
00393     if (iinfo >= 0) {
00394 /* Computing MAX */
00395         i__3 = iwork;
00396         i__1 = lwkopt, i__2 = (integer) work[i__3].r + iwork - 1;
00397         lwkopt = max(i__1,i__2);
00398     }
00399     if (iinfo != 0) {
00400         *info = *n + 2;
00401         goto L10;
00402     }
00403 
00404     i__1 = *lwork + 1 - iwork;
00405     cunmqr_("L", "C", &irows, &icols, &irows, &b[ilo + ilo * b_dim1], ldb, &
00406             work[itau], &a[ilo + ilo * a_dim1], lda, &work[iwork], &i__1, &
00407             iinfo);
00408     if (iinfo >= 0) {
00409 /* Computing MAX */
00410         i__3 = iwork;
00411         i__1 = lwkopt, i__2 = (integer) work[i__3].r + iwork - 1;
00412         lwkopt = max(i__1,i__2);
00413     }
00414     if (iinfo != 0) {
00415         *info = *n + 3;
00416         goto L10;
00417     }
00418 
00419     if (ilvsl) {
00420         claset_("Full", n, n, &c_b1, &c_b2, &vsl[vsl_offset], ldvsl);
00421         i__1 = irows - 1;
00422         i__2 = irows - 1;
00423         clacpy_("L", &i__1, &i__2, &b[ilo + 1 + ilo * b_dim1], ldb, &vsl[ilo 
00424                 + 1 + ilo * vsl_dim1], ldvsl);
00425         i__1 = *lwork + 1 - iwork;
00426         cungqr_(&irows, &irows, &irows, &vsl[ilo + ilo * vsl_dim1], ldvsl, &
00427                 work[itau], &work[iwork], &i__1, &iinfo);
00428         if (iinfo >= 0) {
00429 /* Computing MAX */
00430             i__3 = iwork;
00431             i__1 = lwkopt, i__2 = (integer) work[i__3].r + iwork - 1;
00432             lwkopt = max(i__1,i__2);
00433         }
00434         if (iinfo != 0) {
00435             *info = *n + 4;
00436             goto L10;
00437         }
00438     }
00439 
00440     if (ilvsr) {
00441         claset_("Full", n, n, &c_b1, &c_b2, &vsr[vsr_offset], ldvsr);
00442     }
00443 
00444 /*     Reduce to generalized Hessenberg form */
00445 
00446     cgghrd_(jobvsl, jobvsr, n, &ilo, &ihi, &a[a_offset], lda, &b[b_offset], 
00447             ldb, &vsl[vsl_offset], ldvsl, &vsr[vsr_offset], ldvsr, &iinfo);
00448     if (iinfo != 0) {
00449         *info = *n + 5;
00450         goto L10;
00451     }
00452 
00453 /*     Perform QZ algorithm, computing Schur vectors if desired */
00454 
00455     iwork = itau;
00456     i__1 = *lwork + 1 - iwork;
00457     chgeqz_("S", jobvsl, jobvsr, n, &ilo, &ihi, &a[a_offset], lda, &b[
00458             b_offset], ldb, &alpha[1], &beta[1], &vsl[vsl_offset], ldvsl, &
00459             vsr[vsr_offset], ldvsr, &work[iwork], &i__1, &rwork[irwork], &
00460             iinfo);
00461     if (iinfo >= 0) {
00462 /* Computing MAX */
00463         i__3 = iwork;
00464         i__1 = lwkopt, i__2 = (integer) work[i__3].r + iwork - 1;
00465         lwkopt = max(i__1,i__2);
00466     }
00467     if (iinfo != 0) {
00468         if (iinfo > 0 && iinfo <= *n) {
00469             *info = iinfo;
00470         } else if (iinfo > *n && iinfo <= *n << 1) {
00471             *info = iinfo - *n;
00472         } else {
00473             *info = *n + 6;
00474         }
00475         goto L10;
00476     }
00477 
00478 /*     Apply permutation to VSL and VSR */
00479 
00480     if (ilvsl) {
00481         cggbak_("P", "L", n, &ilo, &ihi, &rwork[ileft], &rwork[iright], n, &
00482                 vsl[vsl_offset], ldvsl, &iinfo);
00483         if (iinfo != 0) {
00484             *info = *n + 7;
00485             goto L10;
00486         }
00487     }
00488     if (ilvsr) {
00489         cggbak_("P", "R", n, &ilo, &ihi, &rwork[ileft], &rwork[iright], n, &
00490                 vsr[vsr_offset], ldvsr, &iinfo);
00491         if (iinfo != 0) {
00492             *info = *n + 8;
00493             goto L10;
00494         }
00495     }
00496 
00497 /*     Undo scaling */
00498 
00499     if (ilascl) {
00500         clascl_("U", &c_n1, &c_n1, &anrmto, &anrm, n, n, &a[a_offset], lda, &
00501                 iinfo);
00502         if (iinfo != 0) {
00503             *info = *n + 9;
00504             return 0;
00505         }
00506         clascl_("G", &c_n1, &c_n1, &anrmto, &anrm, n, &c__1, &alpha[1], n, &
00507                 iinfo);
00508         if (iinfo != 0) {
00509             *info = *n + 9;
00510             return 0;
00511         }
00512     }
00513 
00514     if (ilbscl) {
00515         clascl_("U", &c_n1, &c_n1, &bnrmto, &bnrm, n, n, &b[b_offset], ldb, &
00516                 iinfo);
00517         if (iinfo != 0) {
00518             *info = *n + 9;
00519             return 0;
00520         }
00521         clascl_("G", &c_n1, &c_n1, &bnrmto, &bnrm, n, &c__1, &beta[1], n, &
00522                 iinfo);
00523         if (iinfo != 0) {
00524             *info = *n + 9;
00525             return 0;
00526         }
00527     }
00528 
00529 L10:
00530     work[1].r = (real) lwkopt, work[1].i = 0.f;
00531 
00532     return 0;
00533 
00534 /*     End of CGEGS */
00535 
00536 } /* cgegs_ */


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