X-shooter Pipeline Reference Manual 3.8.15
xsh_data_slice_offset.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: 2011-01-10 09:02:01 $
23 * $Revision: 1.7 $
24 */
25
26#ifdef HAVE_CONFIG_H
27#include <config.h>
28#endif
29
30/*---------------------------------------------------------------------------*/
35/*---------------------------------------------------------------------------*/
36
40/*-----------------------------------------------------------------------------
41 Includes
42 ----------------------------------------------------------------------------*/
43
44#include <math.h>
45#include <xsh_dfs.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
53/*----------------------------------------------------------------------------
54 Function implementation
55 ----------------------------------------------------------------------------*/
56
57/*---------------------------------------------------------------------------*/
65/*---------------------------------------------------------------------------*/
67{
68 xsh_slice_offset* result = NULL;
69
70 XSH_CALLOC(result, xsh_slice_offset, 1);
71
73
74 cleanup:
75 if (cpl_error_get_code() != CPL_ERROR_NONE) {
76 xsh_slice_offset_free( &result);
77 }
78 return result;
79}
80/*---------------------------------------------------------------------------*/
81
82/*---------------------------------------------------------------------------*/
92/*---------------------------------------------------------------------------*/
94 cpl_table *table = NULL;
95 cpl_propertylist* header = NULL;
96 const char* tablename = NULL;
97 xsh_slice_offset *result = NULL;
98
99 /* check input parameters */
100 XSH_ASSURE_NOT_NULL(frame);
101
102 /* get table filename */
103 check(tablename = cpl_frame_get_filename(frame));
104
105 XSH_TABLE_LOAD( table, tablename);
106
107 check( header = cpl_propertylist_load(tablename,0));
108
109 check(result = xsh_slice_offset_create());
110
111 check( cpl_propertylist_append(result->header, header));
112
114 CPL_TYPE_DOUBLE, 0, &(result->cen_up)));
116 CPL_TYPE_DOUBLE, 0, &(result->cen_down)));
117
118 cleanup:
119 if (cpl_error_get_code () != CPL_ERROR_NONE) {
120 xsh_error_msg("can't load frame %s",cpl_frame_get_filename(frame));
121 xsh_slice_offset_free(&result);
122 }
123 xsh_free_propertylist( &header);
124 XSH_TABLE_FREE( table);
125 return result;
126}
127/*---------------------------------------------------------------------------*/
128
129/*---------------------------------------------------------------------------*/
136/*---------------------------------------------------------------------------*/
138{
139 if (list && *list){
140 xsh_free_propertylist( &((*list)->header));
141 cpl_free( *list);
142 *list = NULL;
143 }
144}
145/*---------------------------------------------------------------------------*/
146
147
148/*---------------------------------------------------------------------------*/
157/*---------------------------------------------------------------------------*/
159{
160 cpl_propertylist *res = NULL;
161
162 XSH_ASSURE_NOT_NULL( list);
163 res = list->header;
164 cleanup:
165 return res;
166}
167/*---------------------------------------------------------------------------*/
168
169/*---------------------------------------------------------------------------*/
181/*---------------------------------------------------------------------------*/
183 const char* filename, xsh_instrument *instrument)
184{
185 cpl_table *table = NULL;
186 cpl_frame *result = NULL;
187 const char *tag = NULL ;
188
189 /* check input parameters */
190 XSH_ASSURE_NOT_NULL( list);
191 XSH_ASSURE_NOT_NULL( filename);
193
194 /* create a table */
195 check( table = cpl_table_new( 1));
196
197 /* create column names */
199 XSH_SLICE_OFFSET_TABLE_UNIT_CEN_UP, CPL_TYPE_DOUBLE);
201 XSH_SLICE_OFFSET_TABLE_UNIT_CEN_DOWN, CPL_TYPE_DOUBLE);
202
203 check( cpl_table_set_double( table, XSH_SLICE_OFFSET_TABLE_COLNAME_CEN_UP,
204 0, list->cen_up));
205 check( cpl_table_set_double( table, XSH_SLICE_OFFSET_TABLE_COLNAME_CEN_DOWN,
206 0, list->cen_down));
207
208 /* create fits file */
209 check( cpl_table_save( table, list->header, NULL, filename,
210 CPL_IO_DEFAULT));
211
212 /* Create the frame */
214
215 check( result = xsh_frame_product( filename, tag,
216 CPL_FRAME_TYPE_TABLE, CPL_FRAME_GROUP_PRODUCT,
217 CPL_FRAME_LEVEL_TEMPORARY));
218
219 cleanup:
220 XSH_TABLE_FREE(table);
221 return result ;
222}
223/*---------------------------------------------------------------------------*/
224
static xsh_instrument * instrument
xsh_slice_offset * xsh_slice_offset_create(void)
Create an empty slice_offset.
xsh_slice_offset * xsh_slice_offset_load(cpl_frame *frame)
Load a slice_offset from a frame.
cpl_frame * xsh_slice_offset_save(xsh_slice_offset *list, const char *filename, xsh_instrument *instrument)
Save an slice_offset list to a frame.
void xsh_slice_offset_free(xsh_slice_offset **list)
Free memory associated to a slice_offset.
cpl_propertylist * xsh_slice_offset_get_header(xsh_slice_offset *list)
Get header of the table.
#define check(COMMAND)
Definition: xsh_error.h:71
#define xsh_error_msg(...)
Definition: xsh_error.h:94
#define XSH_ASSURE_NOT_NULL(pointer)
Definition: xsh_error.h:99
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.
cpl_propertylist * header
#define XSH_SLICE_OFFSET_TABLE_COLNAME_CEN_DOWN
#define XSH_SLICE_OFFSET_TABLE_UNIT_CEN_UP
#define XSH_SLICE_OFFSET_TABLE_UNIT_CEN_DOWN
#define XSH_SLICE_OFFSET_TABLE_COLNAME_CEN_UP
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_GET_TAG_FROM_ARM(TAG, instr)
Definition: xsh_dfs.h:1548
#define XSH_SLICE_OFFSET
Definition: xsh_dfs.h:601
#define XSH_TABLE_NEW_COL(TABLE, NAME, UNIT, TYPE)
Definition: xsh_utils.h:113
#define XSH_NEW_PROPERTYLIST(POINTER)
Definition: xsh_utils.h:70
#define XSH_CALLOC(POINTER, TYPE, SIZE)
Definition: xsh_utils.h:56
#define XSH_TABLE_LOAD(TABLE, NAME)
#define XSH_TABLE_FREE(TABLE)