NCEPLIBS-sp  2.5.0
lapack_gen.F
Go to the documentation of this file.
1 C> @file
2 C> @brief Two Numerical Recipes routines for matrix inversion From Numerical Recipes.
3 C>
4 C> ### Program History Log
5 C> Date | Programmer | Comments
6 C> -----|------------|---------
7 C> 2012-11-05 | E.Mirvis | separated this generic LU from the splat.F
8 
9 C> Solves a system of linear equations, follows call to ludcmp().
10 C>
11 C> @param A
12 C> @param N
13 C> @param NP
14 C> @param INDX
15 C> @param B
16  SUBROUTINE lubksb(A,N,NP,INDX,B)
17  REAL A(NP,NP),B(N)
18  INTEGER INDX(N)
19  ii=0
20  DO 12 i=1,n
21  ll=indx(i)
22  sum=b(ll)
23  b(ll)=b(i)
24  IF (ii.NE.0)THEN
25  DO 11 j=ii,i-1
26  sum=sum-a(i,j)*b(j)
27  11 CONTINUE
28  ELSE IF (sum.NE.0.) THEN
29  ii=i
30  ENDIF
31  b(i)=sum
32  12 CONTINUE
33  DO 14 i=n,1,-1
34  sum=b(i)
35  IF(i.LT.n)THEN
36  DO 13 j=i+1,n
37  sum=sum-a(i,j)*b(j)
38  13 CONTINUE
39  ENDIF
40  b(i)=sum/a(i,i)
41  14 CONTINUE
42  RETURN
43  END
44 
45 C> Replaces an NxN matrix a with the LU decomposition.
46 C>
47 C> @param A
48 C> @param N
49 C> @param NP
50 C> @param INDX
51  SUBROUTINE ludcmp(A,N,NP,INDX)
52 C PARAMETER (NMAX=400,TINY=1.0E-20)
53  parameter(tiny=1.0e-20)
54 C==EM==^^^
55 C
56  REAL A(NP,NP),VV(N),D
57 C REAL A(NP,NP),VV(NMAX),D
58 C==EM==^^^
59  INTEGER INDX(N)
60  d=1.
61  DO 12 i=1,n
62  aamax=0.
63  DO 11 j=1,n
64  IF (abs(a(i,j)).GT.aamax) aamax=abs(a(i,j))
65  11 CONTINUE
66  IF (aamax.EQ.0.) print *, 'SINGULAR MATRIX.'
67  vv(i)=1./aamax
68  12 CONTINUE
69  DO 19 j=1,n
70  IF (j.GT.1) THEN
71  DO 14 i=1,j-1
72  sum=a(i,j)
73  IF (i.GT.1)THEN
74  DO 13 k=1,i-1
75  sum=sum-a(i,k)*a(k,j)
76  13 CONTINUE
77  a(i,j)=sum
78  ENDIF
79  14 CONTINUE
80  ENDIF
81  aamax=0.
82  DO 16 i=j,n
83  sum=a(i,j)
84  IF (j.GT.1)THEN
85  DO 15 k=1,j-1
86  sum=sum-a(i,k)*a(k,j)
87  15 CONTINUE
88  a(i,j)=sum
89  ENDIF
90  dum=vv(i)*abs(sum)
91  IF (dum.GE.aamax) THEN
92  imax=i
93  aamax=dum
94  ENDIF
95  16 CONTINUE
96  IF (j.NE.imax)THEN
97  DO 17 k=1,n
98  dum=a(imax,k)
99  a(imax,k)=a(j,k)
100  a(j,k)=dum
101  17 CONTINUE
102  d=-d
103  vv(imax)=vv(j)
104  ENDIF
105  indx(j)=imax
106  IF(j.NE.n)THEN
107  IF(a(j,j).EQ.0.)a(j,j)=tiny
108  dum=1./a(j,j)
109  DO 18 i=j+1,n
110  a(i,j)=a(i,j)*dum
111  18 CONTINUE
112  ENDIF
113  19 CONTINUE
114  IF(a(n,n).EQ.0.)a(n,n)=tiny
115  RETURN
116  END
subroutine ludcmp(A, N, NP, INDX)
Replaces an NxN matrix a with the LU decomposition.
Definition: lapack_gen.F:52
subroutine lubksb(A, N, NP, INDX, B)
Solves a system of linear equations, follows call to ludcmp().
Definition: lapack_gen.F:17