32#include "moo_fibres_table.h"
68 moo_loc *res = cpl_calloc(1,
sizeof(moo_loc));
85 cpl_ensure(filename != NULL, CPL_ERROR_NULL_INPUT, NULL);
86 cpl_errorstate prev_state = cpl_errorstate_get();
88 res->primary_header = cpl_propertylist_new();
89 res->filename = cpl_strdup(filename);
90 cpl_propertylist_save(res->primary_header, filename, CPL_IO_CREATE);
91 if (!cpl_errorstate_is_equal(prev_state)) {
92 cpl_msg_error(
"moo_loc",
"Can't load filename %s (%s)", filename,
93 cpl_error_get_message());
111 cpl_ensure(locframe != NULL, CPL_ERROR_NULL_INPUT, NULL);
113 const char *filename = cpl_frame_get_filename(locframe);
114 cpl_ensure(filename != NULL, CPL_ERROR_NULL_INPUT, NULL);
115 cpl_errorstate prev_state = cpl_errorstate_get();
118 res->filename = cpl_strdup(filename);
119 res->primary_header = cpl_propertylist_load(filename, 0);
121 for (
int i = 1; i <= 2; i++) {
132 if (!cpl_errorstate_is_equal(prev_state)) {
133 const char *tag = cpl_frame_get_tag(locframe);
134 cpl_msg_error(
"moo_loc",
"Cant' load %s (%s) error code : %d", filename,
135 tag, cpl_error_get_code());
157 cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, NULL);
158 cpl_ensure(ntas >= 1 && ntas <= 2, CPL_ERROR_ILLEGAL_INPUT, NULL);
162 return self->ri[ntas - 1];
165 return self->yj[ntas - 1];
168 return self->h[ntas - 1];
191 moo_loc_single *single)
193 cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT);
194 cpl_ensure_code(single != NULL, CPL_ERROR_NULL_INPUT);
196 cpl_error_code status = CPL_ERROR_NONE;
197 cpl_errorstate prev_state = cpl_errorstate_get();
201 self->ri[ntas - 1] = single;
204 self->yj[ntas - 1] = single;
207 self->h[ntas - 1] = single;
210 if (!cpl_errorstate_is_equal(prev_state)) {
211 cpl_msg_error(
"moo_loc",
"Error for adding fibre table to %s (%d)",
212 self->filename, cpl_error_get_code());
213 status = cpl_error_get_code();
214 cpl_errorstate_set(prev_state);
235 moo_loc_single *single,
240 cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT);
241 cpl_ensure_code(self->filename != NULL, CPL_ERROR_NULL_INPUT);
242 cpl_ensure_code(single != NULL, CPL_ERROR_NULL_INPUT);
244 cpl_error_code status = CPL_ERROR_NONE;
245 cpl_errorstate prev_state = cpl_errorstate_get();
249 if (!cpl_errorstate_is_equal(prev_state)) {
250 cpl_errorstate_dump(prev_state, CPL_FALSE, cpl_errorstate_dump_one);
251 cpl_msg_error(
"moo_loc",
"Error for adding LOC single table to %s (%d)",
252 self->filename, cpl_error_get_code());
253 status = cpl_error_get_code();
254 cpl_errorstate_set(prev_state);
273 cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT);
274 cpl_ensure_code(self->filename != NULL, CPL_ERROR_NULL_INPUT);
275 cpl_ensure_code(fibre_table != NULL, CPL_ERROR_NULL_INPUT);
277 cpl_error_code status = CPL_ERROR_NONE;
278 cpl_errorstate prev_state = cpl_errorstate_get();
279 self->fibre_table = fibre_table;
281 cpl_propertylist *h = cpl_propertylist_new();
282 cpl_propertylist_append_string(h, MOO_PFITS_EXTNAME,
283 MOO_FIBRES_TABLE_EXTNAME);
284 cpl_table_save(self->fibre_table, NULL, h, self->filename, CPL_IO_EXTEND);
285 cpl_propertylist_delete(h);
287 if (!cpl_errorstate_is_equal(prev_state)) {
288 cpl_msg_error(
"moo_loc",
"Error for adding fibre table to %s (%d)",
289 self->filename, cpl_error_get_code());
290 status = cpl_error_get_code();
291 cpl_errorstate_set(prev_state);
308 cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, NULL);
310 if (self->fibre_table == NULL && self->filename != NULL) {
312 cpl_fits_find_extension(self->filename, MOO_FIBRES_TABLE_EXTNAME);
314 self->fibre_table = cpl_table_load(self->filename, qnum, 0);
317 return self->fibre_table;
336 if (self->filename != NULL) {
337 cpl_free(self->filename);
339 if (self->primary_header != NULL) {
340 cpl_propertylist_delete(self->primary_header);
342 for (i = 0; i < 2; i++) {
343 if (self->ri[i] != NULL) {
346 if (self->yj[i] != NULL) {
349 if (self->h[i] != NULL) {
353 if (self->fibre_table != NULL) {
354 cpl_table_delete(self->fibre_table);
375 cpl_propertylist_save(self->primary_header, filename, CPL_IO_CREATE);
378 for (i = 0; i < 2; i++) {
379 if (self->ri[i] != NULL) {
382 if (self->yj[i] != NULL) {
385 if (self->h[i] != NULL) {
390 if (self->fibre_table != NULL) {
391 cpl_propertylist *h = cpl_propertylist_new();
392 cpl_propertylist_append_string(h, MOO_PFITS_EXTNAME,
393 MOO_FIBRES_TABLE_EXTNAME);
394 cpl_table_save(self->fibre_table, h, h, filename, CPL_IO_EXTEND);
395 cpl_propertylist_delete(h);
415 cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT);
416 cpl_ensure_code(stream != NULL, CPL_ERROR_NULL_INPUT);
418 fprintf(stream,
"---MOO_LOC\n");
419 fprintf(stream,
"filename %s\n", self->filename);
421 for (i = 0; i < 2; i++) {
427 return CPL_ERROR_NONE;
const char * moo_detector_get_extname(moo_detector_type type, int ntas)
Get the extension name of a detector.
enum _moo_detector_type_ moo_detector_type
The type code type.
void moo_loc_single_delete(moo_loc_single *self)
Delete a moo_loc_single.
void moo_loc_single_save(const moo_loc_single *self, const char *filename, int keep_points)
Save a moo_loc_single to a FITS file.
cpl_error_code moo_loc_single_dump(const moo_loc_single *self, FILE *stream)
Dump structural information of LOC_SINGLE.
moo_loc_single * moo_loc_single_create(const char *filename, const char *extname)
Create a new moo_loc_single from the given LOC filename.
moo_loc * moo_loc_create(const char *filename)
Create a new empty LOC filename.
moo_loc_single * moo_loc_get_single(moo_loc *self, moo_detector_type type, int ntas)
Get the type part in LOC and return it.
cpl_error_code moo_loc_add_fibre_table(moo_loc *self, cpl_table *fibre_table)
Add fibre table to LOC filename and update moo_loc structure.
moo_loc * moo_loc_new(void)
Create a new moo_loc.
cpl_error_code moo_loc_set_single(moo_loc *self, moo_detector_type type, int ntas, moo_loc_single *single)
assign moo_loc_single structure in moo_loc structure
moo_loc * moo_loc_load(const cpl_frame *locframe)
Load a LOC frame and create a moo_loc.
cpl_error_code moo_loc_add_single(moo_loc *self, moo_loc_single *single, moo_detector_type type, int ntas, int keep_points)
Add LOC_SINGLE extension to LOC filename and update moo_loc structure.
cpl_error_code moo_loc_dump(const moo_loc *self, FILE *stream)
Dump structural information of LOC.
cpl_table * moo_loc_get_fibre_table(moo_loc *self)
Get the FIBRE TABLE in LOC.
void moo_loc_save(moo_loc *self, const char *filename, int keep_points)
Save a moo_loc to a FITS file.
void moo_loc_delete(moo_loc *self)
Delete a moo_loc.