FORS Pipeline Reference Manual  5.0.9
fors_header.c
1 /* $Id: fors_header.c,v 1.1 2012-11-05 17:11:56 cgarcia Exp $
2  *
3  * This file is part of the FORS Library
4  * Copyright (C) 2002-2010 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: cgarcia $
23  * $Date: 2012-11-05 17:11:56 $
24  * $Revision: 1.1 $
25  * $Name: not supported by cvs2svn $
26  */
27 
28 #ifdef HAVE_CONFIG_H
29 #include <config.h>
30 #endif
31 
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <ctype.h>
35 #include <string.h>
36 #include <unistd.h>
37 #include <math.h>
38 
39 #include <cpl.h>
40 #include <fors_utils.h>
41 #include <fors_paf.h>
42 #include <fors_dfs.h>
43 #include <fors_qc.h>
44 
45 #define DICT_LINE_LENGTH (80)
46 #define MAX_PAF_NAME_LENGTH (80)
47 #define PAF_ROOT_NAME "qc"
48 
78 cpl_error_code fors_header_write_string(cpl_propertylist *header,
79  const char *name, const char *value,
80  const char *comment)
81 {
82  char *header_name;
83  int i;
84 
85  header_name = cpl_malloc((strlen(name) + 6) * sizeof(char *));
86 
87  strcpy(header_name, "ESO ");
88  strcat(header_name, name);
89 
90  for (i = 0; header_name[i] != '\0'; i++)
91  if (header_name[i] == '.')
92  header_name[i] = ' ';
93 
94  if (cpl_propertylist_update_string(header, header_name, value)) {
95  cpl_free(header_name);
96  cpl_error_set_where(cpl_func);
97  return cpl_error_get_code();
98  }
99 
100  cpl_propertylist_set_comment(header, header_name, comment);
101 
102  cpl_free(header_name);
103 
104  return CPL_ERROR_NONE;
105 }
106 
131 cpl_error_code fors_header_write_double(cpl_propertylist *header, double value,
132  const char *name, const char *unit,
133  const char *comment)
134 {
135 
136  char *header_name;
137  int i;
138  char *allComment;
139 
140  allComment = cpl_malloc(81 * sizeof(char *));
141 
142  if (unit)
143  snprintf(allComment, 80, "%s [%s]", comment, unit);
144  else
145  snprintf(allComment, 80, "%s", comment);
146 
147 
148  header_name = cpl_malloc((strlen(name) + 6) * sizeof(char *));
149 
150  strcpy(header_name, "ESO ");
151  strcat(header_name, name);
152 
153  for (i = 0; header_name[i] != '\0'; i++)
154  if (header_name[i] == '.')
155  header_name[i] = ' ';
156 
157  if (cpl_propertylist_update_double(header, header_name, value)) {
158  cpl_free(header_name);
159  cpl_error_set_where(cpl_func);
160  return cpl_error_get_code();
161  }
162 
163  cpl_propertylist_set_comment(header, header_name, allComment);
164 
165  cpl_free(header_name);
166  cpl_free(allComment);
167 
168  return CPL_ERROR_NONE;
169 
170 }
171 
172 
173 cpl_error_code fors_header_write_int(cpl_propertylist *header, int value,
174  const char *name, const char *unit,
175  const char *comment)
176 {
177 
178  char *header_name;
179  int i;
180  char *allComment;
181 
182  allComment = cpl_malloc(81 * sizeof(char *));
183 
184  if (unit)
185  snprintf(allComment, 80, "%s [%s]", comment, unit);
186  else
187  snprintf(allComment, 80, "%s", comment);
188 
189  header_name = cpl_malloc((strlen(name) + 6) * sizeof(char *));
190 
191  strcpy(header_name, "ESO ");
192  strcat(header_name, name);
193 
194  for (i = 0; header_name[i] != '\0'; i++)
195  if (header_name[i] == '.')
196  header_name[i] = ' ';
197 
198  if (cpl_propertylist_update_int(header, header_name, value)) {
199  cpl_free(header_name);
200  cpl_error_set_where(cpl_func);
201  return cpl_error_get_code();
202  }
203 
204  cpl_propertylist_set_comment(header, header_name, allComment);
205 
206  cpl_free(header_name);
207  cpl_free(allComment);
208 
209  return CPL_ERROR_NONE;
210 
211 }
212 
cpl_error_code fors_header_write_double(cpl_propertylist *header, double value, const char *name, const char *unit, const char *comment)
Write an integer value to the active QC1 PAF object and to a header.
Definition: fors_header.c:131
cpl_error_code fors_header_write_string(cpl_propertylist *header, const char *name, const char *value, const char *comment)
Write a string value to the active QC1 PAF object and to a header.
Definition: fors_header.c:78