33 #include <cxstrutils.h>
35 #include <cpl_error.h>
53 _giraffe_frame_update_product(cpl_propertylist* properties,
54 const cxchar* name,
const cxchar* tag,
55 const cxchar* type,
const cxchar* tech)
58 cxchar* dpr_tech = NULL;
63 if (properties == NULL) {
78 if (cpl_propertylist_has(properties, GIALIAS_DPRTECH) == TRUE) {
80 const cxchar* s = cpl_propertylist_get_string(properties,
83 dpr_tech = cx_strdup(s);
86 else if (cpl_propertylist_has(properties, GIALIAS_PROTECH) == TRUE) {
88 const cxchar* s = cpl_propertylist_get_string(properties,
91 dpr_tech = cx_strdup(s);
95 if ((dpr_tech == NULL) || (dpr_tech[0] ==
'\0')) {
109 if (cpl_propertylist_has(properties, GIALIAS_PROSCIENCE) == FALSE) {
111 if (cpl_propertylist_has(properties, GIALIAS_DPRCATG) == TRUE) {
113 const cxchar* s = cpl_propertylist_get_string(properties,
117 science = (strncmp(s,
"SCIENCE", 7) == 0) ? 1 : 0;
129 cpl_propertylist_erase(properties, GIALIAS_ORIGIN);
130 cpl_propertylist_erase(properties, GIALIAS_DATE);
131 cpl_propertylist_erase(properties, GIALIAS_DATAMD5);
132 cpl_propertylist_erase(properties, GIALIAS_ORIGFILE);
133 cpl_propertylist_erase(properties, GIALIAS_ARCFILE);
134 cpl_propertylist_erase(properties, GIALIAS_CHECKSUM);
135 cpl_propertylist_erase(properties, GIALIAS_DATASUM);
137 cpl_propertylist_erase_regexp(properties,
"ESO DPR.*", 0);
140 giraffe_error_push();
142 cpl_propertylist_update_string(properties, GIALIAS_INSTRUMENT,
144 cpl_propertylist_set_comment(properties, GIALIAS_INSTRUMENT,
145 "Name of the Instrument.");
147 cpl_propertylist_update_string(properties, GIALIAS_DATAMD5,
149 cpl_propertylist_set_comment(properties, GIALIAS_DATAMD5,
153 cpl_propertylist_update_string(properties, GIALIAS_PIPEFILE, name);
154 cpl_propertylist_set_comment(properties, GIALIAS_PIPEFILE,
155 "Filename of data product");
158 if (cpl_error_get_code() != CPL_ERROR_NONE) {
172 giraffe_error_push();
174 cpl_propertylist_update_string(properties, GIALIAS_PRODID, PRODUCT_DID);
175 cpl_propertylist_set_comment(properties, GIALIAS_PRODID,
176 "Data dictionary for PRO");
180 cpl_propertylist_update_string(properties, GIALIAS_PROCATG, tag);
181 cpl_propertylist_set_comment(properties, GIALIAS_PROCATG,
182 "Pipeline product category");
186 cpl_propertylist_update_string(properties, GIALIAS_PROTYPE, type);
187 cpl_propertylist_set_comment(properties, GIALIAS_PROTYPE,
190 cpl_propertylist_update_string(properties, GIALIAS_PROTECH, tech);
191 cpl_propertylist_set_comment(properties, GIALIAS_PROTECH,
192 "Observation technique");
197 cpl_propertylist_update_bool(properties, GIALIAS_PROSCIENCE, science);
198 cpl_propertylist_set_comment(properties, GIALIAS_PROSCIENCE,
199 "Scientific product if T");
202 if (cpl_error_get_code() != CPL_ERROR_NONE) {
246 const cpl_propertylist *properties, cxcptr
object,
247 cxcptr data, GiFrameCreator creator)
250 const cxchar *
const fctid =
"giraffe_frame_create";
254 cx_string *name = NULL;
256 cpl_propertylist *p = NULL;
258 cpl_frame *frame = NULL;
261 if (properties == NULL || creator == NULL) {
262 cpl_error_set(fctid, CPL_ERROR_NULL_INPUT);
267 cpl_error_set(fctid, CPL_ERROR_NULL_INPUT);
271 p = cpl_propertylist_duplicate(properties);
272 cx_assert(p != NULL);
278 name = cx_string_create(tag);
279 cx_assert(name != NULL);
281 cx_string_lower(name);
282 cx_string_append(name,
".fits");
284 _giraffe_frame_update_product(p, cx_string_get(name), tag,
"REDUCED",
287 frame = cpl_frame_new();
288 cpl_frame_set_filename(frame, cx_string_get(name));
289 cpl_frame_set_tag(frame, tag);
290 cpl_frame_set_type(frame, CPL_FRAME_TYPE_IMAGE);
291 cpl_frame_set_group(frame, CPL_FRAME_GROUP_PRODUCT);
292 cpl_frame_set_level(frame, level);
298 status = creator(
object, p, cx_string_get(name), data);
301 cpl_frame_delete(frame);
305 cx_string_delete(name);
306 cpl_propertylist_delete(p);
333 const cpl_propertylist* properties,
334 cxcptr
object, cxcptr data,
335 GiFrameCreator creator)
338 const cxchar*
const fctid =
"giraffe_frame_save";
342 cpl_propertylist* p = NULL;
345 if (properties == NULL || creator == NULL) {
346 cpl_error_set(fctid, CPL_ERROR_NULL_INPUT);
357 p = cpl_propertylist_duplicate(properties);
358 cx_assert(p != NULL);
365 status = creator(
object, p, cpl_frame_get_filename(frame), data);
367 cpl_propertylist_delete(p);
402 cpl_frame_level level, cxbool save,
405 const cxchar *fctid =
"giraffe_frame_create_image";
411 cpl_propertylist *properties;
414 if (image == NULL || tag == NULL) {
415 cpl_error_set(fctid, CPL_ERROR_NULL_INPUT);
421 if (properties == NULL) {
422 cpl_error_set(fctid, CPL_ERROR_DATA_NOT_FOUND);
426 if (update == TRUE) {
431 if (_image == NULL) {
432 cpl_error_set(fctid, CPL_ERROR_DATA_NOT_FOUND);
436 cpl_propertylist_update_double(properties, GIALIAS_DATAMIN,
437 cpl_image_get_min(_image));
438 cpl_propertylist_set_comment(properties, GIALIAS_DATAMIN,
439 "Minimal pixel value");
441 cpl_propertylist_update_double(properties, GIALIAS_DATAMAX,
442 cpl_image_get_max(_image));
443 cpl_propertylist_set_comment(properties, GIALIAS_DATAMAX,
444 "Maximum pixel value");
446 cpl_propertylist_update_double(properties, GIALIAS_DATAMEAN,
447 cpl_image_get_mean(_image));
448 cpl_propertylist_set_comment(properties, GIALIAS_DATAMEAN,
449 "Mean of pixel values");
451 cpl_propertylist_update_double(properties, GIALIAS_DATASIG,
452 cpl_image_get_stdev(_image));
453 cpl_propertylist_set_comment(properties, GIALIAS_DATASIG,
454 "Standard deviation of pixel values");
456 cpl_propertylist_update_double(properties, GIALIAS_DATAMEDI,
457 cpl_image_get_median(_image));
458 cpl_propertylist_set_comment(properties, GIALIAS_DATAMEDI,
459 "Median of pixel values");
461 cpl_propertylist_update_int(properties, GIALIAS_NAXIS1,
462 cpl_image_get_size_x(_image));
463 cpl_propertylist_update_int(properties, GIALIAS_NAXIS2,
464 cpl_image_get_size_y(_image));
473 name = cx_string_create(tag);
474 cx_string_lower(name);
475 cx_string_append(name,
".fits");
477 _giraffe_frame_update_product(properties, cx_string_get(name), tag,
480 frame = cpl_frame_new();
481 cpl_frame_set_filename(frame, cx_string_get(name));
482 cpl_frame_set_tag(frame, tag);
483 cpl_frame_set_type(frame, CPL_FRAME_TYPE_IMAGE);
484 cpl_frame_set_group(frame, CPL_FRAME_GROUP_PRODUCT);
485 cpl_frame_set_level(frame, level);
487 cx_string_delete(name);
501 cpl_error_set(fctid, CPL_ERROR_FILE_IO);
502 cpl_frame_delete(frame);
541 cpl_frame_level level, cxbool save,
545 const cxchar *fctid =
"giraffe_frame_create_table";
551 cpl_propertylist *properties;
554 if (table == NULL || tag == NULL) {
555 cpl_error_set(fctid, CPL_ERROR_NULL_INPUT);
561 if (properties == NULL) {
562 cpl_error_set(fctid, CPL_ERROR_DATA_NOT_FOUND);
566 if (update == TRUE) {
568 cpl_propertylist_update_string(properties, GIALIAS_EXTNAME, tag);
569 cpl_propertylist_set_comment(properties, GIALIAS_EXTNAME,
570 "FITS Extension name");
579 name = cx_string_create(tag);
580 cx_string_lower(name);
581 cx_string_append(name,
".fits");
583 _giraffe_frame_update_product(properties, cx_string_get(name), tag,
586 frame = cpl_frame_new();
587 cpl_frame_set_filename(frame, cx_string_get(name));
588 cpl_frame_set_tag(frame, tag);
589 cpl_frame_set_type(frame, CPL_FRAME_TYPE_TABLE);
590 cpl_frame_set_group(frame, CPL_FRAME_GROUP_PRODUCT);
591 cpl_frame_set_level(frame, level);
593 cx_string_delete(name);
607 cpl_error_set(fctid, CPL_ERROR_FILE_IO);
608 cpl_frame_delete(frame);
643 const cxchar *tag, cxbool update)
646 const cxchar *fctid =
"giraffe_frame_attach_table";
653 cpl_propertylist *properties;
659 if (frame == NULL || table == NULL || tag == NULL) {
660 cpl_error_set(fctid, CPL_ERROR_NULL_INPUT);
664 name = (cxchar *)cpl_frame_get_filename(frame);
667 cpl_error_set(fctid, CPL_ERROR_ILLEGAL_INPUT);
673 if (properties == NULL) {
674 cpl_error_set(fctid, CPL_ERROR_DATA_NOT_FOUND);
681 cpl_error_set(fctid, CPL_ERROR_DATA_NOT_FOUND);
686 if (update == TRUE) {
698 cpl_propertylist_update_string(properties, GIALIAS_EXTNAME, tag);
699 cpl_propertylist_set_comment(properties, GIALIAS_EXTNAME,
700 "FITS Extension name");
707 status = cpl_table_save(data, NULL, properties, name, CPL_IO_EXTEND);
709 if (status != CPL_ERROR_NONE) {
710 cpl_error_set(fctid, CPL_ERROR_FILE_IO);
737 cpl_frame_group group)
740 cpl_frameset* _set = (cpl_frameset*)set;
742 cpl_frame *frame = NULL;
745 if (_set == NULL || tag == NULL) {
749 frame = cpl_frameset_find(_set, tag);
751 if (group != CPL_FRAME_GROUP_NONE) {
753 while (frame != NULL && cpl_frame_get_group(frame) != group) {
754 frame = cpl_frameset_find(_set, NULL);
786 cpl_frameset* _set = (cpl_frameset*)set;
788 cpl_frame *frame = NULL;
795 frame = cpl_frameset_find(_set, GIFRAME_SLITSETUP);
796 frame = frame == 0 ? cpl_frameset_find(_set, GIFRAME_SLITMASTER) : frame;
797 frame = frame == 0 ? cpl_frameset_find(_set, GIFRAME_SLITGEOMETRY) : 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.
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_table * giraffe_table_get(const GiTable *self)
Get the table data from a Giraffe table.
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.
cpl_frame * giraffe_frame_create_table(GiTable *table, const cxchar *tag, cpl_frame_level level, cxbool save, cxbool update)
Create a table product frame.
cxint giraffe_image_save(GiImage *self, const cxchar *filename)
Write a Giraffe image to a file.
cxint giraffe_frame_attach_table(cpl_frame *frame, GiTable *table, const cxchar *tag, cxbool update)
Attach a table to a product frame.
cxint giraffe_table_save(GiTable *self, const cxchar *filename)
Write a Giraffe table to a file.
cpl_image * giraffe_image_get(const GiImage *self)
Gets the image data.
cpl_propertylist * giraffe_table_get_properties(const GiTable *self)
Gets the table properties.
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_propertylist * giraffe_image_get_properties(const GiImage *self)
Get the properties of an image.