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
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
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
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159 #ifndef UVES_UTILS_H
00160 #define UVES_UTILS_H
00161
00162
00163 #ifdef HAVE_CONFIG_H
00164 # include <config.h>
00165 #endif
00166
00167
00168
00169
00170
00171 #include <uves_utils_polynomial.h>
00172 #include <uves_extract_iterate.h>
00173 #include <uves_extract_profile.h>
00174 #include <uves_chip.h>
00175
00176 #include <cpl.h>
00177 #include <math.h>
00178
00179
00180
00181
00182
00183
00184 #if defined HAVE_DECL___FUNC__ && !HAVE_DECL___FUNC__
00185
00186 #ifndef __func__
00187 #define __func__ "<fct.id>"
00188 #endif
00189 #endif
00190
00191 #ifndef inline
00192 #define inline
00193 #endif
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205 #ifndef WANT_BIG_LOGFILE
00206 #define WANT_BIG_LOGFILE 0
00207 #endif
00208
00209
00210
00211
00212
00213 #ifndef WANT_TIME_MEASURE
00214 #define WANT_TIME_MEASURE 0
00215 #endif
00216
00217
00218 #if WANT_TIME_MEASURE
00219 #define UVES_TIME_START(what) uves_msg("Timing (%s, l%d) %s start", \
00220 __FILE__, __LINE__, what)
00221 #define UVES_TIME_END uves_msg("Timing (%s, l%d) end", \
00222 __FILE__, __LINE__)
00223 #else
00224 #define UVES_TIME_START(what) uves_msg_debug("Timing (%s, l%d) %s start", \
00225 __FILE__, __LINE__, what)
00226 #define UVES_TIME_END uves_msg_debug("Timing (%s, l%d) end", \
00227 __FILE__, __LINE__)
00228 #endif
00229
00230
00231 #ifndef stringify
00232 #ifndef make_str
00233 #define stringify(X) #X
00234 #define make_str(X) stringify(X)
00235 #endif
00236 #endif
00237
00238 #define TWOSQRT2LN2 2.35482004503095
00239
00240 #ifndef M_PI
00241 #define M_PI 3.1415926535897932384626433832795
00242 #endif
00243
00244 #define SPEED_OF_LIGHT 299792458
00245
00246 #define COS_DEG(x) cos(((x)/180)*M_PI)
00247 #define SIN_DEG(x) sin(((x)/180)*M_PI)
00248 #define ACOS_DEG(x) (acos(x)*180/M_PI)
00249
00250
00251
00252
00253
00254 cpl_image *
00255 uves_create_image(uves_iterate_position *pos, enum uves_chip chip,
00256 const cpl_image *spectrum, const cpl_image *sky,
00257 const cpl_image *cosmic_image,
00258 const uves_extract_profile *profile,
00259 cpl_image **image_noise, uves_propertylist **image_header);
00260 cpl_frameset *
00261 uves_frameset_extract(const cpl_frameset *frames,const char *tag);
00262
00263 const char*
00264 uves_string_tolower(char* s);
00265 const char*
00266 uves_string_toupper(char* s);
00267
00268 double uves_gaussrand(void);
00269 double uves_pow_int(double x, int y);
00270 long uves_round_double(double x);
00271 double uves_max_double(double x, double y);
00272 int uves_max_int(int x, int y);
00273 double uves_min_double(double x, double y);
00274 int uves_min_int(int x, int y);
00275 double uves_error_fraction(double x, double y, double dx, double dy);
00276 const char *uves_get_license(void);
00277 cpl_error_code uves_get_version(int *major, int *minor, int *micro);
00278 int uves_get_version_binary(void);
00279
00280 char * uves_initialize(cpl_frameset *frames, const cpl_parameterlist *parlist,
00281 const char *recipe_id, const char *short_descr);
00282 cpl_error_code uves_end(const char *recipe_id, const cpl_frameset *frames);
00283
00284 uves_propertylist *uves_initialize_image_header(const char *ctype1, const char *ctype2,
00285 const char *bunit,
00286 double crval1 , double crval2,
00287 double crpix1 , double crpix2,
00288 double crdelt1, double crdelt2);
00289
00290 cpl_parameterlist*
00291 uves_parameterlist_duplicate(const cpl_parameterlist* pin);
00292
00293 cpl_image *uves_define_noise(const cpl_image *image, const uves_propertylist *image_header,
00294 int ncom, enum uves_chip);
00295 cpl_image *uves_average_images(const cpl_image *image1, const cpl_image *noise1,
00296 const cpl_image *image2, const cpl_image *noise2,
00297 cpl_image **noise);
00298
00299
00300 cpl_error_code uves_subtract_bias(cpl_image *image, const cpl_image *master_bias);
00301 cpl_error_code uves_subtract_dark(cpl_image *image, const uves_propertylist *image_header,
00302 const cpl_image *master_dark,
00303 const uves_propertylist *mdark_header);
00304
00305 polynomial *
00306 uves_polynomial_regression_2d_autodegree(cpl_table *t,
00307 const char *X1, const char *X2, const char *Y,
00308 const char *sigmaY,
00309 const char *polynomial_fit,
00310 const char *residual_square,
00311 const char *variance_fit,
00312 double *mean_squared_error, double *red_chisq,
00313 polynomial **variance, double kappa,
00314 int maxdeg1, int maxdeg2, double min_rms,
00315 double min_reject,
00316 bool verbose,
00317 const double *min_val,
00318 const double *max_val,
00319 int npos, double positions[][2]);
00320
00321 polynomial *
00322 uves_polynomial_regression_2d(cpl_table *t,
00323 const char *X1, const char *X2, const char *Y,
00324 const char *sigmaY,
00325 int degree1, int degree2,
00326 const char *polynomial_fit, const char *residual_square,
00327 const char *variance_fit,
00328 double *mse, double *red_chisq,
00329 polynomial **variance, double kappa,
00330 double min_reject);
00331
00332 polynomial *uves_polynomial_regression_1d(cpl_table *t,
00333 const char *X, const char *Y, const char *sigmaY,
00334 int degree,
00335 const char *polynomial_fit, const char *residual_square,
00336 double *mean_squared_error, const double kappa);
00337
00338 const char *uves_remove_string_prefix(const char *s, const char *prefix);
00339
00340 double uves_spline_hermite_table( double xp, const cpl_table *t, const char *column_x,
00341 const char *column_y, int *istart );
00342
00343 double uves_spline_hermite( double xp, const double *x, const double *y, int n, int *istart );
00344
00345 double uves_spline_cubic(double xp, double *x, float *y, float *y2, int n, int *kstart );
00346
00347 int uves_absolute_order(int first_abs_order, int last_abs_order, int relative_order);
00348
00349 double uves_average_reject(cpl_table *t,
00350 const char *column,
00351 const char *residual2,
00352 double kappa);
00353
00354
00355 cpl_table *uves_ordertable_traces_new(void);
00356 cpl_error_code uves_ordertable_traces_add(cpl_table *traces,
00357 int fibre_ID, double fibre_offset, int fibre_mask);
00358 bool uves_table_is_sorted_double(const cpl_table *t, const char *column, const bool reverse);
00359
00360 int uves_moffat(const double x[], const double a[], double *result);
00361 int uves_moffat_derivative(const double x[], const double a[], double result[]);
00362 int uves_gauss(const double x[], const double a[], double *result);
00363 int uves_gauss_derivative(const double x[], const double a[], double result[]);
00364 int uves_gauss_linear(const double x[], const double a[], double *result);
00365 int uves_gauss_linear_derivative(const double x[], const double a[], double result[]);
00366 void uves_check_version(void);
00367 void uves_frameset_dump(cpl_frameset* set);
00368 cpl_error_code
00369 uves_rcosmic(cpl_image* ima,
00370 cpl_image** flt,
00371 cpl_image** out,
00372 cpl_image** msk,
00373 const double sky,
00374 const double ron,
00375 const double gain,
00376 const int ns,
00377 const double rc);
00378 #endif