To expand the discussion around the topic by Developer1 ( https://forums.silverfrost.com/Forum/Topic/1351 ), please consider the following examples. I wrote a VB main program which populate an array 'e' and pass it to a FTN95 subroutine with a vector 'd'.
Sub Main()
Dim d(9), e(9, 9) As Single
For j = 0 To 9
For i = 0 To 9
e(i, j) = CSng(i * j)
Next
d(j) = 0
Next
FortranFunctions.Add(e, d)
End Sub
The FTN95 subroutine take s the array 'E' and assign to vector 'D' elements the second column elements of matrix 'E' plus 2.
SUBROUTINE DIRECTCALL_ADD(E,D)
ASSEMBLY_INTERFACE(NAME='Add')
REAL, intent(in):: E(:,:)
REAL, intent(out):: D(:)
do i = 1, ubound(E,1)
D(i) = E(i,2) + 2.0
end do
END
This works fine! Now I tried to use a function instead of a subroutine to make the same thing. The modified VB code,
Sub Main()
Dim d(9), e(9, 9) As Single
For j = 0 To 9
For i = 0 To 9
e(i, j) = CSng(i * j)
Next
d(j) = 0
Next
d = FortranFunctions.Add(e)
End Sub
and the FTN,
REAL FUNCTION DIRECTCALL_ADD(E) RESULT(D)
ASSEMBLY_INTERFACE(NAME='Add')
REAL, intent(in):: E(:,:)
REAL:: D(ubound(E,1))
do i = 1, ubound(E,1)
D(i) = E(i,2) + 2.0
end do
END
In this case I got an unhandled exception: the message told 'System.ExecutionEngineException', without any other details. I'm using VS 2008 with FTN95 5.50 (Academic).
Can someone explain this behaviour? Thank you in advance for any suggestion.