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