X-shooter Pipeline Reference Manual 3.8.15
test-xsh_mark_tell.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: 2011-09-14 11:37:12 $
23 * $Revision: 1.3 $
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_error.h>
46#include <xsh_msg.h>
47#include <xsh_drl.h>
48#include <cpl.h>
49#include <math.h>
50#include <xsh_data_spectrum.h>
51#include <string.h>
52#include <getopt.h>
53
54/*--------------------------------------------------------------------------
55 Defines
56 --------------------------------------------------------------------------*/
57
58#define MODULE_ID "XSH_MARK_TELL"
59
60enum {
62} ;
63
64static struct option long_options[] = {
65 {"help", 0, 0, HELP_OPT},
66 {0, 0, 0, 0}
67};
68
69static void Help( void )
70{
71 puts( "Unitary test of xsh_mark_tell");
72 puts( "Usage: test_xsh_mark_tell [options] S1D TELLLIST");
73
74 puts( "Options" ) ;
75 puts( " --help : What you see" ) ;
76 puts( "\nInput Files" ) ;
77 puts( "S1D : 1D spectrum file");
78 puts( "TELL_MASK : telluric mask");
79 TEST_END();
80}
81
82
83static void HandleOptions( int argc, char **argv)
84{
85 int opt ;
86 int option_index = 0;
87
88 while (( opt = getopt_long (argc, argv,
89 "help",
90 long_options, &option_index)) != EOF ){
91
92 switch ( opt ) {
93 default:
94 Help(); exit(-1);
95 }
96 }
97 return;
98}
99
100static void analyse_spectrum( cpl_frame* spectrum_frame);
101
102/*--------------------------------------------------------------------------
103 * Implementation
104 *--------------------------------------------------------------------------*/
105static void analyse_spectrum( cpl_frame* spectrum_frame)
106{
107 const char* spectrum_name = NULL;
108 xsh_spectrum *spectrum = NULL;
109 int i;
110 FILE* fulldatfile = NULL;
111 double* flux = NULL;
112 int *qual = NULL;
113
114 XSH_ASSURE_NOT_NULL( spectrum_frame);
115
116 check (spectrum_name = cpl_frame_get_filename( spectrum_frame));
117
118 xsh_msg("Spectrum frame : %s", spectrum_name);
119
120 check( spectrum = xsh_spectrum_load( spectrum_frame));
121 check( flux = xsh_spectrum_get_flux( spectrum));
122 check( qual = xsh_spectrum_get_qual( spectrum));
123
124 fulldatfile = fopen("s1d_with_tell.dat","w");
125 for(i=0; i< spectrum->size; i++){
126 fprintf( fulldatfile, "%f %f %d\n", spectrum->lambda_min+i*spectrum->lambda_step, flux[i],
127 qual[i]);
128 }
129 xsh_msg("Save file s1d_with_tell.dat");
130 fclose( fulldatfile);
131
132 cleanup:
133 xsh_spectrum_free( &spectrum);
134 return;
135}
136
137int main( int argc, char **argv)
138{
139 /* Declarations */
140 int ret = 0 ;
141 const char *s1d_name = NULL;
142 cpl_frame *s1d_frame = NULL;
143 const char *mask_name = NULL;
144 cpl_frame *mask_frame = NULL;
145
146 /* Initialize libraries */
148
149 cpl_msg_set_level(CPL_MSG_DEBUG);
151
152 /* Analyse parameters */
153 HandleOptions( argc, argv);
154
155 if ( (argc - optind) > 1 ) {
156 s1d_name = argv[optind];
157 mask_name = argv[optind+1];
158 }
159 else {
160 Help();
161 exit( 0);
162 }
163
164 xsh_msg("---Input Files");
165 xsh_msg("S1D File : %s ", s1d_name);
166 xsh_msg("Tell mask File : %s ", mask_name);
167
168 TESTS_XSH_FRAME_CREATE( s1d_frame, "S1D", s1d_name);
169 TESTS_XSH_FRAME_CREATE( mask_frame, "TELL_MASK", mask_name);
170
171 check( xsh_mark_tell( s1d_frame, mask_frame));
172
173 analyse_spectrum( s1d_frame);
174 cleanup:
175 if (cpl_error_get_code() != CPL_ERROR_NONE) {
176 xsh_error_dump(CPL_MSG_ERROR);
177 ret=1;
178 }
179 xsh_free_frame( &s1d_frame);
180 xsh_free_frame( &mask_frame);
181 TEST_END();
182 return ret ;
183}
184
185
int main()
Unit test of xsh_bspline_interpol.
static void analyse_spectrum(cpl_frame *spectrum_frame)
#define MODULE_ID
static struct option long_options[]
@ HELP_OPT
void xsh_mark_tell(cpl_frame *s1d_frame, cpl_frame *tellmask_frame)
Mark telluric in spectrum.
xsh_spectrum * xsh_spectrum_load(cpl_frame *s1d_frame)
Load a 1D spectrum structure.
int * xsh_spectrum_get_qual(xsh_spectrum *s)
Get qual of spectrum.
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
#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
static void HandleOptions(int argc, char **argv)
static void Help(void)
#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_DEBUG_LEVEL_MEDIUM
Definition: xsh_utils.h:138