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/)
|
||||
|
||||
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;
|
||||
// check if JSON file is loaded. If not, calculate...
|
||||
if (files.length <= 0) {
|
||||
// checks if usecase is offline, then uses WebAssembly
|
||||
if ( $("body").attr("use") != "online" ) {
|
||||
var astrologer = new Worker('js/sweph.js');
|
||||
astrologer.postMessage([days, ts, lat, lon]);
|
||||
astrologer.onmessage = function(response) {
|
||||
Hours.moments = response.data;
|
||||
maker();
|
||||
}
|
||||
// checks if usecase is online, then uses server based calculation
|
||||
} else {
|
||||
var url = "https://almanac.sublunar.space/pmom.php?days="+days+"&ts="+ts+"&lat="+lat+"&lon="+lon;
|
||||
fetch(url)
|
||||
.then(function(response) {
|
||||
return response.json();
|
||||
})
|
||||
.then(function(json) {
|
||||
Hours.moments = json.query;
|
||||
maker();
|
||||
});
|
||||
}
|
||||
// always use the local WASM worker (no PHP backend needed)
|
||||
var astrologer = new Worker('js/sweph.js');
|
||||
astrologer.postMessage([days, ts, lat, lon]);
|
||||
astrologer.onmessage = function(response) {
|
||||
Hours.moments = response.data;
|
||||
maker();
|
||||
};
|
||||
astrologer.onerror = function(err) {
|
||||
NProgress.done();
|
||||
$('#settings').modal('show');
|
||||
alert("Ephemeris calculation failed. Please ensure pmom.js/pmom.wasm are available.\n\n" + err.message);
|
||||
console.error(err);
|
||||
};
|
||||
} else {
|
||||
// display calendar data from JSON file
|
||||
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
|
||||
|
||||
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:
|
||||
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
|
||||
# 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;
|
||||
int32 year, month, day, hour, minute, second, iflag, iflgret;
|
||||
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];
|
||||
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
|
||||
|
||||
// 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);
|
||||
lunar[1] = moon[0];
|
||||
lunar[2] = moon[1];
|
||||
|
|
@ -221,7 +222,7 @@ int * solar_moment(double lat, double lon, long unixtime, long *solar) {
|
|||
long epoch = 0;
|
||||
struct tm *tmp;
|
||||
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];
|
||||
double hours, tjd, td;
|
||||
double datm[2], geopos[3], lastset, lastrise, nextset, nextrise, onextrise, onextset;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue