static PyObject* pytocqspline(PyObject *self, PyObject *args) { int i, j, n, ns, maxit; double ds, tol; PyObject *wi_object, *wf_object, *x_object, *y_object; double *wi, *wf, *x, *y, *t, *q, *omega, *alpha; if (!PyArg_ParseTuple(args, "iididOOOO", &n, &ns, &ds, &maxit, &tol, &wi_object, &wf_object, &x_object, &y_object)) return NULL; wi = loadarray(wi_object,3); wf = loadarray(wf_object,3); x = loadarray(x_object,n); y = loadarray(y_object,4*n); if(ds > 0.0) { ns = (int) ((x[n - 1] - x[0])/ds) + 1; } t = (double *) malloc(ns*sizeof(double)); q = (double *) malloc(4*ns*sizeof(double)); omega = (double *) malloc(3*ns*sizeof(double)); alpha = (double *) malloc(3*ns*sizeof(double)); qspline(n,ns,ds,maxit,tol,wi,wf,x,y,t,q,omega,alpha); PyObject* t_out = PyList_New(ns); PyObject* q_out = PyList_New(4*ns); PyObject* omega_out = PyList_New(3*ns); PyObject* alpha_out = PyList_New(3*ns); for (i=0;i<ns;i++) { PyList_SetItem(t_out,i,PyFloat_FromDouble(t[i])); for (j=0;j<3;j++) { PyList_SetItem(q_out,4*i+j,PyFloat_FromDouble(q[4*i+j])); PyList_SetItem(omega_out,3*i+j,PyFloat_FromDouble(omega[3*i+j])); PyList_SetItem(alpha_out,3*i+j,PyFloat_FromDouble(alpha[3*i+j])); } PyList_SetItem(q_out,4*i+3,PyFloat_FromDouble(q[4*i+3])); } free(wi); free(wf); free(x); free(y); free(t); free(q); free(omega); free(alpha); return Py_BuildValue("OOOO",t_out,q_out,omega_out,alpha_out); }
bool MCVariableValue::decode(const MCString& p_value) { IO_handle t_stream_handle; t_stream_handle = MCS_fakeopen(p_value); if (t_stream_handle == NULL) return false; MCObjectInputStream *t_stream = nil; t_stream = new MCObjectInputStream(t_stream_handle, p_value . getlength()); if (t_stream == NULL) { MCS_close(t_stream_handle); return false; } IO_stat t_stat; t_stat = IO_NORMAL; uint8_t t_type; t_stat = t_stream -> ReadU8(t_type); if (t_stat == IO_NORMAL) { switch(t_type) { case kMCEncodedValueTypeUndefined: clear(); break; case kMCEncodedValueTypeEmpty: assign_empty(); break; case kMCEncodedValueTypeString: { uint32_t t_length; t_stat = t_stream -> ReadU32(t_length); if (t_stat == IO_NORMAL) { char *t_value; t_value = new char[t_length]; if (t_value != NULL) assign_buffer(t_value, t_length); else t_stat = IO_ERROR; } } break; case kMCEncodedValueTypeNumber: { double t_value; t_stat = t_stream -> ReadFloat64(t_value); if (t_stat == IO_NORMAL) assign_real(t_value); } break; case kMCEncodedValueTypeArray: t_stat = loadarray(*t_stream, false); break; default: t_stat = IO_ERROR; break; } } delete t_stream; MCS_close(t_stream_handle); set_dbg_changed(true); return t_stat == IO_NORMAL; }