/* * 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. */ #include #include #include #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; double times[100]; int ephem = 1; /* default to SGP4 */ int i; /* Index for loops etc */ if( !ifile) { printf( "Couldn't open input TLE file\n"); exit( -1); } for( i = 0; i < n_times; i++) times[i] = (double)(i * 30); fgets( line1, sizeof( line1), ifile); while( fgets( line2, sizeof( line2), ifile)) { if( !memcmp( line2, "Ephem ", 6)) ephem = (line2[6] - '0'); 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)) /* hey! we got a TLE! */ { int is_deep = select_ephemeris( &tle); char *ephem_names[5] = { "SGP ", "SGP4", "SGP8", "SDP4", "SDP8" }; double sat_params[N_SAT_PARAMS]; if( is_deep && (ephem == 1 || ephem == 2)) ephem += 2; /* switch to an SDx */ if( !is_deep && (ephem == 3 || ephem == 4)) ephem -= 2; /* switch to an SGx */ printf( "%s%s", 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 0: SGP_init( sat_params, &tle); break; case 1: SGP4_init( sat_params, &tle); break; case 2: SGP8_init( sat_params, &tle); break; case 3: SDP4_init( sat_params, &tle); break; case 4: SDP8_init( sat_params, &tle); break; } for( i = 0; i < n_times; i++) { switch( ephem) { case 0: SGP(times[i], &tle, sat_params, pos, vel); break; case 1: SGP4(times[i], &tle, sat_params, pos, vel); break; case 2: SGP8(times[i], &tle, sat_params, pos, vel); break; case 3: SDP4(times[i], &tle, sat_params, pos, vel); break; case 4: 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.; printf(" %12.4f %16.8f %16.8f %16.8f \n", 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); } return(0); } /* End of main() */ /*------------------------------------------------------------------*/