// write a primitive static PyObject* pydat_put(HDSObject *self, PyObject *args) { PyObject *value, *dimobj; PyArrayObject *npyval; const char* type; int ndim; if(!PyArg_ParseTuple(args,"siOO:pydat_put",&type,&ndim,&dimobj,&value)) return NULL; if(!checkHDStype(type)) return NULL; HDSLoc* loc = HDS_retrieve_locator(self); // create a pointer to an array of the appropriate data type if(strcmp(type,"_INTEGER") == 0) { npyval = (PyArrayObject*) PyArray_FROM_OTF(value, NPY_INT, NPY_IN_ARRAY | NPY_FORCECAST); } else if(strcmp(type,"_REAL") == 0) { npyval = (PyArrayObject*) PyArray_FROM_OTF(value, NPY_FLOAT, NPY_IN_ARRAY | NPY_FORCECAST); } else if(strcmp(type,"_DOUBLE") == 0) { npyval = (PyArrayObject*) PyArray_FROM_OTF(value, NPY_DOUBLE, NPY_IN_ARRAY | NPY_FORCECAST); } else if(strcmp(type,"_BYTE") == 0) { npyval = (PyArrayObject*) PyArray_FROM_OTF(value, NPY_BYTE, NPY_IN_ARRAY | NPY_FORCECAST); } else if(strcmp(type,"_UBYTE") == 0) { npyval = (PyArrayObject*) PyArray_FROM_OTF(value, NPY_UBYTE, NPY_IN_ARRAY | NPY_FORCECAST); } else if(strncmp(type,"_CHAR*",6) == 0) { npyval = (PyArrayObject*) PyArray_FROM_OT(value, NPY_STRING); } else { return NULL; } void *valptr = PyArray_DATA(npyval); int status = SAI__OK; errBegin(&status); if (ndim > 0) { // npydim is 1-D array stating the size of each dimension ie. npydim = numpy.array([1072 1072]) // these are stored in an hdsdim type (note these are declared as signed) PyArrayObject *npydim = (PyArrayObject*) PyArray_FROM_OTF(dimobj,NPY_INT,NPY_IN_ARRAY|NPY_FORCECAST); hdsdim *dims = (hdsdim*)PyArray_DATA(npydim); datPut(loc,type,ndim,dims,valptr,&status); Py_DECREF(npydim); } else { datPut(loc,type,0,0,valptr,&status); } if (raiseHDSException(&status)) return NULL; Py_DECREF(npyval); Py_RETURN_NONE; }
/*===============================================*/ int datPutUW(const HDSLoc *locator, int ndim, const hdsdim dims[], const unsigned short values[], int *status) { #undef context_name #undef context_message #define context_name "DAT_PUTUW_ERR" #define context_message\ "DAT_PUTUW: Error writing unsigned short integer values to an HDS primitive." datPut(locator, "_UWORD", ndim, dims, values, status); return *status; }
/*========================================*/ int datPutK(const HDSLoc *locator, int ndim, const hdsdim dims[], const int64_t values[], int *status) { #undef context_name #undef context_message #define context_name "DAT_PUTK_ERR" #define context_message\ "DAT_PUTK: Error writing 64-bit integer values to an HDS primitive." datPut(locator, "_INT64", ndim, dims, values, status); return *status; }
/*===============================*/ int datPutL( const HDSLoc *locator, int ndim, const hdsdim dims[], const hdsbool_t values[], int *status) { #undef context_name #undef context_message #define context_name "DAT_PUTL_ERR" #define context_message\ "DAT_PUTL: Error writing logical values to an HDS primitive." datPut(locator, "_LOGICAL", ndim, dims, values, status); return *status; }
/*========================================*/ int datPutD( const HDSLoc *locator, int ndim, const hdsdim dims[], const double values[], int *status) { #undef context_name #undef context_message #define context_name "DAT_PUTD_ERR" #define context_message\ "DAT_PUTD: Error writing double precision value(s) to an HDS primitive." datPut(locator, "_DOUBLE", ndim, dims, values, status); return *status; }
/*============================*/ int datPutR( const HDSLoc *locator, int ndim, const hdsdim dims[], const float values[], int *status) { #undef context_name #undef context_message #define context_name "DAT_PUTR_ERR" #define context_message\ "DAT_PUTR: Error writing real values to an HDS primitive." datPut(locator, "_REAL", ndim, dims, values, status); return *status; }
/*=================================*/ int datPutC( const HDSLoc *locator, int ndim, const hdsdim dims[], const char string[], size_t string_length, int *status) { /* Local variables */ char *string1; char stype[DAT__SZTYP+1]; #undef context_name #undef context_message #define context_name "DAT_PUTC_ERR" #define context_message\ "DAT_PUTC: Error writing character value(s) to an HDS primitive." /* Encode the (fixed) string length into the primitive type definition */ /* before calling datPut */ /* Assume that a zero length string (eg. prefix=\"\") is a single space */ /* to make consistent with earlier HDS behaviour! */ if( string_length > 0 ) { datCctyp( string_length, stype ); string1 = (char*)string; } else { strcpy( stype, "_CHAR" ); string1 = " "; } datPut(locator, stype, ndim, dims, string1, status); return *status; }