static PyObject *PyCMOR_write(PyObject * self, PyObject * args) { signal(signal_to_catch, signal_handler); int ierr, var_id; PyObject *data_obj = NULL; PyArrayObject *data_array = NULL; void *data; char *suffix; char *itype; char type; int ntimes; PyObject *times_obj = NULL; PyArrayObject *times_array = NULL; void *times; double itime; PyObject *times_bnds_obj = NULL; PyArrayObject *times_bnds_array = NULL; void *times_bnds; PyObject *ref_obj; int *ref; int iref; if (!PyArg_ParseTuple (args, "iOssiOOO", &var_id, &data_obj, &itype, &suffix, &ntimes, ×_obj, ×_bnds_obj, &ref_obj)) return NULL; data_array = (PyArrayObject *) PyArray_ContiguousFromObject(data_obj, NPY_NOTYPE, 1, 0); data = PyArray_DATA(data_array); if (times_obj == Py_None) { times = NULL; } else { if (ntimes > 1) { times_array = (PyArrayObject *) PyArray_ContiguousFromObject(times_obj, NPY_NOTYPE, 1, 0); times = (void *)PyArray_DATA(times_array); } else { itime = (double)PyFloat_AsDouble(times_obj); times = &itime; } } if (times_bnds_obj == Py_None) { times_bnds = NULL; } else { times_bnds_array = (PyArrayObject *) PyArray_ContiguousFromObject(times_bnds_obj, NPY_NOTYPE, 1, 0); times_bnds = (void *)PyArray_DATA(times_bnds_array); } if (ref_obj == Py_None) { ref = NULL; } else { #if PY_MAJOR_VERSION >= 3 iref = (int)PyLong_AsLong(ref_obj); #else iref = (int)PyInt_AsLong(ref_obj); #endif ref = &iref; } type = itype[0]; ierr = 0; ierr = cmor_write(var_id, data, type, suffix, ntimes, times, times_bnds, ref); Py_DECREF(data_array); if (times_array != NULL) { Py_DECREF(times_array); } if (times_bnds_array != NULL) { Py_DECREF(times_bnds_array); } if (ierr != 0 || raise_exception) { raise_exception = 0; PyErr_Format(CMORError, exception_message, "write"); return NULL; } return (Py_BuildValue("i", ierr)); }
static PyObject * PyCMOR_write(PyObject *self,PyObject *args) { int ierr,var_id; PyObject *data_obj=NULL; PyArrayObject *data_array=NULL; void *data; char *suffix,*itype; char type; int ntimes; PyObject *times_obj=NULL; PyArrayObject *times_array=NULL; void *times; double itime; PyObject *times_bnds_obj=NULL; PyArrayObject *times_bnds_array=NULL; void *times_bnds; PyObject *ref_obj; int *ref; int iref; /* HUGE assumtion here is that the data is contiguous! */ if (!PyArg_ParseTuple(args,"iOssiOOO",&var_id,&data_obj,&itype,&suffix,&ntimes,×_obj,×_bnds_obj,&ref_obj)) return NULL; data_array =(PyArrayObject *) PyArray_ContiguousFromObject(data_obj,PyArray_NOTYPE,1,0); data = data_array->data; if (times_obj == Py_None) { times = NULL; } else { if (ntimes>1) { times_array =(PyArrayObject *) PyArray_ContiguousFromObject(times_obj,PyArray_NOTYPE,1,0); times = (void *)times_array->data; } else { itime = (double) PyFloat_AsDouble(times_obj); times = &itime; } } if (times_bnds_obj == Py_None) { times_bnds = NULL; } else { times_bnds_array =(PyArrayObject *) PyArray_ContiguousFromObject(times_bnds_obj,PyArray_NOTYPE,1,0); times_bnds = (void *)times_bnds_array->data; } if (ref_obj == Py_None) { ref = NULL; } else { iref = (int) PyInt_AsLong(ref_obj); ref = &iref; } type = itype[0]; /* printf("going in, suffix is: -%s-\n",suffix); */ ierr = 0; ierr = cmor_write(var_id, data, type, suffix, ntimes, times, times_bnds, ref); Py_DECREF(data_array); if (times_array!=NULL) {Py_DECREF(times_array);} if (times_bnds_array!=NULL) {Py_DECREF(times_bnds_array);} if (ierr != 0 ) return NULL; /* Return NULL Python Object */ Py_INCREF(Py_None); return Py_None; }