X-shooter Pipeline Reference Manual 3.8.15
xsh_data_shift_tab.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-18 14:15:44 $
23 * $Revision: 1.13 $
24 * $Name: not supported by cvs2svn $
25 */
26
27#ifdef HAVE_CONFIG_H
28#include <config.h>
29#endif
30
31/*---------------------------------------------------------------------------*/
36/*---------------------------------------------------------------------------*/
37
41/*-----------------------------------------------------------------------------
42 Includes
43 ----------------------------------------------------------------------------*/
44
45#include <xsh_data_shift_tab.h>
46#include <xsh_utils.h>
47#include <xsh_utils_table.h>
48#include <xsh_error.h>
49#include <xsh_msg.h>
50#include <xsh_pfits.h>
51#include <cpl.h>
52#include <xsh_drl.h>
53#include <math.h>
54
55/*----------------------------------------------------------------------------
56 Function implementation
57 ----------------------------------------------------------------------------*/
58
59/*---------------------------------------------------------------------------*/
66/*---------------------------------------------------------------------------*/
68{
69 cpl_table *table = NULL;
70 const char* tablename = NULL;
71 xsh_shift_tab *result = NULL;
73 double shift_cen=0, shift_up=0, shift_down=0;
74
75 XSH_ASSURE_NOT_NULL( frame);
76 check( tablename = cpl_frame_get_filename( frame));
77 XSH_TABLE_LOAD( table, tablename);
78
79 /* allocate memory */
80 XSH_CALLOC( result, xsh_shift_tab, 1);
81
83
84 result->is_ifu = ( mode == XSH_MODE_IFU);
85
86 if ( result->is_ifu){
88 CPL_TYPE_DOUBLE, 0, &shift_down));
90 CPL_TYPE_DOUBLE, 0, &shift_cen));
92 CPL_TYPE_DOUBLE, 0, &shift_up));
93
94 result->shift_y_cen = shift_cen;
95 result->shift_y_down = shift_down;
96 result->shift_y_up = shift_up;
97 }
98 else{
100 CPL_TYPE_DOUBLE, 0, &shift_cen));
101 result->shift_y = shift_cen;
102 }
103 check( result->header = cpl_propertylist_load( tablename, 0));
104
105 cleanup:
106 if ( cpl_error_get_code() != CPL_ERROR_NONE){
107 xsh_shift_tab_free( &result);
108 }
109 XSH_TABLE_FREE( table);
110 return result;
111}
112/*---------------------------------------------------------------------------*/
113
114
115/*---------------------------------------------------------------------------*/
122/*---------------------------------------------------------------------------*/
124{
125 if( tab && *tab) {
126 xsh_free_propertylist(&((*tab)->header));
127 cpl_free( *tab);
128 *tab=NULL;
129 }
130
131}
132/*---------------------------------------------------------------------------*/
133
134
135cpl_frame * xsh_shift_tab_save(xsh_shift_tab *tab, const char * tag,const int clean_tmp )
136{
137 cpl_frame * result = NULL ;
138 cpl_table *table = NULL;
139 cpl_propertylist *header = NULL;
140 char filename[256];
141
142 XSH_ASSURE_NOT_NULL( tab ) ;
143
144 check( table = cpl_table_new( 1 )); /* One row */
145 if ( tab->is_ifu == 0 ) {
146
147 /* create column */
149 XSH_SHIFT_TABLE_UNIT_YSHIFT, CPL_TYPE_DOUBLE);
150 /* insert data */
151 check(cpl_table_set_double(table,XSH_SHIFT_TABLE_COLNAME_YSHIFT,
152 0, tab->shift_y));
153 }
154 else {
155 /* create columns */
157 XSH_SHIFT_TABLE_UNIT_YSHIFT_DOWN, CPL_TYPE_DOUBLE);
159 XSH_SHIFT_TABLE_UNIT_YSHIFT_CEN, CPL_TYPE_DOUBLE);
161 XSH_SHIFT_TABLE_UNIT_YSHIFT_UP, CPL_TYPE_DOUBLE);
162 /* insert data */
163 check(cpl_table_set_double(table, XSH_SHIFT_TABLE_COLNAME_YSHIFT_DOWN,
164 0, tab->shift_y_down));
165 check(cpl_table_set_double(table, XSH_SHIFT_TABLE_COLNAME_YSHIFT_CEN,
166 0, tab->shift_y_cen));
167 check(cpl_table_set_double(table, XSH_SHIFT_TABLE_COLNAME_YSHIFT_UP,
168 0, tab->shift_y_up));
169 }
170
171 header = tab->header;
172
173 check( xsh_pfits_set_pcatg( header, tag ) );
174 sprintf(filename,"%s.fits",tag) ;
175 check( cpl_table_save(table, header, NULL, filename, CPL_IO_DEFAULT));
176
177 /* Create the frame */
178 check(result=xsh_frame_product(filename,
179 tag,
180 CPL_FRAME_TYPE_TABLE,
181 CPL_FRAME_GROUP_PRODUCT,
182 CPL_FRAME_LEVEL_TEMPORARY));
183
184
185 if(clean_tmp) {
186 check (xsh_add_temporary_file( filename));
187 }
188 cleanup:
189 if (cpl_error_get_code() != CPL_ERROR_NONE){
190 xsh_free_frame(&result);
191 }
192
193 XSH_TABLE_FREE( table);
194 return result ;
195
196}
197
198
207{
208 xsh_shift_tab * result = NULL;
210
212 /* allocate memory */
213 XSH_CALLOC( result, xsh_shift_tab, 1);
214
215 check (result->header = cpl_propertylist_new());
217
218 result->is_ifu = ( mode == XSH_MODE_IFU);
219
220 cleanup:
221 return result ;
222}
223
static char mode[32]
static xsh_instrument * instrument
cpl_frame * xsh_shift_tab_save(xsh_shift_tab *tab, const char *tag, const int clean_tmp)
xsh_shift_tab * xsh_shift_tab_create(xsh_instrument *instrument)
void xsh_shift_tab_free(xsh_shift_tab **tab)
Free memory associated to a the_arcline.
xsh_shift_tab * xsh_shift_tab_load(cpl_frame *frame, xsh_instrument *instr)
Load a shift table.
#define check(COMMAND)
Definition: xsh_error.h:71
#define XSH_ASSURE_NOT_NULL(pointer)
Definition: xsh_error.h:99
XSH_MODE xsh_instrument_get_mode(xsh_instrument *i)
Get a mode on instrument structure.
void xsh_pfits_set_pcatg(cpl_propertylist *plist, const char *value)
Write the PCATG value.
Definition: xsh_pfits.c:1008
void xsh_free_frame(cpl_frame **f)
Deallocate a frame and set the pointer to NULL.
Definition: xsh_utils.c:2269
void xsh_free_propertylist(cpl_propertylist **p)
Deallocate a property list and set the pointer to NULL.
Definition: xsh_utils.c:2179
cpl_error_code xsh_get_table_value(const cpl_table *table, const char *colname, cpl_type coltype, int i, void *result)
Read a table value from a fits table.
void xsh_add_temporary_file(const char *name)
Add temporary file to temprary files list.
Definition: xsh_utils.c:1432
cpl_propertylist * header
@ XSH_MODE_IFU
#define XSH_SHIFT_TABLE_UNIT_YSHIFT_CEN
#define XSH_SHIFT_TABLE_COLNAME_YSHIFT_DOWN
#define XSH_SHIFT_TABLE_COLNAME_YSHIFT_UP
#define XSH_SHIFT_TABLE_UNIT_YSHIFT_UP
#define XSH_SHIFT_TABLE_COLNAME_YSHIFT_CEN
#define XSH_SHIFT_TABLE_COLNAME_YSHIFT
#define XSH_SHIFT_TABLE_UNIT_YSHIFT_DOWN
#define XSH_SHIFT_TABLE_UNIT_YSHIFT
cpl_frame * xsh_frame_product(const char *fname, const char *tag, cpl_frame_type type, cpl_frame_group group, cpl_frame_level level)
Creates a frame with given characteristics.
Definition: xsh_dfs.c:930
#define XSH_TABLE_NEW_COL(TABLE, NAME, UNIT, TYPE)
Definition: xsh_utils.h:113
#define XSH_CALLOC(POINTER, TYPE, SIZE)
Definition: xsh_utils.h:56
#define XSH_TABLE_LOAD(TABLE, NAME)
#define XSH_TABLE_FREE(TABLE)