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) {
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));
457 if(strcmp(tag,GIFRAME_SCIENCE_RBNSPECTRA)==0){
458 cpl_propertylist_update_string(properties, GIALIAS_PRODCATG,
459 GIALIAS_PRODCATG_RBNSPECTRA );
469 name = cx_string_create(tag);
470 cx_string_lower(name);
471 cx_string_append(name,
".fits");
473 _giraffe_frame_update_product(properties, cx_string_get(name), tag,
476 frame = cpl_frame_new();
477 cpl_frame_set_filename(frame, cx_string_get(name));
478 cpl_frame_set_tag(frame, tag);
479 cpl_frame_set_type(frame, CPL_FRAME_TYPE_IMAGE);
480 cpl_frame_set_group(frame, CPL_FRAME_GROUP_PRODUCT);
481 cpl_frame_set_level(frame, level);
483 cx_string_delete(name);
497 cpl_error_set(fctid, CPL_ERROR_FILE_IO);
498 cpl_frame_delete(frame);
537 cpl_frame_level level, cxbool save,
541 const cxchar *fctid =
"giraffe_frame_create_table";
547 cpl_propertylist *properties;
550 if (table == NULL || tag == NULL) {
551 cpl_error_set(fctid, CPL_ERROR_NULL_INPUT);
557 if (properties == NULL) {
558 cpl_error_set(fctid, CPL_ERROR_DATA_NOT_FOUND);
562 if (update == TRUE) {
564 cpl_propertylist_update_string(properties, GIALIAS_EXTNAME, tag);
565 cpl_propertylist_set_comment(properties, GIALIAS_EXTNAME,
566 "FITS Extension name");
575 name = cx_string_create(tag);
576 cx_string_lower(name);
577 cx_string_append(name,
".fits");
579 _giraffe_frame_update_product(properties, cx_string_get(name), tag,
582 frame = cpl_frame_new();
583 cpl_frame_set_filename(frame, cx_string_get(name));
584 cpl_frame_set_tag(frame, tag);
585 cpl_frame_set_type(frame, CPL_FRAME_TYPE_TABLE);
586 cpl_frame_set_group(frame, CPL_FRAME_GROUP_PRODUCT);
587 cpl_frame_set_level(frame, level);
589 cx_string_delete(name);
603 cpl_error_set(fctid, CPL_ERROR_FILE_IO);
604 cpl_frame_delete(frame);
639 const cxchar *tag, cxbool update)
642 const cxchar *fctid =
"giraffe_frame_attach_table";
649 cpl_propertylist *properties;
655 if (frame == NULL || table == NULL || tag == NULL) {
656 cpl_error_set(fctid, CPL_ERROR_NULL_INPUT);
660 name = (cxchar *)cpl_frame_get_filename(frame);
663 cpl_error_set(fctid, CPL_ERROR_ILLEGAL_INPUT);
669 if (properties == NULL) {
670 cpl_error_set(fctid, CPL_ERROR_DATA_NOT_FOUND);
677 cpl_error_set(fctid, CPL_ERROR_DATA_NOT_FOUND);
682 if (update == TRUE) {
694 cpl_propertylist_update_string(properties, GIALIAS_EXTNAME, tag);
695 cpl_propertylist_set_comment(properties, GIALIAS_EXTNAME,
696 "FITS Extension name");
703 status = cpl_table_save(data, NULL, properties, name, CPL_IO_EXTEND);
705 if (status != CPL_ERROR_NONE) {
706 cpl_error_set(fctid, CPL_ERROR_FILE_IO);
733 cpl_frame_group group)
736 cpl_frameset* _set = (cpl_frameset*)set;
738 cpl_frame *frame = NULL;
741 if (_set == NULL || tag == NULL) {
745 frame = cpl_frameset_find(_set, tag);
747 if (group != CPL_FRAME_GROUP_NONE) {
749 while (frame != NULL && cpl_frame_get_group(frame) != group) {
750 frame = cpl_frameset_find(_set, NULL);
782 cpl_frameset* _set = (cpl_frameset*)set;
784 cpl_frame *frame = NULL;
791 frame = cpl_frameset_find(_set, GIFRAME_SLITSETUP);
792 frame = frame == 0 ? cpl_frameset_find(_set, GIFRAME_SLITMASTER) : frame;
793 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.