Question

NOTE: I'm still investigating this issue - please don't look into it yet - the mistake may be elsewhere

I would like an argument to a subroutine to be OPTIONAL, but that argument also happens to be an assume shape array. When I try to compile the module containing this subroutine, I get the following error:

PGF90-S-0189-Argument number 3 to (routine): association of scalar actual argument to array dummy argument (location)

The routine looks like this:

SUBROUTINE EXAMPLE(A, B, C)
   IMPLICIT NONE
   INTEGER, INTENT(IN) :: A, B
   INTEGER, OPTIONAL, DIMENSION(:), INTENT(IN)   :: C
   INTEGER :: TEST

   IF (PRESENT(C)) THEN
      TEST=C(1)
      PRINT *,TEST
   ELSE
      PRINT *,A,B
   ENDIF

END SUBROUTINE EXAMPLE

It is contained within a module. I get the error when I try to call it with only two arguments from a subroutine which is USEing the module.

I have only found one possibly related question on the Portland Group forums here:

http://www.pgroup.com/userforum/viewtopic.php?t=624&sid=d76fdf8ca2bf4fc3109f4f49b1de0ad7

The answer boils down to the user using an optional argument which has not been allocated - I don't know if this applies in my case as I'm not using 'C' outside of the IF(PRESENT(C)) block, but could there be an implicit allocation going on when defining a variable as assumed shape, which cannot be carried out when it is not passed in the first place?

Was it helpful?

Solution

This problem is now resolved - you can indeed use assumed shape arrays as optional arguments. As pointed out in the comments - the error stemmed from an old version of a source file which was not being regenerated by a pre-processing step due to a bug. As a result, the call was not what I thought it was - it actually contained a single integer as the third argument.

Thanks for the help all.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top