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