I am getting an error message in my subroutine when I run my code.
This code is from an exercise in Kincaid & Cheney's book on Gauss Seidel methods to solve elliptic partial differential equations.
The error message is:
dummy argument 'u' with INTENT(IN) in variable definition context (assignment) at (1).
I refer to (1) in the code below. How can I fix the subroutine so the error message does not come up?
subroutine seidel(ax,ay,nx,ny,h,itmax,u)
real, dimension(0:nx,0:ny), intent(in) :: u
real, intent(in) :: ax,ay, h
integer, intent(in) :: nx, ny, itmax
integer:: i,j,k
do k = 1,itmax
do j = 1,ny-1
y = ay + real(j)*h
do i = 1,nx-1
x = ax + real(i)*h
v = u(i+1,j) + u(i-1,j) + u(i,j+1) + u(i,j-1)
u(i,j) = (v - h*h*g(x,y))/(4.0 - h*h*f(x,y)) (1)
end do
end do
end do
end subroutine seidel
intent(in)
is a promise to the compiler that a routine won't try to update the value of an argument. The code you show breaks that promise in the line:
u(i,j) = (v - h*h*g(x,y))/(4.0 - h*h*f(x,y))
Fix this either by not breaking your promises or, probably more appropriate in this case, making the intent inout
, like this
real, dimension(0:nx,0:ny), intent(inout) :: u
inout
tells the compiler that the routine will be passed the argument and may make modifications to it.
(I think this is probably a duplicate, but can't find one yet.)