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);
}