Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29007 Discussions

problem passing an array between visual and a fortran dll

kudegu
Beginner
418 Views
Hi

well i'm not really new to fortran but almost a rookie.
I found an old program which was written in fortran and i tried to link it as an dll because new programming wouldn't have been very easy. So everything works fine calling the sub by passing some arguments.
But in a next step i tried to pass back results in an array.
I tried it first by writing a short example and this works fine too. So i used my growing knowledge to do it in the same way with the dll. So what should i say it fails. I still use the output in the dll so i know that within the dll all values are stored well in the array but when it is passed back to my visual array something strange happens.
The problem is that it depends on input data what dimension the array gets. If it's only a 1-dimension array it wors but if it's not fortran seems to count all elements from 1 to x and for example if it is a 2D array the element 1,1 is stored in 1,1 but the next element (1,2) is stored in 1,3 and element 2,1 is stored in 1,2.

Well as i mentioned above im not so into fortran ... thats why i ask :-)

thanx

oli
0 Kudos
1 Reply
Jugoslav_Dujic
Valued Contributor II
418 Views
Quoting - kudegu

The problem is that it depends on input data what dimension the array gets. If it's only a 1-dimension array it wors but if it's not fortran seems to count all elements from 1 to x and for example if it is a 2D array the element 1,1 is stored in 1,1 but the next element (1,2) is stored in 1,3 and element 2,1 is stored in 1,2.

Well, you got pretty far on your own, then :-).

And also, you found 90% of the answer yourself. Since the 2-D array must be laid out in a linearly addressed, 1-D memory, there are 2 principal ways to do it -- row-wise (aka "row-major") and column-wise (aka "column-major"). See the Wikipedia entry. As result, when you exchange the data beween "incompatible" languages, the result appear transposed.

The obvious solution is to declare your arrays in VB and Fortran as transposed to one another, and use the DO-loops accordingly.

Note that computers "like" when you access the memory in linear-order, so in Fortran the innermost do-loop index should correspond to the first index, for the fastest access:

[cpp]DO i=1,nCols
   DO j=1,nRows
      A(j,i) = ... !As opposed to A(i,j)
   END DO
END DO[/cpp]





0 Kudos
Reply