1       SUBROUTINE ZDRGES( NSIZES, NN, NTYPES, DOTYPE, ISEED, THRESH,
  2      $                   NOUNIT, A, LDA, B, S, T, Q, LDQ, Z, ALPHA,
  3      $                   BETA, WORK, LWORK, RWORK, RESULT, BWORK, INFO )
  4 *
  5 *  -- LAPACK test routine (version 3.1.1) --
  6 *     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
  7 *     February 2007
  8 *
  9 *     .. Scalar Arguments ..
 10       INTEGER            INFO, LDA, LDQ, LWORK, NOUNIT, NSIZES, NTYPES
 11       DOUBLE PRECISION   THRESH
 12 *     ..
 13 *     .. Array Arguments ..
 14       LOGICAL            BWORK( * ), DOTYPE( * )
 15       INTEGER            ISEED( 4 ), NN( * )
 16       DOUBLE PRECISION   RESULT13 ), RWORK( * )
 17       COMPLEX*16         A( LDA, * ), ALPHA( * ), B( LDA, * ),
 18      $                   BETA( * ), Q( LDQ, * ), S( LDA, * ),
 19      $                   T( LDA, * ), WORK( * ), Z( LDQ, * )
 20 *     ..
 21 *
 22 *  Purpose
 23 *  =======
 24 *
 25 *  ZDRGES checks the nonsymmetric generalized eigenvalue (Schur form)
 26 *  problem driver ZGGES.
 27 *
 28 *  ZGGES factors A and B as Q*S*Z'  and Q*T*Z' , where ' means conjugate
 29 *  transpose, S and T are  upper triangular (i.e., in generalized Schur
 30 *  form), and Q and Z are unitary. It also computes the generalized
 31 *  eigenvalues (alpha(j),beta(j)), j=1,...,n.  Thus,
 32 *  w(j) = alpha(j)/beta(j) is a root of the characteristic equation
 33 *
 34 *                  det( A - w(j) B ) = 0
 35 *
 36 *  Optionally it also reorder the eigenvalues so that a selected
 37 *  cluster of eigenvalues appears in the leading diagonal block of the
 38 *  Schur forms.
 39 *
 40 *  When ZDRGES is called, a number of matrix "sizes" ("N's") and a
 41 *  number of matrix "TYPES" are specified.  For each size ("N")
 42 *  and each TYPE of matrix, a pair of matrices (A, B) will be generated
 43 *  and used for testing. For each matrix pair, the following 13 tests
 44 *  will be performed and compared with the threshhold THRESH except
 45 *  the tests (5), (11) and (13).
 46 *
 47 *
 48 *  (1)   | A - Q S Z' | / ( |A| n ulp ) (no sorting of eigenvalues)
 49 *
 50 *
 51 *  (2)   | B - Q T Z' | / ( |B| n ulp ) (no sorting of eigenvalues)
 52 *
 53 *
 54 *  (3)   | I - QQ' | / ( n ulp ) (no sorting of eigenvalues)
 55 *
 56 *
 57 *  (4)   | I - ZZ' | / ( n ulp ) (no sorting of eigenvalues)
 58 *
 59 *  (5)   if A is in Schur form (i.e. triangular form) (no sorting of
 60 *        eigenvalues)
 61 *
 62 *  (6)   if eigenvalues = diagonal elements of the Schur form (S, T),
 63 *        i.e., test the maximum over j of D(j)  where:
 64 *
 65 *                      |alpha(j) - S(j,j)|        |beta(j) - T(j,j)|
 66 *            D(j) = ------------------------ + -----------------------
 67 *                   max(|alpha(j)|,|S(j,j)|)   max(|beta(j)|,|T(j,j)|)
 68 *
 69 *        (no sorting of eigenvalues)
 70 *
 71 *  (7)   | (A,B) - Q (S,T) Z' | / ( |(A,B)| n ulp )
 72 *        (with sorting of eigenvalues).
 73 *
 74 *  (8)   | I - QQ' | / ( n ulp ) (with sorting of eigenvalues).
 75 *
 76 *  (9)   | I - ZZ' | / ( n ulp ) (with sorting of eigenvalues).
 77 *
 78 *  (10)  if A is in Schur form (i.e. quasi-triangular form)
 79 *        (with sorting of eigenvalues).
 80 *
 81 *  (11)  if eigenvalues = diagonal elements of the Schur form (S, T),
 82 *        i.e. test the maximum over j of D(j)  where:
 83 *
 84 *                      |alpha(j) - S(j,j)|        |beta(j) - T(j,j)|
 85 *            D(j) = ------------------------ + -----------------------
 86 *                   max(|alpha(j)|,|S(j,j)|)   max(|beta(j)|,|T(j,j)|)
 87 *
 88 *        (with sorting of eigenvalues).
 89 *
 90 *  (12)  if sorting worked and SDIM is the number of eigenvalues
 91 *        which were CELECTed.
 92 *
 93 *  Test Matrices
 94 *  =============
 95 *
 96 *  The sizes of the test matrices are specified by an array
 97 *  NN(1:NSIZES); the value of each element NN(j) specifies one size.
 98 *  The "types" are specified by a logical array DOTYPE( 1:NTYPES ); if
 99 *  DOTYPE(j) is .TRUE., then matrix type "j" will be generated.
100 *  Currently, the list of possible types is:
101 *
102 *  (1)  ( 0, 0 )         (a pair of zero matrices)
103 *
104 *  (2)  ( I, 0 )         (an identity and a zero matrix)
105 *
106 *  (3)  ( 0, I )         (an identity and a zero matrix)
107 *
108 *  (4)  ( I, I )         (a pair of identity matrices)
109 *
110 *          t   t
111 *  (5)  ( J , J  )       (a pair of transposed Jordan blocks)
112 *
113 *                                      t                ( I   0  )
114 *  (6)  ( X, Y )         where  X = ( J   0  )  and Y = (      t )
115 *                                   ( 0   I  )          ( 0   J  )
116 *                        and I is a k x k identity and J a (k+1)x(k+1)
117 *                        Jordan block; k=(N-1)/2
118 *
119 *  (7)  ( D, I )         where D is diag( 0, 1,..., N-1 ) (a diagonal
120 *                        matrix with those diagonal entries.)
121 *  (8)  ( I, D )
122 *
123 *  (9)  ( big*D, small*I ) where "big" is near overflow and small=1/big
124 *
125 *  (10) ( small*D, big*I )
126 *
127 *  (11) ( big*I, small*D )
128 *
129 *  (12) ( small*I, big*D )
130 *
131 *  (13) ( big*D, big*I )
132 *
133 *  (14) ( small*D, small*I )
134 *
135 *  (15) ( D1, D2 )        where D1 is diag( 0, 0, 1, ..., N-3, 0 ) and
136 *                         D2 is diag( 0, N-3, N-4,..., 1, 0, 0 )
137 *            t   t
138 *  (16) Q ( J , J ) Z     where Q and Z are random orthogonal matrices.
139 *
140 *  (17) Q ( T1, T2 ) Z    where T1 and T2 are upper triangular matrices
141 *                         with random O(1) entries above the diagonal
142 *                         and diagonal entries diag(T1) =
143 *                         ( 0, 0, 1, ..., N-3, 0 ) and diag(T2) =
144 *                         ( 0, N-3, N-4,..., 1, 0, 0 )
145 *
146 *  (18) Q ( T1, T2 ) Z    diag(T1) = ( 0, 0, 1, 1, s, ..., s, 0 )
147 *                         diag(T2) = ( 0, 1, 0, 1,..., 1, 0 )
148 *                         s = machine precision.
149 *
150 *  (19) Q ( T1, T2 ) Z    diag(T1)=( 0,0,1,1, 1-d, ..., 1-(N-5)*d=s, 0 )
151 *                         diag(T2) = ( 0, 1, 0, 1, ..., 1, 0 )
152 *
153 *                                                         N-5
154 *  (20) Q ( T1, T2 ) Z    diag(T1)=( 0, 0, 1, 1, a, ..., a   =s, 0 )
155 *                         diag(T2) = ( 0, 1, 0, 1, ..., 1, 0, 0 )
156 *
157 *  (21) Q ( T1, T2 ) Z    diag(T1)=( 0, 0, 1, r1, r2, ..., r(N-4), 0 )
158 *                         diag(T2) = ( 0, 1, 0, 1, ..., 1, 0, 0 )
159 *                         where r1,..., r(N-4) are random.
160 *
161 *  (22) Q ( big*T1, small*T2 ) Z    diag(T1) = ( 0, 0, 1, ..., N-3, 0 )
162 *                                   diag(T2) = ( 0, 1, ..., 1, 0, 0 )
163 *
164 *  (23) Q ( small*T1, big*T2 ) Z    diag(T1) = ( 0, 0, 1, ..., N-3, 0 )
165 *                                   diag(T2) = ( 0, 1, ..., 1, 0, 0 )
166 *
167 *  (24) Q ( small*T1, small*T2 ) Z  diag(T1) = ( 0, 0, 1, ..., N-3, 0 )
168 *                                   diag(T2) = ( 0, 1, ..., 1, 0, 0 )
169 *
170 *  (25) Q ( big*T1, big*T2 ) Z      diag(T1) = ( 0, 0, 1, ..., N-3, 0 )
171 *                                   diag(T2) = ( 0, 1, ..., 1, 0, 0 )
172 *
173 *  (26) Q ( T1, T2 ) Z     where T1 and T2 are random upper-triangular
174 *                          matrices.
175 *
176 *
177 *  Arguments
178 *  =========
179 *
180 *  NSIZES  (input) INTEGER
181 *          The number of sizes of matrices to use.  If it is zero,
182 *          DDRGES does nothing.  NSIZES >= 0.
183 *
184 *  NN      (input) INTEGER array, dimension (NSIZES)
185 *          An array containing the sizes to be used for the matrices.
186 *          Zero values will be skipped.  NN >= 0.
187 *
188 *  NTYPES  (input) INTEGER
189 *          The number of elements in DOTYPE.   If it is zero, DDRGES
190 *          does nothing.  It must be at least zero.  If it is MAXTYP+1
191 *          and NSIZES is 1, then an additional type, MAXTYP+1 is
192 *          defined, which is to use whatever matrix is in A on input.
193 *          This is only useful if DOTYPE(1:MAXTYP) is .FALSE. and
194 *          DOTYPE(MAXTYP+1) is .TRUE. .
195 *
196 *  DOTYPE  (input) LOGICAL array, dimension (NTYPES)
197 *          If DOTYPE(j) is .TRUE., then for each size in NN a
198 *          matrix of that size and of type j will be generated.
199 *          If NTYPES is smaller than the maximum number of types
200 *          defined (PARAMETER MAXTYP), then types NTYPES+1 through
201 *          MAXTYP will not be generated. If NTYPES is larger
202 *          than MAXTYP, DOTYPE(MAXTYP+1) through DOTYPE(NTYPES)
203 *          will be ignored.
204 *
205 *  ISEED   (input/output) INTEGER array, dimension (4)
206 *          On entry ISEED specifies the seed of the random number
207 *          generator. The array elements should be between 0 and 4095;
208 *          if not they will be reduced mod 4096. Also, ISEED(4) must
209 *          be odd.  The random number generator uses a linear
210 *          congruential sequence limited to small integers, and so
211 *          should produce machine independent random numbers. The
212 *          values of ISEED are changed on exit, and can be used in the
213 *          next call to DDRGES to continue the same random number
214 *          sequence.
215 *
216 *  THRESH  (input) DOUBLE PRECISION
217 *          A test will count as "failed" if the "error", computed as
218 *          described above, exceeds THRESH.  Note that the error is
219 *          scaled to be O(1), so THRESH should be a reasonably small
220 *          multiple of 1, e.g., 10 or 100.  In particular, it should
221 *          not depend on the precision (single vs. double) or the size
222 *          of the matrix.  THRESH >= 0.
223 *
224 *  NOUNIT  (input) INTEGER
225 *          The FORTRAN unit number for printing out error messages
226 *          (e.g., if a routine returns IINFO not equal to 0.)
227 *
228 *  A       (input/workspace) COMPLEX*16 array, dimension(LDA, max(NN))
229 *          Used to hold the original A matrix.  Used as input only
230 *          if NTYPES=MAXTYP+1, DOTYPE(1:MAXTYP)=.FALSE., and
231 *          DOTYPE(MAXTYP+1)=.TRUE.
232 *
233 *  LDA     (input) INTEGER
234 *          The leading dimension of A, B, S, and T.
235 *          It must be at least 1 and at least max( NN ).
236 *
237 *  B       (input/workspace) COMPLEX*16 array, dimension(LDA, max(NN))
238 *          Used to hold the original B matrix.  Used as input only
239 *          if NTYPES=MAXTYP+1, DOTYPE(1:MAXTYP)=.FALSE., and
240 *          DOTYPE(MAXTYP+1)=.TRUE.
241 *
242 *  S       (workspace) COMPLEX*16 array, dimension (LDA, max(NN))
243 *          The Schur form matrix computed from A by ZGGES.  On exit, S
244 *          contains the Schur form matrix corresponding to the matrix
245 *          in A.
246 *
247 *  T       (workspace) COMPLEX*16 array, dimension (LDA, max(NN))
248 *          The upper triangular matrix computed from B by ZGGES.
249 *
250 *  Q       (workspace) COMPLEX*16 array, dimension (LDQ, max(NN))
251 *          The (left) orthogonal matrix computed by ZGGES.
252 *
253 *  LDQ     (input) INTEGER
254 *          The leading dimension of Q and Z. It must
255 *          be at least 1 and at least max( NN ).
256 *
257 *  Z       (workspace) COMPLEX*16 array, dimension( LDQ, max(NN) )
258 *          The (right) orthogonal matrix computed by ZGGES.
259 *
260 *  ALPHA   (workspace) COMPLEX*16 array, dimension (max(NN))
261 *  BETA    (workspace) COMPLEX*16 array, dimension (max(NN))
262 *          The generalized eigenvalues of (A,B) computed by ZGGES.
263 *          ALPHA(k) / BETA(k) is the k-th generalized eigenvalue of A
264 *          and B.
265 *
266 *  WORK    (workspace) COMPLEX*16 array, dimension (LWORK)
267 *
268 *  LWORK   (input) INTEGER
269 *          The dimension of the array WORK.  LWORK >= 3*N*N.
270 *
271 *  RWORK   (workspace) DOUBLE PRECISION array, dimension ( 8*N )
272 *          Real workspace.
273 *
274 *  RESULT  (output) DOUBLE PRECISION array, dimension (15)
275 *          The values computed by the tests described above.
276 *          The values are currently limited to 1/ulp, to avoid overflow.
277 *
278 *  BWORK   (workspace) LOGICAL array, dimension (N)
279 *
280 *  INFO    (output) INTEGER
281 *          = 0:  successful exit
282 *          < 0:  if INFO = -i, the i-th argument had an illegal value.
283 *          > 0:  A routine returned an error code.  INFO is the
284 *                absolute value of the INFO value returned.
285 *
286 *  =====================================================================
287 *
288 *     .. Parameters ..
289       DOUBLE PRECISION   ZERO, ONE
290       PARAMETER          ( ZERO = 0.0D+0, ONE = 1.0D+0 )
291       COMPLEX*16         CZERO, CONE
292       PARAMETER          ( CZERO = ( 0.0D+00.0D+0 ),
293      $                   CONE = ( 1.0D+00.0D+0 ) )
294       INTEGER            MAXTYP
295       PARAMETER          ( MAXTYP = 26 )
296 *     ..
297 *     .. Local Scalars ..
298       LOGICAL            BADNN, ILABAD
299       CHARACTER          SORT
300       INTEGER            I, IADD, IINFO, IN, ISORT, J, JC, JR, JSIZE,
301      $                   JTYPE, KNTEIG, MAXWRK, MINWRK, MTYPES, N, N1,
302      $                   NB, NERRS, NMATS, NMAX, NTEST, NTESTT, RSUB,
303      $                   SDIM
304       DOUBLE PRECISION   SAFMAX, SAFMIN, TEMP1, TEMP2, ULP, ULPINV
305       COMPLEX*16         CTEMP, X
306 *     ..
307 *     .. Local Arrays ..
308       LOGICAL            LASIGN( MAXTYP ), LBSIGN( MAXTYP )
309       INTEGER            IOLDSD( 4 ), KADD( 6 ), KAMAGN( MAXTYP ),
310      $                   KATYPE( MAXTYP ), KAZERO( MAXTYP ),
311      $                   KBMAGN( MAXTYP ), KBTYPE( MAXTYP ),
312      $                   KBZERO( MAXTYP ), KCLASS( MAXTYP ),
313      $                   KTRIAN( MAXTYP ), KZ1( 6 ), KZ2( 6 )
314       DOUBLE PRECISION   RMAGN( 03 )
315 *     ..
316 *     .. External Functions ..
317       LOGICAL            ZLCTES
318       INTEGER            ILAENV
319       DOUBLE PRECISION   DLAMCH
320       COMPLEX*16         ZLARND
321       EXTERNAL           ZLCTES, ILAENV, DLAMCH, ZLARND
322 *     ..
323 *     .. External Subroutines ..
324       EXTERNAL           ALASVM, DLABAD, XERBLA, ZGET51, ZGET54, ZGGES,
325      $                   ZLACPY, ZLARFG, ZLASET, ZLATM4, ZUNM2R
326 *     ..
327 *     .. Intrinsic Functions ..
328       INTRINSIC          ABSDBLEDCONJGDIMAGMAXMINSIGN
329 *     ..
330 *     .. Statement Functions ..
331       DOUBLE PRECISION   ABS1
332 *     ..
333 *     .. Statement Function definitions ..
334       ABS1( X ) = ABSDBLE( X ) ) + ABSDIMAG( X ) )
335 *     ..
336 *     .. Data statements ..
337       DATA               KCLASS / 15*110*21*3 /
338       DATA               KZ1 / 012133 /
339       DATA               KZ2 / 001211 /
340       DATA               KADD / 000032 /
341       DATA               KATYPE / 0101234144114,
342      $                   442458794*40 /
343       DATA               KBTYPE / 00112-3141144,
344      $                   11-42-48*80 /
345       DATA               KAZERO / 6*1212*22*12*2313,
346      $                   4*54*31 /
347       DATA               KBZERO / 6*1122*12*22*1414,
348      $                   4*64*41 /
349       DATA               KAMAGN / 8*12323237*1233,
350      $                   21 /
351       DATA               KBMAGN / 8*13232237*1323,
352      $                   21 /
353       DATA               KTRIAN / 16*010*1 /
354       DATA               LASIGN / 6*.FALSE..TRUE..FALSE.2*.TRUE.,
355      $                   2*.FALSE.3*.TRUE..FALSE..TRUE.,
356      $                   3*.FALSE.5*.TRUE..FALSE. /
357       DATA               LBSIGN / 7*.FALSE..TRUE.2*.FALSE.,
358      $                   2*.TRUE.2*.FALSE..TRUE..FALSE..TRUE.,
359      $                   9*.FALSE. /
360 *     ..
361 *     .. Executable Statements ..
362 *
363 *     Check for errors
364 *
365       INFO = 0
366 *
367       BADNN = .FALSE.
368       NMAX = 1
369       DO 10 J = 1, NSIZES
370          NMAX = MAX( NMAX, NN( J ) )
371          IF( NN( J ).LT.0 )
372      $      BADNN = .TRUE.
373    10 CONTINUE
374 *
375       IF( NSIZES.LT.0 ) THEN
376          INFO = -1
377       ELSE IF( BADNN ) THEN
378          INFO = -2
379       ELSE IF( NTYPES.LT.0 ) THEN
380          INFO = -3
381       ELSE IF( THRESH.LT.ZERO ) THEN
382          INFO = -6
383       ELSE IF( LDA.LE.1 .OR. LDA.LT.NMAX ) THEN
384          INFO = -9
385       ELSE IF( LDQ.LE.1 .OR. LDQ.LT.NMAX ) THEN
386          INFO = -14
387       END IF
388 *
389 *     Compute workspace
390 *      (Note: Comments in the code beginning "Workspace:" describe the
391 *       minimal amount of workspace needed at that point in the code,
392 *       as well as the preferred amount for good performance.
393 *       NB refers to the optimal block size for the immediately
394 *       following subroutine, as returned by ILAENV.
395 *
396       MINWRK = 1
397       IF( INFO.EQ.0 .AND. LWORK.GE.1 ) THEN
398          MINWRK = 3*NMAX*NMAX
399          NB = MAX1, ILAENV( 1'ZGEQRF'' ', NMAX, NMAX, -1-1 ),
400      $        ILAENV( 1'ZUNMQR''LC', NMAX, NMAX, NMAX, -1 ),
401      $        ILAENV( 1'ZUNGQR'' ', NMAX, NMAX, NMAX, -1 ) )
402          MAXWRK = MAX( NMAX+NMAX*NB, 3*NMAX*NMAX )
403          WORK( 1 ) = MAXWRK
404       END IF
405 *
406       IF( LWORK.LT.MINWRK )
407      $   INFO = -19
408 *
409       IF( INFO.NE.0 ) THEN
410          CALL XERBLA( 'ZDRGES'-INFO )
411          RETURN
412       END IF
413 *
414 *     Quick return if possible
415 *
416       IF( NSIZES.EQ.0 .OR. NTYPES.EQ.0 )
417      $   RETURN
418 *
419       ULP = DLAMCH( 'Precision' )
420       SAFMIN = DLAMCH( 'Safe minimum' )
421       SAFMIN = SAFMIN / ULP
422       SAFMAX = ONE / SAFMIN
423       CALL DLABAD( SAFMIN, SAFMAX )
424       ULPINV = ONE / ULP
425 *
426 *     The values RMAGN(2:3) depend on N, see below.
427 *
428       RMAGN( 0 ) = ZERO
429       RMAGN( 1 ) = ONE
430 *
431 *     Loop over matrix sizes
432 *
433       NTESTT = 0
434       NERRS = 0
435       NMATS = 0
436 *
437       DO 190 JSIZE = 1, NSIZES
438          N = NN( JSIZE )
439          N1 = MAX1, N )
440          RMAGN( 2 ) = SAFMAX*ULP / DBLE( N1 )
441          RMAGN( 3 ) = SAFMIN*ULPINV*DBLE( N1 )
442 *
443          IF( NSIZES.NE.1 ) THEN
444             MTYPES = MIN( MAXTYP, NTYPES )
445          ELSE
446             MTYPES = MIN( MAXTYP+1, NTYPES )
447          END IF
448 *
449 *        Loop over matrix types
450 *
451          DO 180 JTYPE = 1, MTYPES
452             IF.NOT.DOTYPE( JTYPE ) )
453      $         GO TO 180
454             NMATS = NMATS + 1
455             NTEST = 0
456 *
457 *           Save ISEED in case of an error.
458 *
459             DO 20 J = 14
460                IOLDSD( J ) = ISEED( J )
461    20       CONTINUE
462 *
463 *           Initialize RESULT
464 *
465             DO 30 J = 113
466                RESULT( J ) = ZERO
467    30       CONTINUE
468 *
469 *           Generate test matrices A and B
470 *
471 *           Description of control parameters:
472 *
473 *           KZLASS: =1 means w/o rotation, =2 means w/ rotation,
474 *                   =3 means random.
475 *           KATYPE: the "type" to be passed to ZLATM4 for computing A.
476 *           KAZERO: the pattern of zeros on the diagonal for A:
477 *                   =1: ( xxx ), =2: (0, xxx ) =3: ( 0, 0, xxx, 0 ),
478 *                   =4: ( 0, xxx, 0, 0 ), =5: ( 0, 0, 1, xxx, 0 ),
479 *                   =6: ( 0, 1, 0, xxx, 0 ).  (xxx means a string of
480 *                   non-zero entries.)
481 *           KAMAGN: the magnitude of the matrix: =0: zero, =1: O(1),
482 *                   =2: large, =3: small.
483 *           LASIGN: .TRUE. if the diagonal elements of A are to be
484 *                   multiplied by a random magnitude 1 number.
485 *           KBTYPE, KBZERO, KBMAGN, LBSIGN: the same, but for B.
486 *           KTRIAN: =0: don't fill in the upper triangle, =1: do.
487 *           KZ1, KZ2, KADD: used to implement KAZERO and KBZERO.
488 *           RMAGN: used to implement KAMAGN and KBMAGN.
489 *
490             IF( MTYPES.GT.MAXTYP )
491      $         GO TO 110
492             IINFO = 0
493             IF( KCLASS( JTYPE ).LT.3 ) THEN
494 *
495 *              Generate A (w/o rotation)
496 *
497                IFABS( KATYPE( JTYPE ) ).EQ.3 ) THEN
498                   IN = 2*( ( N-1 ) / 2 ) + 1
499                   IFIN.NE.N )
500      $               CALL ZLASET( 'Full', N, N, CZERO, CZERO, A, LDA )
501                ELSE
502                   IN = N
503                END IF
504                CALL ZLATM4( KATYPE( JTYPE ), IN, KZ1( KAZERO( JTYPE ) ),
505      $                      KZ2( KAZERO( JTYPE ) ), LASIGN( JTYPE ),
506      $                      RMAGN( KAMAGN( JTYPE ) ), ULP,
507      $                      RMAGN( KTRIAN( JTYPE )*KAMAGN( JTYPE ) ), 2,
508      $                      ISEED, A, LDA )
509                IADD = KADD( KAZERO( JTYPE ) )
510                IF( IADD.GT.0 .AND. IADD.LE.N )
511      $            A( IADD, IADD ) = RMAGN( KAMAGN( JTYPE ) )
512 *
513 *              Generate B (w/o rotation)
514 *
515                IFABS( KBTYPE( JTYPE ) ).EQ.3 ) THEN
516                   IN = 2*( ( N-1 ) / 2 ) + 1
517                   IFIN.NE.N )
518      $               CALL ZLASET( 'Full', N, N, CZERO, CZERO, B, LDA )
519                ELSE
520                   IN = N
521                END IF
522                CALL ZLATM4( KBTYPE( JTYPE ), IN, KZ1( KBZERO( JTYPE ) ),
523      $                      KZ2( KBZERO( JTYPE ) ), LBSIGN( JTYPE ),
524      $                      RMAGN( KBMAGN( JTYPE ) ), ONE,
525      $                      RMAGN( KTRIAN( JTYPE )*KBMAGN( JTYPE ) ), 2,
526      $                      ISEED, B, LDA )
527                IADD = KADD( KBZERO( JTYPE ) )
528                IF( IADD.NE.0 .AND. IADD.LE.N )
529      $            B( IADD, IADD ) = RMAGN( KBMAGN( JTYPE ) )
530 *
531                IF( KCLASS( JTYPE ).EQ.2 .AND. N.GT.0 ) THEN
532 *
533 *                 Include rotations
534 *
535 *                 Generate Q, Z as Householder transformations times
536 *                 a diagonal matrix.
537 *
538                   DO 50 JC = 1, N - 1
539                      DO 40 JR = JC, N
540                         Q( JR, JC ) = ZLARND( 3, ISEED )
541                         Z( JR, JC ) = ZLARND( 3, ISEED )
542    40                CONTINUE
543                      CALL ZLARFG( N+1-JC, Q( JC, JC ), Q( JC+1, JC ), 1,
544      $                            WORK( JC ) )
545                      WORK( 2*N+JC ) = SIGN( ONE, DBLE( Q( JC, JC ) ) )
546                      Q( JC, JC ) = CONE
547                      CALL ZLARFG( N+1-JC, Z( JC, JC ), Z( JC+1, JC ), 1,
548      $                            WORK( N+JC ) )
549                      WORK( 3*N+JC ) = SIGN( ONE, DBLE( Z( JC, JC ) ) )
550                      Z( JC, JC ) = CONE
551    50             CONTINUE
552                   CTEMP = ZLARND( 3, ISEED )
553                   Q( N, N ) = CONE
554                   WORK( N ) = CZERO
555                   WORK( 3*N ) = CTEMP / ABS( CTEMP )
556                   CTEMP = ZLARND( 3, ISEED )
557                   Z( N, N ) = CONE
558                   WORK( 2*N ) = CZERO
559                   WORK( 4*N ) = CTEMP / ABS( CTEMP )
560 *
561 *                 Apply the diagonal matrices
562 *
563                   DO 70 JC = 1, N
564                      DO 60 JR = 1, N
565                         A( JR, JC ) = WORK( 2*N+JR )*
566      $                                DCONJG( WORK( 3*N+JC ) )*
567      $                                A( JR, JC )
568                         B( JR, JC ) = WORK( 2*N+JR )*
569      $                                DCONJG( WORK( 3*N+JC ) )*
570      $                                B( JR, JC )
571    60                CONTINUE
572    70             CONTINUE
573                   CALL ZUNM2R( 'L''N', N, N, N-1, Q, LDQ, WORK, A,
574      $                         LDA, WORK( 2*N+1 ), IINFO )
575                   IF( IINFO.NE.0 )
576      $               GO TO 100
577                   CALL ZUNM2R( 'R''C', N, N, N-1, Z, LDQ, WORK( N+1 ),
578      $                         A, LDA, WORK( 2*N+1 ), IINFO )
579                   IF( IINFO.NE.0 )
580      $               GO TO 100
581                   CALL ZUNM2R( 'L''N', N, N, N-1, Q, LDQ, WORK, B,
582      $                         LDA, WORK( 2*N+1 ), IINFO )
583                   IF( IINFO.NE.0 )
584      $               GO TO 100
585                   CALL ZUNM2R( 'R''C', N, N, N-1, Z, LDQ, WORK( N+1 ),
586      $                         B, LDA, WORK( 2*N+1 ), IINFO )
587                   IF( IINFO.NE.0 )
588      $               GO TO 100
589                END IF
590             ELSE
591 *
592 *              Random matrices
593 *
594                DO 90 JC = 1, N
595                   DO 80 JR = 1, N
596                      A( JR, JC ) = RMAGN( KAMAGN( JTYPE ) )*
597      $                             ZLARND( 4, ISEED )
598                      B( JR, JC ) = RMAGN( KBMAGN( JTYPE ) )*
599      $                             ZLARND( 4, ISEED )
600    80             CONTINUE
601    90          CONTINUE
602             END IF
603 *
604   100       CONTINUE
605 *
606             IF( IINFO.NE.0 ) THEN
607                WRITE( NOUNIT, FMT = 9999 )'Generator', IINFO, N, JTYPE,
608      $            IOLDSD
609                INFO = ABS( IINFO )
610                RETURN
611             END IF
612 *
613   110       CONTINUE
614 *
615             DO 120 I = 113
616                RESULT( I ) = -ONE
617   120       CONTINUE
618 *
619 *           Test with and without sorting of eigenvalues
620 *
621             DO 150 ISORT = 01
622                IF( ISORT.EQ.0 ) THEN
623                   SORT = 'N'
624                   RSUB = 0
625                ELSE
626                   SORT = 'S'
627                   RSUB = 5
628                END IF
629 *
630 *              Call ZGGES to compute H, T, Q, Z, alpha, and beta.
631 *
632                CALL ZLACPY( 'Full', N, N, A, LDA, S, LDA )
633                CALL ZLACPY( 'Full', N, N, B, LDA, T, LDA )
634                NTEST = 1 + RSUB + ISORT
635                RESULT1+RSUB+ISORT ) = ULPINV
636                CALL ZGGES( 'V''V', SORT, ZLCTES, N, S, LDA, T, LDA,
637      $                     SDIM, ALPHA, BETA, Q, LDQ, Z, LDQ, WORK,
638      $                     LWORK, RWORK, BWORK, IINFO )
639                IF( IINFO.NE.0 .AND. IINFO.NE.N+2 ) THEN
640                   RESULT1+RSUB+ISORT ) = ULPINV
641                   WRITE( NOUNIT, FMT = 9999 )'ZGGES', IINFO, N, JTYPE,
642      $               IOLDSD
643                   INFO = ABS( IINFO )
644                   GO TO 160
645                END IF
646 *
647                NTEST = 4 + RSUB
648 *
649 *              Do tests 1--4 (or tests 7--9 when reordering )
650 *
651                IF( ISORT.EQ.0 ) THEN
652                   CALL ZGET51( 1, N, A, LDA, S, LDA, Q, LDQ, Z, LDQ,
653      $                         WORK, RWORK, RESULT1 ) )
654                   CALL ZGET51( 1, N, B, LDA, T, LDA, Q, LDQ, Z, LDQ,
655      $                         WORK, RWORK, RESULT2 ) )
656                ELSE
657                   CALL ZGET54( N, A, LDA, B, LDA, S, LDA, T, LDA, Q,
658      $                         LDQ, Z, LDQ, WORK, RESULT2+RSUB ) )
659                END IF
660 *
661                CALL ZGET51( 3, N, B, LDA, T, LDA, Q, LDQ, Q, LDQ, WORK,
662      $                      RWORK, RESULT3+RSUB ) )
663                CALL ZGET51( 3, N, B, LDA, T, LDA, Z, LDQ, Z, LDQ, WORK,
664      $                      RWORK, RESULT4+RSUB ) )
665 *
666 *              Do test 5 and 6 (or Tests 10 and 11 when reordering):
667 *              check Schur form of A and compare eigenvalues with
668 *              diagonals.
669 *
670                NTEST = 6 + RSUB
671                TEMP1 = ZERO
672 *
673                DO 130 J = 1, N
674                   ILABAD = .FALSE.
675                   TEMP2 = ( ABS1( ALPHA( J )-S( J, J ) ) /
676      $                    MAX( SAFMIN, ABS1( ALPHA( J ) ), ABS1( S( J,
677      $                    J ) ) )+ABS1( BETA( J )-T( J, J ) ) /
678      $                    MAX( SAFMIN, ABS1( BETA( J ) ), ABS1( T( J,
679      $                    J ) ) ) ) / ULP
680 *
681                   IF( J.LT.N ) THEN
682                      IF( S( J+1, J ).NE.ZERO ) THEN
683                         ILABAD = .TRUE.
684                         RESULT5+RSUB ) = ULPINV
685                      END IF
686                   END IF
687                   IF( J.GT.1 ) THEN
688                      IF( S( J, J-1 ).NE.ZERO ) THEN
689                         ILABAD = .TRUE.
690                         RESULT5+RSUB ) = ULPINV
691                      END IF
692                   END IF
693                   TEMP1 = MAX( TEMP1, TEMP2 )
694                   IF( ILABAD ) THEN
695                      WRITE( NOUNIT, FMT = 9998 )J, N, JTYPE, IOLDSD
696                   END IF
697   130          CONTINUE
698                RESULT6+RSUB ) = TEMP1
699 *
700                IF( ISORT.GE.1 ) THEN
701 *
702 *                 Do test 12
703 *
704                   NTEST = 12
705                   RESULT12 ) = ZERO
706                   KNTEIG = 0
707                   DO 140 I = 1, N
708                      IF( ZLCTES( ALPHA( I ), BETA( I ) ) )
709      $                  KNTEIG = KNTEIG + 1
710   140             CONTINUE
711                   IF( SDIM.NE.KNTEIG )
712      $               RESULT13 ) = ULPINV
713                END IF
714 *
715   150       CONTINUE
716 *
717 *           End of Loop -- Check for RESULT(j) > THRESH
718 *
719   160       CONTINUE
720 *
721             NTESTT = NTESTT + NTEST
722 *
723 *           Print out tests which fail.
724 *
725             DO 170 JR = 1, NTEST
726                IFRESULT( JR ).GE.THRESH ) THEN
727 *
728 *                 If this is the first test to fail,
729 *                 print a header to the data file.
730 *
731                   IF( NERRS.EQ.0 ) THEN
732                      WRITE( NOUNIT, FMT = 9997 )'ZGS'
733 *
734 *                    Matrix types
735 *
736                      WRITE( NOUNIT, FMT = 9996 )
737                      WRITE( NOUNIT, FMT = 9995 )
738                      WRITE( NOUNIT, FMT = 9994 )'Unitary'
739 *
740 *                    Tests performed
741 *
742                      WRITE( NOUNIT, FMT = 9993 )'unitary''''',
743      $                  'transpose', ( '''', J = 18 )
744 *
745                   END IF
746                   NERRS = NERRS + 1
747                   IFRESULT( JR ).LT.10000.0D0 ) THEN
748                      WRITE( NOUNIT, FMT = 9992 )N, JTYPE, IOLDSD, JR,
749      $                  RESULT( JR )
750                   ELSE
751                      WRITE( NOUNIT, FMT = 9991 )N, JTYPE, IOLDSD, JR,
752      $                  RESULT( JR )
753                   END IF
754                END IF
755   170       CONTINUE
756 *
757   180    CONTINUE
758   190 CONTINUE
759 *
760 *     Summary
761 *
762       CALL ALASVM( 'ZGS', NOUNIT, NERRS, NTESTT, 0 )
763 *
764       WORK( 1 ) = MAXWRK
765 *
766       RETURN
767 *
768  9999 FORMAT' ZDRGES: ', A, ' returned INFO=', I6, '.'/ 9X'N=',
769      $      I6, ', JTYPE=', I6, ', ISEED=('4( I4, ',' ), I5, ')' )
770 *
771  9998 FORMAT' ZDRGES: S not in Schur form at eigenvalue ', I6, '.',
772      $      / 9X'N=', I6, ', JTYPE=', I6, ', ISEED=('3( I5, ',' ),
773      $      I5, ')' )
774 *
775  9997 FORMAT/ 1X, A3, ' -- Complex Generalized Schur from problem ',
776      $      'driver' )
777 *
778  9996 FORMAT' Matrix types (see ZDRGES for details): ' )
779 *
780  9995 FORMAT' Special Matrices:'23X,
781      $      '(J''=transposed Jordan block)',
782      $      / '   1=(0,0)  2=(I,0)  3=(0,I)  4=(I,I)  5=(J'',J'')  ',
783      $      '6=(diag(J'',I), diag(I,J''))'/ ' Diagonal Matrices:  ( ',
784      $      'D=diag(0,1,2,...) )'/ '   7=(D,I)   9=(large*D, small*I',
785      $      ')  11=(large*I, small*D)  13=(large*D, large*I)'/
786      $      '   8=(I,D)  10=(small*D, large*I)  12=(small*I, large*D) ',
787      $      ' 14=(small*D, small*I)'/ '  15=(D, reversed D)' )
788  9994 FORMAT' Matrices Rotated by Random ', A, ' Matrices U, V:',
789      $      / '  16=Transposed Jordan Blocks             19=geometric ',
790      $      'alpha, beta=0,1'/ '  17=arithm. alpha&beta             ',
791      $      '      20=arithmetic alpha, beta=0,1'/ '  18=clustered ',
792      $      'alpha, beta=0,1            21=random alpha, beta=0,1',
793      $      / ' Large & Small Matrices:'/ '  22=(large, small)   ',
794      $      '23=(small,large)    24=(small,small)    25=(large,large)',
795      $      / '  26=random O(1) matrices.' )
796 *
797  9993 FORMAT/ ' Tests performed:  (S is Schur, T is triangular, ',
798      $      'Q and Z are ', A, ','/ 19X,
799      $      'l and r are the appropriate left and right'/ 19X,
800      $      'eigenvectors, resp., a is alpha, b is beta, and'/ 19X, A,
801      $      ' means ', A, '.)'/ ' Without ordering: ',
802      $      / '  1 = | A - Q S Z', A,
803      $      ' | / ( |A| n ulp )      2 = | B - Q T Z', A,
804      $      ' | / ( |B| n ulp )'/ '  3 = | I - QQ', A,
805      $      ' | / ( n ulp )             4 = | I - ZZ', A,
806      $      ' | / ( n ulp )'/ '  5 = A is in Schur form S',
807      $      / '  6 = difference between (alpha,beta)',
808      $      ' and diagonals of (S,T)'/ ' With ordering: ',
809      $      / '  7 = | (A,B) - Q (S,T) Z', A, ' | / ( |(A,B)| n ulp )',
810      $      / '  8 = | I - QQ', A,
811      $      ' | / ( n ulp )             9 = | I - ZZ', A,
812      $      ' | / ( n ulp )'/ ' 10 = A is in Schur form S',
813      $      / ' 11 = difference between (alpha,beta) and diagonals',
814      $      ' of (S,T)'/ ' 12 = SDIM is the correct number of ',
815      $      'selected eigenvalues'/ )
816  9992 FORMAT' Matrix order=', I5, ', type=', I2, ', seed=',
817      $      4( I4, ',' ), ' result ', I2, ' is', 0P, F8.2 )
818  9991 FORMAT' Matrix order=', I5, ', type=', I2, ', seed=',
819      $      4( I4, ',' ), ' result ', I2, ' is', 1P, D10.3 )
820 *
821 *     End of ZDRGES
822 *
823       END