It's real easy to pass a C array to Fortran and have it subscriptable
as desired; it's the reverse that is difficult.
For example:
C:
void fortran_sub( float r, int n1, int n2, int n3 );
...
float *r;
r = malloc( 100 * sizeof(float) );
if( r == NULL ) /* check for successful malloc() */...
fortran_sub( r, 2, 5, 10 );
...
Fortran:
SUBROUTINE fortran_sub( r, n1, n2, n3 )
IMPLICIT NONE
INTEGER n1, n2, n3
REAL r( n1, n2, n3 )
INTEGER i1, i2, i3
DO i1 = 1, n1
DO i2 = 1, n2
DO i3 = 1, n3
r( i1, i2, i3 ) = <whatever>
END DO
END DO
END DO
...
AFAIK, to do the reverse -- declare an array in Fortran and
pass it to C, where it is to be accessed using subscript
notation, is not, in general, possible, except perhaps using F90
if you know all the details of the implementation (like how to
take apart the implementation's array descriptor from the C side).
It is even difficult (though not impossible) to declare an array
in C with dimensions known only at runtime and pass it to another
C routine in a manner that allows use of subscript notation in
the called subroutine. (That is, it's hard if the array is
multidimensional.)
One solution is dope arrays; the other solution is not to use
subscript notation, but to calculate the offset into a 1D array.
-P.
*** "Freedom's just another word for nothing left to lose." (B. Yeltsin)***
*Peter Shenkin; Chemistry, Columbia U.; [log in to unmask] (212)854-5143*
* MacroModel URL: http://www.cc.columbia.edu/cu/chemistry/mmod/mmod.html *
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|