python调用fortran模块
2016-04-08 00:00
489 查看
在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
编译
运行
另外附上f2py支持的数据类型有
以上所述就是本文的全部内容了,希望大家能够喜欢
使用python调用浏览器并打开一个网址的例子
Python调用C/C++动态链接库的方法详解
Python实现子类调用父类的方法
Nodejs中调用系统命令、Shell脚本和Python脚本的方法和实例
举例讲解Linux系统下Python调用系统Shell的方法
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
以上所述就是本文的全部内容了,希望大家能够喜欢
您可能感兴趣的文章:
Python自定义函数的创建、调用和函数的参数详解使用python调用浏览器并打开一个网址的例子
Python调用C/C++动态链接库的方法详解
Python实现子类调用父类的方法
Nodejs中调用系统命令、Shell脚本和Python脚本的方法和实例
举例讲解Linux系统下Python调用系统Shell的方法
相关文章推荐
- Python动态类型的学习---引用的理解
- Python3写爬虫(四)多线程实现数据爬取
- 垃圾邮件过滤器 python简单实现
- 下载并遍历 names.txt 文件,输出长度最长的回文人名。
- install and upgrade scrapy
- Scrapy的架构介绍
- Centos6 编译安装Python
- 使用Python生成Excel格式的图片
- 让Python文件也可以当bat文件运行
- [Python]推算数独
- Python中zip()函数用法举例
- Python中map()函数浅析
- Python将excel导入到mysql中
- Python在CAM软件Genesis2000中的应用
- 使用Shiboken为C++和Qt库创建Python绑定
- FREEBASIC 编译可被python调用的dll函数示例
- Python 七步捉虫法