aboutsummaryrefslogtreecommitdiff
path: root/src/cal/get_tle/make_orbit.pl.in
blob: c00992c75cccf01021947e38fdafeb4bcae6a22a (plain) (blame)
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
#!/usr/bin/env perl
use FileHandle;

# Ed Murphy's program to rewrite the orbit page
# Updated 03/27/00  Changed GSOC to Heavens Above

$output_filename = "/data2/violet/htdocs/users/orbit.html";
open (OUTF, ">$output_filename") || die "Cannot open $output_filename file";

system("chmod ug+rw $output_filename");
system("chgrp www $output_filename");

$input_filename = "@DATADIR@/calfiles/FUSE.TLE";
open (INP_TLE, "<$input_filename") || die "Cannot open $input_filename file";

$satid = 25791;

&input_lines;

close (INP_TLE);

&parse_lines;

&convert_doy;
&convert_dayfrac;
&calculate_a0;
&calculate_orbs;

$now=`date`;
$datest = substr($now,4,3)." ".substr($now,8,2).", ".substr($now,24,4);

print OUTF "<HTML>\n";
print OUTF "<HEAD>\n";
print OUTF "<title>FUSE Orbital Elements page</title>\n";
print OUTF "</HEAD>\n";
print OUTF "<BODY bgcolor=#ffffff ALINK=\"#000000\" VLINK=\"darkblue\">\n";
print OUTF "<center>\n";
print OUTF "<table width=640>\n";
print OUTF "<tr><td>\n";
print OUTF "<img src=\"/figures/purple_line2.gif\" width=640>\n";
print OUTF "<table cellpadding=5 cellspacing=5 width=550>\n";
print OUTF "<tr>\n";
print OUTF "<td valign=top align=left>\n";
print OUTF "<img src=\"/figures/andromeda_moo_small.gif\">\n";
print OUTF "</td>\n";
print OUTF "<td valign=top align=left>\n";
print OUTF "<font size=+3><font color=\"#6666CC\">\n";
print OUTF "<b>FUSE<P>\n";
print OUTF "<i>Orbital Elements</font></font></i></b>\n";
print OUTF "</td>\n";
print OUTF "</tr>\n";
print OUTF "</table>\n";
print OUTF "<img src=\"/figures/purple_line2.gif\" width=640>\n";
print OUTF "<p>\n";
print OUTF "<center>\n";
print OUTF "<font color=\"#CC0099\" size=4><b>\n";
print OUTF "Where is FUSE now?<br></b></font>\n";
print OUTF "<font size=4>Check out the\n";
print OUTF "<a href=\"http://www.heavens-above.com/orbitdisplay.asp?lat=39.3&lng=-76.6&loc=BALTIMORE&TZ=EST&satid=25791\" >\n";
print OUTF "Heavens-Above Satellite Predictions page </a></font>.\n";
print OUTF "</center>\n";
print OUTF "<P>\n";
print OUTF "<hr>\n";
print OUTF "<p><pre>\n";
print OUTF " \n";
print OUTF  "FUSE orbital elements:\n";
print OUTF  "     NORAD number       25791\n";
print OUTF  "     International ID  99035A\n";
print OUTF  " \n";

&print_orb;

print OUTF "</pre>\n";

&print_tail;

close (OUTF);

### end of Perl script


sub convert_doy {
    @daytab1 = (0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
    @daytab2 = (0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
    @monthstr = ("", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");

    if ((($year%4 == 0) && ($year%100 != 0)) || ($year%400 == 0)) {
        # $year is a leap year use daytab1
        for ($i = 1; $doy > $daytab1[$i]; $i++) {
	    $doy -= $daytab1[$i];
	}
    } else {
        # $year is not a leap year, use daytab2
        for ($i = 1; $doy > $daytab2[$i]; $i++) {
	    $doy -= $daytab2[$i];
	}
    }
    $month = $monthstr[$i];
    $day = $doy;
}

sub convert_dayfrac {
    $dayfrac *= 24.0;
    $hour = int($dayfrac);
    $minute = int(($dayfrac-$hour)*60.0);
    $second = ((($dayfrac-$hour)*60.0)-$minute)*60.0;
}

sub input_lines {
$line1 = <INP_TLE>;
$line2 = <INP_TLE>;
$line3 = <INP_TLE>;

$id2 = substr($line2, 2, 5);
$id3 = substr($line3, 2, 5);

if (($id2 != $satid) || ($id3 != $satid)) {
    print STDOUT "Error in TLE:\n";
    print STDOUT $line1;
    print STDOUT $line2;
    print STDOUT $line3;
#    die "Error in TLE";
}

}

sub parse_lines {
$year = substr($line2, 18, 2);
$doy = substr($line2, 20, 3);
$dayfrac = substr($line2, 23, 9);
$epoch = $year.$doy.$dayfrac;
$incl = substr($line3, 9, 8);
$raan = substr($line3, 17,8);
$eccen = substr($line3, 26, 7);
$eccen = "0." . $eccen;
$mean_mot = substr($line3, 52, 11);
$mean_anom = substr($line3, 43, 8);
$arg_perig = substr($line3, 34, 8);


if ($year > 50) {
    $year += 1900;
} else {
    $year += 2000;
}

$dayfrac = "0".$dayfrac;

}

sub calculate_a0 {

$mu = 3.986005E5;
$pi = 3.14159265358979;
$radian = 0.0174532925200;

$mm=2.0*$pi*$mean_mot/(24.0*60.0);
$ke=0.74366916E-1;
$k2=5.413080E-4;
$a1=($ke/$mm)**(2.0/3.0);
$inrad = $incl * $radian;

$d1=3.0/2.0*$k2/($a1*$a1)*(3.0*cos($inrad)*cos($inrad)-1.0)/((1.0-$eccen*$eccen)**(3.0/2.0));
$a0=$a1*(1.0-$d1/3.0-$d1*$d1-134.0/81.0*$d1*$d1*$d1);
$d0=3.0/2.0*$k2/($a0*$a0)*(3.0*cos($inrad)*cos($inrad)-1.0)/((1.0-$eccen*$eccen)**(3.0/2.0));
$semiax=$a0/(1-$d0)*6378.135;

}

sub calculate_orbs {

$period = 60.0*24.0/($mean_mot/(1+$d0));
$cax=$eccen*$semiax;
$perigee=$semiax-$cax-6378.1;
$apogee=$semiax+$cax-6378.1;

}

sub print_orb {
print OUTF  "     Epoch           $epoch\n";
printf OUTF "     Semimajor axis   %7.2f km\n",$semiax;
printf OUTF "     Apogee            %5.2f km\n",$apogee;
printf OUTF "     Perigee           %5.2f km\n",$perigee;
print OUTF  "     Eccentricity   $eccen\n";
printf OUTF  "     Inclination       %6.2f degrees\n",$incl;
printf OUTF "     Period            %6.2f minutes\n",$period;
printf OUTF "     RA of asc. node   %6.2f degrees\n",$raan;
printf OUTF "     Arg. of perigee   %6.2f degrees\n",$arg_perig;
printf OUTF "     Mean anomaly      %6.2f degrees\n",$mean_anom;
print OUTF  " \n";

}

sub print_tail {
print OUTF "<p>";

print OUTF "The FUSE Delta II second stage (NORAD #25792) reentered on \n";
print OUTF "the morning of August 4, 1999 during orbit number 708.  \n";
print OUTF "According to predictions by Alan Pickup, reentry \n";
print OUTF "occured within 90 minutes of 5:31 UT, probably over the \n";
print OUTF "Arabian Sea or India.  The final orbit was 119 x 103 km (74 x 64 mi).\n";
print OUTF "<p>";
print OUTF "<center>";
print OUTF "<font size=+2><font color=\"#6666CC\">\n";
print OUTF "<a href=\"reentry.html\"> Could anything have survived reentry?</a></font></font><p>\n";
print OUTF "</center>";
print OUTF "<img align=center src=\"delta2decay.gif\">\n";
print OUTF "<P>These numbers assume a Keplerian orbit; the actual apogee and perigee \n";
print OUTF "will differ by a few km on an orbit-to-orbit basis.\n";
print OUTF "<p>";
print OUTF "<p>The NORAD Two-Line Elements (TLEs) for FUSE can be found in the file \n";
print OUTF "<a href=\"./FUSE.TLE\" > FUSE.TLE </A>.\n";
print OUTF "<p> \n";
print OUTF "This page is automatically updated daily.  I wish to thank \n";
print OUTF "<a href=\"mailto:deej\@deej.com\">Doyle Groves</a> \n";
print OUTF "for providing a Perl script to access the NASA\n";
print OUTF "Orbital Information Group web page.\n";
print OUTF "<p> Ed Murphy, <a href=\"mailto:emurphy\@pha.jhu.edu\">\n";
print OUTF "<address>emurphy\@pha.jhu.edu</address></a>\n";
print OUTF "<P>\n";
print OUTF "<img src=\"/figures/purple_line2.gif\" width=640>\n";
print OUTF "<P>\n";
print OUTF "Last changed: $datest.\n";
print OUTF "<P>\n";
print OUTF "<i><a href=\"/index.shtml\">Return to the FUSE home page.</a></i><br clear=left>\n";
print OUTF "<p>\n";
print OUTF "</td></tr>\n";
print OUTF "</table>\n";
print OUTF "</center>\n";
print OUTF "</BODY>\n";
print OUTF "</HTML>\n";

}