001:       SUBROUTINE SORGL2( 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: *  SORGL2 generates an m by n real matrix Q with orthonormal rows,
019: *  which is defined as the first m rows of a product of k elementary
020: *  reflectors of order n
021: *
022: *        Q  =  H(k) . . . H(2) H(1)
023: *
024: *  as returned by SGELQF.
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. N >= M.
034: *
035: *  K       (input) INTEGER
036: *          The number of elementary reflectors whose product defines the
037: *          matrix Q. M >= K >= 0.
038: *
039: *  A       (input/output) REAL array, dimension (LDA,N)
040: *          On entry, the i-th row must contain the vector which defines
041: *          the elementary reflector H(i), for i = 1,2,...,k, as returned
042: *          by SGELQF in the first k rows of its array 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 SGELQF.
051: *
052: *  WORK    (workspace) REAL array, dimension (M)
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, 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.M ) THEN
081:          INFO = -2
082:       ELSE IF( K.LT.0 .OR. K.GT.M ) 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( 'SORGL2', -INFO )
089:          RETURN
090:       END IF
091: *
092: *     Quick return if possible
093: *
094:       IF( M.LE.0 )
095:      $   RETURN
096: *
097:       IF( K.LT.M ) THEN
098: *
099: *        Initialise rows k+1:m to rows of the unit matrix
100: *
101:          DO 20 J = 1, N
102:             DO 10 L = K + 1, M
103:                A( L, J ) = ZERO
104:    10       CONTINUE
105:             IF( J.GT.K .AND. J.LE.M )
106:      $         A( J, J ) = ONE
107:    20    CONTINUE
108:       END IF
109: *
110:       DO 40 I = K, 1, -1
111: *
112: *        Apply H(i) to A(i:m,i:n) from the right
113: *
114:          IF( I.LT.N ) THEN
115:             IF( I.LT.M ) THEN
116:                A( I, I ) = ONE
117:                CALL SLARF( 'Right', M-I, N-I+1, A( I, I ), LDA,
118:      $                     TAU( I ), A( I+1, I ), LDA, WORK )
119:             END IF
120:             CALL SSCAL( N-I, -TAU( I ), A( I, I+1 ), LDA )
121:          END IF
122:          A( I, I ) = ONE - TAU( I )
123: *
124: *        Set A(i,1:i-1) to zero
125: *
126:          DO 30 L = 1, I - 1
127:             A( I, L ) = ZERO
128:    30    CONTINUE
129:    40 CONTINUE
130:       RETURN
131: *
132: *     End of SORGL2
133: *
134:       END
135: