/* obs_test.cpp 23 September 2002 An example 'main' function illustrating how to get topocentric ephemerides for artificial satellites, using the basic satellite code plus the add-on topocentric functions. The code reads the file 'obs_test.txt', getting commands setting the observer lat/lon and altitude and time of observation. When it gets a command setting a particular JD, it computes the topocentric RA/dec/dist and prints them out. At present, 'obs_test.txt' sets up a lat/lon/height in Bowdoinham, Maine, corporate headquarters of Project Pluto, and computes the position of one low-orbit satellite (ISS) and one high-orbit satellite (Cosmos 1966 rocket booster). Comparison values are given in 'obs_test.txt', so you can check your implementation. */ #include #include #include #include "norad.h" #include "observe.h" #define PI 3.141592653589793238462643383279 int main( int argc, char **argv) { FILE *ifile = fopen( (argc == 1) ? "obs_test.txt" : argv[1], "rb"); tle_t tle; /* Pointer to two-line elements set for satellite */ char line1[100], line2[100]; double lat = 0., lon = 0., ht_in_meters = 0., jd = 0.; int ephem = 1; /* default to SGP4 */ if( !ifile) { printf( "Couldn't open input OBS_TEST.TXT file\n"); exit( -1); } fgets( line1, sizeof( line1), ifile); while( fgets( line2, sizeof( line2), ifile)) { if( !memcmp( line2, "Ephem ", 6)) ephem = (line2[6] - '0'); else if( !memcmp( line2, "JD ", 3)) jd = atof( line2 + 3); else if( !memcmp( line2, "ht ", 3)) ht_in_meters = atof( line2 + 3); else if( !memcmp( line2, "lat ", 4)) lat = atof( line2 + 4) * PI / 180.; /* cvt degrees to radians */ else if( !memcmp( line2, "lon ", 4)) lon = atof( line2 + 4) * PI / 180.; 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], observer_loc[3]; double rho_sin_phi, rho_cos_phi; double t_since; double pos[3]; /* Satellite position vector */ lat_alt_to_parallax( lat, ht_in_meters, &rho_cos_phi, &rho_sin_phi); observer_cartesian_coords( jd, lon, rho_cos_phi, rho_sin_phi, observer_loc); 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 */ if( is_deep) printf("Deep-Space type Ephemeris (%s) selected:\n", ephem_names[ephem]); else printf("Near-Earth type Ephemeris (%s) selected:\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 */ t_since = (jd - tle.epoch) * 1440.; SGP_init( sat_params, &tle); SGP( t_since, &tle, sat_params, pos, NULL); line1[15] = '\0'; printf( "Object %s, %f x %.5lf y %.5lf z %.5lf\n", line1 + 2, jd-245.0e4, pos[0], pos[1], pos[2]); SGP4_init( sat_params, &tle); SGP4( t_since, &tle, sat_params, pos, NULL); line1[15] = '\0'; printf( "Object %s, x %.5lf y %.5lf z %.5lf\n", line1 + 2, pos[0], pos[1], pos[2]); SGP8_init( sat_params, &tle); SGP8( t_since, &tle, sat_params, pos, NULL); line1[15] = '\0'; printf( "Object %s, x %.5lf y %.5lf z %.5lf\n", line1 + 2, pos[0], pos[1], pos[2]); SDP4_init( sat_params, &tle); SDP4( t_since, &tle, sat_params, pos, NULL); line1[15] = '\0'; printf( "Object %s, x %.5lf y %.5lf z %.5lf\n", line1 + 2, pos[0], pos[1], pos[2]); SDP8_init( sat_params, &tle); SDP8( t_since, &tle, sat_params, pos, NULL); line1[15] = '\0'; printf( "Object %s, x %.5lf y %.5lf z %.5lf\n", line1 + 2, pos[0], pos[1], pos[2]); } strcpy( line1, line2); } return( 0); } /* End of main() */