0
votes

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?

1
It isn't the exact code itself, I just took the essence of what it is doing as a simplified illustration. I have renamed the subroutine to EXAMPLE to prevent what appeared to be a name clash. - Chris Whittleston
There is no outright prohibition on using optional with an assumed-shape dummy. That isn't to say that all uses are correct, so could you provide a MCVE for your problematic case? - francescalus
The error message you report has nothing to do with optional or assumed-shape - it is complaining that you passed a scalar to an array argument, which is not allowed by the standard (with some exceptions.) I discuss this in software.intel.com/en-us/blogs/2009/03/31/… . Since you have not shown us the call, it's hard to be more specific. - Steve Lionel
Thanks for the replies, I will add additional detail including the call when I'm not in transit. - Chris Whittleston
I've just written a simplified version of what is in the actual code and it now seems to be working, so I suspect the issue is not what I originally thought. I'm going to do some more investigating and update this when I have. - Chris Whittleston

1 Answers

0
votes

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.