3 * =========== DOCUMENTATION ===========
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
9 *> Download SORGQL + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/sorgql.f">
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/sorgql.f">
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/sorgql.f">
21 * SUBROUTINE SORGQL( M, N, K, A, LDA, TAU, WORK, LWORK, INFO )
23 * .. Scalar Arguments ..
24 * INTEGER INFO, K, LDA, LWORK, M, N
26 * .. Array Arguments ..
27 * REAL A( LDA, * ), TAU( * ), WORK( * )
36 *> SORGQL generates an M-by-N real matrix Q with orthonormal columns,
37 *> which is defined as the last N columns of a product of K elementary
38 *> reflectors of order M
40 *> Q = H(k) . . . H(2) H(1)
42 *> as returned by SGEQLF.
51 *> The number of rows of the matrix Q. M >= 0.
57 *> The number of columns of the matrix Q. M >= N >= 0.
63 *> The number of elementary reflectors whose product defines the
64 *> matrix Q. N >= K >= 0.
69 *> A is REAL array, dimension (LDA,N)
70 *> On entry, the (n-k+i)-th column must contain the vector which
71 *> defines the elementary reflector H(i), for i = 1,2,...,k, as
72 *> returned by SGEQLF in the last k columns of its array
74 *> On exit, the M-by-N matrix Q.
80 *> The first dimension of the array A. LDA >= max(1,M).
85 *> TAU is REAL array, dimension (K)
86 *> TAU(i) must contain the scalar factor of the elementary
87 *> reflector H(i), as returned by SGEQLF.
92 *> WORK is REAL array, dimension (MAX(1,LWORK))
93 *> On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
99 *> The dimension of the array WORK. LWORK >= max(1,N).
100 *> For optimum performance LWORK >= N*NB, where NB is the
101 *> optimal blocksize.
103 *> If LWORK = -1, then a workspace query is assumed; the routine
104 *> only calculates the optimal size of the WORK array, returns
105 *> this value as the first entry of the WORK array, and no error
106 *> message related to LWORK is issued by XERBLA.
112 *> = 0: successful exit
113 *> < 0: if INFO = -i, the i-th argument has an illegal value
119 *> \author Univ. of Tennessee
120 *> \author Univ. of California Berkeley
121 *> \author Univ. of Colorado Denver
124 *> \date November 2011
126 *> \ingroup realOTHERcomputational
128 * =====================================================================
129 SUBROUTINE SORGQL( M, N, K, A, LDA, TAU, WORK, LWORK, INFO )
131 * -- LAPACK computational routine (version 3.4.0) --
132 * -- LAPACK is a software package provided by Univ. of Tennessee, --
133 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
136 * .. Scalar Arguments ..
137 INTEGER INFO, K, LDA, LWORK, M, N
139 * .. Array Arguments ..
140 REAL A( LDA, * ), TAU( * ), WORK( * )
143 * =====================================================================
147 PARAMETER ( ZERO = 0.0E+0 )
149 * .. Local Scalars ..
151 INTEGER I, IB, IINFO, IWS, J, KK, L, LDWORK, LWKOPT,
154 * .. External Subroutines ..
155 EXTERNAL SLARFB, SLARFT, SORG2L, XERBLA
157 * .. Intrinsic Functions ..
160 * .. External Functions ..
164 * .. Executable Statements ..
166 * Test the input arguments
169 LQUERY = ( LWORK.EQ.-1 )
172 ELSE IF( N.LT.0 .OR. N.GT.M ) THEN
174 ELSE IF( K.LT.0 .OR. K.GT.N ) THEN
176 ELSE IF( LDA.LT.MAX( 1, M ) ) THEN
184 NB = ILAENV( 1, 'SORGQL', ' ', M, N, K, -1 )
189 IF( LWORK.LT.MAX( 1, N ) .AND. .NOT.LQUERY ) THEN
195 CALL XERBLA( 'SORGQL', -INFO )
197 ELSE IF( LQUERY ) THEN
201 * Quick return if possible
210 IF( NB.GT.1 .AND. NB.LT.K ) THEN
212 * Determine when to cross over from blocked to unblocked code.
214 NX = MAX( 0, ILAENV( 3, 'SORGQL', ' ', M, N, K, -1 ) )
217 * Determine if workspace is large enough for blocked code.
221 IF( LWORK.LT.IWS ) THEN
223 * Not enough workspace to use optimal NB: reduce NB and
224 * determine the minimum value of NB.
227 NBMIN = MAX( 2, ILAENV( 2, 'SORGQL', ' ', M, N, K, -1 ) )
232 IF( NB.GE.NBMIN .AND. NB.LT.K .AND. NX.LT.K ) THEN
234 * Use blocked code after the first block.
235 * The last kk columns are handled by the block method.
237 KK = MIN( K, ( ( K-NX+NB-1 ) / NB )*NB )
239 * Set A(m-kk+1:m,1:n-kk) to zero.
242 DO 10 I = M - KK + 1, M
250 * Use unblocked code for the first or only block.
252 CALL SORG2L( M-KK, N-KK, K-KK, A, LDA, TAU, WORK, IINFO )
258 DO 50 I = K - KK + 1, K, NB
259 IB = MIN( NB, K-I+1 )
260 IF( N-K+I.GT.1 ) THEN
262 * Form the triangular factor of the block reflector
263 * H = H(i+ib-1) . . . H(i+1) H(i)
265 CALL SLARFT( 'Backward', 'Columnwise', M-K+I+IB-1, IB,
266 $ A( 1, N-K+I ), LDA, TAU( I ), WORK, LDWORK )
268 * Apply H to A(1:m-k+i+ib-1,1:n-k+i-1) from the left
270 CALL SLARFB( 'Left', 'No transpose', 'Backward',
271 $ 'Columnwise', M-K+I+IB-1, N-K+I-1, IB,
272 $ A( 1, N-K+I ), LDA, WORK, LDWORK, A, LDA,
273 $ WORK( IB+1 ), LDWORK )
276 * Apply H to rows 1:m-k+i+ib-1 of current block
278 CALL SORG2L( M-K+I+IB-1, IB, IB, A( 1, N-K+I ), LDA,
279 $ TAU( I ), WORK, IINFO )
281 * Set rows m-k+i+ib:m of current block to zero
283 DO 40 J = N - K + I, N - K + I + IB - 1
284 DO 30 L = M - K + I + IB, M