Skip to content

Commit

Permalink
Added get_ra_dec_from_string() and get_dec_from_string() functions. T…
Browse files Browse the repository at this point in the history
…o be used initially in the satellites-in-field-finding program, but they should be used anywhere RA or dec strings are input and parsed.
  • Loading branch information
Bill-Gray committed Dec 3, 2023
1 parent 4bf4ee7 commit 06680af
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
39 changes: 38 additions & 1 deletion mpc_code.cpp
Expand Up @@ -446,8 +446,11 @@ static double _get_angle( const char *buff, int *nbytes, int *n_fields)
{
double rval;
const char *tptr = buff;
int is_integer;
int is_integer, dummy_nbytes;

assert( n_fields);
if( !nbytes)
nbytes = &dummy_nbytes;
*n_fields = 0;
rval = _get_number_for_angle( buff, nbytes, &is_integer);
if( is_integer != -1)
Expand Down Expand Up @@ -645,6 +648,40 @@ int get_lat_lon_info( mpc_code_t *cinfo, const char *buff)
return( rval);
}

double get_ra_from_string( const char *buff, int *bytes_read)
{
int n_fields;
double rval = _get_angle( buff, bytes_read, &n_fields);

if( n_fields > 2) /* assume HH MM.mm or HH MM SS.sss */
rval *= 15.;
if( !n_fields || rval > 360.)
*bytes_read = 0;
return( rval * PI / 180.);
}

double get_dec_from_string( const char *buff, int *bytes_read)
{
if( *buff != '+' && *buff != '-')
{
*bytes_read = 0;
return( 0.);
}
else
{
int n_fields;
double rval = _get_angle( buff + 1, bytes_read, &n_fields);

if( !n_fields || rval > 90.)
*bytes_read = 0;
if( *buff == '-')
rval = -rval;
if( n_fields)
(*bytes_read)++;
return( rval * PI / 180.);
}
}

/* https://www.minorplanetcenter.net/iau/info/Astrometry.html#HowObsCode
suggests that you start out using "observatory code" (XXX), whilst
including a comment such as
Expand Down
2 changes: 2 additions & 0 deletions mpc_func.h
Expand Up @@ -50,6 +50,8 @@ typedef struct
int get_mpc_code_info( mpc_code_t *cinfo, const char *buff);
int get_xxx_location_info( mpc_code_t *cinfo, const char *buff);
int get_lat_lon_info( mpc_code_t *cinfo, const char *buff);
double get_ra_from_string( const char *buff, int *bytes_read);
double get_dec_from_string( const char *buff, int *bytes_read);
double point_to_ellipse( const double a, const double b,
const double x, const double y, double *dist);
int lat_alt_to_parallax( const double lat, const double ht_in_meters,
Expand Down

0 comments on commit 06680af

Please sign in to comment.