32 #include <fors_star.h>
33 #include <fors_utils.h>
51 double _square(
double a);
73 cpl_errorstate errstat = cpl_errorstate_get();
76 if (colname != NULL && colname[0] !=
'\0')
79 d = cpl_table_get( tab, colname, row, &null);
80 if (!cpl_errorstate_is_equal(errstat))
82 switch (errc = cpl_error_get_code())
84 case CPL_ERROR_DATA_NOT_FOUND:
85 cpl_error_set_message( cpl_func,
87 "Column \"%s\" not found",
90 case CPL_ERROR_INVALID_TYPE:
91 cpl_error_set_message( cpl_func,
93 "Column \"%s\" is not numeric",
109 unsigned char bytes[8];
112 for (n = 0; n < 8; n++)
113 nan.bytes[n] = (
unsigned char)255;
126 double _square(
double a)
141 cpl_table_delete(t); \
162 fors_std_star *fors_std_star_new(
double ra,
double dec,
164 double cat_m,
double dcat_m,
165 double col,
double dcol,
169 fors_std_star *s = cpl_malloc(
sizeof(*s));
175 s->cat_magnitude = cat_m;
176 s->dcat_magnitude = dcat_m;
179 s->cov_catm_color = cov_catm_col;
184 s->name = cpl_strdup(name);
197 #define cleanup fors_std_star_delete(&s)
229 fors_std_star *fors_std_star_new_from_table(
230 const cpl_table *tab,
235 const char *dmag_col,
236 const char *catmag_col,
237 const char *dcatmag_col,
238 const char *color_col,
239 const char *dcolor_col,
240 const char *cov_catm_color_col,
243 const char *name_col)
245 cpl_errorstate errstat = cpl_errorstate_get();
249 fors_std_star *s = cpl_malloc(
sizeof(*s));
253 assure(cpl_errorstate_is_equal(errstat),
return s, NULL);
255 assure(cpl_errorstate_is_equal(errstat),
return s, NULL);
257 assure(cpl_errorstate_is_equal(errstat),
return s, NULL);
259 assure(cpl_errorstate_is_equal(errstat),
return s, NULL);
261 assure(cpl_errorstate_is_equal(errstat),
return s, NULL);
263 assure(cpl_errorstate_is_equal(errstat),
return s, NULL);
265 assure(cpl_errorstate_is_equal(errstat),
return s, NULL);
267 assure(cpl_errorstate_is_equal(errstat),
return s, NULL);
270 assure(cpl_errorstate_is_equal(errstat),
return s, NULL);
275 (isnan(y) ? -1 : y));
276 assure(cpl_errorstate_is_equal(errstat),
return s, NULL);
277 if (s->pixel->x < 1) s->pixel->x = -1;
278 if (s->pixel->y < 1) s->pixel->y = -1;
281 if (name_col != NULL)
284 str = cpl_table_get_string(tab, name_col, row);
285 if (!cpl_errorstate_is_equal(errstat))
288 switch (errc = cpl_error_get_code())
290 case CPL_ERROR_DATA_NOT_FOUND:
291 cpl_error_set_message( cpl_func,
293 "Column \"%s\" not found",
296 case CPL_ERROR_INVALID_TYPE:
297 cpl_error_set_message( cpl_func,
299 "Column \"%s\" is not string type",
308 s->name = cpl_strdup(str);
322 void fors_std_star_delete( fors_std_star **s){
325 if ((*s)->name != NULL) {
326 cpl_free((
void *)(*s)->name); (*s)->name = NULL;
328 cpl_free(*s); *s = NULL;
339 void fors_std_star_delete_const(
const fors_std_star **s){
340 fors_std_star_delete((fors_std_star **)s);
353 fors_std_star *fors_std_star_duplicate(
const fors_std_star *s)
355 fors_std_star *d = NULL;
357 assure( s != NULL,
return NULL, NULL );
359 d = cpl_malloc(
sizeof(*d));
363 d->magnitude = s->magnitude;
364 d->dmagnitude = s->dmagnitude;
365 d->cat_magnitude = s->cat_magnitude;
366 d->dcat_magnitude = s->dcat_magnitude;
368 d->dcolor = s->dcolor;
369 d->cov_catm_color = s->cov_catm_color;
372 d->name = s->name != NULL ? cpl_strdup(s->name) : NULL;
374 d->trusted = s->trusted;
389 void fors_std_star_set_name( fors_std_star *s,
392 assure( s != NULL,
return, NULL );
395 s->name = (name != NULL) ? cpl_strdup(name) : NULL;
410 bool fors_std_star_equal(
const fors_std_star *s,
411 const fors_std_star *t)
413 assure( s != NULL && t != NULL,
return true, NULL );
415 return( s->trusted && t->trusted &&
416 fabs(s->ra - t->ra ) < DBL_EPSILON &&
417 fabs(s->dec - t->dec) < DBL_EPSILON);
429 void fors_std_star_print( cpl_msg_severity level,
430 const fors_std_star *star)
433 fors_msg(level,
"NULL std.star");
436 fors_msg(level,
"(%7.4f, %7.4f): %sm = %g +- %g "
437 "(col = %g +- %g)%s, (x=%7.2f, y=%7.2f) %s",
439 (star->trusted ?
"" :
"untrusted magnitude (values are: "),
440 star->magnitude, star->dmagnitude,
441 star->color, star->dcolor,
442 (star->trusted ?
"" :
")"),
443 star->pixel->x, star->pixel->y,
444 ((star->name != NULL) ? star->name :
""));
459 void fors_std_star_print_list( cpl_msg_severity level,
460 const fors_std_star_list *sl)
462 if (sl == NULL) fors_msg(level,
"Null list");
464 const fors_std_star *s;
466 for (s = fors_std_star_list_first_const(sl);
468 s = fors_std_star_list_next_const(sl)) {
470 fors_std_star_print(level, s);
485 bool fors_std_star_brighter_than(
const fors_std_star *s,
486 const fors_std_star *t,
489 return (s->trusted && t->trusted &&
490 s->magnitude < t->magnitude);
503 double fors_std_star_dist_arcsec(
const fors_std_star *s,
504 const fors_std_star *t)
506 assure( s != NULL,
return -1, NULL );
507 assure( t != NULL,
return -1, NULL );
511 double s_ra = s->ra * 2*M_PI / 360;
512 double s_dec = s->dec * 2*M_PI / 360;
513 double t_ra = t->ra * 2*M_PI / 360;
514 double t_dec = t->dec * 2*M_PI / 360;
516 double cos_separation =
517 sin(s_dec)*sin(t_dec) +
518 cos(s_dec)*cos(t_dec) * cos(s_ra - t_ra);
520 if (cos_separation < -1) cos_separation = -1;
521 if (cos_separation > 1) cos_separation = 1;
524 return (acos(cos_separation) * 360 / (2*M_PI)) * 3600;
538 void fors_std_star_compute_corrected_mag(
543 cassure( s != NULL, CPL_ERROR_NULL_INPUT,
return, NULL);
545 s->magnitude = s->cat_magnitude - color_term * s->color;
546 s->dmagnitude = sqrt( _square(s->dcat_magnitude)
547 - 2.0 * color_term * s->cov_catm_color
548 + _square(color_term * s->dcolor)
549 + _square(s->color * dcolor_term));
555 #define LIST_ELEM fors_std_star
fors_point * fors_point_new(double x, double y)
Constructor.
static double _get_optional_table_value(const cpl_table *tab, unsigned int row, const char *colname)
Get a double value from a table.
void fors_point_delete(fors_point **p)
Destructor.
fors_point * fors_point_duplicate(const fors_point *p)
Copy constructor.