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 #ifdef HAVE_CONFIG_H
00029 #include <config.h>
00030 #endif
00031
00032 #include <fors_star.h>
00033
00034 #include <fors_utils.h>
00035
00036 #include <cpl.h>
00037
00038 #include <math.h>
00039 #include <assert.h>
00040
00050 #undef clenaup
00051 #define cleanup
00052
00065 fors_star *fors_star_new(double x, double y,
00066 double fwhm,
00067 double smajor, double sminor,
00068 double orientation,
00069 double m, double dm,
00070 double si)
00071 {
00072 assure( smajor >= sminor && sminor >= 0, return NULL,
00073 "Illegal semi major/minor axes: %g, %g",
00074 smajor, sminor );
00075
00076 assure( 0 <= si && si <= 1, return NULL,
00077 "Stellarity index must be between 0 and 1, is %f",
00078 si);
00079
00080 assure( fwhm >= 0, return NULL,
00081 "Star FWHM must be non-negative, is %f",
00082 fwhm);
00083
00084 fors_star *s = cpl_malloc(sizeof(*s));
00085
00086 s->pixel = fors_point_new(x, y);
00087 s->fwhm = fwhm;
00088 s->semi_major = smajor;
00089 s->semi_minor = sminor;
00090 s->stellarity_index = si;
00091 s->orientation = orientation;
00092 s->magnitude = m;
00093 s->dmagnitude = dm;
00094 s->magnitude_corr = 0;
00095 s->dmagnitude_corr = 0;
00096 s->id = NULL;
00097 s->weight = 0;
00098
00099 return s;
00100 }
00101
00102
00103 #undef clenaup
00104 #define cleanup
00105
00110 fors_star *fors_star_duplicate(const fors_star *star)
00111 {
00112 fors_star *d;
00113
00114 assure( star != NULL, return NULL, NULL );
00115
00116 d = cpl_malloc(sizeof(*d));
00117 *d = *star;
00118
00119
00120 d->pixel = fors_point_duplicate(star->pixel);
00121
00122 if (star->id != NULL) {
00123 d->id = fors_std_star_duplicate(star->id);
00124 }
00125
00126 return d;
00127 }
00128
00133 void fors_star_delete(fors_star **star)
00134 {
00135 if (star && *star) {
00136 fors_point_delete(&(*star)->pixel);
00137 if ((*star)->id != NULL) {
00138 fors_std_star_delete_const(&((*star)->id));
00139 }
00140 cpl_free(*star); *star = NULL;
00141 }
00142 return;
00143 }
00144
00149 void fors_star_delete_but_standard(fors_star **star)
00150 {
00151 if (star && *star) {
00152 fors_point_delete(&(*star)->pixel);
00153 cpl_free(*star); *star = NULL;
00154 }
00155 return;
00156 }
00157
00164 bool
00165 fors_star_equal(const fors_star *s,
00166 const fors_star *t)
00167 {
00168 assure( s != NULL && t != NULL, return true, NULL );
00169
00170 return (fors_point_equal(s->pixel, t->pixel));
00171 }
00172
00173 #undef clenaup
00174 #define cleanup
00175
00182 bool
00183 fors_star_brighter_than(const fors_star *s1,
00184 const fors_star *s2,
00185 void *data)
00186 {
00187 data = data;
00188 return (s1->magnitude < s2->magnitude);
00189 }
00190
00191 #undef cleanup
00192 #define cleanup
00193
00199 double fors_star_distsq(const fors_star *s, const fors_star *t)
00200 {
00201 assure( s != NULL, return 0, NULL );
00202 assure( t != NULL, return 0, NULL );
00203
00204 return fors_point_distsq(s->pixel, t->pixel);
00205 }
00206
00207 #undef cleanup
00208 #define cleanup
00209
00215 double fors_star_extension(const fors_star *s, void *data)
00216 {
00217 assure( s != NULL, return -1, NULL );
00218 data = data;
00219
00220
00221 return s->fwhm / TWOSQRT2LN2;
00222 }
00223
00224 #undef cleanup
00225 #define cleanup
00226
00232 double fors_star_stellarity(const fors_star *s, void *data)
00233 {
00234 assure( s != NULL, return -1, NULL );
00235 data = data;
00236
00237 return s->stellarity_index;
00238 }
00239
00240 #undef cleanup
00241 #define cleanup
00242
00248 double fors_star_ellipticity(const fors_star *s, void *data)
00249 {
00250 assure( s != NULL, return -1, NULL );
00251 data = data;
00252
00253 if (s->semi_major <= 0) return 1;
00254 else return 1 - (s->semi_minor / s->semi_major);
00255 }
00256
00262 void fors_star_print(cpl_msg_severity level, const fors_star *s)
00263 {
00264 if (s == NULL) {
00265 fors_msg(level, "[NULL]");
00266 }
00267 else {
00268 fors_msg(level, "at (%7.2f, %7.2f): m = %g +- %g (mc = %g +- %g), "
00269 "shape: (%g, %g, %g)",
00270 s->pixel->x, s->pixel->y,
00271 s->magnitude, s->dmagnitude,
00272 s->magnitude_corr, s->dmagnitude_corr,
00273 s->orientation, s->semi_major, s->semi_minor);
00274 }
00275
00276 return;
00277 }
00278
00284 void
00285 fors_star_print_list(cpl_msg_severity level, const fors_star_list *sl)
00286 {
00287 if (sl == NULL) fors_msg(level, "Null list");
00288 else {
00289 const fors_star *s;
00290
00291 for (s = fors_star_list_first_const(sl);
00292 s != NULL;
00293 s = fors_star_list_next_const(sl)) {
00294 fors_star_print(level, s);
00295 }
00296 }
00297 return;
00298 }
00305 double
00306 fors_star_get_x(const fors_star *s, void *data)
00307 {
00308 assure( s != NULL, return -1, NULL );
00309
00310 data = data;
00311
00312 return s->pixel->x;
00313 }
00314
00321 double
00322 fors_star_get_y(const fors_star *s, void *data)
00323 {
00324 assure( s != NULL, return -1, NULL );
00325
00326 data = data;
00327
00328 return s->pixel->y;
00329 }
00330
00331
00338 double
00339 fors_star_get_zeropoint(const fors_star *s, void *data)
00340 {
00341 assure( s != NULL, return 0, NULL );
00342 assure( s->id != NULL, return 0, NULL );
00343 data = data;
00344
00345 return (s->id->magnitude - s->magnitude_corr);
00346 }
00347
00354 double
00355 fors_star_get_zeropoint_err(const fors_star *s, void *data)
00356 {
00357 assure( s != NULL, return 0, NULL );
00358 assure( s->id != NULL, return 0, NULL );
00359 data = data;
00360
00361 return sqrt(s->dmagnitude_corr * s->dmagnitude_corr +
00362 s->id->dmagnitude * s->id->dmagnitude);
00363 }
00364
00371 bool
00372 fors_star_is_identified(const fors_star *s, void *data)
00373 {
00374 data = data;
00375 assure( s != NULL, return 0, NULL );
00376 return (s->id != NULL);
00377 }
00378
00379 #define LIST_DEFINE
00380 #undef LIST_ELEM
00381 #define LIST_ELEM fors_star
00382 #include <list.h>
00383