25#include <cxstrutils.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) {
422 if (_image == NULL) {
423 cpl_error_set(fctid, CPL_ERROR_DATA_NOT_FOUND);
427 if (cpl_image_get_bpm_const(_image) == NULL) {
428 cpl_mask *_mask = cpl_mask_threshold_image_create(_image, -DBL_MAX, DBL_MAX);
430 cpl_image_set_bpm(_image, _mask);
433 cpl_propertylist_update_double(properties, GIALIAS_DATAMIN,
434 cpl_image_get_min(_image));
435 cpl_propertylist_set_comment(properties, GIALIAS_DATAMIN,
436 "Minimal pixel value");
438 cpl_propertylist_update_double(properties, GIALIAS_DATAMAX,
439 cpl_image_get_max(_image));
440 cpl_propertylist_set_comment(properties, GIALIAS_DATAMAX,
441 "Maximum pixel value");
443 cpl_propertylist_update_double(properties, GIALIAS_DATAMEAN,
444 cpl_image_get_mean(_image));
445 cpl_propertylist_set_comment(properties, GIALIAS_DATAMEAN,
446 "Mean of pixel values");
448 cpl_propertylist_update_double(properties, GIALIAS_DATASIG,
449 cpl_image_get_stdev(_image));
450 cpl_propertylist_set_comment(properties, GIALIAS_DATASIG,
451 "Standard deviation of pixel values");
453 cpl_propertylist_update_double(properties, GIALIAS_DATAMEDI,
454 cpl_image_get_median(_image));
455 cpl_propertylist_set_comment(properties, GIALIAS_DATAMEDI,
456 "Median of pixel values");
458 cpl_propertylist_update_int(properties, GIALIAS_NAXIS1,
459 cpl_image_get_size_x(_image));
460 cpl_propertylist_update_int(properties, GIALIAS_NAXIS2,
461 cpl_image_get_size_y(_image));
462 if(strcmp(tag,GIFRAME_SCIENCE_RBNSPECTRA)==0){
463 cpl_propertylist_update_string(properties, GIALIAS_PRODCATG,
464 GIALIAS_PRODCATG_RBNSPECTRA );
474 name = cx_string_create(tag);
475 cx_string_lower(name);
476 cx_string_append(name,
".fits");
478 _giraffe_frame_update_product(properties, cx_string_get(name), tag,
481 frame = cpl_frame_new();
482 cpl_frame_set_filename(frame, cx_string_get(name));
483 cpl_frame_set_tag(frame, tag);
484 cpl_frame_set_type(frame, CPL_FRAME_TYPE_IMAGE);
485 cpl_frame_set_group(frame, CPL_FRAME_GROUP_PRODUCT);
486 cpl_frame_set_level(frame, level);
488 cx_string_delete(name);
502 cpl_error_set(fctid, CPL_ERROR_FILE_IO);
503 cpl_frame_delete(frame);
542 cpl_frame_level level, cxbool save,
546 const cxchar *fctid =
"giraffe_frame_create_table";
552 cpl_propertylist *properties;
555 if (table == NULL || tag == NULL) {
556 cpl_error_set(fctid, CPL_ERROR_NULL_INPUT);
562 if (properties == NULL) {
563 cpl_error_set(fctid, CPL_ERROR_DATA_NOT_FOUND);
567 if (update == TRUE) {
569 cpl_propertylist_update_string(properties, GIALIAS_EXTNAME, tag);
570 cpl_propertylist_set_comment(properties, GIALIAS_EXTNAME,
571 "FITS Extension name");
580 name = cx_string_create(tag);
581 cx_string_lower(name);
582 cx_string_append(name,
".fits");
584 _giraffe_frame_update_product(properties, cx_string_get(name), tag,
587 frame = cpl_frame_new();
588 cpl_frame_set_filename(frame, cx_string_get(name));
589 cpl_frame_set_tag(frame, tag);
590 cpl_frame_set_type(frame, CPL_FRAME_TYPE_TABLE);
591 cpl_frame_set_group(frame, CPL_FRAME_GROUP_PRODUCT);
592 cpl_frame_set_level(frame, level);
594 cx_string_delete(name);
608 cpl_error_set(fctid, CPL_ERROR_FILE_IO);
609 cpl_frame_delete(frame);
644 const cxchar *tag, cxbool update)
647 const cxchar *fctid =
"giraffe_frame_attach_table";
654 cpl_propertylist *properties;
660 if (frame == NULL || table == NULL || tag == NULL) {
661 cpl_error_set(fctid, CPL_ERROR_NULL_INPUT);
665 name = (cxchar *)cpl_frame_get_filename(frame);
668 cpl_error_set(fctid, CPL_ERROR_ILLEGAL_INPUT);
674 if (properties == NULL) {
675 cpl_error_set(fctid, CPL_ERROR_DATA_NOT_FOUND);
682 cpl_error_set(fctid, CPL_ERROR_DATA_NOT_FOUND);
687 if (update == TRUE) {
699 cpl_propertylist_update_string(properties, GIALIAS_EXTNAME, tag);
700 cpl_propertylist_set_comment(properties, GIALIAS_EXTNAME,
701 "FITS Extension name");
708 status = cpl_table_save(data, NULL, properties, name, CPL_IO_EXTEND);
710 if (status != CPL_ERROR_NONE) {
711 cpl_error_set(fctid, CPL_ERROR_FILE_IO);
738 cpl_frame_group group)
741 cpl_frameset* _set = (cpl_frameset*)set;
743 cpl_frame *frame = NULL;
746 if (_set == NULL || tag == NULL) {
750 frame = cpl_frameset_find(_set, tag);
752 if (group != CPL_FRAME_GROUP_NONE) {
754 while (frame != NULL && cpl_frame_get_group(frame) != group) {
755 frame = cpl_frameset_find(_set, NULL);
787 cpl_frameset* _set = (cpl_frameset*)set;
789 cpl_frame *frame = NULL;
796 frame = cpl_frameset_find(_set, GIFRAME_SLITSETUP);
797 frame = frame == 0 ? cpl_frameset_find(_set, GIFRAME_SLITMASTER) : frame;
798 frame = frame == 0 ? cpl_frameset_find(_set, GIFRAME_SLITGEOMETRY) : frame;
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.
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_image(GiImage *image, const cxchar *tag, cpl_frame_level level, cxbool save, cxbool update)
Create an image product 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_get_slitgeometry(const cpl_frameset *set)
Get the slit geometry frame from a frame set.
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_image * giraffe_image_get(const GiImage *self)
Gets the image data.
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.
cxint giraffe_table_save(GiTable *self, const cxchar *filename)
Write a Giraffe table to a file.
cpl_table * giraffe_table_get(const GiTable *self)
Get the table data from a Giraffe table.
cpl_propertylist * giraffe_table_get_properties(const GiTable *self)
Gets the table properties.