#include <stdio.h>
#include <stdlib.h>
#include "Python.h"
int main(int argc, char *argv) {
int cListA[8500];
int cListB[8500];
int cListC[8500];
int cListD[8500];
int cListE[8500];
int cListF[8500];
int *cResult = NULL;
int randInt = -1;
int loopControl = 0;
int sz;
PyObject *module, *dict, *func, *value, *arglist,*pArgs;
PyListObject *listA, *listB, *listC, *listD, *listE, *listF, *componentList;
Py_Initialize(); //Set up the interpreter
PyRun_SimpleString("import sys\n"); //This line and the next
PyRun_SimpleString("sys.path.append('.')\n"); //are only b/c of my system
module = PyImport_ImportModule("logic"); //Import the module in logic.py
dict = PyModule_GetDict(module); //I have no idea
func = PyDict_GetItemString(dict, "HW"); //Get a reference to the function
for(loopControl = 0; loopControl < 8500; loopControl++) { //C data setup
cListA[loopControl] = rand();
cListB[loopControl] = rand();
cListC[loopControl] = rand();
cListD[loopControl] = rand();
cListE[loopControl] = rand();
cListF[loopControl] = rand();
}
listA = PyList_New(8500);
listB = PyList_New(8500);
listC = PyList_New(8500);
listD = PyList_New(8500);
listE = PyList_New(8500);
listF = PyList_New(8500);
for(loopControl = 0; loopControl < 8500; loopControl++) {
PyList_SetItem(listA,loopControl,PyInt_FromLong((long)cListA[loopControl]));
PyList_SetItem(listB,loopControl,PyInt_FromLong((long)cListB[loopControl]));
PyList_SetItem(listC,loopControl,PyInt_FromLong((long)cListC[loopControl]));
PyList_SetItem(listD,loopControl,PyInt_FromLong((long)cListD[loopControl]));
PyList_SetItem(listE,loopControl,PyInt_FromLong((long)cListE[loopControl]));
PyList_SetItem(listF,loopControl,PyInt_FromLong((long)cListF[loopControl]));
}
componentList = PyList_New(6);
PyList_SetItem(componentList,0,listA);
PyList_SetItem(componentList,1,listB);
PyList_SetItem(componentList,2,listC);
PyList_SetItem(componentList,3,listD);
PyList_SetItem(componentList,4,listE);
PyList_SetItem(componentList,5,listF);
pArgs = PyTuple_New(1);
PyTuple_SetItem(pArgs,0,componentList);
value = PyObject_CallObject(func,pArgs); //Call HW
Py_DECREF(module);
Py_DECREF(dict);
Py_DECREF(func);
Py_DECREF(listA);
Py_DECREF(listB);
Py_DECREF(listC);
Py_DECREF(listD);
Py_DECREF(listE);
Py_DECREF(listF);
Py_DECREF(componentList);
Py_DECREF(pArgs);
sz = PyList_Size(PyList_GetItem(value,0));
cResult = malloc(sz*sizeof(int));
for(loopControl = 0; loopControl < sz; loopControl++) {
cResult[loopControl] = (int) PyInt_AsLong(PyList_GetItem(PyList_GetItem(value,0),loopControl));
if(loopControl % 1000 == 0) printf("Value: %d\n",cResult[loopControl]);
}
free((void *)cResult);
Py_DECREF(value);
Py_Finalize();
return 0;
}