001:       SUBROUTINE DORMR3( SIDE, TRANS, M, N, K, L, A, LDA, TAU, C, LDC,
002:      $                   WORK, INFO )
003: *
004: *  -- LAPACK routine (version 3.2) --
005: *     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
006: *     November 2006
007: *
008: *     .. Scalar Arguments ..
009:       CHARACTER          SIDE, TRANS
010:       INTEGER            INFO, K, L, LDA, LDC, M, N
011: *     ..
012: *     .. Array Arguments ..
013:       DOUBLE PRECISION   A( LDA, * ), C( LDC, * ), TAU( * ), WORK( * )
014: *     ..
015: *
016: *  Purpose
017: *  =======
018: *
019: *  DORMR3 overwrites the general real m by n matrix C with
020: *
021: *        Q * C  if SIDE = 'L' and TRANS = 'N', or
022: *
023: *        Q'* C  if SIDE = 'L' and TRANS = 'T', or
024: *
025: *        C * Q  if SIDE = 'R' and TRANS = 'N', or
026: *
027: *        C * Q' if SIDE = 'R' and TRANS = 'T',
028: *
029: *  where Q is a real orthogonal matrix defined as the product of k
030: *  elementary reflectors
031: *
032: *        Q = H(1) H(2) . . . H(k)
033: *
034: *  as returned by DTZRZF. Q is of order m if SIDE = 'L' and of order n
035: *  if SIDE = 'R'.
036: *
037: *  Arguments
038: *  =========
039: *
040: *  SIDE    (input) CHARACTER*1
041: *          = 'L': apply Q or Q' from the Left
042: *          = 'R': apply Q or Q' from the Right
043: *
044: *  TRANS   (input) CHARACTER*1
045: *          = 'N': apply Q  (No transpose)
046: *          = 'T': apply Q' (Transpose)
047: *
048: *  M       (input) INTEGER
049: *          The number of rows of the matrix C. M >= 0.
050: *
051: *  N       (input) INTEGER
052: *          The number of columns of the matrix C. N >= 0.
053: *
054: *  K       (input) INTEGER
055: *          The number of elementary reflectors whose product defines
056: *          the matrix Q.
057: *          If SIDE = 'L', M >= K >= 0;
058: *          if SIDE = 'R', N >= K >= 0.
059: *
060: *  L       (input) INTEGER
061: *          The number of columns of the matrix A containing
062: *          the meaningful part of the Householder reflectors.
063: *          If SIDE = 'L', M >= L >= 0, if SIDE = 'R', N >= L >= 0.
064: *
065: *  A       (input) DOUBLE PRECISION array, dimension
066: *                               (LDA,M) if SIDE = 'L',
067: *                               (LDA,N) if SIDE = 'R'
068: *          The i-th row must contain the vector which defines the
069: *          elementary reflector H(i), for i = 1,2,...,k, as returned by
070: *          DTZRZF in the last k rows of its array argument A.
071: *          A is modified by the routine but restored on exit.
072: *
073: *  LDA     (input) INTEGER
074: *          The leading dimension of the array A. LDA >= max(1,K).
075: *
076: *  TAU     (input) DOUBLE PRECISION array, dimension (K)
077: *          TAU(i) must contain the scalar factor of the elementary
078: *          reflector H(i), as returned by DTZRZF.
079: *
080: *  C       (input/output) DOUBLE PRECISION array, dimension (LDC,N)
081: *          On entry, the m-by-n matrix C.
082: *          On exit, C is overwritten by Q*C or Q'*C or C*Q' or C*Q.
083: *
084: *  LDC     (input) INTEGER
085: *          The leading dimension of the array C. LDC >= max(1,M).
086: *
087: *  WORK    (workspace) DOUBLE PRECISION array, dimension
088: *                                   (N) if SIDE = 'L',
089: *                                   (M) if SIDE = 'R'
090: *
091: *  INFO    (output) INTEGER
092: *          = 0: successful exit
093: *          < 0: if INFO = -i, the i-th argument had an illegal value
094: *
095: *  Further Details
096: *  ===============
097: *
098: *  Based on contributions by
099: *    A. Petitet, Computer Science Dept., Univ. of Tenn., Knoxville, USA
100: *
101: *  =====================================================================
102: *
103: *     .. Local Scalars ..
104:       LOGICAL            LEFT, NOTRAN
105:       INTEGER            I, I1, I2, I3, IC, JA, JC, MI, NI, NQ
106: *     ..
107: *     .. External Functions ..
108:       LOGICAL            LSAME
109:       EXTERNAL           LSAME
110: *     ..
111: *     .. External Subroutines ..
112:       EXTERNAL           DLARZ, XERBLA
113: *     ..
114: *     .. Intrinsic Functions ..
115:       INTRINSIC          MAX
116: *     ..
117: *     .. Executable Statements ..
118: *
119: *     Test the input arguments
120: *
121:       INFO = 0
122:       LEFT = LSAME( SIDE, 'L' )
123:       NOTRAN = LSAME( TRANS, 'N' )
124: *
125: *     NQ is the order of Q
126: *
127:       IF( LEFT ) THEN
128:          NQ = M
129:       ELSE
130:          NQ = N
131:       END IF
132:       IF( .NOT.LEFT .AND. .NOT.LSAME( SIDE, 'R' ) ) THEN
133:          INFO = -1
134:       ELSE IF( .NOT.NOTRAN .AND. .NOT.LSAME( TRANS, 'T' ) ) THEN
135:          INFO = -2
136:       ELSE IF( M.LT.0 ) THEN
137:          INFO = -3
138:       ELSE IF( N.LT.0 ) THEN
139:          INFO = -4
140:       ELSE IF( K.LT.0 .OR. K.GT.NQ ) THEN
141:          INFO = -5
142:       ELSE IF( L.LT.0 .OR. ( LEFT .AND. ( L.GT.M ) ) .OR.
143:      $         ( .NOT.LEFT .AND. ( L.GT.N ) ) ) THEN
144:          INFO = -6
145:       ELSE IF( LDA.LT.MAX( 1, K ) ) THEN
146:          INFO = -8
147:       ELSE IF( LDC.LT.MAX( 1, M ) ) THEN
148:          INFO = -11
149:       END IF
150:       IF( INFO.NE.0 ) THEN
151:          CALL XERBLA( 'DORMR3', -INFO )
152:          RETURN
153:       END IF
154: *
155: *     Quick return if possible
156: *
157:       IF( M.EQ.0 .OR. N.EQ.0 .OR. K.EQ.0 )
158:      $   RETURN
159: *
160:       IF( ( LEFT .AND. .NOT.NOTRAN .OR. .NOT.LEFT .AND. NOTRAN ) ) THEN
161:          I1 = 1
162:          I2 = K
163:          I3 = 1
164:       ELSE
165:          I1 = K
166:          I2 = 1
167:          I3 = -1
168:       END IF
169: *
170:       IF( LEFT ) THEN
171:          NI = N
172:          JA = M - L + 1
173:          JC = 1
174:       ELSE
175:          MI = M
176:          JA = N - L + 1
177:          IC = 1
178:       END IF
179: *
180:       DO 10 I = I1, I2, I3
181:          IF( LEFT ) THEN
182: *
183: *           H(i) or H(i)' is applied to C(i:m,1:n)
184: *
185:             MI = M - I + 1
186:             IC = I
187:          ELSE
188: *
189: *           H(i) or H(i)' is applied to C(1:m,i:n)
190: *
191:             NI = N - I + 1
192:             JC = I
193:          END IF
194: *
195: *        Apply H(i) or H(i)'
196: *
197:          CALL DLARZ( SIDE, MI, NI, L, A( I, JA ), LDA, TAU( I ),
198:      $               C( IC, JC ), LDC, WORK )
199: *
200:    10 CONTINUE
201: *
202:       RETURN
203: *
204: *     End of DORMR3
205: *
206:       END
207: