1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
|
/*============================================================================
WCSLIB 4.8 - an implementation of the FITS WCS standard.
Copyright (C) 1995-2011, Mark Calabretta
This file is part of WCSLIB.
WCSLIB is free software: you can redistribute it and/or modify it under the
terms of the GNU Lesser General Public License as published by the Free
Software Foundation, either version 3 of the License, or (at your option)
any later version.
WCSLIB is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
more details.
You should have received a copy of the GNU Lesser General Public License
along with WCSLIB. If not, see <http://www.gnu.org/licenses/>.
Correspondence concerning WCSLIB may be directed to:
Internet email: mcalabre@atnf.csiro.au
Postal address: Dr. Mark Calabretta
Australia Telescope National Facility, CSIRO
PO Box 76
Epping NSW 1710
AUSTRALIA
Author: Mark Calabretta, Australia Telescope National Facility
http://www.atnf.csiro.au/~mcalabre/index.html
$Id: getwcstab.c,v 4.8.1.1 2011/08/15 08:07:06 cal103 Exp cal103 $
*===========================================================================*/
#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;
/* Zero the array pointers. */
wtbp = wtb;
for (iwtb = 0; iwtb < nwtb; iwtb++, wtbp++) {
*wtbp->arrayp = 0x0;
}
/* Save HDU number so that we can move back to it later. */
fits_get_hdu_num(fptr, &hdunum);
wtbp = wtb;
for (iwtb = 0; iwtb < nwtb; iwtb++, wtbp++) {
/* Move to the required binary table extension. */
if (fits_movnam_hdu(fptr, BINARY_TBL, (char *)(wtbp->extnam),
wtbp->extver, status)) {
goto cleanup;
}
/* Locate the table column. */
if (fits_get_colnum(fptr, CASEINSEN, (char *)(wtbp->ttype), &colnum,
status)) {
goto cleanup;
}
/* Get the array dimensions and check for consistency. */
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) {
/* Allow TDIMn to be omitted for degenerate coordinate arrays. */
naxis = 2;
naxes[1] = naxes[0];
naxes[0] = 1;
} else {
*status = BAD_TDIM;
goto cleanup;
}
}
if (wtbp->kind == 'c') {
/* Coordinate array; calculate the array size. */
nelem = naxes[0];
for (m = 0; m < naxis-1; m++) {
*(wtbp->dimlen + m) = naxes[m+1];
nelem *= naxes[m+1];
}
} else {
/* Index vector; check length. */
if ((nelem = naxes[0]) != *(wtbp->dimlen)) {
/* N.B. coordinate array precedes the index vectors. */
*status = BAD_TDIM;
goto cleanup;
}
}
free(naxes);
naxes = 0;
/* Allocate memory for the array. */
if (!(*wtbp->arrayp = calloc((size_t)nelem, sizeof(double)))) {
*status = MEMORY_ALLOCATION;
goto cleanup;
}
/* Read the array from the table. */
if (fits_read_col_dbl(fptr, colnum, wtbp->row, 1L, nelem, 0.0,
*wtbp->arrayp, &anynul, status)) {
goto cleanup;
}
}
cleanup:
/* Move back to the starting HDU. */
nostat = 0;
fits_movabs_hdu(fptr, hdunum, 0, &nostat);
/* Release allocated memory. */
if (naxes) free(naxes);
if (*status) {
wtbp = wtb;
for (iwtb = 0; iwtb < nwtb; iwtb++, wtbp++) {
if (*wtbp->arrayp) free(*wtbp->arrayp);
}
}
return *status;
}
|