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_n1 = -1;
00020 static real c_b36 = 0.f;
00021 static real c_b37 = 1.f;
00022
00023 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
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
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 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 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 int slascl_(char *, integer *, integer *, real *,
00059 real *, integer *, integer *, real *, integer *, integer *);
00060 integer ijobvl, iright;
00061 extern int sgeqrf_(integer *, integer *, real *, integer
00062 *, real *, real *, integer *, integer *);
00063 integer ijobvr;
00064 extern 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 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 int sorgqr_(integer *, integer *, integer *, real
00076 *, integer *, real *, real *, integer *, integer *);
00077 integer lwkopt;
00078 logical lquery;
00079 extern int sormqr_(char *, char *, integer *, integer *,
00080 integer *, real *, integer *, real *, real *, integer *, real *,
00081 integer *, integer *);
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
00231
00232
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
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
00274
00275
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
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
00320
00321 if (*n == 0) {
00322 return 0;
00323 }
00324
00325
00326
00327 eps = slamch_("E") * slamch_("B");
00328 safmin = slamch_("S");
00329 smlnum = *n * safmin / eps;
00330 bignum = 1.f / smlnum;
00331
00332
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
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
00375
00376
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
00389
00390
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
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
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
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
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
00457
00458
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
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
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
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
00544
00545 }