-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathfake_ast.cpp
112 lines (102 loc) · 3.65 KB
/
fake_ast.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/* Copyright (C) 2018, Project Pluto. See LICENSE.
This program will generate simulated geocentric observations
for a given object from a TLE. In theory, one can then fit these
pseudo-observations to a higher-quality physical model to get a
considerably more accurate ephemeris for the object. */
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "norad.h"
#include "observe.h"
#define PI 3.1415926535897932384626433832795028841971693993751058209749445923
int main( const int argc, const char **argv)
{
FILE *ifile = fopen( argv[1], "rb");
char line1[100], line2[100];
const char *intl_id = NULL;
double step_size = .1;
int i, n_steps = 100;
bool show_vectors = false;
if( !ifile)
{
printf( "Couldn't open input file\n");
exit( -1);
}
for( i = 1; i < argc; i++)
if( argv[i][0] == '-')
switch( argv[i][1])
{
case 'i':
intl_id = argv[i] + 2;
break;
case 'n':
n_steps = atoi( argv[i] + 2);
break;
case 's':
step_size = atof( argv[i] + 2);
break;
case 'v':
show_vectors = true;
break;
default:
printf( "Unrecognized option '%s'\n", argv[i]);
break;
}
*line1 = '\0';
sxpx_set_implementation_param( SXPX_DUNDEE_COMPLIANCE, 1);
while( fgets( line2, sizeof( line2), ifile))
{
tle_t tle; /* Pointer to two-line elements set for satellite */
int err_val;
if( (!intl_id || !memcmp( intl_id, line1 + 9, 6))
&& (err_val = parse_elements( line1, line2, &tle)) >= 0)
{ /* hey! we got a TLE! */
int is_deep = select_ephemeris( &tle);
double sat_params[N_SAT_PARAMS], observer_loc[3];
double prev_pos[3];
if( err_val)
printf( "WARNING: TLE parsing error %d\n", err_val);
for( i = 0; i < 3; i++)
observer_loc[i] = 0.;
if( is_deep)
SDP4_init( sat_params, &tle);
else
SGP4_init( sat_params, &tle);
for( i = 0; i < n_steps; i++)
{
double pos[3]; /* Satellite position vector */
double t_since = (double)( i - n_steps / 2) * step_size;
double jd = tle.epoch + t_since;
t_since *= 1440.;
if( is_deep)
err_val = SDP4( t_since, &tle, sat_params, pos, NULL);
else
err_val = SGP4( t_since, &tle, sat_params, pos, NULL);
if( err_val)
printf( "Ephemeris error %d\n", err_val);
if( show_vectors)
{
if( i)
printf( "%14.6f %14.6f %14.6f - ", pos[0] - prev_pos[0],
pos[1] - prev_pos[1],
pos[2] - prev_pos[2]);
printf( "%14.6f %14.6f %14.6f\n", pos[0], pos[1], pos[2]);
memcpy( prev_pos, pos, 3 * sizeof( double));
}
else
{
double ra, dec, dist_to_satellite;
get_satellite_ra_dec_delta( observer_loc, pos,
&ra, &dec, &dist_to_satellite);
epoch_of_date_to_j2000( jd, &ra, &dec);
printf( "%-14sC%13.5f %08.4f %+08.4f",
intl_id, jd, ra * 180. / PI, dec * 180. / PI);
printf( " TLEs 500\n");
}
}
}
strcpy( line1, line2);
}
fclose( ifile);
return( 0);
} /* End of main() */