summaryrefslogtreecommitdiff
path: root/Utilib/src/ALINVD.f
blob: f059773e922f82624574dcaa47991d9b51e2549f (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
88
89
90
91
92
*DECK ALINVD
      SUBROUTINE ALINVD(N,A,MAX,IER)
*
*-----------------------------------------------------------------------
*
*Purpose:
* in-place inversion of a non singular matrix using gaussian elimination
* with partial pivoting. Double precision version.
*
*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
*
*Parameters: input
* N       order of the coefficient matrix.
* A       coefficient matrix to be inverted.
* MAX     first dimention of matrix A.
*
*Parameters: output
* A       inverted matrix.
* IER     error flag (execution failure if IER.ne.0).
*
*-----------------------------------------------------------------------
*
      IMPLICIT DOUBLE PRECISION (A-H,O-Z)
*----
*  SUBROUTINE ARGUMENTS
*----
      INTEGER N,MAX,IER
      DOUBLE PRECISION A(MAX,N)
*----
*  ALLOCATABLE ARRAY
*----
      INTEGER, DIMENSION(:), ALLOCATABLE :: IND
*
      ALLOCATE(IND(N))
      IN=0
      IER=0
      DO 1 I=1,N
      IND(I)=I
1     CONTINUE
      DO 12 J=1,N
      TEST=0.0D0
      DO 2 I=J,N
      IF (ABS(A(I,J)).LE.TEST) GO TO 2
      TEST=ABS(A(I,J))
      IN=I
2     CONTINUE
      IF (TEST.NE.0.0D0) GO TO 3
      IER=1
      DEALLOCATE(IND)
      RETURN
3     PMX=A(IN,J)
      A(IN,J)=1.0D0
      DO 4 I=1,N
      PER=A(IN,I)/PMX
      A(IN,I)=A(J,I)
      A(J,I)=PER
4     CONTINUE
      IPER=IND(IN)
      IND(IN)=IND(J)
      IND(J)=IPER
      DO 11 I=1,N
      IF (I.EQ.J) GO TO 11
      PMX=A(I,J)
      A(I,J)=0.0D0
      DO 9 K=1,N
      A(I,K)=A(I,K)-PMX*A(J,K)
9     CONTINUE
11    CONTINUE
12    CONTINUE
      DO 16 J=1,N
      DO 13 K=J,N
      IF (IND(K).NE.J) GO TO 13
      IN=K
      GO TO 14
13    CONTINUE
14    DO 15 I=1,N
      PER=A(I,J)
      A(I,J)=A(I,IN)
      A(I,IN)=PER
      IND(IN)=IND(J)
15    CONTINUE
16    CONTINUE
      DEALLOCATE(IND)
      RETURN
      END