00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054 #ifndef IRPLIB_UTILS_H
00055 #define IRPLIB_UTILS_H
00056
00057
00058
00059
00060
00061 #include <cpl.h>
00062
00063 #include <stdarg.h>
00064
00065
00066
00067
00068
00069 #define IRPLIB_XSTRINGIFY(TOSTRING) #TOSTRING
00070 #define IRPLIB_STRINGIFY(TOSTRING) IRPLIB_XSTRINGIFY(TOSTRING)
00071
00072
00073 #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
00074 #define IRPLIB_DIAG_PRAGMA_PUSH_IGN(x) \
00075 _Pragma("GCC diagnostic push") \
00076 _Pragma(IRPLIB_STRINGIFY(GCC diagnostic ignored #x))
00077 #define IRPLIB_DIAG_PRAGMA_PUSH_ERR(x) \
00078 _Pragma("GCC diagnostic push") \
00079 _Pragma(IRPLIB_STRINGIFY(GCC diagnostic error #x))
00080 #define IRPLIB_DIAG_PRAGMA_POP \
00081 _Pragma("GCC diagnostic pop")
00082 #else
00083 #define IRPLIB_DIAG_PRAGMA_PUSH_IGN(x)
00084 #define IRPLIB_DIAG_PRAGMA_PUSH_ERR(x)
00085 #define IRPLIB_DIAG_PRAGMA_POP
00086 #endif
00087
00088
00089
00090
00091 #define irplib_trace() do if (cpl_error_get_code()) { \
00092 cpl_msg_debug(cpl_func, __FILE__ " at line %d: ERROR '%s' at %s", \
00093 __LINE__, cpl_error_get_message(), cpl_error_get_where()); \
00094 } else { \
00095 cpl_msg_debug(cpl_func, __FILE__ " at line %d: OK", __LINE__); \
00096 } while (0)
00097
00098 #define irplib_error_recover(ESTATE, ...) \
00099 do if (!cpl_errorstate_is_equal(ESTATE)) { \
00100 cpl_msg_warning(cpl_func, __VA_ARGS__); \
00101 cpl_msg_indent_more(); \
00102 cpl_errorstate_dump(ESTATE, CPL_FALSE, \
00103 cpl_errorstate_dump_one_warning); \
00104 cpl_msg_indent_less(); \
00105 cpl_errorstate_set(ESTATE); \
00106 } while (0)
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118 #define IRPLIB_UTIL_SET_ROW(table_set_row) \
00119 cpl_boolean table_set_row(cpl_table *, \
00120 const char *, \
00121 int, \
00122 const cpl_frame *, \
00123 const cpl_parameterlist *)
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134 #define IRPLIB_UTIL_CHECK(table_check) \
00135 cpl_error_code table_check(cpl_table *, \
00136 const cpl_frameset *, \
00137 const cpl_parameterlist *)
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188 #define skip_if(CONDITION) \
00189 do { \
00190 cpl_error_ensure(!cpl_error_get_code(), cpl_error_get_code(), \
00191 goto cleanup, "Propagating a pre-existing error"); \
00192 cpl_error_ensure(!(CONDITION), cpl_error_get_code(), \
00193 goto cleanup, "Propagating error");\
00194 } while (0)
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208 #define skip_if_lt(A, B, ...) \
00209 do { \
00210 \
00211 const double irplib_utils_a = (double)(A); \
00212 const double irplib_utils_b = (double)(B); \
00213 \
00214 cpl_error_ensure(!cpl_error_get_code(), cpl_error_get_code(), \
00215 goto cleanup, "Propagating a pre-existing error"); \
00216 if (irplib_utils_a < irplib_utils_b) { \
00217 char * irplib_utils_msg = cpl_sprintf(__VA_ARGS__); \
00218 (void)cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND, \
00219 "Need at least %g (not %g) %s", \
00220 irplib_utils_b, irplib_utils_a, \
00221 irplib_utils_msg); \
00222 cpl_free(irplib_utils_msg); \
00223 goto cleanup; \
00224 } \
00225 } while (0)
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235 #define bug_if(CONDITION) \
00236 do { \
00237 cpl_error_ensure(!cpl_error_get_code(), cpl_error_get_code(), \
00238 goto cleanup, "Propagating an unexpected error, " \
00239 "please report to " PACKAGE_BUGREPORT); \
00240 cpl_error_ensure(!(CONDITION), CPL_ERROR_UNSPECIFIED, \
00241 goto cleanup, "Internal error, please report to " \
00242 PACKAGE_BUGREPORT); \
00243 } while (0)
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257 #define error_if(CONDITION, ERROR, ...) \
00258 cpl_error_ensure(cpl_error_get_code() == CPL_ERROR_NONE && \
00259 !(CONDITION), ERROR, goto cleanup, __VA_ARGS__)
00260
00261
00262
00263
00264
00265
00266
00267
00268 #define any_if(...) \
00269 cpl_error_ensure(!cpl_error_get_code(), cpl_error_get_code(), \
00270 goto cleanup, __VA_ARGS__)
00271
00272
00273
00274
00275
00276
00277
00278
00279 #define end_skip \
00280 do { \
00281 cleanup: \
00282 if (cpl_error_get_code()) \
00283 cpl_msg_debug(cpl_func, "Cleanup in " __FILE__ " line %u with " \
00284 "error '%s' at %s", __LINE__, \
00285 cpl_error_get_message(), cpl_error_get_where()); \
00286 else \
00287 cpl_msg_debug(cpl_func, "Cleanup in " __FILE__ " line %u", \
00288 __LINE__); \
00289 } while (0)
00290
00291
00292
00304
00305 #define irplib_ensure(CONDITION, ec, ...) \
00306 cpl_error_ensure(CONDITION, ec, goto cleanup, __VA_ARGS__)
00307
00308
00338
00339
00340 #define irplib_check(COMMAND, ...) \
00341 do { \
00342 cpl_errorstate irplib_check_prestate = cpl_errorstate_get(); \
00343 skip_if(0); \
00344 COMMAND; \
00345 irplib_trace(); \
00346 irplib_ensure(cpl_errorstate_is_equal(irplib_check_prestate), \
00347 cpl_error_get_code(), __VA_ARGS__); \
00348 irplib_trace(); \
00349 } while (0)
00350
00351
00352
00353
00354
00355 cpl_error_code irplib_dfs_save_image(cpl_frameset *,
00356 const cpl_parameterlist *,
00357 const cpl_frameset *,
00358 const cpl_image *,
00359 cpl_type_bpp ,
00360 const char *,
00361 const char *,
00362 const cpl_propertylist *,
00363 const char *,
00364 const char *,
00365 const char *);
00366
00367
00368 cpl_error_code irplib_dfs_save_propertylist(cpl_frameset *,
00369 const cpl_parameterlist *,
00370 const cpl_frameset *,
00371 const char *,
00372 const char *,
00373 const cpl_propertylist *,
00374 const char *,
00375 const char *,
00376 const char *);
00377
00378 cpl_error_code irplib_dfs_save_imagelist(cpl_frameset *,
00379 const cpl_parameterlist *,
00380 const cpl_frameset *,
00381 const cpl_imagelist *,
00382 cpl_type_bpp ,
00383 const char *,
00384 const char *,
00385 const cpl_propertylist *,
00386 const char *,
00387 const char *,
00388 const char *);
00389
00390 cpl_error_code irplib_dfs_save_table(cpl_frameset *,
00391 const cpl_parameterlist *,
00392 const cpl_frameset *,
00393 const cpl_table *,
00394 const cpl_propertylist *,
00395 const char *,
00396 const char *,
00397 const cpl_propertylist *,
00398 const char *,
00399 const char *,
00400 const char *);
00401
00402 cpl_error_code irplib_dfs_save_image_(cpl_frameset *,
00403 cpl_propertylist *,
00404 const cpl_parameterlist *,
00405 const cpl_frameset *,
00406 const cpl_frame *,
00407 const cpl_image *,
00408 cpl_type ,
00409 const char *,
00410 const cpl_propertylist *,
00411 const char *,
00412 const char *,
00413 const char *);
00414
00415 void irplib_reset(void);
00416 int irplib_compare_tags(cpl_frame *, cpl_frame *);
00417 const char * irplib_frameset_find_file(const cpl_frameset *, const char *);
00418 const cpl_frame * irplib_frameset_get_first_from_group(const cpl_frameset *,
00419 cpl_frame_group);
00420
00421 cpl_error_code irplib_apertures_find_max_flux(const cpl_apertures *, int *,
00422 int);
00423
00424 int irplib_isinf(double value);
00425 int irplib_isnan(double value);
00426
00427 cpl_error_code
00428 irplib_dfs_table_convert(cpl_table *, cpl_frameset *, const cpl_frameset *,
00429 int, char, const char *, const char *,
00430 const cpl_parameterlist *, const char *,
00431 const cpl_propertylist *, const cpl_propertylist *,
00432 const char *, const char *, const char *,
00433 cpl_boolean (*)(cpl_table *, const char *, int,
00434 const cpl_frame *,
00435 const cpl_parameterlist *),
00436 cpl_error_code (*)(cpl_table *,
00437 const cpl_frameset *,
00438 const cpl_parameterlist *));
00439
00440 cpl_error_code irplib_table_read_from_frameset(cpl_table *,
00441 const cpl_frameset *,
00442 int,
00443 char,
00444 const cpl_parameterlist *,
00445 cpl_boolean (*)
00446 (cpl_table *, const char *,
00447 int, const cpl_frame *,
00448 const cpl_parameterlist *));
00449
00450 cpl_error_code irplib_image_split(const cpl_image *,
00451 cpl_image *, cpl_image *, cpl_image *,
00452 double, cpl_boolean,
00453 double, cpl_boolean,
00454 double, double,
00455 cpl_boolean, cpl_boolean, cpl_boolean);
00456
00457 void irplib_errorstate_dump_warning(unsigned, unsigned, unsigned);
00458 void irplib_errorstate_dump_info(unsigned, unsigned, unsigned);
00459 void irplib_errorstate_dump_debug(unsigned, unsigned, unsigned);
00460
00461 cpl_polynomial * irplib_polynomial_fit_1d_create(
00462 const cpl_vector * x_pos,
00463 const cpl_vector * values,
00464 int degree,
00465 double * mse
00466 );
00467 cpl_polynomial * irplib_polynomial_fit_1d_create_chiq(
00468 const cpl_vector * x_pos,
00469 const cpl_vector * values,
00470 int degree,
00471 double * rechiq
00472 );
00473
00481 cpl_error_code irplib_frameset_sort(
00482 const cpl_frameset * self,
00483 int* iindex,
00484 double* exptime);
00485
00486 #endif