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
     541
     542
     543
     544
     545
     546
     547
     548
     549
     550
     551
     552
     553
     554
     555
     556
     557
     558
     559
     560
     561
     562
     563
     564
     565
     566
     567
     568
     569
     570
     571
     572
     573
     574
     575
     576
     577
     578
     579
     580
     581
     582
     583
     584
     585
     586
     587
     588
     589
     590
     591
     592
     593
     594
     595
     596
     597
     598
     599
     600
     601
     602
     603
     604
     605
     606
     607
     608
     609
     610
     611
     612
     613
     614
     615
     616
     617
     618
     619
     620
     621
     622
     623
     624
     625
     626
     627
     628
     629
     630
     631
     632
     633
     634
     635
     636
     637
     638
     639
     640
     641
     642
     643
     644
     645
     646
     647
     648
     649
     650
     651
     652
     653
     654
     655
     656
     657
     658
     659
     660
     661
     662
     663
     664
     665
     666
     667
     668
     669
     670
     671
     672
     673
     674
     675
     676
     677
     678
     679
     680
     681
     682
     683
     684
     685
     686
     687
     688
     689
     690
     691
     692
     693
     694
     695
     696
     697
     698
     699
     700
     701
     702
     703
     704
     705
     706
     707
     708
     709
     710
     711
     712
     713
     714
     715
     716
     717
     718
     719
     720
     721
     722
     723
     724
     725
     726
     727
     728
     729
     730
     731
     732
     733
     734
     735
     736
     737
     738
     739
     740
     741
     742
     743
     744
     745
     746
     747
     748
     749
     750
     751
     752
     753
     754
     755
     756
     757
     758
     759
     760
     761
     762
     763
     764
     765
     766
     767
     768
     769
     770
     771
     772
     773
     774
     775
     776
     777
     778
     779
     780
     781
     782
     783
     784
     785
     786
     787
     788
     789
     790
     791
     792
     793
     794
     795
     796
     797
     798
     799
     800
     801
     802
     803
     804
     805
     806
     807
     808
     809
     810
     811
     812
     813
     814
     815
     816
     817
     818
     819
     820
     821
     822
     823
     824
     825
     826
     827
     828
     829
     830
     831
     832
     833
     834
     835
     836
     837
     838
      SUBROUTINE ZDRGSXNSIZENCMAXTHRESHNINNOUTALDABAI,
     $                   BIZQALPHABETACLDCSWORKLWORK,
     $                   RWORKIWORKLIWORKBWORKINFO )
*
*  -- LAPACK test routine (version 3.3.1) --
*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
*  -- April 2011                                                      --
*
*     .. Scalar Arguments ..
      INTEGER            INFOLDALDCLIWORKLWORKNCMAXNIN,
     $                   NOUTNSIZE
      DOUBLE PRECISION   THRESH
*     ..
*     .. Array Arguments ..
      LOGICAL            BWORK* )
      INTEGER            IWORK* )
      DOUBLE PRECISION   RWORK* ), S* )
      COMPLEX*16         ALDA* ), AILDA* ), ALPHA* ),
     $                   BLDA* ), BETA* ), BILDA* ),
     $                   CLDC* ), QLDA* ), WORK* ),
     $                   ZLDA* )
*     ..
*
*  Purpose
*  =======
*
*  ZDRGSX checks the nonsymmetric generalized eigenvalue (Schur form)
*  problem expert driver ZGGESX.
*
*  ZGGES factors A and B as Q*S*Z'  and Q*T*Z' , where ' means conjugate
*  transpose, S and T are  upper triangular (i.e., in generalized Schur
*  form), and Q and Z are unitary. It also computes the generalized
*  eigenvalues (alpha(j),beta(j)), j=1,...,n.  Thus,
*  w(j) = alpha(j)/beta(j) is a root of the characteristic equation
*
*                  det( A - w(j) B ) = 0
*
*  Optionally it also reorders the eigenvalues so that a selected
*  cluster of eigenvalues appears in the leading diagonal block of the
*  Schur forms; computes a reciprocal condition number for the average
*  of the selected eigenvalues; and computes a reciprocal condition
*  number for the right and left deflating subspaces corresponding to
*  the selected eigenvalues.
*
*  When ZDRGSX is called with NSIZE > 0, five (5) types of built-in
*  matrix pairs are used to test the routine ZGGESX.
*
*  When ZDRGSX is called with NSIZE = 0, it reads in test matrix data
*  to test ZGGESX.
*  (need more details on what kind of read-in data are needed).
*
*  For each matrix pair, the following tests will be performed and
*  compared with the threshhold THRESH except for the tests (7) and (9):
*
*  (1)   | A - Q S Z' | / ( |A| n ulp )
*
*  (2)   | B - Q T Z' | / ( |B| n ulp )
*
*  (3)   | I - QQ' | / ( n ulp )
*
*  (4)   | I - ZZ' | / ( n ulp )
*
*  (5)   if A is in Schur form (i.e. triangular form)
*
*  (6)   maximum over j of D(j)  where:
*
*                      |alpha(j) - S(j,j)|        |beta(j) - T(j,j)|
*            D(j) = ------------------------ + -----------------------
*                   max(|alpha(j)|,|S(j,j)|)   max(|beta(j)|,|T(j,j)|)
*
*  (7)   if sorting worked and SDIM is the number of eigenvalues
*        which were selected.
*
*  (8)   the estimated value DIF does not differ from the true values of
*        Difu and Difl more than a factor 10*THRESH. If the estimate DIF
*        equals zero the corresponding true values of Difu and Difl
*        should be less than EPS*norm(A, B). If the true value of Difu
*        and Difl equal zero, the estimate DIF should be less than
*        EPS*norm(A, B).
*
*  (9)   If INFO = N+3 is returned by ZGGESX, the reordering "failed"
*        and we check that DIF = PL = PR = 0 and that the true value of
*        Difu and Difl is < EPS*norm(A, B). We count the events when
*        INFO=N+3.
*
*  For read-in test matrices, the same tests are run except that the
*  exact value for DIF (and PL) is input data.  Additionally, there is
*  one more test run for read-in test matrices:
*
*  (10)  the estimated value PL does not differ from the true value of
*        PLTRU more than a factor THRESH. If the estimate PL equals
*        zero the corresponding true value of PLTRU should be less than
*        EPS*norm(A, B). If the true value of PLTRU equal zero, the
*        estimate PL should be less than EPS*norm(A, B).
*
*  Note that for the built-in tests, a total of 10*NSIZE*(NSIZE-1)
*  matrix pairs are generated and tested. NSIZE should be kept small.
*
*  SVD (routine ZGESVD) is used for computing the true value of DIF_u
*  and DIF_l when testing the built-in test problems.
*
*  Built-in Test Matrices
*  ======================
*
*  All built-in test matrices are the 2 by 2 block of triangular
*  matrices
*
*           A = [ A11 A12 ]    and      B = [ B11 B12 ]
*               [     A22 ]                 [     B22 ]
*
*  where for different type of A11 and A22 are given as the following.
*  A12 and B12 are chosen so that the generalized Sylvester equation
*
*           A11*R - L*A22 = -A12
*           B11*R - L*B22 = -B12
*
*  have prescribed solution R and L.
*
*  Type 1:  A11 = J_m(1,-1) and A_22 = J_k(1-a,1).
*           B11 = I_m, B22 = I_k
*           where J_k(a,b) is the k-by-k Jordan block with ``a'' on
*           diagonal and ``b'' on superdiagonal.
*
*  Type 2:  A11 = (a_ij) = ( 2(.5-sin(i)) ) and
*           B11 = (b_ij) = ( 2(.5-sin(ij)) ) for i=1,...,m, j=i,...,m
*           A22 = (a_ij) = ( 2(.5-sin(i+j)) ) and
*           B22 = (b_ij) = ( 2(.5-sin(ij)) ) for i=m+1,...,k, j=i,...,k
*
*  Type 3:  A11, A22 and B11, B22 are chosen as for Type 2, but each
*           second diagonal block in A_11 and each third diagonal block
*           in A_22 are made as 2 by 2 blocks.
*
*  Type 4:  A11 = ( 20(.5 - sin(ij)) ) and B22 = ( 2(.5 - sin(i+j)) )
*              for i=1,...,m,  j=1,...,m and
*           A22 = ( 20(.5 - sin(i+j)) ) and B22 = ( 2(.5 - sin(ij)) )
*              for i=m+1,...,k,  j=m+1,...,k
*
*  Type 5:  (A,B) and have potentially close or common eigenvalues and
*           very large departure from block diagonality A_11 is chosen
*           as the m x m leading submatrix of A_1:
*                   |  1  b                            |
*                   | -b  1                            |
*                   |        1+d  b                    |
*                   |         -b 1+d                   |
*            A_1 =  |                  d  1            |
*                   |                 -1  d            |
*                   |                        -d  1     |
*                   |                        -1 -d     |
*                   |                               1  |
*           and A_22 is chosen as the k x k leading submatrix of A_2:
*                   | -1  b                            |
*                   | -b -1                            |
*                   |       1-d  b                     |
*                   |       -b  1-d                    |
*            A_2 =  |                 d 1+b            |
*                   |               -1-b d             |
*                   |                       -d  1+b    |
*                   |                      -1+b  -d    |
*                   |                              1-d |
*           and matrix B are chosen as identity matrices (see DLATM5).
*
*
*  Arguments
*  =========
*
*  NSIZE   (input) INTEGER
*          The maximum size of the matrices to use. NSIZE >= 0.
*          If NSIZE = 0, no built-in tests matrices are used, but
*          read-in test matrices are used to test DGGESX.
*
*  NCMAX   (input) INTEGER
*          Maximum allowable NMAX for generating Kroneker matrix
*          in call to ZLAKF2
*
*  THRESH  (input) DOUBLE PRECISION
*          A test will count as "failed" if the "error", computed as
*          described above, exceeds THRESH.  Note that the error
*          is scaled to be O(1), so THRESH should be a reasonably
*          small multiple of 1, e.g., 10 or 100.  In particular,
*          it should not depend on the precision (single vs. double)
*          or the size of the matrix.  THRESH >= 0.
*
*  NIN     (input) INTEGER
*          The FORTRAN unit number for reading in the data file of
*          problems to solve.
*
*  NOUT    (input) INTEGER
*          The FORTRAN unit number for printing out error messages
*          (e.g., if a routine returns INFO not equal to 0.)
*
*  A       (workspace) COMPLEX*16 array, dimension (LDA, NSIZE)
*          Used to store the matrix whose eigenvalues are to be
*          computed.  On exit, A contains the last matrix actually used.
*
*  LDA     (input) INTEGER
*          The leading dimension of A, B, AI, BI, Z and Q,
*          LDA >= max( 1, NSIZE ). For the read-in test,
*          LDA >= max( 1, N ), N is the size of the test matrices.
*
*  B       (workspace) COMPLEX*16 array, dimension (LDA, NSIZE)
*          Used to store the matrix whose eigenvalues are to be
*          computed.  On exit, B contains the last matrix actually used.
*
*  AI      (workspace) COMPLEX*16 array, dimension (LDA, NSIZE)
*          Copy of A, modified by ZGGESX.
*
*  BI      (workspace) COMPLEX*16 array, dimension (LDA, NSIZE)
*          Copy of B, modified by ZGGESX.
*
*  Z       (workspace) COMPLEX*16 array, dimension (LDA, NSIZE)
*          Z holds the left Schur vectors computed by ZGGESX.
*
*  Q       (workspace) COMPLEX*16 array, dimension (LDA, NSIZE)
*          Q holds the right Schur vectors computed by ZGGESX.
*
*  ALPHA   (workspace) COMPLEX*16 array, dimension (NSIZE)
*  BETA    (workspace) COMPLEX*16 array, dimension (NSIZE)
*          On exit, ALPHA/BETA are the eigenvalues.
*
*  C       (workspace) COMPLEX*16 array, dimension (LDC, LDC)
*          Store the matrix generated by subroutine ZLAKF2, this is the
*          matrix formed by Kronecker products used for estimating
*          DIF.
*
*  LDC     (input) INTEGER
*          The leading dimension of C. LDC >= max(1, LDA*LDA/2 ).
*
*  S       (workspace) DOUBLE PRECISION array, dimension (LDC)
*          Singular values of C
*
*  WORK    (workspace) COMPLEX*16 array, dimension (LWORK)
*
*  LWORK   (input) INTEGER
*          The dimension of the array WORK.  LWORK >= 3*NSIZE*NSIZE/2
*
*  RWORK   (workspace) DOUBLE PRECISION array,
*                                 dimension (5*NSIZE*NSIZE/2 - 4)
*
*  IWORK   (workspace) INTEGER array, dimension (LIWORK)
*
*  LIWORK  (input) INTEGER
*          The dimension of the array IWORK. LIWORK >= NSIZE + 2.
*
*  BWORK   (workspace) LOGICAL array, dimension (NSIZE)
*
*  INFO    (output) INTEGER
*          = 0:  successful exit
*          < 0:  if INFO = -i, the i-th argument had an illegal value.
*          > 0:  A routine returned an error code.
*
*  =====================================================================
*
*     .. Parameters ..
      DOUBLE PRECISION   ZEROONETEN
      PARAMETER          ( ZERO = 0.0D+0ONE = 1.0D+0TEN = 1.0D+1 )
      COMPLEX*16         CZERO
      PARAMETER          ( CZERO = ( 0.0D+00.0D+0 ) )
*     ..
*     .. Local Scalars ..
      LOGICAL            ILABAD
      CHARACTER          SENSE
      INTEGER            BDSPACIIFUNCJLINFOMAXWRKMINWRKMM,
     $                   MN2NERRSNPTKNTNTESTNTESTTPRTYPEQBA,
     $                   QBB
      DOUBLE PRECISION   ABNRMBIGNUMDIFTRUPLTRUSMLNUMTEMP1,
     $                   TEMP2THRSH2ULPULPINVWEIGHT
      COMPLEX*16         X
*     ..
*     .. Local Arrays ..
      DOUBLE PRECISION   DIFEST2 ), PL2 ), RESULT10 )
*     ..
*     .. External Functions ..
      LOGICAL            ZLCTSX
      INTEGER            ILAENV
      DOUBLE PRECISION   DLAMCHZLANGE
      EXTERNAL           ZLCTSXILAENVDLAMCHZLANGE
*     ..
*     .. External Subroutines ..
      EXTERNAL           ALASVMDLABADXERBLAZGESVDZGET51ZGGESX,
     $                   ZLACPYZLAKF2ZLASETZLATM5
*     ..
*     .. Scalars in Common ..
      LOGICAL            FS
      INTEGER            KMMPLUSNN
*     ..
*     .. Common blocks ..
      COMMON             / MN / MNMPLUSNKFS
*     ..
*     .. Intrinsic Functions ..
      INTRINSIC          ABSDBLEDIMAGMAXSQRT
*     ..
*     .. Statement Functions ..
      DOUBLE PRECISION   ABS1
*     ..
*     .. Statement Function definitions ..
      ABS1X ) = ABSDBLEX ) ) + ABSDIMAGX ) )
*     ..
*     .. Executable Statements ..
*
*     Check for errors
*
      INFO = 0
      IFNSIZE.LT.0 ) THEN
         INFO = -1
      ELSE IFTHRESH.LT.ZERO ) THEN
         INFO = -2
      ELSE IFNIN.LE.0 ) THEN
         INFO = -3
      ELSE IFNOUT.LE.0 ) THEN
         INFO = -4
      ELSE IFLDA.LT.1 .OR. LDA.LT.NSIZE ) THEN
         INFO = -6
      ELSE IFLDC.LT.1 .OR. LDC.LT.NSIZE*NSIZE / 2 ) THEN
         INFO = -15
      ELSE IFLIWORK.LT.NSIZE+2 ) THEN
         INFO = -21
      END IF
*
*     Compute workspace
*      (Note: Comments in the code beginning "Workspace:" describe the
*       minimal amount of workspace needed at that point in the code,
*       as well as the preferred amount for good performance.
*       NB refers to the optimal block size for the immediately
*       following subroutine, as returned by ILAENV.)
*
      MINWRK = 1
      IFINFO.EQ.0 .AND. LWORK.GE.1 ) THEN
         MINWRK = 3*NSIZE*NSIZE / 2
*
*        workspace for cggesx
*
         MAXWRK = NSIZE*1+ILAENV1'ZGEQRF'' 'NSIZE1NSIZE,
     $            0 ) )
         MAXWRK = MAXMAXWRKNSIZE*1+ILAENV1'ZUNGQR'' ',
     $            NSIZE1NSIZE-1 ) ) )
*
*        workspace for zgesvd
*
         BDSPAC = 3*NSIZE*NSIZE / 2
         MAXWRK = MAXMAXWRKNSIZE*NSIZE*
     $            ( 1+ILAENV1'ZGEBRD'' 'NSIZE*NSIZE / 2,
     $            NSIZE*NSIZE / 2-1-1 ) ) )
         MAXWRK = MAXMAXWRKBDSPAC )
*
         MAXWRK = MAXMAXWRKMINWRK )
*
         WORK1 ) = MAXWRK
      END IF
*
      IFLWORK.LT.MINWRK )
     $   INFO = -18
*
      IFINFO.NE.0 ) THEN
         CALL XERBLA'ZDRGSX'-INFO )
         RETURN
      END IF
*
*     Important constants
*
      ULP = DLAMCH'P' )
      ULPINV = ONE / ULP
      SMLNUM = DLAMCH'S' ) / ULP
      BIGNUM = ONE / SMLNUM
      CALL DLABADSMLNUMBIGNUM )
      THRSH2 = TEN*THRESH
      NTESTT = 0
      NERRS = 0
*
*     Go to the tests for read-in matrix pairs
*
      IFUNC = 0
      IFNSIZE.EQ.0 )
     $   GO TO 70
*
*     Test the built-in matrix pairs.
*     Loop over different functions (IFUNC) of ZGGESX, types (PRTYPE)
*     of test matrices, different size (M+N)
*
      PRTYPE = 0
      QBA = 3
      QBB = 4
      WEIGHT = SQRTULP )
*
      DO 60 IFUNC = 03
         DO 50 PRTYPE = 15
            DO 40 M = 1NSIZE - 1
               DO 30 N = 1NSIZE - M
*
                  WEIGHT = ONE / WEIGHT
                  MPLUSN = M + N
*
*                 Generate test matrices
*
                  FS = .TRUE.
                  K = 0
*
                  CALL ZLASET'Full'MPLUSNMPLUSNCZEROCZEROAI,
     $                         LDA )
                  CALL ZLASET'Full'MPLUSNMPLUSNCZEROCZEROBI,
     $                         LDA )
*
                  CALL ZLATM5PRTYPEMNAILDAAIM+1M+1 ),
     $                         LDAAI1M+1 ), LDABILDA,
     $                         BIM+1M+1 ), LDABI1M+1 ), LDA,
     $                         QLDAZLDAWEIGHTQBAQBB )
*
*                 Compute the Schur factorization and swapping the
*                 m-by-m (1,1)-blocks with n-by-n (2,2)-blocks.
*                 Swapping is accomplished via the function ZLCTSX
*                 which is supplied below.
*
                  IFIFUNC.EQ.0 ) THEN
                     SENSE = 'N'
                  ELSE IFIFUNC.EQ.1 ) THEN
                     SENSE = 'E'
                  ELSE IFIFUNC.EQ.2 ) THEN
                     SENSE = 'V'
                  ELSE IFIFUNC.EQ.3 ) THEN
                     SENSE = 'B'
                  END IF
*
                  CALL ZLACPY'Full'MPLUSNMPLUSNAILDAALDA )
                  CALL ZLACPY'Full'MPLUSNMPLUSNBILDABLDA )
*
                  CALL ZGGESX'V''V''S'ZLCTSXSENSEMPLUSNAI,
     $                         LDABILDAMMALPHABETAQLDAZ,
     $                         LDAPLDIFESTWORKLWORKRWORK,
     $                         IWORKLIWORKBWORKLINFO )
*
                  IFLINFO.NE.0 .AND. LINFO.NE.MPLUSN+2 ) THEN
                     RESULT1 ) = ULPINV
                     WRITENOUT, FMT = 9999 )'ZGGESX', LINFO, MPLUSN,
     $                  PRTYPE
                     INFO = LINFO
                     GO TO 30
                  END IF
*
*                 Compute the norm(A, B)
*
                  CALL ZLACPY'Full'MPLUSNMPLUSNAILDAWORK,
     $                         MPLUSN )
                  CALL ZLACPY'Full'MPLUSNMPLUSNBILDA,
     $                         WORKMPLUSN*MPLUSN+1 ), MPLUSN )
                  ABNRM = ZLANGE'Fro'MPLUSN2*MPLUSNWORKMPLUSN,
     $                    RWORK )
*
*                 Do tests (1) to (4)
*
                  RESULT2 ) = ZERO
                  CALL ZGET511MPLUSNALDAAILDAQLDAZ,
     $                         LDAWORKRWORKRESULT1 ) )
                  CALL ZGET511MPLUSNBLDABILDAQLDAZ,
     $                         LDAWORKRWORKRESULT2 ) )
                  CALL ZGET513MPLUSNBLDABILDAQLDAQ,
     $                         LDAWORKRWORKRESULT3 ) )
                  CALL ZGET513MPLUSNBLDABILDAZLDAZ,
     $                         LDAWORKRWORKRESULT4 ) )
                  NTEST = 4
*
*                 Do tests (5) and (6): check Schur form of A and
*                 compare eigenvalues with diagonals.
*
                  TEMP1 = ZERO
                  RESULT5 ) = ZERO
                  RESULT6 ) = ZERO
*
                  DO 10 J = 1MPLUSN
                     ILABAD = .FALSE.
                     TEMP2 = ( ABS1ALPHAJ )-AIJJ ) ) /
     $                       MAXSMLNUMABS1ALPHAJ ) ),
     $                       ABS1AIJJ ) ) )+
     $                       ABS1BETAJ )-BIJJ ) ) /
     $                       MAXSMLNUMABS1BETAJ ) ),
     $                       ABS1BIJJ ) ) ) ) / ULP
                     IFJ.LT.MPLUSN ) THEN
                        IFAIJ+1J ).NE.ZERO ) THEN
                           ILABAD = .TRUE.
                           RESULT5 ) = ULPINV
                        END IF
                     END IF
                     IFJ.GT.1 ) THEN
                        IFAIJJ-1 ).NE.ZERO ) THEN
                           ILABAD = .TRUE.
                           RESULT5 ) = ULPINV
                        END IF
                     END IF
                     TEMP1 = MAXTEMP1TEMP2 )
                     IFILABAD ) THEN
                        WRITENOUT, FMT = 9997 )J, MPLUSN, PRTYPE
                     END IF
   10             CONTINUE
                  RESULT6 ) = TEMP1
                  NTEST = NTEST + 2
*
*                 Test (7) (if sorting worked)
*
                  RESULT7 ) = ZERO
                  IFLINFO.EQ.MPLUSN+3 ) THEN
                     RESULT7 ) = ULPINV
                  ELSE IFMM.NE.N ) THEN
                     RESULT7 ) = ULPINV
                  END IF
                  NTEST = NTEST + 1
*
*                 Test (8): compare the estimated value DIF and its
*                 value. first, compute the exact DIF.
*
                  RESULT8 ) = ZERO
                  MN2 = MM*MPLUSN-MM )*2
                  IFIFUNC.GE.2 .AND. MN2.LE.NCMAX*NCMAX ) THEN
*
*                    Note: for either following two cases, there are
*                    almost same number of test cases fail the test.
*
                     CALL ZLAKF2MMMPLUSN-MMAILDA,
     $                            AIMM+1MM+1 ), BI,
     $                            BIMM+1MM+1 ), CLDC )
*
                     CALL ZGESVD'N''N'MN2MN2CLDCSWORK,
     $                            1WORK2 ), 1WORK3 ), LWORK-2,
     $                            RWORKINFO )
                     DIFTRU = SMN2 )
*
                     IFDIFEST2 ).EQ.ZERO ) THEN
                        IFDIFTRU.GT.ABNRM*ULP )
     $                     RESULT8 ) = ULPINV
                     ELSE IFDIFTRU.EQ.ZERO ) THEN
                        IFDIFEST2 ).GT.ABNRM*ULP )
     $                     RESULT8 ) = ULPINV
                     ELSE IF( ( DIFTRU.GT.THRSH2*DIFEST2 ) ) .OR.
     $                        ( DIFTRU*THRSH2.LT.DIFEST2 ) ) ) THEN
                        RESULT8 ) = MAXDIFTRU / DIFEST2 ),
     $                                DIFEST2 ) / DIFTRU )
                     END IF
                     NTEST = NTEST + 1
                  END IF
*
*                 Test (9)
*
                  RESULT9 ) = ZERO
                  IFLINFO.EQ.MPLUSN+2 ) ) THEN
                     IFDIFTRU.GT.ABNRM*ULP )
     $                  RESULT9 ) = ULPINV
                     IF( ( IFUNC.GT.1 ) .AND. ( DIFEST2 ).NE.ZERO ) )
     $                  RESULT9 ) = ULPINV
                     IF( ( IFUNC.EQ.1 ) .AND. ( PL1 ).NE.ZERO ) )
     $                  RESULT9 ) = ULPINV
                     NTEST = NTEST + 1
                  END IF
*
                  NTESTT = NTESTT + NTEST
*
*                 Print out tests which fail.
*
                  DO 20 J = 19
                     IFRESULTJ ).GE.THRESH ) THEN
*
*                       If this is the first test to fail,
*                       print a header to the data file.
*
                        IFNERRS.EQ.0 ) THEN
                           WRITENOUT, FMT = 9996 )'ZGX'
*
*                          Matrix types
*
                           WRITENOUT, FMT = 9994 )
*
*                          Tests performed
*
                           WRITENOUT, FMT = 9993 )'unitary''''',
     $                        'transpose', ( '''', I = 14 )
*
                        END IF
                        NERRS = NERRS + 1
                        IFRESULTJ ).LT.10000.0D0 ) THEN
                           WRITENOUT, FMT = 9992 )MPLUSN, PRTYPE,
     $                        WEIGHT, M, J, RESULT( J )
                        ELSE
                           WRITENOUT, FMT = 9991 )MPLUSN, PRTYPE,
     $                        WEIGHT, M, J, RESULT( J )
                        END IF
                     END IF
   20             CONTINUE
*
   30          CONTINUE
   40       CONTINUE
   50    CONTINUE
   60 CONTINUE
*
      GO TO 150
*
   70 CONTINUE
*
*     Read in data from file to check accuracy of condition estimation
*     Read input data until N=0
*
      NPTKNT = 0
*
   80 CONTINUE
      READNIN, FMT = *, END = 140 )MPLUSN
      IFMPLUSN.EQ.0 )
     $   GO TO 140
      READNIN, FMT = *, END = 140 )N
      DO 90 I = 1MPLUSN
         READNIN, FMT = * )( AI( I, J ), J = 1, MPLUSN )
   90 CONTINUE
      DO 100 I = 1MPLUSN
         READNIN, FMT = * )( BI( I, J ), J = 1, MPLUSN )
  100 CONTINUE
      READNIN, FMT = * )PLTRU, DIFTRU
*
      NPTKNT = NPTKNT + 1
      FS = .TRUE.
      K = 0
      M = MPLUSN - N
*
      CALL ZLACPY'Full'MPLUSNMPLUSNAILDAALDA )
      CALL ZLACPY'Full'MPLUSNMPLUSNBILDABLDA )
*
*     Compute the Schur factorization while swaping the
*     m-by-m (1,1)-blocks with n-by-n (2,2)-blocks.
*
      CALL ZGGESX'V''V''S'ZLCTSX'B'MPLUSNAILDABILDA,
     $             MMALPHABETAQLDAZLDAPLDIFESTWORK,
     $             LWORKRWORKIWORKLIWORKBWORKLINFO )
*
      IFLINFO.NE.0 .AND. LINFO.NE.MPLUSN+2 ) THEN
         RESULT1 ) = ULPINV
         WRITENOUT, FMT = 9998 )'ZGGESX', LINFO, MPLUSN, NPTKNT
         GO TO 130
      END IF
*
*     Compute the norm(A, B)
*        (should this be norm of (A,B) or (AI,BI)?)
*
      CALL ZLACPY'Full'MPLUSNMPLUSNAILDAWORKMPLUSN )
      CALL ZLACPY'Full'MPLUSNMPLUSNBILDA,
     $             WORKMPLUSN*MPLUSN+1 ), MPLUSN )
      ABNRM = ZLANGE'Fro'MPLUSN2*MPLUSNWORKMPLUSNRWORK )
*
*     Do tests (1) to (4)
*
      CALL ZGET511MPLUSNALDAAILDAQLDAZLDAWORK,
     $             RWORKRESULT1 ) )
      CALL ZGET511MPLUSNBLDABILDAQLDAZLDAWORK,
     $             RWORKRESULT2 ) )
      CALL ZGET513MPLUSNBLDABILDAQLDAQLDAWORK,
     $             RWORKRESULT3 ) )
      CALL ZGET513MPLUSNBLDABILDAZLDAZLDAWORK,
     $             RWORKRESULT4 ) )
*
*     Do tests (5) and (6): check Schur form of A and compare
*     eigenvalues with diagonals.
*
      NTEST = 6
      TEMP1 = ZERO
      RESULT5 ) = ZERO
      RESULT6 ) = ZERO
*
      DO 110 J = 1MPLUSN
         ILABAD = .FALSE.
         TEMP2 = ( ABS1ALPHAJ )-AIJJ ) ) /
     $           MAXSMLNUMABS1ALPHAJ ) ), ABS1AIJJ ) ) )+
     $           ABS1BETAJ )-BIJJ ) ) /
     $           MAXSMLNUMABS1BETAJ ) ), ABS1BIJJ ) ) ) )
     $            / ULP
         IFJ.LT.MPLUSN ) THEN
            IFAIJ+1J ).NE.ZERO ) THEN
               ILABAD = .TRUE.
               RESULT5 ) = ULPINV
            END IF
         END IF
         IFJ.GT.1 ) THEN
            IFAIJJ-1 ).NE.ZERO ) THEN
               ILABAD = .TRUE.
               RESULT5 ) = ULPINV
            END IF
         END IF
         TEMP1 = MAXTEMP1TEMP2 )
         IFILABAD ) THEN
            WRITENOUT, FMT = 9997 )J, MPLUSN, NPTKNT
         END IF
  110 CONTINUE
      RESULT6 ) = TEMP1
*
*     Test (7) (if sorting worked)  <--------- need to be checked.
*
      NTEST = 7
      RESULT7 ) = ZERO
      IFLINFO.EQ.MPLUSN+3 )
     $   RESULT7 ) = ULPINV
*
*     Test (8): compare the estimated value of DIF and its true value.
*
      NTEST = 8
      RESULT8 ) = ZERO
      IFDIFEST2 ).EQ.ZERO ) THEN
         IFDIFTRU.GT.ABNRM*ULP )
     $      RESULT8 ) = ULPINV
      ELSE IFDIFTRU.EQ.ZERO ) THEN
         IFDIFEST2 ).GT.ABNRM*ULP )
     $      RESULT8 ) = ULPINV
      ELSE IF( ( DIFTRU.GT.THRSH2*DIFEST2 ) ) .OR.
     $         ( DIFTRU*THRSH2.LT.DIFEST2 ) ) ) THEN
         RESULT8 ) = MAXDIFTRU / DIFEST2 ), DIFEST2 ) / DIFTRU )
      END IF
*
*     Test (9)
*
      NTEST = 9
      RESULT9 ) = ZERO
      IFLINFO.EQ.MPLUSN+2 ) ) THEN
         IFDIFTRU.GT.ABNRM*ULP )
     $      RESULT9 ) = ULPINV
         IF( ( IFUNC.GT.1 ) .AND. ( DIFEST2 ).NE.ZERO ) )
     $      RESULT9 ) = ULPINV
         IF( ( IFUNC.EQ.1 ) .AND. ( PL1 ).NE.ZERO ) )
     $      RESULT9 ) = ULPINV
      END IF
*
*     Test (10): compare the estimated value of PL and it true value.
*
      NTEST = 10
      RESULT10 ) = ZERO
      IFPL1 ).EQ.ZERO ) THEN
         IFPLTRU.GT.ABNRM*ULP )
     $      RESULT10 ) = ULPINV
      ELSE IFPLTRU.EQ.ZERO ) THEN
         IFPL1 ).GT.ABNRM*ULP )
     $      RESULT10 ) = ULPINV
      ELSE IF( ( PLTRU.GT.THRESH*PL1 ) ) .OR.
     $         ( PLTRU*THRESH.LT.PL1 ) ) ) THEN
         RESULT10 ) = ULPINV
      END IF
*
      NTESTT = NTESTT + NTEST
*
*     Print out tests which fail.
*
      DO 120 J = 1NTEST
         IFRESULTJ ).GE.THRESH ) THEN
*
*           If this is the first test to fail,
*           print a header to the data file.
*
            IFNERRS.EQ.0 ) THEN
               WRITENOUT, FMT = 9996 )'ZGX'
*
*              Matrix types
*
               WRITENOUT, FMT = 9995 )
*
*              Tests performed
*
               WRITENOUT, FMT = 9993 )'unitary''''''transpose',
     $            ( '''', I = 14 )
*
            END IF
            NERRS = NERRS + 1
            IFRESULTJ ).LT.10000.0D0 ) THEN
               WRITENOUT, FMT = 9990 )NPTKNT, MPLUSN, J, RESULT( J )
            ELSE
               WRITENOUT, FMT = 9989 )NPTKNT, MPLUSN, J, RESULT( J )
            END IF
         END IF
*
  120 CONTINUE
*
  130 CONTINUE
      GO TO 80
  140 CONTINUE
*
  150 CONTINUE
*
*     Summary
*
      CALL ALASVM'ZGX'NOUTNERRSNTESTT0 )
*
      WORK1 ) = MAXWRK
*
      RETURN
*
 9999 FORMAT( ' ZDRGSX: ', A, ' returned INFO=', I6, '.', / 9X, 'N=',
     $      I6, ', JTYPE=', I6, ')' )
*
 9998 FORMAT( ' ZDRGSX: ', A, ' returned INFO=', I6, '.', / 9X, 'N=',
     $      I6, ', Input Example #', I2, ')' )
*
 9997 FORMAT( ' ZDRGSX: S not in Schur form at eigenvalue ', I6, '.',
     $      / 9X, 'N=', I6, ', JTYPE=', I6, ')' )
*
 9996 FORMAT( / 1X, A3, ' -- Complex Expert Generalized Schur form',
     $      ' problem driver' )
*
 9995 FORMAT( 'Input Example' )
*
 9994 FORMAT( ' Matrix types: ', /
     $      '  1:  A is a block diagonal matrix of Jordan blocks ',
     $      'and B is the identity ', / '      matrix, ',
     $      / '  2:  A and B are upper triangular matrices, ',
     $      / '  3:  A and B are as type 2, but each second diagonal ',
     $      'block in A_11 and ', /
     $      '      each third diaongal block in A_22 are 2x2 blocks,',
     $      / '  4:  A and B are block diagonal matrices, ',
     $      / '  5:  (A,B) has potentially close or common ',
     $      'eigenvalues.', / )
*
 9993 FORMAT( / ' Tests performed:  (S is Schur, T is triangular, ',
     $      'Q and Z are ', A, ',', / 19X,
     $      ' a is alpha, b is beta, and ', A, ' means ', A, '.)',
     $      / '  1 = | A - Q S Z', A,
     $      ' | / ( |A| n ulp )      2 = | B - Q T Z', A,
     $      ' | / ( |B| n ulp )', / '  3 = | I - QQ', A,
     $      ' | / ( n ulp )             4 = | I - ZZ', A,
     $      ' | / ( n ulp )', / '  5 = 1/ULP  if A is not in ',
     $      'Schur form S', / '  6 = difference between (alpha,beta)',
     $      ' and diagonals of (S,T)', /
     $      '  7 = 1/ULP  if SDIM is not the correct number of ',
     $      'selected eigenvalues', /
     $      '  8 = 1/ULP  if DIFEST/DIFTRU > 10*THRESH or ',
     $      'DIFTRU/DIFEST > 10*THRESH',
     $      / '  9 = 1/ULP  if DIFEST <> 0 or DIFTRU > ULP*norm(A,B) ',
     $      'when reordering fails', /
     $      ' 10 = 1/ULP  if PLEST/PLTRU > THRESH or ',
     $      'PLTRU/PLEST > THRESH', /
     $      '    ( Test 10 is only for input examples )', / )
 9992 FORMAT( ' Matrix order=', I2, ', type=', I2, ', a=', D10.3,
     $      ', order(A_11)=', I2, ', result ', I2, ' is ', 0P, F8.2 )
 9991 FORMAT( ' Matrix order=', I2, ', type=', I2, ', a=', D10.3,
     $      ', order(A_11)=', I2, ', result ', I2, ' is ', 0P, D10.3 )
 9990 FORMAT( ' Input example #', I2, ', matrix order=', I4, ',',
     $      ' result ', I2, ' is', 0P, F8.2 )
 9989 FORMAT( ' Input example #', I2, ', matrix order=', I4, ',',
     $      ' result ', I2, ' is', 1P, D10.3 )
*
*     End of ZDRGSX
*
      END