27 #include <cxmessages.h>
30 #include <cpl_error.h>
31 #include <cpl_array.h>
47 cpl_propertylist *properties;
56 _giraffe_table_clear(GiTable *
self)
60 cpl_table_delete(self->data);
64 if (self->properties) {
65 cpl_propertylist_delete(self->properties);
66 self->properties = NULL;
88 GiTable *
self = cx_calloc(1,
sizeof(GiTable));
91 self->properties = NULL;
118 GiTable *
self = NULL;
123 self->data = cpl_table_duplicate(table);
129 self->properties = cpl_propertylist_duplicate(properties);
130 if (!self->properties) {
158 _giraffe_table_clear(
self);
179 GiTable *
self = NULL;
187 self = cx_calloc(1,
sizeof(GiTable));
190 self->properties = cpl_propertylist_duplicate(properties);
194 self->data = cpl_table_duplicate(data);
224 _giraffe_table_clear(
self);
263 const cxchar *fctid =
"giraffe_table_copy_matrix";
269 cpl_array *labels = NULL;
270 cpl_table *_table = NULL;
273 cx_assert(table != NULL);
279 nrow = cpl_matrix_get_nrow(matrix);
280 ncol = cpl_matrix_get_ncol(matrix);
281 cx_assert(nrow > 0 && ncol > 0);
285 labels = cpl_table_get_column_names(_table);
286 cx_assert(cpl_array_get_size(labels) > 0);
291 if (cpl_table_has_column(_table, name) == 0) {
293 cpl_array_delete(labels);
294 cpl_error_set(fctid, CPL_ERROR_DATA_NOT_FOUND);
307 while (strcmp(cpl_array_get_string(labels, count), name) != 0) {
316 if (cpl_table_get_nrow(_table) != nrow ||
317 cpl_table_get_ncol(_table) - count < ncol) {
319 cpl_array_delete(labels);
320 cpl_error_set(fctid, CPL_ERROR_INCOMPATIBLE_INPUT);
329 cxdouble *elements = cpl_matrix_get_data(matrix);
332 for (i = 0; i < ncol; ++i) {
334 const cxchar *label = cpl_array_get_string(labels, count + i);
336 cpl_type type = cpl_table_get_column_type(_table, label);
344 for (j = 0; j < nrow; ++j) {
345 cpl_table_set_int(_table, label, j,
346 (cxint) elements[j * ncol + i]);
355 for (j = 0; j < nrow; ++j) {
356 cpl_table_set_float(_table, label, j,
357 (cxfloat) elements[j * ncol + i]);
362 case CPL_TYPE_DOUBLE:
366 for (j = 0; j < nrow; ++j) {
367 cpl_table_set_double(_table, label, j,
368 elements[j * ncol + i]);
373 case CPL_TYPE_STRING:
376 cpl_array_delete(labels);
377 cpl_error_set(fctid, CPL_ERROR_INVALID_TYPE);
388 cpl_array_delete(labels);
415 return self->properties == NULL ? 1 : 0;
436 cx_assert(
self != NULL);
459 cpl_table *tmp = NULL;
463 cx_assert(table != NULL);
466 cpl_table_delete(tmp);
469 self->data = cpl_table_duplicate(table);
492 cx_assert(
self != NULL);
494 return self->properties;
523 if (self->properties) {
524 cpl_propertylist_delete(self->properties);
525 self->properties = NULL;
528 self->properties = cpl_propertylist_duplicate(properties);
530 return self->properties ? 0 : 1;
566 const cxchar *fctid =
"giraffe_table_load";
569 if (!
self || !filename) {
573 self->data = cpl_table_load((cxchar *)filename, position, 0);
575 if (cpl_error_get_code() == CPL_ERROR_NULL_INPUT) {
576 cpl_error_set(fctid, CPL_ERROR_DATA_NOT_FOUND);
583 self->properties = cpl_propertylist_load(filename, position);
585 if (self->properties == NULL) {
586 _giraffe_table_clear(
self);
593 if (self->properties &&
594 cpl_propertylist_has(self->properties, GIALIAS_EXTNAME)) {
598 magic = cpl_propertylist_get_string(self->properties,
601 if (strcmp(
id, magic) == 0) {
608 _giraffe_table_clear(
self);
609 cpl_error_set(fctid, CPL_ERROR_BAD_FILE_FORMAT);
639 if (filename == NULL) {
649 cpl_propertylist *plist1 = NULL;
652 if (cpl_propertylist_is_empty(plist0)) {
656 plist0 = cpl_propertylist_duplicate(plist0);
663 cpl_propertylist_erase(plist0,
"BSCALE");
664 cpl_propertylist_erase(plist0,
"BZERO");
665 cpl_propertylist_erase(plist0,
"BUNIT");
667 cpl_propertylist_erase(plist0,
"DATAMIN");
668 cpl_propertylist_erase(plist0,
"DATAMAX");
675 cpl_propertylist_erase_regexp(plist0,
"^CRPIX[0-9]$", 0);
676 cpl_propertylist_erase_regexp(plist0,
"^CRVAL[0-9]$", 0);
677 cpl_propertylist_erase_regexp(plist0,
"^CDELT[0-9]$", 0);
678 cpl_propertylist_erase_regexp(plist0,
"^CTYPE[0-9]$", 0);
686 plist1 = cpl_propertylist_duplicate(plist0);
694 cpl_propertylist_erase(plist0,
"EXTNAME");
696 cpl_propertylist_erase(plist1,
"DATAMD5");
697 cpl_propertylist_erase(plist1,
"INHERIT");
698 cpl_propertylist_erase(plist1,
"PIPEFILE");
699 cpl_propertylist_erase(plist1, GIALIAS_ANCESTOR);
706 code = cpl_table_save(table, plist0, plist1, filename, CPL_IO_CREATE);
708 if (code != CPL_ERROR_NONE) {
709 cpl_propertylist_delete(plist0);
712 cpl_propertylist_delete(plist1);
718 cpl_propertylist_delete(plist0);
721 cpl_propertylist_delete(plist1);
755 cpl_table *table = NULL;
756 cpl_propertylist *plist = NULL;
759 cx_assert(
self != NULL);
761 if (filename == NULL) {
772 plist = cpl_propertylist_duplicate(plist);
779 cpl_propertylist_erase(plist,
"BSCALE");
780 cpl_propertylist_erase(plist,
"BZERO");
781 cpl_propertylist_erase(plist,
"BUNIT");
783 cpl_propertylist_erase(plist,
"DATAMIN");
784 cpl_propertylist_erase(plist,
"DATAMAX");
785 cpl_propertylist_erase(plist,
"DATAMD5");
786 cpl_propertylist_erase(plist,
"INHERIT");
787 cpl_propertylist_erase(plist,
"PIPEFILE");
788 cpl_propertylist_erase(plist, GIALIAS_ANCESTOR);
794 cpl_propertylist_erase_regexp(plist,
"^CRPIX[0-9]$", 0);
795 cpl_propertylist_erase_regexp(plist,
"^CRVAL[0-9]$", 0);
796 cpl_propertylist_erase_regexp(plist,
"^CDELT[0-9]$", 0);
797 cpl_propertylist_erase_regexp(plist,
"^CTYPE[0-9]$", 0);
801 cpl_propertylist_update_string(plist, GIALIAS_EXTNAME,
id);
802 cpl_propertylist_set_comment(plist, GIALIAS_EXTNAME,
803 "FITS Extension name");
806 if (cpl_propertylist_is_empty(plist)) {
811 code = cpl_table_save(table, NULL, plist, filename, CPL_IO_EXTEND);
813 if (code != CPL_ERROR_NONE) {
814 cpl_propertylist_delete(plist);
820 cpl_propertylist_delete(plist);
837 const cpl_frameset *set)
842 cpl_propertylist *properties = NULL;
851 if (properties == NULL) {
cxint giraffe_table_set(GiTable *self, cpl_table *table)
Sets the table data.
cxint giraffe_table_save(GiTable *self, const cxchar *filename)
Write a Giraffe table to a file.
cxint giraffe_table_load(GiTable *self, const cxchar *filename, cxint position, const cxchar *id)
Reads a data set from a file into a Giraffe table.
cxint giraffe_table_copy_matrix(GiTable *table, const cxchar *name, cpl_matrix *matrix)
Copies matrix elements into a table.
void giraffe_table_clear(GiTable *self)
Clears a Giraffe table.
cxint giraffe_table_attach(GiTable *self, const cxchar *filename, cxint position, const cxchar *id)
Attach a Giraffe table to a file.
GiTable * giraffe_table_create(cpl_table *table, cpl_propertylist *properties)
Creates a Giraffe table from a table and a property list.
cpl_propertylist * giraffe_table_get_properties(const GiTable *self)
Gets the table properties.
GiTable * giraffe_table_new(void)
Creates a new, empty Giraffe table.
void giraffe_table_delete(GiTable *self)
Destroys a Giraffe table.
cpl_table * giraffe_table_get(const GiTable *self)
Get the table data from a Giraffe table.
cxint giraffe_table_is_empty(GiTable *self)
Check whether a Giraffe table is empty.
GiTable * giraffe_table_duplicate(const GiTable *src)
Duplicate a Giraffe table.
cxint giraffe_table_add_info(GiTable *table, const GiRecipeInfo *info, const cpl_frameset *set)
Add additional frame information to a table.
cxint giraffe_table_set_properties(GiTable *self, cpl_propertylist *properties)
Attaches a property list to an table.
cxint giraffe_add_recipe_info(cpl_propertylist *plist, const GiRecipeInfo *info)
Add recipe specific information to a property list.
cxint giraffe_add_frameset_info(cpl_propertylist *plist, const cpl_frameset *set, cxint sequence)
Add frameset specific information to a property list.