133
134
135
136
137
138
139 CHARACTER DIAG, TRANS, UPLO
140 INTEGER IMAT, INFO, LDA, N
141
142
143 INTEGER ISEED( 4 )
144 DOUBLE PRECISION A( LDA, * ), B( * ), WORK( * )
145
146
147
148
149
150 DOUBLE PRECISION ONE, TWO, ZERO
151 parameter( one = 1.0d+0, two = 2.0d+0, zero = 0.0d+0 )
152
153
154 LOGICAL UPPER
155 CHARACTER DIST, TYPE
156 CHARACTER*3 PATH
157 INTEGER I, IY, J, JCOUNT, KL, KU, MODE
158 DOUBLE PRECISION ANORM, BIGNUM, BNORM, BSCAL, C, CNDNUM, PLUS1,
159 $ PLUS2, RA, RB, REXP, S, SFAC, SMLNUM, STAR1,
160 $ TEXP, TLEFT, TSCAL, ULP, UNFL, X, Y, Z
161
162
163 LOGICAL LSAME
164 INTEGER IDAMAX
165 DOUBLE PRECISION DLAMCH, DLARND
167
168
171
172
173 INTRINSIC abs, dble, max, sign, sqrt
174
175
176
177 path( 1: 1 ) = 'Double precision'
178 path( 2: 3 ) = 'TR'
179 unfl =
dlamch(
'Safe minimum' )
181 smlnum = unfl
182 bignum = ( one-ulp ) / smlnum
183 IF( ( imat.GE.7 .AND. imat.LE.10 ) .OR. imat.EQ.18 ) THEN
184 diag = 'U'
185 ELSE
186 diag = 'N'
187 END IF
188 info = 0
189
190
191
192 IF( n.LE.0 )
193 $ RETURN
194
195
196
197 upper =
lsame( uplo,
'U' )
198 IF( upper ) THEN
199 CALL dlatb4( path, imat, n, n,
TYPE, KL, KU, ANORM, MODE,
200 $ CNDNUM, DIST )
201 ELSE
202 CALL dlatb4( path, -imat, n, n,
TYPE, KL, KU, ANORM, MODE,
203 $ CNDNUM, DIST )
204 END IF
205
206
207
208 IF( imat.LE.6 ) THEN
209 CALL dlatms( n, n, dist, iseed,
TYPE, B, MODE, CNDNUM, ANORM,
210 $ KL, KU, 'No packing', A, LDA, WORK, INFO )
211
212
213
214
215
216
217 ELSE IF( imat.EQ.7 ) THEN
218 IF( upper ) THEN
219 DO 20 j = 1, n
220 DO 10 i = 1, j - 1
221 a( i, j ) = zero
222 10 CONTINUE
223 a( j, j ) = j
224 20 CONTINUE
225 ELSE
226 DO 40 j = 1, n
227 a( j, j ) = j
228 DO 30 i = j + 1, n
229 a( i, j ) = zero
230 30 CONTINUE
231 40 CONTINUE
232 END IF
233
234
235
236
237
238
239
240 ELSE IF( imat.LE.10 ) THEN
241 IF( upper ) THEN
242 DO 60 j = 1, n
243 DO 50 i = 1, j - 1
244 a( i, j ) = zero
245 50 CONTINUE
246 a( j, j ) = j
247 60 CONTINUE
248 ELSE
249 DO 80 j = 1, n
250 a( j, j ) = j
251 DO 70 i = j + 1, n
252 a( i, j ) = zero
253 70 CONTINUE
254 80 CONTINUE
255 END IF
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315 star1 = 0.25d0
316 sfac = 0.5d0
317 plus1 = sfac
318 DO 90 j = 1, n, 2
319 plus2 = star1 / plus1
320 work( j ) = plus1
321 work( n+j ) = star1
322 IF( j+1.LE.n ) THEN
323 work( j+1 ) = plus2
324 work( n+j+1 ) = zero
325 plus1 = star1 / plus2
327 star1 = star1*( sfac**rexp )
328 IF( rexp.LT.zero ) THEN
329 star1 = -sfac**( one-rexp )
330 ELSE
331 star1 = sfac**( one+rexp )
332 END IF
333 END IF
334 90 CONTINUE
335
336 x = sqrt( cndnum ) - 1 / sqrt( cndnum )
337 IF( n.GT.2 ) THEN
338 y = sqrt( 2.d0 / ( n-2 ) )*x
339 ELSE
340 y = zero
341 END IF
342 z = x*x
343
344 IF( upper ) THEN
345 IF( n.GT.3 ) THEN
346 CALL dcopy( n-3, work, 1, a( 2, 3 ), lda+1 )
347 IF( n.GT.4 )
348 $
CALL dcopy( n-4, work( n+1 ), 1, a( 2, 4 ), lda+1 )
349 END IF
350 DO 100 j = 2, n - 1
351 a( 1, j ) = y
352 a( j, n ) = y
353 100 CONTINUE
354 a( 1, n ) = z
355 ELSE
356 IF( n.GT.3 ) THEN
357 CALL dcopy( n-3, work, 1, a( 3, 2 ), lda+1 )
358 IF( n.GT.4 )
359 $
CALL dcopy( n-4, work( n+1 ), 1, a( 4, 2 ), lda+1 )
360 END IF
361 DO 110 j = 2, n - 1
362 a( j, 1 ) = y
363 a( n, j ) = y
364 110 CONTINUE
365 a( n, 1 ) = z
366 END IF
367
368
369
370 IF( upper ) THEN
371 DO 120 j = 1, n - 1
372 ra = a( j, j+1 )
373 rb = 2.0d0
374 CALL drotg( ra, rb, c, s )
375
376
377
378 IF( n.GT.j+1 )
379 $
CALL drot( n-j-1, a( j, j+2 ), lda, a( j+1, j+2 ),
380 $ lda, c, s )
381
382
383
384 IF( j.GT.1 )
385 $
CALL drot( j-1, a( 1, j+1 ), 1, a( 1, j ), 1, -c, -s )
386
387
388
389 a( j, j+1 ) = -a( j, j+1 )
390 120 CONTINUE
391 ELSE
392 DO 130 j = 1, n - 1
393 ra = a( j+1, j )
394 rb = 2.0d0
395 CALL drotg( ra, rb, c, s )
396
397
398
399 IF( n.GT.j+1 )
400 $
CALL drot( n-j-1, a( j+2, j+1 ), 1, a( j+2, j ), 1, c,
401 $ -s )
402
403
404
405 IF( j.GT.1 )
406 $
CALL drot( j-1, a( j, 1 ), lda, a( j+1, 1 ), lda, -c,
407 $ s )
408
409
410
411 a( j+1, j ) = -a( j+1, j )
412 130 CONTINUE
413 END IF
414
415
416
417
418
419 ELSE IF( imat.EQ.11 ) THEN
420
421
422
423
424
425 IF( upper ) THEN
426 DO 140 j = 1, n
427 CALL dlarnv( 2, iseed, j, a( 1, j ) )
428 a( j, j ) = sign( two, a( j, j ) )
429 140 CONTINUE
430 ELSE
431 DO 150 j = 1, n
432 CALL dlarnv( 2, iseed, n-j+1, a( j, j ) )
433 a( j, j ) = sign( two, a( j, j ) )
434 150 CONTINUE
435 END IF
436
437
438
439 CALL dlarnv( 2, iseed, n, b )
441 bnorm = abs( b( iy ) )
442 bscal = bignum / max( one, bnorm )
443 CALL dscal( n, bscal, b, 1 )
444
445 ELSE IF( imat.EQ.12 ) THEN
446
447
448
449
450
451 CALL dlarnv( 2, iseed, n, b )
452 tscal = one / max( one, dble( n-1 ) )
453 IF( upper ) THEN
454 DO 160 j = 1, n
455 CALL dlarnv( 2, iseed, j, a( 1, j ) )
456 CALL dscal( j-1, tscal, a( 1, j ), 1 )
457 a( j, j ) = sign( one, a( j, j ) )
458 160 CONTINUE
459 a( n, n ) = smlnum*a( n, n )
460 ELSE
461 DO 170 j = 1, n
462 CALL dlarnv( 2, iseed, n-j+1, a( j, j ) )
463 IF( n.GT.j )
464 $
CALL dscal( n-j, tscal, a( j+1, j ), 1 )
465 a( j, j ) = sign( one, a( j, j ) )
466 170 CONTINUE
467 a( 1, 1 ) = smlnum*a( 1, 1 )
468 END IF
469
470 ELSE IF( imat.EQ.13 ) THEN
471
472
473
474
475
476 CALL dlarnv( 2, iseed, n, b )
477 IF( upper ) THEN
478 DO 180 j = 1, n
479 CALL dlarnv( 2, iseed, j, a( 1, j ) )
480 a( j, j ) = sign( one, a( j, j ) )
481 180 CONTINUE
482 a( n, n ) = smlnum*a( n, n )
483 ELSE
484 DO 190 j = 1, n
485 CALL dlarnv( 2, iseed, n-j+1, a( j, j ) )
486 a( j, j ) = sign( one, a( j, j ) )
487 190 CONTINUE
488 a( 1, 1 ) = smlnum*a( 1, 1 )
489 END IF
490
491 ELSE IF( imat.EQ.14 ) THEN
492
493
494
495
496
497 IF( upper ) THEN
498 jcount = 1
499 DO 210 j = n, 1, -1
500 DO 200 i = 1, j - 1
501 a( i, j ) = zero
502 200 CONTINUE
503 IF( jcount.LE.2 ) THEN
504 a( j, j ) = smlnum
505 ELSE
506 a( j, j ) = one
507 END IF
508 jcount = jcount + 1
509 IF( jcount.GT.4 )
510 $ jcount = 1
511 210 CONTINUE
512 ELSE
513 jcount = 1
514 DO 230 j = 1, n
515 DO 220 i = j + 1, n
516 a( i, j ) = zero
517 220 CONTINUE
518 IF( jcount.LE.2 ) THEN
519 a( j, j ) = smlnum
520 ELSE
521 a( j, j ) = one
522 END IF
523 jcount = jcount + 1
524 IF( jcount.GT.4 )
525 $ jcount = 1
526 230 CONTINUE
527 END IF
528
529
530
531 IF( upper ) THEN
532 b( 1 ) = zero
533 DO 240 i = n, 2, -2
534 b( i ) = zero
535 b( i-1 ) = smlnum
536 240 CONTINUE
537 ELSE
538 b( n ) = zero
539 DO 250 i = 1, n - 1, 2
540 b( i ) = zero
541 b( i+1 ) = smlnum
542 250 CONTINUE
543 END IF
544
545 ELSE IF( imat.EQ.15 ) THEN
546
547
548
549
550
551 texp = one / max( one, dble( n-1 ) )
552 tscal = smlnum**texp
553 CALL dlarnv( 2, iseed, n, b )
554 IF( upper ) THEN
555 DO 270 j = 1, n
556 DO 260 i = 1, j - 2
557 a( i, j ) = 0.d0
558 260 CONTINUE
559 IF( j.GT.1 )
560 $ a( j-1, j ) = -one
561 a( j, j ) = tscal
562 270 CONTINUE
563 b( n ) = one
564 ELSE
565 DO 290 j = 1, n
566 DO 280 i = j + 2, n
567 a( i, j ) = 0.d0
568 280 CONTINUE
569 IF( j.LT.n )
570 $ a( j+1, j ) = -one
571 a( j, j ) = tscal
572 290 CONTINUE
573 b( 1 ) = one
574 END IF
575
576 ELSE IF( imat.EQ.16 ) THEN
577
578
579
580 iy = n / 2 + 1
581 IF( upper ) THEN
582 DO 300 j = 1, n
583 CALL dlarnv( 2, iseed, j, a( 1, j ) )
584 IF( j.NE.iy ) THEN
585 a( j, j ) = sign( two, a( j, j ) )
586 ELSE
587 a( j, j ) = zero
588 END IF
589 300 CONTINUE
590 ELSE
591 DO 310 j = 1, n
592 CALL dlarnv( 2, iseed, n-j+1, a( j, j ) )
593 IF( j.NE.iy ) THEN
594 a( j, j ) = sign( two, a( j, j ) )
595 ELSE
596 a( j, j ) = zero
597 END IF
598 310 CONTINUE
599 END IF
600 CALL dlarnv( 2, iseed, n, b )
601 CALL dscal( n, two, b, 1 )
602
603 ELSE IF( imat.EQ.17 ) THEN
604
605
606
607
608
609
610 tscal = unfl / ulp
611 tscal = ( one-ulp ) / tscal
612 DO 330 j = 1, n
613 DO 320 i = 1, n
614 a( i, j ) = 0.d0
615 320 CONTINUE
616 330 CONTINUE
617 texp = one
618 IF( upper ) THEN
619 DO 340 j = n, 2, -2
620 a( 1, j ) = -tscal / dble( n+1 )
621 a( j, j ) = one
622 b( j ) = texp*( one-ulp )
623 a( 1, j-1 ) = -( tscal / dble( n+1 ) ) / dble( n+2 )
624 a( j-1, j-1 ) = one
625 b( j-1 ) = texp*dble( n*n+n-1 )
626 texp = texp*2.d0
627 340 CONTINUE
628 b( 1 ) = ( dble( n+1 ) / dble( n+2 ) )*tscal
629 ELSE
630 DO 350 j = 1, n - 1, 2
631 a( n, j ) = -tscal / dble( n+1 )
632 a( j, j ) = one
633 b( j ) = texp*( one-ulp )
634 a( n, j+1 ) = -( tscal / dble( n+1 ) ) / dble( n+2 )
635 a( j+1, j+1 ) = one
636 b( j+1 ) = texp*dble( n*n+n-1 )
637 texp = texp*2.d0
638 350 CONTINUE
639 b( n ) = ( dble( n+1 ) / dble( n+2 ) )*tscal
640 END IF
641
642 ELSE IF( imat.EQ.18 ) THEN
643
644
645
646
647
648 IF( upper ) THEN
649 DO 360 j = 1, n
650 CALL dlarnv( 2, iseed, j-1, a( 1, j ) )
651 a( j, j ) = zero
652 360 CONTINUE
653 ELSE
654 DO 370 j = 1, n
655 IF( j.LT.n )
656 $
CALL dlarnv( 2, iseed, n-j, a( j+1, j ) )
657 a( j, j ) = zero
658 370 CONTINUE
659 END IF
660
661
662
663 CALL dlarnv( 2, iseed, n, b )
665 bnorm = abs( b( iy ) )
666 bscal = bignum / max( one, bnorm )
667 CALL dscal( n, bscal, b, 1 )
668
669 ELSE IF( imat.EQ.19 ) THEN
670
671
672
673
674
675
676 tleft = bignum / max( one, dble( n-1 ) )
677 tscal = bignum*( dble( n-1 ) / max( one, dble( n ) ) )
678 IF( upper ) THEN
679 DO 390 j = 1, n
680 CALL dlarnv( 2, iseed, j, a( 1, j ) )
681 DO 380 i = 1, j
682 a( i, j ) = sign( tleft, a( i, j ) ) + tscal*a( i, j )
683 380 CONTINUE
684 390 CONTINUE
685 ELSE
686 DO 410 j = 1, n
687 CALL dlarnv( 2, iseed, n-j+1, a( j, j ) )
688 DO 400 i = j, n
689 a( i, j ) = sign( tleft, a( i, j ) ) + tscal*a( i, j )
690 400 CONTINUE
691 410 CONTINUE
692 END IF
693 CALL dlarnv( 2, iseed, n, b )
694 CALL dscal( n, two, b, 1 )
695 END IF
696
697
698
699 IF( .NOT.
lsame( trans,
'N' ) )
THEN
700 IF( upper ) THEN
701 DO 420 j = 1, n / 2
702 CALL dswap( n-2*j+1, a( j, j ), lda, a( j+1, n-j+1 ),
703 $ -1 )
704 420 CONTINUE
705 ELSE
706 DO 430 j = 1, n / 2
707 CALL dswap( n-2*j+1, a( j, j ), 1, a( n-j+1, j+1 ),
708 $ -lda )
709 430 CONTINUE
710 END IF
711 END IF
712
713 RETURN
714
715
716
double precision function dlarnd(idist, iseed)
DLARND
subroutine dlatb4(path, imat, m, n, type, kl, ku, anorm, mode, cndnum, dist)
DLATB4
subroutine dlatms(m, n, dist, iseed, sym, d, mode, cond, dmax, kl, ku, pack, a, lda, work, info)
DLATMS
subroutine dcopy(n, dx, incx, dy, incy)
DCOPY
integer function idamax(n, dx, incx)
IDAMAX
double precision function dlamch(cmach)
DLAMCH
subroutine dlarnv(idist, iseed, n, x)
DLARNV returns a vector of random numbers from a uniform or normal distribution.
logical function lsame(ca, cb)
LSAME
subroutine drot(n, dx, incx, dy, incy, c, s)
DROT
subroutine drotg(a, b, c, s)
DROTG
subroutine dscal(n, da, dx, incx)
DSCAL
subroutine dswap(n, dx, incx, dy, incy)
DSWAP