s**l 发帖数: 30 | 1 want to use calloc in c to allocate memory dynamically in fortran,
because f77 can not support allocate memory dynamically.
I heard it is doable, who can help me and give me an example, like
allocate an array. Thanks. |
s**s 发帖数: 242 | 2 in C:
....
float *B,...
B=(float *)malloc(N*sizeof(float));
fsub_(B,...)
in fortran:
subroutine fsub(B,....)
real B(1)
【在 s**l 的大作中提到】 : want to use calloc in c to allocate memory dynamically in fortran, : because f77 can not support allocate memory dynamically. : I heard it is doable, who can help me and give me an example, like : allocate an array. Thanks.
|
s**l 发帖数: 30 | 3 Can it be more specified?
like an example which is tested. Thanks.
I tested the following
Fortran part:
program test
real B(1)
call fsub(B)
end
subroutine fsub(B)
real B(1)
do i=1,10
B(i)=i*1.
write(6,*) B(i)
enddo
end
C part:
#include
#include
void aaa( )
{
float * B;
B=(float *)malloc(10*sizeof(float));
fsub_(B);
}
But it says segmentation fault.....
【在 s**s 的大作中提到】 : in C: : .... : float *B,... : B=(float *)malloc(N*sizeof(float)); : fsub_(B,...) : in fortran: : subroutine fsub(B,....) : real B(1)
|
q*****m 发帖数: 73 | 4 Do you want to call a "C" subroutine _from_ Fortran,
or do you want to call a Fortran subroutine _from_ C?
【在 s**l 的大作中提到】 : Can it be more specified? : like an example which is tested. Thanks. : I tested the following : Fortran part: : program test : real B(1) : call fsub(B) : end : subroutine fsub(B) : real B(1)
|
s**l 发帖数: 30 | 5 I want to call a "C" subroutine from Fortran.
【在 q*****m 的大作中提到】 : Do you want to call a "C" subroutine _from_ Fortran, : or do you want to call a Fortran subroutine _from_ C?
|
q*****m 发帖数: 73 | 6 example
test.for:
program test
integer i, j
call sub(i,j)
print*, i, j
end
sub.c:
void sub_(int* i, int* j)
{
*i = 100;
*j=200;
return;
}
compile: gcc -c sub.c; g77 test.for sub.o
【在 s**l 的大作中提到】 : I want to call a "C" subroutine from Fortran.
|
s**l 发帖数: 30 | 7 Thanks, it works, but I need to allocate an array from C subroutine and
use it in fortran.
【在 q*****m 的大作中提到】 : example : test.for: : program test : integer i, j : call sub(i,j) : print*, i, j : end : sub.c: : void sub_(int* i, int* j) : {
|
q*****m 发帖数: 73 | 8 那没戏.
Suggest you make the Fortran program as subroutine, then call from C.
【在 s**l 的大作中提到】 : Thanks, it works, but I need to allocate an array from C subroutine and : use it in fortran.
|
s**l 发帖数: 30 | 9 I heard it is possible.
I think the problem is the data communication between C and fortran.
【在 q*****m 的大作中提到】 : 那没戏. : Suggest you make the Fortran program as subroutine, then call from C.
|
q*****m 发帖数: 73 | 10 Ask the person whom you "heard" this from. Please share with us
how to do that once you work things out.
【在 s**l 的大作中提到】 : I heard it is possible. : I think the problem is the data communication between C and fortran.
|