ERIS Pipeline Reference Manual 1.9.2
eris_ifu_debug.c
1#ifdef HAVE_CONFIG_H
2#include <config.h>
3#endif
4
5#include <string.h>
6
7#include <cpl.h>
8
9#include "eris_ifu_debug.h"
10#include "eris_ifu_error.h"
11
12/*----------------------------------------------------------------------------*/
25/*----------------------------------------------------------------------------*/
26
29/*----------------------------------------------------------------------------*/
45/*----------------------------------------------------------------------------*/
46cpl_error_code eris_ifu_debug_header(const cpl_propertylist *header)
47{
48 int i = 0;
49 const cpl_property *p = NULL;
50 cpl_type t;
51 cpl_error_code ret_error = CPL_ERROR_NONE;
52
53 TRY
54 {
55 cpl_msg_debug("", "===== START HEADER =====");
56 if (header == NULL) {
57 cpl_msg_warning("", "Empty header!");
58 } else {
59 for (i = 0; i < cpl_propertylist_get_size(header); i++) {
61 p = cpl_propertylist_get_const(header, i));
62
63 t = cpl_property_get_type (p);
65 switch (t) {
66 case CPL_TYPE_BOOL:
67 cpl_msg_debug("", "%s: %d", cpl_property_get_name(p),
68 cpl_property_get_bool(p));
69 break;
70 case CPL_TYPE_INT:
71 cpl_msg_debug("", "%s: %d", cpl_property_get_name(p),
72 cpl_property_get_int(p));
73 break;
74 case CPL_TYPE_DOUBLE:
75 cpl_msg_debug("", "%s: %12.16g", cpl_property_get_name(p),
76 cpl_property_get_double(p));
77 break;
78 case CPL_TYPE_FLOAT:
79 cpl_msg_debug("", "%s: %12.16f", cpl_property_get_name(p),
80 cpl_property_get_float(p));
81 break;
82 case CPL_TYPE_STRING:
83 cpl_msg_debug("", "%s: %s", cpl_property_get_name(p),
84 cpl_property_get_string(p));
85 break;
86 default:
87 break;
88 }
89 }
90 }
91 cpl_msg_debug("", "====== END HEADER ======");
93 }
94 CATCH
95 {
96 CATCH_MSG();
97 ret_error = cpl_error_get_code();
98 }
99
100 return ret_error;
101}
102
103/*----------------------------------------------------------------------------*/
117/*----------------------------------------------------------------------------*/
118cpl_error_code eris_ifu_debug_frameset(const cpl_frameset *frameset)
119{
120 const cpl_frame *frame = NULL; /* must not be deleted at the end */
121 cpl_error_code ret_error = CPL_ERROR_NONE;
122
123 TRY
124 {
125 cpl_msg_debug("", "====== START FRAMESET ======");
126 if (frameset == NULL) {
127 cpl_msg_warning("", "Empty frameset!");
128 } else {
129 frame = cpl_frameset_find_const(frameset, NULL);
130
131 if (GET_NEW_ERROR(void) != CPL_ERROR_NONE) {
132 RECOVER();
133
134 cpl_msg_debug("", "====== END FRAMESET ======");
135
136 return CPL_ERROR_NONE;
137 }
138
139 while (frame != NULL) {
142 frame = cpl_frameset_find_const(frameset, NULL));
143 }
144 }
145 cpl_msg_debug("", "====== END FRAMESET ======");
147 }
148 CATCH
149 {
150 CATCH_MSG();
151 ret_error = cpl_error_get_code();
152 }
153
154 return ret_error;
155}
156
157/*----------------------------------------------------------------------------*/
173/*----------------------------------------------------------------------------*/
174cpl_error_code eris_ifu_debug_parameterlist(const cpl_parameterlist *plist)
175{
176 cpl_error_code ret_error = CPL_ERROR_NONE;
177 const cpl_parameter *par = NULL;
178 const char* name = NULL;
179 int intVal;
180 int intDef;
181 double dblVal;
182 double dblDef;
183 const char *strVal;
184 const char *strDef;
185
186 TRY
187 {
188 cpl_msg_debug("", "====== START PARAMETERLIST ======");
189 if (plist == NULL) {
190 cpl_msg_warning("", "Empty parameterlist!");
191 } else {
192 printf("Number of elements in parameter list: %lld\n",
193 cpl_parameterlist_get_size(plist));
194 par = cpl_parameterlist_get_first_const(plist);
195 while (par != NULL) {
196 name = cpl_parameter_get_name(par);
197 switch(cpl_parameter_get_type(par)) {
198 case CPL_TYPE_BOOL:
199 intVal = cpl_parameter_get_bool(par);
200 intDef = cpl_parameter_get_default_bool(par);
201 printf("Parameter %s: %d [%d]\n", name, intVal, intDef);
202 break;
203 case CPL_TYPE_INT:
204 intVal = cpl_parameter_get_int(par);
205 intDef = cpl_parameter_get_default_int(par);
206 printf("Parameter %s: %d [%d]\n", name, intVal, intDef);
207 break;
208 case CPL_TYPE_DOUBLE:
209 dblVal = cpl_parameter_get_double(par);
210 dblDef = cpl_parameter_get_default_double(par);
211 printf("Parameter %s: %f [%f]\n", name, dblVal, dblDef);
212 break;
213 case CPL_TYPE_STRING:
214 strVal = cpl_parameter_get_string(par);
215 strDef = cpl_parameter_get_default_string(par);
216 printf("Parameter %s: %s [%s]\n", name, strVal, strDef);
217 break;
218 default:
219 BRK_WITH_ERROR(CPL_ERROR_INVALID_TYPE);
220 break;
221 }
222 par = cpl_parameterlist_get_next_const(plist);
223 }
224 }
225 cpl_msg_debug("", "====== END PARAMETERLIST ======");
227 }
228 CATCH
229 {
230 CATCH_MSG();
231 ret_error = cpl_error_get_code();
232 }
233
234 return ret_error;
235}
236
237/*----------------------------------------------------------------------------*/
249/*----------------------------------------------------------------------------*/
250cpl_error_code eris_ifu_debug_propertylist(const cpl_propertylist *plist)
251{
252 cpl_error_code ret_error = CPL_ERROR_NONE;
253
254 TRY
255 {
256 cpl_msg_debug("", "====== START PROPERTYLIST ======");
257 if (plist == NULL) {
258 cpl_msg_warning("", "Empty propertylist!");
259 } else {
260
261 cpl_propertylist_dump(plist, NULL);
262 }
263 cpl_msg_debug("", "====== END PROPERTYLIST ======");
265 }
266 CATCH
267 {
268 CATCH_MSG();
269 ret_error = cpl_error_get_code();
270 }
271
272 return ret_error;
273
274}
275
276/*----------------------------------------------------------------------------*/
288/*----------------------------------------------------------------------------*/
289cpl_error_code eris_ifu_debug_frame(const cpl_frame *frame)
290{
291 const char *tmp = NULL;
292 int i = 0;
293 cpl_error_code ret_error = CPL_ERROR_NONE;
294
295 TRY
296 {
297 cpl_msg_debug("", " ====== START FRAME ======");
298 if (frame == NULL) {
299 cpl_msg_warning("", "Empty frame!");
300 } else {
301 tmp = cpl_frame_get_filename(frame);
302
303 if (GET_NEW_ERROR(void) != CPL_ERROR_NONE) {
304
305 RECOVER();
306 cpl_msg_debug("", " ====== END FRAME ======");
307 return CPL_ERROR_NONE;
308 }
309
310 cpl_msg_debug("", "filename: %s", tmp);
311 cpl_msg_debug("", "tag: %s", cpl_frame_get_tag(frame));
312
313 i = cpl_frame_get_type(frame);
315 switch(i) {
316 case CPL_FRAME_TYPE_NONE:
317 cpl_msg_debug("", "type: CPL_FRAME_TYPE_NONE (%d)", i);
318 break;
319 case CPL_FRAME_TYPE_IMAGE:
320 cpl_msg_debug("", "type: CPL_FRAME_TYPE_IMAGE (%d)", i);
321 break;
322 case CPL_FRAME_TYPE_MATRIX:
323 cpl_msg_debug("", "type: CPL_FRAME_TYPE_MATRIX (%d)", i);
324 break;
325 case CPL_FRAME_TYPE_TABLE:
326 cpl_msg_debug("", "type: CPL_FRAME_TYPE_TABLE (%d)", i);
327 break;
328 case CPL_FRAME_TYPE_PAF:
329 cpl_msg_debug("", "type: CPL_FRAME_TYPE_PAF (%d)", i);
330 break;
331 case CPL_FRAME_TYPE_ANY:
332 cpl_msg_debug("", "type: CPL_FRAME_TYPE_ANY (%d)", i);
333 break;
334 default:
335 cpl_msg_debug("", "type: other ERROR (%d)", i);
336 }
337
338 i = cpl_frame_get_group(frame);
340 switch(i) {
341 case CPL_FRAME_GROUP_NONE:
342 cpl_msg_debug("", "group: CPL_FRAME_GROUP_NONE (%d)", i);
343 break;
344 case CPL_FRAME_GROUP_RAW:
345 cpl_msg_debug("", "group: CPL_FRAME_GROUP_RAW (%d)", i);
346 break;
347 case CPL_FRAME_GROUP_CALIB:
348 cpl_msg_debug("", "group: CPL_FRAME_GROUP_CALIB (%d)", i);
349 break;
350 case CPL_FRAME_GROUP_PRODUCT:
351 cpl_msg_debug("", "group: CPL_FRAME_GROUP_PRODUCT (%d)", i);
352 break;
353 default:
354 cpl_msg_debug("", "group: other ERROR (%d)", i);
355 }
356
357 i = cpl_frame_get_level(frame);
359 switch(i) {
360 case CPL_FRAME_GROUP_NONE:
361 cpl_msg_debug("", "level: CPL_FRAME_LEVEL_NONE (%d)", i);
362 break;
363 case CPL_FRAME_GROUP_RAW:
364 cpl_msg_debug("", "level: CPL_FRAME_LEVEL_TEMPORARY (%d)", i);
365 break;
366 case CPL_FRAME_GROUP_CALIB:
367 cpl_msg_debug("", "level: CPL_FRAME_LEVEL_INTERMEDIATE (%d)", i);
368 break;
369 case CPL_FRAME_GROUP_PRODUCT:
370 cpl_msg_debug("", "level: CPL_FRAME_LEVEL_FINAL (%d)", i);
371 break;
372 default:
373 cpl_msg_debug("", "level: other ERROR (%d)", i);
374 }
375 }
376 cpl_msg_debug("", " ====== END FRAME ======");
378 }
379 CATCH
380 {
381 CATCH_MSG();
382 ret_error = cpl_error_get_code();
383 }
384
385 return ret_error;
386}
387
388/*----------------------------------------------------------------------------*/
403/*----------------------------------------------------------------------------*/
404cpl_error_code eris_ifu_debug_cube(const cpl_imagelist *imglist)
405{
406 int i = 0;
407 cpl_error_code ret_error = CPL_ERROR_NONE;
408
409 TRY
410 {
411 cpl_msg_debug("", "====== START IMAGELIST ======");
412 if (imglist == NULL) {
413 cpl_msg_warning("", "Empty cube!");
414 } else {
415 for (i = 0; i < cpl_imagelist_get_size(imglist); i++) {
417 eris_ifu_debug_image(cpl_imagelist_get_const(imglist, i)));
418 }
419 }
420 cpl_msg_debug("", "====== END IMAGELIST ======");
422 }
423 CATCH
424 {
425 CATCH_MSG();
426 ret_error = cpl_error_get_code();
427 }
428
429 return ret_error;
430}
431
432/*----------------------------------------------------------------------------*/
448/*----------------------------------------------------------------------------*/
449cpl_error_code eris_ifu_debug_image(const cpl_image *img)
450{
451 int x = 0,
452 y = 0;
453 int gaga = 0;
454 cpl_error_code ret_error = CPL_ERROR_NONE;
455 char line[200000],
456 tmp[2048];
457
458 TRY
459 {
460 cpl_msg_debug("", " ====== START IMAGE ======");
461 if (img == NULL) {
462 cpl_msg_warning("", "Empty image!");
463 } else {
464 strcpy(line, " ");
465 for (y = 1; y <= cpl_image_get_size_y(img); y++) {
466 for (x = 1; x <= cpl_image_get_size_x(img); x++) {
467 sprintf(tmp, "%f ", cpl_image_get(img, x, y, &gaga));
468 strcat(line, tmp);
470 }
471 strcat(line, "");
472 cpl_msg_debug("", "%s", line);
473 }
474 }
475 cpl_msg_debug("", " ====== END IMAGE ======");
477 }
478 CATCH
479 {
480 CATCH_MSG();
481 ret_error = cpl_error_get_code();
482 }
483
484 return ret_error;
485}
486
487/*----------------------------------------------------------------------------*/
499/*----------------------------------------------------------------------------*/
500cpl_error_code eris_ifu_debug_vector(const cpl_vector *vec)
501{
502 int x = 0;
503 cpl_size size = 0;
504 cpl_error_code ret_error = CPL_ERROR_NONE;
505 const double *pvec = NULL;
506
507 TRY
508 {
509 cpl_msg_debug("", " ====== START VECTOR ======");
510 if (vec == NULL) {
511 cpl_msg_warning("", "Empty vector!");
512 } else {
514 pvec = cpl_vector_get_data_const(vec));
515
516 size = cpl_vector_get_size(vec);
517 for (x = 0; x < size; x++) {
518 cpl_msg_debug("", "%12.16g ", pvec[x]);
519 }
520 }
521 cpl_msg_debug("", " ====== END VECTOR ======");
523 }
524 CATCH
525 {
526 CATCH_MSG();
527 ret_error = cpl_error_get_code();
528 }
529
530 return ret_error;
531}
532
533
534/*----------------------------------------------------------------------------*/
548/*----------------------------------------------------------------------------*/
549cpl_error_code eris_ifu_debug_array(const cpl_array *arr)
550{
551 int x = 0;
552 cpl_size size = 0;
553 const int *pint = NULL;
554 const double *pdouble = NULL;
555 cpl_error_code ret_error = CPL_ERROR_NONE;
556 cpl_type type;
557
558 TRY
559 {
560 if (arr != NULL) {
561 type = cpl_array_get_type(arr);
562 size = cpl_array_get_size(arr);
563
564 switch (type) {
565 case CPL_TYPE_INT:
566 pint = cpl_array_get_data_int_const(arr);
567 cpl_msg_debug("", " ====== START ARRAY ======");
568 if (arr== NULL) {
569 cpl_msg_warning("", "Empty array!");
570 } else {
571 for (x = 0; x < size; x++) {
572 cpl_msg_debug("", "%i", pint[x]);
573 }
574 }
575 cpl_msg_debug("", " ====== END ARRAY ======");
576 break;
577 case CPL_TYPE_DOUBLE:
578 pdouble = cpl_array_get_data_double_const(arr);
579 cpl_msg_debug("", " ====== START ARRAY ======");
580 if (arr== NULL) {
581 cpl_msg_warning("", "Empty array!");
582 } else {
583 for (x = 0; x < size; x++) {
584 cpl_msg_debug("", "%12.16g", pdouble[x]);
585 }
586 }
587 cpl_msg_debug("", " ====== END ARRAY ======");
588 break;
589 default:
590 cpl_msg_debug("", ">>> cpl_type (%d) not supported!", type);
591 break;
592 }
594 } else {
595 cpl_msg_debug("", " ====== START ARRAY ======");
596 cpl_msg_debug("", "Empty array!");
597 cpl_msg_debug("", " ====== END ARRAY ======");
598 }
599 }
600 CATCH
601 {
602 CATCH_MSG();
603 ret_error = cpl_error_get_code();
604 }
605
606 return ret_error;
607}
608
609/*----------------------------------------------------------------------------*/
621/*----------------------------------------------------------------------------*/
622cpl_error_code eris_ifu_debug_table(const cpl_table *table)
623{
624 cpl_error_code ret_error = CPL_ERROR_NONE;
625
626 TRY
627 {
628 cpl_msg_debug("", " ====== START TABLE ======");
629 if (table == NULL) {
630 cpl_msg_warning("", "Empty table pointer!");
631 } else {
632 cpl_table_dump(table, 0, cpl_table_get_nrow(table), NULL);
633 }
634 cpl_msg_debug("", " ====== END TABLE ======");
636 }
637 CATCH
638 {
639 CATCH_MSG();
640 ret_error = cpl_error_get_code();
641 }
642
643 return ret_error;
644}
645
646/*----------------------------------------------------------------------------*/
664/*----------------------------------------------------------------------------*/
665cpl_error_code eris_ifu_plot_vector(const char *pre, const char *opt,
666 const cpl_vector *vector)
667{
668 cpl_error_code ret_error = CPL_ERROR_NONE;
669
670 char *ostype = NULL,
671 pre_final[1024];
672
673 TRY
674 {
675 if ((vector != NULL) &&
676 (cpl_msg_get_level() == CPL_MSG_DEBUG))
677 {
678 strcpy(pre_final, "");
679 if (pre != NULL) {
680 strcat(pre_final, pre);
681 }
682 ostype = getenv("OSTYPE");
683 if(strcmp(ostype, "darwin") == 0) {
684 strcat(pre_final, "set term x11;");
685 }
686
688 cpl_plot_vector(pre_final, opt, NULL, vector));
689 }
690 }
691 CATCH
692 {
693 CATCH_MSG();
694 ret_error = cpl_error_get_code();
695 }
696
697 return ret_error;
698}
699
700/*----------------------------------------------------------------------------*/
719/*----------------------------------------------------------------------------*/
720cpl_error_code eris_ifu_plot_vectors_xy(const char *pre, const char *opt,
721 const cpl_vector *x, const cpl_vector *y)
722{
723 cpl_error_code ret_error = CPL_ERROR_NONE;
724
725 cpl_bivector *bi = NULL;
726
727 char *ostype = NULL,
728 pre_final[1024];
729
730 TRY
731 {
732 if ((x != NULL) && (y != NULL) &&
733 (cpl_msg_get_level() == CPL_MSG_DEBUG))
734 {
735 strcpy(pre_final, "");
736 if (pre != NULL) {
737 strcat(pre_final, pre);
738 }
739 ostype = getenv("OSTYPE");
740 if(strcmp(ostype, "darwin") == 0) {
741 strcat(pre_final, "set term x11;");
742 }
743// The function cpl_bivector_wrap_vectors will discard the const qualifier
744// However as it is know that cpl_plot_bivector will not modifiy its
745// bivector argument it is save to turn off the compiler warning
746
747#ifdef __GNUC__
748#pragma GCC diagnostic push
749#pragma GCC diagnostic ignored "-Wcast-qual"
750#endif
752 bi = cpl_bivector_wrap_vectors((cpl_vector*)x,
753 (cpl_vector*)y));
754#ifdef __GNUC__
755#pragma GCC diagnostic pop
756#endif
758 cpl_plot_bivector(pre_final, opt, NULL, bi));
759
760 cpl_bivector_unwrap_vectors(bi);
761 }
762 }
763 CATCH
764 {
765 CATCH_MSG();
766 ret_error = cpl_error_get_code();
767 }
768
769 return ret_error;
770}
771
772/*----------------------------------------------------------------------------*/
792/*----------------------------------------------------------------------------*/
793cpl_error_code eris_ifu_plot_vectors2(const char *pre, const char **opt,
794 const cpl_vector *x,
795 const cpl_vector *y1,
796 const cpl_vector *y2)
797{
798 cpl_error_code ret_error = CPL_ERROR_NONE;
799
800 int nr_plots = 2;
801 cpl_bivector *plots[nr_plots];
802 char *ostype = NULL,
803 pre_final[1024];
804
805 TRY
806 {
807 if ((x != NULL) && (y1 != NULL) && (y2 != NULL) &&
808 (cpl_msg_get_level() == CPL_MSG_DEBUG))
809 {
810 strcpy(pre_final, "");
811 if (pre != NULL) {
812 strcat(pre_final, pre);
813 }
814 ostype = getenv("OSTYPE");
815 if(strcmp(ostype, "darwin") == 0) {
816 strcat(pre_final, "set term x11;");
817 }
818
819 // The function cpl_bivector_wrap_vectors will discard the const qualifier
820 // However as it is know that cpl_plot_bivector will not modifiy its
821 // bivector argument it is save to turn off the compiler warning
822
823#ifdef __GNUC__
824#pragma GCC diagnostic push
825#pragma GCC diagnostic ignored "-Wcast-qual"
826#endif
828 plots[0] = cpl_bivector_wrap_vectors((cpl_vector*)x,
829 (cpl_vector*)y1));
831 plots[1] = cpl_bivector_wrap_vectors((cpl_vector*)x,
832 (cpl_vector*)y2));
833
835 cpl_plot_bivectors(pre_final,
836 (const char**)opt,
837 "",
838 (const cpl_bivector **) plots,
839 nr_plots));
840#ifdef __GNUC__
841#pragma GCC diagnostic pop
842#endif
843
844 int k = 0;
845 for (k = 0; k < nr_plots; k++) {
846 cpl_bivector_unwrap_vectors(plots[k]);
847 }
849 }
850 }
851 CATCH
852 {
853 CATCH_MSG();
854 ret_error = cpl_error_get_code();
855 }
856
857 return ret_error;
858}
859
860/*----------------------------------------------------------------------------*/
877/*----------------------------------------------------------------------------*/
878cpl_error_code eris_ifu_plot_image(const char *pre, const char *opt,
879 const cpl_image *img)
880{
881 cpl_error_code ret_error = CPL_ERROR_NONE;
882
883 char *ostype = NULL,
884 pre_final[1024];
885
886 TRY
887 {
888 if ((img != NULL) &&
889 (cpl_msg_get_level() == CPL_MSG_DEBUG))
890 {
891 strcpy(pre_final, "");
892 if (pre != NULL) {
893 strcat(pre_final, pre);
894 }
895 ostype = getenv("OSTYPE");
896 if(strcmp(ostype, "darwin") == 0) {
897 strcat(pre_final, "set term x11;");
898 }
899
901 cpl_plot_image(pre_final, opt, NULL, img));
902 }
903 }
904 CATCH
905 {
906 CATCH_MSG();
907 ret_error = cpl_error_get_code();
908 }
909
910 return ret_error;
911}
912
cpl_error_code eris_ifu_plot_vectors_xy(const char *pre, const char *opt, const cpl_vector *x, const cpl_vector *y)
Plot vector y against vector x for debugging.
cpl_error_code eris_ifu_debug_cube(const cpl_imagelist *imglist)
Print all images in an imagelist for debugging.
cpl_error_code eris_ifu_debug_propertylist(const cpl_propertylist *plist)
Print all properties in a propertylist for debugging.
cpl_error_code eris_ifu_debug_frameset(const cpl_frameset *frameset)
Print all frames in a frameset for debugging.
cpl_error_code eris_ifu_debug_array(const cpl_array *arr)
Print all values in an array for debugging.
cpl_error_code eris_ifu_debug_image(const cpl_image *img)
Print all pixel values in an image for debugging.
cpl_error_code eris_ifu_plot_vector(const char *pre, const char *opt, const cpl_vector *vector)
Plot a vector for debugging.
cpl_error_code eris_ifu_plot_vectors2(const char *pre, const char **opt, const cpl_vector *x, const cpl_vector *y1, const cpl_vector *y2)
Plot two y-vectors against an x-vector for debugging.
cpl_error_code eris_ifu_debug_parameterlist(const cpl_parameterlist *plist)
Print all parameters in a parameterlist for debugging.
cpl_error_code eris_ifu_debug_vector(const cpl_vector *vec)
Print all values in a vector for debugging.
cpl_error_code eris_ifu_plot_image(const char *pre, const char *opt, const cpl_image *img)
Plot an image for debugging.
cpl_error_code eris_ifu_debug_header(const cpl_propertylist *header)
Print all properties in a propertylist for debugging.
cpl_error_code eris_ifu_debug_frame(const cpl_frame *frame)
Print frame information for debugging.
cpl_error_code eris_ifu_debug_table(const cpl_table *table)
Print all values in a table for debugging.
#define BRK_WITH_ERROR(code)
Set a new CPL error, and exit the try-block.
#define BRK_IF_ERROR(function)
If function is or returns an error != CPL_ERROR_NONE, then the try-block is exited.
#define RECOVER(void)
Recover the error state which was present during TRY (at the beginning of the try-block).
#define GET_NEW_ERROR(void)
Return new CPL error code.
#define CHECK_ERROR_STATE(void)
Check the CPL error state, and exit the try-block if not CPL_ERROR_NONE.
#define CATCH_MSG()
Displays an error message.
#define TRY
Beginning of a TRY-block.
#define CATCH
End of a TRY-block, beginning of a CATCH-block.
#define BRK_IF_NULL(function)
If function is or returns a NULL pointer, then the try-block is exited.