1*> \brief \b SCHKTP
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 SCHKTP( DOTYPE, NN, NVAL, NNS, NSVAL, THRESH, TSTERR,
12*                          NMAX, AP, AINVP, B, X, XACT, WORK, RWORK,
13*                          IWORK, NOUT )
14*
15*       .. Scalar Arguments ..
16*       LOGICAL            TSTERR
17*       INTEGER            NMAX, NN, NNS, NOUT
18*       REAL               THRESH
19*       ..
20*       .. Array Arguments ..
21*       LOGICAL            DOTYPE( * )
22*       INTEGER            IWORK( * ), NSVAL( * ), NVAL( * )
23*       REAL               AINVP( * ), AP( * ), B( * ), RWORK( * ),
24*      $                   WORK( * ), X( * ), XACT( * )
25*       ..
26*
27*
28*> \par Purpose:
29*  =============
30*>
31*> \verbatim
32*>
33*> SCHKTP tests STPTRI, -TRS, -RFS, and -CON, and SLATPS
34*> \endverbatim
35*
36*  Arguments:
37*  ==========
38*
39*> \param[in] DOTYPE
40*> \verbatim
41*>          DOTYPE is LOGICAL array, dimension (NTYPES)
42*>          The matrix types to be used for testing.  Matrices of type j
43*>          (for 1 <= j <= NTYPES) are used for testing if DOTYPE(j) =
44*>          .TRUE.; if DOTYPE(j) = .FALSE., then type j is not used.
45*> \endverbatim
46*>
47*> \param[in] NN
48*> \verbatim
49*>          NN is INTEGER
50*>          The number of values of N contained in the vector NVAL.
51*> \endverbatim
52*>
53*> \param[in] NVAL
54*> \verbatim
55*>          NVAL is INTEGER array, dimension (NN)
56*>          The values of the matrix column dimension N.
57*> \endverbatim
58*>
59*> \param[in] NNS
60*> \verbatim
61*>          NNS is INTEGER
62*>          The number of values of NRHS contained in the vector NSVAL.
63*> \endverbatim
64*>
65*> \param[in] NSVAL
66*> \verbatim
67*>          NSVAL is INTEGER array, dimension (NNS)
68*>          The values of the number of right hand sides NRHS.
69*> \endverbatim
70*>
71*> \param[in] THRESH
72*> \verbatim
73*>          THRESH is REAL
74*>          The threshold value for the test ratios.  A result is
75*>          included in the output file if RESULT >= THRESH.  To have
76*>          every test ratio printed, use THRESH = 0.
77*> \endverbatim
78*>
79*> \param[in] TSTERR
80*> \verbatim
81*>          TSTERR is LOGICAL
82*>          Flag that indicates whether error exits are to be tested.
83*> \endverbatim
84*>
85*> \param[in] NMAX
86*> \verbatim
87*>          NMAX is INTEGER
88*>          The leading dimension of the work arrays.  NMAX >= the
89*>          maximumm value of N in NVAL.
90*> \endverbatim
91*>
92*> \param[out] AP
93*> \verbatim
94*>          AP is REAL array, dimension
95*>                      (NMAX*(NMAX+1)/2)
96*> \endverbatim
97*>
98*> \param[out] AINVP
99*> \verbatim
100*>          AINVP is REAL array, dimension
101*>                      (NMAX*(NMAX+1)/2)
102*> \endverbatim
103*>
104*> \param[out] B
105*> \verbatim
106*>          B is REAL array, dimension (NMAX*NSMAX)
107*>          where NSMAX is the largest entry in NSVAL.
108*> \endverbatim
109*>
110*> \param[out] X
111*> \verbatim
112*>          X is REAL array, dimension (NMAX*NSMAX)
113*> \endverbatim
114*>
115*> \param[out] XACT
116*> \verbatim
117*>          XACT is REAL array, dimension (NMAX*NSMAX)
118*> \endverbatim
119*>
120*> \param[out] WORK
121*> \verbatim
122*>          WORK is REAL array, dimension
123*>                      (NMAX*max(3,NSMAX))
124*> \endverbatim
125*>
126*> \param[out] IWORK
127*> \verbatim
128*>          IWORK is INTEGER array, dimension (NMAX)
129*> \endverbatim
130*>
131*> \param[out] RWORK
132*> \verbatim
133*>          RWORK is REAL array, dimension
134*>                      (max(NMAX,2*NSMAX))
135*> \endverbatim
136*>
137*> \param[in] NOUT
138*> \verbatim
139*>          NOUT is INTEGER
140*>          The unit number for output.
141*> \endverbatim
142*
143*  Authors:
144*  ========
145*
146*> \author Univ. of Tennessee
147*> \author Univ. of California Berkeley
148*> \author Univ. of Colorado Denver
149*> \author NAG Ltd.
150*
151*> \ingroup single_lin
152*
153*  =====================================================================
154      SUBROUTINE SCHKTP( DOTYPE, NN, NVAL, NNS, NSVAL, THRESH, TSTERR,
155     $                   NMAX, AP, AINVP, B, X, XACT, WORK, RWORK,
156     $                   IWORK, NOUT )
157*
158*  -- LAPACK test routine --
159*  -- LAPACK is a software package provided by Univ. of Tennessee,    --
160*  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
161*
162*     .. Scalar Arguments ..
163      LOGICAL            TSTERR
164      INTEGER            NMAX, NN, NNS, NOUT
165      REAL               THRESH
166*     ..
167*     .. Array Arguments ..
168      LOGICAL            DOTYPE( * )
169      INTEGER            IWORK( * ), NSVAL( * ), NVAL( * )
170      REAL               AINVP( * ), AP( * ), B( * ), RWORK( * ),
171     $                   WORK( * ), X( * ), XACT( * )
172*     ..
173*
174*  =====================================================================
175*
176*     .. Parameters ..
177      INTEGER            NTYPE1, NTYPES
178      PARAMETER          ( NTYPE1 = 10, NTYPES = 18 )
179      INTEGER            NTESTS
180      PARAMETER          ( NTESTS = 9 )
181      INTEGER            NTRAN
182      PARAMETER          ( NTRAN = 3 )
183      REAL               ONE, ZERO
184      PARAMETER          ( ONE = 1.0E+0, ZERO = 0.0E+0 )
185*     ..
186*     .. Local Scalars ..
187      CHARACTER          DIAG, NORM, TRANS, UPLO, XTYPE
188      CHARACTER*3        PATH
189      INTEGER            I, IDIAG, IMAT, IN, INFO, IRHS, ITRAN, IUPLO,
190     $                   K, LAP, LDA, N, NERRS, NFAIL, NRHS, NRUN
191      REAL               AINVNM, ANORM, RCOND, RCONDC, RCONDI, RCONDO,
192     $                   SCALE
193*     ..
194*     .. Local Arrays ..
195      CHARACTER          TRANSS( NTRAN ), UPLOS( 2 )
196      INTEGER            ISEED( 4 ), ISEEDY( 4 )
197      REAL               RESULT( NTESTS )
198*     ..
199*     .. External Functions ..
200      LOGICAL            LSAME
201      REAL               SLANTP
202      EXTERNAL           LSAME, SLANTP
203*     ..
204*     .. External Subroutines ..
205      EXTERNAL           ALAERH, ALAHD, ALASUM, SCOPY, SERRTR, SGET04,
206     $                   SLACPY, SLARHS, SLATPS, SLATTP, STPCON, STPRFS,
207     $                   STPT01, STPT02, STPT03, STPT05, STPT06, STPTRI,
208     $                   STPTRS
209*     ..
210*     .. Scalars in Common ..
211      LOGICAL            LERR, OK
212      CHARACTER*32       SRNAMT
213      INTEGER            INFOT, IOUNIT
214*     ..
215*     .. Common blocks ..
216      COMMON             / INFOC / INFOT, IOUNIT, OK, LERR
217      COMMON             / SRNAMC / SRNAMT
218*     ..
219*     .. Intrinsic Functions ..
220      INTRINSIC          MAX
221*     ..
222*     .. Data statements ..
223      DATA               ISEEDY / 1988, 1989, 1990, 1991 /
224      DATA               UPLOS / 'U', 'L' / , TRANSS / 'N', 'T', 'C' /
225*     ..
226*     .. Executable Statements ..
227*
228*     Initialize constants and the random number seed.
229*
230      PATH( 1: 1 ) = 'Single precision'
231      PATH( 2: 3 ) = 'TP'
232      NRUN = 0
233      NFAIL = 0
234      NERRS = 0
235      DO 10 I = 1, 4
236         ISEED( I ) = ISEEDY( I )
237   10 CONTINUE
238*
239*     Test the error exits
240*
241      IF( TSTERR )
242     $   CALL SERRTR( PATH, NOUT )
243      INFOT = 0
244*
245      DO 110 IN = 1, NN
246*
247*        Do for each value of N in NVAL
248*
249         N = NVAL( IN )
250         LDA = MAX( 1, N )
251         LAP = LDA*( LDA+1 ) / 2
252         XTYPE = 'N'
253*
254         DO 70 IMAT = 1, NTYPE1
255*
256*           Do the tests only if DOTYPE( IMAT ) is true.
257*
258            IF( .NOT.DOTYPE( IMAT ) )
259     $         GO TO 70
260*
261            DO 60 IUPLO = 1, 2
262*
263*              Do first for UPLO = 'U', then for UPLO = 'L'
264*
265               UPLO = UPLOS( IUPLO )
266*
267*              Call SLATTP to generate a triangular test matrix.
268*
269               SRNAMT = 'SLATTP'
270               CALL SLATTP( IMAT, UPLO, 'No transpose', DIAG, ISEED, N,
271     $                      AP, X, WORK, INFO )
272*
273*              Set IDIAG = 1 for non-unit matrices, 2 for unit.
274*
275               IF( LSAME( DIAG, 'N' ) ) THEN
276                  IDIAG = 1
277               ELSE
278                  IDIAG = 2
279               END IF
280*
281*+    TEST 1
282*              Form the inverse of A.
283*
284               IF( N.GT.0 )
285     $            CALL SCOPY( LAP, AP, 1, AINVP, 1 )
286               SRNAMT = 'STPTRI'
287               CALL STPTRI( UPLO, DIAG, N, AINVP, INFO )
288*
289*              Check error code from STPTRI.
290*
291               IF( INFO.NE.0 )
292     $            CALL ALAERH( PATH, 'STPTRI', INFO, 0, UPLO // DIAG, N,
293     $                         N, -1, -1, -1, IMAT, NFAIL, NERRS, NOUT )
294*
295*              Compute the infinity-norm condition number of A.
296*
297               ANORM = SLANTP( 'I', UPLO, DIAG, N, AP, RWORK )
298               AINVNM = SLANTP( 'I', UPLO, DIAG, N, AINVP, RWORK )
299               IF( ANORM.LE.ZERO .OR. AINVNM.LE.ZERO ) THEN
300                  RCONDI = ONE
301               ELSE
302                  RCONDI = ( ONE / ANORM ) / AINVNM
303               END IF
304*
305*              Compute the residual for the triangular matrix times its
306*              inverse.  Also compute the 1-norm condition number of A.
307*
308               CALL STPT01( UPLO, DIAG, N, AP, AINVP, RCONDO, RWORK,
309     $                      RESULT( 1 ) )
310*
311*              Print the test ratio if it is .GE. THRESH.
312*
313               IF( RESULT( 1 ).GE.THRESH ) THEN
314                  IF( NFAIL.EQ.0 .AND. NERRS.EQ.0 )
315     $               CALL ALAHD( NOUT, PATH )
316                  WRITE( NOUT, FMT = 9999 )UPLO, DIAG, N, IMAT, 1,
317     $               RESULT( 1 )
318                  NFAIL = NFAIL + 1
319               END IF
320               NRUN = NRUN + 1
321*
322               DO 40 IRHS = 1, NNS
323                  NRHS = NSVAL( IRHS )
324                  XTYPE = 'N'
325*
326                  DO 30 ITRAN = 1, NTRAN
327*
328*                 Do for op(A) = A, A**T, or A**H.
329*
330                     TRANS = TRANSS( ITRAN )
331                     IF( ITRAN.EQ.1 ) THEN
332                        NORM = 'O'
333                        RCONDC = RCONDO
334                     ELSE
335                        NORM = 'I'
336                        RCONDC = RCONDI
337                     END IF
338*
339*+    TEST 2
340*                 Solve and compute residual for op(A)*x = b.
341*
342                     SRNAMT = 'SLARHS'
343                     CALL SLARHS( PATH, XTYPE, UPLO, TRANS, N, N, 0,
344     $                            IDIAG, NRHS, AP, LAP, XACT, LDA, B,
345     $                            LDA, ISEED, INFO )
346                     XTYPE = 'C'
347                     CALL SLACPY( 'Full', N, NRHS, B, LDA, X, LDA )
348*
349                     SRNAMT = 'STPTRS'
350                     CALL STPTRS( UPLO, TRANS, DIAG, N, NRHS, AP, X,
351     $                            LDA, INFO )
352*
353*                 Check error code from STPTRS.
354*
355                     IF( INFO.NE.0 )
356     $                  CALL ALAERH( PATH, 'STPTRS', INFO, 0,
357     $                               UPLO // TRANS // DIAG, N, N, -1,
358     $                               -1, -1, IMAT, NFAIL, NERRS, NOUT )
359*
360                     CALL STPT02( UPLO, TRANS, DIAG, N, NRHS, AP, X,
361     $                            LDA, B, LDA, WORK, RESULT( 2 ) )
362*
363*+    TEST 3
364*                 Check solution from generated exact solution.
365*
366                     CALL SGET04( N, NRHS, X, LDA, XACT, LDA, RCONDC,
367     $                            RESULT( 3 ) )
368*
369*+    TESTS 4, 5, and 6
370*                 Use iterative refinement to improve the solution and
371*                 compute error bounds.
372*
373                     SRNAMT = 'STPRFS'
374                     CALL STPRFS( UPLO, TRANS, DIAG, N, NRHS, AP, B,
375     $                            LDA, X, LDA, RWORK, RWORK( NRHS+1 ),
376     $                            WORK, IWORK, INFO )
377*
378*                 Check error code from STPRFS.
379*
380                     IF( INFO.NE.0 )
381     $                  CALL ALAERH( PATH, 'STPRFS', INFO, 0,
382     $                               UPLO // TRANS // DIAG, N, N, -1,
383     $                               -1, NRHS, IMAT, NFAIL, NERRS,
384     $                               NOUT )
385*
386                     CALL SGET04( N, NRHS, X, LDA, XACT, LDA, RCONDC,
387     $                            RESULT( 4 ) )
388                     CALL STPT05( UPLO, TRANS, DIAG, N, NRHS, AP, B,
389     $                            LDA, X, LDA, XACT, LDA, RWORK,
390     $                            RWORK( NRHS+1 ), RESULT( 5 ) )
391*
392*                    Print information about the tests that did not pass
393*                    the threshold.
394*
395                     DO 20 K = 2, 6
396                        IF( RESULT( K ).GE.THRESH ) THEN
397                           IF( NFAIL.EQ.0 .AND. NERRS.EQ.0 )
398     $                        CALL ALAHD( NOUT, PATH )
399                           WRITE( NOUT, FMT = 9998 )UPLO, TRANS, DIAG,
400     $                        N, NRHS, IMAT, K, RESULT( K )
401                           NFAIL = NFAIL + 1
402                        END IF
403   20                CONTINUE
404                     NRUN = NRUN + 5
405   30             CONTINUE
406   40          CONTINUE
407*
408*+    TEST 7
409*                 Get an estimate of RCOND = 1/CNDNUM.
410*
411               DO 50 ITRAN = 1, 2
412                  IF( ITRAN.EQ.1 ) THEN
413                     NORM = 'O'
414                     RCONDC = RCONDO
415                  ELSE
416                     NORM = 'I'
417                     RCONDC = RCONDI
418                  END IF
419*
420                  SRNAMT = 'STPCON'
421                  CALL STPCON( NORM, UPLO, DIAG, N, AP, RCOND, WORK,
422     $                         IWORK, INFO )
423*
424*                 Check error code from STPCON.
425*
426                  IF( INFO.NE.0 )
427     $               CALL ALAERH( PATH, 'STPCON', INFO, 0,
428     $                            NORM // UPLO // DIAG, N, N, -1, -1,
429     $                            -1, IMAT, NFAIL, NERRS, NOUT )
430*
431                  CALL STPT06( RCOND, RCONDC, UPLO, DIAG, N, AP, RWORK,
432     $                         RESULT( 7 ) )
433*
434*                 Print the test ratio if it is .GE. THRESH.
435*
436                  IF( RESULT( 7 ).GE.THRESH ) THEN
437                     IF( NFAIL.EQ.0 .AND. NERRS.EQ.0 )
438     $                  CALL ALAHD( NOUT, PATH )
439                     WRITE( NOUT, FMT = 9997 ) 'STPCON', NORM, UPLO,
440     $                  DIAG, N, IMAT, 7, RESULT( 7 )
441                     NFAIL = NFAIL + 1
442                  END IF
443                  NRUN = NRUN + 1
444   50          CONTINUE
445   60       CONTINUE
446   70    CONTINUE
447*
448*        Use pathological test matrices to test SLATPS.
449*
450         DO 100 IMAT = NTYPE1 + 1, NTYPES
451*
452*           Do the tests only if DOTYPE( IMAT ) is true.
453*
454            IF( .NOT.DOTYPE( IMAT ) )
455     $         GO TO 100
456*
457            DO 90 IUPLO = 1, 2
458*
459*              Do first for UPLO = 'U', then for UPLO = 'L'
460*
461               UPLO = UPLOS( IUPLO )
462               DO 80 ITRAN = 1, NTRAN
463*
464*                 Do for op(A) = A, A**T, or A**H.
465*
466                  TRANS = TRANSS( ITRAN )
467*
468*                 Call SLATTP to generate a triangular test matrix.
469*
470                  SRNAMT = 'SLATTP'
471                  CALL SLATTP( IMAT, UPLO, TRANS, DIAG, ISEED, N, AP, X,
472     $                         WORK, INFO )
473*
474*+    TEST 8
475*                 Solve the system op(A)*x = b.
476*
477                  SRNAMT = 'SLATPS'
478                  CALL SCOPY( N, X, 1, B, 1 )
479                  CALL SLATPS( UPLO, TRANS, DIAG, 'N', N, AP, B, SCALE,
480     $                         RWORK, INFO )
481*
482*                 Check error code from SLATPS.
483*
484                  IF( INFO.NE.0 )
485     $               CALL ALAERH( PATH, 'SLATPS', INFO, 0,
486     $                            UPLO // TRANS // DIAG // 'N', N, N,
487     $                            -1, -1, -1, IMAT, NFAIL, NERRS, NOUT )
488*
489                  CALL STPT03( UPLO, TRANS, DIAG, N, 1, AP, SCALE,
490     $                         RWORK, ONE, B, LDA, X, LDA, WORK,
491     $                         RESULT( 8 ) )
492*
493*+    TEST 9
494*                 Solve op(A)*x = b again with NORMIN = 'Y'.
495*
496                  CALL SCOPY( N, X, 1, B( N+1 ), 1 )
497                  CALL SLATPS( UPLO, TRANS, DIAG, 'Y', N, AP, B( N+1 ),
498     $                         SCALE, RWORK, INFO )
499*
500*                 Check error code from SLATPS.
501*
502                  IF( INFO.NE.0 )
503     $               CALL ALAERH( PATH, 'SLATPS', INFO, 0,
504     $                            UPLO // TRANS // DIAG // 'Y', N, N,
505     $                            -1, -1, -1, IMAT, NFAIL, NERRS, NOUT )
506*
507                  CALL STPT03( UPLO, TRANS, DIAG, N, 1, AP, SCALE,
508     $                         RWORK, ONE, B( N+1 ), LDA, X, LDA, WORK,
509     $                         RESULT( 9 ) )
510*
511*                 Print information about the tests that did not pass
512*                 the threshold.
513*
514                  IF( RESULT( 8 ).GE.THRESH ) THEN
515                     IF( NFAIL.EQ.0 .AND. NERRS.EQ.0 )
516     $                  CALL ALAHD( NOUT, PATH )
517                     WRITE( NOUT, FMT = 9996 )'SLATPS', UPLO, TRANS,
518     $                  DIAG, 'N', N, IMAT, 8, RESULT( 8 )
519                     NFAIL = NFAIL + 1
520                  END IF
521                  IF( RESULT( 9 ).GE.THRESH ) THEN
522                     IF( NFAIL.EQ.0 .AND. NERRS.EQ.0 )
523     $                  CALL ALAHD( NOUT, PATH )
524                     WRITE( NOUT, FMT = 9996 )'SLATPS', UPLO, TRANS,
525     $                  DIAG, 'Y', N, IMAT, 9, RESULT( 9 )
526                     NFAIL = NFAIL + 1
527                  END IF
528                  NRUN = NRUN + 2
529   80          CONTINUE
530   90       CONTINUE
531  100    CONTINUE
532  110 CONTINUE
533*
534*     Print a summary of the results.
535*
536      CALL ALASUM( PATH, NOUT, NFAIL, NRUN, NERRS )
537*
538 9999 FORMAT( ' UPLO=''', A1, ''', DIAG=''', A1, ''', N=', I5,
539     $      ', type ', I2, ', test(', I2, ')= ', G12.5 )
540 9998 FORMAT( ' UPLO=''', A1, ''', TRANS=''', A1, ''', DIAG=''', A1,
541     $      ''', N=', I5, ''', NRHS=', I5, ', type ', I2, ', test(',
542     $      I2, ')= ', G12.5 )
543 9997 FORMAT( 1X, A, '( ''', A1, ''', ''', A1, ''', ''', A1, ''',',
544     $      I5, ', ... ), type ', I2, ', test(', I2, ')=', G12.5 )
545 9996 FORMAT( 1X, A, '( ''', A1, ''', ''', A1, ''', ''', A1, ''', ''',
546     $      A1, ''',', I5, ', ... ), type ', I2, ', test(', I2, ')=',
547     $      G12.5 )
548      RETURN
549*
550*     End of SCHKTP
551*
552      END
553