```001:       SUBROUTINE DORMBR( VECT, SIDE, TRANS, M, N, K, A, LDA, TAU, C,
002:      \$                   LDC, WORK, LWORK, 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, VECT
010:       INTEGER            INFO, K, LDA, LDC, LWORK, M, N
011: *     ..
012: *     .. Array Arguments ..
013:       DOUBLE PRECISION   A( LDA, * ), C( LDC, * ), TAU( * ), WORK( * )
014: *     ..
015: *
016: *  Purpose
017: *  =======
018: *
019: *  If VECT = 'Q', DORMBR overwrites the general real M-by-N matrix C
020: *  with
021: *                  SIDE = 'L'     SIDE = 'R'
022: *  TRANS = 'N':      Q * C          C * Q
023: *  TRANS = 'T':      Q**T * C       C * Q**T
024: *
025: *  If VECT = 'P', DORMBR overwrites the general real M-by-N matrix C
026: *  with
027: *                  SIDE = 'L'     SIDE = 'R'
028: *  TRANS = 'N':      P * C          C * P
029: *  TRANS = 'T':      P**T * C       C * P**T
030: *
031: *  Here Q and P**T are the orthogonal matrices determined by DGEBRD when
032: *  reducing a real matrix A to bidiagonal form: A = Q * B * P**T. Q and
033: *  P**T are defined as products of elementary reflectors H(i) and G(i)
034: *  respectively.
035: *
036: *  Let nq = m if SIDE = 'L' and nq = n if SIDE = 'R'. Thus nq is the
037: *  order of the orthogonal matrix Q or P**T that is applied.
038: *
039: *  If VECT = 'Q', A is assumed to have been an NQ-by-K matrix:
040: *  if nq >= k, Q = H(1) H(2) . . . H(k);
041: *  if nq < k, Q = H(1) H(2) . . . H(nq-1).
042: *
043: *  If VECT = 'P', A is assumed to have been a K-by-NQ matrix:
044: *  if k < nq, P = G(1) G(2) . . . G(k);
045: *  if k >= nq, P = G(1) G(2) . . . G(nq-1).
046: *
047: *  Arguments
048: *  =========
049: *
050: *  VECT    (input) CHARACTER*1
051: *          = 'Q': apply Q or Q**T;
052: *          = 'P': apply P or P**T.
053: *
054: *  SIDE    (input) CHARACTER*1
055: *          = 'L': apply Q, Q**T, P or P**T from the Left;
056: *          = 'R': apply Q, Q**T, P or P**T from the Right.
057: *
058: *  TRANS   (input) CHARACTER*1
059: *          = 'N':  No transpose, apply Q  or P;
060: *          = 'T':  Transpose, apply Q**T or P**T.
061: *
062: *  M       (input) INTEGER
063: *          The number of rows of the matrix C. M >= 0.
064: *
065: *  N       (input) INTEGER
066: *          The number of columns of the matrix C. N >= 0.
067: *
068: *  K       (input) INTEGER
069: *          If VECT = 'Q', the number of columns in the original
070: *          matrix reduced by DGEBRD.
071: *          If VECT = 'P', the number of rows in the original
072: *          matrix reduced by DGEBRD.
073: *          K >= 0.
074: *
075: *  A       (input) DOUBLE PRECISION array, dimension
076: *                                (LDA,min(nq,K)) if VECT = 'Q'
077: *                                (LDA,nq)        if VECT = 'P'
078: *          The vectors which define the elementary reflectors H(i) and
079: *          G(i), whose products determine the matrices Q and P, as
080: *          returned by DGEBRD.
081: *
082: *  LDA     (input) INTEGER
083: *          The leading dimension of the array A.
084: *          If VECT = 'Q', LDA >= max(1,nq);
085: *          if VECT = 'P', LDA >= max(1,min(nq,K)).
086: *
087: *  TAU     (input) DOUBLE PRECISION array, dimension (min(nq,K))
088: *          TAU(i) must contain the scalar factor of the elementary
089: *          reflector H(i) or G(i) which determines Q or P, as returned
090: *          by DGEBRD in the array argument TAUQ or TAUP.
091: *
092: *  C       (input/output) DOUBLE PRECISION array, dimension (LDC,N)
093: *          On entry, the M-by-N matrix C.
094: *          On exit, C is overwritten by Q*C or Q**T*C or C*Q**T or C*Q
095: *          or P*C or P**T*C or C*P or C*P**T.
096: *
097: *  LDC     (input) INTEGER
098: *          The leading dimension of the array C. LDC >= max(1,M).
099: *
100: *  WORK    (workspace/output) DOUBLE PRECISION array, dimension (MAX(1,LWORK))
101: *          On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
102: *
103: *  LWORK   (input) INTEGER
104: *          The dimension of the array WORK.
105: *          If SIDE = 'L', LWORK >= max(1,N);
106: *          if SIDE = 'R', LWORK >= max(1,M).
107: *          For optimum performance LWORK >= N*NB if SIDE = 'L', and
108: *          LWORK >= M*NB if SIDE = 'R', where NB is the optimal
109: *          blocksize.
110: *
111: *          If LWORK = -1, then a workspace query is assumed; the routine
112: *          only calculates the optimal size of the WORK array, returns
113: *          this value as the first entry of the WORK array, and no error
114: *          message related to LWORK is issued by XERBLA.
115: *
116: *  INFO    (output) INTEGER
117: *          = 0:  successful exit
118: *          < 0:  if INFO = -i, the i-th argument had an illegal value
119: *
120: *  =====================================================================
121: *
122: *     .. Local Scalars ..
123:       LOGICAL            APPLYQ, LEFT, LQUERY, NOTRAN
124:       CHARACTER          TRANST
125:       INTEGER            I1, I2, IINFO, LWKOPT, MI, NB, NI, NQ, NW
126: *     ..
127: *     .. External Functions ..
128:       LOGICAL            LSAME
129:       INTEGER            ILAENV
130:       EXTERNAL           LSAME, ILAENV
131: *     ..
132: *     .. External Subroutines ..
133:       EXTERNAL           DORMLQ, DORMQR, XERBLA
134: *     ..
135: *     .. Intrinsic Functions ..
136:       INTRINSIC          MAX, MIN
137: *     ..
138: *     .. Executable Statements ..
139: *
140: *     Test the input arguments
141: *
142:       INFO = 0
143:       APPLYQ = LSAME( VECT, 'Q' )
144:       LEFT = LSAME( SIDE, 'L' )
145:       NOTRAN = LSAME( TRANS, 'N' )
146:       LQUERY = ( LWORK.EQ.-1 )
147: *
148: *     NQ is the order of Q or P and NW is the minimum dimension of WORK
149: *
150:       IF( LEFT ) THEN
151:          NQ = M
152:          NW = N
153:       ELSE
154:          NQ = N
155:          NW = M
156:       END IF
157:       IF( .NOT.APPLYQ .AND. .NOT.LSAME( VECT, 'P' ) ) THEN
158:          INFO = -1
159:       ELSE IF( .NOT.LEFT .AND. .NOT.LSAME( SIDE, 'R' ) ) THEN
160:          INFO = -2
161:       ELSE IF( .NOT.NOTRAN .AND. .NOT.LSAME( TRANS, 'T' ) ) THEN
162:          INFO = -3
163:       ELSE IF( M.LT.0 ) THEN
164:          INFO = -4
165:       ELSE IF( N.LT.0 ) THEN
166:          INFO = -5
167:       ELSE IF( K.LT.0 ) THEN
168:          INFO = -6
169:       ELSE IF( ( APPLYQ .AND. LDA.LT.MAX( 1, NQ ) ) .OR.
170:      \$         ( .NOT.APPLYQ .AND. LDA.LT.MAX( 1, MIN( NQ, K ) ) ) )
171:      \$          THEN
172:          INFO = -8
173:       ELSE IF( LDC.LT.MAX( 1, M ) ) THEN
174:          INFO = -11
175:       ELSE IF( LWORK.LT.MAX( 1, NW ) .AND. .NOT.LQUERY ) THEN
176:          INFO = -13
177:       END IF
178: *
179:       IF( INFO.EQ.0 ) THEN
180:          IF( APPLYQ ) THEN
181:             IF( LEFT ) THEN
182:                NB = ILAENV( 1, 'DORMQR', SIDE // TRANS, M-1, N, M-1,
183:      \$              -1 )
184:             ELSE
185:                NB = ILAENV( 1, 'DORMQR', SIDE // TRANS, M, N-1, N-1,
186:      \$              -1 )
187:             END IF
188:          ELSE
189:             IF( LEFT ) THEN
190:                NB = ILAENV( 1, 'DORMLQ', SIDE // TRANS, M-1, N, M-1,
191:      \$              -1 )
192:             ELSE
193:                NB = ILAENV( 1, 'DORMLQ', SIDE // TRANS, M, N-1, N-1,
194:      \$              -1 )
195:             END IF
196:          END IF
197:          LWKOPT = MAX( 1, NW )*NB
198:          WORK( 1 ) = LWKOPT
199:       END IF
200: *
201:       IF( INFO.NE.0 ) THEN
202:          CALL XERBLA( 'DORMBR', -INFO )
203:          RETURN
204:       ELSE IF( LQUERY ) THEN
205:          RETURN
206:       END IF
207: *
208: *     Quick return if possible
209: *
210:       WORK( 1 ) = 1
211:       IF( M.EQ.0 .OR. N.EQ.0 )
212:      \$   RETURN
213: *
214:       IF( APPLYQ ) THEN
215: *
216: *        Apply Q
217: *
218:          IF( NQ.GE.K ) THEN
219: *
220: *           Q was determined by a call to DGEBRD with nq >= k
221: *
222:             CALL DORMQR( SIDE, TRANS, M, N, K, A, LDA, TAU, C, LDC,
223:      \$                   WORK, LWORK, IINFO )
224:          ELSE IF( NQ.GT.1 ) THEN
225: *
226: *           Q was determined by a call to DGEBRD with nq < k
227: *
228:             IF( LEFT ) THEN
229:                MI = M - 1
230:                NI = N
231:                I1 = 2
232:                I2 = 1
233:             ELSE
234:                MI = M
235:                NI = N - 1
236:                I1 = 1
237:                I2 = 2
238:             END IF
239:             CALL DORMQR( SIDE, TRANS, MI, NI, NQ-1, A( 2, 1 ), LDA, TAU,
240:      \$                   C( I1, I2 ), LDC, WORK, LWORK, IINFO )
241:          END IF
242:       ELSE
243: *
244: *        Apply P
245: *
246:          IF( NOTRAN ) THEN
247:             TRANST = 'T'
248:          ELSE
249:             TRANST = 'N'
250:          END IF
251:          IF( NQ.GT.K ) THEN
252: *
253: *           P was determined by a call to DGEBRD with nq > k
254: *
255:             CALL DORMLQ( SIDE, TRANST, M, N, K, A, LDA, TAU, C, LDC,
256:      \$                   WORK, LWORK, IINFO )
257:          ELSE IF( NQ.GT.1 ) THEN
258: *
259: *           P was determined by a call to DGEBRD with nq <= k
260: *
261:             IF( LEFT ) THEN
262:                MI = M - 1
263:                NI = N
264:                I1 = 2
265:                I2 = 1
266:             ELSE
267:                MI = M
268:                NI = N - 1
269:                I1 = 1
270:                I2 = 2
271:             END IF
272:             CALL DORMLQ( SIDE, TRANST, MI, NI, NQ-1, A( 1, 2 ), LDA,
273:      \$                   TAU, C( I1, I2 ), LDC, WORK, LWORK, IINFO )
274:          END IF
275:       END IF
276:       WORK( 1 ) = LWKOPT
277:       RETURN
278: *
279: *     End of DORMBR
280: *
281:       END
282: ```