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


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