1!$Id:$
2      subroutine invert(a,nmax,ndm)
3
4!      * * F E A P * * A Finite Element Analysis Program
5
6!....  Copyright (c) 1984-2017: Regents of the University of California
7!                               All rights reserved
8
9!-----[--.----+----.----+----.-----------------------------------------]
10!      Purpose: Invert small square matrix
11
12!      Inputs:
13!         a(ndm,*) - Matrix to be inverted
14!         nmax     - Size of upper submatrix to invert
15!         ndm      - Dimension of array
16
17!      Outputs:
18!         a(ndm,*) - Submatrix replaces original terms, others not
19!                    changed
20!-----[--.----+----.----+----.-----------------------------------------]
21      implicit  none
22
23      integer   i,j,n,ndm,nmax
24      real*8    d, a(ndm,*)
25
26      do n = 1,nmax
27        if(a(n,n).ne.0.0d0) then
28          d = 1.d0/a(n,n)
29          do j = 1,nmax
30            a(n,j) = -a(n,j)*d
31          end do
32
33          do i = 1,nmax
34            if(n.ne.i) then
35              do j = 1,nmax
36                if(n.ne.j) a(i,j) = a(i,j) +a(i,n)*a(n,j)
37              end do
38            endif
39            a(i,n) = a(i,n)*d
40          end do
41          a(n,n) = d
42        else
43          write(*,*) ' *WARNING* Zero pivot in INVERT'
44        endif
45      end do
46
47      end
48