1*> \brief \b ZCHKGK
2*
3*  =========== DOCUMENTATION ===========
4*
5* Online html documentation available at
6*            http://www.netlib.org/lapack/explore-html/
7*
8*  Definition:
9*  ===========
10*
11*       SUBROUTINE ZCHKGK( NIN, NOUT )
12*
13*       .. Scalar Arguments ..
14*       INTEGER            NIN, NOUT
15*       ..
16*
17*
18*> \par Purpose:
19*  =============
20*>
21*> \verbatim
22*>
23*> ZCHKGK tests ZGGBAK, a routine for backward balancing  of
24*> a matrix pair (A, B).
25*> \endverbatim
26*
27*  Arguments:
28*  ==========
29*
30*> \param[in] NIN
31*> \verbatim
32*>          NIN is INTEGER
33*>          The logical unit number for input.  NIN > 0.
34*> \endverbatim
35*>
36*> \param[in] NOUT
37*> \verbatim
38*>          NOUT is INTEGER
39*>          The logical unit number for output.  NOUT > 0.
40*> \endverbatim
41*
42*  Authors:
43*  ========
44*
45*> \author Univ. of Tennessee
46*> \author Univ. of California Berkeley
47*> \author Univ. of Colorado Denver
48*> \author NAG Ltd.
49*
50*> \ingroup complex16_eig
51*
52*  =====================================================================
53      SUBROUTINE ZCHKGK( NIN, NOUT )
54*
55*  -- LAPACK test routine --
56*  -- LAPACK is a software package provided by Univ. of Tennessee,    --
57*  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
58*
59*     .. Scalar Arguments ..
60      INTEGER            NIN, NOUT
61*     ..
62*
63*  =====================================================================
64*
65*     .. Parameters ..
66      INTEGER            LDA, LDB, LDVL, LDVR
67      PARAMETER          ( LDA = 50, LDB = 50, LDVL = 50, LDVR = 50 )
68      INTEGER            LDE, LDF, LDWORK, LRWORK
69      PARAMETER          ( LDE = 50, LDF = 50, LDWORK = 50,
70     $                   LRWORK = 6*50 )
71      DOUBLE PRECISION   ZERO
72      PARAMETER          ( ZERO = 0.0D+0 )
73      COMPLEX*16         CZERO, CONE
74      PARAMETER          ( CZERO = ( 0.0D+0, 0.0D+0 ),
75     $                   CONE = ( 1.0D+0, 0.0D+0 ) )
76*     ..
77*     .. Local Scalars ..
78      INTEGER            I, IHI, ILO, INFO, J, KNT, M, N, NINFO
79      DOUBLE PRECISION   ANORM, BNORM, EPS, RMAX, VMAX
80      COMPLEX*16         CDUM
81*     ..
82*     .. Local Arrays ..
83      INTEGER            LMAX( 4 )
84      DOUBLE PRECISION   LSCALE( LDA ), RSCALE( LDA ), RWORK( LRWORK )
85      COMPLEX*16         A( LDA, LDA ), AF( LDA, LDA ), B( LDB, LDB ),
86     $                   BF( LDB, LDB ), E( LDE, LDE ), F( LDF, LDF ),
87     $                   VL( LDVL, LDVL ), VLF( LDVL, LDVL ),
88     $                   VR( LDVR, LDVR ), VRF( LDVR, LDVR ),
89     $                   WORK( LDWORK, LDWORK )
90*     ..
91*     .. External Functions ..
92      DOUBLE PRECISION   DLAMCH, ZLANGE
93      EXTERNAL           DLAMCH, ZLANGE
94*     ..
95*     .. External Subroutines ..
96      EXTERNAL           ZGEMM, ZGGBAK, ZGGBAL, ZLACPY
97*     ..
98*     .. Intrinsic Functions ..
99      INTRINSIC          ABS, DBLE, DIMAG, MAX
100*     ..
101*     .. Statement Functions ..
102      DOUBLE PRECISION   CABS1
103*     ..
104*     .. Statement Function definitions ..
105      CABS1( CDUM ) = ABS( DBLE( CDUM ) ) + ABS( DIMAG( CDUM ) )
106*     ..
107*     .. Executable Statements ..
108*
109      LMAX( 1 ) = 0
110      LMAX( 2 ) = 0
111      LMAX( 3 ) = 0
112      LMAX( 4 ) = 0
113      NINFO = 0
114      KNT = 0
115      RMAX = ZERO
116*
117      EPS = DLAMCH( 'Precision' )
118*
119   10 CONTINUE
120      READ( NIN, FMT = * )N, M
121      IF( N.EQ.0 )
122     $   GO TO 100
123*
124      DO 20 I = 1, N
125         READ( NIN, FMT = * )( A( I, J ), J = 1, N )
126   20 CONTINUE
127*
128      DO 30 I = 1, N
129         READ( NIN, FMT = * )( B( I, J ), J = 1, N )
130   30 CONTINUE
131*
132      DO 40 I = 1, N
133         READ( NIN, FMT = * )( VL( I, J ), J = 1, M )
134   40 CONTINUE
135*
136      DO 50 I = 1, N
137         READ( NIN, FMT = * )( VR( I, J ), J = 1, M )
138   50 CONTINUE
139*
140      KNT = KNT + 1
141*
142      ANORM = ZLANGE( 'M', N, N, A, LDA, RWORK )
143      BNORM = ZLANGE( 'M', N, N, B, LDB, RWORK )
144*
145      CALL ZLACPY( 'FULL', N, N, A, LDA, AF, LDA )
146      CALL ZLACPY( 'FULL', N, N, B, LDB, BF, LDB )
147*
148      CALL ZGGBAL( 'B', N, A, LDA, B, LDB, ILO, IHI, LSCALE, RSCALE,
149     $             RWORK, INFO )
150      IF( INFO.NE.0 ) THEN
151         NINFO = NINFO + 1
152         LMAX( 1 ) = KNT
153      END IF
154*
155      CALL ZLACPY( 'FULL', N, M, VL, LDVL, VLF, LDVL )
156      CALL ZLACPY( 'FULL', N, M, VR, LDVR, VRF, LDVR )
157*
158      CALL ZGGBAK( 'B', 'L', N, ILO, IHI, LSCALE, RSCALE, M, VL, LDVL,
159     $             INFO )
160      IF( INFO.NE.0 ) THEN
161         NINFO = NINFO + 1
162         LMAX( 2 ) = KNT
163      END IF
164*
165      CALL ZGGBAK( 'B', 'R', N, ILO, IHI, LSCALE, RSCALE, M, VR, LDVR,
166     $             INFO )
167      IF( INFO.NE.0 ) THEN
168         NINFO = NINFO + 1
169         LMAX( 3 ) = KNT
170      END IF
171*
172*     Test of ZGGBAK
173*
174*     Check tilde(VL)'*A*tilde(VR) - VL'*tilde(A)*VR
175*     where tilde(A) denotes the transformed matrix.
176*
177      CALL ZGEMM( 'N', 'N', N, M, N, CONE, AF, LDA, VR, LDVR, CZERO,
178     $            WORK, LDWORK )
179      CALL ZGEMM( 'C', 'N', M, M, N, CONE, VL, LDVL, WORK, LDWORK,
180     $            CZERO, E, LDE )
181*
182      CALL ZGEMM( 'N', 'N', N, M, N, CONE, A, LDA, VRF, LDVR, CZERO,
183     $            WORK, LDWORK )
184      CALL ZGEMM( 'C', 'N', M, M, N, CONE, VLF, LDVL, WORK, LDWORK,
185     $            CZERO, F, LDF )
186*
187      VMAX = ZERO
188      DO 70 J = 1, M
189         DO 60 I = 1, M
190            VMAX = MAX( VMAX, CABS1( E( I, J )-F( I, J ) ) )
191   60    CONTINUE
192   70 CONTINUE
193      VMAX = VMAX / ( EPS*MAX( ANORM, BNORM ) )
194      IF( VMAX.GT.RMAX ) THEN
195         LMAX( 4 ) = KNT
196         RMAX = VMAX
197      END IF
198*
199*     Check tilde(VL)'*B*tilde(VR) - VL'*tilde(B)*VR
200*
201      CALL ZGEMM( 'N', 'N', N, M, N, CONE, BF, LDB, VR, LDVR, CZERO,
202     $            WORK, LDWORK )
203      CALL ZGEMM( 'C', 'N', M, M, N, CONE, VL, LDVL, WORK, LDWORK,
204     $            CZERO, E, LDE )
205*
206      CALL ZGEMM( 'n', 'n', N, M, N, CONE, B, LDB, VRF, LDVR, CZERO,
207     $            WORK, LDWORK )
208      CALL ZGEMM( 'C', 'N', M, M, N, CONE, VLF, LDVL, WORK, LDWORK,
209     $            CZERO, F, LDF )
210*
211      VMAX = ZERO
212      DO 90 J = 1, M
213         DO 80 I = 1, M
214            VMAX = MAX( VMAX, CABS1( E( I, J )-F( I, J ) ) )
215   80    CONTINUE
216   90 CONTINUE
217      VMAX = VMAX / ( EPS*MAX( ANORM, BNORM ) )
218      IF( VMAX.GT.RMAX ) THEN
219         LMAX( 4 ) = KNT
220         RMAX = VMAX
221      END IF
222*
223      GO TO 10
224*
225  100 CONTINUE
226*
227      WRITE( NOUT, FMT = 9999 )
228 9999 FORMAT( 1X, '.. test output of ZGGBAK .. ' )
229*
230      WRITE( NOUT, FMT = 9998 )RMAX
231 9998 FORMAT( ' value of largest test error                  =', D12.3 )
232      WRITE( NOUT, FMT = 9997 )LMAX( 1 )
233 9997 FORMAT( ' example number where ZGGBAL info is not 0    =', I4 )
234      WRITE( NOUT, FMT = 9996 )LMAX( 2 )
235 9996 FORMAT( ' example number where ZGGBAK(L) info is not 0 =', I4 )
236      WRITE( NOUT, FMT = 9995 )LMAX( 3 )
237 9995 FORMAT( ' example number where ZGGBAK(R) info is not 0 =', I4 )
238      WRITE( NOUT, FMT = 9994 )LMAX( 4 )
239 9994 FORMAT( ' example number having largest error          =', I4 )
240      WRITE( NOUT, FMT = 9992 )NINFO
241 9992 FORMAT( ' number of examples where info is not 0       =', I4 )
242      WRITE( NOUT, FMT = 9991 )KNT
243 9991 FORMAT( ' total number of examples tested              =', I4 )
244*
245      RETURN
246*
247*     End of ZCHKGK
248*
249      END
250