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 #ifndef IRPLIB_UTILS_H
00029 #define IRPLIB_UTILS_H
00030
00031
00032
00033
00034
00035 #include <stdarg.h>
00036
00037 #include <cpl.h>
00038
00039
00040
00041
00042
00043 #define IRPLIB_XSTRINGIFY(TOSTRING) #TOSTRING
00044 #define IRPLIB_STRINGIFY(TOSTRING) IRPLIB_XSTRINGIFY(TOSTRING)
00045
00046
00047
00048 #define irplib_trace() do if (cpl_error_get_code()) { \
00049 cpl_msg_debug(cpl_func, __FILE__ " at line %d: ERROR '%s' at %s", \
00050 __LINE__, cpl_error_get_message(), cpl_error_get_where()); \
00051 } else { \
00052 cpl_msg_debug(cpl_func, __FILE__ " at line %d: OK", __LINE__); \
00053 } while (0)
00054
00055 #define irplib_error_recover(ESTATE, ...) \
00056 do if (!cpl_errorstate_is_equal(ESTATE)) { \
00057 cpl_msg_warning(cpl_func, __VA_ARGS__); \
00058 cpl_msg_indent_more(); \
00059 cpl_errorstate_dump(ESTATE, CPL_FALSE, irplib_errorstate_warning); \
00060 cpl_msg_indent_less(); \
00061 cpl_errorstate_set(ESTATE); \
00062 } while (0)
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074 #define IRPLIB_UTIL_SET_ROW(table_set_row) \
00075 cpl_boolean table_set_row(cpl_table *, \
00076 const char *, \
00077 int, \
00078 const cpl_frame *, \
00079 const cpl_parameterlist *)
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090 #define IRPLIB_UTIL_CHECK(table_check) \
00091 cpl_error_code table_check(cpl_table *, \
00092 const cpl_frameset *, \
00093 const cpl_parameterlist *)
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
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 #define skip_if(CONDITION) \
00145 do { \
00146 cpl_error_ensure(!cpl_error_get_code(), cpl_error_get_code(), \
00147 goto cleanup, "Propagating a pre-existing error"); \
00148 cpl_error_ensure(!(CONDITION), cpl_error_get_code(), \
00149 goto cleanup, "Propagating error");\
00150 } while (0)
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162 #define skip_if_lt(A, B, MSG) \
00163 do { \
00164 const double tmpa = (double)(A); \
00165 const double tmpb = (double)(B); \
00166 \
00167 cpl_error_ensure(!cpl_error_get_code(), cpl_error_get_code(), \
00168 goto cleanup, "Propagating a pre-existing error"); \
00169 cpl_error_ensure(tmpa >= tmpb, CPL_ERROR_DATA_NOT_FOUND, \
00170 goto cleanup, "Need at least %g (not %g) %s", \
00171 tmpb, tmpa, MSG); \
00172 } while (0)
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182 #define bug_if(CONDITION) \
00183 do { \
00184 cpl_error_ensure(!cpl_error_get_code(), cpl_error_get_code(), \
00185 goto cleanup, "Propagating an unexpected error, " \
00186 "please report to " PACKAGE_BUGREPORT); \
00187 cpl_error_ensure(!(CONDITION), CPL_ERROR_UNSPECIFIED, \
00188 goto cleanup, "Internal error, please report to " \
00189 PACKAGE_BUGREPORT); \
00190 } while (0)
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204 #define error_if(CONDITION, ERROR, ...) \
00205 cpl_error_ensure(cpl_error_get_code() == CPL_ERROR_NONE && \
00206 !(CONDITION), ERROR, goto cleanup, __VA_ARGS__)
00207
00208
00209
00210
00211
00212
00213
00214
00215 #define any_if(...) \
00216 cpl_error_ensure(!cpl_error_get_code(), cpl_error_get_code(), \
00217 goto cleanup, __VA_ARGS__)
00218
00219
00220
00221
00222
00223
00224
00225
00226 #define end_skip \
00227 do { \
00228 cleanup: \
00229 if (cpl_error_get_code()) \
00230 cpl_msg_debug(cpl_func, "Cleanup in " __FILE__ " line %u with " \
00231 "error '%s' at %s", __LINE__, \
00232 cpl_error_get_message(), cpl_error_get_where()); \
00233 else \
00234 cpl_msg_debug(cpl_func, "Cleanup in " __FILE__ " line %u", \
00235 __LINE__); \
00236 } while (0)
00237
00238
00239
00251
00252 #define irplib_ensure(CONDITION, ec, ...) \
00253 cpl_error_ensure(CONDITION, ec, goto cleanup, __VA_ARGS__)
00254
00255
00285
00286
00287 #define irplib_check(COMMAND, ...) \
00288 do { \
00289 cpl_errorstate irplib_check_prestate = cpl_errorstate_get(); \
00290 skip_if(0); \
00291 COMMAND; \
00292 irplib_trace(); \
00293 irplib_ensure(cpl_errorstate_is_equal(irplib_check_prestate), \
00294 cpl_error_get_code(), __VA_ARGS__); \
00295 irplib_trace(); \
00296 } while (0)
00297
00298
00299
00300
00301
00302 cpl_error_code irplib_dfs_save_image(cpl_frameset *,
00303 const cpl_parameterlist *,
00304 const cpl_frameset *,
00305 const cpl_image *,
00306 cpl_type_bpp ,
00307 const char *,
00308 const char *,
00309 const cpl_propertylist *,
00310 const char *,
00311 const char *,
00312 const char *);
00313
00314
00315 cpl_error_code irplib_dfs_save_propertylist(cpl_frameset *,
00316 const cpl_parameterlist *,
00317 const cpl_frameset *,
00318 const char *,
00319 const char *,
00320 const cpl_propertylist *,
00321 const char *,
00322 const char *,
00323 const char *);
00324
00325 cpl_error_code irplib_dfs_save_imagelist(cpl_frameset *,
00326 const cpl_parameterlist *,
00327 const cpl_frameset *,
00328 const cpl_imagelist *,
00329 cpl_type_bpp ,
00330 const char *,
00331 const char *,
00332 const cpl_propertylist *,
00333 const char *,
00334 const char *,
00335 const char *);
00336
00337 cpl_error_code irplib_dfs_save_table(cpl_frameset *,
00338 const cpl_parameterlist *,
00339 const cpl_frameset *,
00340 const cpl_table *,
00341 const cpl_propertylist *,
00342 const char *,
00343 const char *,
00344 const cpl_propertylist *,
00345 const char *,
00346 const char *,
00347 const char *);
00348
00349 void irplib_reset(void);
00350 int irplib_compare_tags(cpl_frame *, cpl_frame *);
00351 const char * irplib_frameset_find_file(const cpl_frameset *, const char *);
00352 const cpl_frame * irplib_frameset_get_first_from_group(const cpl_frameset *,
00353 cpl_frame_group);
00354
00355 cpl_error_code irplib_apertures_find_max_flux(const cpl_apertures *, int *,
00356 int);
00357
00358 int irplib_isinf(double value);
00359 int irplib_isnan(double value);
00360
00361 void irplib_errorstate_warning(unsigned, unsigned, unsigned);
00362
00363 cpl_error_code
00364 irplib_dfs_table_convert(cpl_table *, cpl_frameset *, const cpl_frameset *,
00365 int, char, const char *, const char *,
00366 const cpl_parameterlist *, const char *,
00367 const cpl_propertylist *, const cpl_propertylist *,
00368 const char *, const char *, const char *,
00369 cpl_boolean (*)(cpl_table *, const char *, int,
00370 const cpl_frame *,
00371 const cpl_parameterlist *),
00372 cpl_error_code (*)(cpl_table *,
00373 const cpl_frameset *,
00374 const cpl_parameterlist *));
00375
00376 cpl_error_code irplib_table_read_from_frameset(cpl_table *,
00377 const cpl_frameset *,
00378 int,
00379 char,
00380 const cpl_parameterlist *,
00381 cpl_boolean (*)
00382 (cpl_table *, const char *,
00383 int, const cpl_frame *,
00384 const cpl_parameterlist *));
00385
00386 cpl_error_code irplib_image_split(const cpl_image *,
00387 cpl_image *, cpl_image *, cpl_image *,
00388 double, cpl_boolean,
00389 double, cpl_boolean,
00390 double, double,
00391 cpl_boolean, cpl_boolean, cpl_boolean);
00392
00393 void irplib_errorstate_dump_warning(unsigned, unsigned, unsigned);
00394 void irplib_errorstate_dump_info(unsigned, unsigned, unsigned);
00395 void irplib_errorstate_dump_debug(unsigned, unsigned, unsigned);
00396
00397 cpl_polynomial * irplib_polynomial_fit_1d_create(
00398 const cpl_vector * x_pos,
00399 const cpl_vector * values,
00400 int degree,
00401 double * mse
00402 );
00403 cpl_polynomial * irplib_polynomial_fit_1d_create_chiq(
00404 const cpl_vector * x_pos,
00405 const cpl_vector * values,
00406 int degree,
00407 double * rechiq
00408 );
00409
00410 cpl_error_code irplib_frameset_sort(const cpl_frameset * self, int* index, double* exptime);
00411
00412 #endif