forked from koansys/isat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tle.js
49 lines (47 loc) · 1.69 KB
/
tle.js
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
// Get, parse, and return TLE structures
var tle = {
// I need to get a grip on proper OO patterns :-(
content : null,
lines : null,
tles : null,
readFile : function (fileName) {
// https://developer.mozilla.org/en-US/docs/DOM/XMLHttpRequest/Using_XMLHttpRequest
var request = new XMLHttpRequest();
var ASYNC = false; // TODO do async callback properly
request.open('GET', fileName, ASYNC);
request.send(); // blocks until returned due to ASYNC=false
if (request.status !== 200) {
return null; // TODO throw an error
}
this.content = request.responseText;
return this.content;
},
readFileLines : function (fileName) {
this.readFile(fileName);
this.lines = this.content.split('\n');
return this.lines;
},
parseFile : function (fileName) {
// Read file: if line starts with '1' or '2' assume TLE line 1, 2, otherwise store as comment/name
var lines = this.readFileLines(fileName);
var line;
var tle = [];
var tles = [];
for (linenum = 0; linenum < lines.length; linenum++) {
if (lines[linenum].substring(0, 2) === '1 ') {
tle[1] = lines[linenum];
}
else if (lines[linenum].substring(0, 2) === '2 ') {
tle[2] = lines[linenum];
tles.push(tle);
tle = [];
}
else {
tle[0] = lines[linenum]; // TODO: trim whitespace
}
}
console.log('tle.js: File=' + fileName + ' TLEs=' + tles.length);
this.tles = tles;
return tles;
}
};