-
Notifications
You must be signed in to change notification settings - Fork 1
/
testcpp.cpp
275 lines (237 loc) · 10.2 KB
/
testcpp.cpp
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
/* ---------------------------------------------------------------------
*
* testcpp.cpp
*
* this program tests the sgp4 propagator. an stk ephemeris file is generated
* along with the test output. the code for this is left justified for easy
* location.
*
* companion code for
* fundamentals of astrodynamics and applications
* 2007
* by david vallado
*
* (w) 719-573-2600, email [email protected]
* *****************************************************************
* current :
* 3 sep 08 david vallado
* add switch for afspc compatibility and improved operation
* changes :
* 14 may 08 david vallado
* fixes for linux suggested by brian micek
* misc fixes noted by the community - manual operation,
* formats, char lengths
* 14 aug 06 david vallado
* update mfe for verification time steps, constants
* 20 jul 05 david vallado
* fixes for paper, corrections from paul crawford
* 7 jul 04 david vallado
* fix record file and get working
* 14 may 01 david vallado
* 2nd edition baseline
* 80 norad
* original baseline
* ---------------------------------------------------------------- */
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <fstream>
#ifdef _WIN32
#include <io.h>
#endif
//#include <conio.h>
#include "sgp4ext.h"
#include "sgp4unit.h"
#include "sgp4io.h"
int main()
{
char str[2];
char infilename[15];
double ro[3];
double vo[3];
char typerun, typeinput, opsmode;
gravconsttype whichconst;
int whichcon;
FILE *infile, *outfile, *outfilee;
// ---------------------------- locals -------------------------------
double p, a, ecc, incl, node, argp, nu, m, arglat, truelon, lonper;
double sec, jd, rad, tsince, startmfe, stopmfe, deltamin;
double tumin, mu, radiusearthkm, xke, j2, j3, j4, j3oj2;
int year; int mon; int day; int hr; int min;
char longstr1[130];
typedef char str3[4];
str3 monstr[13];
char outname[64];
char longstr2[130];
elsetrec satrec;
rad = 180.0 / pi;
// ------------------------ implementation --------------------------
strcpy(monstr[1], "Jan");
strcpy(monstr[2], "Feb");
strcpy(monstr[3], "Mar");
strcpy(monstr[4], "Apr");
strcpy(monstr[5], "May");
strcpy(monstr[6], "Jun");
strcpy(monstr[7], "Jul");
strcpy(monstr[8], "Aug");
strcpy(monstr[9], "Sep");
strcpy(monstr[10], "Oct");
strcpy(monstr[11], "Nov");
strcpy(monstr[12], "Dec");
printf("%s\n",SGP4Version );
//opsmode = 'a' best understanding of how afspc code works
//opsmode = 'i' imporved sgp4 resulting in smoother behavior
printf("input operation mode a, i \n");
// ppl
opsmode = 'i';
//scanf(" %c", &opsmode);
printf("you entered: %c\n", opsmode);
//typerun = 'c' compare 1 year of full satcat data
//typerun = 'v' verification run, requires modified elm file with
// start, stop, and delta times
//typerun = 'm' maunual operation- either mfe, epoch, or dayof yr also
printf("input type of run c, v, m \n");
// ppl
typerun = 'v';
//scanf(" %c", &typerun);
printf("you entered: %c\n", typerun);
//typeinput = 'm' input start stop mfe
//typeinput = 'e' input start stop ymd hms
//typeinput = 'd' input start stop yr dayofyr
if ((typerun != 'v') && (typerun != 'c'))
{
printf("input mfe, epoch (YMDHMS), or dayofyr approach, m,e,d \n\n");
scanf(" %c", &typeinput);
printf("you entered: %c\n", typeinput);
}
else
typeinput = 'e';
printf("input which constants 721 72 84 \n");
// ppl
whichcon = 84;
//scanf( "%i",&whichcon );
if (whichcon == 721) whichconst = wgs72old;
if (whichcon == 72) whichconst = wgs72;
if (whichcon == 84) whichconst = wgs84;
getgravconst( whichconst, tumin, mu, radiusearthkm, xke, j2, j3, j4, j3oj2 );
// ---------------- setup files for operation ------------------
// input 2-line element set file
printf("input elset filename: \n");
strcpy(infilename, "sgp4-ver.tle");
// scanf( "%s",infilename );
infile = fopen(infilename, "r");
if (infile == NULL)
{
printf("Failed to open file: %s\n", infilename);
return 1;
}
if (typerun == 'c')
outfile = fopen("tcppall.out", "w");
else
{
if (typerun == 'v')
outfile = fopen("test_cpp_version.out", "w");
else
outfile = fopen("test_cpp_version_o.out", "w");
}
// dbgfile = fopen("sgp4test.dbg", "w");
// fprintf(dbgfile,"this is the debug output\n\n" );
// ----------------- test simple propagation -------------------
while (feof(infile) == 0)
{
do
{
fgets( longstr1,130,infile);
strncpy(str, &longstr1[0], 1);
str[1] = '\0';
} while ((strcmp(str, "#")==0)&&(feof(infile) == 0));
if (feof(infile) == 0)
{
fgets( longstr2,130,infile);
// convert the char string to sgp4 elements
// includes initialization of sgp4
twoline2rv( longstr1, longstr2, typerun, typeinput, opsmode, whichconst,
startmfe, stopmfe, deltamin, satrec );
fprintf(outfile, "%ld xx\n", satrec.satnum);
printf("// %ld\n", satrec.satnum);
// call the propagator to get the initial state vector value
sgp4 (whichconst, satrec, 0.0, ro, vo);
// generate .e files for stk
jd = satrec.jdsatepoch;
strncpy(outname,&longstr1[2],5);
outname[5]= '.';
outname[6]= 'e';
outname[7]= '\0';
invjday( jd, year,mon,day,hr,min, sec );
/*
outfilee = fopen(outname, "w");
fprintf(outfilee,"stk.v.4.3 \n"); // must use 4.3...
fprintf(outfilee,"\n");
fprintf(outfilee,"BEGIN Ephemeris \n");
fprintf(outfilee," \n");
fprintf(outfilee,"NumberOfEphemerisPoints 146 \n");
fprintf(outfilee,"ScenarioEpoch %3i %3s%5i%3i:%2i:%12.9f \n",day,monstr[mon],
year,hr,min,sec );
fprintf(outfilee,"InterpolationMethod Lagrange \n");
fprintf(outfilee,"InterpolationOrder 5 \n");
fprintf(outfilee,"CentralBody Earth \n");
fprintf(outfilee,"CoordinateSystem TEME \n");
fprintf(outfilee,"CoordinateSystemEpoch %3i %3s%5i%3i:%2i:%12.9f \n",day,
monstr[mon],year,hr,min,sec );
fprintf(outfilee,"DistanceUnit Kilometers \n");
fprintf(outfilee," \n");
fprintf(outfilee,"EphemerisTimePosVel \n");
fprintf(outfilee," \n");
fprintf(outfilee, " %16.8f %16.8f %16.8f %16.8f %12.9f %12.9f %12.9f\n",
satrec.t,ro[0],ro[1],ro[2],vo[0],vo[1],vo[2]);
*/
fprintf(outfile, " %16.8f %16.8f %16.8f %16.8f %12.9f %12.9f %12.9f\n",
satrec.t,ro[0],ro[1],ro[2],vo[0],vo[1],vo[2]);
tsince = startmfe;
// check so the first value isn't written twice
if ( fabs(tsince) > 1.0e-8 )
tsince = tsince - deltamin;
// ----------------- loop to perform the propagation ----------------
while ((tsince < stopmfe) && (satrec.error == 0))
{
tsince = tsince + deltamin;
if(tsince > stopmfe)
tsince = stopmfe;
sgp4 (whichconst, satrec, tsince, ro, vo);
if (satrec.error > 0)
printf("# *** error: t:= %f *** code = %3d\n",
satrec.t, satrec.error);
if (satrec.error == 0)
{
if ((typerun != 'v') && (typerun != 'c'))
{
jd = satrec.jdsatepoch + tsince/1440.0;
invjday( jd, year,mon,day,hr,min, sec );
fprintf(outfile,
" %16.8f %16.8f %16.8f %16.8f %12.9f %12.9f %12.9f %5i%3i%3i %2i:%2i:%9.6f\n",
tsince, ro[0],ro[1],ro[2],vo[0],vo[1],vo[2],year,mon,day,hr,min,sec );
// fprintf(outfile, " %16.8f %16.8f %16.8f %16.8f %12.9f %12.9f %12.9f\n",
// tsince,ro[0],ro[1],ro[2],vo[0],vo[1],vo[2]);
}
else
{
jd = satrec.jdsatepoch + tsince/1440.0;
invjday( jd, year,mon,day,hr,min, sec );
// fprintf(outfilee, " %16.6f %16.8f %16.8f %16.8f %12.9f %12.9f %12.9f \n",
// tsince*60.0,ro[0],ro[1],ro[2],vo[0],vo[1],vo[2]);
fprintf(outfile, " %16.8f %16.8f %16.8f %16.8f %12.9f %12.9f %12.9f",
tsince,ro[0],ro[1],ro[2],vo[0],vo[1],vo[2]);
rv2coe(ro, vo, mu, p, a, ecc, incl, node, argp, nu, m, arglat, truelon, lonper );
fprintf(outfile, " %14.6f %8.6f %10.5f %10.5f %10.5f %10.5f %10.5f %5i%3i%3i %2i:%2i:%9.6f\n",
a, ecc, incl*rad, node*rad, argp*rad, nu*rad,
m*rad,year,mon,day,hr,min,sec);
}
} // if satrec.error == 0
} // while propagating the orbit
//fprintf(outfilee," END Ephemeris \n");
//fclose (outfilee);
} // if not eof
} // while through the input file
return 0;
} // end testcpp