39 #include "hawki_distortion.h"
40 #include "hawki_save.h"
41 #include "hawki_load.h"
42 #include "hawki_pfits.h"
43 #include "hawki_utils.h"
44 #include "hawki_dfs.h"
73 cpl_frameset * allframes,
74 const cpl_parameterlist * parlist,
75 const cpl_frameset * usedframes,
76 const cpl_imagelist * images,
80 const cpl_propertylist * applist,
81 const cpl_propertylist ** applists,
82 const char * filename)
85 cpl_propertylist * pro_list;
86 cpl_type_bpp pixeltype;
92 if (allframes == NULL)
return -1 ;
97 cpl_msg_error(__func__,
"Could not find a suitable reference frame");
102 if (applist != NULL) pro_list = cpl_propertylist_duplicate(applist) ;
103 else pro_list = cpl_propertylist_new() ;
105 cpl_propertylist_append_string(pro_list, CPL_DFS_PRO_TYPE, protype) ;
107 cpl_propertylist_append_string(pro_list, CPL_DFS_PRO_CATG, procat) ;
110 if (cpl_dfs_save_image(allframes, NULL, parlist, usedframes, NULL, NULL,
111 CPL_BPP_IEEE_FLOAT, recipe, pro_list, NULL,
112 PACKAGE
"/" PACKAGE_VERSION,
113 filename) != CPL_ERROR_NONE) {
114 cpl_msg_error(__func__,
"Cannot save the empty primary HDU of file %s",
116 cpl_propertylist_delete(pro_list);
121 cpl_propertylist_delete(pro_list);
124 if (cpl_image_get_type(cpl_imagelist_get_const(images, 0)) == CPL_TYPE_INT)
125 pixeltype = CPL_BPP_32_SIGNED ;
127 pixeltype = CPL_BPP_IEEE_FLOAT ;
130 for (iext=0 ; iext<HAWKI_NB_DETECTORS ; iext++) {
131 cpl_propertylist * qc_ext_list;
135 cpl_msg_error(__func__,
"Cannot get the chip for extension %d when "
136 "writing file %s", iext+1, filename);
139 if ((applists != NULL) && (applists[chip_nb-1] != NULL))
140 qc_ext_list = cpl_propertylist_duplicate(applists[chip_nb-1]) ;
142 qc_ext_list = cpl_propertylist_new() ;
144 snprintf(sval, 16,
"CHIP%d.INT1", chip_nb) ;
145 cpl_propertylist_prepend_string(qc_ext_list,
"EXTNAME", sval) ;
146 if(cpl_image_save(cpl_imagelist_get_const(images, chip_nb-1), filename,
147 pixeltype, qc_ext_list, CPL_IO_EXTEND) != CPL_ERROR_NONE)
149 cpl_msg_error(__func__,
"Cannot save extension %d of file %s",
151 cpl_propertylist_delete(qc_ext_list) ;
154 cpl_propertylist_delete(qc_ext_list) ;
178 (cpl_frameset * allframes,
179 const cpl_parameterlist * parlist,
180 const cpl_frameset * usedframes,
183 const char * protype,
184 const cpl_propertylist * applist,
185 const char * filename)
187 cpl_propertylist * pro_list;
190 if (allframes == NULL)
return -1 ;
193 if (applist != NULL) pro_list = cpl_propertylist_duplicate(applist) ;
194 else pro_list = cpl_propertylist_new() ;
196 cpl_propertylist_append_string(pro_list, CPL_DFS_PRO_TYPE, protype) ;
198 cpl_propertylist_append_string(pro_list, CPL_DFS_PRO_CATG, procat) ;
201 if (cpl_dfs_save_image(allframes, NULL, parlist, usedframes, NULL, NULL,
202 CPL_BPP_IEEE_FLOAT, recipe, pro_list, NULL,
203 PACKAGE
"/" PACKAGE_VERSION,
204 filename) != CPL_ERROR_NONE) {
205 cpl_msg_error(__func__,
"Cannot save the empty primary HDU of file %s",
207 cpl_propertylist_delete(pro_list);
212 cpl_propertylist_delete(pro_list);
227 (
const cpl_frameset * allframes,
228 const cpl_image * image,
230 const cpl_propertylist * ext_prop_list,
231 const char * filename)
234 cpl_type_bpp pixeltype;
235 cpl_propertylist * ext_prop;
240 if (allframes == NULL)
return -1 ;
245 cpl_msg_error(__func__,
"Could not find a suitable reference frame");
250 if (cpl_image_get_type(image) == CPL_TYPE_INT)
251 pixeltype = CPL_BPP_32_SIGNED ;
253 pixeltype = CPL_BPP_IEEE_FLOAT ;
258 cpl_msg_error(__func__,
"Cannot get the chip id for extension %d "
259 "when saving %s", iext, filename);
262 if (ext_prop_list != NULL)
263 ext_prop = cpl_propertylist_duplicate(ext_prop_list) ;
265 ext_prop = cpl_propertylist_new() ;
267 snprintf(sval, 16,
"CHIP%d.INT1", idet) ;
268 cpl_propertylist_prepend_string(ext_prop,
"EXTNAME", sval) ;
269 if(cpl_image_save(image, filename,
270 pixeltype, ext_prop, CPL_IO_EXTEND) != CPL_ERROR_NONE)
272 cpl_msg_error(__func__,
"Could not save extension %d of file %s",
274 cpl_propertylist_delete(ext_prop);
277 cpl_propertylist_delete(ext_prop) ;
303 cpl_frameset * allframes,
304 const cpl_parameterlist * parlist,
305 const cpl_frameset * usedframes,
306 const cpl_image ** images,
309 const char * protype,
310 const cpl_propertylist * applist,
311 const cpl_propertylist ** applists,
312 const char * filename)
315 cpl_propertylist * pro_list ;
316 cpl_type_bpp pixeltype ;
317 cpl_propertylist * qc_ext_list ;
323 if (allframes == NULL)
return -1 ;
328 cpl_msg_error(__func__,
"Could not find a suitable reference frame");
333 if (applist != NULL) pro_list = cpl_propertylist_duplicate(applist) ;
334 else pro_list = cpl_propertylist_new() ;
336 cpl_propertylist_append_string(pro_list, CPL_DFS_PRO_TYPE, protype) ;
338 cpl_propertylist_append_string(pro_list, CPL_DFS_PRO_CATG, procat) ;
341 if (cpl_dfs_save_image(allframes, NULL, parlist, usedframes, NULL, NULL,
342 CPL_BPP_IEEE_FLOAT, recipe, pro_list, NULL,
343 PACKAGE
"/" PACKAGE_VERSION,
344 filename) != CPL_ERROR_NONE) {
345 cpl_msg_error(__func__,
"Cannot save the empty primary HDU of file %s",
347 cpl_propertylist_delete(pro_list) ;
352 cpl_propertylist_delete(pro_list) ;
355 if (cpl_image_get_type(images[0]) == CPL_TYPE_INT)
356 pixeltype = CPL_BPP_32_SIGNED ;
358 pixeltype = CPL_BPP_IEEE_FLOAT ;
361 for (iext=0 ; iext<HAWKI_NB_DETECTORS ; iext++) {
364 cpl_msg_error(__func__,
"Cannot get the chip for extension %d "
365 "when saving file %s", iext+1, filename);
369 if ((applists != NULL) && (applists[chip_nb-1] != NULL))
370 qc_ext_list = cpl_propertylist_duplicate(applists[chip_nb-1]) ;
372 qc_ext_list = cpl_propertylist_new() ;
374 snprintf(sval, 16,
"CHIP%d.INT1", chip_nb) ;
375 cpl_propertylist_prepend_string(qc_ext_list,
"EXTNAME", sval) ;
376 if(cpl_image_save(images[chip_nb-1], filename,
377 pixeltype, qc_ext_list, CPL_IO_EXTEND) != CPL_ERROR_NONE)
379 cpl_msg_error(__func__,
"Cannot save extension %d of file %s",
381 cpl_propertylist_delete(qc_ext_list);
384 cpl_propertylist_delete(qc_ext_list) ;
407 cpl_frameset * allframes,
408 const cpl_parameterlist * parlist,
409 const cpl_frameset * usedframes,
410 const cpl_table ** tables,
413 const char * protype,
414 const cpl_propertylist * applist,
415 const cpl_propertylist ** applists,
416 const char * filename)
418 cpl_propertylist * qc_ext_list ;
419 cpl_propertylist * pro_list ;
426 if (allframes == NULL)
return -1 ;
431 cpl_msg_error(__func__,
"Could not find a suitable reference frame");
436 if (applist != NULL) pro_list = cpl_propertylist_duplicate(applist) ;
437 else pro_list = cpl_propertylist_new() ;
439 cpl_propertylist_append_string(pro_list, CPL_DFS_PRO_TYPE, protype) ;
441 cpl_propertylist_append_string(pro_list, CPL_DFS_PRO_CATG, procat) ;
444 if ((applists != NULL) && (applists[0] != NULL))
445 qc_ext_list = cpl_propertylist_duplicate(applists[0]) ;
447 qc_ext_list = cpl_propertylist_new() ;
448 cpl_propertylist_prepend_string(qc_ext_list,
"EXTNAME",
"CHIP1.INT1") ;
449 if (cpl_dfs_save_table(allframes, NULL, parlist, usedframes, NULL, tables[0],
450 qc_ext_list, recipe, pro_list, NULL,
451 PACKAGE
"/" PACKAGE_VERSION,
452 filename) != CPL_ERROR_NONE) {
453 cpl_msg_error(__func__,
454 "Cannot save the first extension table of file %s", filename);
455 cpl_propertylist_delete(qc_ext_list) ;
456 cpl_propertylist_delete(pro_list) ;
459 cpl_propertylist_delete(qc_ext_list) ;
460 cpl_propertylist_delete(pro_list) ;
463 for (iext=1 ; iext<HAWKI_NB_DETECTORS; iext++) {
466 cpl_msg_error(__func__,
"Cannot get the chip for extension %d "
467 "when writing file %s", iext+1, filename);
470 if ((applists != NULL) && (applists[chip_nb-1] != NULL))
471 qc_ext_list = cpl_propertylist_duplicate(applists[chip_nb-1]) ;
473 qc_ext_list = cpl_propertylist_new() ;
475 snprintf(sval, 16,
"CHIP%d.INT1", chip_nb) ;
476 cpl_propertylist_prepend_string(qc_ext_list,
"EXTNAME", sval) ;
477 if(cpl_table_save(tables[chip_nb-1], NULL, qc_ext_list, filename,
478 CPL_IO_EXTEND) != CPL_ERROR_NONE)
480 cpl_msg_error(__func__,
"Cannot save extension %d of table %s",
482 cpl_propertylist_delete(qc_ext_list) ;
486 cpl_propertylist_delete(qc_ext_list) ;
514 (cpl_frameset * allframes,
515 const cpl_parameterlist * parlist,
516 const cpl_frameset * usedframes,
517 const hawki_distortion ** distortion,
519 const cpl_propertylist * applist,
520 const cpl_propertylist ** applists,
521 const char * filename_x,
522 const char * filename_y)
525 cpl_propertylist * pro_list_x;
526 cpl_propertylist * pro_list_y;
527 cpl_type_bpp pixeltype ;
528 cpl_propertylist * qc_ext_list ;
534 if (allframes == NULL)
return -1 ;
539 cpl_msg_error(__func__,
"Could not find a suitable reference frame");
545 pro_list_x = cpl_propertylist_duplicate(applist);
547 pro_list_x = cpl_propertylist_new();
549 pro_list_y = cpl_propertylist_duplicate(applist);
551 pro_list_y = cpl_propertylist_new();
553 cpl_propertylist_append_string(pro_list_x, CPL_DFS_PRO_TYPE,
554 HAWKI_PROTYPE_DISTORTION_X);
555 cpl_propertylist_append_string(pro_list_y, CPL_DFS_PRO_TYPE,
556 HAWKI_PROTYPE_DISTORTION_Y);
557 cpl_propertylist_append_string(pro_list_x, CPL_DFS_PRO_CATG,
558 HAWKI_CALPRO_DISTORTION_X);
559 cpl_propertylist_append_string(pro_list_y, CPL_DFS_PRO_CATG,
560 HAWKI_CALPRO_DISTORTION_Y);
563 if (cpl_dfs_save_image(allframes, NULL, parlist, usedframes, NULL, NULL,
564 CPL_BPP_IEEE_FLOAT, recipe, pro_list_x, NULL,
565 PACKAGE
"/" PACKAGE_VERSION,
566 filename_x) != CPL_ERROR_NONE) {
567 cpl_msg_error(__func__,
"Cannot save the empty primary HDU of file %s",
569 cpl_propertylist_delete(pro_list_x);
570 cpl_propertylist_delete(pro_list_y);
573 if (cpl_dfs_save_image(allframes, NULL, parlist, usedframes, NULL, NULL,
574 CPL_BPP_IEEE_FLOAT, recipe, pro_list_y, NULL,
575 PACKAGE
"/" PACKAGE_VERSION,
576 filename_y) != CPL_ERROR_NONE) {
577 cpl_msg_error(__func__,
"Cannot save the empty primary HDU of file %s",
579 cpl_propertylist_delete(pro_list_x);
580 cpl_propertylist_delete(pro_list_y);
585 cpl_propertylist_delete(pro_list_x);
586 cpl_propertylist_delete(pro_list_y);
589 if (cpl_image_get_type(distortion[0]->dist_x) == CPL_TYPE_INT)
590 pixeltype = CPL_BPP_32_SIGNED ;
592 pixeltype = CPL_BPP_IEEE_FLOAT ;
595 for (iext=0 ; iext<HAWKI_NB_DETECTORS ; iext++) {
598 cpl_msg_error(__func__,
"Cannot get the chip for extension %d "
599 "when saving %s and %s", iext+1, filename_x, filename_y);
603 if ((applists != NULL) && (applists[chip_nb-1] != NULL))
604 qc_ext_list = cpl_propertylist_duplicate(applists[chip_nb-1]) ;
606 qc_ext_list = cpl_propertylist_new() ;
609 cpl_propertylist_prepend_double(qc_ext_list,
"CRPIX2", 1);
610 cpl_propertylist_prepend_double(qc_ext_list,
"CDELT2",
611 distortion[chip_nb-1]->y_cdelt);
612 cpl_propertylist_prepend_double(qc_ext_list,
"CRVAL2",
613 distortion[chip_nb-1]->y_crval);
614 cpl_propertylist_prepend_double(qc_ext_list,
"CRPIX1", 1);
615 cpl_propertylist_prepend_double(qc_ext_list,
"CDELT1",
616 distortion[chip_nb-1]->x_cdelt);
617 cpl_propertylist_prepend_double(qc_ext_list,
"CRVAL1",
618 distortion[chip_nb-1]->x_crval);
620 snprintf(sval, 16,
"CHIP%d.INT1", chip_nb) ;
621 cpl_propertylist_prepend_string(qc_ext_list,
"EXTNAME", sval) ;
622 if(cpl_image_save(distortion[chip_nb-1]->dist_x, filename_x,
623 pixeltype, qc_ext_list, CPL_IO_EXTEND) != CPL_ERROR_NONE)
625 cpl_msg_error(__func__,
"Cannot save extension %d of file %s",
627 cpl_propertylist_delete(qc_ext_list);
630 if(cpl_image_save(distortion[chip_nb-1]->dist_y, filename_y,
631 pixeltype, qc_ext_list, CPL_IO_EXTEND) != CPL_ERROR_NONE)
633 cpl_msg_error(__func__,
"Cannot save extension %d of file %s",
635 cpl_propertylist_delete(qc_ext_list);
638 cpl_propertylist_delete(qc_ext_list) ;
659 const char * fname = NULL;
661 for(iframe = 0 ; iframe < cpl_frameset_get_size(frameset); ++iframe)
663 const cpl_frame * frame;
665 frame = cpl_frameset_get_frame_const(frameset, iframe);
669 if(cpl_frame_get_group(frame) == CPL_FRAME_GROUP_RAW &&
670 cpl_frame_get_nextensions(frame) == HAWKI_NB_DETECTORS)
672 fname = cpl_frame_get_filename(frame);
680 for(iframe = 0 ; iframe < cpl_frameset_get_size(frameset); ++iframe)
682 const cpl_frame * frame;
684 frame = cpl_frameset_get_frame_const(frameset, iframe);
688 if(cpl_frame_get_group(frame) == CPL_FRAME_GROUP_PRODUCT &&
689 cpl_frame_get_nextensions(frame) == HAWKI_NB_DETECTORS)
691 fname = cpl_frame_get_filename(frame);
696 fname = cpl_frame_get_filename(cpl_frameset_get_first_const(frameset));