001:       SUBROUTINE ZUNGL2( 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:       COMPLEX*16         A( LDA, * ), TAU( * ), WORK( * )
013: *     ..
014: *
015: *  Purpose
016: *  =======
017: *
018: *  ZUNGL2 generates an m-by-n complex 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 ZGELQF.
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) COMPLEX*16 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 ZGELQF 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) COMPLEX*16 array, dimension (K)
049: *          TAU(i) must contain the scalar factor of the elementary
050: *          reflector H(i), as returned by ZGELQF.
051: *
052: *  WORK    (workspace) COMPLEX*16 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:       COMPLEX*16         ONE, ZERO
062:       PARAMETER          ( ONE = ( 1.0D+0, 0.0D+0 ),
063:      $                   ZERO = ( 0.0D+0, 0.0D+0 ) )
064: *     ..
065: *     .. Local Scalars ..
066:       INTEGER            I, J, L
067: *     ..
068: *     .. External Subroutines ..
069:       EXTERNAL           XERBLA, ZLACGV, ZLARF, ZSCAL
070: *     ..
071: *     .. Intrinsic Functions ..
072:       INTRINSIC          DCONJG, 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.M ) THEN
082:          INFO = -2
083:       ELSE IF( K.LT.0 .OR. K.GT.M ) 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( 'ZUNGL2', -INFO )
090:          RETURN
091:       END IF
092: *
093: *     Quick return if possible
094: *
095:       IF( M.LE.0 )
096:      $   RETURN
097: *
098:       IF( K.LT.M ) THEN
099: *
100: *        Initialise rows k+1:m to rows of the unit matrix
101: *
102:          DO 20 J = 1, N
103:             DO 10 L = K + 1, M
104:                A( L, J ) = ZERO
105:    10       CONTINUE
106:             IF( J.GT.K .AND. J.LE.M )
107:      $         A( J, J ) = ONE
108:    20    CONTINUE
109:       END IF
110: *
111:       DO 40 I = K, 1, -1
112: *
113: *        Apply H(i)' to A(i:m,i:n) from the right
114: *
115:          IF( I.LT.N ) THEN
116:             CALL ZLACGV( N-I, A( I, I+1 ), LDA )
117:             IF( I.LT.M ) THEN
118:                A( I, I ) = ONE
119:                CALL ZLARF( 'Right', M-I, N-I+1, A( I, I ), LDA,
120:      $                     DCONJG( TAU( I ) ), A( I+1, I ), LDA, WORK )
121:             END IF
122:             CALL ZSCAL( N-I, -TAU( I ), A( I, I+1 ), LDA )
123:             CALL ZLACGV( N-I, A( I, I+1 ), LDA )
124:          END IF
125:          A( I, I ) = ONE - DCONJG( TAU( I ) )
126: *
127: *        Set A(i,1:i-1) to zero
128: *
129:          DO 30 L = 1, I - 1
130:             A( I, L ) = ZERO
131:    30    CONTINUE
132:    40 CONTINUE
133:       RETURN
134: *
135: *     End of ZUNGL2
136: *
137:       END
138: