Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

ReDim VB.NET array in Fortran

mamey4
Beginner
338 Views

Hi

the programming problem I'm dealing with right now can be broken down do allocating an array in Fortran, which was created in VB.NET. My code in VB.NET looks like this:

dim test(),testvar2 as double
n = fortran_function(test, ...)
testvar2=test(1)

And the Fortran function:

integer function fortran_function(test, ...)
REAL(KIND=8), INTENT(INOUT), ALLOCATABLE :: test(:)
allocate(test(1))
test(1)=...
...
end function fortran_function

Doing it that way does not allocate space for the array, but it crashes my VB.NET application with an ExecutionEngineException. My question is, how can I "outsource" the ReDim command that I'd usually use in VB.NET to the Fortran function (this is necessary since the array size is calculated there).

mamey

0 Kudos
1 Reply
Arjen_Markus
Honored Contributor I
338 Views
Since allocation algorithms have to keep track of a lot of stuff and Fortran allocatable arrays use descriptors
to keep track of what memory they have available and in what shape, it is very unlikely that there will
be any chance of doing what you in exactly this way.

What you could do instead is:
- Compute the required size in Fortran routine A
- Return to VB to allocate the array to the proper size
- Pass that array (as if it was an ordinary one) to Fortran routine B that actually
uses it.

I do not see how the runtime libraries of two very different languages/environments could
cooperate directly, but this is at least a workaround.

Regards,

Arjen
0 Kudos
Reply