views:

104

answers:

1

I have a VB.net console app and I am opening a function in a dll written in fortran. I am passing 3 arrays through the function by reference. When they come back out the otherside they ahve all tunred to arrays of only one element. And that element is 0.

I read on the internet somewhere that when doing this kind of thing it is a good idea to only pass the first element of the array into the function. I tried changing my function declaration to accepting single elements rather than single dimensional arrays, and now the arrays are the same length before and after the function call, but they don't seem to be changing at all, so i'm not sure that this is working.

Anyone ever have any problems like this or know what to try? Any help would be much appreciated.

A: 

FORTRAN functions only receive pointers, no matter if its an array or a single value.

I dont know how you can do this in VB.net, but try to find the way to send the pointer to the first item.

In C, it would be:

double *a = ...;  
fortran_func(a);  // or...
fortran_func(&a[0]); 

Also, ensure to send the correct type of floating point (real*8 vs real*4, for double vs single precision). Once in FORTRAN, you will not be able to know the size of the array, you'll need to assume it.

SUBROUTINE fortran_func(a)
  real*8 a(16)
  ...
END

if the size is not static, maybe do something like this

SUBROUTINE fortran_func(a,sz)
  real*8 a(sz)
  integer sz
  ...
END

Then send the integer also as a pointer. In C it would be:

int sz=16;
fortran_func(a,&sz);
Blklight