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 #include <fors_utils.h>
00034
00035 #include <cpl.h>
00036
00037 #include <math.h>
00038 #include <assert.h>
00039 #include <stdbool.h>
00040 #include <float.h>
00041
00042 #undef cleanup
00043 #define cleanup \
00044 do { \
00045 cpl_table_delete(t); \
00046 } while(0)
00047
00060 fors_std_star *
00061 fors_std_star_new(double ra, double dec, double m, double dm,
00062 double cat_m, double dcat_m,
00063 double col,
00064 const char *name)
00065 {
00066 fors_std_star *s = cpl_malloc(sizeof(*s));
00067
00068 s->ra = ra;
00069 s->dec = dec;
00070 s->magnitude = m;
00071 s->dmagnitude = dm;
00072 s->cat_magnitude = cat_m;
00073 s->dcat_magnitude = dcat_m;
00074 s->color = col;
00075
00076 s->pixel = fors_point_new(-1, -1);
00077
00078 if (name != NULL) {
00079 s->name = cpl_strdup(name);
00080 }
00081 else {
00082 s->name = NULL;
00083 }
00084
00085 return s;
00086 }
00087
00092 void
00093 fors_std_star_delete(fors_std_star **s)
00094 {
00095 if (s && *s) {
00096 fors_point_delete(&(*s)->pixel);
00097 if ((*s)->name != NULL) {
00098 cpl_free((void *)(*s)->name); (*s)->name = NULL;
00099 }
00100 cpl_free(*s); *s = NULL;
00101 }
00102 return;
00103 }
00104
00109 void
00110 fors_std_star_delete_const(const fors_std_star **s)
00111 {
00112 fors_std_star_delete((fors_std_star **)s);
00113 return;
00114 }
00115
00116
00117 #undef cleanup
00118 #define cleanup
00119
00125 fors_std_star *
00126 fors_std_star_duplicate(const fors_std_star *s)
00127 {
00128 fors_std_star *d = NULL;
00129
00130 assure( s != NULL, return NULL, NULL );
00131
00132 d = cpl_malloc(sizeof(*d));
00133
00134 d->ra = s->ra;
00135 d->dec = s->dec;
00136 d->magnitude = s->magnitude;
00137 d->dmagnitude = s->dmagnitude;
00138 d->cat_magnitude = s->cat_magnitude;
00139 d->dcat_magnitude = s->dcat_magnitude;
00140 d->color = s->color;
00141
00142 d->pixel = fors_point_duplicate(s->pixel);
00143 d->name = s->name != NULL ? cpl_strdup(s->name) : NULL;
00144
00145 return d;
00146 }
00147
00156 bool
00157 fors_std_star_equal(const fors_std_star *s,
00158 const fors_std_star *t)
00159 {
00160 assure( s != NULL && t != NULL, return true, NULL );
00161
00162 return(fabs(s->ra - t->ra ) < DBL_EPSILON &&
00163 fabs(s->dec - t->dec) < DBL_EPSILON);
00164 }
00165
00166 #undef cleanup
00167 #define cleanup
00168
00173 void
00174 fors_std_star_print(cpl_msg_severity level, const fors_std_star *star)
00175 {
00176 if (star == NULL) {
00177 fors_msg(level, "NULL std.star");
00178 }
00179 else {
00180 fors_msg(level, "(%7.4f, %7.4f): m = %g +- %g (col = %g), (%7.2f, %7.2f) %s",
00181 star->ra, star->dec,
00182 star->magnitude, star->dmagnitude,
00183 star->color,
00184 star->pixel->x, star->pixel->y,
00185 star->name != NULL ? star->name : "");
00186 }
00187
00188 return;
00189 }
00190
00191
00199 bool
00200 fors_std_star_brighter_than(const fors_std_star *s,
00201 const fors_std_star *t,
00202 void *data)
00203 {
00204 data = data;
00205 return (s->magnitude < t->magnitude);
00206 }
00207
00208 #undef cleanup
00209 #define cleanup
00210
00215 void
00216 fors_std_star_print_list(cpl_msg_severity level, const fors_std_star_list *sl)
00217 {
00218 if (sl == NULL) fors_msg(level, "Null list");
00219 else {
00220 const fors_std_star *s;
00221
00222 for (s = fors_std_star_list_first_const(sl);
00223 s != NULL;
00224 s = fors_std_star_list_next_const(sl)) {
00225
00226 fors_std_star_print(level, s);
00227 }
00228 }
00229 return;
00230 }
00231
00232 #undef cleanup
00233 #define cleanup
00234
00240 double
00241 fors_std_star_dist_arcsec(const fors_std_star *s,
00242 const fors_std_star *t)
00243 {
00244 assure( s != NULL, return -1, NULL );
00245 assure( t != NULL, return -1, NULL );
00246
00247
00248
00249 double s_ra = s->ra * 2*M_PI / 360;
00250 double s_dec = s->dec * 2*M_PI / 360;
00251 double t_ra = t->ra * 2*M_PI / 360;
00252 double t_dec = t->dec * 2*M_PI / 360;
00253
00254 double cos_separation =
00255 sin(s_dec)*sin(t_dec) +
00256 cos(s_dec)*cos(t_dec) * cos(s_ra - t_ra);
00257
00258 if (cos_separation < -1) cos_separation = -1;
00259 if (cos_separation > 1) cos_separation = 1;
00260
00261
00262 return (acos(cos_separation) * 360 / (2*M_PI)) * 3600;
00263 }
00264
00265
00266 #define LIST_DEFINE
00267 #undef LIST_ELEM
00268 #define LIST_ELEM fors_std_star
00269 #include <list.h>
00270