33#include "moo_molectable.h"
69 moo_molectable *res = cpl_calloc(1,
sizeof(moo_molectable));
88 cpl_ensure(frame != NULL, CPL_ERROR_NULL_INPUT, NULL);
89 const char *filename = cpl_frame_get_filename(frame);
90 cpl_ensure(filename != NULL, CPL_ERROR_NULL_INPUT, NULL);
94 cpl_errorstate prev_state = cpl_errorstate_get();
97 res->filename = cpl_strdup(filename);
98 res->primary_header = cpl_propertylist_load(filename, 0);
100 for (
int i = 0; i < 3; i++) {
103 if (modename == NULL || strcmp(bandname,
"YJ") == 0) {
104 extname = cpl_sprintf(
"%s", bandname);
107 extname = cpl_sprintf(
"%s_%s", bandname, modename);
109 cpl_size qnum = cpl_fits_find_extension(filename, extname);
112 cpl_propertylist *header = NULL;
113 header = moo_fits_load_extension_header(filename, NULL, extname);
114 res->data_header[i] = header;
117 res->data[i] = cpl_table_load(filename, qnum, 0);
124 if (!cpl_errorstate_is_equal(prev_state)) {
126 cpl_errorstate_set(prev_state);
127 cpl_msg_error(
"moo_molectable",
"Error in loading table %s", filename);
147 cpl_table *result = NULL;
149 cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, NULL);
151 result = self->data[type];
170 cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT);
172 self->data[type] = cpl_table_duplicate(data);
174 return CPL_ERROR_NONE;
191 cpl_propertylist_save(self->primary_header, filename, CPL_IO_CREATE);
193 for (
int i = 0; i < 3; i++) {
197 extname, self->data_header[i]);
218 if (self->primary_header != NULL) {
219 cpl_propertylist_delete(self->primary_header);
222 if (self->filename != NULL) {
223 cpl_free(self->filename);
225 for (i = 0; i < 3; i++) {
226 if (self->data[i] != NULL) {
227 cpl_table_delete(self->data[i]);
229 if (self->data_header[i] != NULL) {
230 cpl_propertylist_delete(self->data_header[i]);
254 cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT);
255 cpl_ensure_code(stream != NULL, CPL_ERROR_NULL_INPUT);
257 fprintf(stream,
"---MOO_MAP\n");
260 for (i = 0; i < 3; i++) {
261 if (self->data[i] != NULL) {
262 fprintf(stream,
"data[%d] %p\n", i, (
void *)self->data[i]);
263 if (self->data[i] != NULL) {
264 cpl_table_dump_structure(self->data[i], stream);
268 return CPL_ERROR_NONE;
const char * moo_detector_get_name(moo_detector_type type)
Get the extension name of a detector.
enum _moo_detector_type_ moo_detector_type
The type code type.
cpl_error_code moo_fits_write_extension_table(cpl_table *table, const char *filename, const char *name, const char *detectorname, cpl_propertylist *header)
Write an image as extension in FITS file.
cpl_error_code moo_molectable_set_data(moo_molectable *self, moo_detector_type type, cpl_table *data)
Set table in molectable.
cpl_error_code moo_molectable_dump(const moo_molectable *self, FILE *stream)
Dump structural information of MOLECTABLE.
moo_molectable * moo_molectable_load(const cpl_frame *frame, const char *modename)
Load a moo_molectable.
void moo_molectable_save(moo_molectable *self, const char *filename)
Save a moo_molectable to a FITS file.
cpl_table * moo_molectable_get_data(moo_molectable *self, moo_detector_type type)
Get table from molec_table.
void moo_molectable_delete(moo_molectable *self)
Delete a moo_molectable.
moo_molectable * moo_molectable_new(void)
Create a new moo_molectable.
int moo_pfits_get_naxis(const cpl_propertylist *plist)
find out the NAXIS value