1
       2
       3
       4
       5
       6
       7
       8
       9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      19
      20
      21
      22
      23
      24
      25
      26
      27
      28
      29
      30
      31
      32
      33
      34
      35
      36
      37
      38
      39
      40
      41
      42
      43
      44
      45
      46
      47
      48
      49
      50
      51
      52
      53
      54
      55
      56
      57
      58
      59
      60
      61
      62
      63
      64
      65
      66
      67
      68
      69
      70
      71
      72
      73
      74
      75
      76
      77
      78
      79
      80
      81
      82
      83
      84
      85
      86
      87
      88
      89
      90
      91
      92
      93
      94
      95
      96
      97
      98
      99
     100
     101
     102
     103
     104
     105
     106
     107
     108
     109
     110
     111
     112
     113
     114
     115
     116
     117
     118
     119
     120
     121
     122
     123
     124
     125
     126
     127
     128
     129
     130
     131
     132
     133
     134
     135
     136
     137
     138
     139
     140
     141
     142
     143
     144
     145
     146
     147
     148
     149
     150
     151
     152
     153
     154
     155
     156
     157
     158
     159
     160
     161
     162
     163
     164
     165
     166
     167
     168
     169
     170
     171
     172
     173
     174
     175
     176
     177
     178
     179
     180
     181
     182
     183
     184
     185
     186
     187
     188
     189
     190
     191
     192
     193
     194
     195
     196
     197
     198
     199
     200
     201
     202
     203
     204
     205
     206
     207
     208
     209
     210
     211
     212
     213
     214
     215
     216
     217
     218
     219
     220
     221
     222
     223
     224
     225
     226
     227
     228
     229
     230
     231
     232
     233
     234
     235
     236
     237
     238
     239
     240
     241
     242
     243
     244
     245
     246
     247
     248
     249
     250
     251
     252
     253
     254
     255
     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
     316
     317
     318
     319
     320
     321
     322
     323
     324
     325
     326
     327
     328
     329
     330
     331
     332
     333
     334
     335
     336
     337
     338
     339
     340
     341
     342
     343
     344
     345
     346
     347
     348
     349
     350
     351
     352
     353
     354
     355
     356
     357
     358
     359
     360
     361
     362
     363
     364
     365
     366
     367
     368
     369
     370
     371
     372
     373
     374
     375
     376
     377
     378
     379
     380
     381
     382
     383
     384
     385
     386
     387
     388
     389
     390
     391
     392
     393
     394
     395
     396
     397
     398
     399
     400
     401
     402
     403
     404
     405
     406
     407
     408
     409
     410
     411
     412
     413
     414
     415
     416
     417
     418
     419
     420
     421
     422
     423
     424
     425
     426
     427
     428
     429
     430
     431
     432
     433
     434
     435
     436
     437
     438
     439
     440
     441
     442
     443
     444
     445
     446
     447
     448
     449
     450
     451
     452
     453
     454
     455
     456
     457
     458
     459
     460
     461
     462
     463
     464
     465
     466
     467
     468
     469
     470
     471
     472
     473
     474
     475
     476
     477
     478
     479
     480
     481
     482
     483
     484
     485
     486
     487
     488
     489
     490
     491
     492
     493
     494
     495
     496
     497
     498
     499
     500
     501
     502
     503
     504
     505
     506
     507
     508
     509
     510
     511
     512
     513
     514
     515
     516
     517
     518
     519
     520
     521
     522
     523
     524
     525
     526
     527
     528
     529
     530
     531
     532
     533
     534
     535
     536
     537
     538
     539
     540
      SUBROUTINE ZLATMENDISTISEEDDMODECONDDMAXEI
     $  RSIGN
     $                   UPPERSIMDSMODESCONDSKLKUANORM
     $  A
     $                   LDAWORKINFO )
*
*  -- LAPACK test routine (version 3.1) --
*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
*     June 2010
*
*     .. Scalar Arguments ..
      CHARACTER          DISTEIRSIGNSIMUPPER
      INTEGER            INFOKLKULDAMODEMODESN
      DOUBLE PRECISION   ANORMCONDCONDS
      COMPLEX*16         DMAX
*     ..
*     .. Array Arguments ..
      INTEGER            ISEED4 )
      DOUBLE PRECISION   DS* )
      COMPLEX*16         ALDA* ), D* ), WORK* )
*     ..
*
*  Purpose
*  =======
*
*     ZLATME generates random non-symmetric square matrices with
*     specified eigenvalues for testing LAPACK programs.
*
*     ZLATME operates by applying the following sequence of
*     operations:
*
*     1. Set the diagonal to D, where D may be input or
*          computed according to MODE, COND, DMAX, and RSIGN
*          as described below.
*
*     2. If UPPER='T', the upper triangle of A is set to random values
*          out of distribution DIST.
*
*     3. If SIM='T', A is multiplied on the left by a random matrix
*          X, whose singular values are specified by DS, MODES, and
*          CONDS, and on the right by X inverse.
*
*     4. If KL < N-1, the lower bandwidth is reduced to KL using
*          Householder transformations.  If KU < N-1, the upper
*          bandwidth is reduced to KU.
*
*     5. If ANORM is not negative, the matrix is scaled to have
*          maximum-element-norm ANORM.
*
*     (Note: since the matrix cannot be reduced beyond Hessenberg form,
*      no packing options are available.)
*
*  Arguments
*  =========
*
*  N        (input) INTEGER
*           The number of columns (or rows) of A. Not modified.
*
*  DIST     (input) CHARACTER*1
*           On entry, DIST specifies the type of distribution to be used
*           to generate the random eigen-/singular values, and on the
*           upper triangle (see UPPER).
*           'U' => UNIFORM( 0, 1 )  ( 'U' for uniform )
*           'S' => UNIFORM( -1, 1 ) ( 'S' for symmetric )
*           'N' => NORMAL( 0, 1 )   ( 'N' for normal )
*           'D' => uniform on the complex disc |z| < 1.
*           Not modified.
*
*  ISEED    (input/output) INTEGER array, dimension ( 4 )
*           On entry ISEED specifies the seed of the random number
*           generator. They should lie between 0 and 4095 inclusive,
*           and ISEED(4) should be odd. The random number generator
*           uses a linear congruential sequence limited to small
*           integers, and so should produce machine independent
*           random numbers. The values of ISEED are changed on
*           exit, and can be used in the next call to ZLATME
*           to continue the same random number sequence.
*           Changed on exit.
*
*  D        (input/output) COMPLEX*16 array, dimension ( N )
*           This array is used to specify the eigenvalues of A.  If
*           MODE=0, then D is assumed to contain the eigenvalues
*           otherwise they will be computed according to MODE, COND,
*           DMAX, and RSIGN and placed in D.
*           Modified if MODE is nonzero.
*
*  MODE     (input) INTEGER
*           On entry this describes how the eigenvalues are to
*           be specified:
*           MODE = 0 means use D as input
*           MODE = 1 sets D(1)=1 and D(2:N)=1.0/COND
*           MODE = 2 sets D(1:N-1)=1 and D(N)=1.0/COND
*           MODE = 3 sets D(I)=COND**(-(I-1)/(N-1))
*           MODE = 4 sets D(i)=1 - (i-1)/(N-1)*(1 - 1/COND)
*           MODE = 5 sets D to random numbers in the range
*                    ( 1/COND , 1 ) such that their logarithms
*                    are uniformly distributed.
*           MODE = 6 set D to random numbers from same distribution
*                    as the rest of the matrix.
*           MODE < 0 has the same meaning as ABS(MODE), except that
*              the order of the elements of D is reversed.
*           Thus if MODE is between 1 and 4, D has entries ranging
*              from 1 to 1/COND, if between -1 and -4, D has entries
*              ranging from 1/COND to 1,
*           Not modified.
*
*  COND     (input) DOUBLE PRECISION
*           On entry, this is used as described under MODE above.
*           If used, it must be >= 1. Not modified.
*
*  DMAX     (input) COMPLEX*16
*           If MODE is neither -6, 0 nor 6, the contents of D, as
*           computed according to MODE and COND, will be scaled by
*           DMAX / max(abs(D(i))).  Note that DMAX need not be
*           positive or real: if DMAX is negative or complex (or zero),
*           D will be scaled by a negative or complex number (or zero).
*           If RSIGN='F' then the largest (absolute) eigenvalue will be
*           equal to DMAX.
*           Not modified.
*
*  EI       (input) CHARACTER*1 array, dimension ( N )
*           (ignored)
*           Not modified.
*
*  RSIGN    (input) CHARACTER*1
*           If MODE is not 0, 6, or -6, and RSIGN='T', then the
*           elements of D, as computed according to MODE and COND, will
*           be multiplied by a random complex number from the unit
*           circle |z| = 1.  If RSIGN='F', they will not be.  RSIGN may
*           only have the values 'T' or 'F'.
*           Not modified.
*
*  UPPER    (input) CHARACTER*1
*           If UPPER='T', then the elements of A above the diagonal
*           will be set to random numbers out of DIST.  If UPPER='F',
*           they will not.  UPPER may only have the values 'T' or 'F'.
*           Not modified.
*
*  SIM      (input) CHARACTER*1
*           If SIM='T', then A will be operated on by a "similarity
*           transform", i.e., multiplied on the left by a matrix X and
*           on the right by X inverse.  X = U S V, where U and V are
*           random unitary matrices and S is a (diagonal) matrix of
*           singular values specified by DS, MODES, and CONDS.  If
*           SIM='F', then A will not be transformed.
*           Not modified.
*
*  DS       (input/output) DOUBLE PRECISION array, dimension ( N )
*           This array is used to specify the singular values of X,
*           in the same way that D specifies the eigenvalues of A.
*           If MODE=0, the DS contains the singular values, which
*           may not be zero.
*           Modified if MODE is nonzero.
*
*  MODES    (input) INTEGER
*
*  CONDS    (input) DOUBLE PRECISION
*           Similar to MODE and COND, but for specifying the diagonal
*           of S.  MODES=-6 and +6 are not allowed (since they would
*           result in randomly ill-conditioned eigenvalues.)
*
*  KL       (input) INTEGER
*           This specifies the lower bandwidth of the  matrix.  KL=1
*           specifies upper Hessenberg form.  If KL is at least N-1,
*           then A will have full lower bandwidth.
*           Not modified.
*
*  KU       (input) INTEGER
*           This specifies the upper bandwidth of the  matrix.  KU=1
*           specifies lower Hessenberg form.  If KU is at least N-1,
*           then A will have full upper bandwidth; if KU and KL
*           are both at least N-1, then A will be dense.  Only one of
*           KU and KL may be less than N-1.
*           Not modified.
*
*  ANORM    (input) DOUBLE PRECISION
*           If ANORM is not negative, then A will be scaled by a non-
*           negative real number to make the maximum-element-norm of A
*           to be ANORM.
*           Not modified.
*
*  A        (output) COMPLEX*16 array, dimension ( LDA, N )
*           On exit A is the desired test matrix.
*           Modified.
*
*  LDA      (input) INTEGER
*           LDA specifies the first dimension of A as declared in the
*           calling program.  LDA must be at least M.
*           Not modified.
*
*  WORK     (workspace) COMPLEX*16 array, dimension ( 3*N )
*           Workspace.
*           Modified.
*
*  INFO     (output) INTEGER
*           Error code.  On exit, INFO will be set to one of the
*           following values:
*             0 => normal return
*            -1 => N negative
*            -2 => DIST illegal string
*            -5 => MODE not in range -6 to 6
*            -6 => COND less than 1.0, and MODE neither -6, 0 nor 6
*            -9 => RSIGN is not 'T' or 'F'
*           -10 => UPPER is not 'T' or 'F'
*           -11 => SIM   is not 'T' or 'F'
*           -12 => MODES=0 and DS has a zero singular value.
*           -13 => MODES is not in the range -5 to 5.
*           -14 => MODES is nonzero and CONDS is less than 1.
*           -15 => KL is less than 1.
*           -16 => KU is less than 1, or KL and KU are both less than
*                  N-1.
*           -19 => LDA is less than M.
*            1  => Error return from ZLATM1 (computing D)
*            2  => Cannot scale to DMAX (max. eigenvalue is 0)
*            3  => Error return from DLATM1 (computing DS)
*            4  => Error return from ZLARGE
*            5  => Zero singular value from DLATM1.
*
*  =====================================================================
*
*     .. Parameters ..
      DOUBLE PRECISION   ZERO
      PARAMETER          ( ZERO = 0.0D+0 )
      DOUBLE PRECISION   ONE
      PARAMETER          ( ONE = 1.0D+0 )
      COMPLEX*16         CZERO
      PARAMETER          ( CZERO = ( 0.0D+00.0D+0 ) )
      COMPLEX*16         CONE
      PARAMETER          ( CONE = ( 1.0D+00.0D+0 ) )
*     ..
*     .. Local Scalars ..
      LOGICAL            BADS
      INTEGER            IICICOLSIDISTIINFOIRIROWSIRSIGN,
     $                   ISIMIUPPERJJCJCR
      DOUBLE PRECISION   RALPHATEMP
      COMPLEX*16         ALPHATAUXNORMS
*     ..
*     .. Local Arrays ..
      DOUBLE PRECISION   TEMPA1 )
*     ..
*     .. External Functions ..
      LOGICAL            LSAME
      DOUBLE PRECISION   ZLANGE
      COMPLEX*16         ZLARND
      EXTERNAL           LSAMEZLANGEZLARND
*     ..
*     .. External Subroutines ..
      EXTERNAL           DLATM1XERBLAZCOPYZDSCALZGEMVZGERC,
     $                   ZLACGVZLARFGZLARGEZLARNVZLASETZLATM1,
     $                   ZSCAL
*     ..
*     .. Intrinsic Functions ..
      INTRINSIC          ABSDCONJGMAXMOD
*     ..
*     .. Executable Statements ..
*
*     1)      Decode and Test the input parameters.
*             Initialize flags & seed.
*
      INFO = 0
*
*     Quick return if possible
*
      IFN.EQ.0 )
     $   RETURN
*
*     Decode DIST
*
      IFLSAMEDIST'U' ) ) THEN
         IDIST = 1
      ELSE IFLSAMEDIST'S' ) ) THEN
         IDIST = 2
      ELSE IFLSAMEDIST'N' ) ) THEN
         IDIST = 3
      ELSE IFLSAMEDIST'D' ) ) THEN
         IDIST = 4
      ELSE
         IDIST = -1
      END IF
*
*     Decode RSIGN
*
      IFLSAMERSIGN'T' ) ) THEN
         IRSIGN = 1
      ELSE IFLSAMERSIGN'F' ) ) THEN
         IRSIGN = 0
      ELSE
         IRSIGN = -1
      END IF
*
*     Decode UPPER
*
      IFLSAMEUPPER'T' ) ) THEN
         IUPPER = 1
      ELSE IFLSAMEUPPER'F' ) ) THEN
         IUPPER = 0
      ELSE
         IUPPER = -1
      END IF
*
*     Decode SIM
*
      IFLSAMESIM'T' ) ) THEN
         ISIM = 1
      ELSE IFLSAMESIM'F' ) ) THEN
         ISIM = 0
      ELSE
         ISIM = -1
      END IF
*
*     Check DS, if MODES=0 and ISIM=1
*
      BADS = .FALSE.
      IFMODES.EQ.0 .AND. ISIM.EQ.1 ) THEN
         DO 10 J = 1N
            IFDSJ ).EQ.ZERO )
     $         BADS = .TRUE.
   10    CONTINUE
      END IF
*
*     Set INFO if an error
*
      IFN.LT.0 ) THEN
         INFO = -1
      ELSE IFIDIST.EQ.-1 ) THEN
         INFO = -2
      ELSE IFABSMODE ).GT.6 ) THEN
         INFO = -5
      ELSE IF( ( MODE.NE.0 .AND. ABSMODE ).NE.6 ) .AND. COND.LT.ONE )
     $          THEN
         INFO = -6
      ELSE IFIRSIGN.EQ.-1 ) THEN
         INFO = -9
      ELSE IFIUPPER.EQ.-1 ) THEN
         INFO = -10
      ELSE IFISIM.EQ.-1 ) THEN
         INFO = -11
      ELSE IFBADS ) THEN
         INFO = -12
      ELSE IFISIM.EQ.1 .AND. ABSMODES ).GT.5 ) THEN
         INFO = -13
      ELSE IFISIM.EQ.1 .AND. MODES.NE.0 .AND. CONDS.LT.ONE ) THEN
         INFO = -14
      ELSE IFKL.LT.1 ) THEN
         INFO = -15
      ELSE IFKU.LT.1 .OR. ( KU.LT.N-1 .AND. KL.LT.N-1 ) ) THEN
         INFO = -16
      ELSE IFLDA.LT.MAX1N ) ) THEN
         INFO = -19
      END IF
*
      IFINFO.NE.0 ) THEN
         CALL XERBLA'ZLATME'-INFO )
         RETURN
      END IF
*
*     Initialize random number generator
*
      DO 20 I = 14
         ISEEDI ) = MODABSISEEDI ) ), 4096 )
   20 CONTINUE
*
      IFMODISEED4 ), 2 ).NE.1 )
     $   ISEED4 ) = ISEED4 ) + 1
*
*     2)      Set up diagonal of A
*
*             Compute D according to COND and MODE
*
      CALL ZLATM1MODECONDIRSIGNIDISTISEEDDNIINFO )
      IFIINFO.NE.0 ) THEN
         INFO = 1
         RETURN
      END IF
      IFMODE.NE.0 .AND. ABSMODE ).NE.6 ) THEN
*
*        Scale by DMAX
*
         TEMP = ABSD1 ) )
         DO 30 I = 2N
            TEMP = MAXTEMPABSDI ) ) )
   30    CONTINUE
*
         IFTEMP.GT.ZERO ) THEN
            ALPHA = DMAX / TEMP
         ELSE
            INFO = 2
            RETURN
         END IF
*
         CALL ZSCALNALPHAD1 )
*
      END IF
*
      CALL ZLASET'Full'NNCZEROCZEROALDA )
      CALL ZCOPYND1ALDA+1 )
*
*     3)      If UPPER='T', set upper triangle of A to random numbers.
*
      IFIUPPER.NE.0 ) THEN
         DO 40 JC = 2N
            CALL ZLARNVIDISTISEEDJC-1A1JC ) )
   40    CONTINUE
      END IF
*
*     4)      If SIM='T', apply similarity transformation.
*
*                                -1
*             Transform is  X A X  , where X = U S V, thus
*
*             it is  U S V A V' (1/S) U'
*
      IFISIM.NE.0 ) THEN
*
*        Compute S (singular values of the eigenvector matrix)
*        according to CONDS and MODES
*
         CALL DLATM1MODESCONDS00ISEEDDSNIINFO )
         IFIINFO.NE.0 ) THEN
            INFO = 3
            RETURN
         END IF
*
*        Multiply by V and V'
*
         CALL ZLARGENALDAISEEDWORKIINFO )
         IFIINFO.NE.0 ) THEN
            INFO = 4
            RETURN
         END IF
*
*        Multiply by S and (1/S)
*
         DO 50 J = 1N
            CALL ZDSCALNDSJ ), AJ1 ), LDA )
            IFDSJ ).NE.ZERO ) THEN
               CALL ZDSCALNONE / DSJ ), A1J ), 1 )
            ELSE
               INFO = 5
               RETURN
            END IF
   50    CONTINUE
*
*        Multiply by U and U'
*
         CALL ZLARGENALDAISEEDWORKIINFO )
         IFIINFO.NE.0 ) THEN
            INFO = 4
            RETURN
         END IF
      END IF
*
*     5)      Reduce the bandwidth.
*
      IFKL.LT.N-1 ) THEN
*
*        Reduce bandwidth -- kill column
*
         DO 60 JCR = KL + 1N - 1
            IC = JCR - KL
            IROWS = N + 1 - JCR
            ICOLS = N + KL - JCR
*
            CALL ZCOPYIROWSAJCRIC ), 1WORK1 )
            XNORMS = WORK1 )
            CALL ZLARFGIROWSXNORMSWORK2 ), 1TAU )
            TAU = DCONJGTAU )
            WORK1 ) = CONE
            ALPHA = ZLARND5ISEED )
*
            CALL ZGEMV'C'IROWSICOLSCONEAJCRIC+1 ), LDA,
     $                  WORK1CZEROWORKIROWS+1 ), 1 )
            CALL ZGERCIROWSICOLS-TAUWORK1WORKIROWS+1 ), 1,
     $                  AJCRIC+1 ), LDA )
*
            CALL ZGEMV'N'NIROWSCONEA1JCR ), LDAWORK1,
     $                  CZEROWORKIROWS+1 ), 1 )
            CALL ZGERCNIROWS-DCONJGTAU ), WORKIROWS+1 ), 1,
     $                  WORK1A1JCR ), LDA )
*
            AJCRIC ) = XNORMS
            CALL ZLASET'Full'IROWS-11CZEROCZERO,
     $                   AJCR+1IC ), LDA )
*
            CALL ZSCALICOLS+1ALPHAAJCRIC ), LDA )
            CALL ZSCALNDCONJGALPHA ), A1JCR ), 1 )
   60    CONTINUE
      ELSE IFKU.LT.N-1 ) THEN
*
*        Reduce upper bandwidth -- kill a row at a time.
*
         DO 70 JCR = KU + 1N - 1
            IR = JCR - KU
            IROWS = N + KU - JCR
            ICOLS = N + 1 - JCR
*
            CALL ZCOPYICOLSAIRJCR ), LDAWORK1 )
            XNORMS = WORK1 )
            CALL ZLARFGICOLSXNORMSWORK2 ), 1TAU )
            TAU = DCONJGTAU )
            WORK1 ) = CONE
            CALL ZLACGVICOLS-1WORK2 ), 1 )
            ALPHA = ZLARND5ISEED )
*
            CALL ZGEMV'N'IROWSICOLSCONEAIR+1JCR ), LDA,
     $                  WORK1CZEROWORKICOLS+1 ), 1 )
            CALL ZGERCIROWSICOLS-TAUWORKICOLS+1 ), 1WORK1,
     $                  AIR+1JCR ), LDA )
*
            CALL ZGEMV'C'ICOLSNCONEAJCR1 ), LDAWORK1,
     $                  CZEROWORKICOLS+1 ), 1 )
            CALL ZGERCICOLSN-DCONJGTAU ), WORK1,
     $                  WORKICOLS+1 ), 1AJCR1 ), LDA )
*
            AIRJCR ) = XNORMS
            CALL ZLASET'Full'1ICOLS-1CZEROCZERO,
     $                   AIRJCR+1 ), LDA )
*
            CALL ZSCALIROWS+1ALPHAAIRJCR ), 1 )
            CALL ZSCALNDCONJGALPHA ), AJCR1 ), LDA )
   70    CONTINUE
      END IF
*
*     Scale the matrix to have norm ANORM
*
      IFANORM.GE.ZERO ) THEN
         TEMP = ZLANGE'M'NNALDATEMPA )
         IFTEMP.GT.ZERO ) THEN
            RALPHA = ANORM / TEMP
            DO 80 J = 1N
               CALL ZDSCALNRALPHAA1J ), 1 )
   80       CONTINUE
         END IF
      END IF
*
      RETURN
*
*     End of ZLATME
*
      END