Fortran array cannot be returned in function: not DUMMY variable

As a newbie in the free Fortran 90 form, I'd really like to know why the following code snippet won't work:

program test2
    implicit none
    !!! A program to practice f90 writing.
    ! Define double precision data
    integer, parameter :: dp = kind(1.d0)
    real(dp) :: a(3), b(3)
    integer :: i
    a = (/(i, i=1, 3)/)
    b = (/(i, i=1, 3)/)
    write (*, *) m31tensorprod(a, b)

contains
    function m31tensorprod(a, b)
        real(dp), dimension(3), intent(in) :: a, b
        real(dp), intent(out) :: m31tensorprod(3, 3)
        integer :: k1, k2
        forall(k1=1:3, k2=1:3)
            m31tensorprod(k1, k2) = a(k1) * b(k2)
        end forall
        return
    end function m31tensorprod
end program test2

When I try to compile this with gfortran test2.f90, it says:

test2.f90: 13.4:

function m31tensorprod(a, b)
1 Error: Symbol at (1) is not a DUMMY variable

I thought, because it m31tensorprodis an internal function, it does not need to be declared. Where am I wrong?

Thank,

+4
source share
1 answer

You are right, which m31tensorprodis an internal function which means that you do not need to declare it in the main program. In jargon, it has an explicit interface.

. , , . [ , .]

function m31tensorprod(a, b)

m31tensorprod.

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

. (real(dp)) ((3,3)), intent(out) .

intent, Fortran, (C538)

INTENT .

, m31tensorprod . a b. ( ),

+6

Source: https://habr.com/ru/post/1570355/


All Articles