| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| #include <stdlib.h> |
| #include <string.h> |
|
|
| #include <fitsio.h> |
|
|
| #include "getwcstab.h" |
|
|
| |
|
|
| int fits_read_wcstab( |
| fitsfile *fptr, |
| int nwtb, |
| wtbarr *wtb, |
| int *status) |
|
|
| { |
| int anynul, colnum, hdunum, iwtb, m, naxis, nostat; |
| long *naxes = 0, nelem; |
| wtbarr *wtbp; |
|
|
|
|
| if (*status) return *status; |
|
|
| if (fptr == 0) { |
| return (*status = NULL_INPUT_PTR); |
| } |
|
|
| if (nwtb == 0) return 0; |
|
|
| |
| wtbp = wtb; |
| for (iwtb = 0; iwtb < nwtb; iwtb++, wtbp++) { |
| *wtbp->arrayp = 0x0; |
| } |
|
|
| |
| fits_get_hdu_num(fptr, &hdunum); |
|
|
| wtbp = wtb; |
| for (iwtb = 0; iwtb < nwtb; iwtb++, wtbp++) { |
| |
| if (fits_movnam_hdu(fptr, BINARY_TBL, (char *)(wtbp->extnam), |
| wtbp->extver, status)) { |
| goto cleanup; |
| } |
|
|
| |
| if (fits_get_colnum(fptr, CASEINSEN, (char *)(wtbp->ttype), &colnum, |
| status)) { |
| goto cleanup; |
| } |
|
|
| |
| if (wtbp->ndim < 1) { |
| *status = NEG_AXIS; |
| goto cleanup; |
| } |
|
|
| if (!(naxes = calloc(wtbp->ndim, sizeof(long)))) { |
| *status = MEMORY_ALLOCATION; |
| goto cleanup; |
| } |
|
|
| if (fits_read_tdim(fptr, colnum, wtbp->ndim, &naxis, naxes, status)) { |
| goto cleanup; |
| } |
|
|
| if (naxis != wtbp->ndim) { |
| if (wtbp->kind == 'c' && wtbp->ndim == 2) { |
| |
| naxis = 2; |
| naxes[1] = naxes[0]; |
| naxes[0] = 1; |
| } else { |
| *status = BAD_TDIM; |
| goto cleanup; |
| } |
| } |
|
|
| if (wtbp->kind == 'c') { |
| |
| nelem = naxes[0]; |
| for (m = 0; m < naxis-1; m++) { |
| *(wtbp->dimlen + m) = naxes[m+1]; |
| nelem *= naxes[m+1]; |
| } |
| } else { |
| |
| if ((nelem = naxes[0]) != *(wtbp->dimlen)) { |
| |
| *status = BAD_TDIM; |
| goto cleanup; |
| } |
| } |
|
|
| free(naxes); |
| naxes = 0; |
|
|
| |
| if (!(*wtbp->arrayp = calloc((size_t)nelem, sizeof(double)))) { |
| *status = MEMORY_ALLOCATION; |
| goto cleanup; |
| } |
|
|
| |
| if (fits_read_col_dbl(fptr, colnum, wtbp->row, 1L, nelem, 0.0, |
| *wtbp->arrayp, &anynul, status)) { |
| goto cleanup; |
| } |
| } |
|
|
| cleanup: |
| |
| nostat = 0; |
| fits_movabs_hdu(fptr, hdunum, 0, &nostat); |
|
|
| |
| if (naxes) free(naxes); |
| if (*status) { |
| wtbp = wtb; |
| for (iwtb = 0; iwtb < nwtb; iwtb++, wtbp++) { |
| if (*wtbp->arrayp) free(*wtbp->arrayp); |
| } |
| } |
|
|
| return *status; |
| } |
|
|