001:       SUBROUTINE SORG2L( M, N, K, A, LDA, TAU, WORK, INFO )
002: *
003: *  -- LAPACK routine (version 3.2) --
004: *     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
005: *     November 2006
006: *
007: *     .. Scalar Arguments ..
008:       INTEGER            INFO, K, LDA, M, N
009: *     ..
010: *     .. Array Arguments ..
011:       REAL               A( LDA, * ), TAU( * ), WORK( * )
012: *     ..
013: *
014: *  Purpose
015: *  =======
016: *
017: *  SORG2L generates an m by n real matrix Q with orthonormal columns,
018: *  which is defined as the last n columns of a product of k elementary
019: *  reflectors of order m
020: *
021: *        Q  =  H(k) . . . H(2) H(1)
022: *
023: *  as returned by SGEQLF.
024: *
025: *  Arguments
026: *  =========
027: *
028: *  M       (input) INTEGER
029: *          The number of rows of the matrix Q. M >= 0.
030: *
031: *  N       (input) INTEGER
032: *          The number of columns of the matrix Q. M >= N >= 0.
033: *
034: *  K       (input) INTEGER
035: *          The number of elementary reflectors whose product defines the
036: *          matrix Q. N >= K >= 0.
037: *
038: *  A       (input/output) REAL array, dimension (LDA,N)
039: *          On entry, the (n-k+i)-th column must contain the vector which
040: *          defines the elementary reflector H(i), for i = 1,2,...,k, as
041: *          returned by SGEQLF in the last k columns of its array
042: *          argument A.
043: *          On exit, the m by n matrix Q.
044: *
045: *  LDA     (input) INTEGER
046: *          The first dimension of the array A. LDA >= max(1,M).
047: *
048: *  TAU     (input) REAL array, dimension (K)
049: *          TAU(i) must contain the scalar factor of the elementary
050: *          reflector H(i), as returned by SGEQLF.
051: *
052: *  WORK    (workspace) REAL array, dimension (N)
053: *
054: *  INFO    (output) INTEGER
055: *          = 0: successful exit
056: *          < 0: if INFO = -i, the i-th argument has an illegal value
057: *
058: *  =====================================================================
059: *
060: *     .. Parameters ..
061:       REAL               ONE, ZERO
062:       PARAMETER          ( ONE = 1.0E+0, ZERO = 0.0E+0 )
063: *     ..
064: *     .. Local Scalars ..
065:       INTEGER            I, II, J, L
066: *     ..
067: *     .. External Subroutines ..
068:       EXTERNAL           SLARF, SSCAL, XERBLA
069: *     ..
070: *     .. Intrinsic Functions ..
071:       INTRINSIC          MAX
072: *     ..
073: *     .. Executable Statements ..
074: *
075: *     Test the input arguments
076: *
077:       INFO = 0
078:       IF( M.LT.0 ) THEN
079:          INFO = -1
080:       ELSE IF( N.LT.0 .OR. N.GT.M ) THEN
081:          INFO = -2
082:       ELSE IF( K.LT.0 .OR. K.GT.N ) THEN
083:          INFO = -3
084:       ELSE IF( LDA.LT.MAX( 1, M ) ) THEN
085:          INFO = -5
086:       END IF
087:       IF( INFO.NE.0 ) THEN
088:          CALL XERBLA( 'SORG2L', -INFO )
089:          RETURN
090:       END IF
091: *
092: *     Quick return if possible
093: *
094:       IF( N.LE.0 )
095:      $   RETURN
096: *
097: *     Initialise columns 1:n-k to columns of the unit matrix
098: *
099:       DO 20 J = 1, N - K
100:          DO 10 L = 1, M
101:             A( L, J ) = ZERO
102:    10    CONTINUE
103:          A( M-N+J, J ) = ONE
104:    20 CONTINUE
105: *
106:       DO 40 I = 1, K
107:          II = N - K + I
108: *
109: *        Apply H(i) to A(1:m-k+i,1:n-k+i) from the left
110: *
111:          A( M-N+II, II ) = ONE
112:          CALL SLARF( 'Left', M-N+II, II-1, A( 1, II ), 1, TAU( I ), A,
113:      $               LDA, WORK )
114:          CALL SSCAL( M-N+II-1, -TAU( I ), A( 1, II ), 1 )
115:          A( M-N+II, II ) = ONE - TAU( I )
116: *
117: *        Set A(m-k+i+1:m,n-k+i) to zero
118: *
119:          DO 30 L = M - N + II + 1, M
120:             A( L, II ) = ZERO
121:    30    CONTINUE
122:    40 CONTINUE
123:       RETURN
124: *
125: *     End of SORG2L
126: *
127:       END
128: