1*> \brief \b SLARHS
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 SLARHS( PATH, XTYPE, UPLO, TRANS, M, N, KL, KU, NRHS,
12*                          A, LDA, X, LDX, B, LDB, ISEED, INFO )
13*
14*       .. Scalar Arguments ..
15*       CHARACTER          TRANS, UPLO, XTYPE
16*       CHARACTER*3        PATH
17*       INTEGER            INFO, KL, KU, LDA, LDB, LDX, M, N, NRHS
18*       ..
19*       .. Array Arguments ..
20*       INTEGER            ISEED( 4 )
21*       REAL               A( LDA, * ), B( LDB, * ), X( LDX, * )
22*       ..
23*
24*
25*> \par Purpose:
26*  =============
27*>
28*> \verbatim
29*>
30*> SLARHS chooses a set of NRHS random solution vectors and sets
31*> up the right hand sides for the linear system
32*>    op(A) * X = B,
33*> where op(A) = A or A**T, depending on TRANS.
34*> \endverbatim
35*
36*  Arguments:
37*  ==========
38*
39*> \param[in] PATH
40*> \verbatim
41*>          PATH is CHARACTER*3
42*>          The type of the real matrix A.  PATH may be given in any
43*>          combination of upper and lower case.  Valid types include
44*>             xGE:  General m x n matrix
45*>             xGB:  General banded matrix
46*>             xPO:  Symmetric positive definite, 2-D storage
47*>             xPP:  Symmetric positive definite packed
48*>             xPB:  Symmetric positive definite banded
49*>             xSY:  Symmetric indefinite, 2-D storage
50*>             xSP:  Symmetric indefinite packed
51*>             xSB:  Symmetric indefinite banded
52*>             xTR:  Triangular
53*>             xTP:  Triangular packed
54*>             xTB:  Triangular banded
55*>             xQR:  General m x n matrix
56*>             xLQ:  General m x n matrix
57*>             xQL:  General m x n matrix
58*>             xRQ:  General m x n matrix
59*>          where the leading character indicates the precision.
60*> \endverbatim
61*>
62*> \param[in] XTYPE
63*> \verbatim
64*>          XTYPE is CHARACTER*1
65*>          Specifies how the exact solution X will be determined:
66*>          = 'N':  New solution; generate a random X.
67*>          = 'C':  Computed; use value of X on entry.
68*> \endverbatim
69*>
70*> \param[in] UPLO
71*> \verbatim
72*>          UPLO is CHARACTER*1
73*>          Specifies whether the upper or lower triangular part of the
74*>          matrix A is stored, if A is symmetric.
75*>          = 'U':  Upper triangular
76*>          = 'L':  Lower triangular
77*> \endverbatim
78*>
79*> \param[in] TRANS
80*> \verbatim
81*>          TRANS is CHARACTER*1
82*>          Used only if A is nonsymmetric; specifies the operation
83*>          applied to the matrix A.
84*>          = 'N':  B := A    * X  (No transpose)
85*>          = 'T':  B := A**T * X  (Transpose)
86*>          = 'C':  B := A**H * X  (Conjugate transpose = Transpose)
87*> \endverbatim
88*>
89*> \param[in] M
90*> \verbatim
91*>          M is INTEGER
92*>          The number or rows of the matrix A.  M >= 0.
93*> \endverbatim
94*>
95*> \param[in] N
96*> \verbatim
97*>          N is INTEGER
98*>          The number of columns of the matrix A.  N >= 0.
99*> \endverbatim
100*>
101*> \param[in] KL
102*> \verbatim
103*>          KL is INTEGER
104*>          Used only if A is a band matrix; specifies the number of
105*>          subdiagonals of A if A is a general band matrix or if A is
106*>          symmetric or triangular and UPLO = 'L'; specifies the number
107*>          of superdiagonals of A if A is symmetric or triangular and
108*>          UPLO = 'U'.  0 <= KL <= M-1.
109*> \endverbatim
110*>
111*> \param[in] KU
112*> \verbatim
113*>          KU is INTEGER
114*>          Used only if A is a general band matrix or if A is
115*>          triangular.
116*>
117*>          If PATH = xGB, specifies the number of superdiagonals of A,
118*>          and 0 <= KU <= N-1.
119*>
120*>          If PATH = xTR, xTP, or xTB, specifies whether or not the
121*>          matrix has unit diagonal:
122*>          = 1:  matrix has non-unit diagonal (default)
123*>          = 2:  matrix has unit diagonal
124*> \endverbatim
125*>
126*> \param[in] NRHS
127*> \verbatim
128*>          NRHS is INTEGER
129*>          The number of right hand side vectors in the system A*X = B.
130*> \endverbatim
131*>
132*> \param[in] A
133*> \verbatim
134*>          A is REAL array, dimension (LDA,N)
135*>          The test matrix whose type is given by PATH.
136*> \endverbatim
137*>
138*> \param[in] LDA
139*> \verbatim
140*>          LDA is INTEGER
141*>          The leading dimension of the array A.
142*>          If PATH = xGB, LDA >= KL+KU+1.
143*>          If PATH = xPB, xSB, xHB, or xTB, LDA >= KL+1.
144*>          Otherwise, LDA >= max(1,M).
145*> \endverbatim
146*>
147*> \param[in,out] X
148*> \verbatim
149*>          X is or output) REAL array, dimension(LDX,NRHS)
150*>          On entry, if XTYPE = 'C' (for 'Computed'), then X contains
151*>          the exact solution to the system of linear equations.
152*>          On exit, if XTYPE = 'N' (for 'New'), then X is initialized
153*>          with random values.
154*> \endverbatim
155*>
156*> \param[in] LDX
157*> \verbatim
158*>          LDX is INTEGER
159*>          The leading dimension of the array X.  If TRANS = 'N',
160*>          LDX >= max(1,N); if TRANS = 'T', LDX >= max(1,M).
161*> \endverbatim
162*>
163*> \param[out] B
164*> \verbatim
165*>          B is REAL array, dimension (LDB,NRHS)
166*>          The right hand side vector(s) for the system of equations,
167*>          computed from B = op(A) * X, where op(A) is determined by
168*>          TRANS.
169*> \endverbatim
170*>
171*> \param[in] LDB
172*> \verbatim
173*>          LDB is INTEGER
174*>          The leading dimension of the array B.  If TRANS = 'N',
175*>          LDB >= max(1,M); if TRANS = 'T', LDB >= max(1,N).
176*> \endverbatim
177*>
178*> \param[in,out] ISEED
179*> \verbatim
180*>          ISEED is INTEGER array, dimension (4)
181*>          The seed vector for the random number generator (used in
182*>          SLATMS).  Modified on exit.
183*> \endverbatim
184*>
185*> \param[out] INFO
186*> \verbatim
187*>          INFO is INTEGER
188*>          = 0: successful exit
189*>          < 0: if INFO = -i, the i-th argument had an illegal value
190*> \endverbatim
191*
192*  Authors:
193*  ========
194*
195*> \author Univ. of Tennessee
196*> \author Univ. of California Berkeley
197*> \author Univ. of Colorado Denver
198*> \author NAG Ltd.
199*
200*> \ingroup single_eig
201*
202*  =====================================================================
203      SUBROUTINE SLARHS( PATH, XTYPE, UPLO, TRANS, M, N, KL, KU, NRHS,
204     $                   A, LDA, X, LDX, B, LDB, ISEED, INFO )
205*
206*  -- LAPACK test routine --
207*  -- LAPACK is a software package provided by Univ. of Tennessee,    --
208*  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
209*
210*     .. Scalar Arguments ..
211      CHARACTER          TRANS, UPLO, XTYPE
212      CHARACTER*3        PATH
213      INTEGER            INFO, KL, KU, LDA, LDB, LDX, M, N, NRHS
214*     ..
215*     .. Array Arguments ..
216      INTEGER            ISEED( 4 )
217      REAL               A( LDA, * ), B( LDB, * ), X( LDX, * )
218*     ..
219*
220*  =====================================================================
221*
222*     .. Parameters ..
223      REAL               ONE, ZERO
224      PARAMETER          ( ONE = 1.0E+0, ZERO = 0.0E+0 )
225*     ..
226*     .. Local Scalars ..
227      LOGICAL            BAND, GEN, NOTRAN, QRS, SYM, TRAN, TRI
228      CHARACTER          C1, DIAG
229      CHARACTER*2        C2
230      INTEGER            J, MB, NX
231*     ..
232*     .. External Functions ..
233      LOGICAL            LSAME, LSAMEN
234      EXTERNAL           LSAME, LSAMEN
235*     ..
236*     .. External Subroutines ..
237      EXTERNAL           SGBMV, SGEMM, SLACPY, SLARNV, SSBMV, SSPMV,
238     $                   SSYMM, STBMV, STPMV, STRMM, XERBLA
239*     ..
240*     .. Intrinsic Functions ..
241      INTRINSIC          MAX
242*     ..
243*     .. Executable Statements ..
244*
245*     Test the input parameters.
246*
247      INFO = 0
248      C1 = PATH( 1: 1 )
249      C2 = PATH( 2: 3 )
250      TRAN = LSAME( TRANS, 'T' ) .OR. LSAME( TRANS, 'C' )
251      NOTRAN = .NOT.TRAN
252      GEN = LSAME( PATH( 2: 2 ), 'G' )
253      QRS = LSAME( PATH( 2: 2 ), 'Q' ) .OR. LSAME( PATH( 3: 3 ), 'Q' )
254      SYM = LSAME( PATH( 2: 2 ), 'P' ) .OR. LSAME( PATH( 2: 2 ), 'S' )
255      TRI = LSAME( PATH( 2: 2 ), 'T' )
256      BAND = LSAME( PATH( 3: 3 ), 'B' )
257      IF( .NOT.LSAME( C1, 'Single precision' ) ) THEN
258         INFO = -1
259      ELSE IF( .NOT.( LSAME( XTYPE, 'N' ) .OR. LSAME( XTYPE, 'C' ) ) )
260     $          THEN
261         INFO = -2
262      ELSE IF( ( SYM .OR. TRI ) .AND. .NOT.
263     $         ( LSAME( UPLO, 'U' ) .OR. LSAME( UPLO, 'L' ) ) ) THEN
264         INFO = -3
265      ELSE IF( ( GEN .OR. QRS ) .AND. .NOT.
266     $         ( TRAN .OR. LSAME( TRANS, 'N' ) ) ) THEN
267         INFO = -4
268      ELSE IF( M.LT.0 ) THEN
269         INFO = -5
270      ELSE IF( N.LT.0 ) THEN
271         INFO = -6
272      ELSE IF( BAND .AND. KL.LT.0 ) THEN
273         INFO = -7
274      ELSE IF( BAND .AND. KU.LT.0 ) THEN
275         INFO = -8
276      ELSE IF( NRHS.LT.0 ) THEN
277         INFO = -9
278      ELSE IF( ( .NOT.BAND .AND. LDA.LT.MAX( 1, M ) ) .OR.
279     $         ( BAND .AND. ( SYM .OR. TRI ) .AND. LDA.LT.KL+1 ) .OR.
280     $         ( BAND .AND. GEN .AND. LDA.LT.KL+KU+1 ) ) THEN
281         INFO = -11
282      ELSE IF( ( NOTRAN .AND. LDX.LT.MAX( 1, N ) ) .OR.
283     $         ( TRAN .AND. LDX.LT.MAX( 1, M ) ) ) THEN
284         INFO = -13
285      ELSE IF( ( NOTRAN .AND. LDB.LT.MAX( 1, M ) ) .OR.
286     $         ( TRAN .AND. LDB.LT.MAX( 1, N ) ) ) THEN
287         INFO = -15
288      END IF
289      IF( INFO.NE.0 ) THEN
290         CALL XERBLA( 'SLARHS', -INFO )
291         RETURN
292      END IF
293*
294*     Initialize X to NRHS random vectors unless XTYPE = 'C'.
295*
296      IF( TRAN ) THEN
297         NX = M
298         MB = N
299      ELSE
300         NX = N
301         MB = M
302      END IF
303      IF( .NOT.LSAME( XTYPE, 'C' ) ) THEN
304         DO 10 J = 1, NRHS
305            CALL SLARNV( 2, ISEED, N, X( 1, J ) )
306   10    CONTINUE
307      END IF
308*
309*     Multiply X by op(A) using an appropriate
310*     matrix multiply routine.
311*
312      IF( LSAMEN( 2, C2, 'GE' ) .OR. LSAMEN( 2, C2, 'QR' ) .OR.
313     $    LSAMEN( 2, C2, 'LQ' ) .OR. LSAMEN( 2, C2, 'QL' ) .OR.
314     $    LSAMEN( 2, C2, 'RQ' ) ) THEN
315*
316*        General matrix
317*
318         CALL SGEMM( TRANS, 'N', MB, NRHS, NX, ONE, A, LDA, X, LDX,
319     $               ZERO, B, LDB )
320*
321      ELSE IF( LSAMEN( 2, C2, 'PO' ) .OR. LSAMEN( 2, C2, 'SY' ) ) THEN
322*
323*        Symmetric matrix, 2-D storage
324*
325         CALL SSYMM( 'Left', UPLO, N, NRHS, ONE, A, LDA, X, LDX, ZERO,
326     $               B, LDB )
327*
328      ELSE IF( LSAMEN( 2, C2, 'GB' ) ) THEN
329*
330*        General matrix, band storage
331*
332         DO 20 J = 1, NRHS
333            CALL SGBMV( TRANS, MB, NX, KL, KU, ONE, A, LDA, X( 1, J ),
334     $                  1, ZERO, B( 1, J ), 1 )
335   20    CONTINUE
336*
337      ELSE IF( LSAMEN( 2, C2, 'PB' ) ) THEN
338*
339*        Symmetric matrix, band storage
340*
341         DO 30 J = 1, NRHS
342            CALL SSBMV( UPLO, N, KL, ONE, A, LDA, X( 1, J ), 1, ZERO,
343     $                  B( 1, J ), 1 )
344   30    CONTINUE
345*
346      ELSE IF( LSAMEN( 2, C2, 'PP' ) .OR. LSAMEN( 2, C2, 'SP' ) ) THEN
347*
348*        Symmetric matrix, packed storage
349*
350         DO 40 J = 1, NRHS
351            CALL SSPMV( UPLO, N, ONE, A, X( 1, J ), 1, ZERO, B( 1, J ),
352     $                  1 )
353   40    CONTINUE
354*
355      ELSE IF( LSAMEN( 2, C2, 'TR' ) ) THEN
356*
357*        Triangular matrix.  Note that for triangular matrices,
358*           KU = 1 => non-unit triangular
359*           KU = 2 => unit triangular
360*
361         CALL SLACPY( 'Full', N, NRHS, X, LDX, B, LDB )
362         IF( KU.EQ.2 ) THEN
363            DIAG = 'U'
364         ELSE
365            DIAG = 'N'
366         END IF
367         CALL STRMM( 'Left', UPLO, TRANS, DIAG, N, NRHS, ONE, A, LDA, B,
368     $               LDB )
369*
370      ELSE IF( LSAMEN( 2, C2, 'TP' ) ) THEN
371*
372*        Triangular matrix, packed storage
373*
374         CALL SLACPY( 'Full', N, NRHS, X, LDX, B, LDB )
375         IF( KU.EQ.2 ) THEN
376            DIAG = 'U'
377         ELSE
378            DIAG = 'N'
379         END IF
380         DO 50 J = 1, NRHS
381            CALL STPMV( UPLO, TRANS, DIAG, N, A, B( 1, J ), 1 )
382   50    CONTINUE
383*
384      ELSE IF( LSAMEN( 2, C2, 'TB' ) ) THEN
385*
386*        Triangular matrix, banded storage
387*
388         CALL SLACPY( 'Full', N, NRHS, X, LDX, B, LDB )
389         IF( KU.EQ.2 ) THEN
390            DIAG = 'U'
391         ELSE
392            DIAG = 'N'
393         END IF
394         DO 60 J = 1, NRHS
395            CALL STBMV( UPLO, TRANS, DIAG, N, KL, A, LDA, B( 1, J ), 1 )
396   60    CONTINUE
397*
398      ELSE
399*
400*        If PATH is none of the above, return with an error code.
401*
402         INFO = -1
403         CALL XERBLA( 'SLARHS', -INFO )
404      END IF
405*
406      RETURN
407*
408*     End of SLARHS
409*
410      END
411