1       SUBROUTINE DPBTF2( UPLO, N, KD, AB, LDAB, INFO )
  2 *
  3 *  -- LAPACK routine (version 3.3.1) --
  4 *  -- LAPACK is a software package provided by Univ. of Tennessee,    --
  5 *  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
  6 *  -- April 2011                                                      --
  7 *
  8 *     .. Scalar Arguments ..
  9       CHARACTER          UPLO
 10       INTEGER            INFO, KD, LDAB, N
 11 *     ..
 12 *     .. Array Arguments ..
 13       DOUBLE PRECISION   AB( LDAB, * )
 14 *     ..
 15 *
 16 *  Purpose
 17 *  =======
 18 *
 19 *  DPBTF2 computes the Cholesky factorization of a real symmetric
 20 *  positive definite band matrix A.
 21 *
 22 *  The factorization has the form
 23 *     A = U**T * U ,  if UPLO = 'U', or
 24 *     A = L  * L**T,  if UPLO = 'L',
 25 *  where U is an upper triangular matrix, U**T is the transpose of U, and
 26 *  L is lower triangular.
 27 *
 28 *  This is the unblocked version of the algorithm, calling Level 2 BLAS.
 29 *
 30 *  Arguments
 31 *  =========
 32 *
 33 *  UPLO    (input) CHARACTER*1
 34 *          Specifies whether the upper or lower triangular part of the
 35 *          symmetric matrix A is stored:
 36 *          = 'U':  Upper triangular
 37 *          = 'L':  Lower triangular
 38 *
 39 *  N       (input) INTEGER
 40 *          The order of the matrix A.  N >= 0.
 41 *
 42 *  KD      (input) INTEGER
 43 *          The number of super-diagonals of the matrix A if UPLO = 'U',
 44 *          or the number of sub-diagonals if UPLO = 'L'.  KD >= 0.
 45 *
 46 *  AB      (input/output) DOUBLE PRECISION array, dimension (LDAB,N)
 47 *          On entry, the upper or lower triangle of the symmetric band
 48 *          matrix A, stored in the first KD+1 rows of the array.  The
 49 *          j-th column of A is stored in the j-th column of the array AB
 50 *          as follows:
 51 *          if UPLO = 'U', AB(kd+1+i-j,j) = A(i,j) for max(1,j-kd)<=i<=j;
 52 *          if UPLO = 'L', AB(1+i-j,j)    = A(i,j) for j<=i<=min(n,j+kd).
 53 *
 54 *          On exit, if INFO = 0, the triangular factor U or L from the
 55 *          Cholesky factorization A = U**T*U or A = L*L**T of the band
 56 *          matrix A, in the same storage format as A.
 57 *
 58 *  LDAB    (input) INTEGER
 59 *          The leading dimension of the array AB.  LDAB >= KD+1.
 60 *
 61 *  INFO    (output) INTEGER
 62 *          = 0: successful exit
 63 *          < 0: if INFO = -k, the k-th argument had an illegal value
 64 *          > 0: if INFO = k, the leading minor of order k is not
 65 *               positive definite, and the factorization could not be
 66 *               completed.
 67 *
 68 *  Further Details
 69 *  ===============
 70 *
 71 *  The band storage scheme is illustrated by the following example, when
 72 *  N = 6, KD = 2, and UPLO = 'U':
 73 *
 74 *  On entry:                       On exit:
 75 *
 76 *      *    *   a13  a24  a35  a46      *    *   u13  u24  u35  u46
 77 *      *   a12  a23  a34  a45  a56      *   u12  u23  u34  u45  u56
 78 *     a11  a22  a33  a44  a55  a66     u11  u22  u33  u44  u55  u66
 79 *
 80 *  Similarly, if UPLO = 'L' the format of A is as follows:
 81 *
 82 *  On entry:                       On exit:
 83 *
 84 *     a11  a22  a33  a44  a55  a66     l11  l22  l33  l44  l55  l66
 85 *     a21  a32  a43  a54  a65   *      l21  l32  l43  l54  l65   *
 86 *     a31  a42  a53  a64   *    *      l31  l42  l53  l64   *    *
 87 *
 88 *  Array elements marked * are not used by the routine.
 89 *
 90 *  =====================================================================
 91 *
 92 *     .. Parameters ..
 93       DOUBLE PRECISION   ONE, ZERO
 94       PARAMETER          ( ONE = 1.0D+0, ZERO = 0.0D+0 )
 95 *     ..
 96 *     .. Local Scalars ..
 97       LOGICAL            UPPER
 98       INTEGER            J, KLD, KN
 99       DOUBLE PRECISION   AJJ
100 *     ..
101 *     .. External Functions ..
102       LOGICAL            LSAME
103       EXTERNAL           LSAME
104 *     ..
105 *     .. External Subroutines ..
106       EXTERNAL           DSCAL, DSYR, XERBLA
107 *     ..
108 *     .. Intrinsic Functions ..
109       INTRINSIC          MAXMINSQRT
110 *     ..
111 *     .. Executable Statements ..
112 *
113 *     Test the input parameters.
114 *
115       INFO = 0
116       UPPER = LSAME( UPLO, 'U' )
117       IF.NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN
118          INFO = -1
119       ELSE IF( N.LT.0 ) THEN
120          INFO = -2
121       ELSE IF( KD.LT.0 ) THEN
122          INFO = -3
123       ELSE IF( LDAB.LT.KD+1 ) THEN
124          INFO = -5
125       END IF
126       IF( INFO.NE.0 ) THEN
127          CALL XERBLA( 'DPBTF2'-INFO )
128          RETURN
129       END IF
130 *
131 *     Quick return if possible
132 *
133       IF( N.EQ.0 )
134      $   RETURN
135 *
136       KLD = MAX1, LDAB-1 )
137 *
138       IF( UPPER ) THEN
139 *
140 *        Compute the Cholesky factorization A = U**T*U.
141 *
142          DO 10 J = 1, N
143 *
144 *           Compute U(J,J) and test for non-positive-definiteness.
145 *
146             AJJ = AB( KD+1, J )
147             IF( AJJ.LE.ZERO )
148      $         GO TO 30
149             AJJ = SQRT( AJJ )
150             AB( KD+1, J ) = AJJ
151 *
152 *           Compute elements J+1:J+KN of row J and update the
153 *           trailing submatrix within the band.
154 *
155             KN = MIN( KD, N-J )
156             IF( KN.GT.0 ) THEN
157                CALL DSCAL( KN, ONE / AJJ, AB( KD, J+1 ), KLD )
158                CALL DSYR( 'Upper', KN, -ONE, AB( KD, J+1 ), KLD,
159      $                    AB( KD+1, J+1 ), KLD )
160             END IF
161    10    CONTINUE
162       ELSE
163 *
164 *        Compute the Cholesky factorization A = L*L**T.
165 *
166          DO 20 J = 1, N
167 *
168 *           Compute L(J,J) and test for non-positive-definiteness.
169 *
170             AJJ = AB( 1, J )
171             IF( AJJ.LE.ZERO )
172      $         GO TO 30
173             AJJ = SQRT( AJJ )
174             AB( 1, J ) = AJJ
175 *
176 *           Compute elements J+1:J+KN of column J and update the
177 *           trailing submatrix within the band.
178 *
179             KN = MIN( KD, N-J )
180             IF( KN.GT.0 ) THEN
181                CALL DSCAL( KN, ONE / AJJ, AB( 2, J ), 1 )
182                CALL DSYR( 'Lower', KN, -ONE, AB( 2, J ), 1,
183      $                    AB( 1, J+1 ), KLD )
184             END IF
185    20    CONTINUE
186       END IF
187       RETURN
188 *
189    30 CONTINUE
190       INFO = J
191       RETURN
192 *
193 *     End of DPBTF2
194 *
195       END