X-shooter Pipeline Reference Manual 3.8.15
test-xsh_merge_ord.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: 2013-05-14 07:02:49 $
23 * $Revision: 1.22 $
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#include <xsh_data_pre.h>
45#include <xsh_error.h>
46#include <xsh_msg.h>
47#include <xsh_data_instrument.h>
48#include <xsh_data_rec.h>
49#include <xsh_data_spectrum.h>
50#include <xsh_drl.h>
51#include <xsh_pfits.h>
52#include <xsh_badpixelmap.h>
53#include <cpl.h>
54#include <math.h>
55#include <getopt.h>
56#include <xsh_ifu_defs.h>
57/*--------------------------------------------------------------------------
58 Defines
59 --------------------------------------------------------------------------*/
60
61#define MODULE_ID "XSH_MERGE_ORD"
62
63static void Help( void )
64{
65 puts( "Unitary test of xsh_merge_ord" ) ;
66 puts( "Usage: test_xsh_merge_ord [options] <input_files>" ) ;
67 puts( "Options" );
68 puts( " --method : WEIGHT or MEAN [MEAN]");
69 puts( " --slitlet=n> : Num of the slitlet" ) ;
70 puts( " --debug=<n> : Level of debug LOW | MEDIUM | HIGH [MEDIUM]" );
71 puts( "\nInput Files" ) ;
72 puts( " REC_ORDER_nD_*_arm_DRL frame" ) ;
73 TEST_END();
74}
75
76enum {
78} ;
79
80/*
81static struct option long_options[] = {
82 {"slitlet", required_argument, 0, SLITLET_OPT},
83 {"method", required_argument, 0, METHOD_OPT},
84 {"debug", required_argument, 0, DEBUG_OPT},
85 {0,0,0,0}
86};
87*/
88
89
90static void analyse_merge_ord( cpl_frame* spectrum_frame, xsh_instrument* instr);
91
92/*--------------------------------------------------------------------------
93 * Implementation
94 *--------------------------------------------------------------------------*/
95static void analyse_merge_ord( cpl_frame* spectrum_frame, xsh_instrument* instr)
96{
97 const char* spectrum_name = NULL;
98 xsh_spectrum *spectrum = NULL;
99 int i;
100 FILE* fulldatfile = NULL;
101 double* flux = NULL;
102
103 XSH_ASSURE_NOT_NULL( spectrum_frame);
104 XSH_ASSURE_NOT_NULL( instr);
105
106 check (spectrum_name = cpl_frame_get_filename( spectrum_frame));
107
108 xsh_msg("Spectrum frame : %s", spectrum_name);
109
110 check( spectrum = xsh_spectrum_load( spectrum_frame));
111 check( flux = xsh_spectrum_get_flux( spectrum));
112
113 fulldatfile = fopen("merge_ord.dat","w");
114 for(i=0; i< spectrum->size; i++){
115 fprintf( fulldatfile, "%f %f\n", spectrum->lambda_min+i*spectrum->lambda_step, flux[i]);
116 }
117 xsh_msg("Save file merge_ord.dat");
118 fclose( fulldatfile);
119
120 cleanup:
121 xsh_spectrum_free( &spectrum);
122 return;
123}
124
132int main( int argc, char **argv)
133{
134 /* Declarations */
135 int ret = 0 ;
138 int merge_par = 0 ;
139
140 cpl_frame* result = NULL;
141 char* rec_name = NULL;
142 cpl_frame* rec_frame = NULL;
143 cpl_propertylist *plist = NULL;
144 int slitlet = 0;
145 const int decode_bp=2147483647;
146 /* Initialize libraries */
148 cpl_msg_set_level(CPL_MSG_DEBUG);
150
151 if ( (argc - optind) >=1 ) {
152 rec_name = argv[optind];
153 }
154 else{
155 Help();
156 return 0;
157 }
158
159 /* Create frames */
160 TESTS_XSH_FRAME_CREATE( rec_frame, "REC_arm", rec_name);
161
162 check( plist = cpl_propertylist_load( rec_name, 0));
163
164 /* Create instrument structure and fill */
165 check( arm = xsh_pfits_get_arm( plist));
166
168
169 if ( arm == XSH_ARM_UVB){
171 cpl_frame_set_tag( rec_frame, "REC_UVB");
172 }
173 else if ( arm == XSH_ARM_VIS){
175 cpl_frame_set_tag( rec_frame, "REC_VIS");
176 }
177 else if ( arm == XSH_ARM_NIR){
179 cpl_frame_set_tag( rec_frame, "REC_NIR");
180 }
181 else{
182 xsh_msg( "invalid arm of %s",
184 }
186
187 if (slitlet == 0){
189 }
190 else{
192 }
193
194 xsh_msg("---Input Frames");
195 xsh_msg("Rec frame : %s", rec_name);
196 xsh_msg("---Parameters");
197 xsh_msg(" method WEIGTHED");
198
199 check( result = xsh_merge_ord_slitlet( rec_frame, instrument, merge_par, slitlet,"test"));
200
201 if (result != NULL){
203 }
204
205 cleanup:
206 if (cpl_error_get_code() != CPL_ERROR_NONE) {
207 xsh_error_dump(CPL_MSG_ERROR);
208 ret = 1;
209 }
211 xsh_free_propertylist( &plist);
212 xsh_free_frame( &rec_frame);
213 xsh_free_frame( &result);
214
215 TEST_END();
216 return ret;
217}
218
int main()
Unit test of xsh_bspline_interpol.
static void analyse_merge_ord(cpl_frame *spectrum_frame, xsh_instrument *instr)
static void Help(void)
#define MODULE_ID
@ METHOD_OPT
@ SLITLET_OPT
@ DEBUG_OPT
static xsh_instrument * instrument
xsh_spectrum * xsh_spectrum_load(cpl_frame *s1d_frame)
Load a 1D spectrum structure.
double * xsh_spectrum_get_flux(xsh_spectrum *s)
Get flux of spectrum.
void xsh_spectrum_free(xsh_spectrum **s)
free memory associated to an 1D spectrum
#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.
const char * xsh_instrument_arm_tostring(xsh_instrument *i)
Get the string associated with an arm.
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
void xsh_instrument_set_decode_bp(xsh_instrument *i, const int decode_bp)
Set bad pixel code.
cpl_frame * xsh_merge_ord_slitlet(cpl_frame *rec_frame, xsh_instrument *instrument, int merge_par, int slitlet, const char *rec_prefix)
Merge orders of the rectified frame using merge parameters.
#define xsh_msg(...)
Print a message on info level.
Definition: xsh_msg.h:121
XSH_ARM xsh_pfits_get_arm(const cpl_propertylist *plist)
Definition: xsh_pfits.c:270
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_propertylist(cpl_propertylist **p)
Deallocate a property list and set the pointer to NULL.
Definition: xsh_utils.c:2179
#define TESTS_XSH_FRAME_CREATE(frame, tag, name)
Definition: tests.h:123
#define TEST_END()
Definition: tests.h:111
#define TESTS_INIT(DRL_ID)
Definition: tests.h:105
@ XSH_ARM_UNDEFINED
@ XSH_ARM_UVB
@ XSH_ARM_NIR
@ XSH_ARM_VIS
@ XSH_MODE_SLIT
@ XSH_MODE_IFU
@ XSH_DEBUG_LEVEL_MEDIUM
Definition: xsh_utils.h:138