GIRAFFE Pipeline Reference Manual

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

This file is part of the GIRAFFE Pipeline Reference Manual 2.12.
Documentation copyright © 2002-2006 European Southern Observatory.
Generated on Mon Mar 24 2014 11:43:52 by doxygen 1.8.2 written by Dimitri van Heesch, © 1997-2004