当前位置: 技术问答>linux和unix
怎样在FORTRAN里面调用C写的函数?
来源: 互联网 发布时间:2015-07-31
本文导语: 怎样在FORTRAN里面调用C写的函数? 哪位大虾能帮帮忙!! | 10.8 Example - Fortran Calling C Example 10-4 shows a C function that is called by the Fortran main program shown in Example 10-3. Notice that each ...
怎样在FORTRAN里面调用C写的函数?
哪位大虾能帮帮忙!!
哪位大虾能帮帮忙!!
|
10.8 Example - Fortran Calling C
Example 10-4 shows a C function that is called by the Fortran main program shown in Example 10-3. Notice that each argument is defined as a pointer, since Fortran passes by reference. Also notice that the C function name uses all lower-case and a trailing "_".
logical*1 bool1
character letter1
integer*4 numint1, numint2
real numfloat1
double precision numdoub1
integer*2 numshor1
external cfunc
call cfunc (bool1, letter1, numint1, numint2,
& numfloat1, numdoub1, numshor1)
write( *, "(L2, A2, I5, I5, F6.1, F6.1, I5)")
& bool1, letter1, numint1, numint2, numfloat1,
& numdoub1, numshor1
end
Example 10-3: Fortran Main Program fmain.f
#define TRUE 0xff
#define FALSE 0
void
cfunc_( bool1, letter1, numint1, numint2, numfloat1,
numdoub1, numshor1, len_letter1)
char *bool1, *letter1;
int *numint1, *numint2;
float *numfloat1;
double *numdoub1;
short *numshor1;
int len_letter1;
{
*bool1 = TRUE;
*letter1 = 'v';
*numint1 = 11;
*numint2 = -44;
*numfloat1 = 39.6 ;
*numdoub1 = 39.2 ;
*numshor1 = 981;
}
Example 10-4: C function cfunc_
Compile and execute the program fmain.f with the call to cfunc_ using the following command lines:
$ pgcc -c cfunc.c
$ pgf90 cfunc.o fmain.f
Executing the a.out file should produce the following output:
T v 11 -44 39.6 39.2 981
Example 10-4 shows a C function that is called by the Fortran main program shown in Example 10-3. Notice that each argument is defined as a pointer, since Fortran passes by reference. Also notice that the C function name uses all lower-case and a trailing "_".
logical*1 bool1
character letter1
integer*4 numint1, numint2
real numfloat1
double precision numdoub1
integer*2 numshor1
external cfunc
call cfunc (bool1, letter1, numint1, numint2,
& numfloat1, numdoub1, numshor1)
write( *, "(L2, A2, I5, I5, F6.1, F6.1, I5)")
& bool1, letter1, numint1, numint2, numfloat1,
& numdoub1, numshor1
end
Example 10-3: Fortran Main Program fmain.f
#define TRUE 0xff
#define FALSE 0
void
cfunc_( bool1, letter1, numint1, numint2, numfloat1,
numdoub1, numshor1, len_letter1)
char *bool1, *letter1;
int *numint1, *numint2;
float *numfloat1;
double *numdoub1;
short *numshor1;
int len_letter1;
{
*bool1 = TRUE;
*letter1 = 'v';
*numint1 = 11;
*numint2 = -44;
*numfloat1 = 39.6 ;
*numdoub1 = 39.2 ;
*numshor1 = 981;
}
Example 10-4: C function cfunc_
Compile and execute the program fmain.f with the call to cfunc_ using the following command lines:
$ pgcc -c cfunc.c
$ pgf90 cfunc.o fmain.f
Executing the a.out file should produce the following output:
T v 11 -44 39.6 39.2 981
|
这年头用fortran的太少了。。。
|
好好学习