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