	subroutine gseidl(m,n,np,a,x,b,tol)
	parameter (nmax=10)
	dimension a(np,np),x(np),b(np),r(nmax)
	common /sor/ w
!
!
	do k=1,m

!	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

!	Gauss or SOR iteration

		write(2,*)'iteracao k = ',k
		ki = k
		do i=1,n
			sum=0.d0
			do j=1,n
				if(j.ne.i) then
					sum=sum+a(i,j)*x(j)
				endif
			enddo
			x(i)=(w*(b(i)-sum)+(1.d0-w)*a(i,i)*x(i))/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 
!----------------------------------
