473,395 Members | 1,516 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Call Frotran subroutines by Python Using C++ interface

hey, there

I am new to Python and C++. Now I am trying to call some fortran subroutines in python code. I was told the good way is to write a c++ interface. I am not quite sure how to do it.

For example, in the following case:
I want to call fortran subroutine "realadd" from python , i wrote the following
codes, it seems it far from working. Is there anyone can help me out?
thanks a lot!


t1.py
#!/usr/bin/python
print AddDouble(1.0, 2.0)
----------------------------------------------------------------------------
com.f
SubRoutine RealAdd(a,b,c)
Implicit None
Real *8 a, b, c
c = a+ b
Return
End
------------------------------------------------------------------------------
fort.h
#define FORT(x) x##_
-------------------------------------------------------------------------------
fns.h
#include "fort.h"
#ifdef __cplusplus
extern "C" {
#endif
void FORT(realadd)(double *a, double *b, double *c)
#ifdef __ cplussplus
}
#endif

----------------------------------------------------------------------------------
extension.c
#include <Python.h>
#include "fort.h"
#include "fns.h"

static PyObject *Add(PyObject *self, PyObject *args)
{
double a = 0.0;
double b = 0.0;
double c = -1.0e+23;
if(!PyArg_ParseTuple(args, "dd", &a, &b))
return 0;
FORT(realadd)(&a, &b, &c);
return Py_BuildValue("d", c);
}
Mar 29 '07 #1
0 1347

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Mikko Ohtamaa | last post by:
Hi, I am quite new to Python, PythonCom and COM generally. As a former Java programmer, I have found Python's flexible ability to access native Win32, especially COM, very comfortable. However,...
8
by: Joakim Persson | last post by:
Hello all. I am involved in a project where we have a desire to improve our software testing tools, and I'm in charge of looking for solutions regarding the logging of our software (originating...
47
by: Kenneth McDonald | last post by:
Is there any emerging consensus on the "best" UI for toolkit. Tk never quite made it but from what I can see, both qt and wxWin are both doing fairly well in general. I'm already aware of the...
0
by: haynes george | last post by:
hi .. I was reading the tutorial "Extending and Embedding the python interpreter" available with python .. http://www.python.org/doc/2.2.3/ext/ext.html As per given in the tutorial i...
21
by: Cottonwood | last post by:
I want to call a C module from a Fortran program. Whatever I tried - the linker could not find the C module. I know about the leading underscore and switched even that off. I abstracted everything...
1
by: Wijaya Edward | last post by:
Hi, How does one benchmark multiple subroutines in Python? Is there a built-in library for that? -- Regards, Edward WIJAYA SINGAPORE
1
by: hanhaner | last post by:
hey, there I am new to Python and C++. Now I am trying to call some fortran subroutines in python code. I was told the good way is to write a c++ interface. I am not quite sure how to do it. ...
0
by: SenileOwl | last post by:
I'm working in Visual Basic .NET 2005 I'm creating a program that could potentially hold 50 or more subroutines. However, I will only be calling three or four of the subroutines at a time. I...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.