summaryrefslogtreecommitdiff
path: root/Utilib/src/ALST2F.f
blob: fe74a74a5852ffa61e1c416a02a667e1a9c2b917 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
*DECK ALST2F
      SUBROUTINE ALST2F(MDIM,M,N,A,TAU)
*
*-----------------------------------------------------------------------
*
*Purpose:
* to obtain the QR factorization of the matrix a using Householder
* transformations. Use LAPACK's DGEQRF routine storage. Douple precision
* routine.
*
*Copyright:
* Copyright (C) 1993 Ecole Polytechnique de Montreal
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version
*
*Author(s): A. Hebert
*
*Reference:
* P.A. BUSINGER, Num. Math. 7, 269-276 (1965).
*
*Parameters: input
* MDIM    dimensioned column length of A.
* M       number of rows of A
* N       number of columns of A. N.le.M is assumed.
* A       matrix A.
*
*Parameters: output
* A       decomposed matrix. On exit, the elements on and above the
*         diagonal of the array contain the m by n upper trapezoidal
*         matrix R (R is upper triangular if m >= n); the elements
*         below the diagonal, with the array TAU, represent the
*         orthogonal matrix Q as a product of elementary reflectors.
* TAU     scalar factors of the elementary reflectors.
*
*-----------------------------------------------------------------------
*
      IMPLICIT REAL(KIND=8)(A-H,O-Z)
*----
*  SUBROUTINE ARGUMENTS
*----
      INTEGER MDIM,M,N
      REAL(KIND=8) A(MDIM,N),TAU(N)
*----
*  LOCAL VARIABLES
*----
      CHARACTER HSMG*131
*----
*  ALLOCATABLE ARRAYS
*----
      REAL(KIND=8), ALLOCATABLE, DIMENSION(:,:) :: W
*----
*  CHECK THE INPUT
*----
      IF(MDIM.LT.M) CALL XABORT('ALST2F: MDIM.LT.M')
      IF(N.LT.1) CALL XABORT('ALST2F: N.LT.1')
      IF(N.GT.M) THEN
         WRITE(HSMG,'(18HALST2F: N.GT.M (N=,I3,3H M=,I3,2H).)') N,M
         CALL XABORT(HSMG)
      ENDIF
*----
*  PERFORM QR FACTORIZATION.
*----
      ALLOCATE(W(M,1))
      DO J=1,N
        M1 = M-J+1; W(:M1,1) = A(J:M,J); X1 = W(1,1);
        AX = SQRT(DOT_PRODUCT(W(:M1,1),W(:M1,1)))
        A1 = ABS(X1); S = SIGN(1.0D0,W(1,1));
        SSSS = -AX*S; A1 = A1+AX;
        W(1,1) = A1*S
        DD2 = A1*AX
        IF(DD2 == 0.0D0) CALL XABORT('ALST2F: SINGULAR REFLECTION')
        W(:M1,1) = W(:M1,1)/SQRT(DD2)
        A(J:M,J) = W(:M1,1)
        IF(J < N) THEN
          A(J:M,J+1:N) = A(J:M,J+1:N)
     1      -MATMUL(W(:M1,:),(MATMUL(TRANSPOSE(W(:M1,:)),A(J:M,J+1:N))))
        ENDIF
        DIAG = A(J,J)
        A(J:M,J) = A(J:M,J)/DIAG
        A(J,J) = SSSS
        TAU(J) = -DIAG*DIAG
      ENDDO
      DEALLOCATE(W)
      RETURN
      END