5

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
francescalus
  • 30,576
  • 16
  • 61
  • 96
Jeff Faraci
  • 403
  • 13
  • 28

1 Answers1

6

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.)

High Performance Mark
  • 77,191
  • 7
  • 105
  • 161
  • Thanks for the help. When I changed it to intent(inout), I still get an error message. It says "Interface mismatch in global procedure: INTENT mismatch in argument u" The error message refers to the line I call the subroutine; the first line in my code above. Do you know why this is happening? – Jeff Faraci Jan 21 '17 at 17:52
  • 2
    The phrase `interface mismatch` hints at problems in the parts of the code that you don't show. Give us a [mcve] to work on. And a little bit of `implicit none` would help too, then we won't have to explain the problems which will eventually pop up using variables such as `v` and `x` which are not declared. – High Performance Mark Jan 21 '17 at 17:56
  • @HighPerformanceMark Thank you. I will come up with a complete/minimal example as you suggest and edit my question when I am done doing so. – Jeff Faraci Jan 21 '17 at 18:01
  • @HighPerformanceMark I figured out the problem in my code based on what you've provided. Thanks a lot. – Jeff Faraci Jan 21 '17 at 18:06