| 1 | !----------------------------------------------------------------------- |
| 2 | !----------------------------------------------------------------------- |
| 3 | ! Floquet Multiplier Computation (Tom Fairgrieve, U. of Toronto) |
| 4 | !----------------------------------------------------------------------- |
| 5 | !----------------------------------------------------------------------- |
| 6 | ! References: |
| 7 | ! T. F. Fairgrieve, PhD Thesis, University of Toronto, 1994. |
| 8 | ! |
| 9 | ! T. F. Fairgrieve, A. D. Jepson, O.K. Floquet multipliers, |
| 10 | ! SIAM J. Numer. Anal. 28. No. 5, 1991, 1446-1462. |
| 11 | ! |
| 12 | ! Please inform Tom Fairgrieve ([email protected]) of any |
| 13 | ! modifications to or errors in these routines. |
| 14 | ! Mailing Address: T.F. Fairgrieve, Department of Computer Science, |
| 15 | ! University of Toronto, Toronto, Ontario, CANADA M5S 1A4C |
| 16 | !----------------------------------------------------------------------- |
| 17 | !----------------------------------------------------------------------- |
| 18 | ! Routines included in this file: |
| 19 | ! |
| 20 | ! subroutine flowkm : new routine to compute floquet multipliers |
| 21 | ! subroutine dhhpr : compute a Householder matrix |
| 22 | ! subroutine dhhap : appy a Householder matrix |
| 23 | !----------------------------------------------------------------------- |
| 24 | !----------------------------------------------------------------------- |
| 25 | ! Required library routines (included in the file eispack.f) : |
| 26 | ! |
| 27 | ! subroutine qzhes : QZ reduction to Hessenberg form (EISPACK) |
| 28 | ! subroutine qzit : QZ reduction to quasi-upper triangular form (EISPACK) |
| 29 | ! subroutine qzval : QZ calculation of eigenvalues (EISPACK) |
| 30 | ! function epslon : machine constant routine (EISPACK) |
| 31 | !----------------------------------------------------------------------- |
| 32 | !----------------------------------------------------------------------- |
| 33 | ! function dnrm2 : compute l2-norm of a vector (BLAS-1) |
| 34 | ! function ddot : dot product of two vectors (BLAS-1) |
| 35 | ! subroutine dscal : scale a vector by a constant (BLAS-1) |
| 36 | ! function idamax : find index of element with max abs value (BLAS-1) |
| 37 | ! subroutine daxpy : constant times a vector plus a vector (BLAS-1) |
| 38 | ! subroutine drot : apply a plane rotation (BLAS-1) |
| 39 | ! subroutine dswap : swap two vectors (BLAS-1) |
| 40 | !----------------------------------------------------------------------- |
| 41 | !----------------------------------------------------------------------- |
| 42 | ! subroutine xerbla : BLAS error handling routine (BLAS-2) |
| 43 | ! function lsame : compare character strings (BLAS-2) |
| 44 | !----------------------------------------------------------------------- |
| 45 | !----------------------------------------------------------------------- |
| 46 | ! subroutine dgemm : matrix-matrix multiply (BLAS-3) |
| 47 | !----------------------------------------------------------------------- |
| 48 | !----------------------------------------------------------------------- |
| 49 | ! subroutines ezsvd, ndrotg, ndsvd, prse, sig22, sigmin, sndrtg : |
| 50 | ! Demmel-Kahan svd routines |
| 51 | !----------------------------------------------------------------------- |
| 52 | !----------------------------------------------------------------------- |
| 53 | |
| 54 | MODULE FLOQUET |
| 55 | |
| 56 | IMPLICIT NONE |
| 57 | |
| 58 | PRIVATE |
| 59 | |
| 60 | PUBLIC :: FLOWKM |
| 61 | |
| 62 | CONTAINS |
| 63 | |
| 64 | SUBROUTINE FLOWKM (NDIM, P0, P1, IID, EV) |
| 65 | |
| 66 | ! Subroutine to compute Floquet multipliers via the "deflated circuit |
| 67 | ! pencil" method. This routine is called by the AUTO routine FNSPBV |
| 68 | |
| 69 | ! Parameter declarations: |
| 70 | |
| 71 | INTEGER, INTENT(IN) :: NDIM, IID |
| 72 | DOUBLE PRECISION, INTENT(IN) :: P0(NDIM, NDIM), P1(NDIM, NDIM) |
| 73 | COMPLEX(KIND(1.0D0)), INTENT(OUT) :: EV(NDIM) |
| 74 | |
| 75 | ! Local declarations: |
| 76 | |
| 77 | |
| 78 | ! Maximum order of problem. **** (To avoid changing too many AUTO'86 |
| 79 | ! routines, I need to declare some local array storage here ) |
| 80 | |
| 81 | INTEGER LEFT, RIGHT |
| 82 | PARAMETER (LEFT = 1, RIGHT = 2) |
| 83 | |
| 84 | INTEGER I, J, NDIMM1 |
| 85 | DOUBLE PRECISION X(:),BETA,V(:),C0(:,:),C1(:,:),RWORK(:,:), & |
| 86 | NRMC0X, NRMC1X, CONST |
| 87 | LOGICAL INFEV |
| 88 | |
| 89 | ! storage for SVD computations |
| 90 | |
| 91 | INTEGER SVDINF, SVDLWRK |
| 92 | DOUBLE PRECISION SVDS(:), SVDE(:), SVDWRK(:), SVDV(:,:) |
| 93 | ALLOCATABLE C0,C1,RWORK,X,V,SVDS,SVDE,SVDWRK,SVDV |
| 94 | ! compute right singular vectors only |
| 95 | CHARACTER(1), PARAMETER :: SVDJOBA = 'G', SVDJOBU = 'N', SVDJOBV = 'V' |
| 96 | |
| 97 | ! storage for generalized eigenvalue computations |
| 98 | |
| 99 | INTEGER QZIERR |
| 100 | DOUBLE PRECISION QZZ(1, 1), QZEPS1, QZALFR(:), QZALFI(:), QZBETA(:) |
| 101 | ALLOCATABLE QZALFR,QZALFI,QZBETA |
| 102 | LOGICAL QZMATZ |
| 103 | ! don't want to accumulate the transforms --- vectors not needed |
| 104 | PARAMETER (QZMATZ = .FALSE.) |
| 105 | PARAMETER (QZEPS1 = 0.0D0) |
| 106 | |
| 107 | ! BLAS routines |
| 108 | |
| 109 | DOUBLE PRECISION DNRM2 |
| 110 | EXTERNAL DNRM2, DGEMM |
| 111 | |
| 112 | ! routines from LAPACK |
| 113 | |
| 114 | EXTERNAL DGESVJ, DGGEV |
| 115 | |
| 116 | ! builtin F77 functions |
| 117 | |
| 118 | INTRINSIC MAX, ABS, CMPLX |
| 119 | |
| 120 | SVDLWRK = MAX(6,2*NDIM) |
| 121 | ALLOCATE(C0(NDIM,NDIM),C1(NDIM,NDIM),RWORK(NDIM,NDIM)) |
| 122 | ALLOCATE(SVDE(NDIM),SVDS(NDIM+1),SVDV(NDIM,NDIM),V(NDIM),X(NDIM)) |
| 123 | ALLOCATE(QZALFI(NDIM),QZBETA(NDIM),QZALFR(NDIM),SVDWRK(SVDLWRK)) |
| 124 | |
| 125 | ! Change sign of P1 so that we get the sign of the multipliers right. |
| 126 | |
| 127 | C0=P0 |
| 128 | C1=-P1 |
| 129 | |
| 130 | ! Print the undeflated circuit pencil (C0, C1). |
| 131 | |
| 132 | IF(IID>4) THEN |
| 133 | WRITE(9,101) |
| 134 | WRITE(9,102) |
| 135 | DO I=1,NDIM |
| 136 | WRITE(9,104)(C0(I,J),J=1,NDIM) |
| 137 | ENDDO |
| 138 | WRITE(9,103) |
| 139 | DO I=1,NDIM |
| 140 | WRITE(9,104)(C1(I,J),J=1,NDIM) |
| 141 | ENDDO |
| 142 | END IF |
| 143 | |
| 144 | ! PART I: |
| 145 | ! ======= |
| 146 | |
| 147 | ! Deflate the Floquet multiplier at +1.0 so that the deflated |
| 148 | ! circuit pencil is not defective at periodic branch turning points. |
| 149 | |
| 150 | ! The matrix (C0 - C1) should be (nearly) singular. Find an approximation |
| 151 | ! to the right null vector (call it X). This will be our approximation |
| 152 | ! to the eigenvector corresponding to the fixed multiplier at +1.0. |
| 153 | ! |
| 154 | ! There are many ways to get this approximation. We could use |
| 155 | ! 1) p'(0) = f(p(0)) |
| 156 | ! 2) AUTO'86 routine NLVC applied to C0-C1 |
| 157 | ! 3) the right singular vector corresponding to the smallest |
| 158 | ! singular value of C0-C1 |
| 159 | |
| 160 | ! I've chosen option 3) because it should introduce as little roundoff |
| 161 | ! error as possible. Although it is more expensive, this is insignificant |
| 162 | ! relative to the rest of the AUTO computations. Also, the SVD does give a |
| 163 | ! version of the Householder matrix which we would have to compute |
| 164 | ! anyways. But note that it gives V = ( X perp | X ) and not (X | Xperp), |
| 165 | ! which the Householder routine would give. This will permute the deflated |
| 166 | ! circuit pencil, so that the part to be deflated is in the last column, |
| 167 | ! not it the first column, as was shown in the paper. |
| 168 | |
| 169 | RWORK = C0 - C1 |
| 170 | |
| 171 | CALL DGESVJ( SVDJOBA, SVDJOBU, SVDJOBV, NDIM, NDIM, RWORK, NDIM, & |
| 172 | SVDS, 0, SVDV, NDIM, SVDWRK, SVDLWRK, SVDINF ) |
| 173 | IF (SVDINF /= 0) WRITE (9, 901) SVDINF |
| 174 | |
| 175 | ! Apply a Householder matrix (call it H1) based on the null vector |
| 176 | ! to (C0, C1) from the right. H1 = SVDV = ( Xperp | X ), where X |
| 177 | ! is the null vector. |
| 178 | |
| 179 | CALL DGEMM ( 'n', 'n', NDIM, NDIM, NDIM, 1.0d0, C0, NDIM, & |
| 180 | SVDV, NDIM, 0.0d0, RWORK, NDIM ) |
| 181 | C0 = RWORK |
| 182 | CALL DGEMM ( 'n', 'n', NDIM, NDIM, NDIM, 1.0d0, C1, NDIM, & |
| 183 | SVDV, NDIM, 0.0d0, RWORK, NDIM ) |
| 184 | C1 = RWORK |
| 185 | |
| 186 | ! Apply a Householder matrix (call it H2) based on |
| 187 | ! (C0*X/||C0*X|| + C1*X/||C1*X||) / 2 |
| 188 | ! to (C0*H1, C1*H1) from the left. |
| 189 | |
| 190 | NRMC0X = DNRM2( NDIM, C0(1,NDIM), 1) |
| 191 | NRMC1X = DNRM2( NDIM, C1(1,NDIM), 1) |
| 192 | DO I = 1, NDIM |
| 193 | X(I) = ((C0(I,NDIM)/NRMC0X)+(C1(I,NDIM)/NRMC1X)) / 2.0D0 |
| 194 | ENDDO |
| 195 | CALL DHHPR ( 1, NDIM, NDIM, X, 1, BETA, V ) |
| 196 | CALL DHHAP ( 1, NDIM, NDIM, NDIM, BETA, V, LEFT, C0, NDIM) |
| 197 | CALL DHHAP ( 1, NDIM, NDIM, NDIM, BETA, V, LEFT, C1, NDIM) |
| 198 | |
| 199 | ! Rescale so that (H2^T)*C0*(H1)(1,NDIM) ~= (H2^T)*C1*(H1)(1,NDIM) ~= 1.0 |
| 200 | |
| 201 | CONST = MAX(ABS(C0(1,NDIM)), ABS(C1(1,NDIM))) |
| 202 | DO J = 1, NDIM |
| 203 | DO I = 1, NDIM |
| 204 | C0(I,J) = C0(I,J) / CONST |
| 205 | C1(I,J) = C1(I,J) / CONST |
| 206 | ENDDO |
| 207 | ENDDO |
| 208 | |
| 209 | ! Finished the deflation process! Print the deflated circuit pencil. |
| 210 | |
| 211 | IF(IID>4) THEN |
| 212 | WRITE(9,105) |
| 213 | WRITE(9,106) |
| 214 | DO I=1,NDIM |
| 215 | WRITE(9,104)(C0(I,J),J=1,NDIM) |
| 216 | ENDDO |
| 217 | WRITE(9,107) |
| 218 | DO I=1,NDIM |
| 219 | WRITE(9,104)(C1(I,J),J=1,NDIM) |
| 220 | ENDDO |
| 221 | END IF |
| 222 | |
| 223 | ! At this point we have |
| 224 | |
| 225 | ! (C0Bar, C1Bar) |
| 226 | ! ::= (H2^T)*(C0, C1)*(H1). |
| 227 | |
| 228 | ! (( B0^T | Beta0 ) ( B1^T | Beta1 )) 1 |
| 229 | ! = (( ----------------- ), ( ----------------- )) |
| 230 | ! (( C0BarDef | Delta0 ) ( C1BarDef | Delta1 )) NDIM-1 |
| 231 | |
| 232 | ! NDIM-1 1 NDIM-1 1 |
| 233 | |
| 234 | ! and approximations to the Floquet multipliers are |
| 235 | ! (Beta0/Beta1) union the eigenvalues of the deflated pencil |
| 236 | ! (C0BarDef, C1BarDef). |
| 237 | |
| 238 | ! PART II: |
| 239 | ! ======== |
| 240 | |
| 241 | ! Compute the eigenvalues of the deflated circuit pencil |
| 242 | ! (C0BarDef, C1BarDef) |
| 243 | ! by using the QZ routines from EISPACK. |
| 244 | |
| 245 | NDIMM1 = NDIM - 1 |
| 246 | |
| 247 | ! compute the eigenvalues for the generalized eigenvalue problem |
| 248 | |
| 249 | CALL DGGEV('N', 'N', NDIMM1, C0(2,1), NDIM, C1(2,1), NDIM, QZALFR, & |
| 250 | QZALFI, QZBETA, QZZ, 1, QZZ, 1, SVDWRK, -1, QZIERR) |
| 251 | SVDLWRK = NINT(SVDWRK(1)) |
| 252 | DEALLOCATE(SVDWRK) |
| 253 | ALLOCATE(SVDWRK(SVDLWRK)) |
| 254 | CALL DGGEV('N', 'N', NDIMM1, C0(2,1), NDIM, C1(2,1), NDIM, QZALFR, & |
| 255 | QZALFI, QZBETA, QZZ, 1, QZZ, 1, SVDWRK, SVDLWRK, QZIERR) |
| 256 | IF (QZIERR /= 0) WRITE (9, 902) QZIERR |
| 257 | |
| 258 | ! Pack the eigenvalues into complex form. |
| 259 | |
| 260 | EV(1) = CMPLX( C0(1,NDIM) / C1(1,NDIM), 0.0D0, KIND(1.0D0) ) |
| 261 | INFEV = .FALSE. |
| 262 | DO J = 1, NDIMM1 |
| 263 | IF (QZBETA(J) /= 0.0D0) THEN |
| 264 | EV(J+1) = CMPLX( QZALFR(J)/QZBETA(J), QZALFI(J)/QZBETA(J), & |
| 265 | KIND(1.0D0) ) |
| 266 | ELSE |
| 267 | EV(J+1) = CMPLX( HUGE(1.0D0), HUGE(1.0D0), KIND(1.0D0) ) |
| 268 | INFEV = .TRUE. |
| 269 | END IF |
| 270 | ENDDO |
| 271 | IF (INFEV) WRITE (9, 903) |
| 272 | |
| 273 | ! Done! |
| 274 | |
| 275 | DEALLOCATE(C0,C1,RWORK,X,V,SVDS,SVDE,SVDWRK,SVDV,QZALFR,QZALFI,QZBETA) |
| 276 | |
| 277 | ! Format statements |
| 278 | |
| 279 | 101 FORMAT(' Undeflated circuit pencil (C0, C1) ') |
| 280 | 102 FORMAT(' C0 : ') |
| 281 | 103 FORMAT(' C1 : ') |
| 282 | 104 FORMAT(1X,6E23.16) |
| 283 | 105 FORMAT(' Deflated circuit pencil (H2^T)*(C0, C1)*(H1) ') |
| 284 | 106 FORMAT(' (H2^T)*C0*(H1) : ') |
| 285 | 107 FORMAT(' (H2^T)*C1*(H1) : ') |
| 286 | 901 FORMAT(' NOTE : Warning from subroutine FLOWKM : ', & |
| 287 | /,' SVD routine returned SVDINF = ', I4, & |
| 288 | /,' Floquet multiplier calculations may be wrong') |
| 289 | 902 FORMAT(' NOTE : Warning from subroutine FLOWKM : ', & |
| 290 | /,' QZ routine returned QZIERR = ', I4, & |
| 291 | /,' Floquet multiplier calculations may be wrong ') |
| 292 | 903 FORMAT(' NOTE : Warning from subroutine FLOWKM : ', & |
| 293 | /,' Infinite Floquet multiplier represented by ', & |
| 294 | /,' CMPLX( HUGE(1.0D0), HUGE(1.0D0) )') |
| 295 | |
| 296 | END SUBROUTINE FLOWKM |
| 297 | |
| 298 | ! ************************** |
| 299 | ! * Householder routines * |
| 300 | ! ************************** |
| 301 | |
| 302 | |
| 303 | ! Subroutines for performing Householder plane rotations. |
| 304 | |
| 305 | ! DHHPR: for computing Householder transformations and |
| 306 | ! DHHAP: for applying them. |
| 307 | |
| 308 | ! Ref: Golub and van Loan, Matrix Calcualtions, |
| 309 | ! First Edition, Pages 38-43 |
| 310 | |
| 311 | SUBROUTINE DHHPR ( K, J, N, X, INCX, BETA, V ) |
| 312 | USE SUPPORT, ONLY: AUTOSTOP |
| 313 | ! .. Scalar Arguments .. |
| 314 | INTEGER, INTENT(IN) :: J, K, N, INCX |
| 315 | DOUBLE PRECISION, INTENT(OUT) :: BETA |
| 316 | ! .. Array Arguments .. |
| 317 | DOUBLE PRECISION, INTENT(IN) :: X( * ) |
| 318 | DOUBLE PRECISION, INTENT(INOUT) :: V( * ) |
| 319 | ! .. |
| 320 | |
| 321 | ! Purpose |
| 322 | ! ======= |
| 323 | |
| 324 | ! DHHPR computes a Householder Plane Rotation (G&vL Alg. 3.3-1) |
| 325 | ! defined by v and beta. |
| 326 | ! (I - beta v vt) * x is such that x_i = 0 for i=k+1 to j. |
| 327 | |
| 328 | ! Parameters |
| 329 | ! ========== |
| 330 | |
| 331 | ! K - INTEGER. |
| 332 | ! On entry, K specifies that the K+1st entry of X |
| 333 | ! be the first to be zeroed. |
| 334 | ! K must be at least one. |
| 335 | ! Unchanged on exit. |
| 336 | |
| 337 | ! J - INTEGER. |
| 338 | ! On entry, J specifies the last entry of X to be zeroed. |
| 339 | ! J must be >= K and <= N. |
| 340 | ! Unchanged on exit. |
| 341 | |
| 342 | ! N - INTEGER. |
| 343 | ! On entry, N specifies the (logical) length of X. |
| 344 | ! Unchanged on exit. |
| 345 | |
| 346 | ! X - DOUBLE PRECISION array of DIMENSION at least |
| 347 | ! ( 1 + ( N - 1 )*abs( INCX ) ). |
| 348 | ! On entry, X specifies the vector to be (partially) zeroed. |
| 349 | ! Unchanged on exit. |
| 350 | |
| 351 | ! INCX - INTEGER. |
| 352 | ! On entry, INCX specifies the increment for the elements of |
| 353 | ! X. INCX must be > zero. If X represents part of a matrix, |
| 354 | ! then use INCX = 1 if a column vector is being zeroed and |
| 355 | ! INCX = NDIM if a row vector is being zeroed. |
| 356 | ! Unchanged on exit. |
| 357 | |
| 358 | ! BETA - DOUBLE PRECISION. |
| 359 | ! BETA specifies the scalar beta. (see pg. 40 of G and v.L.) |
| 360 | |
| 361 | ! V - DOUBLE PRECISION array of DIMENSION at least n. |
| 362 | ! Is updated to be the appropriate Householder vector for |
| 363 | ! the given problem. (Note: space for the implicit zeroes is |
| 364 | ! assumed to be present. Will save on time for index translation.) |
| 365 | |
| 366 | ! -- Written by Tom Fairgrieve, |
| 367 | ! Department of Computer Science, |
| 368 | ! University of Toronto, |
| 369 | ! Toronto, Ontario CANADA M5S 1A4 |
| 370 | |
| 371 | ! .. Local Scalars .. |
| 372 | DOUBLE PRECISION ALPHA, M |
| 373 | INTEGER I, L, JMKP1, IEND, ISTART |
| 374 | ! .. External Functions from BLAS .. |
| 375 | INTEGER IDAMAX |
| 376 | DOUBLE PRECISION DNRM2 |
| 377 | EXTERNAL IDAMAX, DNRM2 |
| 378 | ! .. External Subroutines from BLAS .. |
| 379 | EXTERNAL DSCAL |
| 380 | ! .. Intrinsic Functions .. |
| 381 | INTRINSIC ABS, SIGN |
| 382 | |
| 383 | ! .. Executable Statements .. |
| 384 | |
| 385 | ! Test the input parameters. |
| 386 | |
| 387 | IF ((K < 1) .OR. (K > J)) THEN |
| 388 | WRITE (9,*) 'Domain error for K in DHHPR' |
| 389 | CALL AUTOSTOP() |
| 390 | END IF |
| 391 | IF (J > N) THEN |
| 392 | WRITE (9,*) 'Domain error for J in DHHPR' |
| 393 | CALL AUTOSTOP() |
| 394 | END IF |
| 395 | IF (INCX < 1) THEN |
| 396 | WRITE (9,*) 'Domain error for INCX in DHHPR' |
| 397 | CALL AUTOSTOP() |
| 398 | END IF |
| 399 | |
| 400 | ! Number of potential non-zero elements in V. |
| 401 | |
| 402 | JMKP1 = J - K + 1 |
| 403 | |
| 404 | ! Find M := max{ |x_k|, ... , |x_j| } |
| 405 | |
| 406 | M = ABS( X( IDAMAX( JMKP1, X(K), INCX ) ) ) |
| 407 | |
| 408 | ! alpha := 0 |
| 409 | ! For i = k to j |
| 410 | ! v_i = x_i / m |
| 411 | ! alpha := alpha + v_i^2 (i.e. alpha = vtv) |
| 412 | ! End For |
| 413 | ! alpha := sqrt( alpha ) |
| 414 | |
| 415 | ! Copy X(K)/M, ... , X(J)/M to V(K), ... , V(J) |
| 416 | |
| 417 | IF (INCX == 1) THEN |
| 418 | DO I = K, J |
| 419 | V(I) = X(I)/M |
| 420 | ENDDO |
| 421 | ELSE |
| 422 | IEND = JMKP1*INCX |
| 423 | ISTART = (K-1)*INCX + 1 |
| 424 | L = K |
| 425 | DO I = ISTART, IEND, INCX |
| 426 | V(L) = X(I)/M |
| 427 | L = L + 1 |
| 428 | ENDDO |
| 429 | END IF |
| 430 | |
| 431 | ! Compute alpha |
| 432 | |
| 433 | ALPHA = DNRM2(JMKP1, V(K), 1) |
| 434 | |
| 435 | ! beta := 1/(alpha(alpha + |V_k|)) |
| 436 | |
| 437 | BETA = 1.0D0 / (ALPHA*(ALPHA+ABS(V(K)))) |
| 438 | |
| 439 | ! v_k := v_k + sign(v_k)*alpha |
| 440 | |
| 441 | V(K) = V(K) + SIGN(1.0D0,V(K))*ALPHA |
| 442 | |
| 443 | ! Done ! |
| 444 | ! End of DHHPR. |
| 445 | |
| 446 | END SUBROUTINE DHHPR |
| 447 | |
| 448 | SUBROUTINE DHHAP ( K, J, N, Q, BETA, V, JOB, A, LDA ) |
| 449 | USE SUPPORT, ONLY: AUTOSTOP |
| 450 | ! .. Scalar Arguments .. |
| 451 | INTEGER, INTENT(IN) :: J, K, N, Q, JOB, LDA |
| 452 | DOUBLE PRECISION, INTENT(IN) :: BETA |
| 453 | ! .. Array Arguments .. |
| 454 | DOUBLE PRECISION, INTENT(IN) :: V( * ) |
| 455 | DOUBLE PRECISION, INTENT(INOUT) :: A( LDA, * ) |
| 456 | ! .. |
| 457 | |
| 458 | ! Purpose |
| 459 | ! ======= |
| 460 | |
| 461 | ! DHHAP applies a Householder Plane Rotation defined by v and beta |
| 462 | ! to the matrix A. If JOB = 1 then A := (I - beta*v*vt)A and if |
| 463 | ! JOB = 2 then A := A(I - beta*v*vt). (See Golub and van Loan |
| 464 | ! Alg. 3.3-2.) |
| 465 | |
| 466 | ! Parameters |
| 467 | ! ========== |
| 468 | |
| 469 | ! K - INTEGER. |
| 470 | ! On entry, K specifies that the V(K) may be the first |
| 471 | ! non-zero entry of V. |
| 472 | ! K must be at least one. |
| 473 | ! Unchanged on exit. |
| 474 | |
| 475 | ! J - INTEGER. |
| 476 | ! On entry, J specifies the last non-zero entry of V. |
| 477 | ! J must be >= K and <= N. |
| 478 | ! Unchanged on exit. |
| 479 | |
| 480 | ! N - INTEGER. |
| 481 | ! On entry, N specifies the row dimension of A. |
| 482 | ! Unchanged on exit. |
| 483 | |
| 484 | ! Q - INTEGER. |
| 485 | ! On entry, Q specifies the column dimension of A. |
| 486 | ! Unchanged on exit. |
| 487 | |
| 488 | ! BETA - DOUBLE PRECISION. |
| 489 | ! BETA specifies the scalar beta. (see pg. 40 of G and v.L.) |
| 490 | ! Unchanged on exit. |
| 491 | |
| 492 | ! V - DOUBLE PRECISION array of DIMENSION at least n. |
| 493 | ! Householder vector v. |
| 494 | ! Unchanged on exit. |
| 495 | |
| 496 | ! JOB - INTEGER. |
| 497 | ! On entry, JOB specifies the order of the Householder application. |
| 498 | ! If JOB = 1 then A := (I - beta*v*vt)A and if JOB = 2 then |
| 499 | ! A := A(I - beta*v*vt) |
| 500 | ! Unchanged on exit. |
| 501 | |
| 502 | ! A - DOUBLE PRECISION array of DIMENSION at least |
| 503 | ! ( LDA, Q ). |
| 504 | ! On entry, A specifies the matrix to be transformed. |
| 505 | ! On exit, A specifies the transformed matrix. |
| 506 | |
| 507 | ! LDA - INTEGER. |
| 508 | ! On entry, LDA specifies the declared leading dimension of A. |
| 509 | ! Unchanged on exit. |
| 510 | |
| 511 | ! -- Written by Tom Fairgrieve, |
| 512 | ! Department of Computer Science, |
| 513 | ! University of Toronto, |
| 514 | ! Toronto, Ontario CANADA M5S 1A4 |
| 515 | |
| 516 | ! .. Local Scalars .. |
| 517 | DOUBLE PRECISION S |
| 518 | INTEGER JMKP1, ROW, COL |
| 519 | ! .. External Functions from BLAS .. |
| 520 | DOUBLE PRECISION DDOT |
| 521 | EXTERNAL DDOT |
| 522 | |
| 523 | ! .. Executable Statements .. |
| 524 | |
| 525 | ! Test the input parameters. |
| 526 | |
| 527 | IF ((JOB /= 1) .AND. (JOB /= 2)) THEN |
| 528 | WRITE (9,*) 'Domain error for JOB in DHHAP' |
| 529 | CALL AUTOSTOP() |
| 530 | END IF |
| 531 | IF ((K < 1) .OR. (K > J)) THEN |
| 532 | WRITE (9,*) 'Domain error for K in DHHAP' |
| 533 | CALL AUTOSTOP() |
| 534 | END IF |
| 535 | IF (JOB == 1) THEN |
| 536 | IF (J > N) THEN |
| 537 | WRITE (9,*) 'Domain error for J in DHHAP' |
| 538 | CALL AUTOSTOP() |
| 539 | END IF |
| 540 | ELSE |
| 541 | IF (J > Q) THEN |
| 542 | WRITE (9,*) 'Domain error for J in DHHAP' |
| 543 | CALL AUTOSTOP() |
| 544 | END IF |
| 545 | END IF |
| 546 | |
| 547 | ! Minimum {row,col} dimension of update. |
| 548 | |
| 549 | JMKP1 = J - K + 1 |
| 550 | |
| 551 | ! If (JOB = 1) then |
| 552 | ! For p = 1, ... , q |
| 553 | ! s := beta*(v_k*a_k,p + ... + v_j*a_j,p) |
| 554 | ! For i = k, ..., j |
| 555 | ! a_i,p := a_i,p - s*v_i |
| 556 | ! End For |
| 557 | ! End For |
| 558 | ! Else % JOB=2 |
| 559 | ! For p = 1, ... , n |
| 560 | ! s := beta*(v_k*a_p,k + ... + v_j*a_p,j) |
| 561 | ! For i = k, ..., j |
| 562 | ! a_p,i := a_p,i - s*v_i |
| 563 | ! End For |
| 564 | ! End For |
| 565 | ! End If |
| 566 | |
| 567 | IF (JOB == 1) THEN |
| 568 | DO COL = 1, Q |
| 569 | S = BETA * DDOT(JMKP1, V(K), 1, A(K, COL), 1) |
| 570 | DO ROW = K, J |
| 571 | A(ROW,COL) = A(ROW,COL) - S*V(ROW) |
| 572 | ENDDO |
| 573 | ENDDO |
| 574 | ELSE |
| 575 | DO ROW = 1, N |
| 576 | S = BETA * DDOT(JMKP1, V(K), 1, A(ROW, K), LDA) |
| 577 | DO COL = K, J |
| 578 | A(ROW,COL) = A(ROW,COL) - S*V(COL) |
| 579 | ENDDO |
| 580 | ENDDO |
| 581 | END IF |
| 582 | |
| 583 | ! Done ! |
| 584 | ! End of DHHAP. |
| 585 | |
| 586 | END SUBROUTINE DHHAP |
| 587 | !----------------------------------------------------------------------- |
| 588 | !----------------------------------------------------------------------- |
| 589 | END MODULE FLOQUET |