fitstable_t* fitstable_open_extension_2(const char* fn, int ext) { fitstable_t* tab = _fitstable_open(fn); if (!tab) return tab; if (fitstable_open_extension(tab, ext)) { fitstable_close(tab); return NULL; } return tab; }
int fitstable_switch_to_reading(fitstable_t* table) { assert(in_memory(table)); // store the current extension. fitstable_next_extension(table); // This resets all the meta-data about the table, meaning a reader // can then re-add columns it is interested in. fitstable_clear_table(table); table->extension = 1; return fitstable_open_extension(table, table->extension); }
static fitstable_t* get_tagalong(startree_t* s, anbool report_errs) { char* fn; int next; int i; int ext = -1; fitstable_t* tag; if (!s->tree->io) return NULL; fn = fitsbin_get_filename(s->tree->io); if (!fn) { if (report_errs) ERROR("No filename"); return NULL; } tag = fitstable_open(fn); if (!tag) { if (report_errs) ERROR("Failed to open FITS table from %s", fn); return NULL; } next = fitstable_n_extensions(tag); for (i=1; i<next; i++) { char* type; anbool eq; const qfits_header* hdr; hdr = anqfits_get_header_const(tag->anq, i); if (!hdr) { if (report_errs) ERROR("Failed to read FITS header for ext %i in %s", i, fn); return NULL; } type = fits_get_dupstring(hdr, "AN_FILE"); eq = streq(type, AN_FILETYPE_TAGALONG); free(type); if (!eq) continue; ext = i; break; } if (ext == -1) { if (report_errs) ERROR("Failed to find a FITS header with the card AN_FILE = TAGALONG"); return NULL; } fitstable_open_extension(tag, ext); return tag; }
fitstable_t* fitstable_open(const char* fn) { fitstable_t* tab = _fitstable_open(fn); if (!tab) { return NULL; } if (fitstable_open_extension(tab, tab->extension)) { ERROR("Failed to open extension %i in file %s", tab->extension, fn); goto bailout; } return tab; bailout: if (tab) { fitstable_close(tab); } return NULL; }
int fitstable_read_extension(fitstable_t* tab, int ext) { int i; int ok = 1; if (fitstable_open_extension(tab, ext)) return -1; if (tab->readfid) { // close FID so that table->end_table_offset gets refreshed. fclose(tab->readfid); tab->readfid = NULL; } for (i=0; i<ncols(tab); i++) { fitscol_t* col = getcol(tab, i); qfits_col* qcol; // FIXME? set this here? col->csize = fits_get_atom_size(col->ctype); // Column found? col->col = fits_find_column(tab->table, col->colname); if (col->col == -1) continue; qcol = tab->table->col + col->col; // Type & array size correct? if (col->fitstype != fitscolumn_any_type() && col->fitstype != qcol->atom_type) { col->col = -1; continue; } col->fitstype = qcol->atom_type; col->fitssize = fits_get_atom_size(col->fitstype); if (col->arraysize) { if (col->arraysize != qcol->atom_nb) { col->col = -1; continue; } } /* This was causing problems with copying startree tag-along data (Tycho2 test case: FLAGS column) if (col->fitstype == TFITS_BIN_TYPE_X) { // ??? really?? col->arraysize = 8 * qcol->atom_nb; } else { col->arraysize = qcol->atom_nb; } */ col->arraysize = qcol->atom_nb; } if (tab->br) { buffered_read_reset(tab->br); tab->br->ntotal = tab->table->nr; } for (i=0; i<ncols(tab); i++) { fitscol_t* col = getcol(tab, i); if (col->col == -1 && col->required) { ok = 0; break; } } if (ok) return 0; return -1; }
int fitstable_open_next_extension(fitstable_t* tab) { tab->extension++; return fitstable_open_extension(tab, tab->extension); }