Skip to content

Commit f1b4265

Browse files
committed
If 'sat_id' found an object in the non-Spacetrack TLEs, it wouldn't look for it in the Spacetrack TLEs, even if the time span of the former didn't actually cover the observations in question. This is now fixed; we now maintain not only a list of which objects have been tested via non-Spacetrack TLEs, but the time span those TLEs covered.
1 parent d8a1315 commit f1b4265

1 file changed

Lines changed: 27 additions & 21 deletions

File tree

sat_id.cpp

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -954,23 +954,30 @@ static void remove_redundant_desig( char *name, const char *desig)
954954
/* We check astrometry first against TLEs from github.com/Bill-Gray/tles,
955955
then some other sources such as the amateur community's TLEs, and
956956
only then against Space-Track TLEs. If we've already checked an
957-
object against the previous sources, then we really ought not to
958-
check the Space-Track TLEs. For one thing, the mere fact that we've
959-
gone to the effort of computing "our own" TLEs means the Space-Track
960-
TLEs are unreliable (some have poor accuracy; others are not consistently
961-
available).
957+
object against the previous sources, using TLEs whose date range would
958+
cover that object, then we really ought not to check the Space-Track
959+
TLEs. For one thing, the mere fact that we've gone to the effort of
960+
computing "our own" TLEs means the Space-Track TLEs are unreliable (some
961+
have poor accuracy; others are not consistently available).
962962
963963
Therefore, we maintain a list of '# ID:' numbers from tle_list.txt, and when we
964964
get to '# ID off', we figure we're in Space-Track TLE territory. If we
965965
encounter a NORAD number that's in our list, we essentially say :
966966
we already found this object and have handled it. */
967967

968-
static bool already_found_desig( const int curr_norad, size_t n_norad_ids, const int *norad_ids)
968+
typedef struct
969+
{
970+
int norad_number;
971+
double min_jd, max_jd;
972+
} already_found_t;
973+
974+
static bool already_found_desig( const int curr_norad, size_t n_found,
975+
const already_found_t *found, double jd)
969976
{
970977
bool rval = false;
971978

972-
while( !rval && n_norad_ids)
973-
rval = (curr_norad == norad_ids[--n_norad_ids]);
979+
for( size_t i = 0; !rval && i < n_found; i++)
980+
rval = (curr_norad == found[i].norad_number && jd > found[i].min_jd && jd < found[i].max_jd);
974981
return( rval);
975982
}
976983

@@ -1018,7 +1025,7 @@ static int add_tle_to_obs( object_t *objects, const size_t n_objects,
10181025
bool look_for_tles = true;
10191026
static bool error_check_date_ranges = true;
10201027
const clock_t time_started = clock( );
1021-
static int *norad_ids = NULL;
1028+
static already_found_t *norad_ids = NULL;
10221029
static size_t n_norad_ids = 0;
10231030
const double mjd_1970 = 40587.; /* MJD for 1970 Jan 1 */
10241031
const double curr_mjd = mjd_1970 + (double)time( NULL) / 86400.;
@@ -1027,6 +1034,7 @@ static int add_tle_to_obs( object_t *objects, const size_t n_objects,
10271034
{
10281035
if( norad_ids)
10291036
free( norad_ids);
1037+
norad_ids = NULL;
10301038
n_norad_ids = 0;
10311039
return( 0);
10321040
}
@@ -1076,8 +1084,7 @@ static int add_tle_to_obs( object_t *objects, const size_t n_objects,
10761084
if( is_a_tle && (tle.ephemeris_type == 'H'
10771085
|| tle.xno < 2. * PI * max_revs_per_day / mins_per_day)
10781086
&& (!norad_id || norad_id == tle.norad_number)
1079-
&& (!intl_desig || !_compare_intl_desigs( tle.intl_desig, intl_desig))
1080-
&& (search_norad || !already_found_desig( tle.norad_number, n_norad_ids, norad_ids)))
1087+
&& (!intl_desig || !_compare_intl_desigs( tle.intl_desig, intl_desig)))
10811088
{ /* hey! we got a TLE! */
10821089
double sat_params[N_SAT_PARAMS];
10831090
size_t idx;
@@ -1096,7 +1103,8 @@ static int add_tle_to_obs( object_t *objects, const size_t n_objects,
10961103

10971104
assert( obj_ptr->idx1 <= obj_ptr->idx2);
10981105
assert( optr2->jd >= optr1->jd);
1099-
if( is_in_range( optr1->jd, tle_start, tle_range))
1106+
if( is_in_range( optr1->jd, tle_start, tle_range) &&
1107+
(search_norad || !already_found_desig( tle.norad_number, n_norad_ids, norad_ids, optr1->jd)))
11001108
{
11011109
double radius;
11021110
double ra, dec, dist_to_satellite;
@@ -1361,17 +1369,15 @@ static int add_tle_to_obs( object_t *objects, const size_t n_objects,
13611369
strlcpy_err( iname + i, line2 + 10, sizeof( iname) - i);
13621370
if( verbose > 1)
13631371
printf( "Including '%s'\n", iname);
1364-
i = 0;
1365-
while( i < n_norad_ids && search_norad > norad_ids[i])
1366-
i++;
1367-
if( i == n_norad_ids || search_norad != norad_ids[i])
1368-
{ /* insert newly-found ID */
1372+
if( search_norad)
1373+
{ /* add newly-found ID */
13691374
if( !n_norad_ids)
1370-
norad_ids = (int *)malloc( sizeof( int));
1375+
norad_ids = (already_found_t *)malloc( sizeof( already_found_t));
13711376
else if( is_power_of_two( n_norad_ids))
1372-
norad_ids = (int *)realloc( norad_ids, 2 * n_norad_ids * sizeof( int));
1373-
memmove( norad_ids + i + 1, norad_ids + i, (n_norad_ids - i) * sizeof( int));
1374-
norad_ids[i] = search_norad;
1377+
norad_ids = (already_found_t *)realloc( norad_ids, 2 * n_norad_ids * sizeof( already_found_t));
1378+
norad_ids[n_norad_ids].norad_number = search_norad;
1379+
norad_ids[n_norad_ids].min_jd = tle_start;
1380+
norad_ids[n_norad_ids].max_jd = tle_start + tle_range;
13751381
n_norad_ids++;
13761382
}
13771383
rval = add_tle_to_obs( objects, n_objects, iname, search_radius,

0 commit comments

Comments
 (0)