fortran的gui开发 python_python调用fortran模块

在python中调用fortran代码,要用到f2py这个程序。它的项目主页在此。现在该项目已经合并到numpy中了,先安装python再装好numpy,就可以使用f2py。不过对windows平台必须使用gnu的fortran编译器gfortran,在此下载。装完了python,numpy和gfortran这三样东西之后,还必须更改如下几个环境变量:

1.在$PATH中添加gfortran的路径,我的是c:\Program Files\pythonxy\mingw\bin\

2.在$PATH中添加python的路径,我的是c:\Python26\

3.新建环境变量C_INCLUDE_PATH,添加gfortran头文件的路径,我的是c:\Program Files\pythonxy\mingw\include\

好啦现在f2py就可以用了。新建fortran程序foo.f90如下

foo.f90

subroutine hello (a)

integer a

write(*,*)'Hello from Fortran90!!!',a

end subroutine hello

编译

f2py -m foo -c foo.f90

运行

$ python

Python 2.7.6 (default, Jun 22 2015, 17:58:13)

[GCC 4.8.2] on linux2

Type "help", "copyright", "credits" or "license" for more information.

>>> import foo

>>> foo.hello(15)

Hello from Fortran90!!! 15

另外附上f2py支持的数据类型有

integer[ | *1 | *2 | *4 | *8 ], logical[ | *1 | *2 | *4 | *8 ]

integer*([ -1 | -2 | -4 | -8 ])

character[ | *(*) | *1 | *2 | *3 | ... ]

real[ | *4 | *8 | *16 ], double precision

complex[ | *8 | *16 | *32 ]

| : | * | :

intent([ in | inout | out | hide | in,out | inout,out | c |

copy | cache | callback | inplace | aux ])

dimension()

common, parameter

allocatable

optional, required, external

depend([])

check([])

note()

usercode, callstatement, callprotoargument, threadsafe, fortranname

pymethoddef

entry

以上所述就是本文的全部内容了,希望大家能够喜欢

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值