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) do { \
90 const double irplib_swap_double=(A); \
92 (B)=irplib_swap_double; \
95#define IRPLIB_XSTRINGIFY CPL_XSTRINGIFY
96#define IRPLIB_STRINGIFY CPL_STRINGIFY
98#if !defined __GNUC__ && !defined __inline__
99#if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L
100#define __inline__ inline
106#define IRPLIB_DIAG_PRAGMA_PUSH_IGN CPL_DIAG_PRAGMA_PUSH_IGN
107#define IRPLIB_DIAG_PRAGMA_PUSH_ERR CPL_DIAG_PRAGMA_PUSH_ERR
108#define IRPLIB_DIAG_PRAGMA_POP CPL_DIAG_PRAGMA_POP
112#define irplib_trace() do if (cpl_error_get_code()) { \
113 cpl_msg_debug(cpl_func, __FILE__ " at line " \
114 CPL_STRINGIFY(__LINE__) ": ERROR '%s' at %s", \
115 cpl_error_get_message(), cpl_error_get_where()); \
117 cpl_msg_debug(cpl_func, __FILE__ " at line " \
118 CPL_STRINGIFY(__LINE__) ": OK"); \
121#define irplib_error_recover(ESTATE, ...) \
122 do if (!cpl_errorstate_is_equal(ESTATE)) { \
123 cpl_msg_warning(cpl_func, __VA_ARGS__); \
124 cpl_msg_indent_more(); \
125 cpl_errorstate_dump(ESTATE, CPL_FALSE, \
126 cpl_errorstate_dump_one_warning); \
127 cpl_msg_indent_less(); \
128 cpl_errorstate_set(ESTATE); \
141#define IRPLIB_UTIL_SET_ROW(table_set_row) \
142 cpl_boolean table_set_row(cpl_table *, \
146 const cpl_parameterlist *)
157#define IRPLIB_UTIL_CHECK(table_check) \
158 cpl_error_code table_check(cpl_table *, \
159 const cpl_frameset *, \
160 const cpl_parameterlist *)
211#define skip_if(CONDITION) \
213 cpl_error_ensure(!cpl_error_get_code(), cpl_error_get_code(), \
214 goto cleanup, "Propagating a pre-existing error"); \
215 cpl_error_ensure(!(CONDITION), cpl_error_get_code(), \
216 goto cleanup, "Propagating error");\
231#define skip_if_ne(A, B, ...) \
234 const double irplib_utils_a = (double)(A); \
235 const double irplib_utils_b = (double)(B); \
237 cpl_error_ensure(!cpl_error_get_code(), cpl_error_get_code(), \
238 goto cleanup, "Propagating a pre-existing error"); \
239 if (irplib_utils_a != irplib_utils_b) { \
240 char * irplib_utils_msg = cpl_sprintf(__VA_ARGS__); \
241 (void)cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND, \
242 "Need %g (not %g) %s", \
243 irplib_utils_b, irplib_utils_a, \
245 cpl_free(irplib_utils_msg); \
262#define skip_if_lt(A, B, ...) \
265 const double irplib_utils_a = (double)(A); \
266 const double irplib_utils_b = (double)(B); \
268 cpl_error_ensure(!cpl_error_get_code(), cpl_error_get_code(), \
269 goto cleanup, "Propagating a pre-existing error"); \
270 if (irplib_utils_a < irplib_utils_b) { \
271 char * irplib_utils_msg = cpl_sprintf(__VA_ARGS__); \
272 (void)cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND, \
273 "Need at least %g (not %g) %s", \
274 irplib_utils_b, irplib_utils_a, \
276 cpl_free(irplib_utils_msg); \
289#define bug_if(CONDITION) \
291 cpl_error_ensure(!cpl_error_get_code(), cpl_error_get_code(), \
292 goto cleanup, "Propagating an unexpected error, " \
293 "please report to " PACKAGE_BUGREPORT); \
294 cpl_error_ensure(!(CONDITION), CPL_ERROR_UNSPECIFIED, \
295 goto cleanup, "Internal error, please report to " \
296 PACKAGE_BUGREPORT); \
311#define error_if(CONDITION, ERROR, ...) \
312 cpl_error_ensure(cpl_error_get_code() == CPL_ERROR_NONE && \
313 !(CONDITION), ERROR, goto cleanup, __VA_ARGS__)
323 cpl_error_ensure(!cpl_error_get_code(), cpl_error_get_code(), \
324 goto cleanup, __VA_ARGS__)
336 if (cpl_error_get_code()) \
337 cpl_msg_debug(cpl_func, "Cleanup in " __FILE__ " line " \
338 CPL_STRINGIFY(__LINE__) " with error '%s' at %s", \
339 cpl_error_get_message(), cpl_error_get_where()); \
341 cpl_msg_debug(cpl_func, "Cleanup in " __FILE__ " line " \
342 CPL_STRINGIFY(__LINE__)); \
359#define irplib_ensure(CONDITION, ec, ...) \
360 cpl_error_ensure(CONDITION, ec, goto cleanup, __VA_ARGS__)
394#define irplib_check(COMMAND, ...) \
396 cpl_errorstate irplib_check_prestate = cpl_errorstate_get(); \
400 irplib_ensure(cpl_errorstate_is_equal(irplib_check_prestate), \
401 cpl_error_get_code(), __VA_ARGS__); \
410 const cpl_parameterlist *,
411 const cpl_frameset *,
416 const cpl_propertylist *,
423 const cpl_parameterlist *,
424 const cpl_frameset *,
427 const cpl_propertylist *,
433 const cpl_parameterlist *,
434 const cpl_frameset *,
435 const cpl_imagelist *,
439 const cpl_propertylist *,
445 const cpl_parameterlist *,
446 const cpl_frameset *,
448 const cpl_propertylist *,
451 const cpl_propertylist *,
458 const cpl_parameterlist *,
459 const cpl_frameset *,
464 const cpl_propertylist *,
478#if defined HAVE_ISNAN && HAVE_ISNAN != 0
479#if !defined isnan && defined HAVE_DECL_ISNAN && HAVE_DECL_ISNAN == 0
488 int,
char,
const char *,
const char *,
489 const cpl_parameterlist *,
const char *,
490 const cpl_propertylist *,
const cpl_propertylist *,
491 const char *,
const char *,
const char *,
492 cpl_boolean (*)(cpl_table *,
const char *,
int,
494 const cpl_parameterlist *),
495 cpl_error_code (*)(cpl_table *,
496 const cpl_frameset *,
497 const cpl_parameterlist *));
500 const cpl_frameset *,
503 const cpl_parameterlist *,
505 (cpl_table *,
const char *,
506 int,
const cpl_frame *,
507 const cpl_parameterlist *));
510 cpl_image *, cpl_image *, cpl_image *,
514 cpl_boolean, cpl_boolean, cpl_boolean);
520cpl_polynomial * irplib_polynomial_fit_1d_create(
521 const cpl_vector * x_pos,
522 const cpl_vector * values,
526cpl_polynomial * irplib_polynomial_fit_1d_create_chiq(
527 const cpl_vector * x_pos,
528 const cpl_vector * values,
540cpl_error_code irplib_frameset_sort(
541 const cpl_frameset * self,
547void * irplib_aligned_malloc(
size_t alignment,
size_t size) CPL_ATTR_ALLOC;
548void * irplib_aligned_calloc(
size_t alignment,
549 size_t nelem,
size_t nbytes) CPL_ATTR_ALLOC;
550void irplib_aligned_free (
void * aligned_ptr);
553irplib_frameset_get_first_const(cpl_frameset_iterator **iterator,
554 const cpl_frameset *frameset);
557irplib_frameset_get_next_const(cpl_frameset_iterator *iterator);
560void irplib_vector_get_kth(cpl_vector *, cpl_size);
572static __inline__
int irplib_isinf(
double value)
575#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2)
576 return __builtin_isinf(value);
577#elif defined HAVE_ISINF && HAVE_ISINF
580 return value != 0 && value == 2 * value;
590static __inline__
int irplib_isnan(
double value)
593#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2)
594 return __builtin_isnan(value);
595#elif defined HAVE_ISNAN && HAVE_ISNAN
598 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.