?
Solved

Calling a Fortran Program from VB .NET

Posted on 2003-02-24
6
Medium Priority
?
467 Views
Last Modified: 2013-11-08
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
Comment
Question by:BuckeyeZ
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 

Expert Comment

by:davideconsonni
ID: 8025271
you can see a tecnology called Xml-Rpc
is like soap.

http://www.xml-rpc.org

see implementations sections

0
 

Expert Comment

by:tsugani
ID: 8026041
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
 

Accepted Solution

by:
tsugani earned 150 total points
ID: 8026109
....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.

 

Author Comment

by:BuckeyeZ
ID: 8026146
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
 

Author Comment

by:BuckeyeZ
ID: 8026776
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
 

Expert Comment

by:CleanupPing
ID: 9474628
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

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Navigation is an important part of web design from a usability perspective. But it is often a pain when it comes to a developer’s perspective. By navigation, it often means menuing. This is less theory and more practical of how to get a specific gro…
Having just graduated from college and entered the workforce, I don’t find myself always using the tools and programs I grew accustomed to over the past four years. However, there is one program I continually find myself reverting back to…R.   So …
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question