001:       SUBROUTINE SORGL2( 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: *  SORGL2 generates an m by n real matrix Q with orthonormal rows,
018: *  which is defined as the first m rows of a product of k elementary
019: *  reflectors of order n
020: *
021: *        Q  =  H(k) . . . H(2) H(1)
022: *
023: *  as returned by SGELQF.
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. N >= M.
033: *
034: *  K       (input) INTEGER
035: *          The number of elementary reflectors whose product defines the
036: *          matrix Q. M >= K >= 0.
037: *
038: *  A       (input/output) REAL array, dimension (LDA,N)
039: *          On entry, the i-th row must contain the vector which defines
040: *          the elementary reflector H(i), for i = 1,2,...,k, as returned
041: *          by SGELQF in the first k rows of its array argument A.
042: *          On exit, the m-by-n matrix Q.
043: *
044: *  LDA     (input) INTEGER
045: *          The first dimension of the array A. LDA >= max(1,M).
046: *
047: *  TAU     (input) REAL array, dimension (K)
048: *          TAU(i) must contain the scalar factor of the elementary
049: *          reflector H(i), as returned by SGELQF.
050: *
051: *  WORK    (workspace) REAL array, dimension (M)
052: *
053: *  INFO    (output) INTEGER
054: *          = 0: successful exit
055: *          < 0: if INFO = -i, the i-th argument has an illegal value
056: *
057: *  =====================================================================
058: *
059: *     .. Parameters ..
060:       REAL               ONE, ZERO
061:       PARAMETER          ( ONE = 1.0E+0, ZERO = 0.0E+0 )
062: *     ..
063: *     .. Local Scalars ..
064:       INTEGER            I, J, L
065: *     ..
066: *     .. External Subroutines ..
067:       EXTERNAL           SLARF, SSCAL, XERBLA
068: *     ..
069: *     .. Intrinsic Functions ..
070:       INTRINSIC          MAX
071: *     ..
072: *     .. Executable Statements ..
073: *
074: *     Test the input arguments
075: *
076:       INFO = 0
077:       IF( M.LT.0 ) THEN
078:          INFO = -1
079:       ELSE IF( N.LT.M ) THEN
080:          INFO = -2
081:       ELSE IF( K.LT.0 .OR. K.GT.M ) THEN
082:          INFO = -3
083:       ELSE IF( LDA.LT.MAX( 1, M ) ) THEN
084:          INFO = -5
085:       END IF
086:       IF( INFO.NE.0 ) THEN
087:          CALL XERBLA( 'SORGL2', -INFO )
088:          RETURN
089:       END IF
090: *
091: *     Quick return if possible
092: *
093:       IF( M.LE.0 )
094:      $   RETURN
095: *
096:       IF( K.LT.M ) THEN
097: *
098: *        Initialise rows k+1:m to rows of the unit matrix
099: *
100:          DO 20 J = 1, N
101:             DO 10 L = K + 1, M
102:                A( L, J ) = ZERO
103:    10       CONTINUE
104:             IF( J.GT.K .AND. J.LE.M )
105:      $         A( J, J ) = ONE
106:    20    CONTINUE
107:       END IF
108: *
109:       DO 40 I = K, 1, -1
110: *
111: *        Apply H(i) to A(i:m,i:n) from the right
112: *
113:          IF( I.LT.N ) THEN
114:             IF( I.LT.M ) THEN
115:                A( I, I ) = ONE
116:                CALL SLARF( 'Right', M-I, N-I+1, A( I, I ), LDA,
117:      $                     TAU( I ), A( I+1, I ), LDA, WORK )
118:             END IF
119:             CALL SSCAL( N-I, -TAU( I ), A( I, I+1 ), LDA )
120:          END IF
121:          A( I, I ) = ONE - TAU( I )
122: *
123: *        Set A(i,1:i-1) to zero
124: *
125:          DO 30 L = 1, I - 1
126:             A( I, L ) = ZERO
127:    30    CONTINUE
128:    40 CONTINUE
129:       RETURN
130: *
131: *     End of SORGL2
132: *
133:       END
134: