Skip to content

Commit

Permalink
'astcheck' could get confused with truncated 'check' files (which can…
Browse files Browse the repository at this point in the history
… happen if you Ctrl-C in the middle of a run, as I recently did). Now, it checks the file size before assuming it can use the check file in question. Also, put in some test code to look for a possible problem in light-time-lag computation (should converge quickly, got a report in which it didn't... have been unable to verify thus far.)
  • Loading branch information
Bill-Gray committed Mar 7, 2024
1 parent bf53686 commit f59fe40
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions astcheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ static double compute_asteroid_loc( const double *earth_loc,
ELEMENTS *elem, const double jd, double *ra, double *dec)
{
double r1 = 0., dist, asteroid_loc[4];
int i;
int i, n_iterations = 0;

do /* light-time lag: should converge _very_ fast */
{ /* it'll almost always require exactly two iterations */
Expand All @@ -196,6 +196,9 @@ static double compute_asteroid_loc( const double *earth_loc,
for( i = 0; i < 3; i++)
asteroid_loc[i] -= earth_loc[i];
r1 = vector3_length( asteroid_loc);
if( n_iterations >= 15)
fprintf( stderr, "? e=%f, q=%f, jd=%f; diff %f/%f\n", elem->ecc, elem->q, jd, dist - r1, r1);
assert( n_iterations++ < 20);
}
while( fabs( dist - r1) > .001);
ecliptic_to_equatorial( asteroid_loc);
Expand Down Expand Up @@ -306,11 +309,11 @@ file size. */

static AST_DATA *get_cached_day_data( const int ijd)
{
AST_DATA *rval = NULL;
char filename[20];
FILE *ifile, *ofile;
int32_t header[HEADER_SIZE];
const int32_t magic_version_number = 1314159266;
AST_DATA *rval;

/* Create a filename in 'YYYYMMDD.chk' form: */
full_ctime( filename, (double)ijd, FULL_CTIME_YMD | FULL_CTIME_NO_SPACES
Expand All @@ -327,19 +330,18 @@ static AST_DATA *get_cached_day_data( const int ijd)
printf( "Error reading header data in '%s'\n", filename);
exit( -2);
}
if( header[0] != magic_version_number
|| header[1] != sof_checksum || header[2] != n_asteroids)
fclose( ifile);
else /* appears to be legitimate cached data */
if( header[0] == magic_version_number &&
header[1] == sof_checksum && header[2] == n_asteroids)
{
fseek( ifile, 0L, SEEK_END);
if( ftell( ifile) == (n_asteroids + HEADER_SIZE) * 4L)
rval = (AST_DATA *)malloc( n_asteroids * sizeof( AST_DATA));
fseek( ifile, (long)sizeof( header), SEEK_SET);
}
if( rval) /* appears to be legitimate cached data */
{
int n_read = 0, n_iterations = 0;

rval = (AST_DATA *)malloc( n_asteroids * sizeof( AST_DATA));
if( !rval)
{
printf( "Ran out of memory\n");
exit( -4);
}
while( n_read != n_asteroids)
{
n_read += (int)fread( rval + n_read, sizeof( AST_DATA),
Expand Down Expand Up @@ -371,6 +373,7 @@ static AST_DATA *get_cached_day_data( const int ijd)
fclose( ifile);
return( rval);
}
fclose( ifile);
}
header[0] = magic_version_number;
header[1] = sof_checksum;
Expand Down

0 comments on commit f59fe40

Please sign in to comment.