Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Annonces
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.
29285 Discussions

Trouble Passing Multi-Dimensional .NET Arrays to a Fortran95 Dynamic Link Library File

sam48218
Débutant
996 Visites
Hello,

I am embarking on a new multi-language project where the main GUI of our program will be coded up in VB2008. However, we wish to communicate with a Fortran95 DLL file in order to conduct some complex numerical calculations. I am fairly green to multi-language programs (especially Fortran), thus I am having some troubles already and am looking for some guidance. My initial goal is just to determine how .NET and a Fortran DLL can "talk." I've created a simple VB project that generates a multi-dimensional array of singles. All I am trying to do is pass the array to an array-valued Fortran function that, in turn, passes the same array back to VB. Unfortuantely, every time I try passing the .NET array to the DLL I throw an exception. However, if instead of a multi-dimensional array, I try passing a 1-dimensional .NET array to the Fortran DLL, I can get the transfer to occur, but the array that Fortran passes back to the .NET framework contains garbage (i.e., very different numbers than what was originally passed to the DLL). Can anyone give me some guidance as to how I should be passing .NET arrays to a Fortran DLL file.

Thank you much!
0 Compliments
6 Réponses
Steven_L_Intel1
Employé
996 Visites
I suggest that you study the sample VB.NET-SafeArrays, provided with the Intel Visual Fortran product (in the MixedLanguage samples ZIP file.) It illustrates how to pass multidimensional arrays from VB to Fortran and back again.

If you're passing a one-dimensional array, it's simpler - see the VB-Calls-Fortran sample. If you have seen earlier advice to pass just the first element of the VB array, disregard it. Look at how the array arguments are described in the VB "module".
0 Compliments
sam48218
Débutant
996 Visites
Hi Steve,

Thank you very much for your advice. I do have a follow-up question regarding your suggestion. You mention that I should forget about passing the first element of the .NET array by reference, as that worked for VB6 but not for .NET. However, the VB-Calls-Fortran sample does precisely that. When the time is convenient, could you please advise.

Thanks,
0 Compliments
onkelhotte
Nouveau contributeur II
996 Visites
I dont know how VB handels arrays, but in C# the rows and columns are switched compared to Fortran.

That means, when you have an C# Array

int[,,] cIntArray = new int[4,5,6] // values from -2147483648 to 2147483647

you have to use this in Fortran

integer(kind=8) fortranIntArray(6,5,4) ! values from -2147483648 to 2147483647


Markus
0 Compliments
Steven_L_Intel1
Employé
996 Visites
In version 11.1 and earlier, this sample did pass the first element. That was corrected in version 12.
0 Compliments
bevo3
Débutant
996 Visites

Hey Guys,

Thanks for the replies! So I've been able to successfully pass a 1-dimensional .NET array to my Fortran DLL and back to .NET again. However, when I try doing the same thing for a 2-dimensional array the ordering gets all jumbled up when I pass the .NET array byref to the Fortran DLL. In other words, after I pass the .NET array to the FortranDLL I print various elements of that array to check the order, and for some reason Fortran moved elements around and even reset some of them to zero. What do I need to do to preserve the order of my .NET array when passing it byref to the Fortran DLL?

Thanks,

0 Compliments
Steven_L_Intel1
Employé
996 Visites
As I wrote above, for a multidimensional array you'll need to use the SAFEARRAY routines. Fortran is not moving anything.
0 Compliments
Répondre