X-shooter Pipeline Reference Manual 3.8.15
test-xsh_divide_flat.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: rhaigron $
22 * $Date: 2010-04-20 11:48:53 $
23 * $Revision: 1.8 $
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_drl.h>
50#include <xsh_pfits.h>
51#include <xsh_badpixelmap.h>
52#include <cpl.h>
53#include <math.h>
54#include <getopt.h>
55
56/*--------------------------------------------------------------------------
57 Defines
58 --------------------------------------------------------------------------*/
59
60#define MODULE_ID "XSH_DIVIDE_FLAT"
61
62
63enum {
65};
66
67static struct option long_options[] = {
68 {"debug", required_argument, 0, DEBUG_OPT},
69 {"help", 0, 0, HELP_OPT},
70 {0, 0, 0, 0}
71};
72
73
74static void Help( void )
75{
76 puts( "Unitary test of xsh_divide_flat");
77 puts( "Usage: test_xsh_divide_flat [options] <input_files>");
78
79 puts( "Options" ) ;
80 puts( " --debug=<n> : Level of debug LOW | MEDIUM | HIGH [MEDIUM]" );
81 puts( " --help : What you see" ) ;
82 puts( "\nInput Files" ) ;
83 puts( "The input files argument MUST be in this order:" ) ;
84 puts( " 1. Science frame in PRE format" ) ;
85 puts( " 2. SOF [MASTER_FLAT]");
86 TEST_END();
87 exit(0);
88}
89
90static void HandleOptions( int argc, char **argv)
91{
92 int opt ;
93 int option_index = 0;
94 while (( opt = getopt_long (argc, argv, "debug:help",
95 long_options, &option_index)) != EOF ){
96
97 switch ( opt ) {
98 case DEBUG_OPT:
99 if ( strcmp( optarg, "LOW")==0){
101 }
102 else if ( strcmp( optarg, "HIGH")==0){
104 }
105 break;
106 case HELP_OPT:
107 Help();
108 break;
109 default:
110 break;
111 }
112 }
113 return;
114}
115/*--------------------------------------------------------------------------
116 Implementation
117 --------------------------------------------------------------------------*/
118
126int main( int argc, char **argv)
127{
128 /* Declarations */
129 int ret = 0 ;
131 cpl_frame* result = NULL;
132 char *sci_name = NULL;
133 char *sof_name = NULL;
134 cpl_frame *sci_frame = NULL;
135 cpl_frame *flat_frame = NULL;
136 cpl_frameset *set = NULL;
137
138 /* Initialize libraries */
140
141 cpl_msg_set_level(CPL_MSG_DEBUG);
143
144
145 HandleOptions( argc, argv);
146
147 if ( (argc-optind) >= 2 ) {
148 sci_name = argv[optind];
149 sof_name = argv[optind+1];
150
151 /* Create frameset from sof */
152 check( set = sof_to_frameset( sof_name));
153
154 /* Validate frame set */
156 check( flat_frame = xsh_find_master_flat( set, instrument));
157 TESTS_XSH_FRAME_CREATE( sci_frame, "OBJECT_SLIT_STARE_arm",
158 sci_name);
159 }
160 else{
161 Help();
162 }
163
164 /* Create instrument structure and fill */
165 xsh_msg("PRE : %s", cpl_frame_get_filename( sci_frame));
166 xsh_msg("MASTER_FLAT : %s", cpl_frame_get_filename( flat_frame));
167
169
170 check( result = xsh_divide_flat( sci_frame, flat_frame, "DIVIDE_FLAT",
171 instrument));
172 xsh_msg("Save DIVIDE_FLAT.fits frame");
173
174 cleanup:
175 xsh_free_frame( &sci_frame);
176 xsh_free_frameset( &set);
177 xsh_free_frame( &result);
179
180 if (cpl_error_get_code() != CPL_ERROR_NONE) {
181 xsh_error_dump(CPL_MSG_ERROR);
182 ret = 1;
183 }
184 TEST_END();
185 return ret;
186}
187
int main()
Unit test of xsh_bspline_interpol.
static void HandleOptions(int argc, char **argv)
static void Help(void)
#define MODULE_ID
static struct option long_options[]
@ HELP_OPT
@ DEBUG_OPT
static xsh_instrument * instrument
cpl_frameset * sof_to_frameset(const char *sof_name)
Definition: tests.c:576
cpl_frame * xsh_divide_flat(cpl_frame *frame, cpl_frame *flat, const char *tag, xsh_instrument *instr)
divide PRE frame with the master FLAT frame
Definition: xsh_divide.c:75
#define check(COMMAND)
Definition: xsh_error.h:71
#define xsh_error_dump(level)
Definition: xsh_error.h:92
void xsh_instrument_set_recipe_id(xsh_instrument *instrument, const char *recipe_id)
Set the recipe_id into the instrument structure.
void xsh_instrument_free(xsh_instrument **instrument)
free an 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
void xsh_free_frameset(cpl_frameset **f)
Deallocate a frame set and set the pointer to NULL.
Definition: xsh_utils.c:2254
int xsh_debug_level_set(int level)
set debug level
Definition: xsh_utils.c:3125
#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_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_master_flat(cpl_frameset *frames, xsh_instrument *instr)
Find master flat frame.
Definition: xsh_dfs.c:3426
@ XSH_DEBUG_LEVEL_HIGH
Definition: xsh_utils.h:138
@ XSH_DEBUG_LEVEL_LOW
Definition: xsh_utils.h:137
@ XSH_DEBUG_LEVEL_MEDIUM
Definition: xsh_utils.h:138