473,569 Members | 3,015 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Integrating Python with Fortran

Hi all,

I'm currently working on a large, legacy Fortran application. I would
like to start new development in Python (as it is mainly I/O related).
In order to do so, however, the whole project needs to be able to
compile in Fortran.

I'm aware of resources like the F2Py Interface generator, but this only
lets me access the Fortran modules I need in Python. I'm wondering if
there's a way to generate the .o files from Python (maybe using
py2exe?) and then link the .o file with the rest of the Fortran project
using something like gcc.

I realize that all of this is highly dependent on the libraries I use,
etc, but I'm just looking for general strategies to attack the problem
or someone to tell me that this is impossible.

Oct 31 '06 #1
3 5163
unexpected schrieb:
I'm aware of resources like the F2Py Interface generator, but this only
lets me access the Fortran modules I need in Python. I'm wondering if
there's a way to generate the .o files from Python (maybe using
py2exe?) and then link the .o file with the rest of the Fortran project
using something like gcc.

I realize that all of this is highly dependent on the libraries I use,
etc, but I'm just looking for general strategies to attack the problem
or someone to tell me that this is impossible.
Please take a look at the "extending and embedding" tutorial. This
explains you how to integrate Python code into a C application.
If you think this could work for you if just your application was C, I
think the Python-Fortran people can give you precise instructions on how
to integrate Python code into a Fortran program.

In the simplest embedding example, you just link the Python VM itself
into the hosting application. The actual Python files stay on disk, and
invoking a Python function from C/Fortran will just end up doing a
regular Python import (with searching sys.path and everything).

If, for packaging reasons, you prefer to have the Fortran program
stand-alone, I recommend to use freeze. freeze gives you indeed .o files
for Python files, plus a global table of all frozen modules. Then, when
doing an import, the interpreter won't go to disk anymore, but it will
import the byte code "from memory" (it still would be a regular import
operation). Freeze, of course, requires you to recompile/relink your
application every time you change a Python source file.

HTH,
Martin
Oct 31 '06 #2
MC
Hi!

in afternoon: http://calcul.math.cnrs.fr/article.php3?id_article=150

--
@-salutations

Michel Claveau
Nov 1 '06 #3
unexpected wrote:
Hi all,

I'm currently working on a large, legacy Fortran application. I would
like to start new development in Python (as it is mainly I/O related).
In order to do so, however, the whole project needs to be able to
compile in Fortran.

I'm aware of resources like the F2Py Interface generator, but this only
lets me access the Fortran modules I need in Python. I'm wondering if
there's a way to generate the .o files from Python (maybe using
py2exe?) and then link the .o file with the rest of the Fortran project
using something like gcc.
There are no tools specifically for embedded Python in Fortran. However, there
is Elmer, which helps to create a C API for a Python library (essentially the
inverse of SWIG). One can then wrap that C API with a Fortran-compliant
interface in the fairly standard ways.

http://elmer.sourceforge.net/

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco

Nov 1 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
6347
by: Michael Chermside | last post by:
richardc writes: > Im no expert but wouldnt you accept that Python has 'borrowed' FORTRAN's > fixed format syntax. I can only think of Python and FORTRAN off the top of > my head which use whitespace as part of the syntax. Definitely NOT. Without addressing the question of HOW Python came by the idea of using indentation to indicate block...
44
3377
by: Carl | last post by:
"Nine Language Performance Round-up: Benchmarking Math & File I/O" http://www.osnews.com/story.php?news_id=5602 I think this is an unfair comparison! I wouldn't dream of developing a numerical application in Python without using prebuilt numerical libraries and data objects such as dictionaries and lists. I have been experimenting with...
38
3707
by: kbass | last post by:
In different articles that I have read, persons have constantly eluded to the productivity gains of Python. One person stated that Python's productivity gain was 5 to 10 times over Java in some in some cases. The strange thing that I have noticed is that there were no examples of this productivity gain (i.e., projects, programs, etc.,...). ...
29
3577
by: Bart Nessux | last post by:
Just fooling around this weekend. Wrote and timed programs in C, Perl and Python. Each Program counts to 1,000,000 and prints each number to the console as it counts. I was a bit surprised. I'm not an expert C or Perl programming expery, I'm most familiar with Python, but can use the others as well. Here are my results: C = 23 seconds...
7
2058
by: stormslayer | last post by:
Folks: I've been considering a shift to python. I currently use c++builder (borland) or perl. I do computational models / statistics programming, and was interested in python b/c it a. has a library that connects to the R stats package b. has code that seems way more readable than anything else There is, however, at least for my...
54
3935
by: seberino | last post by:
Many people I know ask why Python does slicing the way it does..... Can anyone /please/ give me a good defense/justification??? I'm referring to why mystring gives me elements 0, 1, 2 and 3 but *NOT* mystring (5th element). Many people don't like idea that 5th element is not invited. (BTW, yes I'm aware of the explanation where slicing
53
4312
by: Michael Tobis | last post by:
Someone asked me to write a brief essay regarding the value-add proposition for Python in the Fortran community. Slightly modified to remove a few climatology-related specifics, here it is. I would welcome comments and corrections, and would be happy to contribute some version of this to the Python website if it is of interest. ===
3
2101
by: sam | last post by:
hello all, i am currently in the process of planning a piece of software to model polymerisation kinetics, and intend to use python for all the high-level stuff. the number-crunching is something i would prefer to do in fortran (which i have never used, but will learn), but i have no experience of accessing non-python code from python. i am...
2
2328
by: mwojc | last post by:
Hi! I released feed-forward neural network for python (ffnet) project at sourceforge. Implementation is extremelly fast (code written mostly in fortran with thin python interface, scipy optimizers involved) and very easy to use. I'm announcing it here because you, folks, are potential users/testers. If anyone is interested please visit...
0
7703
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7619
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8138
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7681
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6290
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5228
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3662
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2118
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.