From 06680af02445218bd54f5df0df0013149b8a674c Mon Sep 17 00:00:00 2001 From: Bill-Gray Date: Sun, 3 Dec 2023 16:09:28 -0500 Subject: [PATCH] Added get_ra_dec_from_string() and get_dec_from_string() functions. To be used initially in the satellites-in-field-finding program, but they should be used anywhere RA or dec strings are input and parsed. --- mpc_code.cpp | 39 ++++++++++++++++++++++++++++++++++++++- mpc_func.h | 2 ++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/mpc_code.cpp b/mpc_code.cpp index f41fb74..0ebeb8a 100644 --- a/mpc_code.cpp +++ b/mpc_code.cpp @@ -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) @@ -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 diff --git a/mpc_func.h b/mpc_func.h index 1c02709..d6a1958 100644 --- a/mpc_func.h +++ b/mpc_func.h @@ -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,