Skip to content

Commit

Permalink
For both fo and find_orb, the -P (desig) option can specify which pac…
Browse files Browse the repository at this point in the history
…ked designation(s) are to be processed; the -N (fullname) can specify the full name(s) of an object or objects that are to be processed.
  • Loading branch information
Bill-Gray committed May 2, 2023
1 parent 055ab06 commit e6bd855
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 7 deletions.
14 changes: 14 additions & 0 deletions findorb.cpp
Expand Up @@ -3801,6 +3801,13 @@ int main( int argc, const char **argv)
case 'n':
max_mpc_color_codes = atoi( arg);
break;
case 'N':
{
extern const char *fullname_pattern;

fullname_pattern = arg;
}
break;
case 'O': /* write output files to specified dir */
{
extern const char *output_directory;
Expand All @@ -3817,6 +3824,13 @@ int main( int argc, const char **argv)
process_count = atoi( arg);
}
break;
case 'P':
{
extern const char *desig_pattern;

desig_pattern = arg;
}
break;
case 'q':
{
extern bool take_first_soln;
Expand Down
11 changes: 9 additions & 2 deletions fo.cpp
Expand Up @@ -593,9 +593,9 @@ int main( int argc, const char **argv)
break;
case 'N':
{
extern const char *desig_pattern;
extern const char *fullname_pattern;

desig_pattern = arg;
fullname_pattern = arg;
}
break;
case 'O': /* write output files to specified dir */
Expand All @@ -607,6 +607,13 @@ int main( int argc, const char **argv)
break;
case 'o': /* obj designation / ephemeris from orbital */
break; /* elems: fall through, handle below */
case 'P':
{
extern const char *desig_pattern;

desig_pattern = arg;
}
break;
case 'p':
{
FILE *ifile = fopen_ext( "dummy.txt", "tfcw");
Expand Down
41 changes: 36 additions & 5 deletions mpc_obs.cpp
Expand Up @@ -4287,7 +4287,7 @@ void sort_object_info( OBJECT_INFO *ids, const int n_ids,
&object_info_compare_method);
}

const char *desig_pattern = NULL;
const char *desig_pattern = NULL, *fullname_pattern = NULL;

/* One can specify, e.g., '-N C314159,K22Ea4C' to process only
those two objects. I may eventually implement something more
Expand Down Expand Up @@ -4318,6 +4318,28 @@ static bool desig_pattern_matched( OBJECT_INFO *id, const char *pattern)
return( false);
}

static bool fullname_pattern_matched( const char *full_name, const char *pattern)
{
size_t i = 0, j;

while( pattern[i])
{
char tpattern[80];

j = i;
while( pattern[j] != ',' && pattern[j])
j++;
assert( j - i < sizeof( tpattern) - 1);
strlcpy( tpattern, pattern + i, j - i + 1);
if( pattern_match( tpattern, full_name))
return( true);
i = j;
if( pattern[i] == ',')
i++;
}
return( false);
}

/* find_objects_in_file( ) reads through the file of MPC astrometric data
specified by 'filename', and figures out which objects appear in that
file. Those objects can then be listed on the console (findorb) or
Expand Down Expand Up @@ -4567,22 +4589,31 @@ OBJECT_INFO *find_objects_in_file( const char *filename,
while( i < n)
if( !desig_pattern_matched( rval + i, desig_pattern))
{
memmove( rval+ i, rval + i + 1, (n - i - 1) * sizeof( OBJECT_INFO));
memmove( rval + i, rval + i + 1, (n - i - 1) * sizeof( OBJECT_INFO));
n--;
}
else
i++;
}
*n_found = n;
rval = (OBJECT_INFO *)realloc( rval, n * sizeof( OBJECT_INFO));
/* Only now do we set the 'full' object names, because */
/* some may have been added mid-file using COM fullname. */
for( i = 0; i < n; i++)
{
get_object_name( buff, rval[i].packed_desig);
rval[i].obj_name = (char *)stack_alloc( obj_name_stack, strlen( buff) + 1);
strcpy( rval[i].obj_name, buff);
if( fullname_pattern && !fullname_pattern_matched( buff, fullname_pattern))
{
memmove( rval + i, rval + i + 1, (n - i - 1) * sizeof( OBJECT_INFO));
n--;
i--;
}
else
{
rval[i].obj_name = (char *)stack_alloc( obj_name_stack, strlen( buff) + 1);
strcpy( rval[i].obj_name, buff);
}
}
*n_found = n;
sort_object_info( rval, n, OBJECT_INFO_COMPARE_PACKED);
return( rval);
}
Expand Down

0 comments on commit e6bd855

Please sign in to comment.