1*> \brief \b SORMTR
2*
3*  =========== DOCUMENTATION ===========
4*
5* Online html documentation available at
6*            http://www.netlib.org/lapack/explore-html/
7*
8*> \htmlonly
9*> Download SORMTR + dependencies
10*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/sormtr.f">
11*> [TGZ]</a>
12*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/sormtr.f">
13*> [ZIP]</a>
14*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/sormtr.f">
15*> [TXT]</a>
16*> \endhtmlonly
17*
18*  Definition:
19*  ===========
20*
21*       SUBROUTINE SORMTR( SIDE, UPLO, TRANS, M, N, A, LDA, TAU, C, LDC,
22*                          WORK, LWORK, INFO )
23*
24*       .. Scalar Arguments ..
25*       CHARACTER          SIDE, TRANS, UPLO
26*       INTEGER            INFO, LDA, LDC, LWORK, M, N
27*       ..
28*       .. Array Arguments ..
29*       REAL               A( LDA, * ), C( LDC, * ), TAU( * ),
30*      $                   WORK( * )
31*       ..
32*
33*
34*> \par Purpose:
35*  =============
36*>
37*> \verbatim
38*>
39*> SORMTR overwrites the general real M-by-N matrix C with
40*>
41*>                 SIDE = 'L'     SIDE = 'R'
42*> TRANS = 'N':      Q * C          C * Q
43*> TRANS = 'T':      Q**T * C       C * Q**T
44*>
45*> where Q is a real orthogonal matrix of order nq, with nq = m if
46*> SIDE = 'L' and nq = n if SIDE = 'R'. Q is defined as the product of
47*> nq-1 elementary reflectors, as returned by SSYTRD:
48*>
49*> if UPLO = 'U', Q = H(nq-1) . . . H(2) H(1);
50*>
51*> if UPLO = 'L', Q = H(1) H(2) . . . H(nq-1).
52*> \endverbatim
53*
54*  Arguments:
55*  ==========
56*
57*> \param[in] SIDE
58*> \verbatim
59*>          SIDE is CHARACTER*1
60*>          = 'L': apply Q or Q**T from the Left;
61*>          = 'R': apply Q or Q**T from the Right.
62*> \endverbatim
63*>
64*> \param[in] UPLO
65*> \verbatim
66*>          UPLO is CHARACTER*1
67*>          = 'U': Upper triangle of A contains elementary reflectors
68*>                 from SSYTRD;
69*>          = 'L': Lower triangle of A contains elementary reflectors
70*>                 from SSYTRD.
71*> \endverbatim
72*>
73*> \param[in] TRANS
74*> \verbatim
75*>          TRANS is CHARACTER*1
76*>          = 'N':  No transpose, apply Q;
77*>          = 'T':  Transpose, apply Q**T.
78*> \endverbatim
79*>
80*> \param[in] M
81*> \verbatim
82*>          M is INTEGER
83*>          The number of rows of the matrix C. M >= 0.
84*> \endverbatim
85*>
86*> \param[in] N
87*> \verbatim
88*>          N is INTEGER
89*>          The number of columns of the matrix C. N >= 0.
90*> \endverbatim
91*>
92*> \param[in] A
93*> \verbatim
94*>          A is REAL array, dimension
95*>                               (LDA,M) if SIDE = 'L'
96*>                               (LDA,N) if SIDE = 'R'
97*>          The vectors which define the elementary reflectors, as
98*>          returned by SSYTRD.
99*> \endverbatim
100*>
101*> \param[in] LDA
102*> \verbatim
103*>          LDA is INTEGER
104*>          The leading dimension of the array A.
105*>          LDA >= max(1,M) if SIDE = 'L'; LDA >= max(1,N) if SIDE = 'R'.
106*> \endverbatim
107*>
108*> \param[in] TAU
109*> \verbatim
110*>          TAU is REAL array, dimension
111*>                               (M-1) if SIDE = 'L'
112*>                               (N-1) if SIDE = 'R'
113*>          TAU(i) must contain the scalar factor of the elementary
114*>          reflector H(i), as returned by SSYTRD.
115*> \endverbatim
116*>
117*> \param[in,out] C
118*> \verbatim
119*>          C is REAL array, dimension (LDC,N)
120*>          On entry, the M-by-N matrix C.
121*>          On exit, C is overwritten by Q*C or Q**T*C or C*Q**T or C*Q.
122*> \endverbatim
123*>
124*> \param[in] LDC
125*> \verbatim
126*>          LDC is INTEGER
127*>          The leading dimension of the array C. LDC >= max(1,M).
128*> \endverbatim
129*>
130*> \param[out] WORK
131*> \verbatim
132*>          WORK is REAL array, dimension (MAX(1,LWORK))
133*>          On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
134*> \endverbatim
135*>
136*> \param[in] LWORK
137*> \verbatim
138*>          LWORK is INTEGER
139*>          The dimension of the array WORK.
140*>          If SIDE = 'L', LWORK >= max(1,N);
141*>          if SIDE = 'R', LWORK >= max(1,M).
142*>          For optimum performance LWORK >= N*NB if SIDE = 'L', and
143*>          LWORK >= M*NB if SIDE = 'R', where NB is the optimal
144*>          blocksize.
145*>
146*>          If LWORK = -1, then a workspace query is assumed; the routine
147*>          only calculates the optimal size of the WORK array, returns
148*>          this value as the first entry of the WORK array, and no error
149*>          message related to LWORK is issued by XERBLA.
150*> \endverbatim
151*>
152*> \param[out] INFO
153*> \verbatim
154*>          INFO is INTEGER
155*>          = 0:  successful exit
156*>          < 0:  if INFO = -i, the i-th argument had an illegal value
157*> \endverbatim
158*
159*  Authors:
160*  ========
161*
162*> \author Univ. of Tennessee
163*> \author Univ. of California Berkeley
164*> \author Univ. of Colorado Denver
165*> \author NAG Ltd.
166*
167*> \ingroup realOTHERcomputational
168*
169*  =====================================================================
170      SUBROUTINE SORMTR( SIDE, UPLO, TRANS, M, N, A, LDA, TAU, C, LDC,
171     $                   WORK, LWORK, INFO )
172*
173*  -- LAPACK computational routine --
174*  -- LAPACK is a software package provided by Univ. of Tennessee,    --
175*  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
176*
177*     .. Scalar Arguments ..
178      CHARACTER          SIDE, TRANS, UPLO
179      INTEGER            INFO, LDA, LDC, LWORK, M, N
180*     ..
181*     .. Array Arguments ..
182      REAL               A( LDA, * ), C( LDC, * ), TAU( * ),
183     $                   WORK( * )
184*     ..
185*
186*  =====================================================================
187*
188*     .. Local Scalars ..
189      LOGICAL            LEFT, LQUERY, UPPER
190      INTEGER            I1, I2, IINFO, LWKOPT, MI, NI, NB, NQ, NW
191*     ..
192*     .. External Functions ..
193      LOGICAL            LSAME
194      INTEGER            ILAENV
195      EXTERNAL           ILAENV, LSAME
196*     ..
197*     .. External Subroutines ..
198      EXTERNAL           SORMQL, SORMQR, XERBLA
199*     ..
200*     .. Intrinsic Functions ..
201      INTRINSIC          MAX
202*     ..
203*     .. Executable Statements ..
204*
205*     Test the input arguments
206*
207      INFO = 0
208      LEFT = LSAME( SIDE, 'L' )
209      UPPER = LSAME( UPLO, 'U' )
210      LQUERY = ( LWORK.EQ.-1 )
211*
212*     NQ is the order of Q and NW is the minimum dimension of WORK
213*
214      IF( LEFT ) THEN
215         NQ = M
216         NW = MAX( 1, N )
217      ELSE
218         NQ = N
219         NW = MAX( 1, M )
220      END IF
221      IF( .NOT.LEFT .AND. .NOT.LSAME( SIDE, 'R' ) ) THEN
222         INFO = -1
223      ELSE IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN
224         INFO = -2
225      ELSE IF( .NOT.LSAME( TRANS, 'N' ) .AND. .NOT.LSAME( TRANS, 'T' ) )
226     $          THEN
227         INFO = -3
228      ELSE IF( M.LT.0 ) THEN
229         INFO = -4
230      ELSE IF( N.LT.0 ) THEN
231         INFO = -5
232      ELSE IF( LDA.LT.MAX( 1, NQ ) ) THEN
233         INFO = -7
234      ELSE IF( LDC.LT.MAX( 1, M ) ) THEN
235         INFO = -10
236      ELSE IF( LWORK.LT.NW .AND. .NOT.LQUERY ) THEN
237         INFO = -12
238      END IF
239*
240      IF( INFO.EQ.0 ) THEN
241         IF( UPPER ) THEN
242            IF( LEFT ) THEN
243               NB = ILAENV( 1, 'SORMQL', SIDE // TRANS, M-1, N, M-1,
244     $                      -1 )
245            ELSE
246               NB = ILAENV( 1, 'SORMQL', SIDE // TRANS, M, N-1, N-1,
247     $                      -1 )
248            END IF
249         ELSE
250            IF( LEFT ) THEN
251               NB = ILAENV( 1, 'SORMQR', SIDE // TRANS, M-1, N, M-1,
252     $                      -1 )
253            ELSE
254               NB = ILAENV( 1, 'SORMQR', SIDE // TRANS, M, N-1, N-1,
255     $                      -1 )
256            END IF
257         END IF
258         LWKOPT = NW*NB
259         WORK( 1 ) = LWKOPT
260      END IF
261*
262      IF( INFO.NE.0 ) THEN
263         CALL XERBLA( 'SORMTR', -INFO )
264         RETURN
265      ELSE IF( LQUERY ) THEN
266         RETURN
267      END IF
268*
269*     Quick return if possible
270*
271      IF( M.EQ.0 .OR. N.EQ.0 .OR. NQ.EQ.1 ) THEN
272         WORK( 1 ) = 1
273         RETURN
274      END IF
275*
276      IF( LEFT ) THEN
277         MI = M - 1
278         NI = N
279      ELSE
280         MI = M
281         NI = N - 1
282      END IF
283*
284      IF( UPPER ) THEN
285*
286*        Q was determined by a call to SSYTRD with UPLO = 'U'
287*
288         CALL SORMQL( SIDE, TRANS, MI, NI, NQ-1, A( 1, 2 ), LDA, TAU, C,
289     $                LDC, WORK, LWORK, IINFO )
290      ELSE
291*
292*        Q was determined by a call to SSYTRD with UPLO = 'L'
293*
294         IF( LEFT ) THEN
295            I1 = 2
296            I2 = 1
297         ELSE
298            I1 = 1
299            I2 = 2
300         END IF
301         CALL SORMQR( SIDE, TRANS, MI, NI, NQ-1, A( 2, 1 ), LDA, TAU,
302     $                C( I1, I2 ), LDC, WORK, LWORK, IINFO )
303      END IF
304      WORK( 1 ) = LWKOPT
305      RETURN
306*
307*     End of SORMTR
308*
309      END
310