views:

1758

answers:

1

Can someone explain to me what sort of an abstraction in the parser / compiler a dummy variable or attribute corresponds to?

      PURE SUBROUTINE F(X, Y)
        IMPLICIT NONE
        REAL, INTENT(INOUT) :: X, Y, C
C        REAL :: A, B
C        REAL, SAVE :: C = 3.14E0
        PARAMETER (C = 3.14E0, X = 32, Y = X)
        X = Y + 2 * SIN(Y)
      END


cetin@unique:~/lab/secret/tapenade$ gfortran -x f77 -c 1.f 
1.f:6.37:

        PARAMETER (C = 3.14E0, X = 32, Y = X)                           
                                    1
Error: PARAMETER attribute conflicts with DUMMY attribute in 'x' at (1)
1.f:3.38:

        REAL, INTENT(INOUT) :: X, Y, C                                  
                                     1
Error: Symbol at (1) is not a DUMMY variable


cetin@unique:~/lab/secret/tapenade$ ifort -c 1.f
1.f(3): error #6451: A dummy argument name is required in this context.   [C]
        REAL, INTENT(INOUT) :: X, Y, C
-------------------------------------^
1.f(6): error #6406: Conflicting attributes or multiple declaration of name.   [X]
        PARAMETER (C = 3.14E0, X = 32, Y = X)
-------------------------------^
1.f(6): error #6406: Conflicting attributes or multiple declaration of name.   [Y]
        PARAMETER (C = 3.14E0, X = 32, Y = X)
---------------------------------------^
1.f(6): error #6592: This symbol must be a defined parameter, an enumerator, or an argument of an inquiry function that evaluates to a compile-time constant.   [X]
        PARAMETER (C = 3.14E0, X = 32, Y = X)
-------------------------------------------^
compilation aborted for 1.f (code 1)
+4  A: 

Fortran passes by reference. The dummy attribute corresponds to those variables that are passed in to the function (X and Y in your case). The parameter statement is expecting something static, but since X is whatever is passed into the function, it really doesn't make any sense. The parameter statement is a way to set up constants - it doesn't have anything to do with the parameters to a subroutine.

When you get the error saying that C is not a DUMMY variable, then, it means that it's not finding C in the list of variables that will be passed into/out of the function - your declaration is only F(X, Y): no C in sight. Though that you are not using the DUMMY attribute explicitly, you have the INTENT(INOUT) attribute, which means that these variables correspond to subroutine input/output.

To get what you want, you would have a subroutine that looks something like:

subroutine F(X, Y)
    implicit none

    ! These are the dummy variables
    real, intent(inout) :: X, Y

    ! These are the variables in the scope of this subroutine
    real                  :: a, b
    real, parameter, save :: c = 3.14E0

    X = Y + 2*sin(Y)
end subroutine F

I'm not entirely sure what you are trying to do - you're declaring a pure subroutine, which means a subroutine without side effects, but you are using intent(inout) for your variables, which means that X and Y can be altered in the course of execution.

I'd add as well that inside a subroutine, initializing a variable in its declaration statement like REAL :: C = 3.14E0 yields a variable with an implicit save attribute. If you want it to be saved from call to call, though, you've done the right thing by explicitly adding the save attribute to make it clear that that's what you're doing.

I'm not a parser/compiler guy, but I think that to answer your question, the dummy attribute means that you're just getting a pointer - you don't have to allocate any space, since the variable used in the function call already has space allocated.

Tim Whitcomb