Calling a Fortran Program from VB .NET
Posted on 2003-02-24
I have a Fortran code (sample.f90) that opens a dat file and returns a number of things. Most importantly, are two arrays, ARRAY1 (an array of 8 integer values) & ARRAY2 (double-dimensioned array containing a whole lot of data). Sample code:
SUBROUTINE READDATA (ARRAY1, ARRAY2)
Running the code in Fortran, returns the proper arrays. To call this from VB .NET I built the sample.f90 code as a .dll (sample.dll) and called it using the following VB code:
Declare Sub READDATA Lib "c:\....\sample.dll" (ByVal ARRAY1() As Integer, ByVal ARRAY2(,) As Single)
Private Sub ...
Dim ARRAY1(8) As Integer
Dim ARRAY2(400,1016) As Single
Call READDATA(ARRAY1, ARRAY2)
All values in ARRAY1 come back as they should when displayed in a text box, but ARRAY2 is all messed up. ARRAY2(0,0) has one value that doesn't mean much, but then is repeated along the first row for however many rows were in the array on the Fortran side. For example, if there were 10 rows and 254 columns of data in the array as it existed in Fortran, then in VB .NET it would appear as ARRAY2(0,0) = ARRAY2(0,1) = .. = ARRAY2(0,9) = an unintelligible value depending on how it's declared on the VB side (single/double/integer/etc.) The rest of ARRAY2 is equal to 0.
I'm almost certain that this is a case of a mis-match between variable types from one language to the other, but is there a way to get VB .NET to understand the REAL variable type from Fortran and thus make the array legible?