001:       SUBROUTINE ZUNGL2( 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:       COMPLEX*16         A( LDA, * ), TAU( * ), WORK( * )
012: *     ..
013: *
014: *  Purpose
015: *  =======
016: *
017: *  ZUNGL2 generates an m-by-n complex 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 ZGELQF.
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) COMPLEX*16 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 ZGELQF 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) COMPLEX*16 array, dimension (K)
048: *          TAU(i) must contain the scalar factor of the elementary
049: *          reflector H(i), as returned by ZGELQF.
050: *
051: *  WORK    (workspace) COMPLEX*16 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:       COMPLEX*16         ONE, ZERO
061:       PARAMETER          ( ONE = ( 1.0D+0, 0.0D+0 ),
062:      $                   ZERO = ( 0.0D+0, 0.0D+0 ) )
063: *     ..
064: *     .. Local Scalars ..
065:       INTEGER            I, J, L
066: *     ..
067: *     .. External Subroutines ..
068:       EXTERNAL           XERBLA, ZLACGV, ZLARF, ZSCAL
069: *     ..
070: *     .. Intrinsic Functions ..
071:       INTRINSIC          DCONJG, 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( 'ZUNGL2', -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:             CALL ZLACGV( N-I, A( I, I+1 ), LDA )
116:             IF( I.LT.M ) THEN
117:                A( I, I ) = ONE
118:                CALL ZLARF( 'Right', M-I, N-I+1, A( I, I ), LDA,
119:      $                     DCONJG( TAU( I ) ), A( I+1, I ), LDA, WORK )
120:             END IF
121:             CALL ZSCAL( N-I, -TAU( I ), A( I, I+1 ), LDA )
122:             CALL ZLACGV( N-I, A( I, I+1 ), LDA )
123:          END IF
124:          A( I, I ) = ONE - DCONJG( TAU( I ) )
125: *
126: *        Set A(i,1:i-1) to zero
127: *
128:          DO 30 L = 1, I - 1
129:             A( I, L ) = ZERO
130:    30    CONTINUE
131:    40 CONTINUE
132:       RETURN
133: *
134: *     End of ZUNGL2
135: *
136:       END
137: