Use wasm ephemeris locally and document Caddy serving
This commit is contained in:
parent
dbe9758b7c
commit
ba47f6dae4
7 changed files with 3876 additions and 25 deletions
11
Caddyfile
Normal file
11
Caddyfile
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
:80 {
|
||||||
|
root * /var/home/randogoth/Projects/code/sublunar.almanac
|
||||||
|
encode zstd gzip
|
||||||
|
|
||||||
|
@wasm {
|
||||||
|
path /js/*.wasm
|
||||||
|
}
|
||||||
|
header @wasm Content-Type application/wasm
|
||||||
|
|
||||||
|
file_server
|
||||||
|
}
|
||||||
|
|
@ -4,3 +4,8 @@ browser based tool to find auspicious hours for magical operations
|
||||||
[http://almanac.sublunar.space/](http://almanac.sublunar.space/)
|
[http://almanac.sublunar.space/](http://almanac.sublunar.space/)
|
||||||
|
|
||||||
check the article [here](http://sublunar.space/2018-12-sublunar-almanac.html)
|
check the article [here](http://sublunar.space/2018-12-sublunar-almanac.html)
|
||||||
|
|
||||||
|
## Running without PHP (WASM path)
|
||||||
|
- Build wasm assets: `podman run --rm --userns=keep-id -v $(pwd):/src:Z -w /src/lib/sweph docker.io/emscripten/emsdk make -f JSMakefile clean pmom install`
|
||||||
|
- Serve statically with Caddy (example in `Caddyfile`): `caddy run --config Caddyfile`
|
||||||
|
- Ensure `js/pmom.js` and `js/pmom.wasm` are served (Caddyfile sets `application/wasm` for `*.wasm`).
|
||||||
|
|
|
||||||
|
|
@ -158,26 +158,19 @@ SL.Calendar = (function() {
|
||||||
var files = document.getElementById('fileInput').files;
|
var files = document.getElementById('fileInput').files;
|
||||||
// check if JSON file is loaded. If not, calculate...
|
// check if JSON file is loaded. If not, calculate...
|
||||||
if (files.length <= 0) {
|
if (files.length <= 0) {
|
||||||
// checks if usecase is offline, then uses WebAssembly
|
// always use the local WASM worker (no PHP backend needed)
|
||||||
if ( $("body").attr("use") != "online" ) {
|
|
||||||
var astrologer = new Worker('js/sweph.js');
|
var astrologer = new Worker('js/sweph.js');
|
||||||
astrologer.postMessage([days, ts, lat, lon]);
|
astrologer.postMessage([days, ts, lat, lon]);
|
||||||
astrologer.onmessage = function(response) {
|
astrologer.onmessage = function(response) {
|
||||||
Hours.moments = response.data;
|
Hours.moments = response.data;
|
||||||
maker();
|
maker();
|
||||||
}
|
};
|
||||||
// checks if usecase is online, then uses server based calculation
|
astrologer.onerror = function(err) {
|
||||||
} else {
|
NProgress.done();
|
||||||
var url = "https://almanac.sublunar.space/pmom.php?days="+days+"&ts="+ts+"&lat="+lat+"&lon="+lon;
|
$('#settings').modal('show');
|
||||||
fetch(url)
|
alert("Ephemeris calculation failed. Please ensure pmom.js/pmom.wasm are available.\n\n" + err.message);
|
||||||
.then(function(response) {
|
console.error(err);
|
||||||
return response.json();
|
};
|
||||||
})
|
|
||||||
.then(function(json) {
|
|
||||||
Hours.moments = json.query;
|
|
||||||
maker();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// display calendar data from JSON file
|
// display calendar data from JSON file
|
||||||
var fr = new FileReader();
|
var fr = new FileReader();
|
||||||
|
|
|
||||||
3841
js/pmom.js
Normal file
3841
js/pmom.js
Normal file
File diff suppressed because it is too large
Load diff
BIN
js/pmom.wasm
Executable file
BIN
js/pmom.wasm
Executable file
Binary file not shown.
|
|
@ -27,10 +27,10 @@ SWEOBJ = swedate.o swehouse.o swejpl.o swemmoon.o swemplan.o swepcalc.o sweph.o\
|
||||||
swepdate.o swephlib.o swecl.o swehel.o
|
swepdate.o swephlib.o swecl.o swehel.o
|
||||||
|
|
||||||
pmom: pmom.o libswe.a
|
pmom: pmom.o libswe.a
|
||||||
$(CC) $(OP) -o pmom.js pmom.o -s WASM=1 -s "BINARYEN_TRAP_MODE='clamp'" -s EXTRA_EXPORTED_RUNTIME_METHODS='["ccall", "cwrap"]' -L. -lswe -lm -ldl
|
$(CC) $(OP) -o pmom.js pmom.o -s WASM=1 -s EXPORTED_RUNTIME_METHODS='["ccall","cwrap"]' -L. -lswe -lm -ldl
|
||||||
|
|
||||||
install:
|
install:
|
||||||
mv pmom.js ../../js/; mv pmom.wasm ../../js/; mv pmom.wast ../../js/
|
mv pmom.js ../../js/; mv pmom.wasm ../../js/
|
||||||
|
|
||||||
# create an archive and a dynamic link libary fro SwissEph
|
# create an archive and a dynamic link libary fro SwissEph
|
||||||
# a user of this library will inlcude swephexp.h and link with -lswe
|
# a user of this library will inlcude swephexp.h and link with -lswe
|
||||||
|
|
|
||||||
|
|
@ -133,7 +133,7 @@ int * planetary_moment(double lat, double lon, long unixtime, double *lunar, dou
|
||||||
time_t timestamp = 0;
|
time_t timestamp = 0;
|
||||||
int32 year, month, day, hour, minute, second, iflag, iflgret;
|
int32 year, month, day, hour, minute, second, iflag, iflgret;
|
||||||
int pl, ipl, rsmi, return_code, dl, lhour, nm;
|
int pl, ipl, rsmi, return_code, dl, lhour, nm;
|
||||||
double hours, tjd_ts, te, lastnew;
|
double hours, tjd_ts, te, lastnew = 0.0;
|
||||||
double x2[6], datm[2], geopos[3], moon[20], llp[20], lunarday[31], data[13], datb[10];
|
double x2[6], datm[2], geopos[3], moon[20], llp[20], lunarday[31], data[13], datb[10];
|
||||||
char serr[AS_MAXCH], starname[255];
|
char serr[AS_MAXCH], starname[255];
|
||||||
|
|
||||||
|
|
@ -188,7 +188,8 @@ int * planetary_moment(double lat, double lon, long unixtime, double *lunar, dou
|
||||||
planets[16] = datb[2]; // armc
|
planets[16] = datb[2]; // armc
|
||||||
|
|
||||||
// calculate moon phase
|
// calculate moon phase
|
||||||
return_code = swe_pheno(te, SE_MOON, iflag, &moon, serr);
|
// swe_pheno expects a pointer to the first element
|
||||||
|
return_code = swe_pheno(te, SE_MOON, iflag, moon, serr);
|
||||||
if (return_code == ERR) printf("%s\n", serr);
|
if (return_code == ERR) printf("%s\n", serr);
|
||||||
lunar[1] = moon[0];
|
lunar[1] = moon[0];
|
||||||
lunar[2] = moon[1];
|
lunar[2] = moon[1];
|
||||||
|
|
@ -221,7 +222,7 @@ int * solar_moment(double lat, double lon, long unixtime, long *solar) {
|
||||||
long epoch = 0;
|
long epoch = 0;
|
||||||
struct tm *tmp;
|
struct tm *tmp;
|
||||||
time_t timestamp = 0;
|
time_t timestamp = 0;
|
||||||
int32 year, month, day, hour, minute, second, iflag, pday = 0;
|
int32 year, month, day, hour, minute, second, iflag = 0, pday = 0;
|
||||||
int ipl, rsmi, hourlength[3];
|
int ipl, rsmi, hourlength[3];
|
||||||
double hours, tjd, td;
|
double hours, tjd, td;
|
||||||
double datm[2], geopos[3], lastset, lastrise, nextset, nextrise, onextrise, onextset;
|
double datm[2], geopos[3], lastset, lastrise, nextset, nextrise, onextrise, onextset;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue