2
/* Author: Dr TS Kelso */
3
/* Original Version: 1992 Jun 25 */
4
/* Current Revision: 1999 Nov 27 */
6
/* Copyright: 1992-1999, All Rights Reserved */
8
/* Ported to C by N. Kyriazis April 6 2001 */
12
/* Calculates the checksum mod 10 of a line from a TLE set and */
13
/* returns 1 if it compares with checksum in column 68, else 0.*/
14
/* tle_set is a character string holding the two lines read */
15
/* from a text file containing NASA format Keplerian elements. */
17
Checksum_Good( char *tle_set )
19
int i, check_digit, value, checksum = 0;
21
for(i = 0; i < 68; i++)
23
if( (tle_set[i] >= '0') && (tle_set[i] <= '9') )
24
value = tle_set[i] - '0';
25
else if( tle_set[i] == '-' )
31
} /* End for(i = 0; i < 68; i++) */
34
check_digit = tle_set[68] - '0';
36
return( checksum == check_digit );
37
} /* Function Checksums_Good */
39
/*------------------------------------------------------------------*/
41
/* Carries out various checks on a TLE set to verify its validity */
42
/* tle_set is a character string holding the two lines read */
43
/* from a text file containing NASA format Keplerian elements. */
45
Good_Elements( char *tle_set )
47
/* Verify checksum of both lines of a TLE set */
48
if( !Checksum_Good(&tle_set[0]) || !Checksum_Good(&tle_set[69]) )
50
/* Check the line number of each line */
51
if( (tle_set[0] != '1') || (tle_set[69] != '2') )
53
/* Verify that Satellite Number is same in both lines */
54
if( strncmp( &tle_set[2], &tle_set[71], 5 ) != 0 )
56
/* Check that various elements are in the right place */
58
(tle_set[ 23] != '.') ||
59
(tle_set[ 34] != '.') ||
60
(tle_set[ 80] != '.') ||
61
(tle_set[ 89] != '.') ||
62
(tle_set[106] != '.') ||
63
(tle_set[115] != '.') ||
64
(tle_set[123] != '.') ||
65
(strncmp(&tle_set[61], " 0 ", 3) != 0)
70
} /* Function Good_Elements */
72
/*------------------------------------------------------------------*/
74
/* Converts the strings in a raw two-line element set */
75
/* to their intended numerical values. No processing */
76
/* of these values is done, e.g. from deg to rads etc. */
77
/* This is done in the select_ephemeris() function. */
79
Convert_Satellite_Data( char *tle_set, tle_t *tle )
84
/* Satellite's catalogue number */
85
strncpy( buff, &tle_set[2],5 );
87
tle->catnr = atoi(buff);
89
/* International Designator for satellite */
90
strncpy( tle->idesg, &tle_set[9],8 );
93
/* Satellite's epoch */
94
strncpy( buff, &tle_set[18],14 );
96
tle->epoch = atof(buff);
98
/* Satellite's First Time Derivative */
99
strncpy( buff, &tle_set[33],10 );
101
tle->xndt2o = atof(buff);
103
/* Satellite's Second Time Derivative */
104
strncpy( buff, &tle_set[44],1 );
106
strncpy( &buff[2], &tle_set[45],5 );
108
strncpy( &buff[8], &tle_set[50],2 );
110
tle->xndd6o = atof(buff);
112
/* Satellite's bstar drag term */
113
strncpy( buff, &tle_set[53],1 );
115
strncpy( &buff[2], &tle_set[54],5 );
117
strncpy( &buff[8], &tle_set[59],2 );
119
tle->bstar = atof(buff);
122
strncpy( buff, &tle_set[64],4 );
124
tle->elset = atoi(buff);
126
/** Decode Card 2 **/
127
/* Satellite's Orbital Inclination (degrees) */
128
strncpy( buff, &tle_set[77], 8 );
130
tle->xincl = atof(buff);
132
/* Satellite's RAAN (degrees) */
133
strncpy( buff, &tle_set[86], 8 );
135
tle->xnodeo = atof(buff);
137
/* Satellite's Orbital Eccentricity */
139
strncpy( &buff[1], &tle_set[95], 7 );
141
tle->eo = atof(buff);
143
/* Satellite's Argument of Perigee (degrees) */
144
strncpy( buff, &tle_set[103], 8 );
146
tle->omegao = atof(buff);
148
/* Satellite's Mean Anomaly of Orbit (degrees) */
149
strncpy( buff, &tle_set[112], 8 );
151
tle->xmo = atof(buff);
153
/* Satellite's Mean Motion (rev/day) */
154
strncpy( buff, &tle_set[121], 10 );
156
tle->xno = atof(buff);
158
/* Satellite's Revolution number at epoch */
159
strncpy( buff, &tle_set[132], 5 );
161
tle->revnum = atof(buff);
163
} /* Procedure Convert_Satellite_Data */
165
/*------------------------------------------------------------------*/
168
Get_Next_Tle_Set( char line[3][80], tle_t *tle)
170
int idx, /* Index for loops and arrays */
171
chr; /* Used for inputting characters */
173
char tle_set[139]; /* Two lines of a TLE set */
175
/* Read the satellite's name */
176
for (idx = 0 ; idx < 25; idx++)
178
if( ((chr = line[0][idx]) != CR) && (chr != LF) && (chr != '\0'))
179
tle->sat_name[idx] = chr;
182
/* strip off trailing spaces */
183
while ((chr = line[0][--idx]) == ' ');
184
tle->sat_name[++idx] = '\0';
189
/* Read in first line of TLE set */
190
strncpy(tle_set, line[1], 70);
192
/* Read in second line of TLE set and terminate string */
193
strncpy(&tle_set[69], line[2], 70);
196
/* Check TLE set and abort if not valid */
197
if( !Good_Elements(tle_set) )
200
/* Convert the TLE set to orbital elements */
201
Convert_Satellite_Data( tle_set, tle );
206
/*------------------------------------------------------------------*/
208
/* Selects the apropriate ephemeris type to be used */
209
/* for predictions according to the data in the TLE */
210
/* It also processes values in the tle set so that */
211
/* they are apropriate for the sgp4/sdp4 routines */
213
select_ephemeris(tle_t *tle)
215
double ao,xnodp,dd1,dd2,delo,temp,a1,del1,r1;
217
/* Preprocess tle set */
218
tle->xnodeo *= de2ra;
219
tle-> omegao *= de2ra;
222
temp = twopi/xmnpda/xmnpda;
223
tle->xno = tle->xno*temp*xmnpda;
225
tle->xndd6o = tle->xndd6o*temp/xmnpda;
228
/* Period > 225 minutes is deep space */
229
dd1 = (xke/tle->xno);
232
r1 = cos(tle->xincl);
233
dd1 = (1.0-tle->eo*tle->eo);
234
temp = ck2*1.5f*(r1*r1*3.0-1.0)/pow(dd1, 1.5);
236
ao = a1*(1.0-del1*(tothrd*.5+del1*
237
(del1*1.654320987654321+1.0)));
239
xnodp = tle->xno/(delo+1.0);
241
/* Select a deep-space/near-earth ephemeris */
242
if (twopi/xnodp/xmnpda >= .15625)
243
SetFlag(DEEP_SPACE_EPHEM_FLAG);
245
ClearFlag(DEEP_SPACE_EPHEM_FLAG);
248
} /* End of select_ephemeris() */
250
/*------------------------------------------------------------------*/