PageRenderTime 49ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/tools/miso/src/error.c

https://bitbucket.org/montella/galaxy
C | 179 lines | 149 code | 23 blank | 7 comment | 6 complexity | af89ea5c0da36e097191f860c54b49bb MD5 | raw file
Possible License(s): CC-BY-3.0, GPL-3.0, MIT, Apache-2.0
  1. /* -*- mode: C -*- */
  2. #include "splicing_error.h"
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <assert.h>
  6. static splicing_error_handler_t *splicing_i_error_handler=0;
  7. static char *splicing_i_error_strings[]=
  8. { /* 0 */ "No error",
  9. /* 1 */ "Failed",
  10. /* 2 */ "Out of memory",
  11. /* 3 */ "Parse error",
  12. /* 4 */ "Invalid value",
  13. /* 5 */ "Already exists",
  14. /* 6 */ "Invalid edge vector",
  15. /* 7 */ "Invalid vertex id",
  16. /* 8 */ "Non-square matrix",
  17. /* 9 */ "Invalid mode",
  18. /* 10 */ "File operation error",
  19. /* 11 */ "Unfold infinite iterator",
  20. /* 12 */ "Unimplemented function call",
  21. /* 13 */ "Interrupted",
  22. /* 14 */ "Numeric procedure did not converge",
  23. /* 15 */ "Matrix-vector product failed",
  24. /* 16 */ "N must be positive",
  25. /* 17 */ "NEV must be positive",
  26. /* 18 */ "NCV must be bigger",
  27. /* 19 */ "Maximum number of iterations should be positive",
  28. /* 20 */ "Invalid WHICH parameter",
  29. /* 21 */ "Invalid BMAT parameter",
  30. /* 22 */ "WORKL is too small",
  31. /* 23 */ "LAPACK error in tridiagonal eigenvalue calculation",
  32. /* 24 */ "Starting vector is zero",
  33. /* 25 */ "MODE is invalid",
  34. /* 26 */ "MODE and BMAT are not compatible",
  35. /* 27 */ "ISHIFT must be 0 or 1",
  36. /* 28 */ "NEV and WHICH='BE' are incompatible",
  37. /* 29 */ "Could not build an Arnoldi factorization",
  38. /* 30 */ "No eigenvalues to sufficient accuracy",
  39. /* 31 */ "HOWMNY is invalid",
  40. /* 32 */ "HOWMNY='S' is not implemented",
  41. /* 33 */ "Different number of converged Ritz values",
  42. /* 34 */ "Error from calculation of a real Schur form",
  43. /* 35 */ "LAPACK (dtrevc) error for calculating eigenvectors",
  44. /* 36 */ "Unknown ARPACK error",
  45. /* 37 */ "Negative loop detected while calculating shortest paths",
  46. /* 38 */ "Internal error, likely a bug in splicing",
  47. /* 39 */ "Maximum number of iterations reached",
  48. /* 40 */ "No shifts could be applied during a cycle of the "
  49. "Implicitly restarted Arnoldi iteration. One possibility "
  50. "is to increase the size of NCV relative to NEV",
  51. /* 41 */ "The Schur form computed by LAPACK routine dlahqr "
  52. "could not be reordered by LAPACK routine dtrsen.",
  53. /* 42 */ "Big integer division by zero",
  54. /* 43 */ "GLPK Error, GLP_EBOUND",
  55. /* 44 */ "GLPK Error, GLP_EROOT",
  56. /* 45 */ "GLPK Error, GLP_ENOPFS",
  57. /* 46 */ "GLPK Error, GLP_ENODFS",
  58. /* 47 */ "GLPK Error, GLP_EFAIL",
  59. /* 48 */ "GLPK Error, GLP_EMIPGAP",
  60. /* 49 */ "GLPK Error, GLP_ETMLIM",
  61. /* 50 */ "GLPK Error, GLP_STOP",
  62. /* 51 */ "Internal attribute handler error",
  63. /* 52 */ "Unimplemented attribute combination for this type",
  64. /* 53 */ "LAPACK call resulted an error"
  65. };
  66. const char* splicing_strerror(const int splicing_errno) {
  67. return splicing_i_error_strings[splicing_errno];
  68. }
  69. int splicing_error(const char *reason, const char *file, int line,
  70. int splicing_errno) {
  71. if (splicing_i_error_handler) {
  72. splicing_i_error_handler(reason, file, line, splicing_errno);
  73. } else {
  74. splicing_error_handler_abort(reason, file, line, splicing_errno);
  75. }
  76. return splicing_errno;
  77. }
  78. void splicing_error_handler_abort (const char *reason, const char *file,
  79. int line, int splicing_errno) {
  80. fprintf(stderr, "Error at %s:%i :%s, %s\n", file, line, reason,
  81. splicing_strerror(splicing_errno));
  82. abort();
  83. }
  84. void splicing_error_handler_ignore (const char *reason, const char *file,
  85. int line, int splicing_errno) {
  86. SPLICING_FINALLY_FREE();
  87. }
  88. void splicing_error_handler_printignore (const char *reason, const char *file,
  89. int line, int splicing_errno) {
  90. SPLICING_FINALLY_FREE();
  91. fprintf(stderr, "Error at %s:%i :%s, %s\n", file, line, reason,
  92. splicing_strerror(splicing_errno));
  93. }
  94. splicing_error_handler_t *
  95. splicing_set_error_handler (splicing_error_handler_t * new_handler)
  96. {
  97. splicing_error_handler_t * previous_handler = splicing_i_error_handler;
  98. splicing_i_error_handler = new_handler;
  99. return previous_handler;
  100. }
  101. struct splicing_i_protectedPtr splicing_i_finally_stack[100];
  102. /*
  103. * Adds another element to the free list
  104. */
  105. void SPLICING_FINALLY_REAL(void (*func)(void*), void* ptr) {
  106. int no=splicing_i_finally_stack[0].all;
  107. assert (no<100);
  108. assert (no>=0);
  109. splicing_i_finally_stack[no].ptr=ptr;
  110. splicing_i_finally_stack[no].func=func;
  111. splicing_i_finally_stack[0].all ++;
  112. /* printf("--> Finally stack contains now %d elements\n", splicing_i_finally_stack[0].all); */
  113. }
  114. void SPLICING_FINALLY_CLEAN(int minus) {
  115. splicing_i_finally_stack[0].all -= minus;
  116. if (splicing_i_finally_stack[0].all < 0) {
  117. fprintf(stderr, "corrupt finally stack, popping %d elements when only %d left\n", minus, splicing_i_finally_stack[0].all+minus);
  118. splicing_i_finally_stack[0].all = 0;
  119. }
  120. /* printf("<-- Finally stack contains now %d elements\n", splicing_i_finally_stack[0].all); */
  121. }
  122. void SPLICING_FINALLY_FREE(void) {
  123. int p;
  124. /* printf("[X] Finally stack will be cleaned (contained %d elements)\n", splicing_i_finally_stack[0].all); */
  125. for (p=splicing_i_finally_stack[0].all-1; p>=0; p--) {
  126. splicing_i_finally_stack[p].func(splicing_i_finally_stack[p].ptr);
  127. }
  128. splicing_i_finally_stack[0].all=0;
  129. }
  130. int SPLICING_FINALLY_STACK_SIZE(void) {
  131. return splicing_i_finally_stack[0].all;
  132. }
  133. static splicing_warning_handler_t *splicing_i_warning_handler=0;
  134. void splicing_warning_handler_ignore (const char *reason, const char *file,
  135. int line, int splicing_errno) {
  136. }
  137. void splicing_warning_handler_print (const char *reason, const char *file,
  138. int line, int splicing_errno) {
  139. fprintf(stderr, "Warning: %s in file %s, line %i\n", reason, file, line);
  140. }
  141. int splicing_warning(const char *reason, const char *file, int line,
  142. int splicing_errno) {
  143. if (splicing_i_warning_handler) {
  144. splicing_i_warning_handler(reason, file, line, splicing_errno);
  145. } else {
  146. splicing_warning_handler_print(reason, file, line, splicing_errno);
  147. }
  148. return splicing_errno;
  149. }
  150. splicing_warning_handler_t *
  151. splicing_set_warning_handler (splicing_warning_handler_t * new_handler)
  152. {
  153. splicing_warning_handler_t * previous_handler = splicing_i_warning_handler;
  154. splicing_i_warning_handler = new_handler;
  155. return previous_handler;
  156. }