00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #include "f2c.h"
00014 #include "blaswrap.h"
00015
00016
00017
00018 static integer c__1 = 1;
00019 static integer c__0 = 0;
00020 static integer c_n1 = -1;
00021
00022 int zgees_(char *jobvs, char *sort, L_fp select, integer *n,
00023 doublecomplex *a, integer *lda, integer *sdim, doublecomplex *w,
00024 doublecomplex *vs, integer *ldvs, doublecomplex *work, integer *lwork,
00025 doublereal *rwork, logical *bwork, integer *info)
00026 {
00027
00028 integer a_dim1, a_offset, vs_dim1, vs_offset, i__1, i__2;
00029
00030
00031 double sqrt(doublereal);
00032
00033
00034 integer i__;
00035 doublereal s;
00036 integer ihi, ilo;
00037 doublereal dum[1], eps, sep;
00038 integer ibal;
00039 doublereal anrm;
00040 integer ierr, itau, iwrk, icond, ieval;
00041 extern logical lsame_(char *, char *);
00042 extern int zcopy_(integer *, doublecomplex *, integer *,
00043 doublecomplex *, integer *), dlabad_(doublereal *, doublereal *);
00044 logical scalea;
00045 extern doublereal dlamch_(char *);
00046 doublereal cscale;
00047 extern int zgebak_(char *, char *, integer *, integer *,
00048 integer *, doublereal *, integer *, doublecomplex *, integer *,
00049 integer *), zgebal_(char *, integer *,
00050 doublecomplex *, integer *, integer *, integer *, doublereal *,
00051 integer *), xerbla_(char *, integer *);
00052 extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
00053 integer *, integer *);
00054 extern doublereal zlange_(char *, integer *, integer *, doublecomplex *,
00055 integer *, doublereal *);
00056 doublereal bignum;
00057 extern int zgehrd_(integer *, integer *, integer *,
00058 doublecomplex *, integer *, doublecomplex *, doublecomplex *,
00059 integer *, integer *), zlascl_(char *, integer *, integer *,
00060 doublereal *, doublereal *, integer *, integer *, doublecomplex *,
00061 integer *, integer *), zlacpy_(char *, integer *,
00062 integer *, doublecomplex *, integer *, doublecomplex *, integer *);
00063 integer minwrk, maxwrk;
00064 doublereal smlnum;
00065 extern int zhseqr_(char *, char *, integer *, integer *,
00066 integer *, doublecomplex *, integer *, doublecomplex *,
00067 doublecomplex *, integer *, doublecomplex *, integer *, integer *);
00068 integer hswork;
00069 extern int zunghr_(integer *, integer *, integer *,
00070 doublecomplex *, integer *, doublecomplex *, doublecomplex *,
00071 integer *, integer *);
00072 logical wantst, lquery, wantvs;
00073 extern int ztrsen_(char *, char *, logical *, integer *,
00074 doublecomplex *, integer *, doublecomplex *, integer *,
00075 doublecomplex *, integer *, doublereal *, doublereal *,
00076 doublecomplex *, integer *, integer *);
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206 a_dim1 = *lda;
00207 a_offset = 1 + a_dim1;
00208 a -= a_offset;
00209 --w;
00210 vs_dim1 = *ldvs;
00211 vs_offset = 1 + vs_dim1;
00212 vs -= vs_offset;
00213 --work;
00214 --rwork;
00215 --bwork;
00216
00217
00218 *info = 0;
00219 lquery = *lwork == -1;
00220 wantvs = lsame_(jobvs, "V");
00221 wantst = lsame_(sort, "S");
00222 if (! wantvs && ! lsame_(jobvs, "N")) {
00223 *info = -1;
00224 } else if (! wantst && ! lsame_(sort, "N")) {
00225 *info = -2;
00226 } else if (*n < 0) {
00227 *info = -4;
00228 } else if (*lda < max(1,*n)) {
00229 *info = -6;
00230 } else if (*ldvs < 1 || wantvs && *ldvs < *n) {
00231 *info = -10;
00232 }
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245 if (*info == 0) {
00246 if (*n == 0) {
00247 minwrk = 1;
00248 maxwrk = 1;
00249 } else {
00250 maxwrk = *n + *n * ilaenv_(&c__1, "ZGEHRD", " ", n, &c__1, n, &
00251 c__0);
00252 minwrk = *n << 1;
00253
00254 zhseqr_("S", jobvs, n, &c__1, n, &a[a_offset], lda, &w[1], &vs[
00255 vs_offset], ldvs, &work[1], &c_n1, &ieval);
00256 hswork = (integer) work[1].r;
00257
00258 if (! wantvs) {
00259 maxwrk = max(maxwrk,hswork);
00260 } else {
00261
00262 i__1 = maxwrk, i__2 = *n + (*n - 1) * ilaenv_(&c__1, "ZUNGHR",
00263 " ", n, &c__1, n, &c_n1);
00264 maxwrk = max(i__1,i__2);
00265 maxwrk = max(maxwrk,hswork);
00266 }
00267 }
00268 work[1].r = (doublereal) maxwrk, work[1].i = 0.;
00269
00270 if (*lwork < minwrk && ! lquery) {
00271 *info = -12;
00272 }
00273 }
00274
00275 if (*info != 0) {
00276 i__1 = -(*info);
00277 xerbla_("ZGEES ", &i__1);
00278 return 0;
00279 } else if (lquery) {
00280 return 0;
00281 }
00282
00283
00284
00285 if (*n == 0) {
00286 *sdim = 0;
00287 return 0;
00288 }
00289
00290
00291
00292 eps = dlamch_("P");
00293 smlnum = dlamch_("S");
00294 bignum = 1. / smlnum;
00295 dlabad_(&smlnum, &bignum);
00296 smlnum = sqrt(smlnum) / eps;
00297 bignum = 1. / smlnum;
00298
00299
00300
00301 anrm = zlange_("M", n, n, &a[a_offset], lda, dum);
00302 scalea = FALSE_;
00303 if (anrm > 0. && anrm < smlnum) {
00304 scalea = TRUE_;
00305 cscale = smlnum;
00306 } else if (anrm > bignum) {
00307 scalea = TRUE_;
00308 cscale = bignum;
00309 }
00310 if (scalea) {
00311 zlascl_("G", &c__0, &c__0, &anrm, &cscale, n, n, &a[a_offset], lda, &
00312 ierr);
00313 }
00314
00315
00316
00317
00318
00319 ibal = 1;
00320 zgebal_("P", n, &a[a_offset], lda, &ilo, &ihi, &rwork[ibal], &ierr);
00321
00322
00323
00324
00325
00326 itau = 1;
00327 iwrk = *n + itau;
00328 i__1 = *lwork - iwrk + 1;
00329 zgehrd_(n, &ilo, &ihi, &a[a_offset], lda, &work[itau], &work[iwrk], &i__1,
00330 &ierr);
00331
00332 if (wantvs) {
00333
00334
00335
00336 zlacpy_("L", n, n, &a[a_offset], lda, &vs[vs_offset], ldvs)
00337 ;
00338
00339
00340
00341
00342
00343 i__1 = *lwork - iwrk + 1;
00344 zunghr_(n, &ilo, &ihi, &vs[vs_offset], ldvs, &work[itau], &work[iwrk],
00345 &i__1, &ierr);
00346 }
00347
00348 *sdim = 0;
00349
00350
00351
00352
00353
00354 iwrk = itau;
00355 i__1 = *lwork - iwrk + 1;
00356 zhseqr_("S", jobvs, n, &ilo, &ihi, &a[a_offset], lda, &w[1], &vs[
00357 vs_offset], ldvs, &work[iwrk], &i__1, &ieval);
00358 if (ieval > 0) {
00359 *info = ieval;
00360 }
00361
00362
00363
00364 if (wantst && *info == 0) {
00365 if (scalea) {
00366 zlascl_("G", &c__0, &c__0, &cscale, &anrm, n, &c__1, &w[1], n, &
00367 ierr);
00368 }
00369 i__1 = *n;
00370 for (i__ = 1; i__ <= i__1; ++i__) {
00371 bwork[i__] = (*select)(&w[i__]);
00372
00373 }
00374
00375
00376
00377
00378
00379 i__1 = *lwork - iwrk + 1;
00380 ztrsen_("N", jobvs, &bwork[1], n, &a[a_offset], lda, &vs[vs_offset],
00381 ldvs, &w[1], sdim, &s, &sep, &work[iwrk], &i__1, &icond);
00382 }
00383
00384 if (wantvs) {
00385
00386
00387
00388
00389
00390 zgebak_("P", "R", n, &ilo, &ihi, &rwork[ibal], n, &vs[vs_offset],
00391 ldvs, &ierr);
00392 }
00393
00394 if (scalea) {
00395
00396
00397
00398 zlascl_("U", &c__0, &c__0, &cscale, &anrm, n, n, &a[a_offset], lda, &
00399 ierr);
00400 i__1 = *lda + 1;
00401 zcopy_(n, &a[a_offset], &i__1, &w[1], &c__1);
00402 }
00403
00404 work[1].r = (doublereal) maxwrk, work[1].i = 0.;
00405 return 0;
00406
00407
00408
00409 }