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_b5 = -1.f;
00019 static integer c__1 = 1;
00020 static real c_b13 = 1.f;
00021 static real c_b15 = 0.f;
00022 static integer c__0 = 0;
00023
00024 int clals0_(integer *icompq, integer *nl, integer *nr,
00025 integer *sqre, integer *nrhs, complex *b, integer *ldb, complex *bx,
00026 integer *ldbx, integer *perm, integer *givptr, integer *givcol,
00027 integer *ldgcol, real *givnum, integer *ldgnum, real *poles, real *
00028 difl, real *difr, real *z__, integer *k, real *c__, real *s, real *
00029 rwork, integer *info)
00030 {
00031
00032 integer givcol_dim1, givcol_offset, difr_dim1, difr_offset, givnum_dim1,
00033 givnum_offset, poles_dim1, poles_offset, b_dim1, b_offset,
00034 bx_dim1, bx_offset, i__1, i__2, i__3, i__4, i__5;
00035 real r__1;
00036 complex q__1;
00037
00038
00039 double r_imag(complex *);
00040
00041
00042 integer i__, j, m, n;
00043 real dj;
00044 integer nlp1, jcol;
00045 real temp;
00046 integer jrow;
00047 extern doublereal snrm2_(integer *, real *, integer *);
00048 real diflj, difrj, dsigj;
00049 extern int ccopy_(integer *, complex *, integer *,
00050 complex *, integer *), sgemv_(char *, integer *, integer *, real *
00051 , real *, integer *, real *, integer *, real *, real *, integer *), csrot_(integer *, complex *, integer *, complex *,
00052 integer *, real *, real *);
00053 extern doublereal slamc3_(real *, real *);
00054 extern int clascl_(char *, integer *, integer *, real *,
00055 real *, integer *, integer *, complex *, integer *, integer *), csscal_(integer *, real *, complex *, integer *),
00056 clacpy_(char *, integer *, integer *, complex *, integer *,
00057 complex *, integer *), xerbla_(char *, integer *);
00058 real dsigjp;
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 b_dim1 = *ldb;
00231 b_offset = 1 + b_dim1;
00232 b -= b_offset;
00233 bx_dim1 = *ldbx;
00234 bx_offset = 1 + bx_dim1;
00235 bx -= bx_offset;
00236 --perm;
00237 givcol_dim1 = *ldgcol;
00238 givcol_offset = 1 + givcol_dim1;
00239 givcol -= givcol_offset;
00240 difr_dim1 = *ldgnum;
00241 difr_offset = 1 + difr_dim1;
00242 difr -= difr_offset;
00243 poles_dim1 = *ldgnum;
00244 poles_offset = 1 + poles_dim1;
00245 poles -= poles_offset;
00246 givnum_dim1 = *ldgnum;
00247 givnum_offset = 1 + givnum_dim1;
00248 givnum -= givnum_offset;
00249 --difl;
00250 --z__;
00251 --rwork;
00252
00253
00254 *info = 0;
00255
00256 if (*icompq < 0 || *icompq > 1) {
00257 *info = -1;
00258 } else if (*nl < 1) {
00259 *info = -2;
00260 } else if (*nr < 1) {
00261 *info = -3;
00262 } else if (*sqre < 0 || *sqre > 1) {
00263 *info = -4;
00264 }
00265
00266 n = *nl + *nr + 1;
00267
00268 if (*nrhs < 1) {
00269 *info = -5;
00270 } else if (*ldb < n) {
00271 *info = -7;
00272 } else if (*ldbx < n) {
00273 *info = -9;
00274 } else if (*givptr < 0) {
00275 *info = -11;
00276 } else if (*ldgcol < n) {
00277 *info = -13;
00278 } else if (*ldgnum < n) {
00279 *info = -15;
00280 } else if (*k < 1) {
00281 *info = -20;
00282 }
00283 if (*info != 0) {
00284 i__1 = -(*info);
00285 xerbla_("CLALS0", &i__1);
00286 return 0;
00287 }
00288
00289 m = n + *sqre;
00290 nlp1 = *nl + 1;
00291
00292 if (*icompq == 0) {
00293
00294
00295
00296
00297
00298 i__1 = *givptr;
00299 for (i__ = 1; i__ <= i__1; ++i__) {
00300 csrot_(nrhs, &b[givcol[i__ + (givcol_dim1 << 1)] + b_dim1], ldb, &
00301 b[givcol[i__ + givcol_dim1] + b_dim1], ldb, &givnum[i__ +
00302 (givnum_dim1 << 1)], &givnum[i__ + givnum_dim1]);
00303
00304 }
00305
00306
00307
00308 ccopy_(nrhs, &b[nlp1 + b_dim1], ldb, &bx[bx_dim1 + 1], ldbx);
00309 i__1 = n;
00310 for (i__ = 2; i__ <= i__1; ++i__) {
00311 ccopy_(nrhs, &b[perm[i__] + b_dim1], ldb, &bx[i__ + bx_dim1],
00312 ldbx);
00313
00314 }
00315
00316
00317
00318
00319 if (*k == 1) {
00320 ccopy_(nrhs, &bx[bx_offset], ldbx, &b[b_offset], ldb);
00321 if (z__[1] < 0.f) {
00322 csscal_(nrhs, &c_b5, &b[b_offset], ldb);
00323 }
00324 } else {
00325 i__1 = *k;
00326 for (j = 1; j <= i__1; ++j) {
00327 diflj = difl[j];
00328 dj = poles[j + poles_dim1];
00329 dsigj = -poles[j + (poles_dim1 << 1)];
00330 if (j < *k) {
00331 difrj = -difr[j + difr_dim1];
00332 dsigjp = -poles[j + 1 + (poles_dim1 << 1)];
00333 }
00334 if (z__[j] == 0.f || poles[j + (poles_dim1 << 1)] == 0.f) {
00335 rwork[j] = 0.f;
00336 } else {
00337 rwork[j] = -poles[j + (poles_dim1 << 1)] * z__[j] / diflj
00338 / (poles[j + (poles_dim1 << 1)] + dj);
00339 }
00340 i__2 = j - 1;
00341 for (i__ = 1; i__ <= i__2; ++i__) {
00342 if (z__[i__] == 0.f || poles[i__ + (poles_dim1 << 1)] ==
00343 0.f) {
00344 rwork[i__] = 0.f;
00345 } else {
00346 rwork[i__] = poles[i__ + (poles_dim1 << 1)] * z__[i__]
00347 / (slamc3_(&poles[i__ + (poles_dim1 << 1)], &
00348 dsigj) - diflj) / (poles[i__ + (poles_dim1 <<
00349 1)] + dj);
00350 }
00351
00352 }
00353 i__2 = *k;
00354 for (i__ = j + 1; i__ <= i__2; ++i__) {
00355 if (z__[i__] == 0.f || poles[i__ + (poles_dim1 << 1)] ==
00356 0.f) {
00357 rwork[i__] = 0.f;
00358 } else {
00359 rwork[i__] = poles[i__ + (poles_dim1 << 1)] * z__[i__]
00360 / (slamc3_(&poles[i__ + (poles_dim1 << 1)], &
00361 dsigjp) + difrj) / (poles[i__ + (poles_dim1 <<
00362 1)] + dj);
00363 }
00364
00365 }
00366 rwork[1] = -1.f;
00367 temp = snrm2_(k, &rwork[1], &c__1);
00368
00369
00370
00371
00372
00373
00374
00375 i__ = *k + (*nrhs << 1);
00376 i__2 = *nrhs;
00377 for (jcol = 1; jcol <= i__2; ++jcol) {
00378 i__3 = *k;
00379 for (jrow = 1; jrow <= i__3; ++jrow) {
00380 ++i__;
00381 i__4 = jrow + jcol * bx_dim1;
00382 rwork[i__] = bx[i__4].r;
00383
00384 }
00385
00386 }
00387 sgemv_("T", k, nrhs, &c_b13, &rwork[*k + 1 + (*nrhs << 1)], k,
00388 &rwork[1], &c__1, &c_b15, &rwork[*k + 1], &c__1);
00389 i__ = *k + (*nrhs << 1);
00390 i__2 = *nrhs;
00391 for (jcol = 1; jcol <= i__2; ++jcol) {
00392 i__3 = *k;
00393 for (jrow = 1; jrow <= i__3; ++jrow) {
00394 ++i__;
00395 rwork[i__] = r_imag(&bx[jrow + jcol * bx_dim1]);
00396
00397 }
00398
00399 }
00400 sgemv_("T", k, nrhs, &c_b13, &rwork[*k + 1 + (*nrhs << 1)], k,
00401 &rwork[1], &c__1, &c_b15, &rwork[*k + 1 + *nrhs], &
00402 c__1);
00403 i__2 = *nrhs;
00404 for (jcol = 1; jcol <= i__2; ++jcol) {
00405 i__3 = j + jcol * b_dim1;
00406 i__4 = jcol + *k;
00407 i__5 = jcol + *k + *nrhs;
00408 q__1.r = rwork[i__4], q__1.i = rwork[i__5];
00409 b[i__3].r = q__1.r, b[i__3].i = q__1.i;
00410
00411 }
00412 clascl_("G", &c__0, &c__0, &temp, &c_b13, &c__1, nrhs, &b[j +
00413 b_dim1], ldb, info);
00414
00415 }
00416 }
00417
00418
00419
00420 if (*k < max(m,n)) {
00421 i__1 = n - *k;
00422 clacpy_("A", &i__1, nrhs, &bx[*k + 1 + bx_dim1], ldbx, &b[*k + 1
00423 + b_dim1], ldb);
00424 }
00425 } else {
00426
00427
00428
00429
00430
00431
00432 if (*k == 1) {
00433 ccopy_(nrhs, &b[b_offset], ldb, &bx[bx_offset], ldbx);
00434 } else {
00435 i__1 = *k;
00436 for (j = 1; j <= i__1; ++j) {
00437 dsigj = poles[j + (poles_dim1 << 1)];
00438 if (z__[j] == 0.f) {
00439 rwork[j] = 0.f;
00440 } else {
00441 rwork[j] = -z__[j] / difl[j] / (dsigj + poles[j +
00442 poles_dim1]) / difr[j + (difr_dim1 << 1)];
00443 }
00444 i__2 = j - 1;
00445 for (i__ = 1; i__ <= i__2; ++i__) {
00446 if (z__[j] == 0.f) {
00447 rwork[i__] = 0.f;
00448 } else {
00449 r__1 = -poles[i__ + 1 + (poles_dim1 << 1)];
00450 rwork[i__] = z__[j] / (slamc3_(&dsigj, &r__1) - difr[
00451 i__ + difr_dim1]) / (dsigj + poles[i__ +
00452 poles_dim1]) / difr[i__ + (difr_dim1 << 1)];
00453 }
00454
00455 }
00456 i__2 = *k;
00457 for (i__ = j + 1; i__ <= i__2; ++i__) {
00458 if (z__[j] == 0.f) {
00459 rwork[i__] = 0.f;
00460 } else {
00461 r__1 = -poles[i__ + (poles_dim1 << 1)];
00462 rwork[i__] = z__[j] / (slamc3_(&dsigj, &r__1) - difl[
00463 i__]) / (dsigj + poles[i__ + poles_dim1]) /
00464 difr[i__ + (difr_dim1 << 1)];
00465 }
00466
00467 }
00468
00469
00470
00471
00472
00473
00474
00475 i__ = *k + (*nrhs << 1);
00476 i__2 = *nrhs;
00477 for (jcol = 1; jcol <= i__2; ++jcol) {
00478 i__3 = *k;
00479 for (jrow = 1; jrow <= i__3; ++jrow) {
00480 ++i__;
00481 i__4 = jrow + jcol * b_dim1;
00482 rwork[i__] = b[i__4].r;
00483
00484 }
00485
00486 }
00487 sgemv_("T", k, nrhs, &c_b13, &rwork[*k + 1 + (*nrhs << 1)], k,
00488 &rwork[1], &c__1, &c_b15, &rwork[*k + 1], &c__1);
00489 i__ = *k + (*nrhs << 1);
00490 i__2 = *nrhs;
00491 for (jcol = 1; jcol <= i__2; ++jcol) {
00492 i__3 = *k;
00493 for (jrow = 1; jrow <= i__3; ++jrow) {
00494 ++i__;
00495 rwork[i__] = r_imag(&b[jrow + jcol * b_dim1]);
00496
00497 }
00498
00499 }
00500 sgemv_("T", k, nrhs, &c_b13, &rwork[*k + 1 + (*nrhs << 1)], k,
00501 &rwork[1], &c__1, &c_b15, &rwork[*k + 1 + *nrhs], &
00502 c__1);
00503 i__2 = *nrhs;
00504 for (jcol = 1; jcol <= i__2; ++jcol) {
00505 i__3 = j + jcol * bx_dim1;
00506 i__4 = jcol + *k;
00507 i__5 = jcol + *k + *nrhs;
00508 q__1.r = rwork[i__4], q__1.i = rwork[i__5];
00509 bx[i__3].r = q__1.r, bx[i__3].i = q__1.i;
00510
00511 }
00512
00513 }
00514 }
00515
00516
00517
00518
00519 if (*sqre == 1) {
00520 ccopy_(nrhs, &b[m + b_dim1], ldb, &bx[m + bx_dim1], ldbx);
00521 csrot_(nrhs, &bx[bx_dim1 + 1], ldbx, &bx[m + bx_dim1], ldbx, c__,
00522 s);
00523 }
00524 if (*k < max(m,n)) {
00525 i__1 = n - *k;
00526 clacpy_("A", &i__1, nrhs, &b[*k + 1 + b_dim1], ldb, &bx[*k + 1 +
00527 bx_dim1], ldbx);
00528 }
00529
00530
00531
00532 ccopy_(nrhs, &bx[bx_dim1 + 1], ldbx, &b[nlp1 + b_dim1], ldb);
00533 if (*sqre == 1) {
00534 ccopy_(nrhs, &bx[m + bx_dim1], ldbx, &b[m + b_dim1], ldb);
00535 }
00536 i__1 = n;
00537 for (i__ = 2; i__ <= i__1; ++i__) {
00538 ccopy_(nrhs, &bx[i__ + bx_dim1], ldbx, &b[perm[i__] + b_dim1],
00539 ldb);
00540
00541 }
00542
00543
00544
00545 for (i__ = *givptr; i__ >= 1; --i__) {
00546 r__1 = -givnum[i__ + givnum_dim1];
00547 csrot_(nrhs, &b[givcol[i__ + (givcol_dim1 << 1)] + b_dim1], ldb, &
00548 b[givcol[i__ + givcol_dim1] + b_dim1], ldb, &givnum[i__ +
00549 (givnum_dim1 << 1)], &r__1);
00550
00551 }
00552 }
00553
00554 return 0;
00555
00556
00557
00558 }