黑松山资源网 Design By www.paidiu.com
在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 ] <dim> | <start>:<end> | * | : intent([ in | inout | out | hide | in,out | inout,out | c | copy | cache | callback | inplace | aux ]) dimension(<dimspec>) common, parameter allocatable optional, required, external depend([<names>]) check([<C-booleanexpr>]) note(<LaTeX text>) usercode, callstatement, callprotoargument, threadsafe, fortranname pymethoddef entry
以上所述就是本文的全部内容了,希望大家能够喜欢
黑松山资源网 Design By www.paidiu.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
黑松山资源网 Design By www.paidiu.com
暂无评论...
更新日志
2024年10月09日
2024年10月09日
- s14全球总决赛瑞士轮什么时候开始 s14瑞士轮开始时间介绍
- 晨报|《使命召唤21》全球发布预告 《异形:隔离》续作官宣开发中
- 隐形女联动毁灭博士?杰西卡·阿尔巴与小唐尼晒合影
- 《博德之门3》7号补丁发布后:Mod下载量达到2200万次!
- 徐璨宾《井底的蚯蚓》[FLAC/分轨][218.37MB]
- 王冰冰《Vaga Luna 月球漫游》[320K/MP3][62.76MB]
- 证声音乐图书馆《蔚蓝海岸·爵士度假日》[320K/MP3][59.79MB]
- 群星.1993-飞图合唱歌曲精丫飞图】【WAV+CUE】
- 王霏霏.2024-TOOOOO.BUSY(EP)【SNMUSIC】【FLAC分轨】
- 张宇.2016-好男人的情歌NEWXRCD【金牌大风】【WAV+CUE】
- 《食戟之灵》小林龙胆兔女郎比基尼版模型即将发售
- 重大里程碑!九号电动第500万台智能两轮电动车正式下线
- TGA主持人发文祝贺《暗喻幻想》 国外网友:提名稳了?
- 【原神】V5.0攻略 | 旋曜玉帛收集攻略(序号81~序号90)
- 【原神】V5.0攻略 | 旋曜玉帛收集攻略(序号91~序号100)