X-shooter Pipeline Reference Manual 3.8.15
test-xsh_resid_tab.c
Go to the documentation of this file.
1/* *
2 * This file is part of the ESO X-shooter Pipeline *
3 * Copyright (C) 2006 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/*
21 * $Author: amodigli $
22 * $Date: 2012-08-23 12:00:20 $
23 * $Revision: 1.15 $
24 */
25
26#ifdef HAVE_CONFIG_H
27# include <config.h>
28#endif
29
30/*-------------------------------------------------------------------------*/
36/*-------------------------------------------------------------------------*/
39/*--------------------------------------------------------------------------
40 Includes
41 --------------------------------------------------------------------------*/
42
43#include <tests.h>
44
45#include <xsh_data_pre.h>
46#include <xsh_error.h>
47#include <xsh_msg.h>
48#include <xsh_data_instrument.h>
49#include <xsh_data_resid_tab.h>
50#include <xsh_drl.h>
51#include <xsh_pfits.h>
52
53#include <cpl.h>
54#include <math.h>
55
56#include <getopt.h>
57
58/*--------------------------------------------------------------------------
59 Defines
60 --------------------------------------------------------------------------*/
61
62#define MODULE_ID "XSH_RESID_TAB"
63#define SYNTAX "Test the residual tab\n"\
64 "use : ./the_xsh_resid_tab RESID_TAB \n"\
65 "RESID_TAB => the residual table\n"
66
67
68/*--------------------------------------------------------------------------
69 Implementation
70 --------------------------------------------------------------------------*/
71
79int main( int argc, char **argv)
80{
81 /* Declarations */
82 int ret = 0 ;
84
85 char* resid_tab_name = NULL;
86 const char* extracted_tab_name = "redid_not_flagged.fits";
87 cpl_frame* resid_tab_frame = NULL;
88 xsh_resid_tab* resid_tab = NULL;
89 int resid_tab_size = 0;
90 cpl_table* tab_flagged=NULL;
91 cpl_table* tab_extract=NULL;
92 cpl_propertylist* plist=NULL;
93 int i = 0;
94 FILE* resid_tab_the_file = NULL;
95
96 /* Initialize libraries */
98
99 cpl_msg_set_level(CPL_MSG_DEBUG);
101
102 /* Analyse parameters */
103 if (argc > 1){
104 resid_tab_name = argv[1];
105 }
106 else{
107 printf(SYNTAX);
108 TEST_END();
109 return 0;
110 }
111
112 /* Create instrument structure and fill */
116
117
118 XSH_ASSURE_NOT_NULL( resid_tab_name);
119 tab_flagged=cpl_table_load(resid_tab_name,1,0);
120 plist=cpl_propertylist_load(resid_tab_name,0);
121 cpl_table_and_selected_int(tab_flagged,"Flag",CPL_EQUAL_TO,0);
122 tab_extract=cpl_table_extract_selected(tab_flagged);
123 cpl_table_erase_column(tab_extract,"Flag");
124 cpl_table_save(tab_extract,plist,NULL,extracted_tab_name,CPL_IO_DEFAULT);
125
126 /* Create frames */
127 resid_tab_frame = cpl_frame_new();
128 cpl_frame_set_filename( resid_tab_frame, extracted_tab_name) ;
129 cpl_frame_set_level( resid_tab_frame, CPL_FRAME_LEVEL_TEMPORARY);
130 cpl_frame_set_group( resid_tab_frame, CPL_FRAME_GROUP_RAW ) ;
131
132 check( resid_tab = xsh_resid_tab_load( resid_tab_frame));
133 check( resid_tab_size = xsh_resid_tab_get_size( resid_tab));
134
135 /* Create DS9 REGION FILE */
136 xsh_msg("Save residual tab in RESID_TAB.reg");
137 resid_tab_the_file = fopen( "RESID_TAB.reg", "w");
138
139 fprintf( resid_tab_the_file, "# Region file format: DS9 version 4.0\n"\
140 "global color=red font=\"helvetica 10 normal\""\
141 "select=1 highlite=1 edit=1 move=1 delete=1 include=1 fixed=0 "\
142 "source\nimage\n");
143 fprintf( resid_tab_the_file, "# RED the_x the_y (pixels)\n"\
144 "# MAGENTA corr_x corr_y (pixels)\n"\
145 "# GREEN gauss_x gauss_y (pixels)\n"\
146 "# BLUE poly_x poly_y (pixels)\n");
147
149 xsh_msg("Residual tab compute from POLYNOMIAL");
150 }
151 else{
152 xsh_msg("Residual tab compute from PHYSICAL MODEL");
153 }
154 for( i=0; i<resid_tab_size; i++){
155 double the_x, the_y;
156 double corr_x, corr_y;
157 double gauss_x, gauss_y;
158 double poly_x, poly_y;
159 double lambda;
160
161 lambda = resid_tab->lambda[i];
162 the_x = resid_tab->thpre_x[i];
163 the_y = resid_tab->thpre_y[i];
164 corr_x = resid_tab->thcor_x[i];
165 corr_y = resid_tab->thcor_y[i];
166 gauss_x = resid_tab->xgauss[i];
167 gauss_y = resid_tab->ygauss[i];
169 poly_x = resid_tab->xpoly[i];
170 poly_y = resid_tab->ypoly[i];
171 }
172 else{
173 poly_x = resid_tab->thanneal_x[i];
174 poly_y = resid_tab->thanneal_y[i];
175 }
176 fprintf( resid_tab_the_file, "point(%f,%f) #point=cross color=red text={THE %.3f} font="\
177 "\"helvetica 10 normal\"\n", the_x, the_y, lambda);
178 fprintf( resid_tab_the_file, "point(%f,%f) #point=diamond color=magenta font="\
179 "\"helvetica 4 normal\"\n", corr_x, corr_y);
180 fprintf( resid_tab_the_file, "point(%f,%f) #point=circle color=green font="\
181 "\"helvetica 4 normal\"\n", gauss_x, gauss_y);
182 fprintf( resid_tab_the_file, "point(%f,%f) #point=x color=blue font="\
183 "\"helvetica 4 normal\"\n", poly_x, poly_y);
184 }
185 fclose( resid_tab_the_file);
186 xsh_msg( "Save residual tab in RESID_TAB.dat");
187 check( xsh_resid_tab_log( resid_tab, "RESID_TAB.dat"));
188
189 cleanup:
191 xsh_free_frame (&resid_tab_frame);
192 xsh_resid_tab_free( &resid_tab);
193 xsh_free_table(&tab_extract);
194 xsh_free_propertylist(&plist);
195
196 if (cpl_error_get_code() != CPL_ERROR_NONE) {
197 xsh_error_dump(CPL_MSG_ERROR);
198 ret = 1;
199 }
200 TEST_END();
201 return ret ;
202}
203
int main()
Unit test of xsh_bspline_interpol.
static xsh_instrument * instrument
#define MODULE_ID
#define SYNTAX
void xsh_resid_tab_free(xsh_resid_tab **resid)
Free memory associated to a resid_tab.
xsh_resid_tab * xsh_resid_tab_load(cpl_frame *resid_tab_frame)
Load a residual tab from a frame.
void xsh_resid_tab_log(xsh_resid_tab *resid, const char *filename)
Log the residual tab in a ASCII file
#define check(COMMAND)
Definition: xsh_error.h:71
#define xsh_error_dump(level)
Definition: xsh_error.h:92
#define XSH_ASSURE_NOT_NULL(pointer)
Definition: xsh_error.h:99
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
void xsh_free_frame(cpl_frame **f)
Deallocate a frame and set the pointer to NULL.
Definition: xsh_utils.c:2269
int xsh_debug_level_set(int level)
set debug level
Definition: xsh_utils.c:3125
void xsh_free_table(cpl_table **t)
Deallocate a table and set the pointer to NULL.
Definition: xsh_utils.c:2133
void xsh_free_propertylist(cpl_propertylist **p)
Deallocate a property list and set the pointer to NULL.
Definition: xsh_utils.c:2179
#define TEST_END()
Definition: tests.h:111
#define TESTS_INIT(DRL_ID)
Definition: tests.h:105
@ XSH_ARM_VIS
@ XSH_MODE_IFU
int xsh_resid_tab_get_size(xsh_resid_tab *resid)
#define XSH_DETECT_ARCLINES_TYPE_POLY
Definition: xsh_drl.h:225
@ XSH_DEBUG_LEVEL_MEDIUM
Definition: xsh_utils.h:138