Dear all,
I have a problem that can be reduced to the following situation:
- mainf.f90 (see below)
a Fortran function that returns an array containing
n-copy's of a given double precision number.
- mainc.c (see below)
a C-file that would like to use this function.
The problem is that it doesn't work (Bus Error on assigment of
array(I) in the Fortran code). One way or another, the output argument
is not available in the Fortran code.
I know one solution would be to change the function into a subroutine,
adding the result as an extra argument, but this would spoil the whole
design of the project. So I'd like to know if anyone has an
alternative way to solve this.
Best Regards
ps: for the sake of completeness: I'm using the latest stable
gFortran, gcc 4.3 and I'm working on a Intel Mac.
[1]: http://docs.sun.com/source/806-3593/11_cfort.html
---8<---- MAINF.F90 ---8<-------8<-------8<----
function repeatdouble( N, d ) result( array )
integer, intent( in ) :: N
double precision, dimension( N ) :: array
double precision, intent( in ) :: d
print *, "repeat ", N, " times ..."
print *, "double ", d, "."
print *, "array :", array
do I = 1,N
print *, "making copy nb", i, " of ", N
array(I) = d
end do
end function repeatdouble
--->8------->8------->8------->8------->8------->8----
---8<---- MAINC.C ---8<-------8<-------8<----
#include <stdio.h>
extern void repeatdouble_( double*, int*, double* );
int main(){
double buf[9] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 };
double* ptr2buf = buf;
double d = 3.141592654;
int n = 4;
int i;
// make n copies of ch in sbf
repeatdouble_( ptr2buf, &n, &d );
for( i=0; i<9; i++){
printf("buf[%i]=%d\n", i, buf[i]);
}
}
--->8------->8------->8------->8------->8------->8----


|