program main
    implicit none
    integer,parameter :: MSIZE=8
    real*8,dimension(1:MSIZE) :: x,y,b
    integer :: i
    do i=1,MSIZE
        b(i)=i
    end do
    x=b
    print '("b=")'
    call dvecprint(x)
    do i=1,100
        call sor(1.5d0,x,b)
    end do
    print '("i=",I0," x=")',i
    call dvecprint(x)
    call multA(y,x)
    print '("Ax=")'
    call dvecprint(y)
    return

contains

subroutine sor(w,x,b)
    real*8 :: w
    real*8,dimension(1:) :: x,b
    integer :: i,n
    n=size(x)
    x(1)=x(1)-w/2*(b(1)+2*x(1)-x(2));
    do i=2,n-1
        x(i)=x(i)-w/2*(b(i)-x(i-1)+2*x(i)-x(i+1))
    end do
    x(n)=x(n)-w/2*(b(n)-x(n-1)+2*x(n))
end subroutine

subroutine multA(y,x)
    real*8,dimension(1:) :: x,y
    integer :: i,n
    n=size(x)
    y(1)=-2*x(1)+x(2)
    do i=2,n-1
        y(i)=x(i-1)-2*x(i)+x(i+1)
    end do
    y(n)=x(n-1)-2*x(n)
end subroutine

subroutine dvecprint(x)
    real*8,dimension(1:) :: x
    integer :: N,i
    N=size(x)
    do i=1,N
        print '(G0," ")',x(i)
    end do
end subroutine

end program
