Fortran array cannot be returned in function: not a DUMMY variable

You are correct that m31tensorprod being an internal function means that you do not have to declare it in the main program. In the jargon: it has an explicit interface.

However, that is not the problem with your code. What is going wrong is with the function definition itself. [Admittedly the compiler message isn’t too helpful.]

The definition of the function subprogram

function m31tensorprod(a, b)

defines a function with result variable m31tensorprod. This result variable is subject to your declaration

    real(dp), intent(out) :: m31tensorprod(3, 3)

It is this declaration which is incorrect. You may declare type (real(dp)) and dimension ((3,3)) but the intent(out) is erroneous.

The intent attribute, in the words of the Fortran standard, is subject to the constraint (C538)

An entity with the INTENT attribute shall be a dummy data object or a dummy procedure pointer.

Coming back to the compiler message, m31tensorprod is not a dummy variable. In this case the dummy arguments are a and b. In general the dummy arguments are those things between the ( and the ),

Leave a Comment