Skip to content

Commit 65a6993

Browse files
committed
get_satellite_offset() is now in 'mpc_fmt.cpp' in the lunar library (q.v.) Several other programs also get spacecraft offsets (add_off, sat_id, eventually astcheck and others); they should use a common routine to do so.
1 parent 5ca0d73 commit 65a6993

File tree

2 files changed

+0
-115
lines changed

2 files changed

+0
-115
lines changed

ades_out.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ FILE *fopen_ext( const char *filename, const char *permits); /* miscell.cpp */
4545
char *fgets_trimmed( char *buff, size_t max_bytes, FILE *ifile); /*elem_out.c*/
4646
double utc_from_td( const double jdt, double *delta_t); /* ephem0.cpp */
4747
char *iso_time( char *buff, const double jd, const int precision); /* elem_out.c */
48-
int get_satellite_offset( const char *iline, double *xyz); /* mpc_obs.cpp */
4948
int text_search_and_replace( char FAR *str, const char *oldstr,
5049
const char *newstr); /* ephem0.cpp */
5150
double original_observed_ra( const OBSERVE *obs); /* ephem0.cpp */

mpc_obs.cpp

-114
Original file line numberDiff line numberDiff line change
@@ -903,118 +903,6 @@ static int get_observer_data_latlon( const char FAR *mpc_code,
903903
return( rval);
904904
}
905905

906-
/* The offset between a satellite observation and the earth or sun */
907-
/* is stored in a second line, as described at */
908-
/* https://www.minorplanetcenter.net/iau/info/SatelliteObs.html */
909-
/* This format allows parallax type '1' in kilometers or type '2' */
910-
/* in AU. If the input file contains the line '#relax_xyz', Find_Orb */
911-
/* is less picky about where decimal points and +/- signs appear. */
912-
/* (It used to insist that the field be "filled out" with digits, but */
913-
/* at least some records contain lower precision positions. Thus far, */
914-
/* the ones I've seen still had enough digits to match the precision of */
915-
/* the instrument, so I'm letting "short" records slide if they're */
916-
/* only lacking three or fewer places.) */
917-
918-
#define SATELL_COORD_ERR_NO_ERROR 0
919-
#define SATELL_COORD_ERR_BAD_SIGN -1
920-
#define SATELL_COORD_ERR_BAD_NUMBER -2
921-
#define SATELL_COORD_ERR_NO_DECIMAL -3
922-
#define SATELL_COORD_ERR_DECIMAL_MISPLACED -4
923-
#define SATELL_COORD_ERR_UNKNOWN_OFFSET -5
924-
#define SATELL_COORD_ERR_EXACTLY_ZERO -6
925-
#define SATELL_COORD_ERR_INSIDE_EARTH -7
926-
927-
#define N_SATELL_COORD_ERRORS 8
928-
929-
static bool strict_sat_xyz_format = true;
930-
931-
inline double get_satellite_coordinate( const char *iptr, int *decimal_loc)
932-
{
933-
char tbuff[12];
934-
const char sign_byte = *iptr;
935-
double rval = 0.;
936-
937-
memcpy( tbuff, iptr, 11);
938-
tbuff[11] = '\0';
939-
if( !strict_sat_xyz_format)
940-
{
941-
rval = atof( tbuff + 1);
942-
if( sign_byte == '-')
943-
rval = -rval;
944-
*decimal_loc = 0;
945-
}
946-
else if( sign_byte != '+' && sign_byte != '-')
947-
{
948-
*decimal_loc = SATELL_COORD_ERR_BAD_SIGN;
949-
rval = atof( tbuff);
950-
}
951-
else
952-
{
953-
char *tptr;
954-
int n_bytes_read;
955-
956-
if( sscanf( tbuff + 1, "%lf%n", &rval, &n_bytes_read) != 1
957-
|| n_bytes_read < 7)
958-
*decimal_loc = SATELL_COORD_ERR_BAD_NUMBER;
959-
else if( (tptr = strchr( tbuff, '.')) == NULL)
960-
*decimal_loc = SATELL_COORD_ERR_NO_DECIMAL;
961-
else
962-
*decimal_loc = (int)( tptr - tbuff);
963-
if( sign_byte == '-')
964-
rval = -rval;
965-
if( *decimal_loc <= 0)
966-
debug_printf( "decimal loc %d: '%s', n_bytes_read %d\n", *decimal_loc,
967-
tbuff, n_bytes_read);
968-
}
969-
return( rval);
970-
}
971-
972-
int get_satellite_offset( const char *iline, double *xyz)
973-
{
974-
size_t i;
975-
int error_code = 0;
976-
const int observation_units = (int)iline[32] - '0';
977-
double r2 = 0., min_radius;
978-
979-
assert( 80 == strlen( iline));
980-
if( !strcmp( iline + 77, "275")) /* geocentric occultation observations */
981-
min_radius = 0.; /* can have offsets inside the earth; */
982-
else /* others should be outside the atmosphere */
983-
min_radius = 1.01 * EARTH_RADIUS_IN_AU;
984-
for( i = 0; i < 3; i++) /* in case of error, use 0 offsets */
985-
xyz[i] = 0.;
986-
iline += 34; /* this is where the offsets start */
987-
for( i = 0; i < 3; i++, iline += 12)
988-
{
989-
int decimal_loc;
990-
991-
xyz[i] = get_satellite_coordinate( iline, &decimal_loc);
992-
if( decimal_loc < 0 && !error_code)
993-
error_code = decimal_loc;
994-
if( observation_units == 1) /* offset given in km */
995-
{
996-
xyz[i] /= AU_IN_KM;
997-
if( strict_sat_xyz_format && !error_code)
998-
if( decimal_loc < 6 || decimal_loc > 8)
999-
error_code = SATELL_COORD_ERR_DECIMAL_MISPLACED;
1000-
if( !error_code && xyz[i] == 0.)
1001-
error_code = SATELL_COORD_ERR_EXACTLY_ZERO;
1002-
}
1003-
else if( observation_units == 2) /* offset in AU */
1004-
{ /* offset must be less than 100 AU */
1005-
if( strict_sat_xyz_format && !error_code)
1006-
if( decimal_loc != 2 && decimal_loc != 3)
1007-
error_code = SATELL_COORD_ERR_DECIMAL_MISPLACED;
1008-
}
1009-
else if( !error_code) /* don't know about this sort of offset */
1010-
error_code = SATELL_COORD_ERR_UNKNOWN_OFFSET;
1011-
r2 += xyz[i] * xyz[i];
1012-
}
1013-
if( !error_code && r2 < min_radius * min_radius)
1014-
error_code = SATELL_COORD_ERR_INSIDE_EARTH;
1015-
equatorial_to_ecliptic( xyz);
1016-
return( error_code);
1017-
}
1018906

1019907
/* Used in part for sanity checks ("is the observed RA/dec above the
1020908
horizon? Is the sun _below_ the horizon at that time?") Either
@@ -3995,8 +3883,6 @@ OBSERVE FAR *load_observations( FILE *ifile, const char *packed_desig,
39953883
including_obs = true;
39963884
else if( !memcmp( buff, "#toffset", 7))
39973885
observation_time_offset = atof( buff + 8) / seconds_per_day;
3998-
else if( !memcmp( buff, "#relax_xyz", 10))
3999-
strict_sat_xyz_format = false;
40003886
else if( !memcmp( buff, "#interstellar", 12))
40013887
is_interstellar = 1;
40023888
else if( !memcmp( buff, "#time ", 6))

0 commit comments

Comments
 (0)