Skip to content

Commit

Permalink
MPC designations such as 217P are now recognized for packing, and whe…
Browse files Browse the repository at this point in the history
…n unpacking, we use that instead of P/217. Some fixes for comet fragment designations, interstellar objects, and a few added tests in 'test_des.txt'. Also, packed designations that combine permanent and provisional IDs are now handled better.
  • Loading branch information
Bill-Gray committed Aug 11, 2024
1 parent 9ca2863 commit e8a50e9
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
13 changes: 12 additions & 1 deletion mpc_fmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -734,11 +734,22 @@ int create_mpc_packed_desig( char *packed_desig, const char *obj_name)
if( i == len) /* nothing but numbers */
if( number > 0 && number < 1000000 && i >= 5)
in_parentheses = true;
if( number > 0 && number < 10000 && obj_name[i] && !obj_name[i + 1]
if( number > 0 && number < 10000 && obj_name[i]
&& (!obj_name[i + 1] || obj_name[i + 1] == '-')
&& strchr( "PDI", obj_name[i]))
{ /* such as '297P', '1I', etc. */
snprintf( packed_desig, 5, "%04d", number);
packed_desig[4] = obj_name[i];
if( obj_name[i + 1] == '-' && isupper( obj_name[i + 2]))
{ /* fragment designation */
if( isupper( obj_name[i + 3])) /* two-letter fragment */
{
packed_desig[10] = obj_name[i + 2] + 'a' - 'A';
packed_desig[11] = obj_name[i + 3] + 'a' - 'A';
}
else /* single-letter fragment desig */
packed_desig[11] = obj_name[i + 2] + 'a' - 'A';
}
return( 0);
}

Expand Down
13 changes: 10 additions & 3 deletions test_des.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,23 @@
# N210S; on unpacking, it becomes 'Neptune CCX'.
# Test 2
N210S 5 Neptune 210
# And we have some unpacking-only tests. The following should
# be unpacked correctly, but you lose the redundant provisional desig
# data in the process. So it can't be packed to get the original input.
# Test 1
0001IK17U010 3 1I
0001PI35P010 3 1P
67282J99A38M 1 (67282) = 1999 AM38
# All the other tests are bidirectional :
# Test 3
# Packed Typ Fullname
J95X00A 0 1995 XA
K07Tf8A 0 2007 TA418
SK03J020 4 S/2003 J 2
SJ45Ux90 4 S/1945 U 599
0041P 3 P/41
3141P e 3 P/3141-E
3141P az 3 P/3141-AZ
0041P 3 41P
3141P e 3 3141P-E
3141P az 3 3141P-AZ
DJ65Az9c 2 D/1965 A619-C
XJ65K810 2 X/1965 K81
PLS2040 0 2040 P-L
Expand Down
9 changes: 4 additions & 5 deletions unpack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ int unpack_mpc_desig( char *obuff, const char *packed)
start with an alphanumeric and be followed by three digits.
Four, if it's a numbered asteroid. */
if( isalnum( packed[0]) && (digit_mask & 0xe) == 0xe
&& (space_mask & 0x3e0) == 0x3e0)
&& ((space_mask & 0x3e0) == 0x3e0 || *provisional_desig))
{
if( isdigit( packed[4]))
{ /* it's a numbered asteroid */
Expand All @@ -283,20 +283,19 @@ int unpack_mpc_desig( char *obuff, const char *packed)
}
}
}
else if( strchr( "PCDXA", packed[4])) /* it's a numbered comet */
else if( strchr( "PCDXAI", packed[4])) /* it's a numbered comet */
{
if( obuff)
{
int j = 2;
int j = 0;
const char suffix_char = packed[11];

obuff[0] = packed[4];
obuff[1] = '/';
i = 0;
while( packed[i] == '0') /* skip leading zeroes */
i++;
while( packed[i] >= '0' && packed[i] <= '9') /* read digits... */
obuff[j++] = packed[i++];
obuff[j++] = packed[4];
if( suffix_char >= 'a' && suffix_char <= 'z')
{
const char extra_suffix_char = packed[10];
Expand Down

0 comments on commit e8a50e9

Please sign in to comment.