SUBROUTINE ZHBTRD( VECT, UPLO, N, KD, AB, LDAB, D, E, Q, LDQ,
$ WORK, INFO )
CHARACTER UPLO, VECT
INTEGER INFO, KD, LDAB, LDQ, N
DOUBLE PRECISION D( * ), E( * )
COMPLEX*16 AB( LDAB, * ), Q( LDQ, * ), WORK( * )
DOUBLE PRECISION ZERO
PARAMETER ( ZERO = 0.0D+0 )
COMPLEX*16 CZERO, CONE
PARAMETER ( CZERO = ( 0.0D+0, 0.0D+0 ),
$ CONE = ( 1.0D+0, 0.0D+0 ) )
LOGICAL INITQ, UPPER, WANTQ
INTEGER I, I2, IBL, INCA, INCX, IQAEND, IQB, IQEND, J,
$ J1, J1END, J1INC, J2, JEND, JIN, JINC, K, KD1,
$ KDM1, KDN, L, LAST, LEND, NQ, NR, NRT
DOUBLE PRECISION ABST
COMPLEX*16 T, TEMP
EXTERNAL XERBLA, ZLACGV, ZLAR2V, ZLARGV, ZLARTG, ZLARTV,
$ ZLASET, ZROT, ZSCAL
INTRINSIC ABS, DBLE, DCONJG, MAX, MIN
LOGICAL LSAME
EXTERNAL LSAME
INITQ = LSAME( VECT, 'V' )
WANTQ = INITQ .OR. LSAME( VECT, 'U' )
UPPER = LSAME( UPLO, 'U' )
KD1 = KD + 1
KDM1 = KD - 1
INCX = LDAB - 1
IQEND = 1
INFO = 0
IF( .NOT.WANTQ .AND. .NOT.LSAME( VECT, 'N' ) ) THEN
INFO = -1
ELSE IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN
INFO = -2
ELSE IF( N.LT.0 ) THEN
INFO = -3
ELSE IF( KD.LT.0 ) THEN
INFO = -4
ELSE IF( LDAB.LT.KD1 ) THEN
INFO = -6
ELSE IF( LDQ.LT.MAX( 1, N ) .AND. WANTQ ) THEN
INFO = -10
END IF
IF( INFO.NE.0 ) THEN
CALL XERBLA( 'ZHBTRD', -INFO )
RETURN
END IF
IF( N.EQ.0 )
$ RETURN
IF( INITQ )
$ CALL ZLASET( 'Full', N, N, CZERO, CONE, Q, LDQ )
INCA = KD1*LDAB
KDN = MIN( N-1, KD )
IF( UPPER ) THEN
IF( KD.GT.1 ) THEN
NR = 0
J1 = KDN + 2
J2 = 1
AB( KD1, 1 ) = DBLE( AB( KD1, 1 ) )
DO 90 I = 1, N - 2
DO 80 K = KDN + 1, 2, -1
J1 = J1 + KDN
J2 = J2 + KDN
IF( NR.GT.0 ) THEN
CALL ZLARGV( NR, AB( 1, J1-1 ), INCA, WORK( J1 ),
$ KD1, D( J1 ), KD1 )
IF( NR.GE.2*KD-1 ) THEN
DO 10 L = 1, KD - 1
CALL ZLARTV( NR, AB( L+1, J1-1 ), INCA,
$ AB( L, J1 ), INCA, D( J1 ),
$ WORK( J1 ), KD1 )
10 CONTINUE
ELSE
JEND = J1 + ( NR-1 )*KD1
DO 20 JINC = J1, JEND, KD1
CALL ZROT( KDM1, AB( 2, JINC-1 ), 1,
$ AB( 1, JINC ), 1, D( JINC ),
$ WORK( JINC ) )
20 CONTINUE
END IF
END IF
IF( K.GT.2 ) THEN
IF( K.LE.N-I+1 ) THEN
CALL ZLARTG( AB( KD-K+3, I+K-2 ),
$ AB( KD-K+2, I+K-1 ), D( I+K-1 ),
$ WORK( I+K-1 ), TEMP )
AB( KD-K+3, I+K-2 ) = TEMP
CALL ZROT( K-3, AB( KD-K+4, I+K-2 ), 1,
$ AB( KD-K+3, I+K-1 ), 1, D( I+K-1 ),
$ WORK( I+K-1 ) )
END IF
NR = NR + 1
J1 = J1 - KDN - 1
END IF
IF( NR.GT.0 )
$ CALL ZLAR2V( NR, AB( KD1, J1-1 ), AB( KD1, J1 ),
$ AB( KD, J1 ), INCA, D( J1 ),
$ WORK( J1 ), KD1 )
IF( NR.GT.0 ) THEN
CALL ZLACGV( NR, WORK( J1 ), KD1 )
IF( 2*KD-1.LT.NR ) THEN
DO 30 L = 1, KD - 1
IF( J2+L.GT.N ) THEN
NRT = NR - 1
ELSE
NRT = NR
END IF
IF( NRT.GT.0 )
$ CALL ZLARTV( NRT, AB( KD-L, J1+L ), INCA,
$ AB( KD-L+1, J1+L ), INCA,
$ D( J1 ), WORK( J1 ), KD1 )
30 CONTINUE
ELSE
J1END = J1 + KD1*( NR-2 )
IF( J1END.GE.J1 ) THEN
DO 40 JIN = J1, J1END, KD1
CALL ZROT( KD-1, AB( KD-1, JIN+1 ), INCX,
$ AB( KD, JIN+1 ), INCX,
$ D( JIN ), WORK( JIN ) )
40 CONTINUE
END IF
LEND = MIN( KDM1, N-J2 )
LAST = J1END + KD1
IF( LEND.GT.0 )
$ CALL ZROT( LEND, AB( KD-1, LAST+1 ), INCX,
$ AB( KD, LAST+1 ), INCX, D( LAST ),
$ WORK( LAST ) )
END IF
END IF
IF( WANTQ ) THEN
IF( INITQ ) THEN
IQEND = MAX( IQEND, J2 )
I2 = MAX( 0, K-3 )
IQAEND = 1 + I*KD
IF( K.EQ.2 )
$ IQAEND = IQAEND + KD
IQAEND = MIN( IQAEND, IQEND )
DO 50 J = J1, J2, KD1
IBL = I - I2 / KDM1
I2 = I2 + 1
IQB = MAX( 1, J-IBL )
NQ = 1 + IQAEND - IQB
IQAEND = MIN( IQAEND+KD, IQEND )
CALL ZROT( NQ, Q( IQB, J-1 ), 1, Q( IQB, J ),
$ 1, D( J ), DCONJG( WORK( J ) ) )
50 CONTINUE
ELSE
DO 60 J = J1, J2, KD1
CALL ZROT( N, Q( 1, J-1 ), 1, Q( 1, J ), 1,
$ D( J ), DCONJG( WORK( J ) ) )
60 CONTINUE
END IF
END IF
IF( J2+KDN.GT.N ) THEN
NR = NR - 1
J2 = J2 - KDN - 1
END IF
DO 70 J = J1, J2, KD1
WORK( J+KD ) = WORK( J )*AB( 1, J+KD )
AB( 1, J+KD ) = D( J )*AB( 1, J+KD )
70 CONTINUE
80 CONTINUE
90 CONTINUE
END IF
IF( KD.GT.0 ) THEN
DO 100 I = 1, N - 1
T = AB( KD, I+1 )
ABST = ABS( T )
AB( KD, I+1 ) = ABST
E( I ) = ABST
IF( ABST.NE.ZERO ) THEN
T = T / ABST
ELSE
T = CONE
END IF
IF( I.LT.N-1 )
$ AB( KD, I+2 ) = AB( KD, I+2 )*T
IF( WANTQ ) THEN
CALL ZSCAL( N, DCONJG( T ), Q( 1, I+1 ), 1 )
END IF
100 CONTINUE
ELSE
DO 110 I = 1, N - 1
E( I ) = ZERO
110 CONTINUE
END IF
DO 120 I = 1, N
D( I ) = AB( KD1, I )
120 CONTINUE
ELSE
IF( KD.GT.1 ) THEN
NR = 0
J1 = KDN + 2
J2 = 1
AB( 1, 1 ) = DBLE( AB( 1, 1 ) )
DO 210 I = 1, N - 2
DO 200 K = KDN + 1, 2, -1
J1 = J1 + KDN
J2 = J2 + KDN
IF( NR.GT.0 ) THEN
CALL ZLARGV( NR, AB( KD1, J1-KD1 ), INCA,
$ WORK( J1 ), KD1, D( J1 ), KD1 )
IF( NR.GT.2*KD-1 ) THEN
DO 130 L = 1, KD - 1
CALL ZLARTV( NR, AB( KD1-L, J1-KD1+L ), INCA,
$ AB( KD1-L+1, J1-KD1+L ), INCA,
$ D( J1 ), WORK( J1 ), KD1 )
130 CONTINUE
ELSE
JEND = J1 + KD1*( NR-1 )
DO 140 JINC = J1, JEND, KD1
CALL ZROT( KDM1, AB( KD, JINC-KD ), INCX,
$ AB( KD1, JINC-KD ), INCX,
$ D( JINC ), WORK( JINC ) )
140 CONTINUE
END IF
END IF
IF( K.GT.2 ) THEN
IF( K.LE.N-I+1 ) THEN
CALL ZLARTG( AB( K-1, I ), AB( K, I ),
$ D( I+K-1 ), WORK( I+K-1 ), TEMP )
AB( K-1, I ) = TEMP
CALL ZROT( K-3, AB( K-2, I+1 ), LDAB-1,
$ AB( K-1, I+1 ), LDAB-1, D( I+K-1 ),
$ WORK( I+K-1 ) )
END IF
NR = NR + 1
J1 = J1 - KDN - 1
END IF
IF( NR.GT.0 )
$ CALL ZLAR2V( NR, AB( 1, J1-1 ), AB( 1, J1 ),
$ AB( 2, J1-1 ), INCA, D( J1 ),
$ WORK( J1 ), KD1 )
IF( NR.GT.0 ) THEN
CALL ZLACGV( NR, WORK( J1 ), KD1 )
IF( NR.GT.2*KD-1 ) THEN
DO 150 L = 1, KD - 1
IF( J2+L.GT.N ) THEN
NRT = NR - 1
ELSE
NRT = NR
END IF
IF( NRT.GT.0 )
$ CALL ZLARTV( NRT, AB( L+2, J1-1 ), INCA,
$ AB( L+1, J1 ), INCA, D( J1 ),
$ WORK( J1 ), KD1 )
150 CONTINUE
ELSE
J1END = J1 + KD1*( NR-2 )
IF( J1END.GE.J1 ) THEN
DO 160 J1INC = J1, J1END, KD1
CALL ZROT( KDM1, AB( 3, J1INC-1 ), 1,
$ AB( 2, J1INC ), 1, D( J1INC ),
$ WORK( J1INC ) )
160 CONTINUE
END IF
LEND = MIN( KDM1, N-J2 )
LAST = J1END + KD1
IF( LEND.GT.0 )
$ CALL ZROT( LEND, AB( 3, LAST-1 ), 1,
$ AB( 2, LAST ), 1, D( LAST ),
$ WORK( LAST ) )
END IF
END IF
IF( WANTQ ) THEN
IF( INITQ ) THEN
IQEND = MAX( IQEND, J2 )
I2 = MAX( 0, K-3 )
IQAEND = 1 + I*KD
IF( K.EQ.2 )
$ IQAEND = IQAEND + KD
IQAEND = MIN( IQAEND, IQEND )
DO 170 J = J1, J2, KD1
IBL = I - I2 / KDM1
I2 = I2 + 1
IQB = MAX( 1, J-IBL )
NQ = 1 + IQAEND - IQB
IQAEND = MIN( IQAEND+KD, IQEND )
CALL ZROT( NQ, Q( IQB, J-1 ), 1, Q( IQB, J ),
$ 1, D( J ), WORK( J ) )
170 CONTINUE
ELSE
DO 180 J = J1, J2, KD1
CALL ZROT( N, Q( 1, J-1 ), 1, Q( 1, J ), 1,
$ D( J ), WORK( J ) )
180 CONTINUE
END IF
END IF
IF( J2+KDN.GT.N ) THEN
NR = NR - 1
J2 = J2 - KDN - 1
END IF
DO 190 J = J1, J2, KD1
WORK( J+KD ) = WORK( J )*AB( KD1, J )
AB( KD1, J ) = D( J )*AB( KD1, J )
190 CONTINUE
200 CONTINUE
210 CONTINUE
END IF
IF( KD.GT.0 ) THEN
DO 220 I = 1, N - 1
T = AB( 2, I )
ABST = ABS( T )
AB( 2, I ) = ABST
E( I ) = ABST
IF( ABST.NE.ZERO ) THEN
T = T / ABST
ELSE
T = CONE
END IF
IF( I.LT.N-1 )
$ AB( 2, I+1 ) = AB( 2, I+1 )*T
IF( WANTQ ) THEN
CALL ZSCAL( N, T, Q( 1, I+1 ), 1 )
END IF
220 CONTINUE
ELSE
DO 230 I = 1, N - 1
E( I ) = ZERO
230 CONTINUE
END IF
DO 240 I = 1, N
D( I ) = AB( 1, I )
240 CONTINUE
END IF
RETURN
END