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 doublereal c_b36 = 0.;
00021 static doublereal c_b37 = 1.;
00022
00023 int dgegs_(char *jobvsl, char *jobvsr, integer *n,
00024 doublereal *a, integer *lda, doublereal *b, integer *ldb, doublereal *
00025 alphar, doublereal *alphai, doublereal *beta, doublereal *vsl,
00026 integer *ldvsl, doublereal *vsr, integer *ldvsr, doublereal *work,
00027 integer *lwork, integer *info)
00028 {
00029
00030 integer a_dim1, a_offset, b_dim1, b_offset, vsl_dim1, vsl_offset,
00031 vsr_dim1, vsr_offset, i__1, i__2;
00032
00033
00034 integer nb, nb1, nb2, nb3, ihi, ilo;
00035 doublereal eps, anrm, bnrm;
00036 integer itau, lopt;
00037 extern logical lsame_(char *, char *);
00038 integer ileft, iinfo, icols;
00039 logical ilvsl;
00040 integer iwork;
00041 logical ilvsr;
00042 integer irows;
00043 extern int dggbak_(char *, char *, integer *, integer *,
00044 integer *, doublereal *, doublereal *, integer *, doublereal *,
00045 integer *, integer *), dggbal_(char *, integer *,
00046 doublereal *, integer *, doublereal *, integer *, integer *,
00047 integer *, doublereal *, doublereal *, doublereal *, integer *);
00048 extern doublereal dlamch_(char *), dlange_(char *, integer *,
00049 integer *, doublereal *, integer *, doublereal *);
00050 extern int dgghrd_(char *, char *, integer *, integer *,
00051 integer *, doublereal *, integer *, doublereal *, integer *,
00052 doublereal *, integer *, doublereal *, integer *, integer *), dlascl_(char *, integer *, integer *, doublereal
00053 *, doublereal *, integer *, integer *, doublereal *, integer *,
00054 integer *);
00055 logical ilascl, ilbscl;
00056 extern int dgeqrf_(integer *, integer *, doublereal *,
00057 integer *, doublereal *, doublereal *, integer *, integer *),
00058 dlacpy_(char *, integer *, integer *, doublereal *, integer *,
00059 doublereal *, integer *);
00060 doublereal safmin;
00061 extern int dlaset_(char *, integer *, integer *,
00062 doublereal *, doublereal *, doublereal *, integer *),
00063 xerbla_(char *, integer *);
00064 extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
00065 integer *, integer *);
00066 doublereal bignum;
00067 extern int dhgeqz_(char *, char *, char *, integer *,
00068 integer *, integer *, doublereal *, integer *, doublereal *,
00069 integer *, doublereal *, doublereal *, doublereal *, doublereal *,
00070 integer *, doublereal *, integer *, doublereal *, integer *,
00071 integer *);
00072 integer ijobvl, iright, ijobvr;
00073 extern int dorgqr_(integer *, integer *, integer *,
00074 doublereal *, integer *, doublereal *, doublereal *, integer *,
00075 integer *);
00076 doublereal anrmto;
00077 integer lwkmin;
00078 doublereal bnrmto;
00079 extern int dormqr_(char *, char *, integer *, integer *,
00080 integer *, doublereal *, integer *, doublereal *, doublereal *,
00081 integer *, doublereal *, integer *, integer *);
00082 doublereal smlnum;
00083 integer lwkopt;
00084 logical lquery;
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
00234
00235
00236 a_dim1 = *lda;
00237 a_offset = 1 + a_dim1;
00238 a -= a_offset;
00239 b_dim1 = *ldb;
00240 b_offset = 1 + b_dim1;
00241 b -= b_offset;
00242 --alphar;
00243 --alphai;
00244 --beta;
00245 vsl_dim1 = *ldvsl;
00246 vsl_offset = 1 + vsl_dim1;
00247 vsl -= vsl_offset;
00248 vsr_dim1 = *ldvsr;
00249 vsr_offset = 1 + vsr_dim1;
00250 vsr -= vsr_offset;
00251 --work;
00252
00253
00254 if (lsame_(jobvsl, "N")) {
00255 ijobvl = 1;
00256 ilvsl = FALSE_;
00257 } else if (lsame_(jobvsl, "V")) {
00258 ijobvl = 2;
00259 ilvsl = TRUE_;
00260 } else {
00261 ijobvl = -1;
00262 ilvsl = FALSE_;
00263 }
00264
00265 if (lsame_(jobvsr, "N")) {
00266 ijobvr = 1;
00267 ilvsr = FALSE_;
00268 } else if (lsame_(jobvsr, "V")) {
00269 ijobvr = 2;
00270 ilvsr = TRUE_;
00271 } else {
00272 ijobvr = -1;
00273 ilvsr = FALSE_;
00274 }
00275
00276
00277
00278
00279 i__1 = *n << 2;
00280 lwkmin = max(i__1,1);
00281 lwkopt = lwkmin;
00282 work[1] = (doublereal) lwkopt;
00283 lquery = *lwork == -1;
00284 *info = 0;
00285 if (ijobvl <= 0) {
00286 *info = -1;
00287 } else if (ijobvr <= 0) {
00288 *info = -2;
00289 } else if (*n < 0) {
00290 *info = -3;
00291 } else if (*lda < max(1,*n)) {
00292 *info = -5;
00293 } else if (*ldb < max(1,*n)) {
00294 *info = -7;
00295 } else if (*ldvsl < 1 || ilvsl && *ldvsl < *n) {
00296 *info = -12;
00297 } else if (*ldvsr < 1 || ilvsr && *ldvsr < *n) {
00298 *info = -14;
00299 } else if (*lwork < lwkmin && ! lquery) {
00300 *info = -16;
00301 }
00302
00303 if (*info == 0) {
00304 nb1 = ilaenv_(&c__1, "DGEQRF", " ", n, n, &c_n1, &c_n1);
00305 nb2 = ilaenv_(&c__1, "DORMQR", " ", n, n, n, &c_n1);
00306 nb3 = ilaenv_(&c__1, "DORGQR", " ", n, n, n, &c_n1);
00307
00308 i__1 = max(nb1,nb2);
00309 nb = max(i__1,nb3);
00310 lopt = (*n << 1) + *n * (nb + 1);
00311 work[1] = (doublereal) lopt;
00312 }
00313
00314 if (*info != 0) {
00315 i__1 = -(*info);
00316 xerbla_("DGEGS ", &i__1);
00317 return 0;
00318 } else if (lquery) {
00319 return 0;
00320 }
00321
00322
00323
00324 if (*n == 0) {
00325 return 0;
00326 }
00327
00328
00329
00330 eps = dlamch_("E") * dlamch_("B");
00331 safmin = dlamch_("S");
00332 smlnum = *n * safmin / eps;
00333 bignum = 1. / smlnum;
00334
00335
00336
00337 anrm = dlange_("M", n, n, &a[a_offset], lda, &work[1]);
00338 ilascl = FALSE_;
00339 if (anrm > 0. && anrm < smlnum) {
00340 anrmto = smlnum;
00341 ilascl = TRUE_;
00342 } else if (anrm > bignum) {
00343 anrmto = bignum;
00344 ilascl = TRUE_;
00345 }
00346
00347 if (ilascl) {
00348 dlascl_("G", &c_n1, &c_n1, &anrm, &anrmto, n, n, &a[a_offset], lda, &
00349 iinfo);
00350 if (iinfo != 0) {
00351 *info = *n + 9;
00352 return 0;
00353 }
00354 }
00355
00356
00357
00358 bnrm = dlange_("M", n, n, &b[b_offset], ldb, &work[1]);
00359 ilbscl = FALSE_;
00360 if (bnrm > 0. && bnrm < smlnum) {
00361 bnrmto = smlnum;
00362 ilbscl = TRUE_;
00363 } else if (bnrm > bignum) {
00364 bnrmto = bignum;
00365 ilbscl = TRUE_;
00366 }
00367
00368 if (ilbscl) {
00369 dlascl_("G", &c_n1, &c_n1, &bnrm, &bnrmto, n, n, &b[b_offset], ldb, &
00370 iinfo);
00371 if (iinfo != 0) {
00372 *info = *n + 9;
00373 return 0;
00374 }
00375 }
00376
00377
00378
00379
00380
00381 ileft = 1;
00382 iright = *n + 1;
00383 iwork = iright + *n;
00384 dggbal_("P", n, &a[a_offset], lda, &b[b_offset], ldb, &ilo, &ihi, &work[
00385 ileft], &work[iright], &work[iwork], &iinfo);
00386 if (iinfo != 0) {
00387 *info = *n + 1;
00388 goto L10;
00389 }
00390
00391
00392
00393
00394
00395 irows = ihi + 1 - ilo;
00396 icols = *n + 1 - ilo;
00397 itau = iwork;
00398 iwork = itau + irows;
00399 i__1 = *lwork + 1 - iwork;
00400 dgeqrf_(&irows, &icols, &b[ilo + ilo * b_dim1], ldb, &work[itau], &work[
00401 iwork], &i__1, &iinfo);
00402 if (iinfo >= 0) {
00403
00404 i__1 = lwkopt, i__2 = (integer) work[iwork] + iwork - 1;
00405 lwkopt = max(i__1,i__2);
00406 }
00407 if (iinfo != 0) {
00408 *info = *n + 2;
00409 goto L10;
00410 }
00411
00412 i__1 = *lwork + 1 - iwork;
00413 dormqr_("L", "T", &irows, &icols, &irows, &b[ilo + ilo * b_dim1], ldb, &
00414 work[itau], &a[ilo + ilo * a_dim1], lda, &work[iwork], &i__1, &
00415 iinfo);
00416 if (iinfo >= 0) {
00417
00418 i__1 = lwkopt, i__2 = (integer) work[iwork] + iwork - 1;
00419 lwkopt = max(i__1,i__2);
00420 }
00421 if (iinfo != 0) {
00422 *info = *n + 3;
00423 goto L10;
00424 }
00425
00426 if (ilvsl) {
00427 dlaset_("Full", n, n, &c_b36, &c_b37, &vsl[vsl_offset], ldvsl);
00428 i__1 = irows - 1;
00429 i__2 = irows - 1;
00430 dlacpy_("L", &i__1, &i__2, &b[ilo + 1 + ilo * b_dim1], ldb, &vsl[ilo
00431 + 1 + ilo * vsl_dim1], ldvsl);
00432 i__1 = *lwork + 1 - iwork;
00433 dorgqr_(&irows, &irows, &irows, &vsl[ilo + ilo * vsl_dim1], ldvsl, &
00434 work[itau], &work[iwork], &i__1, &iinfo);
00435 if (iinfo >= 0) {
00436
00437 i__1 = lwkopt, i__2 = (integer) work[iwork] + iwork - 1;
00438 lwkopt = max(i__1,i__2);
00439 }
00440 if (iinfo != 0) {
00441 *info = *n + 4;
00442 goto L10;
00443 }
00444 }
00445
00446 if (ilvsr) {
00447 dlaset_("Full", n, n, &c_b36, &c_b37, &vsr[vsr_offset], ldvsr);
00448 }
00449
00450
00451
00452 dgghrd_(jobvsl, jobvsr, n, &ilo, &ihi, &a[a_offset], lda, &b[b_offset],
00453 ldb, &vsl[vsl_offset], ldvsl, &vsr[vsr_offset], ldvsr, &iinfo);
00454 if (iinfo != 0) {
00455 *info = *n + 5;
00456 goto L10;
00457 }
00458
00459
00460
00461
00462
00463 iwork = itau;
00464 i__1 = *lwork + 1 - iwork;
00465 dhgeqz_("S", jobvsl, jobvsr, n, &ilo, &ihi, &a[a_offset], lda, &b[
00466 b_offset], ldb, &alphar[1], &alphai[1], &beta[1], &vsl[vsl_offset]
00467 , ldvsl, &vsr[vsr_offset], ldvsr, &work[iwork], &i__1, &iinfo);
00468 if (iinfo >= 0) {
00469
00470 i__1 = lwkopt, i__2 = (integer) work[iwork] + iwork - 1;
00471 lwkopt = max(i__1,i__2);
00472 }
00473 if (iinfo != 0) {
00474 if (iinfo > 0 && iinfo <= *n) {
00475 *info = iinfo;
00476 } else if (iinfo > *n && iinfo <= *n << 1) {
00477 *info = iinfo - *n;
00478 } else {
00479 *info = *n + 6;
00480 }
00481 goto L10;
00482 }
00483
00484
00485
00486 if (ilvsl) {
00487 dggbak_("P", "L", n, &ilo, &ihi, &work[ileft], &work[iright], n, &vsl[
00488 vsl_offset], ldvsl, &iinfo);
00489 if (iinfo != 0) {
00490 *info = *n + 7;
00491 goto L10;
00492 }
00493 }
00494 if (ilvsr) {
00495 dggbak_("P", "R", n, &ilo, &ihi, &work[ileft], &work[iright], n, &vsr[
00496 vsr_offset], ldvsr, &iinfo);
00497 if (iinfo != 0) {
00498 *info = *n + 8;
00499 goto L10;
00500 }
00501 }
00502
00503
00504
00505 if (ilascl) {
00506 dlascl_("H", &c_n1, &c_n1, &anrmto, &anrm, n, n, &a[a_offset], lda, &
00507 iinfo);
00508 if (iinfo != 0) {
00509 *info = *n + 9;
00510 return 0;
00511 }
00512 dlascl_("G", &c_n1, &c_n1, &anrmto, &anrm, n, &c__1, &alphar[1], n, &
00513 iinfo);
00514 if (iinfo != 0) {
00515 *info = *n + 9;
00516 return 0;
00517 }
00518 dlascl_("G", &c_n1, &c_n1, &anrmto, &anrm, n, &c__1, &alphai[1], n, &
00519 iinfo);
00520 if (iinfo != 0) {
00521 *info = *n + 9;
00522 return 0;
00523 }
00524 }
00525
00526 if (ilbscl) {
00527 dlascl_("U", &c_n1, &c_n1, &bnrmto, &bnrm, n, n, &b[b_offset], ldb, &
00528 iinfo);
00529 if (iinfo != 0) {
00530 *info = *n + 9;
00531 return 0;
00532 }
00533 dlascl_("G", &c_n1, &c_n1, &bnrmto, &bnrm, n, &c__1, &beta[1], n, &
00534 iinfo);
00535 if (iinfo != 0) {
00536 *info = *n + 9;
00537 return 0;
00538 }
00539 }
00540
00541 L10:
00542 work[1] = (doublereal) lwkopt;
00543
00544 return 0;
00545
00546
00547
00548 }