31#include "moo_extlist.h"
32#include "moo_badpix.h"
59 return (moo_extlist *)cpl_calloc(1,
sizeof(moo_extlist));
74 cpl_ensure(frameset != NULL, CPL_ERROR_NULL_INPUT, NULL);
78 for (i = 0; i < cpl_frameset_get_size(frameset); ++i) {
79 const cpl_frame *current_frame =
80 cpl_frameset_get_position_const(frameset, i);
113 cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT);
114 cpl_ensure_code(num >= 1 && num <= 2, CPL_ERROR_ILLEGAL_INPUT);
118 for (i = 0; i < self->size; i++) {
119 moo_ext *ext = self->list[i];
122 return CPL_ERROR_NONE;
148 cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT);
149 cpl_ensure_code(num >= 1 && num <= 2, CPL_ERROR_ILLEGAL_INPUT);
152 for (i = 0; i < self->size; i++) {
153 moo_ext *ext = self->list[i];
155 if (status != CPL_ERROR_NONE) {
159 return CPL_ERROR_NONE;
176 cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, -1);
178 assert(self->size >= 0);
199 cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, NULL);
200 cpl_ensure(i >= 0, CPL_ERROR_ILLEGAL_INPUT, NULL);
202 cpl_ensure(i < size, CPL_ERROR_ILLEGAL_INPUT, NULL);
204 return self->list[i];
228 cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, NULL);
229 cpl_ensure(num >= 1, CPL_ERROR_ILLEGAL_INPUT, NULL);
230 cpl_ensure(num <= 2, CPL_ERROR_ACCESS_OUT_OF_RANGE, NULL);
232 cpl_errorstate prestate = cpl_errorstate_get();
234 hdrl_imagelist *res = NULL;
237 res = hdrl_imagelist_new();
239 for (i = 0; i < self->size; i++) {
240 moo_ext *ext = self->list[i];
241 moo_ext_single *single = NULL;
244 if (single != NULL) {
246 hdrl_imagelist_set(res, img, i);
251 if (!cpl_errorstate_is_equal(prestate)) {
252 cpl_msg_error(__func__,
"Error in extlist");
253 cpl_errorstate_dump(prestate, CPL_FALSE, cpl_errorstate_dump_one);
254 hdrl_imagelist_delete(res);
284 cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, NULL);
285 cpl_ensure(num >= 1, CPL_ERROR_ILLEGAL_INPUT, NULL);
286 cpl_ensure(num <= 2, CPL_ERROR_ACCESS_OUT_OF_RANGE, NULL);
288 cpl_imagelist *res = cpl_imagelist_new();
291 for (i = 0; i < self->size; i++) {
292 moo_ext *ext = self->list[i];
294 if (single != NULL) {
325 cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, NULL);
326 cpl_ensure(num >= 1, CPL_ERROR_ILLEGAL_INPUT, NULL);
327 cpl_ensure(num <= 2, CPL_ERROR_ACCESS_OUT_OF_RANGE, NULL);
329 cpl_imagelist *res = cpl_imagelist_new();
332 for (i = 0; i < self->size; i++) {
333 moo_ext *ext = self->list[i];
335 if (single != NULL) {
378 cpl_ensure_code(self, CPL_ERROR_NULL_INPUT);
379 cpl_ensure_code(ext, CPL_ERROR_NULL_INPUT);
380 cpl_ensure_code(pos >= 0, CPL_ERROR_ILLEGAL_INPUT);
381 cpl_ensure_code(pos <= self->size, CPL_ERROR_ACCESS_OUT_OF_RANGE);
384 if (pos < self->size && ext == self->list[pos])
385 return CPL_ERROR_NONE;
387 if (pos == self->size) {
390 cpl_realloc(self->list, (
size_t)self->size *
sizeof(moo_ext *));
397 for (i = 0; i < self->size; i++) {
398 if (i != pos && self->list[i] == self->list[pos])
401 if (i == self->size) {
408 self->list[pos] = ext;
410 return CPL_ERROR_NONE;
442 cpl_ensure_code(self, CPL_ERROR_NULL_INPUT);
444 return cpl_error_get_code();
472 cpl_ensure(self, CPL_ERROR_NULL_INPUT, NULL);
473 cpl_ensure(pos >= 0, CPL_ERROR_ILLEGAL_INPUT, NULL);
474 cpl_ensure(pos < self->size, CPL_ERROR_ACCESS_OUT_OF_RANGE, NULL);
477 out = self->list[pos];
480 for (i = pos + 1; i < self->size; i++) {
481 self->list[i - 1] = self->list[i];
508 while (self->size > 0) {
509 int i = self->size - 1;
517 if (self->list[i] == del) {
544 cpl_free(self->list);
583 moo_ext *result = NULL;
584 cpl_frame *res_frame = NULL;
586 cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, NULL);
587 cpl_ensure(filename != NULL, CPL_ERROR_NULL_INPUT, NULL);
595 res_frame = cpl_frame_new();
596 cpl_frame_set_filename(res_frame, filename);
600 for (
int i = 1; i < size; i++) {
607 cpl_frame_delete(res_frame);
cpl_error_code moo_ext_free_single(moo_ext *self, moo_detector_type type, int num)
Free the given type part in EXT.
enum _moo_detector_type_ moo_detector_type
The type code type.
hdrl_image * moo_ext_single_get_image(moo_ext_single *self)
Get image of EXT_SINGLE.
cpl_image * moo_ext_single_get_qual(moo_ext_single *self)
Get image of qual.
cpl_image * moo_ext_single_get_data(moo_ext_single *self)
Get image of data.
moo_ext_single * moo_ext_get_single(moo_ext *self, moo_detector_type type, int ntas)
Get a EXT single from EXT.
moo_ext_single * moo_ext_load_single(moo_ext *self, moo_detector_type type, int num, unsigned int level)
Load the type part in EXT and return it.
cpl_error_code moo_ext_load(moo_ext *self, unsigned int level)
Load all parts in EXT.
moo_ext * moo_ext_create(const cpl_frame *frame)
Create a new empty EXT filename.
cpl_error_code moo_ext_sum(moo_ext *self, moo_ext *ext)
Sum EXT structure.
cpl_table * moo_ext_get_fibre_table(moo_ext *self)
Get the FIBRE TABLE in EXT.
void moo_ext_save(moo_ext *self, const char *filename)
Save a moo_ext to a FITS file.
void moo_ext_delete(moo_ext *self)
Delete a moo_ext.
moo_ext * moo_extlist_get(moo_extlist *self, int i)
Get the DET at the position i in the list.
cpl_imagelist * moo_extlist_get_single_data(const moo_extlist *self, moo_detector_type type, int num)
Get the type data part for all DET in the extlist.
cpl_error_code moo_extlist_push(moo_extlist *self, moo_ext *ext)
Insert a DET a the end of moo_extlist.
cpl_error_code moo_extlist_set(moo_extlist *self, moo_ext *ext, cpl_size pos)
Insert a DET into an moo_extlist.
moo_ext * moo_extlist_unset(moo_extlist *self, cpl_size pos)
Remove a DET from a DET list.
void moo_extlist_unwrap(moo_extlist *self)
Free memory used by a moo_extlist object, except the DET.
void moo_extlist_empty(moo_extlist *self)
Empty an moo_extlist and deallocate all its DET.
moo_ext * moo_extlist_sum(moo_extlist *self, const char *filename)
Sum EXT element from the list and save result in filename.
cpl_error_code moo_extlist_free_single(const moo_extlist *self, moo_detector_type type, int num)
Free the type part for all DET in the extlist.
cpl_imagelist * moo_extlist_get_single_qual(const moo_extlist *self, moo_detector_type type, int num)
Get the type QUAL part for all DET in the extlist.
void moo_extlist_delete(moo_extlist *self)
Free all memory used by a moo_extlist object including the DET.
hdrl_imagelist * moo_extlist_get_image(const moo_extlist *self, moo_detector_type type, int num)
Get the all the images of the type part in the extlist.
moo_extlist * moo_extlist_create(cpl_frameset *frameset)
Create a new moo_extlist from the given DET frameset.
cpl_size moo_extlist_get_size(const moo_extlist *self)
Get the number of DET in the extlist.
cpl_error_code moo_extlist_load_single(const moo_extlist *self, moo_detector_type type, int num, int level)
Load the type part for all DET in the extlist.
moo_extlist * moo_extlist_new(void)
Create a new moo_extlist.