GIRAFFE Pipeline Reference Manual

giframe.c
1/*
2 * This file is part of the GIRAFFE Pipeline
3 * Copyright (C) 2002-2019 European Southern Observatory
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20#ifdef HAVE_CONFIG_H
21# include <config.h>
22#endif
23
24#include <cxstring.h>
25#include <cxstrutils.h>
26
27#include <cpl_error.h>
28
29#include "gialias.h"
30#include "giutils.h"
31#include "giframe.h"
32#include "gierror.h"
33
34
44inline static cxint
45_giraffe_frame_update_product(cpl_propertylist* properties,
46 const cxchar* name, const cxchar* tag,
47 const cxchar* type, const cxchar* tech)
48{
49
50 cxchar* dpr_tech = NULL;
51
52 cxint science = -1;
53
54
55 if (properties == NULL) {
56 return -1;
57 }
58
59
60 /*
61 * Set default values
62 */
63
64 if (type == NULL) {
65 type = "REDUCED";
66 }
67
68 if (tech == NULL) {
69
70 if (cpl_propertylist_has(properties, GIALIAS_DPRTECH) == TRUE) {
71
72 const cxchar* s = cpl_propertylist_get_string(properties,
73 GIALIAS_DPRTECH);
74
75 dpr_tech = cx_strdup(s);
76
77 }
78 else if (cpl_propertylist_has(properties, GIALIAS_PROTECH) == TRUE) {
79
80 const cxchar* s = cpl_propertylist_get_string(properties,
81 GIALIAS_PROTECH);
82
83 dpr_tech = cx_strdup(s);
84
85 }
86
87 if ((dpr_tech == NULL) || (dpr_tech[0] == '\0')) {
88 tech = "UNDEFINED";
89 }
90 else {
91 tech = dpr_tech;
92 }
93
94 }
95
96
97 /*
98 * Check whether a scientific observation was processed.
99 */
100
101 if (cpl_propertylist_has(properties, GIALIAS_PROSCIENCE) == FALSE) {
102
103 if (cpl_propertylist_has(properties, GIALIAS_DPRCATG) == TRUE) {
104
105 const cxchar* s = cpl_propertylist_get_string(properties,
106 GIALIAS_DPRCATG);
107
108 if (s != NULL) {
109 science = (strncmp(s, "SCIENCE", 7) == 0) ? 1 : 0;
110 }
111
112 }
113
114 }
115
116
117 /*
118 * Clean frame properties
119 */
120
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);
128
129 cpl_propertylist_erase_regexp(properties, "ESO DPR.*", 0);
130
131
132 giraffe_error_push();
133
134 cpl_propertylist_update_string(properties, GIALIAS_INSTRUMENT,
135 "GIRAFFE");
136 cpl_propertylist_set_comment(properties, GIALIAS_INSTRUMENT,
137 "Name of the Instrument.");
138
139 cpl_propertylist_update_string(properties, GIALIAS_DATAMD5,
140 "Not computed");
141 cpl_propertylist_set_comment(properties, GIALIAS_DATAMD5,
142 "MD5 checksum");
143
144 if (name != NULL) {
145 cpl_propertylist_update_string(properties, GIALIAS_PIPEFILE, name);
146 cpl_propertylist_set_comment(properties, GIALIAS_PIPEFILE,
147 "Filename of data product");
148 }
149
150 if (cpl_error_get_code() != CPL_ERROR_NONE) {
151
152 cx_free(dpr_tech);
153 return 1;
154
155 }
156
157 giraffe_error_pop();
158
159
160 /*
161 * Set product keywords
162 */
163
164 giraffe_error_push();
165
166 cpl_propertylist_update_string(properties, GIALIAS_PRODID, PRODUCT_DID);
167 cpl_propertylist_set_comment(properties, GIALIAS_PRODID,
168 "Data dictionary for PRO");
169
170 if (tag != NULL) {
171
172 cpl_propertylist_update_string(properties, GIALIAS_PROCATG, tag);
173 cpl_propertylist_set_comment(properties, GIALIAS_PROCATG,
174 "Pipeline product category");
175
176 }
177
178 cpl_propertylist_update_string(properties, GIALIAS_PROTYPE, type);
179 cpl_propertylist_set_comment(properties, GIALIAS_PROTYPE,
180 "Product type");
181
182 cpl_propertylist_update_string(properties, GIALIAS_PROTECH, tech);
183 cpl_propertylist_set_comment(properties, GIALIAS_PROTECH,
184 "Observation technique");
185 cx_free(dpr_tech);
186 dpr_tech = NULL;
187
188 if (science != -1) {
189 cpl_propertylist_update_bool(properties, GIALIAS_PROSCIENCE, science);
190 cpl_propertylist_set_comment(properties, GIALIAS_PROSCIENCE,
191 "Scientific product if T");
192 }
193
194 if (cpl_error_get_code() != CPL_ERROR_NONE) {
195 return 1;
196 }
197
198 giraffe_error_pop();
199
200 return 0;
201
202}
203
204
236cpl_frame *
237giraffe_frame_create(const cxchar *tag, cpl_frame_level level,
238 const cpl_propertylist *properties, cxcptr object,
239 cxcptr data, GiFrameCreator creator)
240{
241
242 const cxchar *const fctid = "giraffe_frame_create";
243
244 cxint status = 0;
245
246 cx_string *name = NULL;
247
248 cpl_propertylist *p = NULL;
249
250 cpl_frame *frame = NULL;
251
252
253 if (properties == NULL || creator == NULL) {
254 cpl_error_set(fctid, CPL_ERROR_NULL_INPUT);
255 return NULL;
256 }
257
258 if (tag == NULL) {
259 cpl_error_set(fctid, CPL_ERROR_NULL_INPUT);
260 return NULL;
261 }
262
263 p = cpl_propertylist_duplicate(properties);
264 cx_assert(p != NULL);
265
266 /*
267 * Update the property list
268 */
269
270 name = cx_string_create(tag);
271 cx_assert(name != NULL);
272
273 cx_string_lower(name);
274 cx_string_append(name, ".fits");
275
276 _giraffe_frame_update_product(p, cx_string_get(name), tag, "REDUCED",
277 NULL);
278
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);
285
286 /*
287 * Write object to file
288 */
289
290 status = creator(object, p, cx_string_get(name), data);
291
292 if (status != 0) {
293 cpl_frame_delete(frame);
294 frame = NULL;
295 }
296
297 cx_string_delete(name);
298 cpl_propertylist_delete(p);
299
300 return frame;
301
302}
303
323cxint
324giraffe_frame_save(const cpl_frame* frame,
325 const cpl_propertylist* properties,
326 cxcptr object, cxcptr data,
327 GiFrameCreator creator)
328{
329
330 const cxchar* const fctid = "giraffe_frame_save";
331
332 cxint status = 0;
333
334 cpl_propertylist* p = NULL;
335
336
337 if (properties == NULL || creator == NULL) {
338 cpl_error_set(fctid, CPL_ERROR_NULL_INPUT);
339 return 127;
340 }
341
342
343 /*
344 * Create a local copy of the property list, to guarantee that
345 * the properties passed by the caller are not modified by the
346 * creator function.
347 */
348
349 p = cpl_propertylist_duplicate(properties);
350 cx_assert(p != NULL);
351
352
353 /*
354 * Write object to file
355 */
356
357 status = creator(object, p, cpl_frame_get_filename(frame), data);
358
359 cpl_propertylist_delete(p);
360 p = NULL;
361
362 return status;
363
364}
365
366
392cpl_frame *
393giraffe_frame_create_image(GiImage *image, const cxchar *tag,
394 cpl_frame_level level, cxbool save,
395 cxbool update)
396{
397 const cxchar *fctid = "giraffe_frame_create_image";
398
399 cx_string *name;
400
401 cpl_frame *frame;
402
403 cpl_propertylist *properties;
404
405
406 if (image == NULL || tag == NULL) {
407 cpl_error_set(fctid, CPL_ERROR_NULL_INPUT);
408 return NULL;
409 }
410
411 properties = giraffe_image_get_properties(image);
412
413 if (properties == NULL) {
414 cpl_error_set(fctid, CPL_ERROR_DATA_NOT_FOUND);
415 return NULL;
416 }
417
418 if (update == TRUE) {
419
420 cpl_image *_image = giraffe_image_get(image);
421
422 if (_image == NULL) {
423 cpl_error_set(fctid, CPL_ERROR_DATA_NOT_FOUND);
424 return NULL;
425 }
426
427 if (cpl_image_get_bpm_const(_image) == NULL) {
428 cpl_mask *_mask = cpl_mask_threshold_image_create(_image, -DBL_MAX, DBL_MAX);
429 cpl_mask_not(_mask);
430 cpl_image_set_bpm(_image, _mask);
431 }
432
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");
437
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");
442
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");
447
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");
452
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");
457
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 );
465 }
466
467 }
468
469
470 /*
471 * Update the property list
472 */
473
474 name = cx_string_create(tag);
475 cx_string_lower(name);
476 cx_string_append(name, ".fits");
477
478 _giraffe_frame_update_product(properties, cx_string_get(name), tag,
479 "REDUCED", NULL);
480
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);
487
488 cx_string_delete(name);
489
490
491 /*
492 * Write image to disk
493 */
494
495 if (save == TRUE) {
496
497 cxint status = 0;
498
499 status = giraffe_image_save(image, cpl_frame_get_filename(frame));
500
501 if (status) {
502 cpl_error_set(fctid, CPL_ERROR_FILE_IO);
503 cpl_frame_delete(frame);
504
505 return NULL;
506 }
507
508 }
509
510 return frame;
511
512}
513
514
540cpl_frame *
541giraffe_frame_create_table(GiTable *table, const cxchar *tag,
542 cpl_frame_level level, cxbool save,
543 cxbool update)
544{
545
546 const cxchar *fctid = "giraffe_frame_create_table";
547
548 cx_string *name;
549
550 cpl_frame *frame;
551
552 cpl_propertylist *properties;
553
554
555 if (table == NULL || tag == NULL) {
556 cpl_error_set(fctid, CPL_ERROR_NULL_INPUT);
557 return NULL;
558 }
559
560 properties = giraffe_table_get_properties(table);
561
562 if (properties == NULL) {
563 cpl_error_set(fctid, CPL_ERROR_DATA_NOT_FOUND);
564 return NULL;
565 }
566
567 if (update == TRUE) {
568
569 cpl_propertylist_update_string(properties, GIALIAS_EXTNAME, tag);
570 cpl_propertylist_set_comment(properties, GIALIAS_EXTNAME,
571 "FITS Extension name");
572
573 }
574
575
576 /*
577 * Update the property list
578 */
579
580 name = cx_string_create(tag);
581 cx_string_lower(name);
582 cx_string_append(name, ".fits");
583
584 _giraffe_frame_update_product(properties, cx_string_get(name), tag,
585 "REDUCED", NULL);
586
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);
593
594 cx_string_delete(name);
595
596
597 /*
598 * Write table to disk
599 */
600
601 if (save == TRUE) {
602
603 cxint status = 0;
604
605 status = giraffe_table_save(table, cpl_frame_get_filename(frame));
606
607 if (status) {
608 cpl_error_set(fctid, CPL_ERROR_FILE_IO);
609 cpl_frame_delete(frame);
610
611 return NULL;
612 }
613
614 }
615
616 return frame;
617
618}
619
620
642cxint
643giraffe_frame_attach_table(cpl_frame *frame, GiTable *table,
644 const cxchar *tag, cxbool update)
645{
646
647 const cxchar *fctid = "giraffe_frame_attach_table";
648
649
650 cxchar *name;
651
652 cxint status = 0;
653
654 cpl_propertylist *properties;
655
656 cpl_table *data;
657
658
659
660 if (frame == NULL || table == NULL || tag == NULL) {
661 cpl_error_set(fctid, CPL_ERROR_NULL_INPUT);
662 return 1;
663 }
664
665 name = (cxchar *)cpl_frame_get_filename(frame);
666
667 if (name == NULL) {
668 cpl_error_set(fctid, CPL_ERROR_ILLEGAL_INPUT);
669 return 1;
670 }
671
672 properties = giraffe_table_get_properties(table);
673
674 if (properties == NULL) {
675 cpl_error_set(fctid, CPL_ERROR_DATA_NOT_FOUND);
676 return 1;
677 }
678
679 data = giraffe_table_get(table);
680
681 if (data == NULL) {
682 cpl_error_set(fctid, CPL_ERROR_DATA_NOT_FOUND);
683 return 1;
684 }
685
686
687 if (update == TRUE) {
688
689 /* For future extensions */
690 ;
691
692 }
693
694
695 /*
696 * Update the property list
697 */
698
699 cpl_propertylist_update_string(properties, GIALIAS_EXTNAME, tag);
700 cpl_propertylist_set_comment(properties, GIALIAS_EXTNAME,
701 "FITS Extension name");
702
703
704 /*
705 * Write table to disk
706 */
707
708 status = cpl_table_save(data, NULL, properties, name, CPL_IO_EXTEND);
709
710 if (status != CPL_ERROR_NONE) {
711 cpl_error_set(fctid, CPL_ERROR_FILE_IO);
712 return 1;
713 }
714
715 return 0;
716
717}
718
719
736cpl_frame *
737giraffe_get_frame(const cpl_frameset *set, const cxchar *tag,
738 cpl_frame_group group)
739{
740
741 cpl_frameset* _set = (cpl_frameset*)set;
742
743 cpl_frame *frame = NULL;
744
745
746 if (_set == NULL || tag == NULL) {
747 return NULL;
748 }
749
750 frame = cpl_frameset_find(_set, tag);
751
752 if (group != CPL_FRAME_GROUP_NONE) {
753
754 while (frame != NULL && cpl_frame_get_group(frame) != group) {
755 frame = cpl_frameset_find(_set, NULL);
756 }
757
758 }
759
760 return frame;
761
762}
763
764
783cpl_frame *
784giraffe_get_slitgeometry(const cpl_frameset *set)
785{
786
787 cpl_frameset* _set = (cpl_frameset*)set;
788
789 cpl_frame *frame = NULL;
790
791
792 if (_set == 0) {
793 return 0;
794 }
795
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;
799
800 return frame;
801
802}
cpl_frame * giraffe_get_frame(const cpl_frameset *set, const cxchar *tag, cpl_frame_group group)
Get a frame from a frame set.
Definition: giframe.c:737
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.
Definition: giframe.c:237
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.
Definition: giframe.c:324
cpl_frame * giraffe_frame_create_image(GiImage *image, const cxchar *tag, cpl_frame_level level, cxbool save, cxbool update)
Create an image product frame.
Definition: giframe.c:393
cxint giraffe_frame_attach_table(cpl_frame *frame, GiTable *table, const cxchar *tag, cxbool update)
Attach a table to a product frame.
Definition: giframe.c:643
cpl_frame * giraffe_get_slitgeometry(const cpl_frameset *set)
Get the slit geometry frame from a frame set.
Definition: giframe.c:784
cpl_frame * giraffe_frame_create_table(GiTable *table, const cxchar *tag, cpl_frame_level level, cxbool save, cxbool update)
Create a table product frame.
Definition: giframe.c:541
cpl_image * giraffe_image_get(const GiImage *self)
Gets the image data.
Definition: giimage.c:218
cpl_propertylist * giraffe_image_get_properties(const GiImage *self)
Get the properties of an image.
Definition: giimage.c:282
cxint giraffe_image_save(GiImage *self, const cxchar *filename)
Write a Giraffe image to a file.
Definition: giimage.c:570
cxint giraffe_table_save(GiTable *self, const cxchar *filename)
Write a Giraffe table to a file.
Definition: gitable.c:636
cpl_table * giraffe_table_get(const GiTable *self)
Get the table data from a Giraffe table.
Definition: gitable.c:433
cpl_propertylist * giraffe_table_get_properties(const GiTable *self)
Gets the table properties.
Definition: gitable.c:489

This file is part of the GIRAFFE Pipeline Reference Manual 2.19.4.
Documentation copyright © 2002-2006 European Southern Observatory.
Generated on Thu Oct 9 2025 11:07:37 by doxygen 1.9.6 written by Dimitri van Heesch, © 1997-2004