25 #include <cxstrutils.h>
27 #include <cpl_error.h>
45 _giraffe_frame_update_product(cpl_propertylist* properties,
46 const cxchar* name,
const cxchar* tag,
47 const cxchar* type,
const cxchar* tech)
50 cxchar* dpr_tech = NULL;
55 if (properties == NULL) {
70 if (cpl_propertylist_has(properties, GIALIAS_DPRTECH) == TRUE) {
72 const cxchar* s = cpl_propertylist_get_string(properties,
75 dpr_tech = cx_strdup(s);
78 else if (cpl_propertylist_has(properties, GIALIAS_PROTECH) == TRUE) {
80 const cxchar* s = cpl_propertylist_get_string(properties,
83 dpr_tech = cx_strdup(s);
87 if ((dpr_tech == NULL) || (dpr_tech[0] ==
'\0')) {
101 if (cpl_propertylist_has(properties, GIALIAS_PROSCIENCE) == FALSE) {
103 if (cpl_propertylist_has(properties, GIALIAS_DPRCATG) == TRUE) {
105 const cxchar* s = cpl_propertylist_get_string(properties,
109 science = (strncmp(s,
"SCIENCE", 7) == 0) ? 1 : 0;
121 cpl_propertylist_erase(properties, GIALIAS_ORIGIN);
122 cpl_propertylist_erase(properties, GIALIAS_DATE);
123 cpl_propertylist_erase(properties, GIALIAS_DATAMD5);
124 cpl_propertylist_erase(properties, GIALIAS_ORIGFILE);
125 cpl_propertylist_erase(properties, GIALIAS_ARCFILE);
126 cpl_propertylist_erase(properties, GIALIAS_CHECKSUM);
127 cpl_propertylist_erase(properties, GIALIAS_DATASUM);
129 cpl_propertylist_erase_regexp(properties,
"ESO DPR.*", 0);
132 giraffe_error_push();
134 cpl_propertylist_update_string(properties, GIALIAS_INSTRUMENT,
136 cpl_propertylist_set_comment(properties, GIALIAS_INSTRUMENT,
137 "Name of the Instrument.");
139 cpl_propertylist_update_string(properties, GIALIAS_DATAMD5,
141 cpl_propertylist_set_comment(properties, GIALIAS_DATAMD5,
145 cpl_propertylist_update_string(properties, GIALIAS_PIPEFILE, name);
146 cpl_propertylist_set_comment(properties, GIALIAS_PIPEFILE,
147 "Filename of data product");
150 if (cpl_error_get_code() != CPL_ERROR_NONE) {
164 giraffe_error_push();
166 cpl_propertylist_update_string(properties, GIALIAS_PRODID, PRODUCT_DID);
167 cpl_propertylist_set_comment(properties, GIALIAS_PRODID,
168 "Data dictionary for PRO");
172 cpl_propertylist_update_string(properties, GIALIAS_PROCATG, tag);
173 cpl_propertylist_set_comment(properties, GIALIAS_PROCATG,
174 "Pipeline product category");
178 cpl_propertylist_update_string(properties, GIALIAS_PROTYPE, type);
179 cpl_propertylist_set_comment(properties, GIALIAS_PROTYPE,
182 cpl_propertylist_update_string(properties, GIALIAS_PROTECH, tech);
183 cpl_propertylist_set_comment(properties, GIALIAS_PROTECH,
184 "Observation technique");
189 cpl_propertylist_update_bool(properties, GIALIAS_PROSCIENCE, science);
190 cpl_propertylist_set_comment(properties, GIALIAS_PROSCIENCE,
191 "Scientific product if T");
194 if (cpl_error_get_code() != CPL_ERROR_NONE) {
238 const cpl_propertylist *properties, cxcptr
object,
239 cxcptr data, GiFrameCreator creator)
242 const cxchar *
const fctid =
"giraffe_frame_create";
246 cx_string *name = NULL;
248 cpl_propertylist *p = NULL;
250 cpl_frame *frame = NULL;
253 if (properties == NULL || creator == NULL) {
254 cpl_error_set(fctid, CPL_ERROR_NULL_INPUT);
259 cpl_error_set(fctid, CPL_ERROR_NULL_INPUT);
263 p = cpl_propertylist_duplicate(properties);
264 cx_assert(p != NULL);
270 name = cx_string_create(tag);
271 cx_assert(name != NULL);
273 cx_string_lower(name);
274 cx_string_append(name,
".fits");
276 _giraffe_frame_update_product(p, cx_string_get(name), tag,
"REDUCED",
279 frame = cpl_frame_new();
280 cpl_frame_set_filename(frame, cx_string_get(name));
281 cpl_frame_set_tag(frame, tag);
282 cpl_frame_set_type(frame, CPL_FRAME_TYPE_IMAGE);
283 cpl_frame_set_group(frame, CPL_FRAME_GROUP_PRODUCT);
284 cpl_frame_set_level(frame, level);
290 status = creator(
object, p, cx_string_get(name), data);
293 cpl_frame_delete(frame);
297 cx_string_delete(name);
298 cpl_propertylist_delete(p);
325 const cpl_propertylist* properties,
326 cxcptr
object, cxcptr data,
327 GiFrameCreator creator)
330 const cxchar*
const fctid =
"giraffe_frame_save";
334 cpl_propertylist* p = NULL;
337 if (properties == NULL || creator == NULL) {
338 cpl_error_set(fctid, CPL_ERROR_NULL_INPUT);
349 p = cpl_propertylist_duplicate(properties);
350 cx_assert(p != NULL);
357 status = creator(
object, p, cpl_frame_get_filename(frame), data);
359 cpl_propertylist_delete(p);
394 cpl_frame_level level, cxbool save,
397 const cxchar *fctid =
"giraffe_frame_create_image";
403 cpl_propertylist *properties;
406 if (image == NULL || tag == NULL) {
407 cpl_error_set(fctid, CPL_ERROR_NULL_INPUT);
413 if (properties == NULL) {
414 cpl_error_set(fctid, CPL_ERROR_DATA_NOT_FOUND);
418 if (update == TRUE) {
423 if (_image == NULL) {
424 cpl_error_set(fctid, CPL_ERROR_DATA_NOT_FOUND);
428 cpl_propertylist_update_double(properties, GIALIAS_DATAMIN,
429 cpl_image_get_min(_image));
430 cpl_propertylist_set_comment(properties, GIALIAS_DATAMIN,
431 "Minimal pixel value");
433 cpl_propertylist_update_double(properties, GIALIAS_DATAMAX,
434 cpl_image_get_max(_image));
435 cpl_propertylist_set_comment(properties, GIALIAS_DATAMAX,
436 "Maximum pixel value");
438 cpl_propertylist_update_double(properties, GIALIAS_DATAMEAN,
439 cpl_image_get_mean(_image));
440 cpl_propertylist_set_comment(properties, GIALIAS_DATAMEAN,
441 "Mean of pixel values");
443 cpl_propertylist_update_double(properties, GIALIAS_DATASIG,
444 cpl_image_get_stdev(_image));
445 cpl_propertylist_set_comment(properties, GIALIAS_DATASIG,
446 "Standard deviation of pixel values");
448 cpl_propertylist_update_double(properties, GIALIAS_DATAMEDI,
449 cpl_image_get_median(_image));
450 cpl_propertylist_set_comment(properties, GIALIAS_DATAMEDI,
451 "Median of pixel values");
453 cpl_propertylist_update_int(properties, GIALIAS_NAXIS1,
454 cpl_image_get_size_x(_image));
455 cpl_propertylist_update_int(properties, GIALIAS_NAXIS2,
456 cpl_image_get_size_y(_image));
465 name = cx_string_create(tag);
466 cx_string_lower(name);
467 cx_string_append(name,
".fits");
469 _giraffe_frame_update_product(properties, cx_string_get(name), tag,
472 frame = cpl_frame_new();
473 cpl_frame_set_filename(frame, cx_string_get(name));
474 cpl_frame_set_tag(frame, tag);
475 cpl_frame_set_type(frame, CPL_FRAME_TYPE_IMAGE);
476 cpl_frame_set_group(frame, CPL_FRAME_GROUP_PRODUCT);
477 cpl_frame_set_level(frame, level);
479 cx_string_delete(name);
493 cpl_error_set(fctid, CPL_ERROR_FILE_IO);
494 cpl_frame_delete(frame);
533 cpl_frame_level level, cxbool save,
537 const cxchar *fctid =
"giraffe_frame_create_table";
543 cpl_propertylist *properties;
546 if (table == NULL || tag == NULL) {
547 cpl_error_set(fctid, CPL_ERROR_NULL_INPUT);
553 if (properties == NULL) {
554 cpl_error_set(fctid, CPL_ERROR_DATA_NOT_FOUND);
558 if (update == TRUE) {
560 cpl_propertylist_update_string(properties, GIALIAS_EXTNAME, tag);
561 cpl_propertylist_set_comment(properties, GIALIAS_EXTNAME,
562 "FITS Extension name");
571 name = cx_string_create(tag);
572 cx_string_lower(name);
573 cx_string_append(name,
".fits");
575 _giraffe_frame_update_product(properties, cx_string_get(name), tag,
578 frame = cpl_frame_new();
579 cpl_frame_set_filename(frame, cx_string_get(name));
580 cpl_frame_set_tag(frame, tag);
581 cpl_frame_set_type(frame, CPL_FRAME_TYPE_TABLE);
582 cpl_frame_set_group(frame, CPL_FRAME_GROUP_PRODUCT);
583 cpl_frame_set_level(frame, level);
585 cx_string_delete(name);
599 cpl_error_set(fctid, CPL_ERROR_FILE_IO);
600 cpl_frame_delete(frame);
635 const cxchar *tag, cxbool update)
638 const cxchar *fctid =
"giraffe_frame_attach_table";
645 cpl_propertylist *properties;
651 if (frame == NULL || table == NULL || tag == NULL) {
652 cpl_error_set(fctid, CPL_ERROR_NULL_INPUT);
656 name = (cxchar *)cpl_frame_get_filename(frame);
659 cpl_error_set(fctid, CPL_ERROR_ILLEGAL_INPUT);
665 if (properties == NULL) {
666 cpl_error_set(fctid, CPL_ERROR_DATA_NOT_FOUND);
673 cpl_error_set(fctid, CPL_ERROR_DATA_NOT_FOUND);
678 if (update == TRUE) {
690 cpl_propertylist_update_string(properties, GIALIAS_EXTNAME, tag);
691 cpl_propertylist_set_comment(properties, GIALIAS_EXTNAME,
692 "FITS Extension name");
699 status = cpl_table_save(data, NULL, properties, name, CPL_IO_EXTEND);
701 if (status != CPL_ERROR_NONE) {
702 cpl_error_set(fctid, CPL_ERROR_FILE_IO);
729 cpl_frame_group group)
732 cpl_frameset* _set = (cpl_frameset*)set;
734 cpl_frame *frame = NULL;
737 if (_set == NULL || tag == NULL) {
741 frame = cpl_frameset_find(_set, tag);
743 if (group != CPL_FRAME_GROUP_NONE) {
745 while (frame != NULL && cpl_frame_get_group(frame) != group) {
746 frame = cpl_frameset_find(_set, NULL);
778 cpl_frameset* _set = (cpl_frameset*)set;
780 cpl_frame *frame = NULL;
787 frame = cpl_frameset_find(_set, GIFRAME_SLITSETUP);
788 frame = frame == 0 ? cpl_frameset_find(_set, GIFRAME_SLITMASTER) : frame;
789 frame = frame == 0 ? cpl_frameset_find(_set, GIFRAME_SLITGEOMETRY) : frame;
cpl_frame * giraffe_frame_create_table(GiTable *table, const cxchar *tag, cpl_frame_level level, cxbool save, cxbool update)
Create a table product frame.
cpl_frame * giraffe_frame_create_image(GiImage *image, const cxchar *tag, cpl_frame_level level, cxbool save, cxbool update)
Create an image product frame.
cpl_frame * giraffe_get_slitgeometry(const cpl_frameset *set)
Get the slit geometry frame from a frame set.
cpl_frame * giraffe_get_frame(const cpl_frameset *set, const cxchar *tag, cpl_frame_group group)
Get a frame from a frame set.
cxint giraffe_frame_save(const cpl_frame *frame, const cpl_propertylist *properties, cxcptr object, cxcptr data, GiFrameCreator creator)
Save a data object to a frame.
cxint giraffe_frame_attach_table(cpl_frame *frame, GiTable *table, const cxchar *tag, cxbool update)
Attach a table to a product frame.
cpl_frame * giraffe_frame_create(const cxchar *tag, cpl_frame_level level, const cpl_propertylist *properties, cxcptr object, cxcptr data, GiFrameCreator creator)
Create a product frame using a provided frame creator.
cpl_propertylist * giraffe_image_get_properties(const GiImage *self)
Get the properties of an image.
cxint giraffe_image_save(GiImage *self, const cxchar *filename)
Write a Giraffe image to a file.
cpl_image * giraffe_image_get(const GiImage *self)
Gets the image data.
cxint giraffe_table_save(GiTable *self, const cxchar *filename)
Write a Giraffe table to a file.
cpl_propertylist * giraffe_table_get_properties(const GiTable *self)
Gets the table properties.
cpl_table * giraffe_table_get(const GiTable *self)
Get the table data from a Giraffe table.