X-shooter Pipeline Reference Manual 3.8.15
xsh_data_atmos_ext.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-01-27 08:04:18 $
23 * $Revision: 1.5 $
24*/
25
35/*----------------------------------------------------------------------------
36 Includes
37 ----------------------------------------------------------------------------*/
38
39#include <xsh_dfs.h>
40#include <xsh_error.h>
41#include <xsh_msg.h>
42#include <cpl.h>
43#include <string.h>
44#include <time.h>
45#include <xsh_utils_table.h>
46#include <xsh_data_atmos_ext.h>
47
48/*----------------------------------------------------------------------------
49 Function prototypes
50 ----------------------------------------------------------------------------*/
51
52/*-----------------------------------------------------------------------------
53 Implementation
54 -----------------------------------------------------------------------------*/
56{
57 xsh_atmos_ext_list * result = NULL ;
58
59 /* Create the list */
60 XSH_CALLOC( result, xsh_atmos_ext_list, 1 ) ;
61 result->size = size ;
62 XSH_CALLOC( result->lambda, double, size ) ;
63 XSH_CALLOC( result->K, double, size ) ;
64
65 cleanup:
66 return result ;
67}
68
69cpl_error_code
70xsh_atmos_ext_dump_ascii( xsh_atmos_ext_list * list, const char* filename )
71{
72 FILE * fout ;
73 int size=0;
74 int i=0;
75 double * plambda=NULL;
76 double * pK=NULL;
77
78 XSH_ASSURE_NOT_NULL_MSG(list,"Null input atmospheric ext frame list!Exit");
79 size=list->size;
80
81 plambda = list->lambda ;
82 pK = list->K ;
83
84 if((fout=fopen(filename,"w"))==NULL) {
85
86 return CPL_ERROR_FILE_IO ;
87 } else {
88 for(i=0;i<size;i++) {
89 fprintf(fout, "%f %f \n", plambda[i], pK[i]);
90 }
91 }
92 if ( fout ) fclose( fout ) ;
93
94 cleanup:
95 return cpl_error_get_code() ;
96}
97
98
100{
101 cpl_table *table = NULL ;
102 const char * tablename = NULL ;
103 xsh_atmos_ext_list * result = NULL ;
104 int nentries, i ;
105 double * plambda, * pK ;
106
107 /* verify input */
108 XSH_ASSURE_NOT_NULL( ext_frame);
109
110 /* get table filename */
111 check(tablename = cpl_frame_get_filename( ext_frame ));
112
113 /* Load the table */
114 XSH_TABLE_LOAD( table, tablename ) ;
115 check( nentries = cpl_table_get_nrow( table ) ) ;
116
117 /* Create the list */
118 check( result = xsh_atmos_ext_list_create( nentries ) ) ;
119
120 plambda = result->lambda ;
121 pK = result->K ;
122 if(!cpl_table_has_column(table,XSH_ATMOS_EXT_LIST_COLNAME_K)){
123 xsh_msg_warning("You are using an obsolete atm extinction line table");
124 cpl_table_duplicate_column(table,XSH_ATMOS_EXT_LIST_COLNAME_K,
126 }
127 /* Fill the list */
128 for( i = 0 ; i< nentries ; i++, plambda++, pK++ ) {
129 float value ;
130
132 CPL_TYPE_FLOAT, i, &value ) ) ;
133 *plambda = value ;
135 CPL_TYPE_FLOAT, i, &value ) ) ;
136 *pK = value ;
137 }
138
139 cleanup:
140 if (cpl_error_get_code () != CPL_ERROR_NONE) {
141 xsh_error_msg("can't load frame %s",cpl_frame_get_filename(ext_frame));
143 }
144 XSH_TABLE_FREE( table);
145 return result ;
146}
147
148
150{
151 if ( list != NULL && *list != NULL ) {
152 check( cpl_free( (*list)->lambda ) ) ;
153 check( cpl_free( (*list)->K ) ) ;
154 check( cpl_free( *list ) ) ;
155 *list = NULL ;
156 }
157
158 cleanup:
159 return ;
160}
161
163{
164 XSH_ASSURE_NOT_NULL( list ) ;
165
166 cleanup:
167 return list->lambda ;
168}
169
171{
172 XSH_ASSURE_NOT_NULL( list ) ;
173
174 cleanup:
175 return list->K ;
176}
#define XSH_ASSURE_NOT_NULL_MSG(pointer, msg)
Definition: xsh_error.h:103
#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
int size
#define xsh_msg_warning(...)
Print an warning message.
Definition: xsh_msg.h:88
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.
xsh_atmos_ext_list * xsh_atmos_ext_list_create(int size)
double * xsh_atmos_ext_list_get_K(xsh_atmos_ext_list *list)
cpl_error_code xsh_atmos_ext_dump_ascii(xsh_atmos_ext_list *list, const char *filename)
xsh_atmos_ext_list * xsh_atmos_ext_list_load(cpl_frame *ext_frame)
void xsh_atmos_ext_list_free(xsh_atmos_ext_list **list)
double * xsh_atmos_ext_list_get_lambda(xsh_atmos_ext_list *list)
#define XSH_ATMOS_EXT_LIST_COLNAME_OLD
#define XSH_ATMOS_EXT_LIST_COLNAME_K
#define XSH_ATMOS_EXT_LIST_COLNAME_WAVELENGTH
#define XSH_CALLOC(POINTER, TYPE, SIZE)
Definition: xsh_utils.h:56
#define XSH_TABLE_LOAD(TABLE, NAME)
#define XSH_TABLE_FREE(TABLE)