4
* A skeleton main() function to demonstrate the use of
5
* the SGP4() and SDP4() in the sgp4sdp4.c file.
6
* The TLE set to be used is read from the file amateur.txt
7
* downloaded from Dr Kelso's website at www.celestrak.com.
8
* Please note that this is a simple application and can only
9
* read the first TLE kep set, including line 0 with the Name.
19
char tle_file[] = "./amateur.txt";
21
/* Observer's geodetic co-ordinates. */
22
/* Lat North, Lon East in rads, Alt in km */
23
geodetic_t obs_geodetic = {0.6056, 0.5761, 0.15, 0.0};
25
/* Two-line Orbital Elements for the satellite */
28
/* Zero vector for initializations */
29
vector_t zero_vector = {0,0,0,0};
31
/* Satellite position and velocity vectors */
32
vector_t vel = zero_vector;
33
vector_t pos = zero_vector;
34
/* Satellite Az, El, Range, Range rate */
37
/* Solar ECI position vector */
38
vector_t solar_vector = zero_vector;
39
/* Solar observed azi and ele vector */
42
/* Calendar date and time (UTC) */
45
/* Satellite's predicted geodetic position */
46
geodetic_t sat_geodetic;
49
tsince, /* Time since epoch (in minutes) */
50
jul_epoch, /* Julian date of epoch */
51
jul_utc, /* Julian UTC date */
52
eclipse_depth = 0, /* Depth of satellite eclipse */
53
/* Satellite's observed position, range, range rate */
54
sat_azi, sat_ele, sat_range, sat_range_rate,
55
/* Satellites geodetic position and velocity */
56
sat_lat, sat_lon, sat_alt, sat_vel,
57
/* Solar azimuth and elevation */
60
/* Used for storing function return codes */
64
ephem[5], /* Ephemeris in use string */
65
sat_status[12], /* Satellite eclipse status */
66
tle_lines[3][80]; /* Satellite name + two line element */
68
/* File pointer for opening TLE source file */
71
/* Open TLE file, abort on failure */
72
if( (fp = fopen( tle_file, "r")) == NULL )
74
printf(" File open failed - Exiting!\n");
78
/* Get the first three lines */
79
fgets(tle_lines[0], 80, fp);
80
fgets(tle_lines[1], 80, fp);
81
fgets(tle_lines[2], 80, fp);
85
flg = Get_Next_Tle_Set(tle_lines, &tle);
87
/* Print satellite name and TLE read status */
88
printf(" %s: ", tle.sat_name);
91
printf("TLE set bad - Exiting!\n");
95
printf("TLE set good - Happy Tracking!\n");
97
/* Printout of tle set data for tests if needed */
98
/* printf("\n %s %s %i %i %i\n"
99
" %14f %10f %8f %8f\n"
100
" %8f %8f %9f %8f %8f %12f\n",
101
tle.sat_name, tle.idesg, tle.catnr, tle.elset, tle.revnum,
102
tle.epoch, tle.xndt2o, tle.xndd6o, tle.bstar,
103
tle.xincl, tle.xnodeo, tle.eo, tle.omegao, tle.xmo, tle.xno);
106
/** !Clear all flags! **/
107
/* Before calling a different ephemeris */
108
/* or changing the TLE set, flow control */
109
/* flags must be cleared in main(). */
110
ClearFlag(ALL_FLAGS);
112
/** Select ephemeris type **/
113
/* Will set or clear the DEEP_SPACE_EPHEM_FLAG */
114
/* depending on the TLE parameters of the satellite. */
115
/* It will also pre-process tle members for the */
116
/* ephemeris functions SGP4 or SDP4 so this function */
117
/* must be called each time a new tle set is used */
118
select_ephemeris(&tle);
122
/* Get UTC calendar and convert to Julian */
123
UTC_Calendar_Now(&utc);
124
jul_utc = Julian_Date(&utc);
126
/* Convert satellite's epoch time to Julian */
127
/* and calculate time since epoch in minutes */
128
jul_epoch = Julian_Date_of_Epoch(tle.epoch);
129
tsince = (jul_utc - jul_epoch) * xmnpda;
131
/* Copy the ephemeris type in use to ephem string */
132
if( isFlagSet(DEEP_SPACE_EPHEM_FLAG) )
133
strcpy(ephem,"SDP4");
135
strcpy(ephem,"SGP4");
137
/* Call NORAD routines according to deep-space flag */
138
if( isFlagSet(DEEP_SPACE_EPHEM_FLAG) )
139
SDP4(tsince, &tle, &pos, &vel);
141
SGP4(tsince, &tle, &pos, &vel);
143
/* Scale position and velocity vectors to km and km/sec */
144
Convert_Sat_State( &pos, &vel );
146
/* Calculate velocity of satellite */
150
/** All angles in rads. Distance in km. Velocity in km/s **/
151
/* Calculate satellite Azi, Ele, Range and Range-rate */
152
Calculate_Obs(jul_utc, &pos, &vel, &obs_geodetic, &obs_set);
154
/* Calculate satellite Lat North, Lon East and Alt. */
155
Calculate_LatLonAlt(jul_utc, &pos, &sat_geodetic);
157
/* Calculate solar position and satellite eclipse depth */
158
/* Also set or clear the satellite eclipsed flag accordingly */
159
Calculate_Solar_Position(jul_utc, &solar_vector);
160
Calculate_Obs(jul_utc,&solar_vector,&zero_vector,&obs_geodetic,&solar_set);
162
if( Sat_Eclipsed(&pos, &solar_vector, &eclipse_depth) )
163
SetFlag( SAT_ECLIPSED_FLAG );
165
ClearFlag( SAT_ECLIPSED_FLAG );
167
/* Copy a satellite eclipse status string in sat_status */
168
if( isFlagSet( SAT_ECLIPSED_FLAG ) )
169
strcpy( sat_status, "Eclipsed" );
171
strcpy( sat_status, "In Sunlight" );
173
/* Convert and print satellite and solar data */
174
sat_azi = Degrees(obs_set.x);
175
sat_ele = Degrees(obs_set.y);
176
sat_range = obs_set.z;
177
sat_range_rate = obs_set.w;
178
sat_lat = Degrees(sat_geodetic.lat);
179
sat_lon = Degrees(sat_geodetic.lon);
180
sat_alt = sat_geodetic.alt;
182
sun_azi = Degrees(solar_set.x);
183
sun_ele = Degrees(solar_set.y);
185
printf("\n Date: %02d/%02d/%04d UTC: %02d:%02d:%02d Ephemeris: %s"
186
"\n Azi=%6.1f Ele=%6.1f Range=%8.1f Range Rate=%6.2f"
187
"\n Lat=%6.1f Lon=%6.1f Alt=%8.1f Vel=%8.3f"
188
"\n Stellite Status: %s - Depth: %2.3f"
189
"\n Sun Azi=%6.1f Sun Ele=%6.1f\n",
190
utc.tm_mday, utc.tm_mon, utc.tm_year,
191
utc.tm_hour, utc.tm_min, utc.tm_sec, ephem,
192
sat_azi, sat_ele, sat_range, sat_range_rate,
193
sat_lat, sat_lon, sat_alt, sat_vel,
194
sat_status, eclipse_depth,
199
while( flg == flg ); /* This stops Compaq ccc 'unreachcode' warning! */
202
} /* End of main() */
204
/*------------------------------------------------------------------*/