3 * =========== DOCUMENTATION ===========
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
9 *> Download CUNGLQ + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/cunglq.f">
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/cunglq.f">
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/cunglq.f">
21 * SUBROUTINE CUNGLQ( M, N, K, A, LDA, TAU, WORK, LWORK, INFO )
23 * .. Scalar Arguments ..
24 * INTEGER INFO, K, LDA, LWORK, M, N
26 * .. Array Arguments ..
27 * COMPLEX A( LDA, * ), TAU( * ), WORK( * )
36 *> CUNGLQ generates an M-by-N complex matrix Q with orthonormal rows,
37 *> which is defined as the first M rows of a product of K elementary
38 *> reflectors of order N
40 *> Q = H(k)**H . . . H(2)**H H(1)**H
42 *> as returned by CGELQF.
51 *> The number of rows of the matrix Q. M >= 0.
57 *> The number of columns of the matrix Q. N >= M.
63 *> The number of elementary reflectors whose product defines the
64 *> matrix Q. M >= K >= 0.
69 *> A is COMPLEX array, dimension (LDA,N)
70 *> On entry, the i-th row must contain the vector which defines
71 *> the elementary reflector H(i), for i = 1,2,...,k, as returned
72 *> by CGELQF in the first k rows of its array argument A.
73 *> On exit, the M-by-N matrix Q.
79 *> The first dimension of the array A. LDA >= max(1,M).
84 *> TAU is COMPLEX array, dimension (K)
85 *> TAU(i) must contain the scalar factor of the elementary
86 *> reflector H(i), as returned by CGELQF.
91 *> WORK is COMPLEX array, dimension (MAX(1,LWORK))
92 *> On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
98 *> The dimension of the array WORK. LWORK >= max(1,M).
99 *> For optimum performance LWORK >= M*NB, where NB is
100 *> the optimal blocksize.
102 *> If LWORK = -1, then a workspace query is assumed; the routine
103 *> only calculates the optimal size of the WORK array, returns
104 *> this value as the first entry of the WORK array, and no error
105 *> message related to LWORK is issued by XERBLA.
111 *> = 0: successful exit;
112 *> < 0: if INFO = -i, the i-th argument has an illegal value
118 *> \author Univ. of Tennessee
119 *> \author Univ. of California Berkeley
120 *> \author Univ. of Colorado Denver
123 *> \date November 2011
125 *> \ingroup complexOTHERcomputational
127 * =====================================================================
128 SUBROUTINE CUNGLQ( M, N, K, A, LDA, TAU, WORK, LWORK, INFO )
130 * -- LAPACK computational routine (version 3.4.0) --
131 * -- LAPACK is a software package provided by Univ. of Tennessee, --
132 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
135 * .. Scalar Arguments ..
136 INTEGER INFO, K, LDA, LWORK, M, N
138 * .. Array Arguments ..
139 COMPLEX A( LDA, * ), TAU( * ), WORK( * )
142 * =====================================================================
146 PARAMETER ( ZERO = ( 0.0E+0, 0.0E+0 ) )
148 * .. Local Scalars ..
150 INTEGER I, IB, IINFO, IWS, J, KI, KK, L, LDWORK,
151 $ LWKOPT, NB, NBMIN, NX
153 * .. External Subroutines ..
154 EXTERNAL CLARFB, CLARFT, CUNGL2, XERBLA
156 * .. Intrinsic Functions ..
159 * .. External Functions ..
163 * .. Executable Statements ..
165 * Test the input arguments
168 NB = ILAENV( 1, 'CUNGLQ', ' ', M, N, K, -1 )
169 LWKOPT = MAX( 1, M )*NB
171 LQUERY = ( LWORK.EQ.-1 )
174 ELSE IF( N.LT.M ) THEN
176 ELSE IF( K.LT.0 .OR. K.GT.M ) THEN
178 ELSE IF( LDA.LT.MAX( 1, M ) ) THEN
180 ELSE IF( LWORK.LT.MAX( 1, M ) .AND. .NOT.LQUERY ) THEN
184 CALL XERBLA( 'CUNGLQ', -INFO )
186 ELSE IF( LQUERY ) THEN
190 * Quick return if possible
200 IF( NB.GT.1 .AND. NB.LT.K ) THEN
202 * Determine when to cross over from blocked to unblocked code.
204 NX = MAX( 0, ILAENV( 3, 'CUNGLQ', ' ', M, N, K, -1 ) )
207 * Determine if workspace is large enough for blocked code.
211 IF( LWORK.LT.IWS ) THEN
213 * Not enough workspace to use optimal NB: reduce NB and
214 * determine the minimum value of NB.
217 NBMIN = MAX( 2, ILAENV( 2, 'CUNGLQ', ' ', M, N, K, -1 ) )
222 IF( NB.GE.NBMIN .AND. NB.LT.K .AND. NX.LT.K ) THEN
224 * Use blocked code after the last block.
225 * The first kk rows are handled by the block method.
227 KI = ( ( K-NX-1 ) / NB )*NB
230 * Set A(kk+1:m,1:kk) to zero.
241 * Use unblocked code for the last or only block.
244 $ CALL CUNGL2( M-KK, N-KK, K-KK, A( KK+1, KK+1 ), LDA,
245 $ TAU( KK+1 ), WORK, IINFO )
251 DO 50 I = KI + 1, 1, -NB
252 IB = MIN( NB, K-I+1 )
255 * Form the triangular factor of the block reflector
256 * H = H(i) H(i+1) . . . H(i+ib-1)
258 CALL CLARFT( 'Forward', 'Rowwise', N-I+1, IB, A( I, I ),
259 $ LDA, TAU( I ), WORK, LDWORK )
261 * Apply H**H to A(i+ib:m,i:n) from the right
263 CALL CLARFB( 'Right', 'Conjugate transpose', 'Forward',
264 $ 'Rowwise', M-I-IB+1, N-I+1, IB, A( I, I ),
265 $ LDA, WORK, LDWORK, A( I+IB, I ), LDA,
266 $ WORK( IB+1 ), LDWORK )
269 * Apply H**H to columns i:n of current block
271 CALL CUNGL2( IB, N-I+1, IB, A( I, I ), LDA, TAU( I ), WORK,
274 * Set columns 1:i-1 of current block to zero
277 DO 30 L = I, I + IB - 1