static int PyUnits_init( PyUnits* self, PyObject* args, PyObject* kwds) { int status = -1; char* have; char* want; char* ctrl_str = NULL; int ctrl = 0; const char* keywords[] = {"have", "want", "translate_units", NULL}; struct wcserr* err = NULL; if (!PyArg_ParseTupleAndKeywords(args, kwds, "ss|s:UnitConverter.__init__", (char **)keywords, &have, &want, &ctrl_str)) { goto exit; } if (ctrl_str != NULL) { if (parse_unsafe_unit_conversion_spec(ctrl_str, &ctrl)) { goto exit; } } /* Copy the strings since we can't have wcslib monkeying with the data in a Python string */ strncpy(self->have, have, 80); strncpy(self->want, want, 80); status = wcsutrne(ctrl, self->have, &err); if (status != -1 && status != 0) { goto exit; } status = wcsutrne(ctrl, self->want, &err); if (status != -1 && status != 0) { goto exit; } status = wcsunitse(self->have, self->want, &self->scale, &self->offset, &self->power, &err); exit: if (PyErr_Occurred()) { return -1; } else if (status == 0) { return 0; } else { wcserr_units_to_python_exc(err); free(err); return -1; } }
int unitfix(int ctrl, struct wcsprm *wcs) { int i, k, status = FIXERR_NO_CHANGE; char orig_unit[80], msg[WCSERR_MSG_LENGTH]; const char *function = "unitfix"; struct wcserr **err; if (wcs == 0x0) return FIXERR_NULL_POINTER; err = &(wcs->err); strcpy(msg, "Changed units: "); for (i = 0; i < wcs->naxis; i++) { strncpy(orig_unit, wcs->cunit[i], 80); if (wcsutrne(ctrl, wcs->cunit[i], &(wcs->err)) == 0) { k = strlen(msg); sprintf(msg+k, "'%s' -> '%s', ", orig_unit, wcs->cunit[i]); status = FIXERR_UNITS_ALIAS; } } if (status == FIXERR_UNITS_ALIAS) { k = strlen(msg) - 2; msg[k] = '\0'; wcserr_set(WCSERR_SET(FIXERR_UNITS_ALIAS), msg); status = FIXERR_SUCCESS; } return status; }
int unitfix(int ctrl, struct wcsprm *wcs) { int i, status = FIXERR_NO_CHANGE; if (wcs == 0x0) return FIXERR_NULL_POINTER; for (i = 0; i < wcs->naxis; i++) { if (wcsutrne(ctrl, wcs->cunit[i], &(wcs->err)) == 0) { status = FIXERR_SUCCESS; } } return status; }
int unitfix(int ctrl, struct wcsprm *wcs) { int i, k, result, status = FIXERR_NO_CHANGE; char orig_unit[80], msg[WCSERR_MSG_LENGTH], msgtmp[WCSERR_MSG_LENGTH]; const char *function = "unitfix"; struct wcserr **err; if (wcs == 0x0) return FIXERR_NULL_POINTER; err = &(wcs->err); strncpy(msg, "Changed units: ", WCSERR_MSG_LENGTH); for (i = 0; i < wcs->naxis; i++) { strncpy(orig_unit, wcs->cunit[i], 80); result = wcsutrne(ctrl, wcs->cunit[i], &(wcs->err)); if (result == 0 || result == 12) { k = strlen(msg); if (k < WCSERR_MSG_LENGTH-1) { wcsutil_null_fill(80, orig_unit); sprintf(msgtmp, "'%s' -> '%s', ", orig_unit, wcs->cunit[i]); strncpy(msg+k, msgtmp, WCSERR_MSG_LENGTH-1-k); status = FIXERR_UNITS_ALIAS; } } } if (status == FIXERR_UNITS_ALIAS) { /* Chop off the trailing ", ". */ k = strlen(msg) - 2; msg[k] = '\0'; wcserr_set(WCSERR_SET(FIXERR_UNITS_ALIAS), msg); status = 0; } return status; }
int wcsutrn(int ctrl, char unitstr[]) { return wcsutrne(ctrl, unitstr, 0x0); }