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

Trouble passing arrays of double to Compaq Visual Fortran

5applerush
Beginner
232 Views
Hello,
A Visual Fortran friend and I (VB6) are trying to collaborate on a mixed language project and we have hit a wall. He has written a dll to which I am calling, and passing 4 arguments, they are as follows:

arr1(0 to 2) as double
lng1
arr2(0 to 2, 31) as double
lng2

For some reason, the double values that he recieves are entirely different from those that I am passing him. Here is what we have checked / tried:

1.) Passing first value along with the array to indicate 0 or 1 base to Fortran:
eg:
FortProc arr1 (0)
2.) We attempted passing the arguments both as zero, and one base arrays
3.) I attempted to pass the array with all values set to zero - still got wild numbers in his debug file (which merely reported what he recieved.)

I apologize for not having code to post, but he has gone home for the night, and I thought I'd see if anyone has had a similar experience. I will post a sample project and the corresponding code from both languages this weekend. Any help would be greatly appreciated.

Best regards,
Danny
0 Kudos
2 Replies
Jugoslav_Dujic
Valued Contributor II
232 Views
Array base doesn't matter in the exchange -- it's a red herring. As long as you correctly pass the starting address, the indices will be correct within each respective language.

I suspect that you have a ByVal/ByRef mismatch. The normal way to exchange the arrays is to declare the argument ByRef and pass only the first (i.e. zeroth) element. I'm not sure if it works with 2-D arrays as well, though, as they could easily be differently stored in VB and Fortran; I'll let others comment on this aspect.
0 Kudos
5applerush
Beginner
232 Views
Thanks for the reply JugoslavDujic. We were able to figure out the problem on Saturday, and I'm just getting around to post my results. It was a simple syntactical error on my part in the declaration for the fortran routine. It read like this:

Declare Sub FortProc Lib "D:FortdllMyFort.dll" (Long1 As Long, ArrayArg () As Double, Long2 As Long)

... and should have read:

Declare Sub FortProc Lib "D:FortdllMyFort.dll" (Long1 As Long, ArrayArg As Double, Long2 As Long)

In my little experience, (I'm green!) I have written one declare to pass an array before, and since then, I've gotten into the habit of putting parentheses "()" after them. I now know this is not the case with declare statements! It was particularly difficult, because VB did not throw an error. It merely returned very wrong values!

Thank you for your input though!
Danny
0 Kudos
Reply