- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi !
I am trying to find an easy way to use some Fortran subroutines in Visual Studio (VB.NET) and take advantage of the speed difference a FORTRAN DLL provides.
My problem is that my FORTRAN code uses many non-zero based (multidimensional) arrays, which is something forbidden in Visual Basic.
A nice way to overcome this in Visual Basic is the use of .NET arrays (created with the Array.CreateInstance method). Thus, in Visual Basic instead of creating an array the standard way:
Dim x(np) as Single
I use:
x = Array.CreateInstance(GetType(Single), New Integer() {np}, New Integer() {1}).
Unfortunately, such an array when "sent" to the FORTRAN subroutine it crashes.
Am I wrong to expect that these arrays should also be handled by a compiler labeled with Visual Studio?
Also, concerning multi-dimensional arrays passes from VS to Fortran, wouldn't be nice if there was a compiler directive to "reshape" such arrays automatically, instead of taking care of it with a Reshape function, just before the subroutine returns?
Regards,
Dimitri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes, you would be mistaken to assume that all forms of variables in one language are automatically interoperable with a different language, whether it be Fortran or C++ or whatever. However, it is generally possible to access Visual Basic multidimensional arrays in Intel Visual Fortran (note that "Visual Studio" is not in the name.) We provide an example program that does exactlty this called VB.Net-Safearrays. You'll find it in the MixedLanguage.zip archive under Samples in the installed product on your system. (Unzip to a writable folder not under Program Files.)
It isn't as simple as you'd like, but it isn't difficult either.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes, you would be mistaken to assume that all forms of variables in one language are automatically interoperable with a different language, whether it be Fortran or C++ or whatever. However, it is generally possible to access Visual Basic multidimensional arrays in Intel Visual Fortran (note that "Visual Studio" is not in the name.) We provide an example program that does exactlty this called VB.Net-Safearrays. You'll find it in the MixedLanguage.zip archive under Samples in the installed product on your system. (Unzip to a writable folder not under Program Files.)
It isn't as simple as you'd like, but it isn't difficult either.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello Steve !
You are right; I succeeded to transform the VB.NET-SafeArrays for REAL data types instead of CHARACTERs.
However, in the Fortran subroutine, retrieving one-by-one the values using the SafeArrayGetElement() isn't that elegant. What would you propose instead?
Also, this example worked for me when sending to the Fortran subroutine, a VB array and not the .NET array (created with the Array.CreateInstance method which could have non-zero lower array bounds. Am I doing something wrong?
Regards,
Dimitri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am not familiar with this other array type.
The reason you need SafeArrayGetElement is that there's no simple memory correspondence for the array element locations.
![](/skins/images/B7BA37F9CE4B52FF7CAE1FB0388839C8/responsive_peak/images/icon_anonymous_message.png)
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page