You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
simulacion-permeabilidad/fftma_module/gen/lib_src/Py_getvalues.c

114 lines
3.6 KiB
C

#include <Python.h>
#include <numpy/arrayobject.h>
#include <stdio.h>
#include <stddef.h>
#include <string.h>
#include <stdarg.h>
#include <stdlib.h>
#include "Py_py-api.h"
#include "genlib.h"
#include "simpio.h"
#include "geostat.h"
#include "pressure.h"
#include "toolsIO.h"
#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 i, varioNargs=12, j=0;
PyObject* listvario;
PyObject* vgr;
//char* gwnfilename;
printf("Py_getvalues\n");
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) return 0;
if(!PyArg_ParseTuple(args, "iiidddlO!ddi", /*"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))) return 0;
variogram->Nvario=PyList_Size(listvario);
variogram->var=(double*)malloc(variogram->Nvario*sizeof(double));
if(variogram->var==NULL) return 0;
variogram->vario=(int*)malloc(variogram->Nvario*sizeof(int));
if(variogram->vario==NULL) return 0;
variogram->alpha=(double*)malloc(variogram->Nvario*sizeof(double));
if(variogram->alpha==NULL) return 0;
variogram->scf=(double*)malloc(3*variogram->Nvario*sizeof(double));
if(variogram->var==NULL) return 0;
variogram->ap=(double*)malloc(9*variogram->Nvario*sizeof(double));
if(variogram->var==NULL) return 0;
for(i=0;i<variogram->Nvario;i++)
{
vgr=PyList_GetItem(listvario,i);
if(PyTuple_Size(vgr)!=12) 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++));
}
return 1;
}