62 #ifndef IRPLIB_UTILS_H
63 #define IRPLIB_UTILS_H
77 #define IRPLIB_XSTRINGIFY(TOSTRING) #TOSTRING
78 #define IRPLIB_STRINGIFY(TOSTRING) IRPLIB_XSTRINGIFY(TOSTRING)
80 #if !defined __GNUC__ && !defined __inline__
81 #if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L
82 #define __inline__ inline
88 #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
89 #define IRPLIB_DIAG_PRAGMA_PUSH_IGN(x) \
90 _Pragma("GCC diagnostic push") \
91 _Pragma(IRPLIB_STRINGIFY(GCC diagnostic ignored #x))
92 #define IRPLIB_DIAG_PRAGMA_PUSH_ERR(x) \
93 _Pragma("GCC diagnostic push") \
94 _Pragma(IRPLIB_STRINGIFY(GCC diagnostic error #x))
95 #define IRPLIB_DIAG_PRAGMA_POP \
96 _Pragma("GCC diagnostic pop")
98 #define IRPLIB_DIAG_PRAGMA_PUSH_IGN(x)
99 #define IRPLIB_DIAG_PRAGMA_PUSH_ERR(x)
100 #define IRPLIB_DIAG_PRAGMA_POP
106 #define irplib_trace() do if (cpl_error_get_code()) { \
107 cpl_msg_debug(cpl_func, __FILE__ " at line %d: ERROR '%s' at %s", \
108 __LINE__, cpl_error_get_message(), cpl_error_get_where()); \
110 cpl_msg_debug(cpl_func, __FILE__ " at line %d: OK", __LINE__); \
113 #define irplib_error_recover(ESTATE, ...) \
114 do if (!cpl_errorstate_is_equal(ESTATE)) { \
115 cpl_msg_warning(cpl_func, __VA_ARGS__); \
116 cpl_msg_indent_more(); \
117 cpl_errorstate_dump(ESTATE, CPL_FALSE, \
118 cpl_errorstate_dump_one_warning); \
119 cpl_msg_indent_less(); \
120 cpl_errorstate_set(ESTATE); \
133 #define IRPLIB_UTIL_SET_ROW(table_set_row) \
134 cpl_boolean table_set_row(cpl_table *, \
138 const cpl_parameterlist *)
149 #define IRPLIB_UTIL_CHECK(table_check) \
150 cpl_error_code table_check(cpl_table *, \
151 const cpl_frameset *, \
152 const cpl_parameterlist *)
203 #define skip_if(CONDITION) \
205 cpl_error_ensure(!cpl_error_get_code(), cpl_error_get_code(), \
206 goto cleanup, "Propagating a pre-existing error"); \
207 cpl_error_ensure(!(CONDITION), cpl_error_get_code(), \
208 goto cleanup, "Propagating error");\
223 #define skip_if_lt(A, B, ...) \
226 const double irplib_utils_a = (double)(A); \
227 const double irplib_utils_b = (double)(B); \
229 cpl_error_ensure(!cpl_error_get_code(), cpl_error_get_code(), \
230 goto cleanup, "Propagating a pre-existing error"); \
231 if (irplib_utils_a < irplib_utils_b) { \
232 char * irplib_utils_msg = cpl_sprintf(__VA_ARGS__); \
233 (void)cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND, \
234 "Need at least %g (not %g) %s", \
235 irplib_utils_b, irplib_utils_a, \
237 cpl_free(irplib_utils_msg); \
250 #define bug_if(CONDITION) \
252 cpl_error_ensure(!cpl_error_get_code(), cpl_error_get_code(), \
253 goto cleanup, "Propagating an unexpected error, " \
254 "please report to " PACKAGE_BUGREPORT); \
255 cpl_error_ensure(!(CONDITION), CPL_ERROR_UNSPECIFIED, \
256 goto cleanup, "Internal error, please report to " \
257 PACKAGE_BUGREPORT); \
272 #define error_if(CONDITION, ERROR, ...) \
273 cpl_error_ensure(cpl_error_get_code() == CPL_ERROR_NONE && \
274 !(CONDITION), ERROR, goto cleanup, __VA_ARGS__)
283 #define any_if(...) \
284 cpl_error_ensure(!cpl_error_get_code(), cpl_error_get_code(), \
285 goto cleanup, __VA_ARGS__)
297 if (cpl_error_get_code()) \
298 cpl_msg_debug(cpl_func, "Cleanup in " __FILE__ " line %u with " \
299 "error '%s' at %s", __LINE__, \
300 cpl_error_get_message(), cpl_error_get_where()); \
302 cpl_msg_debug(cpl_func, "Cleanup in " __FILE__ " line %u", \
320 #define irplib_ensure(CONDITION, ec, ...) \
321 cpl_error_ensure(CONDITION, ec, goto cleanup, __VA_ARGS__)
355 #define irplib_check(COMMAND, ...) \
357 cpl_errorstate irplib_check_prestate = cpl_errorstate_get(); \
361 irplib_ensure(cpl_errorstate_is_equal(irplib_check_prestate), \
362 cpl_error_get_code(), __VA_ARGS__); \
371 const cpl_parameterlist *,
372 const cpl_frameset *,
377 const cpl_propertylist *,
384 const cpl_parameterlist *,
385 const cpl_frameset *,
388 const cpl_propertylist *,
394 const cpl_parameterlist *,
395 const cpl_frameset *,
396 const cpl_imagelist *,
400 const cpl_propertylist *,
406 const cpl_parameterlist *,
407 const cpl_frameset *,
409 const cpl_propertylist *,
412 const cpl_propertylist *,
419 const cpl_parameterlist *,
420 const cpl_frameset *,
425 const cpl_propertylist *,
439 #if defined HAVE_ISNAN && HAVE_ISNAN != 0
440 #if !defined isnan && defined HAVE_DECL_ISNAN && HAVE_DECL_ISNAN == 0
449 int,
char,
const char *,
const char *,
450 const cpl_parameterlist *,
const char *,
451 const cpl_propertylist *,
const cpl_propertylist *,
452 const char *,
const char *,
const char *,
453 cpl_boolean (*)(cpl_table *,
const char *,
int,
455 const cpl_parameterlist *),
456 cpl_error_code (*)(cpl_table *,
457 const cpl_frameset *,
458 const cpl_parameterlist *));
461 const cpl_frameset *,
464 const cpl_parameterlist *,
466 (cpl_table *,
const char *,
467 int,
const cpl_frame *,
468 const cpl_parameterlist *));
471 cpl_image *, cpl_image *, cpl_image *,
475 cpl_boolean, cpl_boolean, cpl_boolean);
481 cpl_polynomial * irplib_polynomial_fit_1d_create(
482 const cpl_vector * x_pos,
483 const cpl_vector * values,
487 cpl_polynomial * irplib_polynomial_fit_1d_create_chiq(
488 const cpl_vector * x_pos,
489 const cpl_vector * values,
501 cpl_error_code irplib_frameset_sort(
502 const cpl_frameset *
self,
508 void * irplib_aligned_malloc(
size_t alignment,
size_t size) CPL_ATTR_ALLOC;
509 void * irplib_aligned_calloc(
size_t alignment,
510 size_t nelem,
size_t nbytes) CPL_ATTR_ALLOC;
511 void irplib_aligned_free (
void * aligned_ptr);
514 irplib_frameset_get_first_const(cpl_frameset_iterator **iterator,
515 const cpl_frameset *frameset);
518 irplib_frameset_get_next_const(cpl_frameset_iterator *iterator);
530 static __inline__
int irplib_isinf(
double value)
533 #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2)
534 return __builtin_isinf(value);
535 #elif defined HAVE_ISINF && HAVE_ISINF
538 return value != 0 && value == 2 * value;
548 static __inline__
int irplib_isnan(
double value)
551 #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2)
552 return __builtin_isnan(value);
553 #elif defined HAVE_ISNAN && HAVE_ISNAN
556 return value != value;
cpl_error_code irplib_dfs_save_table(cpl_frameset *, const cpl_parameterlist *, const cpl_frameset *, const cpl_table *, const cpl_propertylist *, const char *, const char *, const cpl_propertylist *, const char *, const char *, const char *)
Save a table as a DFS-compliant pipeline product.
void irplib_errorstate_dump_info(unsigned, unsigned, unsigned)
Dump a single CPL error at the CPL info level.
cpl_error_code irplib_table_read_from_frameset(cpl_table *, const cpl_frameset *, int, char, const cpl_parameterlist *, cpl_boolean(*)(cpl_table *, const char *, int, const cpl_frame *, const cpl_parameterlist *))
Set the rows of a table with data from one or more (ASCII) files.
void irplib_reset(void)
Reset IRPLIB state.
cpl_error_code irplib_apertures_find_max_flux(const cpl_apertures *, int *, int)
Find the aperture(s) with the greatest flux.
cpl_error_code irplib_dfs_save_propertylist(cpl_frameset *, const cpl_parameterlist *, const cpl_frameset *, const char *, const char *, const cpl_propertylist *, const char *, const char *, const char *)
Save a propertylist as a DFS-compliant pipeline product.
cpl_error_code irplib_dfs_save_image_(cpl_frameset *, cpl_propertylist *, const cpl_parameterlist *, const cpl_frameset *, const cpl_frame *, const cpl_image *, cpl_type, const char *, const cpl_propertylist *, const char *, const char *, const char *)
Save an image as a DFS-compliant pipeline product.
const cpl_frame * irplib_frameset_get_first_from_group(const cpl_frameset *, cpl_frame_group)
Find the first frame belonging to the given group.
cpl_error_code irplib_dfs_table_convert(cpl_table *, cpl_frameset *, const cpl_frameset *, int, char, const char *, const char *, const cpl_parameterlist *, const char *, const cpl_propertylist *, const cpl_propertylist *, const char *, const char *, const char *, cpl_boolean(*)(cpl_table *, const char *, int, const cpl_frame *, const cpl_parameterlist *), cpl_error_code(*)(cpl_table *, const cpl_frameset *, const cpl_parameterlist *))
Create a DFS product with one table from one or more (ASCII) file(s)
void irplib_errorstate_dump_warning(unsigned, unsigned, unsigned)
Dump a single CPL error at the CPL warning level.
void irplib_errorstate_dump_debug(unsigned, unsigned, unsigned)
Dump a single CPL error at the CPL debug level.
cpl_error_code irplib_dfs_save_image(cpl_frameset *, const cpl_parameterlist *, const cpl_frameset *, const cpl_image *, cpl_type_bpp, const char *, const char *, const cpl_propertylist *, const char *, const char *, const char *)
Save an image as a DFS-compliant pipeline product.
int irplib_compare_tags(cpl_frame *, cpl_frame *)
Comparison function to identify different input frames.
const char * irplib_frameset_find_file(const cpl_frameset *, const char *)
Find the filename with the given tag in a frame set.
cpl_error_code irplib_image_split(const cpl_image *, cpl_image *, cpl_image *, cpl_image *, double, cpl_boolean, double, cpl_boolean, double, double, cpl_boolean, cpl_boolean, cpl_boolean)
Split the values in an image in three according to two thresholds.
cpl_error_code irplib_dfs_save_imagelist(cpl_frameset *, const cpl_parameterlist *, const cpl_frameset *, const cpl_imagelist *, cpl_type_bpp, const char *, const char *, const cpl_propertylist *, const char *, const char *, const char *)
Save an imagelist as a DFS-compliant pipeline product.