dtrexc.c
Go to the documentation of this file.
00001 /* dtrexc.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__2 = 2;
00020 
00021 /* Subroutine */ int dtrexc_(char *compq, integer *n, doublereal *t, integer *
00022         ldt, doublereal *q, integer *ldq, integer *ifst, integer *ilst, 
00023         doublereal *work, integer *info)
00024 {
00025     /* System generated locals */
00026     integer q_dim1, q_offset, t_dim1, t_offset, i__1;
00027 
00028     /* Local variables */
00029     integer nbf, nbl, here;
00030     extern logical lsame_(char *, char *);
00031     logical wantq;
00032     extern /* Subroutine */ int dlaexc_(logical *, integer *, doublereal *, 
00033             integer *, doublereal *, integer *, integer *, integer *, integer 
00034             *, doublereal *, integer *), xerbla_(char *, integer *);
00035     integer nbnext;
00036 
00037 
00038 /*  -- LAPACK routine (version 3.2) -- */
00039 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00040 /*     November 2006 */
00041 
00042 /*     .. Scalar Arguments .. */
00043 /*     .. */
00044 /*     .. Array Arguments .. */
00045 /*     .. */
00046 
00047 /*  Purpose */
00048 /*  ======= */
00049 
00050 /*  DTREXC reorders the real Schur factorization of a real matrix */
00051 /*  A = Q*T*Q**T, so that the diagonal block of T with row index IFST is */
00052 /*  moved to row ILST. */
00053 
00054 /*  The real Schur form T is reordered by an orthogonal similarity */
00055 /*  transformation Z**T*T*Z, and optionally the matrix Q of Schur vectors */
00056 /*  is updated by postmultiplying it with Z. */
00057 
00058 /*  T must be in Schur canonical form (as returned by DHSEQR), that is, */
00059 /*  block upper triangular with 1-by-1 and 2-by-2 diagonal blocks; each */
00060 /*  2-by-2 diagonal block has its diagonal elements equal and its */
00061 /*  off-diagonal elements of opposite sign. */
00062 
00063 /*  Arguments */
00064 /*  ========= */
00065 
00066 /*  COMPQ   (input) CHARACTER*1 */
00067 /*          = 'V':  update the matrix Q of Schur vectors; */
00068 /*          = 'N':  do not update Q. */
00069 
00070 /*  N       (input) INTEGER */
00071 /*          The order of the matrix T. N >= 0. */
00072 
00073 /*  T       (input/output) DOUBLE PRECISION array, dimension (LDT,N) */
00074 /*          On entry, the upper quasi-triangular matrix T, in Schur */
00075 /*          Schur canonical form. */
00076 /*          On exit, the reordered upper quasi-triangular matrix, again */
00077 /*          in Schur canonical form. */
00078 
00079 /*  LDT     (input) INTEGER */
00080 /*          The leading dimension of the array T. LDT >= max(1,N). */
00081 
00082 /*  Q       (input/output) DOUBLE PRECISION array, dimension (LDQ,N) */
00083 /*          On entry, if COMPQ = 'V', the matrix Q of Schur vectors. */
00084 /*          On exit, if COMPQ = 'V', Q has been postmultiplied by the */
00085 /*          orthogonal transformation matrix Z which reorders T. */
00086 /*          If COMPQ = 'N', Q is not referenced. */
00087 
00088 /*  LDQ     (input) INTEGER */
00089 /*          The leading dimension of the array Q.  LDQ >= max(1,N). */
00090 
00091 /*  IFST    (input/output) INTEGER */
00092 /*  ILST    (input/output) INTEGER */
00093 /*          Specify the reordering of the diagonal blocks of T. */
00094 /*          The block with row index IFST is moved to row ILST, by a */
00095 /*          sequence of transpositions between adjacent blocks. */
00096 /*          On exit, if IFST pointed on entry to the second row of a */
00097 /*          2-by-2 block, it is changed to point to the first row; ILST */
00098 /*          always points to the first row of the block in its final */
00099 /*          position (which may differ from its input value by +1 or -1). */
00100 /*          1 <= IFST <= N; 1 <= ILST <= N. */
00101 
00102 /*  WORK    (workspace) DOUBLE PRECISION array, dimension (N) */
00103 
00104 /*  INFO    (output) INTEGER */
00105 /*          = 0:  successful exit */
00106 /*          < 0:  if INFO = -i, the i-th argument had an illegal value */
00107 /*          = 1:  two adjacent blocks were too close to swap (the problem */
00108 /*                is very ill-conditioned); T may have been partially */
00109 /*                reordered, and ILST points to the first row of the */
00110 /*                current position of the block being moved. */
00111 
00112 /*  ===================================================================== */
00113 
00114 /*     .. Parameters .. */
00115 /*     .. */
00116 /*     .. Local Scalars .. */
00117 /*     .. */
00118 /*     .. External Functions .. */
00119 /*     .. */
00120 /*     .. External Subroutines .. */
00121 /*     .. */
00122 /*     .. Intrinsic Functions .. */
00123 /*     .. */
00124 /*     .. Executable Statements .. */
00125 
00126 /*     Decode and test the input arguments. */
00127 
00128     /* Parameter adjustments */
00129     t_dim1 = *ldt;
00130     t_offset = 1 + t_dim1;
00131     t -= t_offset;
00132     q_dim1 = *ldq;
00133     q_offset = 1 + q_dim1;
00134     q -= q_offset;
00135     --work;
00136 
00137     /* Function Body */
00138     *info = 0;
00139     wantq = lsame_(compq, "V");
00140     if (! wantq && ! lsame_(compq, "N")) {
00141         *info = -1;
00142     } else if (*n < 0) {
00143         *info = -2;
00144     } else if (*ldt < max(1,*n)) {
00145         *info = -4;
00146     } else if (*ldq < 1 || wantq && *ldq < max(1,*n)) {
00147         *info = -6;
00148     } else if (*ifst < 1 || *ifst > *n) {
00149         *info = -7;
00150     } else if (*ilst < 1 || *ilst > *n) {
00151         *info = -8;
00152     }
00153     if (*info != 0) {
00154         i__1 = -(*info);
00155         xerbla_("DTREXC", &i__1);
00156         return 0;
00157     }
00158 
00159 /*     Quick return if possible */
00160 
00161     if (*n <= 1) {
00162         return 0;
00163     }
00164 
00165 /*     Determine the first row of specified block */
00166 /*     and find out it is 1 by 1 or 2 by 2. */
00167 
00168     if (*ifst > 1) {
00169         if (t[*ifst + (*ifst - 1) * t_dim1] != 0.) {
00170             --(*ifst);
00171         }
00172     }
00173     nbf = 1;
00174     if (*ifst < *n) {
00175         if (t[*ifst + 1 + *ifst * t_dim1] != 0.) {
00176             nbf = 2;
00177         }
00178     }
00179 
00180 /*     Determine the first row of the final block */
00181 /*     and find out it is 1 by 1 or 2 by 2. */
00182 
00183     if (*ilst > 1) {
00184         if (t[*ilst + (*ilst - 1) * t_dim1] != 0.) {
00185             --(*ilst);
00186         }
00187     }
00188     nbl = 1;
00189     if (*ilst < *n) {
00190         if (t[*ilst + 1 + *ilst * t_dim1] != 0.) {
00191             nbl = 2;
00192         }
00193     }
00194 
00195     if (*ifst == *ilst) {
00196         return 0;
00197     }
00198 
00199     if (*ifst < *ilst) {
00200 
00201 /*        Update ILST */
00202 
00203         if (nbf == 2 && nbl == 1) {
00204             --(*ilst);
00205         }
00206         if (nbf == 1 && nbl == 2) {
00207             ++(*ilst);
00208         }
00209 
00210         here = *ifst;
00211 
00212 L10:
00213 
00214 /*        Swap block with next one below */
00215 
00216         if (nbf == 1 || nbf == 2) {
00217 
00218 /*           Current block either 1 by 1 or 2 by 2 */
00219 
00220             nbnext = 1;
00221             if (here + nbf + 1 <= *n) {
00222                 if (t[here + nbf + 1 + (here + nbf) * t_dim1] != 0.) {
00223                     nbnext = 2;
00224                 }
00225             }
00226             dlaexc_(&wantq, n, &t[t_offset], ldt, &q[q_offset], ldq, &here, &
00227                     nbf, &nbnext, &work[1], info);
00228             if (*info != 0) {
00229                 *ilst = here;
00230                 return 0;
00231             }
00232             here += nbnext;
00233 
00234 /*           Test if 2 by 2 block breaks into two 1 by 1 blocks */
00235 
00236             if (nbf == 2) {
00237                 if (t[here + 1 + here * t_dim1] == 0.) {
00238                     nbf = 3;
00239                 }
00240             }
00241 
00242         } else {
00243 
00244 /*           Current block consists of two 1 by 1 blocks each of which */
00245 /*           must be swapped individually */
00246 
00247             nbnext = 1;
00248             if (here + 3 <= *n) {
00249                 if (t[here + 3 + (here + 2) * t_dim1] != 0.) {
00250                     nbnext = 2;
00251                 }
00252             }
00253             i__1 = here + 1;
00254             dlaexc_(&wantq, n, &t[t_offset], ldt, &q[q_offset], ldq, &i__1, &
00255                     c__1, &nbnext, &work[1], info);
00256             if (*info != 0) {
00257                 *ilst = here;
00258                 return 0;
00259             }
00260             if (nbnext == 1) {
00261 
00262 /*              Swap two 1 by 1 blocks, no problems possible */
00263 
00264                 dlaexc_(&wantq, n, &t[t_offset], ldt, &q[q_offset], ldq, &
00265                         here, &c__1, &nbnext, &work[1], info);
00266                 ++here;
00267             } else {
00268 
00269 /*              Recompute NBNEXT in case 2 by 2 split */
00270 
00271                 if (t[here + 2 + (here + 1) * t_dim1] == 0.) {
00272                     nbnext = 1;
00273                 }
00274                 if (nbnext == 2) {
00275 
00276 /*                 2 by 2 Block did not split */
00277 
00278                     dlaexc_(&wantq, n, &t[t_offset], ldt, &q[q_offset], ldq, &
00279                             here, &c__1, &nbnext, &work[1], info);
00280                     if (*info != 0) {
00281                         *ilst = here;
00282                         return 0;
00283                     }
00284                     here += 2;
00285                 } else {
00286 
00287 /*                 2 by 2 Block did split */
00288 
00289                     dlaexc_(&wantq, n, &t[t_offset], ldt, &q[q_offset], ldq, &
00290                             here, &c__1, &c__1, &work[1], info);
00291                     i__1 = here + 1;
00292                     dlaexc_(&wantq, n, &t[t_offset], ldt, &q[q_offset], ldq, &
00293                             i__1, &c__1, &c__1, &work[1], info);
00294                     here += 2;
00295                 }
00296             }
00297         }
00298         if (here < *ilst) {
00299             goto L10;
00300         }
00301 
00302     } else {
00303 
00304         here = *ifst;
00305 L20:
00306 
00307 /*        Swap block with next one above */
00308 
00309         if (nbf == 1 || nbf == 2) {
00310 
00311 /*           Current block either 1 by 1 or 2 by 2 */
00312 
00313             nbnext = 1;
00314             if (here >= 3) {
00315                 if (t[here - 1 + (here - 2) * t_dim1] != 0.) {
00316                     nbnext = 2;
00317                 }
00318             }
00319             i__1 = here - nbnext;
00320             dlaexc_(&wantq, n, &t[t_offset], ldt, &q[q_offset], ldq, &i__1, &
00321                     nbnext, &nbf, &work[1], info);
00322             if (*info != 0) {
00323                 *ilst = here;
00324                 return 0;
00325             }
00326             here -= nbnext;
00327 
00328 /*           Test if 2 by 2 block breaks into two 1 by 1 blocks */
00329 
00330             if (nbf == 2) {
00331                 if (t[here + 1 + here * t_dim1] == 0.) {
00332                     nbf = 3;
00333                 }
00334             }
00335 
00336         } else {
00337 
00338 /*           Current block consists of two 1 by 1 blocks each of which */
00339 /*           must be swapped individually */
00340 
00341             nbnext = 1;
00342             if (here >= 3) {
00343                 if (t[here - 1 + (here - 2) * t_dim1] != 0.) {
00344                     nbnext = 2;
00345                 }
00346             }
00347             i__1 = here - nbnext;
00348             dlaexc_(&wantq, n, &t[t_offset], ldt, &q[q_offset], ldq, &i__1, &
00349                     nbnext, &c__1, &work[1], info);
00350             if (*info != 0) {
00351                 *ilst = here;
00352                 return 0;
00353             }
00354             if (nbnext == 1) {
00355 
00356 /*              Swap two 1 by 1 blocks, no problems possible */
00357 
00358                 dlaexc_(&wantq, n, &t[t_offset], ldt, &q[q_offset], ldq, &
00359                         here, &nbnext, &c__1, &work[1], info);
00360                 --here;
00361             } else {
00362 
00363 /*              Recompute NBNEXT in case 2 by 2 split */
00364 
00365                 if (t[here + (here - 1) * t_dim1] == 0.) {
00366                     nbnext = 1;
00367                 }
00368                 if (nbnext == 2) {
00369 
00370 /*                 2 by 2 Block did not split */
00371 
00372                     i__1 = here - 1;
00373                     dlaexc_(&wantq, n, &t[t_offset], ldt, &q[q_offset], ldq, &
00374                             i__1, &c__2, &c__1, &work[1], info);
00375                     if (*info != 0) {
00376                         *ilst = here;
00377                         return 0;
00378                     }
00379                     here += -2;
00380                 } else {
00381 
00382 /*                 2 by 2 Block did split */
00383 
00384                     dlaexc_(&wantq, n, &t[t_offset], ldt, &q[q_offset], ldq, &
00385                             here, &c__1, &c__1, &work[1], info);
00386                     i__1 = here - 1;
00387                     dlaexc_(&wantq, n, &t[t_offset], ldt, &q[q_offset], ldq, &
00388                             i__1, &c__1, &c__1, &work[1], info);
00389                     here += -2;
00390                 }
00391             }
00392         }
00393         if (here > *ilst) {
00394             goto L20;
00395         }
00396     }
00397     *ilst = here;
00398 
00399     return 0;
00400 
00401 /*     End of DTREXC */
00402 
00403 } /* dtrexc_ */


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