Skip to content

Commit

Permalink
Adjust satutl to deal with alpha5 format
Browse files Browse the repository at this point in the history
Signed-off-by: Cees Bassa <[email protected]>
  • Loading branch information
cbassa committed Dec 22, 2024
1 parent ad9c9ca commit f131bf6
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 14 deletions.
2 changes: 1 addition & 1 deletion alpha5.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ void zero_pad(const char *s, char *result)
}
}

int main() {
int oldmain() {
const char *norad_strings[] = {"00001", " 1", " 1234", "05697", "12345", "A0000", "J2931", "W1928", "E8493", "P4018", "Z9999"};
const int correct_numbers[] = {1, 1, 1234, 5697, 12345, 100000, 182931, 301928, 148493, 234018, 339999};

Expand Down
2 changes: 2 additions & 0 deletions alpha5.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
int alpha5_to_number(const char *s);
void number_to_alpha5(int number, char *result);
9 changes: 9 additions & 0 deletions alpha5_test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
0 ENVISAT
1 27386U 02009A 24356.40818734 .00000308 00000-0 11384-3 0 9993
2 27386 98.3105 311.2628 0001150 82.9407 85.1046 14.38791406195499
0 ISS (ZARYA)
1 B5544U 98067A 24356.58519896 .00014389 00000-0 25222-3 0 9992
2 B5544 51.6403 106.8969 0007877 6.1421 113.2479 15.50801739487615
0 VANGUARD 1
1 00005U 58002B 24355.85605070 .00000390 00000-0 46945-3 0 9993
2 00005 34.2473 191.3006 1842495 208.7893 139.7481 10.85819141384219
23 changes: 13 additions & 10 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ exec_prefix = $(prefix)
bindir = $(exec_prefix)/bin

all:
make rfedit rfplot rffft rfpng rffit rffind rfdop
make rfedit rfplot rffft rfpng rffit rffind rfdop test_alpha5

rffit: rffit.o sgdp4.o satutl.o deep.o ferror.o dsmin.o simplex.o versafit.o rfsites.o rftles.o
gfortran -o rffit rffit.o sgdp4.o satutl.o deep.o ferror.o dsmin.o simplex.o versafit.o rfsites.o rftles.o $(LFLAGS)
rffit: rffit.o sgdp4.o satutl.o deep.o ferror.o dsmin.o simplex.o versafit.o rfsites.o rftles.o alpha5.o
gfortran -o rffit rffit.o sgdp4.o satutl.o deep.o ferror.o dsmin.o simplex.o versafit.o rfsites.o rftles.o alpha5.o $(LFLAGS)

rfpng: rfpng.o rftime.o rfio.o rftrace.o sgdp4.o satutl.o deep.o ferror.o rftles.o zscale.o
gfortran -o rfpng rfpng.o rftime.o rfio.o rftrace.o sgdp4.o satutl.o deep.o ferror.o rftles.o zscale.o $(LFLAGS)
rfpng: rfpng.o rftime.o rfio.o rftrace.o sgdp4.o satutl.o deep.o ferror.o rftles.o zscale.o alpha5.o
gfortran -o rfpng rfpng.o rftime.o rfio.o rftrace.o sgdp4.o satutl.o deep.o ferror.o rftles.o zscale.o alpha5.o $(LFLAGS)

rfdop: rfdop.o rftrace.o rfio.o rftime.o sgdp4.o satutl.o deep.o ferror.o rftles.o zscale.o
$(CC) -o rfdop rfdop.o rftrace.o rfio.o rftime.o sgdp4.o satutl.o deep.o ferror.o rftles.o zscale.o -lm
rfdop: rfdop.o rftrace.o rfio.o rftime.o sgdp4.o satutl.o deep.o ferror.o rftles.o zscale.o alpha5.o
$(CC) -o rfdop rfdop.o rftrace.o rfio.o rftime.o sgdp4.o satutl.o deep.o ferror.o rftles.o zscale.o alpha5.o -lm

rfedit: rfedit.o rfio.o rftime.o zscale.o
$(CC) -o rfedit rfedit.o rfio.o rftime.o zscale.o -lm
Expand All @@ -34,13 +34,16 @@ rffind: rffind.o rfio.o rftime.o zscale.o
rftrack: rftrack.o rfio.o rftime.o rftrace.o sgdp4.o satutl.o deep.o ferror.o zscale.o
$(CC) -o rftrack rftrack.o rfio.o rftime.o rftrace.o sgdp4.o satutl.o deep.o ferror.o zscale.o -lm

rfplot: rfplot.o rftime.o rfio.o rftrace.o sgdp4.o satutl.o deep.o ferror.o versafit.o dsmin.o simplex.o rftles.o zscale.o
gfortran -o rfplot rfplot.o rftime.o rfio.o rftrace.o sgdp4.o satutl.o deep.o ferror.o versafit.o dsmin.o simplex.o rftles.o zscale.o $(LFLAGS)
rfplot: rfplot.o rftime.o rfio.o rftrace.o sgdp4.o satutl.o deep.o ferror.o versafit.o dsmin.o simplex.o rftles.o zscale.o alpha5.o
gfortran -o rfplot rfplot.o rftime.o rfio.o rftrace.o sgdp4.o satutl.o deep.o ferror.o versafit.o dsmin.o simplex.o rftles.o zscale.o alpha5.o $(LFLAGS)

rffft: rffft.o rffft_internal.o rftime.o
$(CC) -o rffft rffft.o rffft_internal.o rftime.o -lfftw3f -lm -lsox

tests/tests: tests/tests.o tests/tests_rffft_internal.o tests/tests_rftles.o rffft_internal.o rftles.o satutl.o ferror.o
test_alpha5: test_alpha5.o rftles.o satutl.o ferror.o alpha5.o
$(CC) -o test_alpha5 test_alpha5.o rftles.o satutl.o ferror.o alpha5.o -lm

tests/tests: tests/tests.o tests/tests_rffft_internal.o tests/tests_rftles.o rffft_internal.o rftles.o satutl.o ferror.o alpha5.o
$(CC) -Wall -o $@ $^ -lcmocka -lm

tests: tests/tests
Expand Down
13 changes: 10 additions & 3 deletions satutl.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


#include "sgdp4h.h"

#include "alpha5.h"
#include <ctype.h>

static char *st_start(char *buf);
Expand Down Expand Up @@ -78,13 +78,17 @@ int read_twoline(FILE *fp, long search_satno, orbit_t *orb, char *satname)
static char search[ST_SIZE];
static char line1[ST_SIZE];
static char line2[ST_SIZE];
char search_satstr[6];
char *st1, *st2;
int found = 0;
double bm, bx;

st1 = line1;
st2 = line2;

// alpha5 designation to search
number_to_alpha5(search_satno, search_satstr);

do {
if(fgets(line1, ST_SIZE-1, fp) == NULL) return -1;
st1 = st_start(line1);
Expand All @@ -93,11 +97,14 @@ int read_twoline(FILE *fp, long search_satno, orbit_t *orb, char *satname)
} while((st1[0] != '1') || (st1[1] != ' '));

if (search_satno != 0) {
sprintf(search, "1 %05ld", search_satno);
sprintf(search, "1 %5s", search_satstr);
} 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);
//search_satno = atol(st1+2);
strncpy(search_satstr, st1+2, 5);
search_satstr[5]='\0';
search_satno=alpha5_to_number(search_satstr);
strncpy(search, line1, 7);
search[7] = '\0';
}
Expand Down
58 changes: 58 additions & 0 deletions test_alpha5.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>

#include "rftles.h"

#define LIM 80

// Read a line of maximum length int lim from file FILE into string s
int fgetline(FILE *file,char *s,int lim)
{
int c,i=0;

while (--lim > 0 && (c=fgetc(file)) != EOF && c != '\n')
s[i++] = c;
// if (c == '\n')
// s[i++] = c;
s[i] = '\0';
return i;
}

int main(int argc,char *argv[])
{
tle_t *tle;
char tlefile[]="alpha5_test.txt";

// Load TLEs
tle_array_t *tle_array = load_tles(tlefile);

if (tle_array->number_of_elements == 0) {
fprintf(stderr,"TLE file %s not found or empty\n", tlefile);
return 0;
}

// Loop over all TLEs
for (long elem = 0; elem < tle_array->number_of_elements; elem++) {
// Get TLE
tle = get_tle_by_index(tle_array, elem);

print_orb(&tle->orbit);
printf("\n");
}

// Find specific TLE
tle = get_tle_by_catalog_id(tle_array, 5);
print_orb(&tle->orbit);
printf("\n");

// Find specific TLE
tle = get_tle_by_catalog_id(tle_array, 115544);
print_orb(&tle->orbit);
printf("\n");


return 0;
}

0 comments on commit f131bf6

Please sign in to comment.