0

I am trying to debug my code that involves a subroutine and a module. I get two error messages from the subroutine : 1) Symbol is not a dummy variable, 2) Legacy Extension : REAL array index. I indicate in the code where the errors come from.

The main program reads in a file with one column of numbers. I then CALL the subroutine using this file as the argument. The sub-routine then gives me these two error messages. How can I fix my code and thus fix these error messages? Thanks

Note : I edited the code based on the useful comment below. I still get the same error messages.

MODULE Stack1
IMPLICIT NONE

INTEGER, PARAMETER:: nx = 48, ny = 48

CONTAINS 

SUBROUTINE Stack2

REAL,DIMENSION(-nx:nx,-ny:ny),INTENT(INOUT):: f !produces error message 1)
REAL :: x0,y0,x1,y1,x,y,a0,a1,a2,a3,nstep,dx,dy
INTEGER :: i
DATA x0,x1,y0,y1,nstep/0.d0,1.d0,0.d0,1.d0,10/ 

p(x,y)=a0 +a1*x+a2*y+a3*x*y !interpolant polynomial

!now evaluate the function f on the 4 known grid points
!use this to solve for the unknown interpolant coefficients a0,a1,a2,a3

a0=(f(x0,y0)*x1*y1-f(x1,y0)*x0*y1+(f(x1,y1)*x0-f(x0,y1)*x1)*y0 )/&
(x1*y1-x0*y1+( x0-x1 )*y0 )  !produces error message 2)

a1=(f(x1,y0)*y1-f(x0,y0)*y1+(f(x0,y1)-f(x1,y1))*y0 )/&
(x1*y1-x0*y1+( x0-x1 )*y0 )  !produces error message 2)

a2=(f(x0,y1)*x1-f(x0,y0)*x1+(f(x1,y0)-f(x1,y1))*x0 )/&
(x1*y1-x0*y1+( x0-x1 )*y0 )  !produces error message 2)

a3=(f(x1,y1)-f(x1,y0)-f(x0,y1)+f(x0,y0) )/&
(x1*y1-x0*y1+( x0-x1 )*y0 )  !produces error message 2)

DO i=0,nstep
    x=x0+dx*FLOAT(i)
    y=y0+dy*FLOAT(i)
    y=0.75d0*y1
    print 100,x,y,p(x,y),f(x,y)
    20 continue
    100 format('x,y,p,f=',4(3x,e10.3))
END DO

END SUBROUTINE  Stack2

END MODULE Stack1

PROGRAM StackProblem

USE Stack1

IMPLICIT NONE

INTEGER :: i,j
REAL,DIMENSION(-nx:nx,-ny:ny) :: Func

OPEN(UNIT=11, file='TestFile1.dat',status='old')

    DO i=-nx,nx
    DO j=-ny,ny
     
        READ(11,*) Func(i,j)
 
    END DO
    END DO

CALL Stack2(Func)

END PROGRAM StackProblem

Note, the file TestFile1.dat is just a single column file with real numbers in it, for ex:

1.30482
1.30787
1.31098
1.32983
2
  • 1
    I am trying to debug my code that involves a subroutine and a module First, insert implicit none right after the module line and get the compiler to check for a common source of errors. Personally I think you're wasting your time developing code without that safety harness; you can probably guess my thinking on my time too :-) Commented Jul 30, 2020 at 19:11
  • You are missing the dummy argument in the subroutine statement. You should have subroutine stack2(f). Commented Jul 30, 2020 at 21:45

1 Answer 1

1

I'll address your error messages first. Then I'll point out a few other problems I see and try to suggest how you might choose to pursue a solution.

  1. Error 1: Symbol is not a dummy variable. This is because the subroutine stack2 is called with an argument in the program stackproblem. However, stack2 has no arguments in its definition. Simply declaring the variable f with intent(inout) is not sufficient, and should probably result in other error messages.
  2. Error 2: Legacy Extension: REAL array index. Note that f from the module stack1 is declared to be a 2D array of real values. Of course, each element within the array may be accessed using f(row,col) where row is the row number and col is the column number. Furthermore, row,col should be integers. However, in the subroutine stack2 you are accessing elements of the array using real values. I believe the fundamental problem is that you are treating f like it is a function - but it is not.

Now, you don't mention any other issues but there appear to be other problems and misunderstandings. Here is one:

  • The variable (?) function (?) p is not declared/defined. Since you have used implicit none this should also cause a compiler error.
Sign up to request clarification or add additional context in comments.

3 Comments

p is a statement function - an archaic bit of syntax which nowadays should be avoided. Here a contained subprogram would do the job.
Thanks a lot. You’ve certainly pointed out the mistakes but can you suggest a solution as to how to fix this? I’m looking for a solution too. Thanks
@Ian Bush THanks for pointing out the old notation. How can I implement a subprogram? Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.