-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathindex.js
95 lines (75 loc) · 3 KB
/
index.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
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
'use strict';
var eph = require('./build/');
// Example call: getAllPlanets("10.8.2015 17:09:01", 10.0014, 53.5653, 0);
function getAllPlanets(gregorianTerrestrialTimeString, geodeticalLongitude, geodeticalLatitude, height) {
var date;
eph.const.tlong = geodeticalLongitude;
eph.const.glat = geodeticalLatitude;
eph.const.height = height;
eph.const.date = gregorianTerrestrialTimeString;
if (eph.const.date) {
var tokens = eph.const.date.split(' ');
tokens[0] = tokens[0].split('.');
tokens[1] = tokens[1].split(':');
date = {
day: parseFloat(tokens[0][0]), // parseFloat strips leading zeros
month: parseFloat(tokens[0][1]),
year: parseFloat(tokens[0][2]),
hours: parseFloat(tokens[1][0]),
minutes: parseFloat(tokens[1][1]),
seconds: parseFloat(tokens[1][2])
};
eph.const.date = date;
}
eph.processor.init();
var ret = {
date: undefined,
observer: undefined,
observed: {}
};
var observables = Object.keys(eph.moshier.body);
for (var i = 0; i < observables.length; i++) {
var observeMe = observables[i];
if (['earth', 'init'].indexOf(observeMe) >= 0) {
continue;
}
eph.const.body = eph.moshier.body[observeMe];
eph.processor.calc(date, eph.const.body);
if (ret.date === undefined) {
ret.date = {
gregorianTerrestrial: [date.day, date.month, date.year].join('.') + ' ' + [date.hours, date.minutes, date.seconds].join(':'),
gregorianTerrestrialRaw: date,
gregorianUniversal: (eph.const.date.universalDateString),
gregorianDelta: ("00:00:" + (eph.const.date.delta)),
julianTerrestrial: (eph.const.date.julian),
julianUniversal: (eph.const.date.universal),
julianDelta: (eph.const.date.delta / 86400)
};
}
if (ret.observer === undefined) {
ret.observer = {
name: "earth",
longitueGeodetic: (eph.const.tlong),
longitudeGeodecentric: (eph.const.tlong),
latitudeGeodetic: (eph.const.glat),
latitudeGeodecentric: (eph.const.tlat),
heightGeodetic: (eph.const.height),
heightGeodecentric: (eph.const.trho * eph.const.aearth / 1000),
};
}
var body = {
name: eph.const.body.key,
raw: eph.const.body,
apparentLongitudeDms30: (eph.const.body.position.apparentLongitude30String),
apparentLongitudeDms360: (eph.const.body.position.apparentLongitudeString),
apparentLongitudeDd: (eph.const.body.position.apparentLongitude),
geocentricDistanceKm: (eph.const.body.position.geocentricDistance)
};
ret.observed[body.name] = body;
}
return ret;
}
module.exports = {
ephemeris: eph,
getAllPlanets: getAllPlanets
};