ERIS Pipeline Reference Manual 1.8.14
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
33cpl_error_code eris_ifu_debug_header(const cpl_propertylist *header)
34{
35 int i = 0;
36 const cpl_property *p = NULL;
37 cpl_type t;
38 cpl_error_code ret_error = CPL_ERROR_NONE;
39
40 TRY
41 {
42 cpl_msg_debug("", "===== START HEADER =====");
43 if (header == NULL) {
44 cpl_msg_warning("", "Empty header!");
45 } else {
46 for (i = 0; i < cpl_propertylist_get_size(header); i++) {
48 p = cpl_propertylist_get_const(header, i));
49
50 t = cpl_property_get_type (p);
52 switch (t) {
53 case CPL_TYPE_BOOL:
54 cpl_msg_debug("", "%s: %d", cpl_property_get_name(p),
55 cpl_property_get_bool(p));
56 break;
57 case CPL_TYPE_INT:
58 cpl_msg_debug("", "%s: %d", cpl_property_get_name(p),
59 cpl_property_get_int(p));
60 break;
61 case CPL_TYPE_DOUBLE:
62 cpl_msg_debug("", "%s: %12.16g", cpl_property_get_name(p),
63 cpl_property_get_double(p));
64 break;
65 case CPL_TYPE_FLOAT:
66 cpl_msg_debug("", "%s: %12.16f", cpl_property_get_name(p),
67 cpl_property_get_float(p));
68 break;
69 case CPL_TYPE_STRING:
70 cpl_msg_debug("", "%s: %s", cpl_property_get_name(p),
71 cpl_property_get_string(p));
72 break;
73 default:
74 break;
75 }
76 }
77 }
78 cpl_msg_debug("", "====== END HEADER ======");
80 }
81 CATCH
82 {
83 CATCH_MSG();
84 ret_error = cpl_error_get_code();
85 }
86
87 return ret_error;
88}
89
104cpl_error_code eris_ifu_debug_frameset(const cpl_frameset *frameset)
105{
106 const cpl_frame *frame = NULL; /* must not be deleted at the end */
107 cpl_error_code ret_error = CPL_ERROR_NONE;
108
109 TRY
110 {
111 cpl_msg_debug("", "====== START FRAMESET ======");
112 if (frameset == NULL) {
113 cpl_msg_warning("", "Empty frameset!");
114 } else {
115 frame = cpl_frameset_find_const(frameset, NULL);
116
117 if (GET_NEW_ERROR(void) != CPL_ERROR_NONE) {
118 RECOVER();
119
120 cpl_msg_debug("", "====== END FRAMESET ======");
121
122 return CPL_ERROR_NONE;
123 }
124
125 while (frame != NULL) {
128 frame = cpl_frameset_find_const(frameset, NULL));
129 }
130 }
131 cpl_msg_debug("", "====== END FRAMESET ======");
133 }
134 CATCH
135 {
136 CATCH_MSG();
137 ret_error = cpl_error_get_code();
138 }
139
140 return ret_error;
141}
142
157cpl_error_code eris_ifu_debug_parameterlist(const cpl_parameterlist *plist)
158{
159 cpl_error_code ret_error = CPL_ERROR_NONE;
160 const cpl_parameter *par = NULL;
161 const char* name = NULL;
162 int intVal;
163 int intDef;
164 double dblVal;
165 double dblDef;
166 const char *strVal;
167 const char *strDef;
168
169 TRY
170 {
171 cpl_msg_debug("", "====== START PARAMETERLIST ======");
172 if (plist == NULL) {
173 cpl_msg_warning("", "Empty parameterlist!");
174 } else {
175 printf("Number of elements in parameter list: %lld\n",
176 cpl_parameterlist_get_size(plist));
177 par = cpl_parameterlist_get_first_const(plist);
178 while (par != NULL) {
179 name = cpl_parameter_get_name(par);
180 switch(cpl_parameter_get_type(par)) {
181 case CPL_TYPE_BOOL:
182 intVal = cpl_parameter_get_bool(par);
183 intDef = cpl_parameter_get_default_bool(par);
184 printf("Parameter %s: %d [%d]\n", name, intVal, intDef);
185 break;
186 case CPL_TYPE_INT:
187 intVal = cpl_parameter_get_int(par);
188 intDef = cpl_parameter_get_default_int(par);
189 printf("Parameter %s: %d [%d]\n", name, intVal, intDef);
190 break;
191 case CPL_TYPE_DOUBLE:
192 dblVal = cpl_parameter_get_double(par);
193 dblDef = cpl_parameter_get_default_double(par);
194 printf("Parameter %s: %f [%f]\n", name, dblVal, dblDef);
195 break;
196 case CPL_TYPE_STRING:
197 strVal = cpl_parameter_get_string(par);
198 strDef = cpl_parameter_get_default_string(par);
199 printf("Parameter %s: %s [%s]\n", name, strVal, strDef);
200 break;
201 default:
202 BRK_WITH_ERROR(CPL_ERROR_INVALID_TYPE);
203 break;
204 }
205 par = cpl_parameterlist_get_next_const(plist);
206 }
207 }
208 cpl_msg_debug("", "====== END FRAMESET ======");
210 }
211 CATCH
212 {
213 CATCH_MSG();
214 ret_error = cpl_error_get_code();
215 }
216
217 return ret_error;
218}
219
234cpl_error_code eris_ifu_debug_propertylist(const cpl_propertylist *plist)
235{
236 cpl_error_code ret_error = CPL_ERROR_NONE;
237
238 TRY
239 {
240 cpl_msg_debug("", "====== START PROPERTYLIST ======");
241 if (plist == NULL) {
242 cpl_msg_warning("", "Empty frameset!");
243 } else {
244
245 cpl_propertylist_dump(plist, NULL);
246 }
247 cpl_msg_debug("", "====== END PROPERTYLIST ======");
249 }
250 CATCH
251 {
252 CATCH_MSG();
253 ret_error = cpl_error_get_code();
254 }
255
256 return ret_error;
257
258}
259
275cpl_error_code eris_ifu_debug_frame(const cpl_frame *frame)
276{
277 const char *tmp = NULL;
278 int i = 0;
279 cpl_error_code ret_error = CPL_ERROR_NONE;
280
281 TRY
282 {
283 cpl_msg_debug("", " ====== START FRAME ======");
284 if (frame == NULL) {
285 cpl_msg_warning("", "Empty frame!");
286 } else {
287 tmp = cpl_frame_get_filename(frame);
288
289 if (GET_NEW_ERROR(void) != CPL_ERROR_NONE) {
290
291 RECOVER();
292 cpl_msg_debug("", " ====== END FRAME ======");
293 return CPL_ERROR_NONE;
294 }
295
296 cpl_msg_debug("", "filename: %s", tmp);
297 cpl_msg_debug("", "tag: %s", cpl_frame_get_tag(frame));
298
299 i = cpl_frame_get_type(frame);
301 switch(i) {
302 case CPL_FRAME_TYPE_NONE:
303 cpl_msg_debug("", "type: CPL_FRAME_TYPE_NONE (%d)", i);
304 break;
305 case CPL_FRAME_TYPE_IMAGE:
306 cpl_msg_debug("", "type: CPL_FRAME_TYPE_IMAGE (%d)", i);
307 break;
308 case CPL_FRAME_TYPE_MATRIX:
309 cpl_msg_debug("", "type: CPL_FRAME_TYPE_MATRIX (%d)", i);
310 break;
311 case CPL_FRAME_TYPE_TABLE:
312 cpl_msg_debug("", "type: CPL_FRAME_TYPE_TABLE (%d)", i);
313 break;
314 case CPL_FRAME_TYPE_PAF:
315 cpl_msg_debug("", "type: CPL_FRAME_TYPE_PAF (%d)", i);
316 break;
317 case CPL_FRAME_TYPE_ANY:
318 cpl_msg_debug("", "type: CPL_FRAME_TYPE_ANY (%d)", i);
319 break;
320 default:
321 cpl_msg_debug("", "type: other ERROR (%d)", i);
322 }
323
324 i = cpl_frame_get_group(frame);
326 switch(i) {
327 case CPL_FRAME_GROUP_NONE:
328 cpl_msg_debug("", "group: CPL_FRAME_GROUP_NONE (%d)", i);
329 break;
330 case CPL_FRAME_GROUP_RAW:
331 cpl_msg_debug("", "group: CPL_FRAME_GROUP_RAW (%d)", i);
332 break;
333 case CPL_FRAME_GROUP_CALIB:
334 cpl_msg_debug("", "group: CPL_FRAME_GROUP_CALIB (%d)", i);
335 break;
336 case CPL_FRAME_GROUP_PRODUCT:
337 cpl_msg_debug("", "group: CPL_FRAME_GROUP_PRODUCT (%d)", i);
338 break;
339 default:
340 cpl_msg_debug("", "group: other ERROR (%d)", i);
341 }
342
343 i = cpl_frame_get_level(frame);
345 switch(i) {
346 case CPL_FRAME_GROUP_NONE:
347 cpl_msg_debug("", "level: CPL_FRAME_LEVEL_NONE (%d)", i);
348 break;
349 case CPL_FRAME_GROUP_RAW:
350 cpl_msg_debug("", "level: CPL_FRAME_LEVEL_TEMPORARY (%d)", i);
351 break;
352 case CPL_FRAME_GROUP_CALIB:
353 cpl_msg_debug("", "level: CPL_FRAME_LEVEL_INTERMEDIATE (%d)", i);
354 break;
355 case CPL_FRAME_GROUP_PRODUCT:
356 cpl_msg_debug("", "level: CPL_FRAME_LEVEL_FINAL (%d)", i);
357 break;
358 default:
359 cpl_msg_debug("", "level: other ERROR (%d)", i);
360 }
361 }
362 cpl_msg_debug("", " ====== END FRAME ======");
364 }
365 CATCH
366 {
367 CATCH_MSG();
368 ret_error = cpl_error_get_code();
369 }
370
371 return ret_error;
372}
373
388cpl_error_code eris_ifu_debug_cube(const cpl_imagelist *imglist)
389{
390 int i = 0;
391 cpl_error_code ret_error = CPL_ERROR_NONE;
392
393 TRY
394 {
395 cpl_msg_debug("", "====== START IMAGELIST ======");
396 if (imglist == NULL) {
397 cpl_msg_warning("", "Empty cube!");
398 } else {
399 for (i = 0; i < cpl_imagelist_get_size(imglist); i++) {
401 eris_ifu_debug_image(cpl_imagelist_get_const(imglist, i)));
402 }
403 }
404 cpl_msg_debug("", "====== END IMAGELIST ======");
406 }
407 CATCH
408 {
409 CATCH_MSG();
410 ret_error = cpl_error_get_code();
411 }
412
413 return ret_error;
414}
415
430cpl_error_code eris_ifu_debug_image(const cpl_image *img)
431{
432 int x = 0,
433 y = 0;
434 int gaga = 0;
435 cpl_error_code ret_error = CPL_ERROR_NONE;
436 char line[200000],
437 tmp[2048];
438
439 TRY
440 {
441 cpl_msg_debug("", " ====== START IMAGE ======");
442 if (img == NULL) {
443 cpl_msg_warning("", "Empty image!");
444 } else {
445 strcpy(line, " ");
446 for (y = 1; y <= cpl_image_get_size_y(img); y++) {
447 for (x = 1; x <= cpl_image_get_size_x(img); x++) {
448 sprintf(tmp, "%f ", cpl_image_get(img, x, y, &gaga));
449 strcat(line, tmp);
451 }
452 strcat(line, "");
453 cpl_msg_debug("", "%s", line);
454 }
455 }
456 cpl_msg_debug("", " ====== END IMAGE ======");
458 }
459 CATCH
460 {
461 CATCH_MSG();
462 ret_error = cpl_error_get_code();
463 }
464
465 return ret_error;
466}
467
482cpl_error_code eris_ifu_debug_vector(const cpl_vector *vec)
483{
484 int x = 0;
485 cpl_size size = 0;
486 cpl_error_code ret_error = CPL_ERROR_NONE;
487 const double *pvec = NULL;
488
489 TRY
490 {
491 cpl_msg_debug("", " ====== START VECTOR ======");
492 if (vec == NULL) {
493 cpl_msg_warning("", "Empty vector!");
494 } else {
496 pvec = cpl_vector_get_data_const(vec));
497
498 size = cpl_vector_get_size(vec);
499 for (x = 0; x < size; x++) {
500 cpl_msg_debug("", "%12.16g ", pvec[x]);
501 }
502 }
503 cpl_msg_debug("", " ====== END VECTOR ======");
505 }
506 CATCH
507 {
508 CATCH_MSG();
509 ret_error = cpl_error_get_code();
510 }
511
512 return ret_error;
513}
514
515
530cpl_error_code eris_ifu_debug_array(const cpl_array *arr)
531{
532 int x = 0;
533 cpl_size size = 0;
534 const int *pint = NULL;
535 const double *pdouble = NULL;
536 cpl_error_code ret_error = CPL_ERROR_NONE;
537 cpl_type type;
538
539 TRY
540 {
541 if (arr != NULL) {
542 type = cpl_array_get_type(arr);
543 size = cpl_array_get_size(arr);
544
545 switch (type) {
546 case CPL_TYPE_INT:
547 pint = cpl_array_get_data_int_const(arr);
548 cpl_msg_debug("", " ====== START ARRAY ======");
549 if (arr== NULL) {
550 cpl_msg_warning("", "Empty array!");
551 } else {
552 for (x = 0; x < size; x++) {
553 cpl_msg_debug("", "%i", pint[x]);
554 }
555 }
556 cpl_msg_debug("", " ====== END ARRAY ======");
557 break;
558 case CPL_TYPE_DOUBLE:
559 pdouble = cpl_array_get_data_double_const(arr);
560 cpl_msg_debug("", " ====== START ARRAY ======");
561 if (arr== NULL) {
562 cpl_msg_warning("", "Empty array!");
563 } else {
564 for (x = 0; x < size; x++) {
565 cpl_msg_debug("", "%12.16g", pdouble[x]);
566 }
567 }
568 cpl_msg_debug("", " ====== END ARRAY ======");
569 break;
570 default:
571 cpl_msg_debug("", ">>> cpl_type (%d) not supported!", type);
572 break;
573 }
575 } else {
576 cpl_msg_debug("", " ====== START ARRAY ======");
577 cpl_msg_debug("", "Empty array!");
578 cpl_msg_debug("", " ====== END ARRAY ======");
579 }
580 }
581 CATCH
582 {
583 CATCH_MSG();
584 ret_error = cpl_error_get_code();
585 }
586
587 return ret_error;
588}
589
604cpl_error_code eris_ifu_debug_table(const cpl_table *table)
605{
606 cpl_error_code ret_error = CPL_ERROR_NONE;
607
608 TRY
609 {
610 cpl_msg_debug("", " ====== START TABLE ======");
611 if (table == NULL) {
612 cpl_msg_warning("", "Empty table pointer!");
613 } else {
614 cpl_table_dump(table, 0, cpl_table_get_nrow(table), NULL);
615 }
616 cpl_msg_debug("", " ====== END TABLE ======");
618 }
619 CATCH
620 {
621 CATCH_MSG();
622 ret_error = cpl_error_get_code();
623 }
624
625 return ret_error;
626}
627
643cpl_error_code eris_ifu_plot_vector(const char *pre, const char *opt,
644 const cpl_vector *vector)
645{
646 cpl_error_code ret_error = CPL_ERROR_NONE;
647
648 char *ostype = NULL,
649 pre_final[1024];
650
651 TRY
652 {
653 if ((vector != NULL) &&
654 (cpl_msg_get_level() == CPL_MSG_DEBUG))
655 {
656 strcpy(pre_final, "");
657 if (pre != NULL) {
658 strcat(pre_final, pre);
659 }
660 ostype = getenv("OSTYPE");
661 if(strcmp(ostype, "darwin") == 0) {
662 strcat(pre_final, "set term x11;");
663 }
664
666 cpl_plot_vector(pre_final, opt, NULL, vector));
667 }
668 }
669 CATCH
670 {
671 CATCH_MSG();
672 ret_error = cpl_error_get_code();
673 }
674
675 return ret_error;
676}
677
694cpl_error_code eris_ifu_plot_vectors_xy(const char *pre, const char *opt,
695 const cpl_vector *x, const cpl_vector *y)
696{
697 cpl_error_code ret_error = CPL_ERROR_NONE;
698
699 cpl_bivector *bi = NULL;
700
701 char *ostype = NULL,
702 pre_final[1024];
703
704 TRY
705 {
706 if ((x != NULL) && (y != NULL) &&
707 (cpl_msg_get_level() == CPL_MSG_DEBUG))
708 {
709 strcpy(pre_final, "");
710 if (pre != NULL) {
711 strcat(pre_final, pre);
712 }
713 ostype = getenv("OSTYPE");
714 if(strcmp(ostype, "darwin") == 0) {
715 strcat(pre_final, "set term x11;");
716 }
717// The function cpl_bivector_wrap_vectors will discard the const qualifier
718// However as it is know that cpl_plot_bivector will not modifiy its
719// bivector argument it is save to turn off the compiler warning
720
721#ifdef __GNUC__
722#pragma GCC diagnostic push
723#pragma GCC diagnostic ignored "-Wcast-qual"
724#endif
726 bi = cpl_bivector_wrap_vectors((cpl_vector*)x,
727 (cpl_vector*)y));
728#ifdef __GNUC__
729#pragma GCC diagnostic pop
730#endif
732 cpl_plot_bivector(pre_final, opt, NULL, bi));
733
734 cpl_bivector_unwrap_vectors(bi);
735 }
736 }
737 CATCH
738 {
739 CATCH_MSG();
740 ret_error = cpl_error_get_code();
741 }
742
743 return ret_error;
744}
745
763cpl_error_code eris_ifu_plot_vectors2(const char *pre, const char **opt,
764 const cpl_vector *x,
765 const cpl_vector *y1,
766 const cpl_vector *y2)
767{
768 cpl_error_code ret_error = CPL_ERROR_NONE;
769
770 int nr_plots = 2;
771 cpl_bivector *plots[nr_plots];
772 char *ostype = NULL,
773 pre_final[1024];
774
775 TRY
776 {
777 if ((x != NULL) && (y1 != NULL) && (y2 != NULL) &&
778 (cpl_msg_get_level() == CPL_MSG_DEBUG))
779 {
780 strcpy(pre_final, "");
781 if (pre != NULL) {
782 strcat(pre_final, pre);
783 }
784 ostype = getenv("OSTYPE");
785 if(strcmp(ostype, "darwin") == 0) {
786 strcat(pre_final, "set term x11;");
787 }
788
789 // The function cpl_bivector_wrap_vectors will discard the const qualifier
790 // However as it is know that cpl_plot_bivector will not modifiy its
791 // bivector argument it is save to turn off the compiler warning
792
793#ifdef __GNUC__
794#pragma GCC diagnostic push
795#pragma GCC diagnostic ignored "-Wcast-qual"
796#endif
798 plots[0] = cpl_bivector_wrap_vectors((cpl_vector*)x,
799 (cpl_vector*)y1));
801 plots[1] = cpl_bivector_wrap_vectors((cpl_vector*)x,
802 (cpl_vector*)y2));
803
805 cpl_plot_bivectors(pre_final,
806 (const char**)opt,
807 "",
808 (const cpl_bivector **) plots,
809 nr_plots));
810#ifdef __GNUC__
811#pragma GCC diagnostic pop
812#endif
813
814 int k = 0;
815 for (k = 0; k < nr_plots; k++) {
816 cpl_bivector_unwrap_vectors(plots[k]);
817 }
819 }
820 }
821 CATCH
822 {
823 CATCH_MSG();
824 ret_error = cpl_error_get_code();
825 }
826
827 return ret_error;
828}
829
845cpl_error_code eris_ifu_plot_image(const char *pre, const char *opt,
846 const cpl_image *img)
847{
848 cpl_error_code ret_error = CPL_ERROR_NONE;
849
850 char *ostype = NULL,
851 pre_final[1024];
852
853 TRY
854 {
855 if ((img != NULL) &&
856 (cpl_msg_get_level() == CPL_MSG_DEBUG))
857 {
858 strcpy(pre_final, "");
859 if (pre != NULL) {
860 strcat(pre_final, pre);
861 }
862 ostype = getenv("OSTYPE");
863 if(strcmp(ostype, "darwin") == 0) {
864 strcat(pre_final, "set term x11;");
865 }
866
868 cpl_plot_image(pre_final, opt, NULL, img));
869 }
870 }
871 CATCH
872 {
873 CATCH_MSG();
874 ret_error = cpl_error_get_code();
875 }
876
877 return ret_error;
878}
879
#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.
cpl_error_code eris_ifu_plot_vectors_xy(const char *pre, const char *opt, const cpl_vector *x, const cpl_vector *y)
Plots vector y against vector x.
cpl_error_code eris_ifu_debug_cube(const cpl_imagelist *imglist)
All images contained in imglist are printed for debugging purposes.
cpl_error_code eris_ifu_debug_propertylist(const cpl_propertylist *plist)
All properties contained in plist are printed for debugging purposes.
cpl_error_code eris_ifu_debug_frameset(const cpl_frameset *frameset)
All frames contained in frameset are printed for debugging purposes.
cpl_error_code eris_ifu_debug_array(const cpl_array *arr)
All values contained in arr are printed for debugging purposes.
cpl_error_code eris_ifu_debug_image(const cpl_image *img)
All values contained in img are printed for debugging purposes.
cpl_error_code eris_ifu_plot_vector(const char *pre, const char *opt, const cpl_vector *vector)
Plots a vector only if message level is CPL_MSG_DEBUG.
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)
Plots 2 vectors against vector x.
cpl_error_code eris_ifu_debug_parameterlist(const cpl_parameterlist *plist)
All parameters contained in plist are printed for debugging purposes.
cpl_error_code eris_ifu_debug_vector(const cpl_vector *vec)
All values contained in vec are printed for debugging purposes.
cpl_error_code eris_ifu_plot_image(const char *pre, const char *opt, const cpl_image *img)
Plots an image only if message level is CPL_MSG_DEBUG.
cpl_error_code eris_ifu_debug_header(const cpl_propertylist *header)
All properties contained in header are printed as pairs of keyword and data for debugging purposes.
cpl_error_code eris_ifu_debug_frame(const cpl_frame *frame)
The CPL_FRAME_TYPE, CPL_FRAME_LEVEL and CPL_FRAME_GROUP of frame are printed for debugging purposes.
cpl_error_code eris_ifu_debug_table(const cpl_table *table)
All values contained in table are printed for debugging purposes.