X-shooter Pipeline Reference Manual 3.8.15
test-xsh_paf_save.c
Go to the documentation of this file.
1/* *
2 * This file is part of the ESO IRPLIB package *
3 * Copyright (C) 2004,2005 European Southern Observatory *
4 * *
5 * This library is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the Free Software *
17 * Foundation, 51 Franklin St, Fifth Floor, Boston, MA 02111-1307 USA *
18 * */
19
20#ifdef HAVE_CONFIG_H
21# include <config.h>
22#endif
23
24/*-----------------------------------------------------------------------------
25 Includes
26 -----------------------------------------------------------------------------*/
27#include <cpl.h>
28#include <xsh_data_pre.h>
29#include <xsh_error.h>
30#include <xsh_msg.h>
31#include <xsh_data_instrument.h>
32#include <xsh_dfs.h>
33#include <xsh_pfits.h>
34#include <math.h>
35#include <string.h>
36#include <xsh_paf_save.h>
37#include <xsh_qc_handling.h>
38#include <tests.h>
39
40/*-----------------------------------------------------------------------------
41 Defines
42 -----------------------------------------------------------------------------*/
43#define MODULE_ID "XSH_PAF_SAVE"
44
45/*----------------------------------------------------------------------------*/
50/*----------------------------------------------------------------------------*/
51
52/*----------------------------------------------------------------------------*/
56/*----------------------------------------------------------------------------*/
57
58static void with_dots( char *to, const char *from, char *filename )
59{
60 int k ;
61
62 k = sprintf( to, "grep --quiet '" ) ;
63 to += k ;
64
65 if ( strncmp( from, "ESO ", 4 ) == 0 )
66 from += 4 ;
67
68 for( ; *from != '\0' ; from++, to++ )
69 if ( *from == ' ' ) *to = '.' ;
70 else *to = *from ;
71 *to++ = '\'' ;
72 *to++ = ' ' ;
73 *to = '\0' ;
74 strcat( to, filename ) ;
75}
76
77int main(void)
78{
79 cpl_propertylist *qc = NULL;
80 char * filename = NULL;
81 qc_description *pqc ;
82 int ret=0;
83 xsh_instrument * iiinstrument = NULL;
84
87
88 /* Create PAF file */
89 {
90 const char * const rrrecipe = "xsh_mbias";
91 const char * pro_catg = NULL ;
92
93
94 iiinstrument = xsh_instrument_new() ;
95 xsh_instrument_set_arm( iiinstrument, XSH_ARM_UVB ) ;
97 pro_catg = "MASTER_BIAS_UVB" ;
98
99 filename = xsh_stringcat_any(rrrecipe, XSH_PAF_SAVE_EXTENSION,
100 (void*)NULL) ;
101
102 assure( xsh_paf_save(iiinstrument, rrrecipe,
103 NULL,
104 filename, pro_catg)
105 == CPL_ERROR_NULL_INPUT, CPL_ERROR_ILLEGAL_OUTPUT,
106 "Failed to fail on NULL input");
108
109 qc = cpl_propertylist_new();
110
111 /* Add QC parameters of xsh_mbias recipe */
112 pqc = NULL ;
113 while ( (pqc = xsh_get_qc_desc_by_recipe( rrrecipe, pqc )) != NULL ) {
114 //xsh_msg( "QC Parameter: %s", pqc->kw_name ) ;
115 switch( pqc->kw_type ) {
116 case CPL_TYPE_INT:
117 cpl_propertylist_append_int (qc, pqc->kw_name, 0 ) ;
118 break ;
119 case CPL_TYPE_DOUBLE:
120 cpl_propertylist_append_double(qc, pqc->kw_name, 1.0 ) ;
121 break ;
122 case CPL_TYPE_CHAR:
123 cpl_propertylist_append_char(qc, pqc->kw_name, 'x' ) ;
124 break ;
125 case CPL_TYPE_FLOAT:
126 cpl_propertylist_append_float(qc, pqc->kw_name, 0.1 ) ;
127 break ;
128 case CPL_TYPE_STRING:
129 cpl_propertylist_append_string(qc, pqc->kw_name, "ABCDEF" ) ;
130 break ;
131 default:
132 xsh_msg( "Other Types not handled" ) ;
133 break ;
134 }
135 if ( pqc->kw_help != NULL )
136 cpl_propertylist_set_comment (qc, pqc->kw_name, pqc->kw_help ) ;
137 }
138
139 assure( xsh_paf_save(iiinstrument, rrrecipe,
140 qc,
141 filename, pro_catg)
142 == CPL_ERROR_NONE, cpl_error_get_code(),
143 "PAF file creation failed");
144 /* Check that PAF contains all the relevant QC */
145 pqc = NULL ;
146 while ( (pqc = xsh_get_qc_desc_by_recipe( rrrecipe, pqc )) != NULL ) {
147 char cmd[128] ;
148
149 memset( cmd, 0, 128 ) ;
150 with_dots( cmd, pqc->kw_name, filename ) ;
151 assure( system( cmd ) == 0, CPL_ERROR_ILLEGAL_INPUT,
152 "QC parameter '%s' NOT in PAF",
153 pqc->kw_name ) ;
154 }
155 }
156
157 cleanup:
158 xsh_instrument_free( &iiinstrument);
160 cpl_free(filename);
162 TEST_END();
163
164 if (cpl_error_get_code() != CPL_ERROR_NONE) {
165 xsh_error_dump(CPL_MSG_ERROR);
166 ret = 1;
167 }
168 return ret;
169}
#define assure(CONDITION, ERROR_CODE,...)
Definition: xsh_error.h:54
#define xsh_error_dump(level)
Definition: xsh_error.h:92
#define xsh_error_reset()
Definition: xsh_error.h:87
void xsh_instrument_set_mode(xsh_instrument *i, XSH_MODE mode)
Set a mode on instrument structure.
void xsh_instrument_set_arm(xsh_instrument *i, XSH_ARM arm)
Set an arm on instrument structure.
void xsh_instrument_free(xsh_instrument **instrument)
free an instrument structure
xsh_instrument * xsh_instrument_new(void)
create new instrument structure
#define xsh_msg(...)
Print a message on info level.
Definition: xsh_msg.h:121
cpl_error_code xsh_paf_save(const xsh_instrument *instrument, const char *recipe, const cpl_propertylist *paflist, const char *filename, const char *pro_catg)
Create a new PAF file.
Definition: xsh_paf_save.c:104
qc_description * xsh_get_qc_desc_by_recipe(const char *recipe, qc_description *prev)
char * xsh_stringcat_any(const char *s,...)
Concatenate an arbitrary number of strings.
Definition: xsh_utils.c:1925
void xsh_free_propertylist(cpl_propertylist **p)
Deallocate a property list and set the pointer to NULL.
Definition: xsh_utils.c:2179
const char * kw_help
const char * kw_name
static void with_dots(char *to, const char *from, char *filename)
Unit tests of PAF saving.
int main(void)
#define MODULE_ID
#define TESTS_CLEAN_WORKSPACE(DRL_ID)
Definition: tests.h:139
#define TESTS_INIT_WORKSPACE(DRL_ID)
Definition: tests.h:133
#define TEST_END()
Definition: tests.h:111
#define TESTS_INIT(DRL_ID)
Definition: tests.h:105
@ XSH_ARM_UVB
@ XSH_MODE_UNDEFINED
#define XSH_PAF_SAVE_EXTENSION
Definition: xsh_paf_save.h:36