X-shooter Pipeline Reference Manual 3.8.15
test-xsh_model.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-12-07 16:51:34 $
23 * $Revision: 1.4 $
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 <xsh_model_io.h>
54#include <xsh_model_kernel.h>
55#include <cpl.h>
56#include <math.h>
57
58#include <getopt.h>
59
60/*--------------------------------------------------------------------------
61 Defines
62 --------------------------------------------------------------------------*/
63
64#define MODULE_ID "XSH_MODEL"
65#define SYNTAX "Create a the tab from model\n"\
66 "use : ./test_xsh_model SOF\n"\
67 "SOF => model config and arclist\n"
68
69
70/*--------------------------------------------------------------------------
71 Implementation
72 --------------------------------------------------------------------------*/
73
81int main( int argc, char **argv)
82{
83 int ret=0;
85 const char *sof_name = NULL;
86 const char *model_config_name = NULL;
87 const char *lines_list_name = NULL;
88 cpl_frame *model_config_frame = NULL;
89 cpl_frame *lines_list_frame = NULL;
90 cpl_frame *the_frame = NULL;
91 cpl_frameset *set = NULL;
92 cpl_frameset *raws = NULL;
93 cpl_frameset *calib = NULL;
94
95 FILE* sof_file = NULL;
96 char sof_line[200];
97 xsh_xs_3 config_model;
98
99 /* Initialize libraries */
101 cpl_msg_set_level(CPL_MSG_DEBUG);
103
104 /* Analyse parameters */
105 if (argc > 1){
106 sof_name = argv[1];
107 }
108 else{
109 printf(SYNTAX);
110 return 0;
111 }
112
113 XSH_ASSURE_NOT_NULL( sof_name);
114
115 /* Create frameset from sof */
116 check( set = cpl_frameset_new());
117 sof_file = fopen( sof_name, "r");
118 while ( fgets( sof_line, 200, sof_file)){
119 char raw_name[200];
120 char raw_tag[200];
121 cpl_frame *raw_frame = NULL;
122 /* Note: update the string format (the %__s) if raw_name(tag) changes size.
123 * Remember: field width must equal 1 less than sizeof(raw_name(tag)). */
124 sscanf( sof_line, "%199s %199s", raw_name, raw_tag);
125 check( raw_frame = cpl_frame_new());
126 check( cpl_frame_set_filename( raw_frame, raw_name));
127 check( cpl_frame_set_tag( raw_frame, raw_tag));
128 check( cpl_frameset_insert(set, raw_frame));
129 }
130
131
132 /* Validate frame set */
134 XSH_NEW_FRAMESET( raws);
135 XSH_NEW_FRAMESET( calib);
136 check( xsh_dfs_split_in_group( set, raws, calib));
137
138 check( lines_list_frame = xsh_find_arc_line_list( calib, instrument));
139 check( model_config_frame = xsh_find_model_config_tab( calib, instrument));
140
141 check( lines_list_name = cpl_frame_get_filename( lines_list_frame));
142 check( model_config_name = cpl_frame_get_filename( model_config_frame));
143
144 xsh_msg(" Find model %s\n", model_config_name);
145 xsh_msg(" Find lines list %s\n", lines_list_name);
146
147 check( xsh_model_config_load_best( model_config_frame, &config_model));
148 the_frame = xsh_model_THE_create( &config_model, instrument,
149 lines_list_name, 9, 1.4, "THE.fits");
150 cleanup:
151 xsh_free_frame(&the_frame);
152 if(sof_file!=NULL) {
153 fclose( sof_file);
154 }
155 if (cpl_error_get_code() != CPL_ERROR_NONE) {
156 xsh_error_dump(CPL_MSG_ERROR);
157 return 1;
158 }
159 else return ret ;
160}
161
int main()
Unit test of xsh_bspline_interpol.
static xsh_instrument * instrument
#define MODULE_ID
#define SYNTAX
#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
cpl_error_code xsh_model_config_load_best(cpl_frame *config_frame, xsh_xs_3 *p_xs_3)
Load the config model table and fill the struct.
Definition: xsh_model_io.c:174
cpl_frame * xsh_model_THE_create(xsh_xs_3 *p_xs_3, xsh_instrument *instr, const char *line_list, int num_ph, double sep_ph, const char *THE_filename)
Compute the THE table (centroid for each feature in lamp spectrum)
#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
#define TESTS_INIT(DRL_ID)
Definition: tests.h:105
void xsh_dfs_split_in_group(cpl_frameset *input, cpl_frameset *raws, cpl_frameset *calib)
split input sof in groups: raw and calib
Definition: xsh_dfs.c:1202
xsh_instrument * xsh_dfs_set_groups(cpl_frameset *set)
Set the group as RAW or CALIB in a frameset and return the instrument detected.
Definition: xsh_dfs.c:1046
cpl_frame * xsh_find_model_config_tab(cpl_frameset *frames, xsh_instrument *instr)
Find a model configuration table frame.
Definition: xsh_dfs.c:3957
cpl_frame * xsh_find_arc_line_list(cpl_frameset *frames, xsh_instrument *instr)
Find an arc line list frame.
Definition: xsh_dfs.c:3908
@ XSH_DEBUG_LEVEL_MEDIUM
Definition: xsh_utils.h:138
#define XSH_NEW_FRAMESET(POINTER)
Definition: xsh_utils.h:84