-
Notifications
You must be signed in to change notification settings - Fork 1
/
testmat.m
133 lines (101 loc) · 4.76 KB
/
testmat.m
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
% script testmat.m
%
% This script tests the SGP4 propagator.
% Author:
% Jeff Beck
% Version Info:
% 1.0 (051019) - Initial version from Vallado C++ version.
% 1.0 (aug 14, 2006) - update for paper
% these are set in sgp4init
global tumin radiusearthkm xke j2 j3 j4 j3oj2
% // ------------------------ implementation --------------------------
% //typerun = 'c' compare 1 year of full satcat data
% //typerun = 'v' verification run, requires modified elm file with
% // start stop and delta times
typerun = input('input type of run c, v: ','s');
whichconst = input('input constants 721, 72, 84 ');
rad = 180.0 / pi;
% // ---------------- setup files for operation ------------------
% // input 2-line element set file
infilename = input('input elset filename: ','s');
infile = fopen(infilename, 'r');
if (infile == -1)
fprintf(1,'Failed to open file: %s\n', infilename);
return;
end
if (typerun == 'c')
outfile = fopen('tmatall.out', 'wt');
else
if (typerun == 'v')
outfile = fopen('tmatver.out', 'wt');
else
outfile = fopen('tmat.out', 'wt');
end
end
global idebug dbgfile
% // ----------------- test simple propagation -------------------
while (~feof(infile))
longstr1 = fgets(infile, 130);
while ( (longstr1(1) == '#') && (feof(infile) == 0) )
longstr1 = fgets(infile, 130);
end
if (feof(infile) == 0)
longstr2 = fgets(infile, 130);
if idebug
catno = strtrim(longstr1(3:7));
dbgfile = fopen(strcat('sgp4test.dbg.',catno), 'wt');
fprintf(dbgfile,'this is the debug output\n\n' );
end
% // convert the char string to sgp4 elements
% // includes initialization of sgp4
[satrec, startmfe, stopmfe, deltamin] = twoline2rv( whichconst, ...
longstr1, longstr2, typerun);
fprintf(outfile, '%d xx\n', satrec.satnum);
fprintf(1,' %d\n', satrec.satnum);
% // call the propagator to get the initial state vector value
[satrec, ro ,vo] = sgp4 (satrec, 0.0);
fprintf(outfile, ' %16.8f %16.8f %16.8f %16.8f %12.9f %12.9f %12.9f\n',...
satrec.t,ro(1),ro(2),ro(3),vo(1),vo(2),vo(3));
% fprintf(1, ' %16.8f %16.8f %16.8f %16.8f %12.9f %12.9f %12.9f\n',...
% satrec.t,ro(1),ro(2),ro(3),vo(1),vo(2),vo(3));
tsince = startmfe;
% // check so the first value isn't written twice
if ( abs(tsince) > 1.0e-8 )
tsince = tsince - deltamin;
end
% // loop to perform the propagation
while ((tsince < stopmfe) && (satrec.error == 0))
tsince = tsince + deltamin;
if(tsince > stopmfe)
tsince = stopmfe;
end
[satrec, ro, vo] = sgp4 (satrec, tsince);
if (satrec.error > 0)
fprintf(1,'# *** error: t:= %f *** code = %3i\n', tsince, satrec.error);
end
if (satrec.error == 0)
if ((typerun ~= 'v') && (typerun ~= 'c'))
jd = satrec.jdsatepoch + tsince;
[year,mon,day,hr,minute,sec] = invjday ( jd );
fprintf(outfile,...
'%5i%3i%3i %2i:%2i:%9.6f %16.8f%16.8f%16.8%12.9f%12.9f%12.9f\n',...
year,mon,day,hr,minute,sec );
else
fprintf(outfile, ' %16.8f %16.8f %16.8f %16.8f %12.9f %12.9f %12.9f',...
tsince,ro(1),ro(2),ro(3),vo(1),vo(2),vo(3));
% fprintf(1, ' %16.8f %16.8f %16.8f %16.8f %12.9f %12.9f %12.9f \n',...
% tsince,ro(1),ro(2),ro(3),vo(1),vo(2),vo(3));
[p,a,ecc,incl,node,argp,nu,m,arglat,truelon,lonper ] = rv2coe (ro,vo);
fprintf(outfile, ' %14.6f %8.6f %10.5f %10.5f %10.5f %10.5f %10.5f \n',...
a, ecc, incl*rad, node*rad, argp*rad, nu*rad, m*rad);
end
end %// if satrec.error == 0
end %// while propagating the orbit
if (idebug && (dbgfile ~= -1))
fclose(dbgfile);
end
end %// if not eof
end %// while through the input file
fclose(infile);
fclose(outfile);