93 #include <uves_response_utils.h>
94 #include <uves_utils_wrappers.h>
95 #include <uves_pfits.h>
96 #include <uves_error.h>
124 cpl_table *flux_table = NULL;
125 const char* dir_name=
"/media/VERBATIM/data7/flames/flames_uves_demo/ref/";
126 const char* tab_name=
"flxstd.fits";
137 const char *columns[3] = {
"LAMBDA",
"BIN_WIDTH",
"F_LAMBDA"};
140 cpl_table* result=NULL;
141 sprintf(full_name,
"%s%s",dir_name,tab_name);
142 uves_msg(
"full name: %s",full_name);
143 flux_table=cpl_table_load(full_name,1,0);
144 nraws=cpl_table_get_nrow(flux_table);
147 uves_msg(
"std: name \t type \t ra \t dec");
148 for(i=0;i<nraws; i++) {
150 check( ref_ra = cpl_table_get_double(flux_table,
"RA_DEG", i, NULL),
151 "Could not read catalogue star right ascension");
153 check( ref_dec = cpl_table_get_double(flux_table,
"DEC_DEG", i, NULL),
154 "Could not read catalogue star declination");
156 check( sprintf(ref_name,
"%s", cpl_table_get_string(flux_table,
"OBJECT", i)),
157 "Could not read reference object name");
159 check( sprintf(ref_type,
"%s", cpl_table_get_string(flux_table,
"TYPE", i)),
160 "Could not read reference object type");
162 uves_msg(
"std: %s \t %s \t %f \t %f",ref_name,ref_type,ref_ra,ref_dec);
164 sprintf(res_name,
"%s.fits",ref_name);
165 check( ndata = cpl_table_get_int(flux_table,
"NDATA", i, NULL),
166 "Error reading length of flux array");
168 result=cpl_table_new(ndata);
169 for(j = 0; j < 3; j++)
171 const cpl_array *data;
174 cpl_table_new_column(result, columns[j], CPL_TYPE_DOUBLE);
176 data = cpl_table_get_array(flux_table, columns[j], i);
180 uves_msg_debug(
"3d table array size = %" CPL_SIZE_FORMAT
", ndata = %d",
181 cpl_array_get_size(data), ndata);
183 assure( cpl_array_get_size(data) >= ndata,
184 CPL_ERROR_ILLEGAL_INPUT,
185 "Flux table row %d: column '%s' depth (%" CPL_SIZE_FORMAT
") "
186 "is less than NDATA (%d)",
187 i, columns[j], cpl_array_get_size(data), ndata);
189 for (indx = 0; indx < ndata; indx++)
192 cpl_table_set_double(result, columns[j], indx,
193 cpl_array_get_float(data, indx, NULL));
197 uves_table_save(result, header, NULL,res_name, CPL_IO_DEFAULT);
198 uves_free_table(&result);
203 uves_free_table(&flux_table);
204 uves_free_propertylist(&header);
218 cpl_table *flux_table = NULL;
220 cpl_array *values = NULL;
223 const char *
object[] = {
"first std",
"another standard star"};
224 const char *type [] = {
"NULL",
"type 2"};
225 const double lambda[] = {8000, 2000};
226 const double fluxes[] = {1000000, 200};
227 const double bin_width[] = {0.8, 0.0003};
228 const double ra[] = {10, 80};
229 const double dec[] = {-8, 0};
231 cpl_table *cat_flux = NULL;
232 char *ref_name = NULL;
237 flux_table = cpl_table_new(nrow);
239 cpl_table_new_column(flux_table,
"RA_DEG", CPL_TYPE_DOUBLE);
240 cpl_table_new_column(flux_table,
"DEC_DEG", CPL_TYPE_DOUBLE);
242 cpl_table_new_column(flux_table,
"OBJECT", CPL_TYPE_STRING);
243 cpl_table_new_column(flux_table,
"TYPE", CPL_TYPE_STRING);
245 cpl_table_new_column(flux_table,
"NDATA", CPL_TYPE_INT);
247 cpl_table_new_column_array(flux_table,
"LAMBDA", CPL_TYPE_FLOAT, depth);
248 cpl_table_new_column_array(flux_table,
"BIN_WIDTH", CPL_TYPE_FLOAT, depth);
249 cpl_table_new_column_array(flux_table,
"F_LAMBDA", CPL_TYPE_FLOAT, depth);
251 values = cpl_array_new(depth, CPL_TYPE_FLOAT);
253 for (i = 0; i < nrow; i++)
255 cpl_table_set_double(flux_table,
"RA_DEG", i, ra[i]);
256 cpl_table_set_double(flux_table,
"DEC_DEG", i, dec[i]);
257 cpl_table_set_string(flux_table,
"OBJECT", i,
object[i]);
258 cpl_table_set_string(flux_table,
"TYPE", i, type[i]);
259 cpl_table_set_int (flux_table,
"NDATA", i, depth);
261 cpl_array_fill_window_float(values, 0, depth, lambda[i]);
262 cpl_table_set_array(flux_table,
"LAMBDA", i, values);
264 cpl_array_fill_window_float(values, 0, depth, bin_width[i]);
265 cpl_table_set_array(flux_table,
"BIN_WIDTH", i, values);
267 cpl_array_fill_window_float(values, 0, depth, fluxes[i]);
268 cpl_table_set_array(flux_table,
"F_LAMBDA", i, values);
276 for (i = 0; i < nrow; i++)
278 double paccuracy = 60;
279 double residual = 30;
284 uves_free_table(&cat_flux);
285 cpl_free(ref_name); ref_name = NULL;
293 while(ref_name[strlen(ref_name)-1] ==
' ')
296 ref_name[strlen(ref_name)-1] =
'\0';
301 assure( cpl_table_get_nrow(cat_flux) == depth, CPL_ERROR_ILLEGAL_OUTPUT,
302 "Flux table has %" CPL_SIZE_FORMAT
" rows, %d expected",
303 cpl_table_get_nrow(cat_flux), depth);
305 assure( strcmp(ref_name,
object[i]) == 0, CPL_ERROR_ILLEGAL_OUTPUT,
306 "Found '%s'; Expected '%s'", ref_name,
object[i]);
309 assure( float_equal(cpl_table_get_column_mean(cat_flux,
"LAMBDA"),
311 CPL_ERROR_ILLEGAL_OUTPUT,
312 "LAMBDA = %f; Expected = %f",
313 cpl_table_get_column_mean(cat_flux,
"LAMBDA"), lambda[i]);
315 assure( float_equal(cpl_table_get_column_mean(cat_flux,
"BIN_WIDTH"),
316 bin_width[i], 0.001),
317 CPL_ERROR_ILLEGAL_OUTPUT,
318 "BIN_WIDTH = %f; Expected = %f",
319 cpl_table_get_column_mean(cat_flux,
"BIN_WIDTH"), bin_width[i]);
321 assure( float_equal(cpl_table_get_column_mean(cat_flux,
"F_LAMBDA"),
323 CPL_ERROR_ILLEGAL_OUTPUT,
324 "F_LAMBDA = %f; Expected = %f",
325 cpl_table_get_column_mean(cat_flux,
"F_LAMBDA"), fluxes[i]);
327 cpl_test_rel(cpl_table_get_column_mean(cat_flux,
"LAMBDA"),
330 cpl_test_rel(cpl_table_get_column_mean(cat_flux,
"BIN_WIDTH"),
331 bin_width[i], 0.001);
333 cpl_test_rel(cpl_table_get_column_mean(cat_flux,
"F_LAMBDA"),
338 uves_free_table(&flux_table);
339 uves_free_table(&cat_flux);
340 uves_free_array(&values);
341 uves_free_propertylist(&raw_header);
356 cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING);
362 return cpl_test_end(0);
static void test_load_3dtable(void)
Test of uves_align.
cpl_table * uves_align(const uves_propertylist *object_header, const cpl_table *flux_table, double accuracy, char **ref_name_dynamic)
Match a star against a catalogue of stars.
static void test_3dtable(void)
Test of uves_align.
int main(void)
Test 3d table usage in uves_align.
uves_propertylist * uves_propertylist_new(void)
Create an empty property list.
#define uves_msg(...)
Print a message on 'info' or 'debug' level.
uves_propertylist * uves_propertylist_load(const char *name, int position)
Create a property list from a file.
void uves_pfits_set_ra(uves_propertylist *plist, double ra)
Write the right ascension.
#define uves_msg_debug(...)
Print a debug message.
void uves_pfits_set_dec(uves_propertylist *plist, double dec)
Write the declination.