FORS Pipeline Reference Manual 4.9.20
|
00001 /* $Id: fors_header.c,v 1.1 2012/11/05 17:11:56 cgarcia Exp $ 00002 * 00003 * This file is part of the FORS Library 00004 * Copyright (C) 2002-2010 European Southern Observatory 00005 * 00006 * This program is free software; you can redistribute it and/or modify 00007 * it under the terms of the GNU General Public License as published by 00008 * the Free Software Foundation; either version 2 of the License, or 00009 * (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software 00018 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00019 */ 00020 00021 /* 00022 * $Author: cgarcia $ 00023 * $Date: 2012/11/05 17:11:56 $ 00024 * $Revision: 1.1 $ 00025 * $Name: fors-4_9_20 $ 00026 */ 00027 00028 #ifdef HAVE_CONFIG_H 00029 #include <config.h> 00030 #endif 00031 00032 #include <stdio.h> 00033 #include <stdlib.h> 00034 #include <ctype.h> 00035 #include <string.h> 00036 #include <unistd.h> 00037 #include <math.h> 00038 00039 #include <cpl.h> 00040 #include <fors_utils.h> 00041 #include <fors_paf.h> 00042 #include <fors_dfs.h> 00043 #include <fors_qc.h> 00044 00045 #define DICT_LINE_LENGTH (80) 00046 #define MAX_PAF_NAME_LENGTH (80) 00047 #define PAF_ROOT_NAME "qc" 00048 00078 cpl_error_code fors_header_write_string(cpl_propertylist *header, 00079 const char *name, const char *value, 00080 const char *comment) 00081 { 00082 char *header_name; 00083 int i; 00084 00085 header_name = cpl_malloc((strlen(name) + 6) * sizeof(char *)); 00086 00087 strcpy(header_name, "ESO "); 00088 strcat(header_name, name); 00089 00090 for (i = 0; header_name[i] != '\0'; i++) 00091 if (header_name[i] == '.') 00092 header_name[i] = ' '; 00093 00094 if (cpl_propertylist_update_string(header, header_name, value)) { 00095 cpl_free(header_name); 00096 cpl_error_set_where(cpl_func); 00097 return cpl_error_get_code(); 00098 } 00099 00100 cpl_propertylist_set_comment(header, header_name, comment); 00101 00102 cpl_free(header_name); 00103 00104 return CPL_ERROR_NONE; 00105 } 00106 00131 cpl_error_code fors_header_write_double(cpl_propertylist *header, double value, 00132 const char *name, const char *unit, 00133 const char *comment) 00134 { 00135 00136 char *header_name; 00137 int i; 00138 char *allComment; 00139 00140 allComment = cpl_malloc(81 * sizeof(char *)); 00141 00142 if (unit) 00143 snprintf(allComment, 80, "%s [%s]", comment, unit); 00144 else 00145 snprintf(allComment, 80, "%s", comment); 00146 00147 00148 header_name = cpl_malloc((strlen(name) + 6) * sizeof(char *)); 00149 00150 strcpy(header_name, "ESO "); 00151 strcat(header_name, name); 00152 00153 for (i = 0; header_name[i] != '\0'; i++) 00154 if (header_name[i] == '.') 00155 header_name[i] = ' '; 00156 00157 if (cpl_propertylist_update_double(header, header_name, value)) { 00158 cpl_free(header_name); 00159 cpl_error_set_where(cpl_func); 00160 return cpl_error_get_code(); 00161 } 00162 00163 cpl_propertylist_set_comment(header, header_name, allComment); 00164 00165 cpl_free(header_name); 00166 cpl_free(allComment); 00167 00168 return CPL_ERROR_NONE; 00169 00170 } 00171 00172 00173 cpl_error_code fors_header_write_int(cpl_propertylist *header, int value, 00174 const char *name, const char *unit, 00175 const char *comment) 00176 { 00177 00178 char *header_name; 00179 int i; 00180 char *allComment; 00181 00182 allComment = cpl_malloc(81 * sizeof(char *)); 00183 00184 if (unit) 00185 snprintf(allComment, 80, "%s [%s]", comment, unit); 00186 else 00187 snprintf(allComment, 80, "%s", comment); 00188 00189 header_name = cpl_malloc((strlen(name) + 6) * sizeof(char *)); 00190 00191 strcpy(header_name, "ESO "); 00192 strcat(header_name, name); 00193 00194 for (i = 0; header_name[i] != '\0'; i++) 00195 if (header_name[i] == '.') 00196 header_name[i] = ' '; 00197 00198 if (cpl_propertylist_update_int(header, header_name, value)) { 00199 cpl_free(header_name); 00200 cpl_error_set_where(cpl_func); 00201 return cpl_error_get_code(); 00202 } 00203 00204 cpl_propertylist_set_comment(header, header_name, allComment); 00205 00206 cpl_free(header_name); 00207 cpl_free(allComment); 00208 00209 return CPL_ERROR_NONE; 00210 00211 } 00212