001:       SUBROUTINE ZUNGR2( 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: *  ZUNGR2 generates an m by n complex matrix Q with orthonormal rows,
019: *  which is defined as the last m rows of a product of k elementary
020: *  reflectors of order n
021: *
022: *        Q  =  H(1)' H(2)' . . . H(k)'
023: *
024: *  as returned by ZGERQF.
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 (m-k+i)-th row must contain the vector which
041: *          defines the elementary reflector H(i), for i = 1,2,...,k, as
042: *          returned by ZGERQF in the last k rows of its array argument
043: *          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) COMPLEX*16 array, dimension (K)
050: *          TAU(i) must contain the scalar factor of the elementary
051: *          reflector H(i), as returned by ZGERQF.
052: *
053: *  WORK    (workspace) COMPLEX*16 array, dimension (M)
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:       COMPLEX*16         ONE, ZERO
063:       PARAMETER          ( ONE = ( 1.0D+0, 0.0D+0 ),
064:      $                   ZERO = ( 0.0D+0, 0.0D+0 ) )
065: *     ..
066: *     .. Local Scalars ..
067:       INTEGER            I, II, J, L
068: *     ..
069: *     .. External Subroutines ..
070:       EXTERNAL           XERBLA, ZLACGV, ZLARF, ZSCAL
071: *     ..
072: *     .. Intrinsic Functions ..
073:       INTRINSIC          DCONJG, MAX
074: *     ..
075: *     .. Executable Statements ..
076: *
077: *     Test the input arguments
078: *
079:       INFO = 0
080:       IF( M.LT.0 ) THEN
081:          INFO = -1
082:       ELSE IF( N.LT.M ) THEN
083:          INFO = -2
084:       ELSE IF( K.LT.0 .OR. K.GT.M ) THEN
085:          INFO = -3
086:       ELSE IF( LDA.LT.MAX( 1, M ) ) THEN
087:          INFO = -5
088:       END IF
089:       IF( INFO.NE.0 ) THEN
090:          CALL XERBLA( 'ZUNGR2', -INFO )
091:          RETURN
092:       END IF
093: *
094: *     Quick return if possible
095: *
096:       IF( M.LE.0 )
097:      $   RETURN
098: *
099:       IF( K.LT.M ) THEN
100: *
101: *        Initialise rows 1:m-k to rows of the unit matrix
102: *
103:          DO 20 J = 1, N
104:             DO 10 L = 1, M - K
105:                A( L, J ) = ZERO
106:    10       CONTINUE
107:             IF( J.GT.N-M .AND. J.LE.N-K )
108:      $         A( M-N+J, J ) = ONE
109:    20    CONTINUE
110:       END IF
111: *
112:       DO 40 I = 1, K
113:          II = M - K + I
114: *
115: *        Apply H(i)' to A(1:m-k+i,1:n-k+i) from the right
116: *
117:          CALL ZLACGV( N-M+II-1, A( II, 1 ), LDA )
118:          A( II, N-M+II ) = ONE
119:          CALL ZLARF( 'Right', II-1, N-M+II, A( II, 1 ), LDA,
120:      $               DCONJG( TAU( I ) ), A, LDA, WORK )
121:          CALL ZSCAL( N-M+II-1, -TAU( I ), A( II, 1 ), LDA )
122:          CALL ZLACGV( N-M+II-1, A( II, 1 ), LDA )
123:          A( II, N-M+II ) = ONE - DCONJG( TAU( I ) )
124: *
125: *        Set A(m-k+i,n-k+i+1:n) to zero
126: *
127:          DO 30 L = N - M + II + 1, N
128:             A( II, L ) = ZERO
129:    30    CONTINUE
130:    40 CONTINUE
131:       RETURN
132: *
133: *     End of ZUNGR2
134: *
135:       END
136: