X-shooter Pipeline Reference Manual 3.8.15
test-xsh_correct_vacuum_to_air.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-08-02 13:29:37 $
23 * $Revision: 1.2 $
24 * $Name: not supported by cvs2svn $
25 */
26#ifdef HAVE_CONFIG_H
27# include <config.h>
28#endif
29
30/*--------------------------------------------------------------------------*/
37/*--------------------------------------------------------------------------*/
40/*---------------------------------------------------------------------------
41 Includes
42 ---------------------------------------------------------------------------*/
43#include <xsh_error.h>
44#include <xsh_msg.h>
45#include <xsh_data_instrument.h>
46#include <xsh_pfits.h>
47#include <tests.h>
48#include <cpl.h>
49#include <math.h>
50#include <time.h>
51#include <getopt.h>
52#include <sys/time.h>
53#include <xsh_cpl_size.h>
54#include <getopt.h>
55
56/*---------------------------------------------------------------------------
57 Defines
58 ---------------------------------------------------------------------------*/
59#define MODULE_ID "XSH_CORRECT_VACUUM_TO_AIR"
60
61/*--------------------------------------------------------------------------*/
67/*--------------------------------------------------------------------------*/
68int main( int argc, char** argv)
69{
70 int ret = 0;
71
72 cpl_table* table_names = NULL;
73 cpl_table* table_spect = NULL;
74 cpl_frame* std_catalog = NULL;
75 cpl_propertylist* phead = NULL;
76 cpl_propertylist* xhead = NULL;
77
78 //xsh_instrument* instrument = NULL;
79 const char* fname_out = "catalog_new.fits";
80 const char* fname_inp;
81
82 int nb_frames = 0;
83 int next = 0;
84 int i = 0;
85 int nrow = 0;
86 int j = 0;
87
88 double* plambda = NULL;
89 //double* pflux = NULL;
90 //double* pbin = NULL;
91 double c1 = 1.0002735182;
92 double c2 = 131.4182;
93 double c4 = 2.76249E8;
94 double w = 0;
95 double w2 = 0;
96 double w4 = 0;
97 double wair=0;
98
99 double nm2AA=10.;
100
102 cpl_msg_set_level(CPL_MSG_DEBUG);
104
105 nb_frames = argc - optind;
106 if (nb_frames == 1) {
107 fname_inp = argv[optind];
108 } else {
109 xsh_msg( "********** NOT ENOUGH INPUT FRAMES **********" );
110 exit(0);
111 }
112
113 std_catalog = cpl_frame_new();
114 cpl_frame_set_filename(std_catalog, fname_inp);
115 next = cpl_frame_get_nextensions(std_catalog);
116 phead = cpl_propertylist_load(fname_inp, 0);
117 table_names = cpl_table_load(fname_inp, 1, 0);
118 xhead = cpl_propertylist_load(fname_inp, 1);
119 cpl_table_save(table_names, phead, xhead, fname_out, CPL_IO_DEFAULT);
120
121 for (i = 2; i <= next; i++) {
122
123 table_spect = cpl_table_load(fname_inp, i, 0);
124 xhead = cpl_propertylist_load(fname_inp, i);
125 plambda = cpl_table_get_data_double(table_spect, "LAMBDA");
126 nrow = cpl_table_get_nrow(table_spect);
127
128 if (i == 2 || i == 4) {
129 /* only for GD71,GD153, that are at extention 2,4 of catalogue apply correction */
130 for (j = 0; j < nrow; j++) {
131 w = nm2AA * plambda[j];
132 w2 = w * w;
133 w4 = w2*w2;
134 wair = w / (c1 + c2 / w2 + c4 / w4 );
135 plambda[j] = wair / nm2AA;
136 //xsh_msg("w_cor star[%d]= %g [AA]",i, w-wair);
137 }
138 }
139 xsh_msg("save out tab on file %s",fname_out);
140 check(cpl_table_save(table_spect, xhead, NULL, fname_out, CPL_IO_EXTEND));
141 xsh_free_propertylist(&xhead);
142 xsh_free_table(&table_spect);
143
144 }
145
146
147 cleanup: xsh_free_table(&table_names);
148 xsh_free_table(&table_spect);
149 xsh_free_propertylist(&xhead);
150 xsh_free_propertylist(&phead);
151 xsh_free_frame(&std_catalog);
152
153 if (cpl_error_get_code() != CPL_ERROR_NONE) {
154 xsh_error_dump(CPL_MSG_ERROR);
155 ret = 1;
156 }
157 return ret;
158}
159
int main()
Unit test of xsh_bspline_interpol.
#define check(COMMAND)
Definition: xsh_error.h:71
#define xsh_error_dump(level)
Definition: xsh_error.h:92
#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
void xsh_free_table(cpl_table **t)
Deallocate a table and set the pointer to NULL.
Definition: xsh_utils.c:2133
void xsh_free_propertylist(cpl_propertylist **p)
Deallocate a property list and set the pointer to NULL.
Definition: xsh_utils.c:2179
#define TESTS_INIT(DRL_ID)
Definition: tests.h:105
@ XSH_DEBUG_LEVEL_MEDIUM
Definition: xsh_utils.h:138