78#define IRPLIB_CONCAT(a, b) a##_##b
79#define IRPLIB_CONCAT2X(a, b) IRPLIB_CONCAT(a, b)
89#define IRPLIB_SWAP_DOUBLE(A, B) \
91 const double irplib_swap_double = (A); \
93 (B) = irplib_swap_double; \
96#define IRPLIB_XSTRINGIFY CPL_XSTRINGIFY
97#define IRPLIB_STRINGIFY CPL_STRINGIFY
99#if !defined __GNUC__ && !defined __inline__
100#if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L
101#define __inline__ inline
107#define IRPLIB_DIAG_PRAGMA_PUSH_IGN CPL_DIAG_PRAGMA_PUSH_IGN
108#define IRPLIB_DIAG_PRAGMA_PUSH_ERR CPL_DIAG_PRAGMA_PUSH_ERR
109#define IRPLIB_DIAG_PRAGMA_POP CPL_DIAG_PRAGMA_POP
113#define irplib_trace() \
115 if (cpl_error_get_code()) { \
116 cpl_msg_debug(cpl_func, __FILE__ " at line " CPL_STRINGIFY(__LINE__) ": ERROR '%s' at %s", \
117 cpl_error_get_message(), \
118 cpl_error_get_where()); \
121 cpl_msg_debug(cpl_func, __FILE__ \
122 " at line " CPL_STRINGIFY(__LINE__) ": OK"); \
126#define irplib_error_recover(ESTATE, ...) \
128 if (!cpl_errorstate_is_equal(ESTATE)) { \
129 cpl_msg_warning(cpl_func, __VA_ARGS__); \
130 cpl_msg_indent_more(); \
131 cpl_errorstate_dump(ESTATE, CPL_FALSE, \
132 cpl_errorstate_dump_one_warning); \
133 cpl_msg_indent_less(); \
134 cpl_errorstate_set(ESTATE); \
147#define IRPLIB_UTIL_SET_ROW(table_set_row) \
148 cpl_boolean table_set_row(cpl_table *, const char *, int, \
149 const cpl_frame *, const cpl_parameterlist *)
160#define IRPLIB_UTIL_CHECK(table_check) \
161 cpl_error_code table_check(cpl_table *, const cpl_frameset *, \
162 const cpl_parameterlist *)
213#define skip_if(CONDITION) \
215 cpl_error_ensure(!cpl_error_get_code(), cpl_error_get_code(), \
216 goto cleanup, "Propagating a pre-existing error"); \
217 cpl_error_ensure(!(CONDITION), cpl_error_get_code(), goto cleanup, \
218 "Propagating error"); \
233#define skip_if_ne(A, B, ...) \
236 const double irplib_utils_a = (double)(A); \
237 const double irplib_utils_b = (double)(B); \
239 cpl_error_ensure(!cpl_error_get_code(), cpl_error_get_code(), \
240 goto cleanup, "Propagating a pre-existing error"); \
241 if (irplib_utils_a != irplib_utils_b) { \
242 char *irplib_utils_msg = cpl_sprintf(__VA_ARGS__); \
243 (void)cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND, \
244 "Need %g (not %g) %s", irplib_utils_b, \
245 irplib_utils_a, irplib_utils_msg); \
246 cpl_free(irplib_utils_msg); \
263#define skip_if_lt(A, B, ...) \
266 const double irplib_utils_a = (double)(A); \
267 const double irplib_utils_b = (double)(B); \
269 cpl_error_ensure(!cpl_error_get_code(), cpl_error_get_code(), \
270 goto cleanup, "Propagating a pre-existing error"); \
271 if (irplib_utils_a < irplib_utils_b) { \
272 char *irplib_utils_msg = cpl_sprintf(__VA_ARGS__); \
273 (void)cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND, \
274 "Need at least %g (not %g) %s", \
275 irplib_utils_b, irplib_utils_a, \
277 cpl_free(irplib_utils_msg); \
290#define bug_if(CONDITION) \
292 cpl_error_ensure(!cpl_error_get_code(), cpl_error_get_code(), \
294 "Propagating an unexpected error, " \
295 "please report to " PACKAGE_BUGREPORT); \
297 !(CONDITION), CPL_ERROR_UNSPECIFIED, goto cleanup, \
298 "Internal error, please report to " PACKAGE_BUGREPORT); \
313#define error_if(CONDITION, ERROR, ...) \
314 cpl_error_ensure(cpl_error_get_code() == CPL_ERROR_NONE && !(CONDITION), \
315 ERROR, goto cleanup, __VA_ARGS__)
325 cpl_error_ensure(!cpl_error_get_code(), cpl_error_get_code(), \
326 goto cleanup, __VA_ARGS__)
338 if (cpl_error_get_code()) \
339 cpl_msg_debug(cpl_func, \
340 "Cleanup in " __FILE__ " line " CPL_STRINGIFY(__LINE__) " with error '%s' at %s", \
341 cpl_error_get_message(), cpl_error_get_where()); \
343 cpl_msg_debug(cpl_func, "Cleanup in " __FILE__ \
344 " line " CPL_STRINGIFY(__LINE__)); \
361#define irplib_ensure(CONDITION, ec, ...) \
362 cpl_error_ensure(CONDITION, ec, goto cleanup, __VA_ARGS__)
396#define irplib_check(COMMAND, ...) \
398 cpl_errorstate irplib_check_prestate = cpl_errorstate_get(); \
402 irplib_ensure(cpl_errorstate_is_equal(irplib_check_prestate), \
403 cpl_error_get_code(), __VA_ARGS__); \
412 const cpl_parameterlist *,
413 const cpl_frameset *,
418 const cpl_propertylist *,
425 const cpl_parameterlist *,
426 const cpl_frameset *,
429 const cpl_propertylist *,
435 const cpl_parameterlist *,
436 const cpl_frameset *,
437 const cpl_imagelist *,
441 const cpl_propertylist *,
447 const cpl_parameterlist *,
448 const cpl_frameset *,
450 const cpl_propertylist *,
453 const cpl_propertylist *,
460 const cpl_parameterlist *,
461 const cpl_frameset *,
466 const cpl_propertylist *,
480#if defined HAVE_ISNAN && HAVE_ISNAN != 0
481#if !defined isnan && defined HAVE_DECL_ISNAN && HAVE_DECL_ISNAN == 0
491 const cpl_frameset *,
496 const cpl_parameterlist *,
498 const cpl_propertylist *,
499 const cpl_propertylist *,
503 cpl_boolean (*)(cpl_table *,
507 const cpl_parameterlist *),
508 cpl_error_code (*)(cpl_table *,
509 const cpl_frameset *,
510 const cpl_parameterlist *));
514 const cpl_frameset *,
517 const cpl_parameterlist *,
518 cpl_boolean (*)(cpl_table *,
522 const cpl_parameterlist *));
542cpl_polynomial *irplib_polynomial_fit_1d_create(
const cpl_vector *x_pos,
543 const cpl_vector *values,
546cpl_polynomial *irplib_polynomial_fit_1d_create_chiq(
const cpl_vector *x_pos,
547 const cpl_vector *values,
559irplib_frameset_sort(
const cpl_frameset *self,
int *iindex,
double *exptime);
563void *irplib_aligned_malloc(
size_t alignment,
size_t size) CPL_ATTR_ALLOC;
564void *irplib_aligned_calloc(
size_t alignment,
566 size_t nbytes) CPL_ATTR_ALLOC;
567void irplib_aligned_free(
void *aligned_ptr);
570irplib_frameset_get_first_const(cpl_frameset_iterator **iterator,
571 const cpl_frameset *frameset);
574irplib_frameset_get_next_const(cpl_frameset_iterator *iterator);
577void irplib_vector_get_kth(cpl_vector *, cpl_size);
590irplib_isinf(
double value)
593#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2)
594 return __builtin_isinf(value);
595#elif defined HAVE_ISINF && HAVE_ISINF
598 return value != 0 && value == 2 * value;
609irplib_isnan(
double value)
612#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2)
613 return __builtin_isnan(value);
614#elif defined HAVE_ISNAN && HAVE_ISNAN
617 return value != value;
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.
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.
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)
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_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.
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.
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.
void irplib_errorstate_dump_warning(unsigned, unsigned, unsigned)
Dump a single CPL error at the CPL warning level.
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.
void irplib_errorstate_dump_info(unsigned, unsigned, unsigned)
Dump a single CPL error at the CPL info level.
const cpl_frame * irplib_frameset_get_first_from_group(const cpl_frameset *, cpl_frame_group)
Find the first frame belonging to the given group.
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_apertures_find_max_flux(const cpl_apertures *, int *, int)
Find the aperture(s) with the greatest flux.
int irplib_compare_tags(cpl_frame *, cpl_frame *)
Comparison function to identify different input frames.
void irplib_reset(void)
Reset IRPLIB state.