#include "Py_py-api.h" #include "genlib.h" #include "log.h" #include "geostat.h" #include "pressure.h" #include "simpio.h" #include "toolsIO.h" #include #include #include #include #include #include #include #include #if PY_MAJOR_VERSION >= 3 #define PyIntObject PyLongObject #define PyInt_Type PyLong_Type #define PyInt_Check(op) PyLong_Check(op) #define PyInt_CheckExact(op) PyLong_CheckExact(op) #define PyInt_FromString PyLong_FromString #define PyInt_FromUnicode PyLong_FromUnicode #define PyInt_FromLong PyLong_FromLong #define PyInt_FromSize_t PyLong_FromSize_t #define PyInt_FromSsize_t PyLong_FromSsize_t #define PyInt_AsLong PyLong_AsLong #define PyInt_AS_LONG PyLong_AS_LONG #define PyInt_AsSsize_t PyLong_AsSsize_t #define PyInt_AsUnsignedLongMask PyLong_AsUnsignedLongMask #define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask #define PyNumber_Int PyNumber_Long #endif #if PY_MAJOR_VERSION >= 3 #define PyBoolObject PyLongObject #endif #if PY_MAJOR_VERSION >= 3 && CYTHON_COMPILING_IN_PYPY #ifndef PyUnicode_InternFromString #define PyUnicode_InternFromString(s) PyUnicode_FromString(s) #endif #endif int Py_getvalues(PyObject* args, long* seed, struct grid_mod* grid, struct vario_mod* variogram, struct statistic_mod* stat, int* cores) { clock_t t = clock(); log_info("RESULT = in progress"); int i, varioNargs = 12, j = 0; PyObject* listvario; PyObject* vgr; //char* gwnfilename; stat->nblock_mean = 1; stat->nblock_var = 1; stat->mean = (double*)malloc(stat->nblock_mean * sizeof(double)); if (stat->mean == NULL) return 0; stat->variance = (double*)malloc(stat->nblock_var * sizeof(double)); if (stat->variance == NULL) { free(stat->mean); log_error("RESULT = failed"); return 0; } if (!PyArg_ParseTuple(args, "iiidddlO!ddii", /*"iiidddslO!ddi",*/ &(grid->NX), &(grid->NY), &(grid->NZ), &(grid->DX), &(grid->DY), &(grid->DZ), /*gwnfilename,*/ seed, &PyList_Type, &listvario, stat->mean + 0, stat->variance + 0, &(stat->type), cores)) { free(stat->mean); free(stat->variance); log_error("RESULT = failed"); return 0; } variogram->Nvario = PyList_Size(listvario); variogram->var = (double*)malloc(variogram->Nvario * sizeof(double)); if (variogram->var == NULL) { free(stat->mean); free(stat->variance); log_error("RESULT = failed"); return 0; } variogram->vario = (int*)malloc(variogram->Nvario * sizeof(int)); if (variogram->vario == NULL) { free(stat->mean); free(stat->variance); free(variogram->var); log_error("RESULT = failed"); return 0; } variogram->alpha = (double*)malloc(variogram->Nvario * sizeof(double)); if (variogram->alpha == NULL) { free(stat->mean); free(stat->variance); free(variogram->var); free(variogram->vario); log_error("RESULT = failed"); return 0; } variogram->scf = (double*)malloc(3 * variogram->Nvario * sizeof(double)); if (variogram->var == NULL) { free(stat->mean); free(stat->variance); free(variogram->var); free(variogram->vario); free(variogram->alpha); log_error("RESULT = failed"); return 0; } variogram->ap = (double*)malloc(9 * variogram->Nvario * sizeof(double)); if (variogram->var == NULL) { free(stat->mean); free(stat->variance); free(variogram->var); free(variogram->vario); free(variogram->alpha); free(variogram->scf); log_error("RESULT = failed"); return 0; } for (i = 0; i < variogram->Nvario; i++) { vgr = PyList_GetItem(listvario, i); if (PyTuple_Size(vgr) != 12) { log_error("RESULT = failed"); return 0; } (variogram->var)[i] = PyFloat_AsDouble(PyTuple_GetItem(vgr, j++)); (variogram->vario)[i] = (int)PyInt_AsLong(PyTuple_GetItem(vgr, j++)); (variogram->alpha)[i] = PyFloat_AsDouble(PyTuple_GetItem(vgr, j++)); (variogram->scf)[i * 3 + 0] = PyFloat_AsDouble(PyTuple_GetItem(vgr, j++)); (variogram->scf)[i * 3 + 1] = PyFloat_AsDouble(PyTuple_GetItem(vgr, j++)); (variogram->scf)[i * 3 + 2] = PyFloat_AsDouble(PyTuple_GetItem(vgr, j++)); (variogram->ap)[i * 9 + 0] = PyFloat_AsDouble(PyTuple_GetItem(vgr, j++)); (variogram->ap)[i * 9 + 1] = PyFloat_AsDouble(PyTuple_GetItem(vgr, j++)); (variogram->ap)[i * 9 + 2] = PyFloat_AsDouble(PyTuple_GetItem(vgr, j++)); (variogram->ap)[i * 9 + 3] = PyFloat_AsDouble(PyTuple_GetItem(vgr, j++)); (variogram->ap)[i * 9 + 4] = PyFloat_AsDouble(PyTuple_GetItem(vgr, j++)); (variogram->ap)[i * 9 + 5] = PyFloat_AsDouble(PyTuple_GetItem(vgr, j++)); } t = clock() - t; double time_taken = ((double)t)/CLOCKS_PER_SEC; // calculate the elapsed time log_info("RESULT = success, ELAPSED = %f seconds", time_taken); return 1; }