我试图从C调用FORTRAN函数
我的问题是:
如果fortRoutine是我的fortran子程序的名称,那么我从C中调用它fortRoutine_.如果fortRoutine只包含一个字符数组参数,那么我可以像这样传递:
fortRoutine_("I am in fortran");
Run Code Online (Sandbox Code Playgroud)在调用FORTRAN子例程时,何时应该使用pass by值和何时通过引用传递?
由于我是C的新手,我对此并不了解.如果可能的话,请提供一些很好的教程链接.
我在Fortran和C之间传递字符串时遇到问题。
Fortran子例程调用如下所示:
CALL MMEINITWRAPPER(TRIM(ADJUSTL(PRMTOP)), 0, SALTCON, RGBMAX, CUT)
Run Code Online (Sandbox Code Playgroud)
与之配合使用的C具有签名:
int mmeinitwrapper_(char *name,
int *igb,
REAL_T *saltcon,
REAL_T *rgbmax1,
REAL_T *cutoff1)
Run Code Online (Sandbox Code Playgroud)
我在不同的地方放了一些打印语句,然后一切正常,直到使用ifort编译为止。在这种情况下,输出如下所示:
Topology file name:
coords.prmtop
coords.prmtop
Topology file name length: 81 13
length in C: 8
read argument: coords.prmtop??*
Reading parm file (coords.prmtop??*)
coords.prmtop??*, coords.prmtop??*.Z: does not exist
Cannot read parm file coords.prmtop??*
Run Code Online (Sandbox Code Playgroud)
使用波特兰编译器:
Topology file name:
coords.prmtop
coords.prmtop
Topology file name length: 81 13
length in C: 8
read argument: coords.prmtop
Reading parm file (coords.prmtop)
Run Code Online (Sandbox Code Playgroud)
第一组中的长度来自未修剪/未调节弦的Fortran,然后来自修剪/已调节弦。C中的长度为sizeof(name)/sizeof(name[0])。
似乎正在传递一段过长的内存,并且在随后的运行中,您会写入不同长度的不良内容(尽管C中报告的长度始终为8)。 …