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 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 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
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
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 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 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 int cgeqrf_(integer *, integer *, complex *,
00056 integer *, complex *, complex *, integer *, integer *);
00057 extern doublereal slamch_(char *);
00058 extern int clacpy_(char *, integer *, integer *, complex
00059 *, integer *, complex *, integer *), claset_(char *,
00060 integer *, integer *, complex *, complex *, complex *, integer *);
00061 real safmin;
00062 extern int xerbla_(char *, integer *);
00063 extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
00064 integer *, integer *);
00065 real bignum;
00066 extern 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 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
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
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
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
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
00271
00272
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
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
00317
00318 if (*n == 0) {
00319 return 0;
00320 }
00321
00322
00323
00324 eps = slamch_("E") * slamch_("B");
00325 safmin = slamch_("S");
00326 smlnum = *n * safmin / eps;
00327 bignum = 1.f / smlnum;
00328
00329
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
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
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
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
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
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
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
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
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
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
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
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
00535
00536 }