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
423 if (_image == NULL) {
424 cpl_error_set(fctid, CPL_ERROR_DATA_NOT_FOUND);
425 return NULL;
426 }
427
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");
432
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");
437
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");
442
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");
447
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");
452
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
458 }
459
460
461 /*
462 * Update the property list
463 */
464
465 name = cx_string_create(tag);
466 cx_string_lower(name);
467 cx_string_append(name, ".fits");
468
469 _giraffe_frame_update_product(properties, cx_string_get(name), tag,
470 "REDUCED", NULL);
471
472 frame = cpl_frame_new();
473 cpl_frame_set_filename(frame, cx_string_get(name));
474 cpl_frame_set_tag(frame, tag);
475 cpl_frame_set_type(frame, CPL_FRAME_TYPE_IMAGE);
476 cpl_frame_set_group(frame, CPL_FRAME_GROUP_PRODUCT);
477 cpl_frame_set_level(frame, level);
478
479 cx_string_delete(name);
480
481
482 /*
483 * Write image to disk
484 */
485
486 if (save == TRUE) {
487
488 cxint status = 0;
489
490 status = giraffe_image_save(image, cpl_frame_get_filename(frame));
491
492 if (status) {
493 cpl_error_set(fctid, CPL_ERROR_FILE_IO);
494 cpl_frame_delete(frame);
495
496 return NULL;
497 }
498
499 }
500
501 return frame;
502
503}
504
505
531cpl_frame *
532giraffe_frame_create_table(GiTable *table, const cxchar *tag,
533 cpl_frame_level level, cxbool save,
534 cxbool update)
535{
536
537 const cxchar *fctid = "giraffe_frame_create_table";
538
539 cx_string *name;
540
541 cpl_frame *frame;
542
543 cpl_propertylist *properties;
544
545
546 if (table == NULL || tag == NULL) {
547 cpl_error_set(fctid, CPL_ERROR_NULL_INPUT);
548 return NULL;
549 }
550
551 properties = giraffe_table_get_properties(table);
552
553 if (properties == NULL) {
554 cpl_error_set(fctid, CPL_ERROR_DATA_NOT_FOUND);
555 return NULL;
556 }
557
558 if (update == TRUE) {
559
560 cpl_propertylist_update_string(properties, GIALIAS_EXTNAME, tag);
561 cpl_propertylist_set_comment(properties, GIALIAS_EXTNAME,
562 "FITS Extension name");
563
564 }
565
566
567 /*
568 * Update the property list
569 */
570
571 name = cx_string_create(tag);
572 cx_string_lower(name);
573 cx_string_append(name, ".fits");
574
575 _giraffe_frame_update_product(properties, cx_string_get(name), tag,
576 "REDUCED", NULL);
577
578 frame = cpl_frame_new();
579 cpl_frame_set_filename(frame, cx_string_get(name));
580 cpl_frame_set_tag(frame, tag);
581 cpl_frame_set_type(frame, CPL_FRAME_TYPE_TABLE);
582 cpl_frame_set_group(frame, CPL_FRAME_GROUP_PRODUCT);
583 cpl_frame_set_level(frame, level);
584
585 cx_string_delete(name);
586
587
588 /*
589 * Write table to disk
590 */
591
592 if (save == TRUE) {
593
594 cxint status = 0;
595
596 status = giraffe_table_save(table, cpl_frame_get_filename(frame));
597
598 if (status) {
599 cpl_error_set(fctid, CPL_ERROR_FILE_IO);
600 cpl_frame_delete(frame);
601
602 return NULL;
603 }
604
605 }
606
607 return frame;
608
609}
610
611
633cxint
634giraffe_frame_attach_table(cpl_frame *frame, GiTable *table,
635 const cxchar *tag, cxbool update)
636{
637
638 const cxchar *fctid = "giraffe_frame_attach_table";
639
640
641 cxchar *name;
642
643 cxint status = 0;
644
645 cpl_propertylist *properties;
646
647 cpl_table *data;
648
649
650
651 if (frame == NULL || table == NULL || tag == NULL) {
652 cpl_error_set(fctid, CPL_ERROR_NULL_INPUT);
653 return 1;
654 }
655
656 name = (cxchar *)cpl_frame_get_filename(frame);
657
658 if (name == NULL) {
659 cpl_error_set(fctid, CPL_ERROR_ILLEGAL_INPUT);
660 return 1;
661 }
662
663 properties = giraffe_table_get_properties(table);
664
665 if (properties == NULL) {
666 cpl_error_set(fctid, CPL_ERROR_DATA_NOT_FOUND);
667 return 1;
668 }
669
670 data = giraffe_table_get(table);
671
672 if (data == NULL) {
673 cpl_error_set(fctid, CPL_ERROR_DATA_NOT_FOUND);
674 return 1;
675 }
676
677
678 if (update == TRUE) {
679
680 /* For future extensions */
681 ;
682
683 }
684
685
686 /*
687 * Update the property list
688 */
689
690 cpl_propertylist_update_string(properties, GIALIAS_EXTNAME, tag);
691 cpl_propertylist_set_comment(properties, GIALIAS_EXTNAME,
692 "FITS Extension name");
693
694
695 /*
696 * Write table to disk
697 */
698
699 status = cpl_table_save(data, NULL, properties, name, CPL_IO_EXTEND);
700
701 if (status != CPL_ERROR_NONE) {
702 cpl_error_set(fctid, CPL_ERROR_FILE_IO);
703 return 1;
704 }
705
706 return 0;
707
708}
709
710
727cpl_frame *
728giraffe_get_frame(const cpl_frameset *set, const cxchar *tag,
729 cpl_frame_group group)
730{
731
732 cpl_frameset* _set = (cpl_frameset*)set;
733
734 cpl_frame *frame = NULL;
735
736
737 if (_set == NULL || tag == NULL) {
738 return NULL;
739 }
740
741 frame = cpl_frameset_find(_set, tag);
742
743 if (group != CPL_FRAME_GROUP_NONE) {
744
745 while (frame != NULL && cpl_frame_get_group(frame) != group) {
746 frame = cpl_frameset_find(_set, NULL);
747 }
748
749 }
750
751 return frame;
752
753}
754
755
774cpl_frame *
775giraffe_get_slitgeometry(const cpl_frameset *set)
776{
777
778 cpl_frameset* _set = (cpl_frameset*)set;
779
780 cpl_frame *frame = NULL;
781
782
783 if (_set == 0) {
784 return 0;
785 }
786
787 frame = cpl_frameset_find(_set, GIFRAME_SLITSETUP);
788 frame = frame == 0 ? cpl_frameset_find(_set, GIFRAME_SLITMASTER) : frame;
789 frame = frame == 0 ? cpl_frameset_find(_set, GIFRAME_SLITGEOMETRY) : frame;
790
791 return frame;
792
793}
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:728
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:634
cpl_frame * giraffe_get_slitgeometry(const cpl_frameset *set)
Get the slit geometry frame from a frame set.
Definition: giframe.c:775
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:532
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.16.12.
Documentation copyright © 2002-2006 European Southern Observatory.
Generated on Thu Feb 13 2025 15:21:30 by doxygen 1.9.6 written by Dimitri van Heesch, © 1997-2004