1*> \brief \b CDRVSY_ROOK
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 CDRVSY_ROOK( DOTYPE, NN, NVAL, NRHS, THRESH, TSTERR,
12*                          NMAX, A, AFAC, AINV, B, X, XACT, WORK, RWORK,
13*                          IWORK, NOUT )
14*
15*       .. Scalar Arguments ..
16*       LOGICAL            TSTERR
17*       INTEGER            NMAX, NN, NOUT, NRHS
18*       REAL               THRESH
19*       ..
20*       .. Array Arguments ..
21*       LOGICAL            DOTYPE( * )
22*       INTEGER            IWORK( * ), NVAL( * )
23*       REAL               RWORK( * )
24*       COMPLEX            A( * ), AFAC( * ), AINV( * ), B( * ),
25*      $                   WORK( * ), X( * ), XACT( * )
26*       ..
27*
28*
29*> \par Purpose:
30*  =============
31*>
32*> \verbatim
33*>
34*> CDRVSY_ROOK tests the driver routines CSYSV_ROOK.
35*> \endverbatim
36*
37*  Arguments:
38*  ==========
39*
40*> \param[in] DOTYPE
41*> \verbatim
42*>          DOTYPE is LOGICAL array, dimension (NTYPES)
43*>          The matrix types to be used for testing.  Matrices of type j
44*>          (for 1 <= j <= NTYPES) are used for testing if DOTYPE(j) =
45*>          .TRUE.; if DOTYPE(j) = .FALSE., then type j is not used.
46*> \endverbatim
47*>
48*> \param[in] NN
49*> \verbatim
50*>          NN is INTEGER
51*>          The number of values of N contained in the vector NVAL.
52*> \endverbatim
53*>
54*> \param[in] NVAL
55*> \verbatim
56*>          NVAL is INTEGER array, dimension (NN)
57*>          The values of the matrix dimension N.
58*> \endverbatim
59*>
60*> \param[in] NRHS
61*> \verbatim
62*>          NRHS is INTEGER
63*>          The number of right hand side vectors to be generated for
64*>          each linear system.
65*> \endverbatim
66*>
67*> \param[in] THRESH
68*> \verbatim
69*>          THRESH is REAL
70*>          The threshold value for the test ratios.  A result is
71*>          included in the output file if RESULT >= THRESH.  To have
72*>          every test ratio printed, use THRESH = 0.
73*> \endverbatim
74*>
75*> \param[in] TSTERR
76*> \verbatim
77*>          TSTERR is LOGICAL
78*>          Flag that indicates whether error exits are to be tested.
79*> \endverbatim
80*>
81*> \param[in] NMAX
82*> \verbatim
83*>          NMAX is INTEGER
84*>          The maximum value permitted for N, used in dimensioning the
85*>          work arrays.
86*> \endverbatim
87*>
88*> \param[out] A
89*> \verbatim
90*>          A is COMPLEX array, dimension (NMAX*NMAX)
91*> \endverbatim
92*>
93*> \param[out] AFAC
94*> \verbatim
95*>          AFAC is COMPLEX array, dimension (NMAX*NMAX)
96*> \endverbatim
97*>
98*> \param[out] AINV
99*> \verbatim
100*>          AINV is COMPLEX array, dimension (NMAX*NMAX)
101*> \endverbatim
102*>
103*> \param[out] B
104*> \verbatim
105*>          B is COMPLEX array, dimension (NMAX*NRHS)
106*> \endverbatim
107*>
108*> \param[out] X
109*> \verbatim
110*>          X is COMPLEX array, dimension (NMAX*NRHS)
111*> \endverbatim
112*>
113*> \param[out] XACT
114*> \verbatim
115*>          XACT is COMPLEX array, dimension (NMAX*NRHS)
116*> \endverbatim
117*>
118*> \param[out] WORK
119*> \verbatim
120*> \endverbatim
121*>
122*> \param[out] RWORK
123*> \verbatim
124*>          RWORK is REAL array, dimension (NMAX+2*NRHS)
125*> \endverbatim
126*>
127*> \param[out] IWORK
128*> \verbatim
129*>          IWORK is INTEGER array, dimension (NMAX)
130*> \endverbatim
131*>
132*> \param[in] NOUT
133*> \verbatim
134*>          NOUT is INTEGER
135*>          The unit number for output.
136*> \endverbatim
137*
138*  Authors:
139*  ========
140*
141*> \author Univ. of Tennessee
142*> \author Univ. of California Berkeley
143*> \author Univ. of Colorado Denver
144*> \author NAG Ltd.
145*
146*> \date November 2013
147*
148*> \ingroup complex_lin
149*
150*  =====================================================================
151      SUBROUTINE CDRVSY_ROOK( DOTYPE, NN, NVAL, NRHS, THRESH, TSTERR,
152     $                        NMAX, A, AFAC, AINV, B, X, XACT, WORK,
153     $                        RWORK, IWORK, NOUT )
154*
155*  -- LAPACK test routine (version 3.5.0) --
156*  -- LAPACK is a software package provided by Univ. of Tennessee,    --
157*  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
158*     November 2013
159*
160*     .. Scalar Arguments ..
161      LOGICAL            TSTERR
162      INTEGER            NMAX, NN, NOUT, NRHS
163      REAL               THRESH
164*     ..
165*     .. Array Arguments ..
166      LOGICAL            DOTYPE( * )
167      INTEGER            IWORK( * ), NVAL( * )
168      REAL               RWORK( * )
169      COMPLEX            A( * ), AFAC( * ), AINV( * ), B( * ),
170     $                   WORK( * ), X( * ), XACT( * )
171*     ..
172*
173*  =====================================================================
174*
175*     .. Parameters ..
176      REAL               ONE, ZERO
177      PARAMETER          ( ONE = 1.0E+0, ZERO = 0.0E+0 )
178      INTEGER            NTYPES, NTESTS
179      PARAMETER          ( NTYPES = 11, NTESTS = 3 )
180      INTEGER            NFACT
181      PARAMETER          ( NFACT = 2 )
182*     ..
183*     .. Local Scalars ..
184      LOGICAL            ZEROT
185      CHARACTER          DIST, FACT, TYPE, UPLO, XTYPE
186      CHARACTER*3        MATPATH, PATH
187      INTEGER            I, I1, I2, IFACT, IMAT, IN, INFO, IOFF, IUPLO,
188     $                   IZERO, J, K, KL, KU, LDA, LWORK, MODE, N,
189     $                   NB, NBMIN, NERRS, NFAIL, NIMAT, NRUN, NT
190      REAL               AINVNM, ANORM, CNDNUM, RCONDC
191*     ..
192*     .. Local Arrays ..
193      CHARACTER          FACTS( NFACT ), UPLOS( 2 )
194      INTEGER            ISEED( 4 ), ISEEDY( 4 )
195      REAL               RESULT( NTESTS )
196
197*     ..
198*     .. External Functions ..
199      REAL               CLANSY
200      EXTERNAL           CLANSY
201*     ..
202*     .. External Subroutines ..
203      EXTERNAL           ALADHD, ALAERH, ALASVM, XLAENV, CERRVX, CGET04,
204     $                   CLACPY, CLARHS, CLASET, CLATB4, CLATMS, CLATSY,
205     $                   CPOT05, CSYSV_ROOK, CSYT01_ROOK, CSYT02,
206     $                   CSYTRF_ROOK, CSYTRI_ROOK
207*     ..
208*     .. Scalars in Common ..
209      LOGICAL            LERR, OK
210      CHARACTER*32       SRNAMT
211      INTEGER            INFOT, NUNIT
212*     ..
213*     .. Common blocks ..
214      COMMON             / INFOC / INFOT, NUNIT, OK, LERR
215      COMMON             / SRNAMC / SRNAMT
216*     ..
217*     .. Intrinsic Functions ..
218      INTRINSIC          MAX, MIN
219*     ..
220*     .. Data statements ..
221      DATA               ISEEDY / 1988, 1989, 1990, 1991 /
222      DATA               UPLOS / 'U', 'L' / , FACTS / 'F', 'N' /
223*     ..
224*     .. Executable Statements ..
225*
226*     Initialize constants and the random number seed.
227*
228*     Test path
229*
230      PATH( 1: 1 ) = 'Complex precision'
231      PATH( 2: 3 ) = 'SR'
232*
233*     Path to generate matrices
234*
235      MATPATH( 1: 1 ) = 'Complex precision'
236      MATPATH( 2: 3 ) = 'SY'
237*
238      NRUN = 0
239      NFAIL = 0
240      NERRS = 0
241      DO 10 I = 1, 4
242         ISEED( I ) = ISEEDY( I )
243   10 CONTINUE
244      LWORK = MAX( 2*NMAX, NMAX*NRHS )
245*
246*     Test the error exits
247*
248      IF( TSTERR )
249     $   CALL CERRVX( PATH, NOUT )
250      INFOT = 0
251*
252*     Set the block size and minimum block size for which the block
253*     routine should be used, which will be later returned by ILAENV.
254*
255      NB = 1
256      NBMIN = 2
257      CALL XLAENV( 1, NB )
258      CALL XLAENV( 2, NBMIN )
259*
260*     Do for each value of N in NVAL
261*
262      DO 180 IN = 1, NN
263         N = NVAL( IN )
264         LDA = MAX( N, 1 )
265         XTYPE = 'N'
266         NIMAT = NTYPES
267         IF( N.LE.0 )
268     $      NIMAT = 1
269*
270         DO 170 IMAT = 1, NIMAT
271*
272*           Do the tests only if DOTYPE( IMAT ) is true.
273*
274            IF( .NOT.DOTYPE( IMAT ) )
275     $         GO TO 170
276*
277*           Skip types 3, 4, 5, or 6 if the matrix size is too small.
278*
279            ZEROT = IMAT.GE.3 .AND. IMAT.LE.6
280            IF( ZEROT .AND. N.LT.IMAT-2 )
281     $         GO TO 170
282*
283*           Do first for UPLO = 'U', then for UPLO = 'L'
284*
285            DO 160 IUPLO = 1, 2
286               UPLO = UPLOS( IUPLO )
287*
288               IF( IMAT.NE.NTYPES ) THEN
289*
290*                 Begin generate the test matrix A.
291*
292*                 Set up parameters with CLATB4 for the matrix generator
293*                 based on the type of matrix to be generated.
294*
295                  CALL CLATB4( MATPATH, IMAT, N, N, TYPE, KL, KU, ANORM,
296     $                         MODE, CNDNUM, DIST )
297*
298*                 Generate a matrix with CLATMS.
299*
300                  SRNAMT = 'CLATMS'
301                  CALL CLATMS( N, N, DIST, ISEED, TYPE, RWORK, MODE,
302     $                         CNDNUM, ANORM, KL, KU, UPLO, A, LDA,
303     $                         WORK, INFO )
304*
305*                 Check error code from CLATMS and handle error.
306*
307                  IF( INFO.NE.0 ) THEN
308                     CALL ALAERH( PATH, 'CLATMS', INFO, 0, UPLO, N, N,
309     $                            -1, -1, -1, IMAT, NFAIL, NERRS, NOUT )
310                     GO TO 160
311                  END IF
312*
313*                 For types 3-6, zero one or more rows and columns of
314*                 the matrix to test that INFO is returned correctly.
315*
316                  IF( ZEROT ) THEN
317                     IF( IMAT.EQ.3 ) THEN
318                        IZERO = 1
319                     ELSE IF( IMAT.EQ.4 ) THEN
320                        IZERO = N
321                     ELSE
322                        IZERO = N / 2 + 1
323                     END IF
324*
325                     IF( IMAT.LT.6 ) THEN
326*
327*                       Set row and column IZERO to zero.
328*
329                        IF( IUPLO.EQ.1 ) THEN
330                           IOFF = ( IZERO-1 )*LDA
331                           DO 20 I = 1, IZERO - 1
332                              A( IOFF+I ) = ZERO
333   20                      CONTINUE
334                           IOFF = IOFF + IZERO
335                           DO 30 I = IZERO, N
336                              A( IOFF ) = ZERO
337                              IOFF = IOFF + LDA
338   30                      CONTINUE
339                        ELSE
340                           IOFF = IZERO
341                           DO 40 I = 1, IZERO - 1
342                              A( IOFF ) = ZERO
343                              IOFF = IOFF + LDA
344   40                      CONTINUE
345                           IOFF = IOFF - IZERO
346                           DO 50 I = IZERO, N
347                              A( IOFF+I ) = ZERO
348   50                      CONTINUE
349                        END IF
350                     ELSE
351                        IF( IUPLO.EQ.1 ) THEN
352*
353*                       Set the first IZERO rows and columns to zero.
354*
355                           IOFF = 0
356                           DO 70 J = 1, N
357                              I2 = MIN( J, IZERO )
358                              DO 60 I = 1, I2
359                                 A( IOFF+I ) = ZERO
360   60                         CONTINUE
361                              IOFF = IOFF + LDA
362   70                      CONTINUE
363                        ELSE
364*
365*                       Set the first IZERO rows and columns to zero.
366*
367                           IOFF = 0
368                           DO 90 J = 1, N
369                              I1 = MAX( J, IZERO )
370                              DO 80 I = I1, N
371                                 A( IOFF+I ) = ZERO
372   80                         CONTINUE
373                              IOFF = IOFF + LDA
374   90                      CONTINUE
375                        END IF
376                     END IF
377                  ELSE
378                     IZERO = 0
379                  END IF
380*
381*                 End generate the test matrix A.
382*
383               ELSE
384*
385*                 IMAT = NTYPES:  Use a special block diagonal matrix to
386*                 test alternate code for the 2-by-2 blocks.
387*
388                  CALL CLATSY( UPLO, N, A, LDA, ISEED )
389               END IF
390*
391               DO 150 IFACT = 1, NFACT
392*
393*                 Do first for FACT = 'F', then for other values.
394*
395                  FACT = FACTS( IFACT )
396*
397*                 Compute the condition number for comparison with
398*                 the value returned by CSYSVX_ROOK.
399*
400                  IF( ZEROT ) THEN
401                     IF( IFACT.EQ.1 )
402     $                  GO TO 150
403                     RCONDC = ZERO
404*
405                  ELSE IF( IFACT.EQ.1 ) THEN
406*
407*                    Compute the 1-norm of A.
408*
409                     ANORM = CLANSY( '1', UPLO, N, A, LDA, RWORK )
410*
411*                    Factor the matrix A.
412*
413
414                     CALL CLACPY( UPLO, N, N, A, LDA, AFAC, LDA )
415                     CALL CSYTRF_ROOK( UPLO, N, AFAC, LDA, IWORK, WORK,
416     $                                 LWORK, INFO )
417*
418*                    Compute inv(A) and take its norm.
419*
420                     CALL CLACPY( UPLO, N, N, AFAC, LDA, AINV, LDA )
421                     LWORK = (N+NB+1)*(NB+3)
422                     CALL CSYTRI_ROOK( UPLO, N, AINV, LDA, IWORK,
423     $                                 WORK, INFO )
424                     AINVNM = CLANSY( '1', UPLO, N, AINV, LDA, RWORK )
425*
426*                    Compute the 1-norm condition number of A.
427*
428                     IF( ANORM.LE.ZERO .OR. AINVNM.LE.ZERO ) THEN
429                        RCONDC = ONE
430                     ELSE
431                        RCONDC = ( ONE / ANORM ) / AINVNM
432                     END IF
433                  END IF
434*
435*                 Form an exact solution and set the right hand side.
436*
437                  SRNAMT = 'CLARHS'
438                  CALL CLARHS( MATPATH, XTYPE, UPLO, ' ', N, N, KL, KU,
439     $                         NRHS, A, LDA, XACT, LDA, B, LDA, ISEED,
440     $                         INFO )
441                  XTYPE = 'C'
442*
443*                 --- Test CSYSV_ROOK  ---
444*
445                  IF( IFACT.EQ.2 ) THEN
446                     CALL CLACPY( UPLO, N, N, A, LDA, AFAC, LDA )
447                     CALL CLACPY( 'Full', N, NRHS, B, LDA, X, LDA )
448*
449*                    Factor the matrix and solve the system using
450*                    CSYSV_ROOK.
451*
452                     SRNAMT = 'CSYSV_ROOK'
453                     CALL CSYSV_ROOK( UPLO, N, NRHS, AFAC, LDA, IWORK,
454     $                                X, LDA, WORK, LWORK, INFO )
455*
456*                    Adjust the expected value of INFO to account for
457*                    pivoting.
458*
459                     K = IZERO
460                     IF( K.GT.0 ) THEN
461  100                   CONTINUE
462                        IF( IWORK( K ).LT.0 ) THEN
463                           IF( IWORK( K ).NE.-K ) THEN
464                              K = -IWORK( K )
465                              GO TO 100
466                           END IF
467                        ELSE IF( IWORK( K ).NE.K ) THEN
468                           K = IWORK( K )
469                           GO TO 100
470                        END IF
471                     END IF
472*
473*                    Check error code from CSYSV_ROOK and handle error.
474*
475                     IF( INFO.NE.K ) THEN
476                        CALL ALAERH( PATH, 'CSYSV_ROOK', INFO, K, UPLO,
477     $                               N, N, -1, -1, NRHS, IMAT, NFAIL,
478     $                               NERRS, NOUT )
479                        GO TO 120
480                     ELSE IF( INFO.NE.0 ) THEN
481                        GO TO 120
482                     END IF
483*
484*+    TEST 1      Reconstruct matrix from factors and compute
485*                 residual.
486*
487                     CALL CSYT01_ROOK( UPLO, N, A, LDA, AFAC, LDA,
488     $                                 IWORK, AINV, LDA, RWORK,
489     $                                 RESULT( 1 ) )
490*
491*+    TEST 2      Compute residual of the computed solution.
492*
493                     CALL CLACPY( 'Full', N, NRHS, B, LDA, WORK, LDA )
494                     CALL CSYT02( UPLO, N, NRHS, A, LDA, X, LDA, WORK,
495     $                            LDA, RWORK, RESULT( 2 ) )
496*
497*+    TEST 3
498*                 Check solution from generated exact solution.
499*
500                     CALL CGET04( N, NRHS, X, LDA, XACT, LDA, RCONDC,
501     $                            RESULT( 3 ) )
502                     NT = 3
503*
504*                    Print information about the tests that did not pass
505*                    the threshold.
506*
507                     DO 110 K = 1, NT
508                        IF( RESULT( K ).GE.THRESH ) THEN
509                           IF( NFAIL.EQ.0 .AND. NERRS.EQ.0 )
510     $                        CALL ALADHD( NOUT, PATH )
511                           WRITE( NOUT, FMT = 9999 )'CSYSV_ROOK', UPLO,
512     $                            N, IMAT, K, RESULT( K )
513                           NFAIL = NFAIL + 1
514                        END IF
515  110                CONTINUE
516                     NRUN = NRUN + NT
517  120                CONTINUE
518                  END IF
519*
520  150          CONTINUE
521*
522  160       CONTINUE
523  170    CONTINUE
524  180 CONTINUE
525*
526*     Print a summary of the results.
527*
528      CALL ALASVM( PATH, NOUT, NFAIL, NRUN, NERRS )
529*
530 9999 FORMAT( 1X, A, ', UPLO=''', A1, ''', N =', I5, ', type ', I2,
531     $      ', test ', I2, ', ratio =', G12.5 )
532      RETURN
533*
534*     End of CDRVSY_ROOK
535*
536      END
537