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 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
|
/*
* test2.cpp 5 July 2002
*
* A skeleton main() function to demonstrate the use of
* the various NORAD ephemerides. It reads in the file
* 'test.tle' and computes ephemerides at assorted times for
* all elements in the file. The times used, and the choice
* of SxP4 vs. SxP8, can be switched with various keywords in
* the 'test.tle' file. The result should match 'test2.txt'.
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "norad.h"
/* Main program */
int main( int argc, char **argv)
{
double vel[3], pos[3]; /* Satellite position and velocity vectors */
FILE *ifile = fopen( (argc == 1) ? "test.tle" : argv[1], "rb");
tle_t tle; /* Pointer to two-line elements set for satellite */
char line1[100], line2[100];
int n_times = 5, dundee_output = 0;
double times[400];
int ephem = TLE_EPHEMERIS_TYPE_SGP4; /* default to SGP4 */
int i; /* Index for loops etc */
for( i = 2; i < argc; i++)
switch( argv[i][0])
{
case 's': case 'S':
sxpx_set_dpsec_integration_step( atof( argv[i] + 1));
break;
case 'd': case 'D':
sxpx_set_implementation_param( SXPX_DUNDEE_COMPLIANCE, 1);
break;
case 'o': case 'O':
{
const int new_order = atoi( argv[i] + 1);
sxpx_set_implementation_param(
SXPX_DPSEC_INTEGRATION_ORDER, new_order);
printf( "Set to order %d\n", new_order);
}
break;
default:
break;
}
if( !ifile)
{
printf( "Couldn't open input TLE file\n");
exit( -1);
}
for( i = 0; i < n_times; i++)
times[i] = (double)(i * 30);
if( fgets( line1, sizeof( line1), ifile))
while( fgets( line2, sizeof( line2), ifile))
{
if( !memcmp( line2, "Ephem ", 6))
ephem = (line2[6] - '0');
else if( !memcmp( line2, "Dundee ", 7))
{
double t0, step;
sscanf( line2 + 7, "%lf %lf %d", &t0, &step, &n_times);
for( i = 0; i < n_times; i++)
times[i] = t0 + (double)i * step;
sxpx_set_implementation_param( SXPX_DUNDEE_COMPLIANCE, 1);
dundee_output = 1;
}
else if( !memcmp( line2, "Times: ", 7))
{
int loc = 7, bytes_read;
n_times = 0;
while( sscanf( line2 + loc, "%lf%n", times + n_times, &bytes_read) == 1)
{
loc += bytes_read;
n_times++;
}
}
else if( parse_elements( line1, line2, &tle) >= 0)
{ /* hey! we got a TLE! */
int is_deep = select_ephemeris( &tle);
const char *ephem_names[6] = { "???", "SGP ", "SGP4", "SDP4", "SGP8", "SDP8" };
double sat_params[N_SAT_PARAMS];
if( is_deep)
if( ephem == TLE_EPHEMERIS_TYPE_SGP4 || ephem == TLE_EPHEMERIS_TYPE_SGP8)
ephem++; /* switch to an SDPx model */
if( !is_deep)
if( ephem == TLE_EPHEMERIS_TYPE_SDP4 || ephem == TLE_EPHEMERIS_TYPE_SDP8)
ephem--; /* switch to an SGPx model */
line1[69] = line2[69] = '\0';
if( dundee_output)
printf( "#%s\n#%s\n", line1, line2);
else
printf( "%s\n%s\n", line1, line2);
if( is_deep)
printf("Deep-Space type Ephemeris (%s) selected:",
ephem_names[ephem]);
else
printf("Near-Earth type Ephemeris (%s) selected:",
ephem_names[ephem]);
/* Print some titles for the results */
printf("\nEphem:%s Tsince "
"X/Xdot Y/Ydot Z/Zdot\n", ephem_names[ephem]);
/* Calling of NORAD routines */
/* Each NORAD routine (SGP, SGP4, SGP8, SDP4, SDP8) */
/* will be called in turn with the appropriate TLE set */
switch( ephem)
{
case TLE_EPHEMERIS_TYPE_SGP:
SGP_init( sat_params, &tle);
break;
case TLE_EPHEMERIS_TYPE_SGP4:
SGP4_init( sat_params, &tle);
break;
case TLE_EPHEMERIS_TYPE_SGP8:
SGP8_init( sat_params, &tle);
break;
case TLE_EPHEMERIS_TYPE_SDP4:
SDP4_init( sat_params, &tle);
break;
case TLE_EPHEMERIS_TYPE_SDP8:
SDP8_init( sat_params, &tle);
break;
}
for( i = 0; i < n_times; i++)
{
switch( ephem)
{
case TLE_EPHEMERIS_TYPE_SGP:
SGP(times[i], &tle, sat_params, pos, vel);
break;
case TLE_EPHEMERIS_TYPE_SGP4:
SGP4(times[i], &tle, sat_params, pos, vel);
break;
case TLE_EPHEMERIS_TYPE_SGP8:
SGP8(times[i], &tle, sat_params, pos, vel);
break;
case TLE_EPHEMERIS_TYPE_SDP4:
SDP4(times[i], &tle, sat_params, pos, vel);
break;
case TLE_EPHEMERIS_TYPE_SDP8:
SDP8(times[i], &tle, sat_params, pos, vel);
break;
}
/* Calculate and print results */
vel[0] /= 60.; /* cvt km/minute to km/second */
vel[1] /= 60.;
vel[2] /= 60.;
if( dundee_output)
{
printf("%12.4f %16.8f %16.8f %16.8f",
times[i],pos[0],pos[1],pos[2]);
printf(" %16.8f %16.8f %16.8f\n",
vel[0],vel[1],vel[2]);
}
else
{
printf("%5d %12.4f %16.8f %16.8f %16.8f\n", tle.norad_number,
times[i],pos[0],pos[1],pos[2]);
printf(" %16.8f %16.8f %16.8f\n",
vel[0],vel[1],vel[2]);
}
} /* End of for( i = 0; i < n_times; i++) */
printf( "\n");
}
strcpy( line1, line2);
}
fclose( ifile);
return(0);
} /* End of main() */
/*------------------------------------------------------------------*/
|