1 subroutine da_ludcmp(n, np, indx, a, d)
3 !-----------------------------------------------------------------------
4 ! Purpose: Adapted Numerical Recipes routine to solve the set of n linear
6 ! A.X=B. Routine takes in to account possibility that B will begin with many
7 ! zero elements, so it is efficient for matrix inversion.
8 !-----------------------------------------------------------------------
12 integer, intent(in) :: n ! Logical size of array.
13 integer, intent(in) :: np ! Physical size of array.
14 integer, intent(out) :: indx(1:n) ! Permutation vector returned by LUDCMP
15 real, intent(inout) :: a(1:np,1:np)! LU decomposition of matrix A in A.x=B
16 real, intent(out) :: d ! On input = B, on output = x.
18 real, parameter :: tiny = 1.0e-20
19 real :: aamax , dum , sum
20 integer :: i , imax , j , k
23 if (trace_use) call da_trace_entry("da_ludcmp")
30 if (abs(a(i,j)) > aamax) aamax = abs(a(i,j))
32 if (aamax == 0.0) then
33 call da_error(__FILE__,__LINE__,(/"Singular matrix"/))
44 sum = sum - a(i,k) * a(k,j)
56 sum = sum - a(i,k) * a(k,j)
60 dum = vv(i) * abs(sum)
61 if (dum >= aamax) then
79 if (a(j,j) == 0.0) a(j,j) = tiny
87 if (a(n,n) == 0.0) a(n,n) = tiny
89 if (trace_use) call da_trace_exit("da_ludcmp")
91 end subroutine da_ludcmp