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 #ifndef IRPLIB_UTILS_H
00049 #define IRPLIB_UTILS_H
00050
00051
00052
00053
00054
00055 #include <stdarg.h>
00056
00057 #include <cpl.h>
00058
00059
00060
00061
00062
00063 #define IRPLIB_XSTRINGIFY(TOSTRING) #TOSTRING
00064 #define IRPLIB_STRINGIFY(TOSTRING) IRPLIB_XSTRINGIFY(TOSTRING)
00065
00066
00067
00068 #define irplib_trace() do if (cpl_error_get_code()) { \
00069 cpl_msg_debug(cpl_func, __FILE__ " at line %d: ERROR '%s' at %s", \
00070 __LINE__, cpl_error_get_message(), cpl_error_get_where()); \
00071 } else { \
00072 cpl_msg_debug(cpl_func, __FILE__ " at line %d: OK", __LINE__); \
00073 } while (0)
00074
00075 #define irplib_error_recover(ESTATE, ...) \
00076 do if (!cpl_errorstate_is_equal(ESTATE)) { \
00077 cpl_msg_warning(cpl_func, __VA_ARGS__); \
00078 cpl_msg_indent_more(); \
00079 cpl_errorstate_dump(ESTATE, CPL_FALSE, irplib_errorstate_warning); \
00080 cpl_msg_indent_less(); \
00081 cpl_errorstate_set(ESTATE); \
00082 } while (0)
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094 #define IRPLIB_UTIL_SET_ROW(table_set_row) \
00095 cpl_boolean table_set_row(cpl_table *, \
00096 const char *, \
00097 int, \
00098 const cpl_frame *, \
00099 const cpl_parameterlist *)
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110 #define IRPLIB_UTIL_CHECK(table_check) \
00111 cpl_error_code table_check(cpl_table *, \
00112 const cpl_frameset *, \
00113 const cpl_parameterlist *)
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
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 #define skip_if(CONDITION) \
00165 do { \
00166 cpl_error_ensure(!cpl_error_get_code(), cpl_error_get_code(), \
00167 goto cleanup, "Propagating a pre-existing error"); \
00168 cpl_error_ensure(!(CONDITION), cpl_error_get_code(), \
00169 goto cleanup, "Propagating error");\
00170 } while (0)
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184 #define skip_if_lt(A, B, ...) \
00185 do { \
00186 \
00187 const double irplib_utils_a = (double)(A); \
00188 const double irplib_utils_b = (double)(B); \
00189 \
00190 cpl_error_ensure(!cpl_error_get_code(), cpl_error_get_code(), \
00191 goto cleanup, "Propagating a pre-existing error"); \
00192 if (irplib_utils_a < irplib_utils_b) { \
00193 char * irplib_utils_msg = cpl_sprintf(__VA_ARGS__); \
00194 (void)cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND, \
00195 "Need at least %g (not %g) %s", \
00196 irplib_utils_b, irplib_utils_a, \
00197 irplib_utils_msg); \
00198 cpl_free(irplib_utils_msg); \
00199 goto cleanup; \
00200 } \
00201 } while (0)
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211 #define bug_if(CONDITION) \
00212 do { \
00213 cpl_error_ensure(!cpl_error_get_code(), cpl_error_get_code(), \
00214 goto cleanup, "Propagating an unexpected error, " \
00215 "please report to " PACKAGE_BUGREPORT); \
00216 cpl_error_ensure(!(CONDITION), CPL_ERROR_UNSPECIFIED, \
00217 goto cleanup, "Internal error, please report to " \
00218 PACKAGE_BUGREPORT); \
00219 } while (0)
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233 #define error_if(CONDITION, ERROR, ...) \
00234 cpl_error_ensure(cpl_error_get_code() == CPL_ERROR_NONE && \
00235 !(CONDITION), ERROR, goto cleanup, __VA_ARGS__)
00236
00237
00238
00239
00240
00241
00242
00243
00244 #define any_if(...) \
00245 cpl_error_ensure(!cpl_error_get_code(), cpl_error_get_code(), \
00246 goto cleanup, __VA_ARGS__)
00247
00248
00249
00250
00251
00252
00253
00254
00255 #define end_skip \
00256 do { \
00257 cleanup: \
00258 if (cpl_error_get_code()) \
00259 cpl_msg_debug(cpl_func, "Cleanup in " __FILE__ " line %u with " \
00260 "error '%s' at %s", __LINE__, \
00261 cpl_error_get_message(), cpl_error_get_where()); \
00262 else \
00263 cpl_msg_debug(cpl_func, "Cleanup in " __FILE__ " line %u", \
00264 __LINE__); \
00265 } while (0)
00266
00267
00268
00280
00281 #define irplib_ensure(CONDITION, ec, ...) \
00282 cpl_error_ensure(CONDITION, ec, goto cleanup, __VA_ARGS__)
00283
00284
00314
00315
00316 #define irplib_check(COMMAND, ...) \
00317 do { \
00318 cpl_errorstate irplib_check_prestate = cpl_errorstate_get(); \
00319 skip_if(0); \
00320 COMMAND; \
00321 irplib_trace(); \
00322 irplib_ensure(cpl_errorstate_is_equal(irplib_check_prestate), \
00323 cpl_error_get_code(), __VA_ARGS__); \
00324 irplib_trace(); \
00325 } while (0)
00326
00327
00328
00329
00330
00331 cpl_error_code irplib_dfs_save_image(cpl_frameset *,
00332 const cpl_parameterlist *,
00333 const cpl_frameset *,
00334 const cpl_image *,
00335 cpl_type_bpp ,
00336 const char *,
00337 const char *,
00338 const cpl_propertylist *,
00339 const char *,
00340 const char *,
00341 const char *);
00342
00343
00344 cpl_error_code irplib_dfs_save_propertylist(cpl_frameset *,
00345 const cpl_parameterlist *,
00346 const cpl_frameset *,
00347 const char *,
00348 const char *,
00349 const cpl_propertylist *,
00350 const char *,
00351 const char *,
00352 const char *);
00353
00354 cpl_error_code irplib_dfs_save_imagelist(cpl_frameset *,
00355 const cpl_parameterlist *,
00356 const cpl_frameset *,
00357 const cpl_imagelist *,
00358 cpl_type_bpp ,
00359 const char *,
00360 const char *,
00361 const cpl_propertylist *,
00362 const char *,
00363 const char *,
00364 const char *);
00365
00366 cpl_error_code irplib_dfs_save_table(cpl_frameset *,
00367 const cpl_parameterlist *,
00368 const cpl_frameset *,
00369 const cpl_table *,
00370 const cpl_propertylist *,
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_image_(cpl_frameset *,
00379 cpl_propertylist *,
00380 const cpl_parameterlist *,
00381 const cpl_frameset *,
00382 const cpl_frame *,
00383 const cpl_image *,
00384 cpl_type ,
00385 const char *,
00386 const cpl_propertylist *,
00387 const char *,
00388 const char *,
00389 const char *);
00390
00391 void irplib_reset(void);
00392 int irplib_compare_tags(cpl_frame *, cpl_frame *);
00393 const char * irplib_frameset_find_file(const cpl_frameset *, const char *);
00394 const cpl_frame * irplib_frameset_get_first_from_group(const cpl_frameset *,
00395 cpl_frame_group);
00396
00397 cpl_error_code irplib_apertures_find_max_flux(const cpl_apertures *, int *,
00398 int);
00399
00400 int irplib_isinf(double value);
00401 int irplib_isnan(double value);
00402
00403 void irplib_errorstate_warning(unsigned, unsigned, unsigned);
00404
00405 cpl_error_code
00406 irplib_dfs_table_convert(cpl_table *, cpl_frameset *, const cpl_frameset *,
00407 int, char, const char *, const char *,
00408 const cpl_parameterlist *, const char *,
00409 const cpl_propertylist *, const cpl_propertylist *,
00410 const char *, const char *, const char *,
00411 cpl_boolean (*)(cpl_table *, const char *, int,
00412 const cpl_frame *,
00413 const cpl_parameterlist *),
00414 cpl_error_code (*)(cpl_table *,
00415 const cpl_frameset *,
00416 const cpl_parameterlist *));
00417
00418 cpl_error_code irplib_table_read_from_frameset(cpl_table *,
00419 const cpl_frameset *,
00420 int,
00421 char,
00422 const cpl_parameterlist *,
00423 cpl_boolean (*)
00424 (cpl_table *, const char *,
00425 int, const cpl_frame *,
00426 const cpl_parameterlist *));
00427
00428 cpl_error_code irplib_image_split(const cpl_image *,
00429 cpl_image *, cpl_image *, cpl_image *,
00430 double, cpl_boolean,
00431 double, cpl_boolean,
00432 double, double,
00433 cpl_boolean, cpl_boolean, cpl_boolean);
00434
00435 void irplib_errorstate_dump_warning(unsigned, unsigned, unsigned);
00436 void irplib_errorstate_dump_info(unsigned, unsigned, unsigned);
00437 void irplib_errorstate_dump_debug(unsigned, unsigned, unsigned);
00438
00439 cpl_polynomial * irplib_polynomial_fit_1d_create(
00440 const cpl_vector * x_pos,
00441 const cpl_vector * values,
00442 int degree,
00443 double * mse
00444 );
00445 cpl_polynomial * irplib_polynomial_fit_1d_create_chiq(
00446 const cpl_vector * x_pos,
00447 const cpl_vector * values,
00448 int degree,
00449 double * rechiq
00450 );
00451
00459 cpl_error_code irplib_frameset_sort(
00460 const cpl_frameset * self,
00461 int* iindex,
00462 double* exptime);
00463
00464 #endif