由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Unix版 - how to use function calloc of c in fortran?
相关主题
Urgent question on Fortran我决定给自己的程序加密?
interview question[转载] gprof question
alloc memory in UNIX[转载] shared library一问
[转载] two programming questionsIs it possible?
help for g77[转载] 为什么会在调用malloc时Segmentation fault?
Can anyone recommend any web site to download a FFT subroutine for alpha machine?[转载] Re: 为什么会在调用malloc时Segmentation fault?
how to fork a subroutine in unix?[转载] system call question
[转载] help: list private and global variables in perlMemory check problem?
相关话题的讨论汇总
话题: fortran话题: calloc话题: subroutine话题: allocate话题: fsub
进入Unix版参与讨论
1 (共1页)
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.

1 (共1页)
进入Unix版参与讨论
相关主题
Memory check problem?help for g77
async-signal safe 问题Can anyone recommend any web site to download a FFT subroutine for alpha machine?
[转载] help about C: reallochow to fork a subroutine in unix?
请问,malloc函数怎样实现?[转载] help: list private and global variables in perl
Urgent question on Fortran我决定给自己的程序加密?
interview question[转载] gprof question
alloc memory in UNIX[转载] shared library一问
[转载] two programming questionsIs it possible?
相关话题的讨论汇总
话题: fortran话题: calloc话题: subroutine话题: allocate话题: fsub