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