X-shooter Pipeline Reference Manual 3.8.15
xsh_qc_handling.c
Go to the documentation of this file.
1/* $Id: xsh_qc_handling.c,v 1.9 2009-09-27 10:39:36 amodigli Exp $
2 *
3 * This file is part of the IRPLIB Package
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: amodigli $
23 * $Date: 2009-09-27 10:39:36 $
24 * $Revision: 1.9 $
25 */
26
27#ifdef HAVE_CONFIG_H
28#include <config.h>
29#endif
30
31/*-----------------------------------------------------------------------------
32 Includes
33 -----------------------------------------------------------------------------*/
34
35#include <cpl.h>
36
37#include <regex.h>
38#include <string.h>
39#include <strings.h>
40#include <sys/types.h>
41#include <fnmatch.h>
42#include <string.h>
43#include <assert.h>
44
45#include "xsh_msg.h"
46#include "xsh_qc_handling.h"
47#include "xsh_qc_definition.h"
48#include "xsh_pfits_qc.h"
49
50
51/*-----------------------------------------------------------------------------
52 Defines and Static variables
53 -----------------------------------------------------------------------------*/
54#define USE_REGEXP
55/*----------------------------------------------------------------------------*/
60/*----------------------------------------------------------------------------*/
61
64/*-----------------------------------------------------------------------------
65 Function codes
66 -----------------------------------------------------------------------------*/
67
68/* Functions */
69
71{
72 qc_description * current ;
73
74 for( current = (qc_description *)qc_table ; current->kw_name != NULL ;
75 current++ )
76 if ( strcmp( current->kw_name, kw ) == 0 ) return current ;
77 return NULL ;
78}
79
80
82{
83 qc_description * current ;
84#if defined(USE_REGEXP)
85 regex_t reg ;
86 int err ;
87
88 for( current = (qc_description *)qc_table ; current->kw_name != NULL ;
89 current++ ) {
90 if ( current->pro_catg == NULL ) continue ;
91 err = regcomp( &reg, current->pro_catg, REG_EXTENDED | REG_ICASE ) ;
92 if ( err != 0 ) continue ;
93 err = regexec( &reg, pro_catg, 0, 0, 0 ) ;
94 regfree( &reg ) ;
95 if ( err == 0 ) return current ;
96 }
97#else
98 for( current = (qc_description *)qc_table ; current->kw_name != NULL ;
99 current++ ) {
100 if ( current->pro_catg == NULL ) return current ;
101 if ( fnmatch( current->pro_catg, pro_catg, 0 ) == 0 )
102 return current ;
103 }
104#endif
105 return NULL ;
106}
107
109{
110 if ( ( pqc->kw_recipes != NULL &&
111 strstr( pqc->kw_recipes, instrument->recipe_id ) != NULL ) ||
112 ( pqc->kw_recipes_tbw != NULL &&
113 strstr( pqc->kw_recipes_tbw, instrument->recipe_id ) != NULL ) ) return 0 ;
114
115 return -1 ;
116}
117
119 qc_description *prev )
120{
121 qc_description * current ;
122
123 if ( prev == NULL ) {
124 current = (qc_description *)qc_table ;
125 }
126 else current = prev+1 ;
127
128 for( ; current->kw_name != NULL ; current++ ) {
129 if ( ((current->kw_recipes != NULL &&
130 strstr( current->kw_recipes, recipe ) != NULL) ||
131 (current->kw_recipes_tbw != NULL &&
132 strstr( current->kw_recipes_tbw, recipe ) != NULL)) &&
133 current->kw_type != CPL_TYPE_INVALID )
134 return current ;
135 }
136 return NULL ;
137}
138
139
141 qc_description *prev )
142{
143 qc_description * current ;
144
145 if ( prev == NULL ) {
146 current = (qc_description *)qc_table ;
147 }
148 else current = prev+1 ;
149
150 for( ; current->kw_name != NULL ; current++ ) {
151 if ( (current->kw_function != NULL &&
152 strstr( current->kw_function, function ) != NULL) )
153 return current ;
154 }
155 return NULL ;
156}
157
169int xsh_is_qc_for_arm( const char * arm, qc_description * pqc )
170{
171 if ( pqc->arms == NULL ||
172 strstr( pqc->arms, arm ) != NULL ) return 1 ;
173 return 0 ;
174}
175
186int xsh_is_qc_for_pro_catg( const char * pro_catg, qc_description * pqc )
187{
188#if defined(USE_REGEXP)
189 regex_t reg ;
190 int err ;
191
192 if ( pqc == NULL || pqc->pro_catg == NULL ) return 1 ;
193
194 err = regcomp( &reg, pqc->pro_catg, REG_EXTENDED | REG_ICASE ) ;
195 if ( err != 0 ) return 0 ;
196 err = regexec( &reg, pro_catg, 0, 0, 0 ) ;
197 regfree( &reg ) ;
198 if ( err == 0 ) return 1 ;
199
200#else
201 if( pqc->pro_catg == NULL || fnmatch( pqc->pro_catg, pro_catg, 0 ) == 0 ) {
202 if ( pqc->pro_catg == NULL ) {
203 xsh_msg_dbg_high( "++++++++ QC '%s' has a NULL PRO.CATG",
204 pqc->kw_name ) ;
205 }
206 else {
207 xsh_msg_dbg_high( "++++++++ QC '%s' found for PRO.CATG '%s'",
208 pqc->kw_name, pqc->pro_catg ) ;
209 }
210 return 1 ;
211 }
212#endif
213 return 0 ;
214}
215
216
217
225void xsh_add_qc_crh (xsh_pre* pre, int nbcrh, int nframes)
226{
227 double qc_crrate = 0.0;
228 float nbcr_avg ;
231 XSH_ASSURE_NOT_ILLEGAL(pre->pszx >0. && pre->pszy > 0);
233 /*
234 QC.CRRATE = avg_nb_of_crh_per_frame/(exposure_time*size_of_detector_in_cm2)
235 Nb of Cosmics per cm2 per second.
236 The whole size of the image in cm2 is given by pszx and pszy. These
237 values are in MICRONS.
238 */
239 xsh_msg_dbg_medium( "add_qc_crh - Exptime = %f", pre->exptime ) ;
240 qc_crrate =
241 (double) nbcrh / (((double) nframes) * (pre->exptime *
242 (pre->pszx / 10000.0) * (pre->pszy /10000.0) * pre->nx * pre->ny)) ;
243 nbcr_avg = nbcrh/nframes ;
244
245 /*
246 Now set QC KW
247 */
248 check( xsh_pfits_set_qc_crrate( pre->data_header,qc_crrate) ) ;
249 check( xsh_pfits_set_qc_ncrh( pre->data_header,nbcrh) ) ;
250 check( xsh_pfits_set_qc_ncrh_mean( pre->data_header,nbcr_avg) ) ;
251 /* Same thing for the qual header */
252 check( xsh_pfits_set_qc_crrate( pre->qual_header,qc_crrate) ) ;
253 check( xsh_pfits_set_qc_ncrh( pre->qual_header,nbcrh) ) ;
254 check( xsh_pfits_set_qc_ncrh_mean( pre->qual_header,nbcr_avg) ) ;
255 cleanup:
256 return ;
257}
258
259
260
261
262
263
static xsh_instrument * instrument
#define XSH_ASSURE_NOT_ILLEGAL(cond)
Definition: xsh_error.h:107
#define check(COMMAND)
Definition: xsh_error.h:71
#define XSH_ASSURE_NOT_NULL(pointer)
Definition: xsh_error.h:99
#define xsh_msg_dbg_medium(...)
Definition: xsh_msg.h:44
#define xsh_msg_dbg_high(...)
Definition: xsh_msg.h:40
void xsh_pfits_set_qc_ncrh_mean(cpl_propertylist *plist, const double value)
Write the QC.NCRH.AVG value.
Definition: xsh_pfits_qc.c:771
void xsh_pfits_set_qc_ncrh(cpl_propertylist *plist, int value)
Write the QC.NCRH value.
Definition: xsh_pfits_qc.c:754
void xsh_pfits_set_qc_crrate(cpl_propertylist *plist, double value)
Write the QC.CRRATE value.
Definition: xsh_pfits_qc.c:805
int xsh_is_qc_for_arm(const char *arm, qc_description *pqc)
qc_description * xsh_get_qc_desc_by_pro_catg(const char *pro_catg)
int xsh_qc_in_recipe(qc_description *pqc, xsh_instrument *instrument)
qc_description * xsh_get_qc_desc_by_recipe(const char *recipe, qc_description *prev)
int xsh_is_qc_for_pro_catg(const char *pro_catg, qc_description *pqc)
qc_description * xsh_get_qc_desc_by_function(char *function, qc_description *prev)
void xsh_add_qc_crh(xsh_pre *pre, int nbcrh, int nframes)
qc_description * xsh_get_qc_desc_by_kw(const char *kw)
const char * kw_recipes
const char * kw_recipes_tbw
const char * pro_catg
const char * arms
const char * kw_name
const char * kw_function
const char * recipe_id
float exptime
Definition: xsh_data_pre.h:92
float pszy
Definition: xsh_data_pre.h:88
cpl_propertylist * qual_header
Definition: xsh_data_pre.h:72
cpl_propertylist * data_header
Definition: xsh_data_pre.h:66
float pszx
Definition: xsh_data_pre.h:88
static const qc_description qc_table[]