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 <cxmemory.h>
25#include <cxmessages.h>
26#include <cxstring.h>
27#include <cxstrutils.h>
28
29#include <cpl_error.h>
30
31#include "gialias.h"
32#include "giutils.h"
33#include "giframe.h"
34#include "gierror.h"
35
36
46inline static cxint
47_giraffe_frame_update_product(cpl_propertylist* properties,
48 const cxchar* name, const cxchar* tag,
49 const cxchar* type, const cxchar* tech)
50{
51
52 cxchar* dpr_tech = NULL;
53
54 cxint science = -1;
55
56
57 if (properties == NULL) {
58 return -1;
59 }
60
61
62 /*
63 * Set default values
64 */
65
66 if (type == NULL) {
67 type = "REDUCED";
68 }
69
70 if (tech == NULL) {
71
72 if (cpl_propertylist_has(properties, GIALIAS_DPRTECH) == TRUE) {
73
74 const cxchar* s = cpl_propertylist_get_string(properties,
75 GIALIAS_DPRTECH);
76
77 dpr_tech = cx_strdup(s);
78
79 }
80 else if (cpl_propertylist_has(properties, GIALIAS_PROTECH) == TRUE) {
81
82 const cxchar* s = cpl_propertylist_get_string(properties,
83 GIALIAS_PROTECH);
84
85 dpr_tech = cx_strdup(s);
86
87 }
88
89 if ((dpr_tech == NULL) || (dpr_tech[0] == '\0')) {
90 tech = "UNDEFINED";
91 }
92 else {
93 tech = dpr_tech;
94 }
95
96 }
97
98
99 /*
100 * Check whether a scientific observation was processed.
101 */
102
103 if (cpl_propertylist_has(properties, GIALIAS_PROSCIENCE) == FALSE) {
104
105 if (cpl_propertylist_has(properties, GIALIAS_DPRCATG) == TRUE) {
106
107 const cxchar* s = cpl_propertylist_get_string(properties,
108 GIALIAS_DPRCATG);
109
110 if (s != NULL) {
111 science = (strncmp(s, "SCIENCE", 7) == 0) ? 1 : 0;
112 }
113
114 }
115
116 }
117
118
119 /*
120 * Clean frame properties
121 */
122
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);
130
131 cpl_propertylist_erase_regexp(properties, "ESO DPR.*", 0);
132
133
134 giraffe_error_push();
135
136 cpl_propertylist_update_string(properties, GIALIAS_INSTRUMENT,
137 "GIRAFFE");
138 cpl_propertylist_set_comment(properties, GIALIAS_INSTRUMENT,
139 "Name of the Instrument.");
140
141 cpl_propertylist_update_string(properties, GIALIAS_DATAMD5,
142 "Not computed");
143 cpl_propertylist_set_comment(properties, GIALIAS_DATAMD5,
144 "MD5 checksum");
145
146 if (name != NULL) {
147 cpl_propertylist_update_string(properties, GIALIAS_PIPEFILE, name);
148 cpl_propertylist_set_comment(properties, GIALIAS_PIPEFILE,
149 "Filename of data product");
150 }
151
152 if (cpl_error_get_code() != CPL_ERROR_NONE) {
153
154 cx_free(dpr_tech);
155 return 1;
156
157 }
158
159 giraffe_error_pop();
160
161
162 /*
163 * Set product keywords
164 */
165
166 giraffe_error_push();
167
168 cpl_propertylist_update_string(properties, GIALIAS_PRODID, PRODUCT_DID);
169 cpl_propertylist_set_comment(properties, GIALIAS_PRODID,
170 "Data dictionary for PRO");
171
172 if (tag != NULL) {
173
174 cpl_propertylist_update_string(properties, GIALIAS_PROCATG, tag);
175 cpl_propertylist_set_comment(properties, GIALIAS_PROCATG,
176 "Pipeline product category");
177
178 }
179
180 cpl_propertylist_update_string(properties, GIALIAS_PROTYPE, type);
181 cpl_propertylist_set_comment(properties, GIALIAS_PROTYPE,
182 "Product type");
183
184 cpl_propertylist_update_string(properties, GIALIAS_PROTECH, tech);
185 cpl_propertylist_set_comment(properties, GIALIAS_PROTECH,
186 "Observation technique");
187 cx_free(dpr_tech);
188 dpr_tech = NULL;
189
190 if (science != -1) {
191 cpl_propertylist_update_bool(properties, GIALIAS_PROSCIENCE, science);
192 cpl_propertylist_set_comment(properties, GIALIAS_PROSCIENCE,
193 "Scientific product if T");
194 }
195
196 if (cpl_error_get_code() != CPL_ERROR_NONE) {
197 return 1;
198 }
199
200 giraffe_error_pop();
201
202 return 0;
203
204}
205
206
238cpl_frame *
239giraffe_frame_create(const cxchar *tag, cpl_frame_level level,
240 const cpl_propertylist *properties, cxcptr object,
241 cxcptr data, GiFrameCreator creator)
242{
243
244 const cxchar *const fctid = "giraffe_frame_create";
245
246 cxint status = 0;
247
248 cx_string *name = NULL;
249
250 cpl_propertylist *p = NULL;
251
252 cpl_frame *frame = NULL;
253
254
255 if (properties == NULL || creator == NULL) {
256 cpl_error_set(fctid, CPL_ERROR_NULL_INPUT);
257 return NULL;
258 }
259
260 if (tag == NULL) {
261 cpl_error_set(fctid, CPL_ERROR_NULL_INPUT);
262 return NULL;
263 }
264
265 p = cpl_propertylist_duplicate(properties);
266 cx_assert(p != NULL);
267
268 /*
269 * Update the property list
270 */
271
272 name = cx_string_create(tag);
273 cx_assert(name != NULL);
274
275 cx_string_lower(name);
276 cx_string_append(name, ".fits");
277
278 _giraffe_frame_update_product(p, cx_string_get(name), tag, "REDUCED",
279 NULL);
280
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);
287
288 /*
289 * Write object to file
290 */
291
292 status = creator(object, p, cx_string_get(name), data);
293
294 if (status != 0) {
295 cpl_frame_delete(frame);
296 frame = NULL;
297 }
298
299 cx_string_delete(name);
300 cpl_propertylist_delete(p);
301
302 return frame;
303
304}
305
325cxint
326giraffe_frame_save(const cpl_frame* frame,
327 const cpl_propertylist* properties,
328 cxcptr object, cxcptr data,
329 GiFrameCreator creator)
330{
331
332 const cxchar* const fctid = "giraffe_frame_save";
333
334 cxint status = 0;
335
336 cpl_propertylist* p = NULL;
337
338
339 if (properties == NULL || creator == NULL) {
340 cpl_error_set(fctid, CPL_ERROR_NULL_INPUT);
341 return 127;
342 }
343
344
345 /*
346 * Create a local copy of the property list, to guarantee that
347 * the properties passed by the caller are not modified by the
348 * creator function.
349 */
350
351 p = cpl_propertylist_duplicate(properties);
352 cx_assert(p != NULL);
353
354
355 /*
356 * Write object to file
357 */
358
359 status = creator(object, p, cpl_frame_get_filename(frame), data);
360
361 cpl_propertylist_delete(p);
362 p = NULL;
363
364 return status;
365
366}
367
368
394cpl_frame *
395giraffe_frame_create_image(GiImage *image, const cxchar *tag,
396 cpl_frame_level level, cxbool save,
397 cxbool update)
398{
399 const cxchar *fctid = "giraffe_frame_create_image";
400
401 cx_string *name;
402
403 cpl_frame *frame;
404
405 cpl_propertylist *properties;
406
407
408 if (image == NULL || tag == NULL) {
409 cpl_error_set(fctid, CPL_ERROR_NULL_INPUT);
410 return NULL;
411 }
412
413 properties = giraffe_image_get_properties(image);
414
415 if (properties == NULL) {
416 cpl_error_set(fctid, CPL_ERROR_DATA_NOT_FOUND);
417 return NULL;
418 }
419
420 if (update == TRUE) {
421
422 cpl_image *_image = giraffe_image_get(image);
423
424 if (_image == NULL) {
425 cpl_error_set(fctid, CPL_ERROR_DATA_NOT_FOUND);
426 return NULL;
427 }
428
429 if (cpl_image_get_bpm_const(_image) == NULL) {
430 cpl_mask *_mask = cpl_mask_threshold_image_create(_image, -DBL_MAX, DBL_MAX);
431 cpl_mask_not(_mask);
432 cpl_image_set_bpm(_image, _mask);
433 }
434
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");
439
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");
444
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");
449
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");
454
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");
459
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 );
467 }
468
469 }
470
471
472 /*
473 * Update the property list
474 */
475
476 name = cx_string_create(tag);
477 cx_string_lower(name);
478 cx_string_append(name, ".fits");
479
480 _giraffe_frame_update_product(properties, cx_string_get(name), tag,
481 "REDUCED", NULL);
482
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);
489
490 cx_string_delete(name);
491
492
493 /*
494 * Write image to disk
495 */
496
497 if (save == TRUE) {
498
499 cxint status = 0;
500
501 status = giraffe_image_save(image, cpl_frame_get_filename(frame));
502
503 if (status) {
504 cpl_error_set(fctid, CPL_ERROR_FILE_IO);
505 cpl_frame_delete(frame);
506
507 return NULL;
508 }
509
510 }
511
512 return frame;
513
514}
515
516
542cpl_frame *
543giraffe_frame_create_table(GiTable *table, const cxchar *tag,
544 cpl_frame_level level, cxbool save,
545 cxbool update)
546{
547
548 const cxchar *fctid = "giraffe_frame_create_table";
549
550 cx_string *name;
551
552 cpl_frame *frame;
553
554 cpl_propertylist *properties;
555
556
557 if (table == NULL || tag == NULL) {
558 cpl_error_set(fctid, CPL_ERROR_NULL_INPUT);
559 return NULL;
560 }
561
562 properties = giraffe_table_get_properties(table);
563
564 if (properties == NULL) {
565 cpl_error_set(fctid, CPL_ERROR_DATA_NOT_FOUND);
566 return NULL;
567 }
568
569 if (update == TRUE) {
570
571 cpl_propertylist_update_string(properties, GIALIAS_EXTNAME, tag);
572 cpl_propertylist_set_comment(properties, GIALIAS_EXTNAME,
573 "FITS Extension name");
574
575 }
576
577
578 /*
579 * Update the property list
580 */
581
582 name = cx_string_create(tag);
583 cx_string_lower(name);
584 cx_string_append(name, ".fits");
585
586 _giraffe_frame_update_product(properties, cx_string_get(name), tag,
587 "REDUCED", NULL);
588
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);
595
596 cx_string_delete(name);
597
598
599 /*
600 * Write table to disk
601 */
602
603 if (save == TRUE) {
604
605 cxint status = 0;
606
607 status = giraffe_table_save(table, cpl_frame_get_filename(frame));
608
609 if (status) {
610 cpl_error_set(fctid, CPL_ERROR_FILE_IO);
611 cpl_frame_delete(frame);
612
613 return NULL;
614 }
615
616 }
617
618 return frame;
619
620}
621
622
644cxint
645giraffe_frame_attach_table(cpl_frame *frame, GiTable *table,
646 const cxchar *tag, cxbool update)
647{
648
649 const cxchar *fctid = "giraffe_frame_attach_table";
650
651
652 cxchar *name;
653
654 cxint status = 0;
655
656 cpl_propertylist *properties;
657
658 cpl_table *data;
659
660
661
662 if (frame == NULL || table == NULL || tag == NULL) {
663 cpl_error_set(fctid, CPL_ERROR_NULL_INPUT);
664 return 1;
665 }
666
667 name = (cxchar *)cpl_frame_get_filename(frame);
668
669 if (name == NULL) {
670 cpl_error_set(fctid, CPL_ERROR_ILLEGAL_INPUT);
671 return 1;
672 }
673
674 properties = giraffe_table_get_properties(table);
675
676 if (properties == NULL) {
677 cpl_error_set(fctid, CPL_ERROR_DATA_NOT_FOUND);
678 return 1;
679 }
680
681 data = giraffe_table_get(table);
682
683 if (data == NULL) {
684 cpl_error_set(fctid, CPL_ERROR_DATA_NOT_FOUND);
685 return 1;
686 }
687
688
689 if (update == TRUE) {
690
691 /* For future extensions */
692 ;
693
694 }
695
696
697 /*
698 * Update the property list
699 */
700
701 cpl_propertylist_update_string(properties, GIALIAS_EXTNAME, tag);
702 cpl_propertylist_set_comment(properties, GIALIAS_EXTNAME,
703 "FITS Extension name");
704
705
706 /*
707 * Write table to disk
708 */
709
710 status = cpl_table_save(data, NULL, properties, name, CPL_IO_EXTEND);
711
712 if (status != CPL_ERROR_NONE) {
713 cpl_error_set(fctid, CPL_ERROR_FILE_IO);
714 return 1;
715 }
716
717 return 0;
718
719}
720
721
738cpl_frame *
739giraffe_get_frame(const cpl_frameset *set, const cxchar *tag,
740 cpl_frame_group group)
741{
742
743 cpl_frameset* _set = (cpl_frameset*)set;
744
745 cpl_frame *frame = NULL;
746
747
748 if (_set == NULL || tag == NULL) {
749 return NULL;
750 }
751
752 frame = cpl_frameset_find(_set, tag);
753
754 if (group != CPL_FRAME_GROUP_NONE) {
755
756 while (frame != NULL && cpl_frame_get_group(frame) != group) {
757 frame = cpl_frameset_find(_set, NULL);
758 }
759
760 }
761
762 return frame;
763
764}
765
766
785cpl_frame *
786giraffe_get_slitgeometry(const cpl_frameset *set)
787{
788
789 cpl_frameset* _set = (cpl_frameset*)set;
790
791 cpl_frame *frame = NULL;
792
793
794 if (_set == 0) {
795 return 0;
796 }
797
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;
801
802 return frame;
803
804}
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:739
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:239
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:326
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:395
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:645
cpl_frame * giraffe_get_slitgeometry(const cpl_frameset *set)
Get the slit geometry frame from a frame set.
Definition: giframe.c:786
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:543
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 Fri Feb 6 2026 13:47:22 by doxygen 1.9.6 written by Dimitri van Heesch, © 1997-2004