171 #include <uves_dfs.h>
172 #include <uves_parameters.h>
173 #include <uves_utils_wrappers.h>
174 #include <uves_test_simulate.h>
175 #include <uves_pfits.h>
176 #include <uves_error.h>
178 #include <cpl_test.h>
210 const char *data[] = {
"",
211 "'COEFFI','I*4',1,7,'7I10'",
212 " 53889 2 3 2 1 4 5",
214 "'COEFFR','R*4',1,5,'5E14.7'",
215 " 4.3300000E+02 4.0880000E+03 1.0000000E+00 2.1000000E+01 0.0000000E+00",
217 "'COEFFD','R*8',1,30,'3E23.15'",
218 " -7.097005629698889E+01 4.050908371864904E-02 -2.886756545398909E-06",
219 " 5.504345508879626E-10 -5.583004967206025E-14 7.624532125635992E+01",
220 " -2.428213567964009E-03 1.819158447566360E-06 -5.090366383338846E-10",
221 " 5.198098506055602E-14 3.513177145982783E-01 5.570332137951829E-04",
222 " -3.876157463910250E-07 1.113253735718822E-10 -1.132455173423791E-14",
223 " 2.977232589499959E-02 -5.389240622889887E-05 3.777456726044612E-08",
224 " -1.083863050648735E-11 1.098450510939580E-15 -1.093309039442914E-03",
225 " 2.402609262989674E-06 -1.688416547941747E-09 4.839101712729582E-13",
226 " -4.884504488944702E-17 1.919853952642526E-05 -4.004133160220927E-08",
227 " 2.816206503824200E-11 -8.051313882805877E-15 8.090579180112579E-19",
229 "'TAB_IN_OUT_YSHIFT','R*8',1,1,'3E23.15'",
230 " 4.180818583555659E+01 ",
235 for (i = 0; i < 8000; i++)
237 uves_propertylist_append_string(
239 " 35834 35835 35836 35837 35838 35839 35840");
242 for (i = 0; i <
sizeof(data)/
sizeof(
char *); i++)
244 uves_propertylist_append_string(
249 check_nomsg( p = uves_polynomial_convert_from_plist_midas(header,
256 uves_free_propertylist(&header);
270 const char *
const filename =
"linetable.fits";
271 cpl_table *linetable_in = NULL;
277 cpl_frame *f = cpl_frame_new();
278 cpl_frameset *frames = cpl_frameset_new();
280 const char *
const chip_id =
"CCD42";
281 cpl_table *ordertable = NULL;
282 cpl_table *tracetable = NULL;
284 int firstabs, lastabs;
285 enum uves_chip chip = UVES_CHIP_BLUE;
294 const char *linetable_filename;
295 cpl_table *linetable_out = NULL;
302 minorder, maxorder, nx));
305 minorder, maxorder, nx));
306 check_nomsg( uves_propertylist_append_string(header, UVES_CHIP_ID(chip), chip_id));
307 check_nomsg( uves_propertylist_append_string(header, UVES_DRS_ID,
"CPL"));
315 check_nomsg( uves_table_save(linetable_in, header, eheader, filename, CPL_IO_DEFAULT) );
316 check_nomsg( uves_save_polynomial(dispersion, filename, eheader) );
317 check_nomsg( uves_save_polynomial(absorder, filename, eheader) );
319 cpl_test_eq(cpl_error_get_code(), CPL_ERROR_NONE);
321 cpl_frame_set_filename(f, filename);
322 cpl_frame_set_tag(f,
"LINE_TABLE_BLUE");
323 cpl_frameset_insert(frames, f);
328 order_locations, minorder, maxorder,
334 chip, trace_id, window));
336 cpl_test_eq(cpl_error_get_code(), CPL_ERROR_NONE);
338 cpl_test( linetable_out != NULL );
339 cpl_test( header_out != NULL );
340 cpl_test( dispersion_out != NULL );
341 cpl_test( absorder_out != NULL );
343 cpl_test_eq( cpl_table_get_nrow(linetable_in),
344 cpl_table_get_nrow(linetable_out) );
350 cpl_test_eq_string( filename, linetable_filename );
356 for (order = minorder; order <= maxorder; order++) {
357 for (x = 1; x <= nx; x += nx/6) {
370 uves_free_frameset(&frames);
371 uves_free_table(&linetable_in);
372 uves_free_table(&linetable_out);
377 uves_free_propertylist(&header_out);
378 uves_free_propertylist(&header);
379 uves_free_propertylist(&eheader);
380 uves_free_table(&ordertable);
381 uves_free_table(&tracetable);
396 const char *values[] = {
"HISTORY",
"",
397 "HISTORY",
"'FIBREPOS','R*8',1,9,'3E23.15'",
398 "HISTORY",
" -3.243571124678650E+01 -2.309646501161805E+01 -1.402902770375962E+01",
399 "HISTORY",
" -4.772375924542811E+00 4.827040349175236E+00 1.378761244187003E+01",
400 "HISTORY",
" 2.321337764943556E+01 3.243571124678650E+01 -3.552713678800501E-15",
402 "HISTORY",
"'COEFFR','R*4',1,20,'5E14.7'",
403 "HISTORY",
"9.4893160E+00 4.0716226E+03 0.0000000E+00 2.3000000E+01 1.8538159E-04",
404 "HISTORY",
"0.0000000E+00 0.0000000E+00 0.0000000E+00 0.0000000E+00 0.0000000E+00",
406 "HISTORY",
"'INTVAL','I",
407 "HISTORY",
"1 2 3 4 5 6",
410 "HISTORY",
"'LEGAL','C",
411 "HISTORY",
" a sdfasdf",
413 "HISTORY",
"'ILLEGAL','C",
417 "HISTORY",
"'CHIPCHOICE','C",
421 int N =
sizeof(values) /
sizeof(
const char *) / 2;
424 double *resultd = NULL;
426 float *resultf = NULL;
427 const char *results = NULL;
428 int result_length, i;
430 cpl_type result_type;
433 for (i = 0; i < N; i++)
435 uves_propertylist_append_string(header, values[i*2], values[i*2+1]);
438 check_nomsg(resultd = uves_read_midas_array(header,
"FIBREPOS", &result_length,
439 &result_type, &nkeys));
441 cpl_test_eq(result_type, CPL_TYPE_DOUBLE);
442 cpl_test_eq(result_length, 9);
443 cpl_test_eq(nkeys, 5);
446 cpl_test_rel(resultd[0], -32, 0.10);
447 cpl_test_rel(resultd[3], -4.7, 0.10);
448 cpl_test_rel(resultd[6], 23, 0.10);
449 cpl_test( fabs(resultd[8]) < 0.001);
452 check_nomsg(resultf = uves_read_midas_array(header,
"COEFFR", &result_length,
453 &result_type, &nkeys));
454 cpl_test_eq(result_type, CPL_TYPE_FLOAT);
455 cpl_test_eq(result_length, 10);
456 cpl_test_eq(nkeys, 4);
458 cpl_test_rel(resultf[0], 9.489, 0.01);
459 cpl_test_rel(resultf[1], 4071, 0.01);
460 cpl_test_abs(resultf[2], 0.000, 0.01);
461 cpl_test_rel(resultf[3], 23.00, 0.01);
464 check_nomsg(resulti = uves_read_midas_array(header,
"INTVAL", &result_length,
465 &result_type, &nkeys));
467 cpl_test_eq(result_type, CPL_TYPE_INT);
468 cpl_test_eq(result_length, 7);
469 cpl_test_eq(nkeys, 4);
470 for (i = 1; i <= 7; i++)
472 cpl_test_eq(resulti[i-1], i);
477 check_nomsg( results = uves_read_midas_array(header,
"LEGAL", &result_length,
478 &result_type, &nkeys) );
480 cpl_test_eq(result_type, CPL_TYPE_STRING);
481 cpl_test_eq(result_length, 10);
482 cpl_test_eq(nkeys, 3);
483 cpl_test_eq_string(results,
" a sdfasdf");
485 cpl_test(uves_read_midas_array(header,
"ILLEGAL2", &result_length,
486 &result_type, &nkeys) == NULL);
489 uves_free_string_const(&results);
490 check_nomsg(results = uves_read_midas_array(header,
"CHIPCHOICE", &result_length,
491 &result_type, &nkeys));
493 cpl_test_eq(result_type, CPL_TYPE_STRING);
494 cpl_test_eq(result_length, 4);
495 cpl_test_eq(nkeys, 3);
496 cpl_test_eq_string(results,
"abcd");
500 uves_free_propertylist(&header);
502 uves_propertylist_append_string(header,
"HISTORY",
"'SELIDX','I*4',1,48389,'7I10'");
503 for (i = 0; i < N; i++)
505 uves_propertylist_append_string(
507 " 64605 64606 64607 64608 64609 64610 64611");
509 uves_propertylist_append_string(header,
"HISTORY",
"");
511 uves_free_int(&resulti);
512 check_nomsg( resulti = uves_read_midas_array(header,
"SELIDX", &result_length,
513 &result_type, &nkeys));
515 cpl_test_eq(result_type, CPL_TYPE_INT);
516 cpl_test_eq(result_length, N*7);
517 cpl_test_eq(nkeys, 1+N+1);
520 uves_free_propertylist(&header);
521 uves_free_double(&resultd);
522 uves_free_int(&resulti);
523 uves_free_float(&resultf);
524 uves_free_string_const(&results);
539 cpl_image *image = cpl_image_new(N, 1, CPL_TYPE_DOUBLE);
541 double inf = DBL_MAX;
542 for (i = 1; i <= N; i++)
544 cpl_image_set(image, i, 1, -FLT_MAX*200);
549 cpl_image_set(image, 1, 1, inf);
550 cpl_image_set(image, 2, 1, inf/inf);
552 uves_save_image(image,
"dfs.fits", NULL,
true,
true);
553 uves_free_image(&image);
566 cpl_frameset *frames = cpl_frameset_new();
567 cpl_parameterlist *parameters = cpl_parameterlist_new();
571 cpl_image *image = cpl_image_new(nx, ny, CPL_TYPE_DOUBLE);
574 const char *starttime;
575 const char *recipe_id =
"uves_cal_phony";
576 const char *tag =
"PHONY_TAG";
577 const char *raw_filename =
"raw_file.fits";
579 uves_define_global_parameters(parameters);
580 cpl_test_eq( cpl_error_get_code(), CPL_ERROR_NONE );
584 cpl_image *raw_image = cpl_image_new(nx, ny, CPL_TYPE_DOUBLE);
585 cpl_frame *raw_frame = cpl_frame_new();
589 for (i = 0; i < nkey; i++)
591 const char *key_name = uves_sprintf(
"KEY%d", i);
592 uves_propertylist_append_int(raw_header, key_name, i);
593 uves_free_string_const(&key_name);
595 uves_propertylist_append_string(raw_header,
"ORIGIN",
"unknown...");
598 uves_image_save(raw_image,
603 cpl_test_eq( cpl_error_get_code(), CPL_ERROR_NONE );
605 uves_free_image(&raw_image);
608 cpl_frame_set_tag(raw_frame,
"BIAS_BLUE");
611 cpl_frame_set_filename(raw_frame, raw_filename);
612 cpl_frameset_insert(frames, raw_frame);
616 "This recipe does not do anything");
617 cpl_test_eq( cpl_error_get_code(), CPL_ERROR_NONE );
619 uves_frameset_insert(frames,
621 CPL_FRAME_GROUP_PRODUCT,
622 CPL_FRAME_TYPE_IMAGE,
623 CPL_FRAME_LEVEL_INTERMEDIATE,
631 PACKAGE
"/" PACKAGE_VERSION,
637 cpl_test_eq( cpl_error_get_code(), CPL_ERROR_NONE );
638 cpl_test( cpl_frameset_find(frames, tag) != NULL);
640 uves_free_frameset(&frames);
641 uves_free_parameterlist(¶meters);
642 uves_free_image(&image);
643 uves_free_propertylist(&raw_header);
644 uves_free_propertylist(&product_header);
645 uves_free_string_const(&starttime);
659 cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING);
660 cpl_errorstate initial_errorstate = cpl_errorstate_get();
664 "Test of MIDAS array conversion");
670 "Test of MIDAS array conversion failed");
677 if (cpl_error_get_code() != CPL_ERROR_NONE)
679 cpl_errorstate_dump(initial_errorstate,CPL_FALSE,NULL);
681 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.