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 doublereal c_b3 = 0.;
00019
00020 int dlatm4_(integer *itype, integer *n, integer *nz1,
00021 integer *nz2, integer *isign, doublereal *amagn, doublereal *rcond,
00022 doublereal *triang, integer *idist, integer *iseed, doublereal *a,
00023 integer *lda)
00024 {
00025
00026 integer a_dim1, a_offset, i__1, i__2, i__3, i__4;
00027 doublereal d__1, d__2, d__3, d__4;
00028
00029
00030 double pow_dd(doublereal *, doublereal *), log(doublereal), exp(
00031 doublereal), sqrt(doublereal);
00032
00033
00034 integer i__, k, jc, jd;
00035 doublereal cl, cr;
00036 integer jr;
00037 doublereal sl, sr, sv1, sv2;
00038 integer kbeg, isdb, kend, ioff, isde, klen;
00039 doublereal temp, alpha;
00040 extern doublereal dlamch_(char *), dlaran_(integer *), dlarnd_(
00041 integer *, integer *);
00042 extern int dlaset_(char *, integer *, integer *,
00043 doublereal *, doublereal *, doublereal *, integer *);
00044 doublereal safmin;
00045
00046
00047
00048
00049
00050
00051
00052
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 --iseed;
00171 a_dim1 = *lda;
00172 a_offset = 1 + a_dim1;
00173 a -= a_offset;
00174
00175
00176 if (*n <= 0) {
00177 return 0;
00178 }
00179 dlaset_("Full", n, n, &c_b3, &c_b3, &a[a_offset], lda);
00180
00181
00182
00183 if (iseed[4] % 2 != 1) {
00184 ++iseed[4];
00185 }
00186
00187
00188
00189
00190 if (*itype != 0) {
00191 if (abs(*itype) >= 4) {
00192
00193
00194 i__3 = *n, i__4 = *nz1 + 1;
00195 i__1 = 1, i__2 = min(i__3,i__4);
00196 kbeg = max(i__1,i__2);
00197
00198
00199 i__3 = *n, i__4 = *n - *nz2;
00200 i__1 = kbeg, i__2 = min(i__3,i__4);
00201 kend = max(i__1,i__2);
00202 klen = kend + 1 - kbeg;
00203 } else {
00204 kbeg = 1;
00205 kend = *n;
00206 klen = *n;
00207 }
00208 isdb = 1;
00209 isde = 0;
00210 switch (abs(*itype)) {
00211 case 1: goto L10;
00212 case 2: goto L30;
00213 case 3: goto L50;
00214 case 4: goto L80;
00215 case 5: goto L100;
00216 case 6: goto L120;
00217 case 7: goto L140;
00218 case 8: goto L160;
00219 case 9: goto L180;
00220 case 10: goto L200;
00221 }
00222
00223
00224
00225 L10:
00226 i__1 = *n;
00227 for (jd = 1; jd <= i__1; ++jd) {
00228 a[jd + jd * a_dim1] = 1.;
00229
00230 }
00231 goto L220;
00232
00233
00234
00235 L30:
00236 i__1 = *n - 1;
00237 for (jd = 1; jd <= i__1; ++jd) {
00238 a[jd + 1 + jd * a_dim1] = 1.;
00239
00240 }
00241 isdb = 1;
00242 isde = *n - 1;
00243 goto L220;
00244
00245
00246
00247
00248 L50:
00249 k = (*n - 1) / 2;
00250 i__1 = k;
00251 for (jd = 1; jd <= i__1; ++jd) {
00252 a[jd + 1 + jd * a_dim1] = 1.;
00253
00254 }
00255 isdb = 1;
00256 isde = k;
00257 i__1 = (k << 1) + 1;
00258 for (jd = k + 2; jd <= i__1; ++jd) {
00259 a[jd + jd * a_dim1] = 1.;
00260
00261 }
00262 goto L220;
00263
00264
00265
00266 L80:
00267 i__1 = kend;
00268 for (jd = kbeg; jd <= i__1; ++jd) {
00269 a[jd + jd * a_dim1] = (doublereal) (jd - *nz1);
00270
00271 }
00272 goto L220;
00273
00274
00275
00276 L100:
00277 i__1 = kend;
00278 for (jd = kbeg + 1; jd <= i__1; ++jd) {
00279 a[jd + jd * a_dim1] = *rcond;
00280
00281 }
00282 a[kbeg + kbeg * a_dim1] = 1.;
00283 goto L220;
00284
00285
00286
00287 L120:
00288 i__1 = kend - 1;
00289 for (jd = kbeg; jd <= i__1; ++jd) {
00290 a[jd + jd * a_dim1] = 1.;
00291
00292 }
00293 a[kend + kend * a_dim1] = *rcond;
00294 goto L220;
00295
00296
00297
00298 L140:
00299 a[kbeg + kbeg * a_dim1] = 1.;
00300 if (klen > 1) {
00301 d__1 = 1. / (doublereal) (klen - 1);
00302 alpha = pow_dd(rcond, &d__1);
00303 i__1 = klen;
00304 for (i__ = 2; i__ <= i__1; ++i__) {
00305 d__1 = (doublereal) (i__ - 1);
00306 a[*nz1 + i__ + (*nz1 + i__) * a_dim1] = pow_dd(&alpha, &d__1);
00307
00308 }
00309 }
00310 goto L220;
00311
00312
00313
00314 L160:
00315 a[kbeg + kbeg * a_dim1] = 1.;
00316 if (klen > 1) {
00317 alpha = (1. - *rcond) / (doublereal) (klen - 1);
00318 i__1 = klen;
00319 for (i__ = 2; i__ <= i__1; ++i__) {
00320 a[*nz1 + i__ + (*nz1 + i__) * a_dim1] = (doublereal) (klen -
00321 i__) * alpha + *rcond;
00322
00323 }
00324 }
00325 goto L220;
00326
00327
00328
00329 L180:
00330 alpha = log(*rcond);
00331 i__1 = kend;
00332 for (jd = kbeg; jd <= i__1; ++jd) {
00333 a[jd + jd * a_dim1] = exp(alpha * dlaran_(&iseed[1]));
00334
00335 }
00336 goto L220;
00337
00338
00339
00340 L200:
00341 i__1 = kend;
00342 for (jd = kbeg; jd <= i__1; ++jd) {
00343 a[jd + jd * a_dim1] = dlarnd_(idist, &iseed[1]);
00344
00345 }
00346
00347 L220:
00348
00349
00350
00351 i__1 = kend;
00352 for (jd = kbeg; jd <= i__1; ++jd) {
00353 a[jd + jd * a_dim1] = *amagn * a[jd + jd * a_dim1];
00354
00355 }
00356 i__1 = isde;
00357 for (jd = isdb; jd <= i__1; ++jd) {
00358 a[jd + 1 + jd * a_dim1] = *amagn * a[jd + 1 + jd * a_dim1];
00359
00360 }
00361
00362
00363
00364
00365 if (*isign > 0) {
00366 i__1 = kend;
00367 for (jd = kbeg; jd <= i__1; ++jd) {
00368 if (a[jd + jd * a_dim1] != 0.) {
00369 if (dlaran_(&iseed[1]) > .5) {
00370 a[jd + jd * a_dim1] = -a[jd + jd * a_dim1];
00371 }
00372 }
00373
00374 }
00375 i__1 = isde;
00376 for (jd = isdb; jd <= i__1; ++jd) {
00377 if (a[jd + 1 + jd * a_dim1] != 0.) {
00378 if (dlaran_(&iseed[1]) > .5) {
00379 a[jd + 1 + jd * a_dim1] = -a[jd + 1 + jd * a_dim1];
00380 }
00381 }
00382
00383 }
00384 }
00385
00386
00387
00388 if (*itype < 0) {
00389 i__1 = (kbeg + kend - 1) / 2;
00390 for (jd = kbeg; jd <= i__1; ++jd) {
00391 temp = a[jd + jd * a_dim1];
00392 a[jd + jd * a_dim1] = a[kbeg + kend - jd + (kbeg + kend - jd)
00393 * a_dim1];
00394 a[kbeg + kend - jd + (kbeg + kend - jd) * a_dim1] = temp;
00395
00396 }
00397 i__1 = (*n - 1) / 2;
00398 for (jd = 1; jd <= i__1; ++jd) {
00399 temp = a[jd + 1 + jd * a_dim1];
00400 a[jd + 1 + jd * a_dim1] = a[*n + 1 - jd + (*n - jd) * a_dim1];
00401 a[*n + 1 - jd + (*n - jd) * a_dim1] = temp;
00402
00403 }
00404 }
00405
00406
00407
00408
00409 if (*isign == 2 && *itype != 2 && *itype != 3) {
00410 safmin = dlamch_("S");
00411 i__1 = kend - 1;
00412 for (jd = kbeg; jd <= i__1; jd += 2) {
00413 if (dlaran_(&iseed[1]) > .5) {
00414
00415
00416
00417 cl = dlaran_(&iseed[1]) * 2. - 1.;
00418 sl = dlaran_(&iseed[1]) * 2. - 1.;
00419
00420
00421 d__3 = cl;
00422
00423 d__4 = sl;
00424 d__1 = safmin, d__2 = sqrt(d__3 * d__3 + d__4 * d__4);
00425 temp = 1. / max(d__1,d__2);
00426 cl *= temp;
00427 sl *= temp;
00428
00429
00430
00431 cr = dlaran_(&iseed[1]) * 2. - 1.;
00432 sr = dlaran_(&iseed[1]) * 2. - 1.;
00433
00434
00435 d__3 = cr;
00436
00437 d__4 = sr;
00438 d__1 = safmin, d__2 = sqrt(d__3 * d__3 + d__4 * d__4);
00439 temp = 1. / max(d__1,d__2);
00440 cr *= temp;
00441 sr *= temp;
00442
00443
00444
00445 sv1 = a[jd + jd * a_dim1];
00446 sv2 = a[jd + 1 + (jd + 1) * a_dim1];
00447 a[jd + jd * a_dim1] = cl * cr * sv1 + sl * sr * sv2;
00448 a[jd + 1 + jd * a_dim1] = -sl * cr * sv1 + cl * sr * sv2;
00449 a[jd + (jd + 1) * a_dim1] = -cl * sr * sv1 + sl * cr *
00450 sv2;
00451 a[jd + 1 + (jd + 1) * a_dim1] = sl * sr * sv1 + cl * cr *
00452 sv2;
00453 }
00454
00455 }
00456 }
00457
00458 }
00459
00460
00461
00462 if (*triang != 0.) {
00463 if (*isign != 2 || *itype == 2 || *itype == 3) {
00464 ioff = 1;
00465 } else {
00466 ioff = 2;
00467 i__1 = *n - 1;
00468 for (jr = 1; jr <= i__1; ++jr) {
00469 if (a[jr + 1 + jr * a_dim1] == 0.) {
00470 a[jr + (jr + 1) * a_dim1] = *triang * dlarnd_(idist, &
00471 iseed[1]);
00472 }
00473
00474 }
00475 }
00476
00477 i__1 = *n;
00478 for (jc = 2; jc <= i__1; ++jc) {
00479 i__2 = jc - ioff;
00480 for (jr = 1; jr <= i__2; ++jr) {
00481 a[jr + jc * a_dim1] = *triang * dlarnd_(idist, &iseed[1]);
00482
00483 }
00484
00485 }
00486 }
00487
00488 return 0;
00489
00490
00491
00492 }