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