```001:       SUBROUTINE ZGEHD2( N, ILO, IHI, 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            IHI, ILO, INFO, LDA, N
009: *     ..
010: *     .. Array Arguments ..
011:       COMPLEX*16         A( LDA, * ), TAU( * ), WORK( * )
012: *     ..
013: *
014: *  Purpose
015: *  =======
016: *
017: *  ZGEHD2 reduces a complex general matrix A to upper Hessenberg form H
018: *  by a unitary similarity transformation:  Q' * A * Q = H .
019: *
020: *  Arguments
021: *  =========
022: *
023: *  N       (input) INTEGER
024: *          The order of the matrix A.  N >= 0.
025: *
026: *  ILO     (input) INTEGER
027: *  IHI     (input) INTEGER
028: *          It is assumed that A is already upper triangular in rows
029: *          and columns 1:ILO-1 and IHI+1:N. ILO and IHI are normally
030: *          set by a previous call to ZGEBAL; otherwise they should be
031: *          set to 1 and N respectively. See Further Details.
032: *          1 <= ILO <= IHI <= max(1,N).
033: *
034: *  A       (input/output) COMPLEX*16 array, dimension (LDA,N)
035: *          On entry, the n by n general matrix to be reduced.
036: *          On exit, the upper triangle and the first subdiagonal of A
037: *          are overwritten with the upper Hessenberg matrix H, and the
038: *          elements below the first subdiagonal, with the array TAU,
039: *          represent the unitary matrix Q as a product of elementary
040: *          reflectors. See Further Details.
041: *
042: *  LDA     (input) INTEGER
043: *          The leading dimension of the array A.  LDA >= max(1,N).
044: *
045: *  TAU     (output) COMPLEX*16 array, dimension (N-1)
046: *          The scalar factors of the elementary reflectors (see Further
047: *          Details).
048: *
049: *  WORK    (workspace) COMPLEX*16 array, dimension (N)
050: *
051: *  INFO    (output) INTEGER
052: *          = 0:  successful exit
053: *          < 0:  if INFO = -i, the i-th argument had an illegal value.
054: *
055: *  Further Details
056: *  ===============
057: *
058: *  The matrix Q is represented as a product of (ihi-ilo) elementary
059: *  reflectors
060: *
061: *     Q = H(ilo) H(ilo+1) . . . H(ihi-1).
062: *
063: *  Each H(i) has the form
064: *
065: *     H(i) = I - tau * v * v'
066: *
067: *  where tau is a complex scalar, and v is a complex vector with
068: *  v(1:i) = 0, v(i+1) = 1 and v(ihi+1:n) = 0; v(i+2:ihi) is stored on
069: *  exit in A(i+2:ihi,i), and tau in TAU(i).
070: *
071: *  The contents of A are illustrated by the following example, with
072: *  n = 7, ilo = 2 and ihi = 6:
073: *
074: *  on entry,                        on exit,
075: *
076: *  ( a   a   a   a   a   a   a )    (  a   a   h   h   h   h   a )
077: *  (     a   a   a   a   a   a )    (      a   h   h   h   h   a )
078: *  (     a   a   a   a   a   a )    (      h   h   h   h   h   h )
079: *  (     a   a   a   a   a   a )    (      v2  h   h   h   h   h )
080: *  (     a   a   a   a   a   a )    (      v2  v3  h   h   h   h )
081: *  (     a   a   a   a   a   a )    (      v2  v3  v4  h   h   h )
082: *  (                         a )    (                          a )
083: *
084: *  where a denotes an element of the original matrix A, h denotes a
085: *  modified element of the upper Hessenberg matrix H, and vi denotes an
086: *  element of the vector defining H(i).
087: *
088: *  =====================================================================
089: *
090: *     .. Parameters ..
091:       COMPLEX*16         ONE
092:       PARAMETER          ( ONE = ( 1.0D+0, 0.0D+0 ) )
093: *     ..
094: *     .. Local Scalars ..
095:       INTEGER            I
096:       COMPLEX*16         ALPHA
097: *     ..
098: *     .. External Subroutines ..
099:       EXTERNAL           XERBLA, ZLARF, ZLARFG
100: *     ..
101: *     .. Intrinsic Functions ..
102:       INTRINSIC          DCONJG, MAX, MIN
103: *     ..
104: *     .. Executable Statements ..
105: *
106: *     Test the input parameters
107: *
108:       INFO = 0
109:       IF( N.LT.0 ) THEN
110:          INFO = -1
111:       ELSE IF( ILO.LT.1 .OR. ILO.GT.MAX( 1, N ) ) THEN
112:          INFO = -2
113:       ELSE IF( IHI.LT.MIN( ILO, N ) .OR. IHI.GT.N ) THEN
114:          INFO = -3
115:       ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
116:          INFO = -5
117:       END IF
118:       IF( INFO.NE.0 ) THEN
119:          CALL XERBLA( 'ZGEHD2', -INFO )
120:          RETURN
121:       END IF
122: *
123:       DO 10 I = ILO, IHI - 1
124: *
125: *        Compute elementary reflector H(i) to annihilate A(i+2:ihi,i)
126: *
127:          ALPHA = A( I+1, I )
128:          CALL ZLARFG( IHI-I, ALPHA, A( MIN( I+2, N ), I ), 1, TAU( I ) )
129:          A( I+1, I ) = ONE
130: *
131: *        Apply H(i) to A(1:ihi,i+1:ihi) from the right
132: *
133:          CALL ZLARF( 'Right', IHI, IHI-I, A( I+1, I ), 1, TAU( I ),
134:      \$               A( 1, I+1 ), LDA, WORK )
135: *
136: *        Apply H(i)' to A(i+1:ihi,i+1:n) from the left
137: *
138:          CALL ZLARF( 'Left', IHI-I, N-I, A( I+1, I ), 1,
139:      \$               DCONJG( TAU( I ) ), A( I+1, I+1 ), LDA, WORK )
140: *
141:          A( I+1, I ) = ALPHA
142:    10 CONTINUE
143: *
144:       RETURN
145: *
146: *     End of ZGEHD2
147: *
148:       END
149: ```