Fortran编译错误一例

Fortran编译错误一例

login2.stampede(111)$ make
mpif90  -g -ffree-form -DTPV26 -O0 -c -ffixed-line-length-250 -o testInterfaceF.o -I../..//seism_io_interface-v0.2/include testInterface.f
ifort: command line warning #10006: ignoring unknown option '-ffree-form'
ifort: command line warning #10006: ignoring unknown option '-ffixed-line-length-250'
testInterface.f(1): error #5149: Illegal character in statement label field  [p]
program main
^
testInterface.f(1): error #5149: Illegal character in statement label field  [r]
program main
-^
testInterface.f(1): error #5149: Illegal character in statement label field  [o]
program main
--^
testInterface.f(1): error #5149: Illegal character in statement label field  [g]
program main
---^
testInterface.f(1): error #5149: Illegal character in statement label field  [r]
program main
----^
testInterface.f(1): error #5118: First statement in file must not be continued
program main
-----^
testInterface.f(2): error #5149: Illegal character in statement label field  [u]
    use mpi
----^
testInterface.f(3): error #5149: Illegal character in statement label field  [i]
    implicit none
----^

解决办法:
mv testInterface.f testInterface.f90

字符串Fortran与C混合调用注意事项

C/FORTRAN 混合编程时,简单变量在两种语言中都有直接对应的类型,堆栈调用的规则也比较简单。
但字符串、字符串数组的传递可能是个特例。
由于不同的FORTRAN编译器,对字符串的堆栈解释不同,本文介绍的方法仅保证在gcc 与 gfortran环境下适用。

C调用Fortran例子

int main()
{
…….
char s[7];
int b[3];

cstrng_( s, &b[1], 7L );

}
Fortran中
SUBROUTINE cstrng(s, b2)
CHARACTER(*) s
INTEGER b2
END SUBROUTINE openfile

Fortran调用C例子

program main
use mpi
implicit none
…….

CHARACTER (LEN=7) :: s
integer :: b

cstrng( s, b);

end

C中
vois cstrng_(char *s, int *b2, unsigned slen)
{
char cs = (char)malloc(sizeof(char)*(slen+1));
strncpy(cs, s, slen);
strncpy(&cs[slen], “\0”, 1);
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值