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 real c_b13 = 0.f;
00019 static real c_b14 = 1.f;
00020 static integer c__1 = 1;
00021 static real c_b43 = -1.f;
00022
00023 int stgsja_(char *jobu, char *jobv, char *jobq, integer *m,
00024 integer *p, integer *n, integer *k, integer *l, real *a, integer *lda,
00025 real *b, integer *ldb, real *tola, real *tolb, real *alpha, real *
00026 beta, real *u, integer *ldu, real *v, integer *ldv, real *q, integer *
00027 ldq, real *work, integer *ncycle, integer *info)
00028 {
00029
00030 integer a_dim1, a_offset, b_dim1, b_offset, q_dim1, q_offset, u_dim1,
00031 u_offset, v_dim1, v_offset, i__1, i__2, i__3, i__4;
00032 real r__1;
00033
00034
00035 integer i__, j;
00036 real a1, a2, a3, b1, b2, b3, csq, csu, csv, snq, rwk, snu, snv;
00037 extern int srot_(integer *, real *, integer *, real *,
00038 integer *, real *, real *);
00039 real gamma;
00040 extern logical lsame_(char *, char *);
00041 extern int sscal_(integer *, real *, real *, integer *);
00042 logical initq, initu, initv, wantq, upper;
00043 real error, ssmin;
00044 logical wantu, wantv;
00045 extern int scopy_(integer *, real *, integer *, real *,
00046 integer *), slags2_(logical *, real *, real *, real *, real *,
00047 real *, real *, real *, real *, real *, real *, real *, real *);
00048 integer kcycle;
00049 extern int xerbla_(char *, integer *), slapll_(
00050 integer *, real *, integer *, real *, integer *, real *), slartg_(
00051 real *, real *, real *, real *, real *), slaset_(char *, integer *
00052 , integer *, real *, real *, real *, integer *);
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
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
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
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319 a_dim1 = *lda;
00320 a_offset = 1 + a_dim1;
00321 a -= a_offset;
00322 b_dim1 = *ldb;
00323 b_offset = 1 + b_dim1;
00324 b -= b_offset;
00325 --alpha;
00326 --beta;
00327 u_dim1 = *ldu;
00328 u_offset = 1 + u_dim1;
00329 u -= u_offset;
00330 v_dim1 = *ldv;
00331 v_offset = 1 + v_dim1;
00332 v -= v_offset;
00333 q_dim1 = *ldq;
00334 q_offset = 1 + q_dim1;
00335 q -= q_offset;
00336 --work;
00337
00338
00339 initu = lsame_(jobu, "I");
00340 wantu = initu || lsame_(jobu, "U");
00341
00342 initv = lsame_(jobv, "I");
00343 wantv = initv || lsame_(jobv, "V");
00344
00345 initq = lsame_(jobq, "I");
00346 wantq = initq || lsame_(jobq, "Q");
00347
00348 *info = 0;
00349 if (! (initu || wantu || lsame_(jobu, "N"))) {
00350 *info = -1;
00351 } else if (! (initv || wantv || lsame_(jobv, "N")))
00352 {
00353 *info = -2;
00354 } else if (! (initq || wantq || lsame_(jobq, "N")))
00355 {
00356 *info = -3;
00357 } else if (*m < 0) {
00358 *info = -4;
00359 } else if (*p < 0) {
00360 *info = -5;
00361 } else if (*n < 0) {
00362 *info = -6;
00363 } else if (*lda < max(1,*m)) {
00364 *info = -10;
00365 } else if (*ldb < max(1,*p)) {
00366 *info = -12;
00367 } else if (*ldu < 1 || wantu && *ldu < *m) {
00368 *info = -18;
00369 } else if (*ldv < 1 || wantv && *ldv < *p) {
00370 *info = -20;
00371 } else if (*ldq < 1 || wantq && *ldq < *n) {
00372 *info = -22;
00373 }
00374 if (*info != 0) {
00375 i__1 = -(*info);
00376 xerbla_("STGSJA", &i__1);
00377 return 0;
00378 }
00379
00380
00381
00382 if (initu) {
00383 slaset_("Full", m, m, &c_b13, &c_b14, &u[u_offset], ldu);
00384 }
00385 if (initv) {
00386 slaset_("Full", p, p, &c_b13, &c_b14, &v[v_offset], ldv);
00387 }
00388 if (initq) {
00389 slaset_("Full", n, n, &c_b13, &c_b14, &q[q_offset], ldq);
00390 }
00391
00392
00393
00394 upper = FALSE_;
00395 for (kcycle = 1; kcycle <= 40; ++kcycle) {
00396
00397 upper = ! upper;
00398
00399 i__1 = *l - 1;
00400 for (i__ = 1; i__ <= i__1; ++i__) {
00401 i__2 = *l;
00402 for (j = i__ + 1; j <= i__2; ++j) {
00403
00404 a1 = 0.f;
00405 a2 = 0.f;
00406 a3 = 0.f;
00407 if (*k + i__ <= *m) {
00408 a1 = a[*k + i__ + (*n - *l + i__) * a_dim1];
00409 }
00410 if (*k + j <= *m) {
00411 a3 = a[*k + j + (*n - *l + j) * a_dim1];
00412 }
00413
00414 b1 = b[i__ + (*n - *l + i__) * b_dim1];
00415 b3 = b[j + (*n - *l + j) * b_dim1];
00416
00417 if (upper) {
00418 if (*k + i__ <= *m) {
00419 a2 = a[*k + i__ + (*n - *l + j) * a_dim1];
00420 }
00421 b2 = b[i__ + (*n - *l + j) * b_dim1];
00422 } else {
00423 if (*k + j <= *m) {
00424 a2 = a[*k + j + (*n - *l + i__) * a_dim1];
00425 }
00426 b2 = b[j + (*n - *l + i__) * b_dim1];
00427 }
00428
00429 slags2_(&upper, &a1, &a2, &a3, &b1, &b2, &b3, &csu, &snu, &
00430 csv, &snv, &csq, &snq);
00431
00432
00433
00434 if (*k + j <= *m) {
00435 srot_(l, &a[*k + j + (*n - *l + 1) * a_dim1], lda, &a[*k
00436 + i__ + (*n - *l + 1) * a_dim1], lda, &csu, &snu);
00437 }
00438
00439
00440
00441 srot_(l, &b[j + (*n - *l + 1) * b_dim1], ldb, &b[i__ + (*n - *
00442 l + 1) * b_dim1], ldb, &csv, &snv);
00443
00444
00445
00446
00447
00448 i__4 = *k + *l;
00449 i__3 = min(i__4,*m);
00450 srot_(&i__3, &a[(*n - *l + j) * a_dim1 + 1], &c__1, &a[(*n - *
00451 l + i__) * a_dim1 + 1], &c__1, &csq, &snq);
00452
00453 srot_(l, &b[(*n - *l + j) * b_dim1 + 1], &c__1, &b[(*n - *l +
00454 i__) * b_dim1 + 1], &c__1, &csq, &snq);
00455
00456 if (upper) {
00457 if (*k + i__ <= *m) {
00458 a[*k + i__ + (*n - *l + j) * a_dim1] = 0.f;
00459 }
00460 b[i__ + (*n - *l + j) * b_dim1] = 0.f;
00461 } else {
00462 if (*k + j <= *m) {
00463 a[*k + j + (*n - *l + i__) * a_dim1] = 0.f;
00464 }
00465 b[j + (*n - *l + i__) * b_dim1] = 0.f;
00466 }
00467
00468
00469
00470 if (wantu && *k + j <= *m) {
00471 srot_(m, &u[(*k + j) * u_dim1 + 1], &c__1, &u[(*k + i__) *
00472 u_dim1 + 1], &c__1, &csu, &snu);
00473 }
00474
00475 if (wantv) {
00476 srot_(p, &v[j * v_dim1 + 1], &c__1, &v[i__ * v_dim1 + 1],
00477 &c__1, &csv, &snv);
00478 }
00479
00480 if (wantq) {
00481 srot_(n, &q[(*n - *l + j) * q_dim1 + 1], &c__1, &q[(*n - *
00482 l + i__) * q_dim1 + 1], &c__1, &csq, &snq);
00483 }
00484
00485
00486 }
00487
00488 }
00489
00490 if (! upper) {
00491
00492
00493
00494
00495
00496
00497
00498 error = 0.f;
00499
00500 i__2 = *l, i__3 = *m - *k;
00501 i__1 = min(i__2,i__3);
00502 for (i__ = 1; i__ <= i__1; ++i__) {
00503 i__2 = *l - i__ + 1;
00504 scopy_(&i__2, &a[*k + i__ + (*n - *l + i__) * a_dim1], lda, &
00505 work[1], &c__1);
00506 i__2 = *l - i__ + 1;
00507 scopy_(&i__2, &b[i__ + (*n - *l + i__) * b_dim1], ldb, &work[*
00508 l + 1], &c__1);
00509 i__2 = *l - i__ + 1;
00510 slapll_(&i__2, &work[1], &c__1, &work[*l + 1], &c__1, &ssmin);
00511 error = dmax(error,ssmin);
00512
00513 }
00514
00515 if (dabs(error) <= dmin(*tola,*tolb)) {
00516 goto L50;
00517 }
00518 }
00519
00520
00521
00522
00523 }
00524
00525
00526
00527 *info = 1;
00528 goto L100;
00529
00530 L50:
00531
00532
00533
00534
00535
00536 i__1 = *k;
00537 for (i__ = 1; i__ <= i__1; ++i__) {
00538 alpha[i__] = 1.f;
00539 beta[i__] = 0.f;
00540
00541 }
00542
00543
00544 i__2 = *l, i__3 = *m - *k;
00545 i__1 = min(i__2,i__3);
00546 for (i__ = 1; i__ <= i__1; ++i__) {
00547
00548 a1 = a[*k + i__ + (*n - *l + i__) * a_dim1];
00549 b1 = b[i__ + (*n - *l + i__) * b_dim1];
00550
00551 if (a1 != 0.f) {
00552 gamma = b1 / a1;
00553
00554
00555
00556 if (gamma < 0.f) {
00557 i__2 = *l - i__ + 1;
00558 sscal_(&i__2, &c_b43, &b[i__ + (*n - *l + i__) * b_dim1], ldb)
00559 ;
00560 if (wantv) {
00561 sscal_(p, &c_b43, &v[i__ * v_dim1 + 1], &c__1);
00562 }
00563 }
00564
00565 r__1 = dabs(gamma);
00566 slartg_(&r__1, &c_b14, &beta[*k + i__], &alpha[*k + i__], &rwk);
00567
00568 if (alpha[*k + i__] >= beta[*k + i__]) {
00569 i__2 = *l - i__ + 1;
00570 r__1 = 1.f / alpha[*k + i__];
00571 sscal_(&i__2, &r__1, &a[*k + i__ + (*n - *l + i__) * a_dim1],
00572 lda);
00573 } else {
00574 i__2 = *l - i__ + 1;
00575 r__1 = 1.f / beta[*k + i__];
00576 sscal_(&i__2, &r__1, &b[i__ + (*n - *l + i__) * b_dim1], ldb);
00577 i__2 = *l - i__ + 1;
00578 scopy_(&i__2, &b[i__ + (*n - *l + i__) * b_dim1], ldb, &a[*k
00579 + i__ + (*n - *l + i__) * a_dim1], lda);
00580 }
00581
00582 } else {
00583
00584 alpha[*k + i__] = 0.f;
00585 beta[*k + i__] = 1.f;
00586 i__2 = *l - i__ + 1;
00587 scopy_(&i__2, &b[i__ + (*n - *l + i__) * b_dim1], ldb, &a[*k +
00588 i__ + (*n - *l + i__) * a_dim1], lda);
00589
00590 }
00591
00592
00593 }
00594
00595
00596
00597 i__1 = *k + *l;
00598 for (i__ = *m + 1; i__ <= i__1; ++i__) {
00599 alpha[i__] = 0.f;
00600 beta[i__] = 1.f;
00601
00602 }
00603
00604 if (*k + *l < *n) {
00605 i__1 = *n;
00606 for (i__ = *k + *l + 1; i__ <= i__1; ++i__) {
00607 alpha[i__] = 0.f;
00608 beta[i__] = 0.f;
00609
00610 }
00611 }
00612
00613 L100:
00614 *ncycle = kcycle;
00615 return 0;
00616
00617
00618
00619 }