- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I have a Fortran subroutine which allocates an array and assign values to components:
subroutine ExampleSub (array) !DEC$ ATTRIBUTES STDCAll, DLLEXPORT::ExampleSub !DEC$ ATTRIBUTES ALIAS:"ExampleSub" :: ExampleSub !DEC$ ATTRIBUTES REFERENCE :: array integer, allocatable, dimension(:), intent (out):: array allocate (array(3)) array(1) = 111 array(2) = 222 array(3) = 333 return end subroutine
I've created a DLL from this subroutine and try to call it in VB.NET. My VB code looks like this:
Declare Sub ExampleSub Lib "C:\Users\Myaddress\Dll1.dll" Alias "ExampleSub" _ (ByVal array() As Integer) Sub Main() Dim array1(2) As Integer Call ExampleSub(array1) End Sub
The VB scripts runs without any errors however it produces wrong values for the array. Each time I run, it gives different results for the array.
Is it even possible to make this work in VB.NET while the Fortran DLL contains an allocatable array?
Thanks,
Arash
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Can't be done. Sorry. Fortran deferred-shape arrays are not compatible with VB, and you certainly can't reallocate a VB array in Fortran.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Can't be done. Sorry. Fortran deferred-shape arrays are not compatible with VB, and you certainly can't reallocate a VB array in Fortran.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for the clarification Steve.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Arash,
I'm curious if your application can obtain the needed array size first, allocate it in VB, then call a Fortran routine? Our approach has been to call a Fortran routine from VB or C# to get the data size, such as reading a file or counting data to return an array size. We then allocate the array in the VB or C# program, and pass that array to the second Fortran routine to do the calculations and return the results. Would this approach work for you?
Regards,
Greg
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Greg,
Thanks for your comment. Yes the approach of allocating the array in VB and pass it to Fortran works. I was wondering if the size of array in the second Fortran subroutine can be set based the passed array size. I can define the size in the second Fortran subroutine to work for many possible sizes. I thought if I could use allocatable arrays in the second subroutine I would save some memory.
Thanks,
Arash
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page