IIINSTRUMENT Pipeline Reference Manual 4.6.2
visir_dfs.c
1/* $Id: visir_dfs.c,v 1.79 2013-05-14 12:59:23 jtaylor Exp $
2 *
3 * This file is part of the VISIR Pipeline
4 * Copyright (C) 2002,2003 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 02111-1307 USA
19 */
20
21/*
22 * $Author: jtaylor $
23 * $Date: 2013-05-14 12:59:23 $
24 * $Revision: 1.79 $
25 * $Name: not supported by cvs2svn $
26 */
27
28#ifdef HAVE_CONFIG_H
29#include <config.h>
30#endif
31
32/*-----------------------------------------------------------------------------
33 Includes
34 -----------------------------------------------------------------------------*/
35
36#include "irplib_utils.h"
37#include "visir_utils.h"
38#include "visir_pfits.h"
39#include "visir_dfs.h"
40#include <cpl.h>
41
42#include <stdarg.h>
43#include <stdio.h>
44#include <string.h>
45#include <math.h>
46
47
48/*-----------------------------------------------------------------------------
49 Private function prototypes
50 -----------------------------------------------------------------------------*/
51
52static const char * visir_dfs_find_tag_from_dpr(const char *, const char *,
53 const char *);
54
55/*----------------------------------------------------------------------------*/
61/*----------------------------------------------------------------------------*/
62
65/*----------------------------------------------------------------------------*/
71/*----------------------------------------------------------------------------*/
72int visir_dfs_set_groups(cpl_frameset * set)
73{
74 int i = 0;
75
76
77 skip_if (0);
78
79 /* Loop on frames */
80 FOR_EACH_FRAMESET(frame, set) {
81 const char * tag = cpl_frame_get_tag(frame);
82
83 skip_if (0);
84
85 /* RAW frames */
86 if (tag == NULL) cpl_msg_warning(cpl_func,
87 "Frame %d has no tag", i);
88 else if (!strcmp(tag, VISIR_IMG_ACHRO_RAW) ||
89 !strcmp(tag, VISIR_IMG_COMBINE_CN) ||
90 !strcmp(tag, VISIR_IMG_COMBINE_CN_BURST) ||
91 !strcmp(tag, VISIR_IMG_COMBINE_CNJ) ||
92 !strcmp(tag, VISIR_IMG_COMBINE_CNJ_BURST) ||
93 !strcmp(tag, VISIR_IMG_COMBINE_CJ) ||
94 !strcmp(tag, VISIR_IMG_COMBINE_NJ) ||
95 !strcmp(tag, VISIR_IMG_COMBINE_DJ) ||
96 !strcmp(tag, VISIR_IMG_CAL_PHOT) ||
97 !strcmp(tag, VISIR_IMG_CAL_PHOT_PP) ||
98 !strcmp(tag, VISIR_IMG_CAL_PHOT_BURST) ||
99 !strcmp(tag, VISIR_IMG_CAL_OBJ) ||
100 !strcmp(tag, VISIR_IMG_CAL_OBJ_BURST) ||
101 !strcmp(tag, VISIR_IMG_FF_RAW) ||
102 !strcmp(tag, VISIR_IMG_TECH_FF_RAW) ||
103 !strcmp(tag, VISIR_IMG_FOCFWHM_RAW) ||
104 !strcmp(tag, VISIR_IMG_ILLU_RAW) ||
105 !strcmp(tag, VISIR_IMG_PFOV_BIN) ||
106 !strcmp(tag, VISIR_IMG_PFOV_TEL) ||
107 !strcmp(tag, VISIR_IMG_PHOT_RAW) ||
108 !strcmp(tag, VISIR_IMG_PHOT_COMBINED_PROCATG) ||
109 !strcmp(tag, VISIR_IMG_COADDED_IMG) ||
110 !strcmp(tag, VISIR_IMG_PSF_RAW) ||
111 !strcmp(tag, VISIR_IMG_TRANS_RAW) ||
112 !strcmp(tag, VISIR_IMG_DARK_RAW) ||
113 !strcmp(tag, VISIR_ACQ_CNJ) ||
114 !strcmp(tag, VISIR_SPC_OBS_ECH_RAW) ||
115 !strcmp(tag, VISIR_SPC_OBS_RAW) ||
116 !strcmp(tag, VISIR_SPC_OBS_PP) ||
117 !strcmp(tag, VISIR_SPC_OBS_HR_RAW) ||
118 !strcmp(tag, VISIR_SPC_PHOT_RAW) ||
119 !strcmp(tag, VISIR_SPC_PHOT_PP) ||
120 !strcmp(tag, VISIR_SPC_PHOT_ECH_RAW) ||
121 !strcmp(tag, VISIR_SPC_PHOT_ECH_PP) ||
122 !strcmp(tag, VISIR_SPC_OBS_ECH_PP) ||
123 !strcmp(tag, VISIR_SPC_WCAL_ECH_RAW) ||
124 !strcmp(tag, VISIR_SPC_WCAL_RAW) ||
125 !strcmp(tag, VISIR_SPC_FF_RAW) ||
126 !strcmp(tag, VISIR_SPC_TECH_FF_RAW) ||
127 !strcmp(tag, VISIR_SPC_DARK_RAW) ||
128 !strcmp(tag, VISIR_SAM_CAL_N_RAW) ||
129 !strcmp(tag, VISIR_SAM_CAL_CN_RAW) ||
130 !strcmp(tag, VISIR_SAM_CAL_NJ_RAW) ||
131 !strcmp(tag, VISIR_SAM_CAL_CNJ_RAW) ||
132 !strcmp(tag, VISIR_CORO_CAL_CNJ_RAW) ||
133 !strcmp(tag, VISIR_SAM_OBS_N_RAW) ||
134 !strcmp(tag, VISIR_SAM_OBS_CN_RAW) ||
135 !strcmp(tag, VISIR_SAM_OBS_NJ_RAW) ||
136 !strcmp(tag, VISIR_SAM_OBS_CNJ_RAW) ||
137 !strcmp(tag, VISIR_CORO_OBS_CNJ_RAW) ||
138 !strcmp(tag, VISIR_UTIL_QC_PROCATG) ||
139 !strcmp(tag, VISIR_UTIL_REPACK_MEAN_PROCATG) ||
140 !strcmp(tag, VISIR_UTIL_REPACK_MEAN_A_PROCATG) ||
141 !strcmp(tag, VISIR_UTIL_REPACK_MEAN_B_PROCATG) ||
142 !strcmp(tag, VISIR_UTIL_REPACK_MEAN_A_ON_PROCATG) ||
143 !strcmp(tag, VISIR_UTIL_REPACK_MEAN_A_OFF_PROCATG) ||
144 !strcmp(tag, VISIR_UTIL_REPACK_MEAN_B_ON_PROCATG) ||
145 !strcmp(tag, VISIR_UTIL_REPACK_MEAN_B_OFF_PROCATG) ||
146 !strcmp(tag, VISIR_UTIL_REPACK_A_ON_PROCATG) ||
147 !strcmp(tag, VISIR_UTIL_REPACK_A_OFF_PROCATG) ||
148 !strcmp(tag, VISIR_UTIL_REPACK_B_ON_PROCATG) ||
149 !strcmp(tag, VISIR_UTIL_REPACK_B_OFF_PROCATG) ||
150 !strcmp(tag, VISIR_UTIL_DETECT_SHIFT_PROCATG) ||
151 !strcmp(tag, VISIR_UTIL_DETECT_SHIFT_TEMPLATE_PROCATG) ||
152 !strcmp(tag, VISIR_UTIL_INPUTS_RAW) ||
153 !strcmp(tag, VISIR_UTIL_CORRECTED) ||
154 !strcmp(tag, VISIR_UTIL_NODDED) ||
155 !strcmp(tag, VISIR_UTIL_CONVERT_RAW) ||
156 !strcmp(tag, VISIR_UTIL_CONVERT_TAB) ||
157 !strcmp(tag, VISIR_UTIL_CONVERT_INV) ||
158 !strcmp(tag, VISIR_UTIL_CONVERT_POS_AUX) ||
159 !strcmp(tag, VISIR_UTIL_CONVERT_INV_AUX) ||
160 !strcmp(tag, VISIR_UTIL_WEIGHT2ERROR) ||
161 !strcmp(tag, VISIR_IMG_BURST) ||
162 !strcmp(tag, VISIR_UTIL_DATA) ||
163 !strcmp(tag, VISIR_UTIL_UNDISTORT_RAW) ||
164 !strcmp(tag, VISIR_UTIL_REPACK_RAW))
165 cpl_frame_set_group(frame, CPL_FRAME_GROUP_RAW);
166 /* CALIB frames */
167 else if (!strcmp(tag, VISIR_CALIB_FLAT) ||
168 !strcmp(tag, VISIR_CALIB_BPM) ||
169 !strcmp(tag, VISIR_CALIB_STATIC_MASK) ||
170 !strcmp(tag, VISIR_CALIB_STDSTAR_IMG) ||
171 !strcmp(tag, VISIR_CALIB_STDSTAR_SPC) ||
172 !strcmp(tag, VISIR_CALIB_LINES_SPC) ||
173 !strcmp(tag, VISIR_CALIB_LIN) ||
174 !strcmp(tag, VISIR_SPC_OBS_SKYFRAME) ||
175 !strcmp(tag, VISIR_UTIL_WEIGHT2ERROR_PROCATG) ||
176 !strcmp(tag, VISIR_IMG_CLIPPED_MAP_PROCATG) ||
177 !strcmp(tag, VISIR_UTIL_WEIGHT2ERROR) ||
178 !strcmp(tag, VISIR_UTIL_WEIGHT_MAP) ||
179 !strcmp(tag, VISIR_UTIL_ERROR_MAP) ||
180 !strcmp(tag, VISIR_UTIL_VARIANCE_MAP) ||
181 !strcmp(tag, VISIR_SPC_CAT_ASCII) ||
182 !strcmp(tag, VISIR_IMG_LINES_ASCII) ||
183 !strcmp(tag, VISIR_SPC_LINES_ASCII) ||
184 !strcmp(tag, VISIR_SPC_QEFF_ASCII) ||
185 !strcmp(tag, VISIR_CALIB_QEFF_SPC))
186 cpl_frame_set_group(frame, CPL_FRAME_GROUP_CALIB);
187 else cpl_msg_warning(cpl_func,
188 "Frame %d has unknown tag: %s", i, tag);
189 }
190
191 end_skip;
192
193 if (cpl_error_get_code())
194 cpl_msg_error(cpl_func, "Could not identify RAW and CALIB frames "
195 "(after processing %d frames)", i);
196
197 return cpl_error_get_code();
198}
199
200const char *
201visir_dfs_output_catg(const char * inpcatg, const char * pipecatg)
202{
203 int phot = 0;
204 if (!strcmp(pipecatg, VISIR_IMG_PHOT_ONEBEAM_PROCATG) ||
205 !strcmp(pipecatg, VISIR_IMG_PHOT_COMBINED_PROCATG)) {
206 phot = 1;
207 }
208 if (!strcmp(inpcatg, VISIR_ACQ_CNJ)) {
209 if (phot) {
210 return "ACQ_IMG_PHOT_COMBINED";
211 }
212 else {
213 return "ACQ_IMG_OBJ_COMBINED";
214 }
215 }
216 else if (!strcmp(inpcatg, VISIR_IMG_CAL_PHOT_BURST)) {
217 return VISIR_IMG_PHOT_COMBINED_PROCATG"_BURST";
218 }
219 else if (!strcmp(inpcatg, VISIR_IMG_CAL_OBJ_BURST) ||
220 !strcmp(inpcatg, VISIR_IMG_COMBINE_CN_BURST) ||
221 !strcmp(inpcatg, VISIR_IMG_COMBINE_CNJ_BURST)) {
222 return VISIR_IMG_OBJ_COMBINED_PROCATG"_BURST";
223 }
224 return pipecatg;
225}
226
227/*----------------------------------------------------------------------------*/
233/*----------------------------------------------------------------------------*/
234cpl_error_code visir_dfs_check_framelist_tag(const irplib_framelist * self)
235{
236
237 if (cpl_error_get_code()) return cpl_error_get_code();
238
239 cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT);
240
241 return irplib_dfs_check_framelist_tag(self, visir_dfs_find_tag_from_dpr);
242
243}
244
247/*----------------------------------------------------------------------------*/
256/*----------------------------------------------------------------------------*/
257static const char * visir_dfs_find_tag_from_dpr(const char * catg,
258 const char * type,
259 const char * tech)
260{
261 const char * docatg = NULL;
262
263
264 if (cpl_error_get_code()) return NULL;
265
266 cpl_ensure(catg != NULL, CPL_ERROR_NULL_INPUT, NULL);
267 cpl_ensure(type != NULL, CPL_ERROR_NULL_INPUT, NULL);
268 cpl_ensure(tech != NULL, CPL_ERROR_NULL_INPUT, NULL);
269
270#include "visir_dfs_dpr.h"
271
272 return docatg;
273
274}
275
276/*----------------------------------------------------------------------------*/
284/*----------------------------------------------------------------------------*/
285void visir_dfs_update_header(cpl_propertylist* plist)
286{
287 const char *radecsys_hdr = "RADECSYS";
288 const char *radesys_hdr = "RADESYS";
289 const char *hdrver_hdr = "HDRVER";
290 const char *func = "update_header";
291 char *radec_str = NULL;
292 char *comment_str = NULL;
293 if (plist) {
294 // Remove HDRVER
295 cpl_propertylist_erase(plist, hdrver_hdr);
296 // Translate RADECSYS to RADESYS.
297 radec_str = cpl_strdup(cpl_propertylist_get_string(plist, radecsys_hdr));
298 comment_str = cpl_strdup(cpl_propertylist_get_comment(plist, radecsys_hdr));
299 cpl_propertylist_erase(plist, radecsys_hdr);
300 cpl_propertylist_update_string(plist, radesys_hdr, radec_str);
301 cpl_propertylist_set_comment(plist, radesys_hdr, comment_str);
302 if (cpl_error_get_code() != CPL_ERROR_NONE) {
303 /* Only give a warning if the header exists but there was a problem
304 * in translating it */
305 if (radec_str) {
306 cpl_msg_warning(func, "Error in updating header: %s",
307 cpl_error_get_message());
308 }
309 }
310 cpl_free(radec_str);
311 cpl_free(comment_str);
312 // Don't want any errors to propagate up from here
313 cpl_error_reset();
314 }
315}
cpl_error_code irplib_dfs_check_framelist_tag(const irplib_framelist *self, const char *(*pfind)(const char *, const char *, const char *))
Check the tags in a frameset (group raw only)
Definition: irplib_pfits.c:225
cpl_error_code visir_dfs_check_framelist_tag(const irplib_framelist *self)
Check the tags in a frameset (group raw only)
Definition: visir_dfs.c:234
int visir_dfs_set_groups(cpl_frameset *set)
Set the group as RAW or CALIB in a frameset.
Definition: visir_dfs.c:72