c----------------------------------------------------------- c Test program for LAPACK "driver" routine 'dgesv' c which computes the solution of a real system c of linear equations: A x = b c----------------------------------------------------------- program tdgesv implicit none c----------------------------------------------------------- c Maximum size of linear system. c----------------------------------------------------------- integer maxn parameter ( maxn = 100 ) c----------------------------------------------------------- c Storage for arrays c----------------------------------------------------------- real*8 a(maxn,maxn), & b(maxn), x(maxn) integer ipiv(maxn) integer i, nrhs, & n, info c----------------------------------------------------------- c Set up sample 3 x 3 system ... c----------------------------------------------------------- a(1,1) = 1.23d0 a(1,2) = 0.24d0 a(1,3) = -0.45d0 a(2,1) = -0.43d0 a(2,2) = 2.45d0 a(2,3) = 0.78d0 a(3,1) = 0.51d0 a(3,2) = -0.68d0 a(3,3) = 3.23d0 b(1) = 6.78d0 b(2) = -3.45d0 b(3) = 1.67d0 c----------------------------------------------------------- c ... and solve it. Note that 'dgsev' is general c enough to solve A x_i = b_i for multiple right-hand- c sides b_i. Here we have only one right-hand-side. c Also note that the procedure performs the LU c decomposition in place, thus destroying the c input-matrix, it also overwrites the right-hand-side(s) c with the solution(s). Finally, observe that we c pass the "leading dimension" (maxn) of both 'a' and c 'b' to the routine. This allows us to load array c elements in the main program as we have just done, c without running into troubles due to the fact that c these elements ARE NOT all contiguous in memory. c----------------------------------------------------------- n = 3 nrhs = 1 call dgesv( n, nrhs, a, maxn, ipiv, b, maxn, info ) if( info .eq. 0 ) then c----------------------------------------------------------- c Solution successful, write soln to stdout. c Note the use of "implied-do-loop" to write a c sequence of elements: the enclosing parenthesis c around the "loop" are required. c----------------------------------------------------------- write(*,*) ( b(i) , i = 1 , n ) else if( info .lt. 0 ) then c----------------------------------------------------------- c Bad argument detected. c----------------------------------------------------------- write(0,*) 'tdgesv: Argument ', abs(info), & ' to dgesv() is invalid' else c----------------------------------------------------------- c Matrix is singular. c----------------------------------------------------------- write(0,*) 'tdgesv: dgesv() detected singular ', & 'matrix' end if stop end