python怎么调用模块化的fortran源代码_如何编译用于FORTRAN的Python脚本?

Although I found many answers and discussions about this question, I am unable to find a solution particular to my situation. Here it is:

I have a main program written in FORTRAN.

I have been given a set of python scripts that are very useful.

My goal is to access these python scripts from my main FORTRAN program. Currently, I simply call the scripts from FORTRAN as such:

CALL SYSTEM ('python pyexample.py')

Data is read from .dat files and written to .dat files. This is how the python scripts and the main FORTRAN program communicate to each other.

I am currently running my code on my local machine. I have python installed with numpy, scipy, etc.

My problem:

The code needs to run on a remote server. For strictly FORTRAN code, I compile the code locally and send the executable to the server where it waits in a queue. However, the server does not have python installed. The server is being used as a number crunching station between universities and industry. Installing python along with the necessary modules on the server is not an option. This means that my “CALL SYSTEM ('python pyexample.py')” strategy no longer works.

Solution?:

I found some information on a couple of things in thread Is it feasible to compile Python to machine code?

Shedskin, Psyco, Cython, Pypy, Cpython API

These “modules”(? Not sure if that's what to call them) seem to compile python script to C code or C++. Apparently not all python features can be translated to C. As well, some of these appear to be experimental. Is it possible to compile my python scripts with my FORTRAN code? There exists f2py which converts FORTRAN code to python, but it doesn't work the other way around.

Any help would be greatly appreciated. Thank you for your time.

Vincent

PS: I'm using python 2.6 on Ubuntu

解决方案

One way or another, you'll need to get the Python runtime on your server, otherwise it won't be possible to execute Python bytecode. Ignacio is on the right track with suggesting invoking libpython directly, but due to Fortran's parameter-passing conventions, it will be a lot easier for you to write a C wrapper to handle the interface between Fortran and the CPython embedding API.

Unfortunately, you're doing this the hard way -- it's a lot easier to write a Python program that can call Fortran subroutines than the other way around.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值