X-shooter Pipeline Reference Manual 3.8.15
test-xsh_the_map.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.10 $
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_the_map.h>
51#include <xsh_drl.h>
52#include <xsh_pfits.h>
53
54#include <xsh_badpixelmap.h>
55
56#include <cpl.h>
57#include <math.h>
58
59#include <getopt.h>
60
61/*--------------------------------------------------------------------------
62 Defines
63 --------------------------------------------------------------------------*/
64
65#define MODULE_ID "XSH_THE_MAP"
66#define SYNTAX "Test the theoretical map\n"\
67 "use : ./the_xsh_themap THE_MAP PRE_FRAME\n"\
68 "THE_MAP => the theoretical map table\n"
69
70
71/*--------------------------------------------------------------------------
72 Implementation
73 --------------------------------------------------------------------------*/
74
82int main( int argc, char **argv)
83{
84 /* Declarations */
85 int ret = 0 ;
86 char* the_name = NULL;
87 cpl_frame* the_frame = NULL;
88 xsh_the_map* themap = NULL;
89 int themap_size = 0;
90 int i = 0;
91 FILE* themap_file = NULL;
92
93 /* Initialize libraries */
95
96 cpl_msg_set_level(CPL_MSG_DEBUG);
98
99 /* Analyse parameters */
100 if (argc > 1){
101 the_name = argv[1];
102 }
103 else{
104 printf(SYNTAX);
105 TEST_END();
106 return 0;
107 }
108
109 /* Create frames */
110 XSH_ASSURE_NOT_NULL( the_name);
111 the_frame = cpl_frame_new();
112 cpl_frame_set_filename( the_frame, the_name) ;
113 cpl_frame_set_level( the_frame, CPL_FRAME_LEVEL_TEMPORARY);
114 cpl_frame_set_group( the_frame, CPL_FRAME_GROUP_RAW ) ;
115
116 check( themap = xsh_the_map_load( the_frame));
117 check(themap_size = xsh_the_map_get_size(themap));
118
119 /* Create DS9 REGION FILE */
120 themap_file = fopen( "THEMAP.reg", "w");
121 fprintf( themap_file, "# Region file format: DS9 version 4.0\n\
122 global color=red font=\"helvetica 4 normal\"\
123 select=1 highlite=1 edit=1 move=1 delete=1 include=1 fixed=0 source \nimage\n");
124
125 for( i=0; i<themap_size; i++){
126 float lambdaTHE = 0.0;
127 double xd, yd, slit;
128
129 check(lambdaTHE = xsh_the_map_get_wavelength(themap, i));
130 check(xd = xsh_the_map_get_detx(themap, i));
131 check(yd = xsh_the_map_get_dety(themap, i));
132
133 check(slit = (double) xsh_the_map_get_slit_position( themap, i));
134 if (slit == 0){
135 fprintf( themap_file, "point(%f,%f) #point=cross color=yellow "\
136 "font=\"helvetica 10 normal\" text={THE %.3f}\n", xd, yd, lambdaTHE);
137 }
138 else{
139 fprintf( themap_file, "point(%f,%f) #point=cross color=yellow "\
140 "font=\"helvetica 10 normal\" text={slit %f}\n", xd, yd, slit);
141 }
142 }
143
144
145 cleanup:
146 xsh_free_frame( &the_frame);
147 xsh_the_map_free( &themap);
148 if(themap_file != NULL) {
149 fclose( themap_file);
150 }
151 if (cpl_error_get_code() != CPL_ERROR_NONE) {
152 xsh_error_dump(CPL_MSG_ERROR);
153 ret = 1;
154 }
155 TEST_END();
156 return ret ;
157}
158
int main()
Unit test of xsh_bspline_interpol.
#define MODULE_ID
#define SYNTAX
void xsh_the_map_free(xsh_the_map **list)
free memory associated to a the_map
double xsh_the_map_get_detx(xsh_the_map *list, int idx)
get detx of the map list
float xsh_the_map_get_slit_position(xsh_the_map *list, int idx)
get slit position of the map list
double xsh_the_map_get_dety(xsh_the_map *list, int idx)
get dety of the map list
int xsh_the_map_get_size(xsh_the_map *list)
get size of the map list
float xsh_the_map_get_wavelength(xsh_the_map *list, int idx)
get wavelength of the map list
xsh_the_map * xsh_the_map_load(cpl_frame *frame)
load a theoretical map frame in the_map structure. Suppress spurious entries in the THE MAP (marked w...
#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_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 TEST_END()
Definition: tests.h:111
#define TESTS_INIT(DRL_ID)
Definition: tests.h:105
@ XSH_DEBUG_LEVEL_MEDIUM
Definition: xsh_utils.h:138