Exemplo n.º 1
0
int spcfix(struct wcsprm *wcs)

{
  char ctype[9], specsys[9];
  int  i, status;

  /* Initialize if required. */
  if (wcs == 0x0) return FIXERR_NULL_POINTER;
  if (wcs->flag != WCSSET) {
    if ((status = wcsset(wcs))) return status;
  }

  if ((i = wcs->spec) < 0) {
    /* Look for a linear spectral axis. */
    for (i = 0; i < wcs->naxis; i++) {
      if (wcs->types[i]/100 == 30) {
        break;
      }
    }

    if (i >= wcs->naxis) {
      /* No spectral axis. */
      return FIXERR_NO_CHANGE;
    }
  }

  /* Translate an AIPS-convention spectral type if present. */
  if ((status = spcaips(wcs->ctype[i], wcs->velref, ctype, specsys))) {
    return status;
  }

  strcpy(wcs->ctype[i], ctype);
  if (wcs->specsys[1] == '\0') strcpy(wcs->specsys, specsys);

  wcsutil_null_fill(72, wcs->ctype[i]);
  wcsutil_null_fill(72, wcs->specsys);

  return 0;
}
Exemplo n.º 2
0
Arquivo: wcsfix.c Projeto: MQQ/astropy
int spcfix(struct wcsprm *wcs)

{
  static const char *function = "spcfix";

  char ctype[9], specsys[9];
  int  i, status;
  struct wcserr **err;

  if (wcs == 0x0) return FIXERR_NULL_POINTER;
  err = &(wcs->err);

  for (i = 0; i < wcs->naxis; i++) {
    /* Translate an AIPS-convention spectral type if present. */
    status = spcaips(wcs->ctype[i], wcs->velref, ctype, specsys);
    if (status == 0) {
      /* An AIPS type was found but it may match what we already have. */
      status = FIXERR_NO_CHANGE;

      /* Was specsys translated? */
      if (wcs->specsys[0] == '\0' && *specsys) {
        strncpy(wcs->specsys, specsys, 9);
        wcserr_set(WCSERR_SET(FIXERR_SPC_UPDATE),
          "Changed SPECSYS to '%s'", specsys);
        status = FIXERR_SUCCESS;
      }

      /* Was ctype translated?  Have to null-fill for comparing them. */
      wcsutil_null_fill(9, wcs->ctype[i]);
      if (strncmp(wcs->ctype[i], ctype, 9)) {
        /* ctype was translated... */
        if (status == FIXERR_SUCCESS) {
          /* ...and specsys was also. */
          wcserr_set(WCSERR_SET(FIXERR_SPC_UPDATE),
            "Changed CTYPE%d from '%s' to '%s', and SPECSYS to '%s'",
            i+1, wcs->ctype[i], ctype, wcs->specsys);
        } else {
          wcserr_set(WCSERR_SET(FIXERR_SPC_UPDATE),
            "Changed CTYPE%d from '%s' to '%s'", i+1, wcs->ctype[i], ctype);
          status = FIXERR_SUCCESS;
        }

        strncpy(wcs->ctype[i], ctype, 9);
      }

      /* Tidy up. */
      if (status == FIXERR_SUCCESS) {
        wcsutil_null_fill(72, wcs->ctype[i]);
        wcsutil_null_fill(72, wcs->specsys);
      }

      /* No need to check for others, wcsset() will fail if so. */
      return status;

    } else if (status == SPCERR_BAD_SPEC_PARAMS) {
      /* An AIPS spectral type was found but with invalid velref. */
      return wcserr_set(WCSERR_SET(FIXERR_BAD_PARAM),
        "Invalid parameter value: velref = %d", wcs->velref);
    }
  }

  return FIXERR_NO_CHANGE;
}