diff --git a/satutl.c b/satutl.c index ccbefda..c5a5911 100644 --- a/satutl.c +++ b/satutl.c @@ -32,12 +32,13 @@ int ii; } } -// If current_line doesn't start with "1 " or "2 ", copy it to satname, -// stripping a potential leading "0 ", leading whitespaces and trailing -// whitespaces and newline -void conditional_copy_satname(char * satname, char * current_line) { - if ((current_line[0] != '1' || current_line[1] != ' ') && - (current_line[0] != '2' || current_line[1] != ' ')) { +// If current_line not lenght of 70 or doesn't start with "1 " or "2 ",copy it +// to satname, stripping a potential leading "0 ", leading whitespaces and +// trailing whitespaces and newline +void conditional_copy_satname(char *satname, char *current_line) { + if ((strlen(current_line) != 70) || + ((current_line[0] != '1' || current_line[1] != ' ') && + (current_line[0] != '2' || current_line[1] != ' '))) { // Name line found // st_start will strip the leading whitespaces if (current_line[0] == '0' && current_line[1] == ' ') { @@ -89,16 +90,18 @@ int read_twoline(FILE *fp, long search_satno, orbit_t *orb, char *satname) st1 = st_start(line1); conditional_copy_satname(tmp_satname, line1); - } while(st1[0] != '1'); + } while((st1[0] != '1') || (st1[1] != ' ')); - if (search_satno == 0) { + if (search_satno != 0) { + sprintf(search, "1 %05ld", search_satno); + } else { // If no search_satno given, set it to the currently read one // so next do/while loop will find it search_satno = atol(st1+2); + strncpy(search, line1, 7); + search[7] = '\0'; } - sprintf(search, "1 %05ld", search_satno); - do { st1 = st_start(line1); if(strncmp(st1, search, 7) == 0) @@ -110,8 +113,7 @@ int read_twoline(FILE *fp, long search_satno, orbit_t *orb, char *satname) conditional_copy_satname(tmp_satname, line1); } while(fgets(line1, ST_SIZE-1, fp) != NULL); - - sprintf(search, "2 %05ld", search_satno); + search[0] = '2'; if(found) { diff --git a/tests/data/catalog.tle b/tests/data/catalog.tle index fd461d1..f4a8d2f 100644 --- a/tests/data/catalog.tle +++ b/tests/data/catalog.tle @@ -132,3 +132,15 @@ 0 CPOD FLT2 (TYVAK-0033) 1 52780U 22057BB 23036.86744141 .00018086 00000-0 87869-3 0 9991 2 52780 97.5313 154.3283 0011660 53.1934 307.0368 15.18441019 16465 +1998-067WV +1 60955U 98067WV 24295.33823779 .06453473 12009-4 26290-2 0 9998 +2 60955 51.6166 43.0490 0010894 336.3668 23.6849 16.22453324 8315 +2 PATHFINDER +1 45727U 20037E 24323.73967089 .00003818 00000+0 31595-3 0 9995 +2 45727 97.7798 139.6782 0011624 329.2427 30.8113 14.99451155239085 +0 SHINSEI (MS-F2) +1 5485U 71080A 24324.43728894 .00000099 00000-0 13784-3 0 9992 +2 5485 32.0564 70.0187 0639723 198.9447 158.6281 12.74214074476065 +OSCAR 7 (AO-7) +1 07530U 74089B 24323.87818483 -.00000039 00000+0 47934-4 0 9997 +2 07530 101.9893 320.0351 0012269 147.9195 274.9996 12.53682684288423 diff --git a/tests/tests_rftles.c b/tests/tests_rftles.c index cc20232..5fe833c 100644 --- a/tests/tests_rftles.c +++ b/tests/tests_rftles.c @@ -70,9 +70,9 @@ void TLE_load_invalid_index_from_file(void **state) { tle_array_t tle_array = **(tle_array_t **)state; assert_non_null(tle_array.tles); - assert_int_equal(tle_array.number_of_elements, 45); + assert_int_equal(tle_array.number_of_elements, 49); - tle_t * tle = get_tle_by_index(&tle_array, 46); + tle_t * tle = get_tle_by_index(&tle_array, 50); assert_null(tle); } @@ -80,7 +80,7 @@ void TLE_load_index_from_file(void **state) { tle_array_t tle_array = **(tle_array_t **)state; assert_non_null(tle_array.tles); - assert_int_equal(tle_array.number_of_elements, 45); + assert_int_equal(tle_array.number_of_elements, 49); // 9th element, 52745 - AMS tle_t * tle = get_tle_by_index(&tle_array, 9); @@ -113,13 +113,37 @@ void TLE_load_index_from_file(void **state) { tle = get_tle_by_index(&tle_array, 0); assert_non_null(tle->name); assert_string_equal(tle->name, "LEMUR 2 KAREN_B"); + + // 45th element, 60955 - 1998-067WV + tle = get_tle_by_index(&tle_array, 45); + assert_int_equal(tle->orbit.satno, 60955); + assert_non_null(tle->name); + assert_string_equal(tle->name, "1998-067WV"); + + // 46th element, 45727 - 2 PATHFINDER + tle = get_tle_by_index(&tle_array, 46); + assert_int_equal(tle->orbit.satno, 45727); + assert_non_null(tle->name); + assert_string_equal(tle->name, "2 PATHFINDER"); + + // 47th element, 5485 - SHINSEI (MS-F2) + tle = get_tle_by_index(&tle_array, 47); + assert_int_equal(tle->orbit.satno, 5485); + assert_non_null(tle->name); + assert_string_equal(tle->name, "SHINSEI (MS-F2)"); + + // 48th element, 07530 - OSCAR 7 (AO-7) + tle = get_tle_by_index(&tle_array, 48); + assert_int_equal(tle->orbit.satno, 7530); + assert_non_null(tle->name); + assert_string_equal(tle->name, "OSCAR 7 (AO-7)"); } void TLE_load_invalid_catalog_id_from_file(void **state) { tle_array_t tle_array = **(tle_array_t **)state; assert_non_null(tle_array.tles); - assert_int_equal(tle_array.number_of_elements, 45); + assert_int_equal(tle_array.number_of_elements, 49); tle_t * tle = get_tle_by_catalog_id(&tle_array, 12000); assert_null(tle); @@ -129,7 +153,7 @@ void TLE_load_catalog_id_from_file(void **state) { tle_array_t tle_array = **(tle_array_t **)state; assert_non_null(tle_array.tles); - assert_int_equal(tle_array.number_of_elements, 45); + assert_int_equal(tle_array.number_of_elements, 49); // 13th element, 52749, - ICEYE-X18 tle_t * tle = get_tle_by_catalog_id(&tle_array, 52749); @@ -162,6 +186,30 @@ void TLE_load_catalog_id_from_file(void **state) { tle = get_tle_by_catalog_id(&tle_array, 52736); assert_non_null(tle->name); assert_string_equal(tle->name, "LEMUR 2 KAREN_B"); + + // 45th element, 60955 - 1998-067WV + tle = get_tle_by_catalog_id(&tle_array, 60955); + assert_int_equal(tle->orbit.satno, 60955); + assert_non_null(tle->name); + assert_string_equal(tle->name, "1998-067WV"); + + // 46th element, 45727 - 2 PATHFINDER + tle = get_tle_by_catalog_id(&tle_array, 45727); + assert_int_equal(tle->orbit.satno, 45727); + assert_non_null(tle->name); + assert_string_equal(tle->name, "2 PATHFINDER"); + + // 47th element, 5485 - SHINSEI (MS-F2) + tle = get_tle_by_catalog_id(&tle_array, 5485); + assert_int_equal(tle->orbit.satno, 5485); + assert_non_null(tle->name); + assert_string_equal(tle->name, "SHINSEI (MS-F2)"); + + // 48th element, 07530 - OSCAR 7 (AO-7) + tle = get_tle_by_catalog_id(&tle_array, 7530); + assert_int_equal(tle->orbit.satno, 7530); + assert_non_null(tle->name); + assert_string_equal(tle->name, "OSCAR 7 (AO-7)"); } // Entry point to run all tests