	subroutine jacobi(m,n,np,a,x,b,tol)
	parameter (nmax=10)
	dimension a(np,np),x(np),b(np),r(nmax),xant(nmax)
!
!
	do k=1,m
		write(2,*)'iteracao k = ',k
		ki = k

!
!	check convergence
!
		do i=1,n
			sum=0.d0
			do j=1,n
				sum=sum+a(i,j)*x(j)
			enddo
			r(i)=b(i)-sum
		enddo
		rnorm=vnorm(r,n,np)
		write(2,*)'|r| = ',rnorm
		if(rnorm.le.tol) goto 300

!	store previous value of x(i) in xant(i)

		do i=1,n
			xant(i)=x(i)
		enddo

!	Compute Jacobi iteration

		do i=1,n
			sum=0.d0
			do j=1,n
				if(j.ne.i) then
					sum=sum+a(i,j)*xant(j)
				endif
			enddo
			x(i)=(b(i)-sum)/a(i,i)
			write(2,*) 'x(',i,')=',x(i)
		enddo
	enddo
	write(2,*)'nao convergiu, rnorm=',rnorm,' k= ',ki
	write(*,*)'nao convergiu, rnorm=',rnorm,' k= ',ki
!	pause
	stop
300	continue
	write(2,*)'convergiu, rnorm=',rnorm,'na iteracao k=',ki
	write(*,*)'convergiu, rnorm=',rnorm,'na iteracao k=',ki
      return
      end 
!----------------------------------
