35 #include <uves_parameters.h>
36 #include <uves_utils_wrappers.h>
37 #include <uves_test_simulate.h>
38 #include <uves_pfits.h>
39 #include <uves_error.h>
73 const char *data[] = {
"",
74 "'COEFFI','I*4',1,7,'7I10'",
77 "'COEFFR','R*4',1,5,'5E14.7'",
78 " 4.3300000E+02 4.0880000E+03 1.0000000E+00 2.1000000E+01 0.0000000E+00",
80 "'COEFFD','R*8',1,30,'3E23.15'",
81 " -7.097005629698889E+01 4.050908371864904E-02 -2.886756545398909E-06",
82 " 5.504345508879626E-10 -5.583004967206025E-14 7.624532125635992E+01",
83 " -2.428213567964009E-03 1.819158447566360E-06 -5.090366383338846E-10",
84 " 5.198098506055602E-14 3.513177145982783E-01 5.570332137951829E-04",
85 " -3.876157463910250E-07 1.113253735718822E-10 -1.132455173423791E-14",
86 " 2.977232589499959E-02 -5.389240622889887E-05 3.777456726044612E-08",
87 " -1.083863050648735E-11 1.098450510939580E-15 -1.093309039442914E-03",
88 " 2.402609262989674E-06 -1.688416547941747E-09 4.839101712729582E-13",
89 " -4.884504488944702E-17 1.919853952642526E-05 -4.004133160220927E-08",
90 " 2.816206503824200E-11 -8.051313882805877E-15 8.090579180112579E-19",
92 "'TAB_IN_OUT_YSHIFT','R*8',1,1,'3E23.15'",
93 " 4.180818583555659E+01 ",
98 for (i = 0; i < 8000; i++)
100 uves_propertylist_append_string(
102 " 35834 35835 35836 35837 35838 35839 35840");
105 for (i = 0; i <
sizeof(data)/
sizeof(
char *); i++)
107 uves_propertylist_append_string(
112 check_nomsg( p = uves_polynomial_convert_from_plist_midas(header,
119 uves_free_propertylist(&header);
133 const char *
const filename =
"linetable.fits";
134 cpl_table *linetable_in = NULL;
140 cpl_frame *f = cpl_frame_new();
141 cpl_frameset *frames = cpl_frameset_new();
143 const char *
const chip_id =
"CCD42";
144 cpl_table *ordertable = NULL;
145 cpl_table *tracetable = NULL;
147 int firstabs, lastabs;
148 enum uves_chip chip = UVES_CHIP_BLUE;
157 const char *linetable_filename;
158 cpl_table *linetable_out = NULL;
165 minorder, maxorder, nx));
168 minorder, maxorder, nx));
169 check_nomsg( uves_propertylist_append_string(header, UVES_CHIP_ID(chip), chip_id));
170 check_nomsg( uves_propertylist_append_string(header, UVES_DRS_ID,
"CPL"));
178 check_nomsg( uves_table_save(linetable_in, header, eheader, filename, CPL_IO_DEFAULT) );
179 check_nomsg( uves_save_polynomial(dispersion, filename, eheader) );
180 check_nomsg( uves_save_polynomial(absorder, filename, eheader) );
182 cpl_test_eq(cpl_error_get_code(), CPL_ERROR_NONE);
184 cpl_frame_set_filename(f, filename);
185 cpl_frame_set_tag(f,
"LINE_TABLE_BLUE");
186 cpl_frameset_insert(frames, f);
191 order_locations, minorder, maxorder,
197 chip, trace_id, window));
199 cpl_test_eq(cpl_error_get_code(), CPL_ERROR_NONE);
201 cpl_test( linetable_out != NULL );
202 cpl_test( header_out != NULL );
203 cpl_test( dispersion_out != NULL );
204 cpl_test( absorder_out != NULL );
206 cpl_test_eq( cpl_table_get_nrow(linetable_in),
207 cpl_table_get_nrow(linetable_out) );
213 cpl_test_eq_string( filename, linetable_filename );
219 for (order = minorder; order <= maxorder; order++) {
220 for (x = 1; x <= nx; x += nx/6) {
233 uves_free_frameset(&frames);
234 uves_free_table(&linetable_in);
235 uves_free_table(&linetable_out);
240 uves_free_propertylist(&header_out);
241 uves_free_propertylist(&header);
242 uves_free_propertylist(&eheader);
243 uves_free_table(&ordertable);
244 uves_free_table(&tracetable);
259 const char *values[] = {
"HISTORY",
"",
260 "HISTORY",
"'FIBREPOS','R*8',1,9,'3E23.15'",
261 "HISTORY",
" -3.243571124678650E+01 -2.309646501161805E+01 -1.402902770375962E+01",
262 "HISTORY",
" -4.772375924542811E+00 4.827040349175236E+00 1.378761244187003E+01",
263 "HISTORY",
" 2.321337764943556E+01 3.243571124678650E+01 -3.552713678800501E-15",
265 "HISTORY",
"'COEFFR','R*4',1,20,'5E14.7'",
266 "HISTORY",
"9.4893160E+00 4.0716226E+03 0.0000000E+00 2.3000000E+01 1.8538159E-04",
267 "HISTORY",
"0.0000000E+00 0.0000000E+00 0.0000000E+00 0.0000000E+00 0.0000000E+00",
269 "HISTORY",
"'INTVAL','I",
270 "HISTORY",
"1 2 3 4 5 6",
273 "HISTORY",
"'LEGAL','C",
274 "HISTORY",
" a sdfasdf",
276 "HISTORY",
"'ILLEGAL','C",
280 "HISTORY",
"'CHIPCHOICE','C",
284 int N =
sizeof(values) /
sizeof(
const char *) / 2;
287 double *resultd = NULL;
289 float *resultf = NULL;
290 const char *results = NULL;
291 int result_length, i;
293 cpl_type result_type;
296 for (i = 0; i < N; i++)
298 uves_propertylist_append_string(header, values[i*2], values[i*2+1]);
301 check_nomsg(resultd = uves_read_midas_array(header,
"FIBREPOS", &result_length,
302 &result_type, &nkeys));
304 cpl_test_eq(result_type, CPL_TYPE_DOUBLE);
305 cpl_test_eq(result_length, 9);
306 cpl_test_eq(nkeys, 5);
309 cpl_test_rel(resultd[0], -32, 0.10);
310 cpl_test_rel(resultd[3], -4.7, 0.10);
311 cpl_test_rel(resultd[6], 23, 0.10);
312 cpl_test( fabs(resultd[8]) < 0.001);
315 check_nomsg(resultf = uves_read_midas_array(header,
"COEFFR", &result_length,
316 &result_type, &nkeys));
317 cpl_test_eq(result_type, CPL_TYPE_FLOAT);
318 cpl_test_eq(result_length, 10);
319 cpl_test_eq(nkeys, 4);
321 cpl_test_rel(resultf[0], 9.489, 0.01);
322 cpl_test_rel(resultf[1], 4071, 0.01);
323 cpl_test_abs(resultf[2], 0.000, 0.01);
324 cpl_test_rel(resultf[3], 23.00, 0.01);
327 check_nomsg(resulti = uves_read_midas_array(header,
"INTVAL", &result_length,
328 &result_type, &nkeys));
330 cpl_test_eq(result_type, CPL_TYPE_INT);
331 cpl_test_eq(result_length, 7);
332 cpl_test_eq(nkeys, 4);
333 for (i = 1; i <= 7; i++)
335 cpl_test_eq(resulti[i-1], i);
340 check_nomsg( results = uves_read_midas_array(header,
"LEGAL", &result_length,
341 &result_type, &nkeys) );
343 cpl_test_eq(result_type, CPL_TYPE_STRING);
344 cpl_test_eq(result_length, 10);
345 cpl_test_eq(nkeys, 3);
346 cpl_test_eq_string(results,
" a sdfasdf");
348 cpl_test(uves_read_midas_array(header,
"ILLEGAL2", &result_length,
349 &result_type, &nkeys) == NULL);
352 uves_free_string_const(&results);
353 check_nomsg(results = uves_read_midas_array(header,
"CHIPCHOICE", &result_length,
354 &result_type, &nkeys));
356 cpl_test_eq(result_type, CPL_TYPE_STRING);
357 cpl_test_eq(result_length, 4);
358 cpl_test_eq(nkeys, 3);
359 cpl_test_eq_string(results,
"abcd");
363 uves_free_propertylist(&header);
365 uves_propertylist_append_string(header,
"HISTORY",
"'SELIDX','I*4',1,48389,'7I10'");
366 for (i = 0; i < N; i++)
368 uves_propertylist_append_string(
370 " 64605 64606 64607 64608 64609 64610 64611");
372 uves_propertylist_append_string(header,
"HISTORY",
"");
374 uves_free_int(&resulti);
375 check_nomsg( resulti = uves_read_midas_array(header,
"SELIDX", &result_length,
376 &result_type, &nkeys));
378 cpl_test_eq(result_type, CPL_TYPE_INT);
379 cpl_test_eq(result_length, N*7);
380 cpl_test_eq(nkeys, 1+N+1);
383 uves_free_propertylist(&header);
384 uves_free_double(&resultd);
385 uves_free_int(&resulti);
386 uves_free_float(&resultf);
387 uves_free_string_const(&results);
402 cpl_image *image = cpl_image_new(N, 1, CPL_TYPE_DOUBLE);
404 double inf = DBL_MAX;
405 for (i = 1; i <= N; i++)
407 cpl_image_set(image, i, 1, -FLT_MAX*200);
412 cpl_image_set(image, 1, 1, inf);
413 cpl_image_set(image, 2, 1, inf/inf);
415 uves_save_image(image,
"dfs.fits", NULL,
true,
true);
416 uves_free_image(&image);
429 cpl_frameset *frames = cpl_frameset_new();
430 cpl_parameterlist *parameters = cpl_parameterlist_new();
434 cpl_image *image = cpl_image_new(nx, ny, CPL_TYPE_DOUBLE);
437 const char *starttime;
438 const char *recipe_id =
"uves_cal_phony";
439 const char *tag =
"PHONY_TAG";
442 uves_define_global_parameters(parameters);
443 cpl_test_eq( cpl_error_get_code(), CPL_ERROR_NONE );
447 cpl_image *raw_image = cpl_image_new(nx, ny, CPL_TYPE_DOUBLE);
448 cpl_frame *raw_frame = cpl_frame_new();
453 for (i = 0; i < nkey; i++)
455 const char *key_name = uves_sprintf(
"KEY%d", i);
456 uves_propertylist_append_int(raw_header, key_name, i);
457 uves_free_string_const(&key_name);
459 uves_propertylist_append_string(raw_header,
"ORIGIN",
"unknown...");
461 const char *raw_filename =
"raw_file.fits";
462 uves_image_save(raw_image,
467 cpl_test_eq( cpl_error_get_code(), CPL_ERROR_NONE );
469 uves_free_image(&raw_image);
472 cpl_frame_set_tag(raw_frame,
"BIAS_BLUE");
475 cpl_frame_set_filename(raw_frame, raw_filename);
476 cpl_frameset_insert(frames, raw_frame);
480 "This recipe does not do anything");
481 cpl_test_eq( cpl_error_get_code(), CPL_ERROR_NONE );
483 uves_frameset_insert(frames,
485 CPL_FRAME_GROUP_PRODUCT,
486 CPL_FRAME_TYPE_IMAGE,
487 CPL_FRAME_LEVEL_INTERMEDIATE,
495 PACKAGE
"/" PACKAGE_VERSION,
501 cpl_test_eq( cpl_error_get_code(), CPL_ERROR_NONE );
502 cpl_test( cpl_frameset_find(frames, tag) != NULL);
504 uves_free_frameset(&frames);
505 uves_free_parameterlist(¶meters);
506 uves_free_image(&image);
507 uves_free_propertylist(&raw_header);
508 uves_free_propertylist(&product_header);
509 uves_free_string_const(&starttime);
523 cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING);
524 cpl_errorstate initial_errorstate = cpl_errorstate_get();
528 "Test of MIDAS array conversion");
534 "Test of MIDAS array conversion failed");
541 if (cpl_error_get_code() != CPL_ERROR_NONE)
543 cpl_errorstate_dump(initial_errorstate,CPL_FALSE,NULL);
545 return cpl_test_end(0);
int uves_polynomial_get_dimension(const polynomial *p)
Get the dimension of a polynomial.
void uves_polynomial_delete(polynomial **p)
Delete a polynomial.
void create_order_table(cpl_table **ordertable, polynomial **order_locations, cpl_table **tracetable, int minorder, int maxorder, int nx)
Create order table.
void uves_pfits_set_windownumber(uves_propertylist *plist, int window_number)
Write the window number.
uves_propertylist * uves_propertylist_new(void)
Create an empty property list.
void uves_pfits_set_traceid(uves_propertylist *plist, int trace_id)
Write the trace ID.
double uves_polynomial_evaluate_2d(const polynomial *p, double x1, double x2)
Evaluate a 2d polynomial.
static void convert_midas_array(void)
this function tests reading MIDAS arrays
char * uves_initialize(cpl_frameset *frames, const cpl_parameterlist *parlist, const char *recipe_id, const char *short_descr)
Recipe initialization.
#define uves_error_reset()
void uves_pfits_set_lastabsorder(uves_propertylist *plist, int last_abs_order)
Write the last absolute order number.
static void test_save_frame(void)
test pipeline product creation
static void test_load_linetable(void)
line table input
static void test_save_image(void)
test image output
static void parse_midas_poly(void)
This function tests reading MIDAS polynomials.
void uves_pfits_set_firstabsorder(uves_propertylist *plist, int first_abs_order)
Write the first absolute order number.
void create_line_table(cpl_table **linetable, polynomial **dispersion, polynomial **abs_orders, int *firstabs, int *lastabs, int minorder, int maxorder, int nx)
Create line table.
int main(void)
Various tests of low-level library functions.