astronomy-bundle
Version:
Bundle for astronomical calculations such as position of moon, sun and planets, sunrise, sunset or solar eclipses. Most of the calculations are based on Jean Meeus 'Astronomical Algorithms' book and the VSOP87 theory.
62 lines (61 loc) • 2.26 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const timeCalc_1 = require("../time/calculations/timeCalc");
function parseTwoLineElement(tleString) {
const rows = tleString
.trim()
.split('\n')
.map((row) => row.trim());
return Object.assign(Object.assign(Object.assign({}, _parseName(rows)), _parseRowOne(rows)), _parseRowTwo(rows));
}
exports.default = parseTwoLineElement;
function _parseName(rows) {
const row = rows.find((row) => row.match(/^[A-Za-z]/));
return {
name: row || 'satellite',
};
}
function _parseRowOne(rows) {
const row = _findRow(rows, 1);
return {
noradNr: parseInt(row.slice(2, 7)),
classification: row.slice(7, 8).trim(),
internationalDesignator: row.slice(9, 17).trim(),
epochYear: (0, timeCalc_1.shortYear2longYear)(row.slice(18, 20)),
epochDayOfYear: parseFloat(row.slice(20, 32)),
firstDerivativeMeanMotion: parseFloat(row.slice(33, 43)),
secondDerivativeMeanMotion: _parseExpString(row.slice(44, 52)),
dragTerm: _parseExpString(row.slice(53, 61)),
ephemerisType: parseInt(row.slice(62, 63)),
setNumber: parseInt(row.slice(64, 68)),
};
}
function _parseRowTwo(rows) {
const row = _findRow(rows, 2);
return {
catalogNumber: parseInt(row.slice(2, 7)),
inclination: parseFloat(row.slice(8, 16)),
rightAscension: parseFloat(row.slice(17, 25)),
eccentricity: parseFloat('0.' + row.slice(26, 33)),
argumentOfPerigee: parseFloat(row.slice(34, 42)),
meanAnomaly: parseFloat(row.slice(43, 51)),
meanMotion: parseFloat(row.slice(52, 63)),
revolution: parseInt(row.slice(63, 68)),
};
}
function _findRow(rows, rowNo) {
const regExp = new RegExp(`^${rowNo} `);
const row = rows.find((row) => row.match(regExp));
if (!row) {
throw new Error('Missing TLE row ' + rowNo);
}
return row;
}
function _parseExpString(expString) {
const matches = expString.match(/^([ -]?)(\d+)(-\d)$/);
if (matches) {
const fixedString = matches[1] + '.' + matches[2] + 'e' + matches[3];
return parseFloat(fixedString);
}
return parseFloat(expString);
}