module jacobi

use dados

contains

!----------------------------------------------------------

subroutine jac

	integer :: i, j, k
	real*8  :: soma1, soma2

	do k = 1, itmax ! Passos 1, 2 e 5

		!Passo 3
		do i = 1, N

			soma1 = 0; soma2 = 0
			do j = 1, i-1
				soma1 = soma1 + A(i,j)*xo(j)
			end do

			do j = i+1, N
				soma2 = soma2 + A(i,j)*xo(j)
			end do

			x(i) = ( -soma1 - soma2 + b(i) ) / A(i,i)

		end do

		write(*,4) k, (x(i),i=1,N)
		4 format ( i2, <N>(1pe12.4) )

		! Passo 4
		if ( sum(abs(x-xo)) <= tol ) exit
		
		! Passo 6 
		xo = x

	end do

end subroutine jac

!----------------------------------------------------------

end module jacobi