25#include <cxmessages.h>
27#include <cxstrutils.h>
47_giraffe_frame_update_product(cpl_propertylist* properties,
48 const cxchar* name,
const cxchar* tag,
49 const cxchar* type,
const cxchar* tech)
52 cxchar* dpr_tech = NULL;
57 if (properties == NULL) {
72 if (cpl_propertylist_has(properties, GIALIAS_DPRTECH) == TRUE) {
74 const cxchar* s = cpl_propertylist_get_string(properties,
77 dpr_tech = cx_strdup(s);
80 else if (cpl_propertylist_has(properties, GIALIAS_PROTECH) == TRUE) {
82 const cxchar* s = cpl_propertylist_get_string(properties,
85 dpr_tech = cx_strdup(s);
89 if ((dpr_tech == NULL) || (dpr_tech[0] ==
'\0')) {
103 if (cpl_propertylist_has(properties, GIALIAS_PROSCIENCE) == FALSE) {
105 if (cpl_propertylist_has(properties, GIALIAS_DPRCATG) == TRUE) {
107 const cxchar* s = cpl_propertylist_get_string(properties,
111 science = (strncmp(s,
"SCIENCE", 7) == 0) ? 1 : 0;
123 cpl_propertylist_erase(properties, GIALIAS_ORIGIN);
124 cpl_propertylist_erase(properties, GIALIAS_DATE);
125 cpl_propertylist_erase(properties, GIALIAS_DATAMD5);
126 cpl_propertylist_erase(properties, GIALIAS_ORIGFILE);
127 cpl_propertylist_erase(properties, GIALIAS_ARCFILE);
128 cpl_propertylist_erase(properties, GIALIAS_CHECKSUM);
129 cpl_propertylist_erase(properties, GIALIAS_DATASUM);
131 cpl_propertylist_erase_regexp(properties,
"ESO DPR.*", 0);
134 giraffe_error_push();
136 cpl_propertylist_update_string(properties, GIALIAS_INSTRUMENT,
138 cpl_propertylist_set_comment(properties, GIALIAS_INSTRUMENT,
139 "Name of the Instrument.");
141 cpl_propertylist_update_string(properties, GIALIAS_DATAMD5,
143 cpl_propertylist_set_comment(properties, GIALIAS_DATAMD5,
147 cpl_propertylist_update_string(properties, GIALIAS_PIPEFILE, name);
148 cpl_propertylist_set_comment(properties, GIALIAS_PIPEFILE,
149 "Filename of data product");
152 if (cpl_error_get_code() != CPL_ERROR_NONE) {
166 giraffe_error_push();
168 cpl_propertylist_update_string(properties, GIALIAS_PRODID, PRODUCT_DID);
169 cpl_propertylist_set_comment(properties, GIALIAS_PRODID,
170 "Data dictionary for PRO");
174 cpl_propertylist_update_string(properties, GIALIAS_PROCATG, tag);
175 cpl_propertylist_set_comment(properties, GIALIAS_PROCATG,
176 "Pipeline product category");
180 cpl_propertylist_update_string(properties, GIALIAS_PROTYPE, type);
181 cpl_propertylist_set_comment(properties, GIALIAS_PROTYPE,
184 cpl_propertylist_update_string(properties, GIALIAS_PROTECH, tech);
185 cpl_propertylist_set_comment(properties, GIALIAS_PROTECH,
186 "Observation technique");
191 cpl_propertylist_update_bool(properties, GIALIAS_PROSCIENCE, science);
192 cpl_propertylist_set_comment(properties, GIALIAS_PROSCIENCE,
193 "Scientific product if T");
196 if (cpl_error_get_code() != CPL_ERROR_NONE) {
240 const cpl_propertylist *properties, cxcptr
object,
241 cxcptr data, GiFrameCreator creator)
244 const cxchar *
const fctid =
"giraffe_frame_create";
248 cx_string *name = NULL;
250 cpl_propertylist *p = NULL;
252 cpl_frame *frame = NULL;
255 if (properties == NULL || creator == NULL) {
256 cpl_error_set(fctid, CPL_ERROR_NULL_INPUT);
261 cpl_error_set(fctid, CPL_ERROR_NULL_INPUT);
265 p = cpl_propertylist_duplicate(properties);
266 cx_assert(p != NULL);
272 name = cx_string_create(tag);
273 cx_assert(name != NULL);
275 cx_string_lower(name);
276 cx_string_append(name,
".fits");
278 _giraffe_frame_update_product(p, cx_string_get(name), tag,
"REDUCED",
281 frame = cpl_frame_new();
282 cpl_frame_set_filename(frame, cx_string_get(name));
283 cpl_frame_set_tag(frame, tag);
284 cpl_frame_set_type(frame, CPL_FRAME_TYPE_IMAGE);
285 cpl_frame_set_group(frame, CPL_FRAME_GROUP_PRODUCT);
286 cpl_frame_set_level(frame, level);
292 status = creator(
object, p, cx_string_get(name), data);
295 cpl_frame_delete(frame);
299 cx_string_delete(name);
300 cpl_propertylist_delete(p);
327 const cpl_propertylist* properties,
328 cxcptr
object, cxcptr data,
329 GiFrameCreator creator)
332 const cxchar*
const fctid =
"giraffe_frame_save";
336 cpl_propertylist* p = NULL;
339 if (properties == NULL || creator == NULL) {
340 cpl_error_set(fctid, CPL_ERROR_NULL_INPUT);
351 p = cpl_propertylist_duplicate(properties);
352 cx_assert(p != NULL);
359 status = creator(
object, p, cpl_frame_get_filename(frame), data);
361 cpl_propertylist_delete(p);
396 cpl_frame_level level, cxbool save,
399 const cxchar *fctid =
"giraffe_frame_create_image";
405 cpl_propertylist *properties;
408 if (image == NULL || tag == NULL) {
409 cpl_error_set(fctid, CPL_ERROR_NULL_INPUT);
415 if (properties == NULL) {
416 cpl_error_set(fctid, CPL_ERROR_DATA_NOT_FOUND);
420 if (update == TRUE) {
424 if (_image == NULL) {
425 cpl_error_set(fctid, CPL_ERROR_DATA_NOT_FOUND);
429 if (cpl_image_get_bpm_const(_image) == NULL) {
430 cpl_mask *_mask = cpl_mask_threshold_image_create(_image, -DBL_MAX, DBL_MAX);
432 cpl_image_set_bpm(_image, _mask);
435 cpl_propertylist_update_double(properties, GIALIAS_DATAMIN,
436 cpl_image_get_min(_image));
437 cpl_propertylist_set_comment(properties, GIALIAS_DATAMIN,
438 "Minimal pixel value");
440 cpl_propertylist_update_double(properties, GIALIAS_DATAMAX,
441 cpl_image_get_max(_image));
442 cpl_propertylist_set_comment(properties, GIALIAS_DATAMAX,
443 "Maximum pixel value");
445 cpl_propertylist_update_double(properties, GIALIAS_DATAMEAN,
446 cpl_image_get_mean(_image));
447 cpl_propertylist_set_comment(properties, GIALIAS_DATAMEAN,
448 "Mean of pixel values");
450 cpl_propertylist_update_double(properties, GIALIAS_DATASIG,
451 cpl_image_get_stdev(_image));
452 cpl_propertylist_set_comment(properties, GIALIAS_DATASIG,
453 "Standard deviation of pixel values");
455 cpl_propertylist_update_double(properties, GIALIAS_DATAMEDI,
456 cpl_image_get_median(_image));
457 cpl_propertylist_set_comment(properties, GIALIAS_DATAMEDI,
458 "Median of pixel values");
460 cpl_propertylist_update_int(properties, GIALIAS_NAXIS1,
461 cpl_image_get_size_x(_image));
462 cpl_propertylist_update_int(properties, GIALIAS_NAXIS2,
463 cpl_image_get_size_y(_image));
464 if(strcmp(tag,GIFRAME_SCIENCE_RBNSPECTRA)==0){
465 cpl_propertylist_update_string(properties, GIALIAS_PRODCATG,
466 GIALIAS_PRODCATG_RBNSPECTRA );
476 name = cx_string_create(tag);
477 cx_string_lower(name);
478 cx_string_append(name,
".fits");
480 _giraffe_frame_update_product(properties, cx_string_get(name), tag,
483 frame = cpl_frame_new();
484 cpl_frame_set_filename(frame, cx_string_get(name));
485 cpl_frame_set_tag(frame, tag);
486 cpl_frame_set_type(frame, CPL_FRAME_TYPE_IMAGE);
487 cpl_frame_set_group(frame, CPL_FRAME_GROUP_PRODUCT);
488 cpl_frame_set_level(frame, level);
490 cx_string_delete(name);
504 cpl_error_set(fctid, CPL_ERROR_FILE_IO);
505 cpl_frame_delete(frame);
544 cpl_frame_level level, cxbool save,
548 const cxchar *fctid =
"giraffe_frame_create_table";
554 cpl_propertylist *properties;
557 if (table == NULL || tag == NULL) {
558 cpl_error_set(fctid, CPL_ERROR_NULL_INPUT);
564 if (properties == NULL) {
565 cpl_error_set(fctid, CPL_ERROR_DATA_NOT_FOUND);
569 if (update == TRUE) {
571 cpl_propertylist_update_string(properties, GIALIAS_EXTNAME, tag);
572 cpl_propertylist_set_comment(properties, GIALIAS_EXTNAME,
573 "FITS Extension name");
582 name = cx_string_create(tag);
583 cx_string_lower(name);
584 cx_string_append(name,
".fits");
586 _giraffe_frame_update_product(properties, cx_string_get(name), tag,
589 frame = cpl_frame_new();
590 cpl_frame_set_filename(frame, cx_string_get(name));
591 cpl_frame_set_tag(frame, tag);
592 cpl_frame_set_type(frame, CPL_FRAME_TYPE_TABLE);
593 cpl_frame_set_group(frame, CPL_FRAME_GROUP_PRODUCT);
594 cpl_frame_set_level(frame, level);
596 cx_string_delete(name);
610 cpl_error_set(fctid, CPL_ERROR_FILE_IO);
611 cpl_frame_delete(frame);
646 const cxchar *tag, cxbool update)
649 const cxchar *fctid =
"giraffe_frame_attach_table";
656 cpl_propertylist *properties;
662 if (frame == NULL || table == NULL || tag == NULL) {
663 cpl_error_set(fctid, CPL_ERROR_NULL_INPUT);
667 name = (cxchar *)cpl_frame_get_filename(frame);
670 cpl_error_set(fctid, CPL_ERROR_ILLEGAL_INPUT);
676 if (properties == NULL) {
677 cpl_error_set(fctid, CPL_ERROR_DATA_NOT_FOUND);
684 cpl_error_set(fctid, CPL_ERROR_DATA_NOT_FOUND);
689 if (update == TRUE) {
701 cpl_propertylist_update_string(properties, GIALIAS_EXTNAME, tag);
702 cpl_propertylist_set_comment(properties, GIALIAS_EXTNAME,
703 "FITS Extension name");
710 status = cpl_table_save(data, NULL, properties, name, CPL_IO_EXTEND);
712 if (status != CPL_ERROR_NONE) {
713 cpl_error_set(fctid, CPL_ERROR_FILE_IO);
740 cpl_frame_group group)
743 cpl_frameset* _set = (cpl_frameset*)set;
745 cpl_frame *frame = NULL;
748 if (_set == NULL || tag == NULL) {
752 frame = cpl_frameset_find(_set, tag);
754 if (group != CPL_FRAME_GROUP_NONE) {
756 while (frame != NULL && cpl_frame_get_group(frame) != group) {
757 frame = cpl_frameset_find(_set, NULL);
789 cpl_frameset* _set = (cpl_frameset*)set;
791 cpl_frame *frame = NULL;
798 frame = cpl_frameset_find(_set, GIFRAME_SLITSETUP);
799 frame = frame == 0 ? cpl_frameset_find(_set, GIFRAME_SLITMASTER) : frame;
800 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.