Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 472
  • Last Modified:

Calling a Fortran Program from VB .NET

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)
  INTEGER ARRAY1(8)
  REAL ARRAY2(400,1016)
  .
  .
  .
  RETURN
END

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)
End Sub

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?
0
BuckeyeZ
Asked:
BuckeyeZ
1 Solution
 
davideconsonniCommented:
you can see a tecnology called Xml-Rpc
is like soap.

http://www.xml-rpc.org

see implementations sections

0
 
tsuganiCommented:
This happens because vb reads entire rows and not separate numbers since vb does not have a format command similar with fortran.
The best way i can think to solve the problem is to alter your fortran code to separate the outputs with commas.
For example if u have a 3x3 array output (fortran side) it should be in the form

1, 2, 3
4, 5, 6
7, 8, 9
0
 
tsuganiCommented:
....If that doesnt solve the problem post your readdata subroutine because there might be something wrong with that.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
BuckeyeZAuthor Commented:
Thanks for the tips, but actually, in the time it took for a response, I figured out most of my problem.  When I was compiling the .dll, I didn't have the /convert:vaxd qualifier in the line.  Once I did that, I could pass the real numbers (sort of).  My other problem had to do with having the indexing reversed.  On the Fortran side, if the array was ARRAY2(400,1016), it had to be dimensioned in VB as ARRAY2(1016,400).  Once I made this two changes, I started to get somewhere.

Now, the only problem is the accuracy of the values that are passed.  If I pass a single value (one that is also contained in the array) from the Fortran side to the VB, I get a very accurate value.  But if that value is compared to the same one that was contained in the array, it's way off.  Is there a way to overcome this problem?
0
 
BuckeyeZAuthor Commented:
Thanks for the tips, but actually, in the time it took for a response, I figured out most of my problem.  When I was compiling the .dll, I didn't have the /convert:vaxd qualifier in the line.  Once I did that, I could pass the real numbers (sort of).  My other problem had to do with having the indexing reversed.  On the Fortran side, if the array was ARRAY2(400,1016), it had to be dimensioned in VB as ARRAY2(1016,400).  Once I made this two changes, I started to get somewhere.

Now, the only problem is the accuracy of the values that are passed.  If I pass a single value (one that is also contained in the array) from the Fortran side to the VB, I get a very accurate value.  But if that value is compared to the same one that was contained in the array, it's way off.  Is there a way to overcome this problem?
0
 
CleanupPingCommented:
BuckeyeZ:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now