I'm trying to implement aprecision index in a Turbodecode algorythm written in C. After finding a way to do that i'm trying to embedd a python function in order tu use matplotlib and plot a graph showing the precision of the decoder.
Problem is trying embedding stops at PYImport_Import() without going anyfurther and without giving any error message.
my python file is called plot.py and inside it is a simple:
import matplotlib.pyplot as plt
def show_plt(max_x, y):
print("enter")
fig, ax1 = plt.subplots()
x_array = range(0,max_x+1)
ax1.plot(x_array, y)
plt.show()
while my C part of code where i'm trying to call this python function is written like this:
#include <python2.7/Python.h>
...
if (decision)
{
printf("here1\n");
Py_Initialize();
//PyRun_SimpleString("import sys; sys.path.append('.')");
decoded = malloc(packet_length * sizeof *decoded);
double est[packet_length];
PyObject *tuple = PyList_New(packet_length);
for (int i = 0; i < packet_length; ++i)
{
double one = app[1][i] + extrinsic[1][i];
double zero = app[0][i] + extrinsic[0][i];
double delta = abs(one + zero);
if (delta > 150)//THRESHHOLD TO DEFINE
delta = 150;
est[i] = (150 - delta) / 150;
PyList_Append(tuple,PyFloat_FromDouble(est[i]));
decoded[i] = one > zero;
}
printf("here2\n");
PyObject *myModuleString = PyString_FromString((char *)"plot");
printf("here3\n");
PyObject *myModule = PyImport_Import(myModuleString);
printf("here4\n");
PyObject *myFunction = PyObject_GetAttrString(myModule, (char *)"show_plt");
printf("here5\n");
PyObject *args = PyTuple_Pack(2, packet_length, tuple);
printf("here6\n");
PyObject_CallObject(myFunction, args);
printf("here7\n");
}
note that code stops after printf("here3") without errors.
I'm not familiar with calling python functions in C so any help would be most appreciated.