- merged offline functionality
- added emscripten makefile
This commit is contained in:
parent
63260b2dee
commit
08a6d31d32
9 changed files with 137424 additions and 53 deletions
60
lib/sweph/JSMakefile
Normal file
60
lib/sweph/JSMakefile
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
# $Header$
|
||||
# this Makefile creates a SwissEph library and a swetest sample on 64-bit
|
||||
# Redhat Enterprise Linux RHEL 6.
|
||||
|
||||
# The mode marked as 'Linux' should also work with the GNU C compiler
|
||||
# gcc on other systems.
|
||||
|
||||
# If you modify this makefile for another compiler, please
|
||||
# let us know. We would like to add as many variations as possible.
|
||||
# If you get warnings and error messages from your compiler, please
|
||||
# let us know. We like to fix the source code so that it compiles
|
||||
# free of warnings.
|
||||
# send email to the Swiss Ephemeris mailing list.
|
||||
#
|
||||
|
||||
CFLAGS = -g -Wall -fPIC -O2 -DVARIANT=2 # for Linux and other gcc systems
|
||||
OP=$(CFLAGS)
|
||||
CC=emcc #for Linux
|
||||
|
||||
# compilation rule for general cases
|
||||
.o :
|
||||
$(CC) $(OP) -o $@ $? -lm
|
||||
.c.o:
|
||||
$(CC) -c $(OP) $<
|
||||
|
||||
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 EXTRA_EXPORTED_RUNTIME_METHODS='["ccall", "cwrap"]' -L. -lswe -lm -ldl
|
||||
|
||||
install:
|
||||
mv pmom.js ../../js/; mv pmom.wasm ../../js/; mv pmom.wast ../../js/
|
||||
|
||||
# create an archive and a dynamic link libary fro SwissEph
|
||||
# a user of this library will inlcude swephexp.h and link with -lswe
|
||||
|
||||
libswe.a: $(SWEOBJ)
|
||||
ar r libswe.a $(SWEOBJ)
|
||||
|
||||
libswe.so: $(SWEOBJ)
|
||||
$(CC) -shared -o libswe.so $(SWEOBJ)
|
||||
|
||||
clean:
|
||||
rm -f *.o *.wasm *.wast *.js *.html pmom libswe*; rm ../../js/pmom.*
|
||||
|
||||
###
|
||||
swecl.o: swejpl.h sweodef.h swephexp.h swedll.h sweph.h swephlib.h
|
||||
sweclips.o: sweodef.h swephexp.h swedll.h
|
||||
swedate.o: swephexp.h sweodef.h swedll.h
|
||||
swehel.o: swephexp.h sweodef.h swedll.h
|
||||
swehouse.o: swephexp.h sweodef.h swedll.h swephlib.h swehouse.h
|
||||
swejpl.o: swephexp.h sweodef.h swedll.h sweph.h swejpl.h
|
||||
swemini.o: swephexp.h sweodef.h swedll.h
|
||||
swemmoon.o: swephexp.h sweodef.h swedll.h sweph.h swephlib.h
|
||||
swemplan.o: swephexp.h sweodef.h swedll.h sweph.h swephlib.h swemptab.h
|
||||
swepcalc.o: swepcalc.h swephexp.h sweodef.h swedll.h
|
||||
sweph.o: swejpl.h sweodef.h swephexp.h swedll.h sweph.h swephlib.h
|
||||
swephlib.o: swephexp.h sweodef.h swedll.h sweph.h swephlib.h
|
||||
swetest.o: swephexp.h sweodef.h swedll.h
|
||||
|
|
@ -13,7 +13,7 @@
|
|||
# send email to the Swiss Ephemeris mailing list.
|
||||
#
|
||||
|
||||
CFLAGS = -g -Wall -fPIC -O2 # for Linux and other gcc systems
|
||||
CFLAGS = -g -Wall -fPIC -O2 -DVARIANT=1 # for Linux and other gcc systems
|
||||
OP=$(CFLAGS)
|
||||
CC=cc #for Linux
|
||||
|
||||
|
|
|
|||
|
|
@ -3,12 +3,23 @@
|
|||
* License MIT: http://www.opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#define ONLINE 1
|
||||
#define OFFLINE 2
|
||||
|
||||
#ifndef VARIANT
|
||||
#error "VARIANT needs to be set"
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include <math.h>
|
||||
#include "swephexp.h"
|
||||
|
||||
#if VARIANT == OFFLINE
|
||||
#include <emscripten.h>
|
||||
#endif
|
||||
|
||||
/**
|
||||
* converts Julian Day to UNIX epoch
|
||||
*/
|
||||
|
|
@ -254,34 +265,19 @@ int * solar_moment(double lat, double lon, unsigned long unixtime, unsigned long
|
|||
/**
|
||||
* calculates JSON Ephemeris Object
|
||||
*/
|
||||
int main(int argc,char* argv[]) // days, timestamp, latitude, longitude
|
||||
const char * pmom(int days, long epoch, double latitude, double longitude, int buflen) // days, timestamp, latitude, longitude
|
||||
{
|
||||
double latitude = 0.0;
|
||||
double longitude = 0.0;
|
||||
unsigned long epoch = 0, queryday;
|
||||
unsigned long queryday;
|
||||
struct tm *tmp;
|
||||
time_t timestamp = 0;
|
||||
int32 year, month, day, hour, minute, second, j, h, m, interval, start, days = 1, hm;
|
||||
int32 year, month, day, hour, minute, second, j, h, m, interval, start, hm;
|
||||
double hours;
|
||||
unsigned long solar[9] = {0};
|
||||
double lunar[3] = {0.0}, planet[16] = {0.0};
|
||||
char* Buffer = malloc(buflen);
|
||||
int length = 0;
|
||||
|
||||
// read and assign commandline arguments
|
||||
if ( argc > 1 ) {
|
||||
days = atof(argv[1]);
|
||||
}
|
||||
if ( argc > 3 ) {
|
||||
latitude = atof(argv[3]);
|
||||
longitude = atof(argv[4]);
|
||||
}
|
||||
if ( argc > 2 ) {
|
||||
sscanf(argv[2], "%lu", &epoch);
|
||||
timestamp = epoch;
|
||||
}
|
||||
else {
|
||||
time(×tamp);
|
||||
epoch = (int) timestamp;
|
||||
}
|
||||
timestamp = epoch;
|
||||
|
||||
// take timestamp, convert it to year, month, day, decimal hour
|
||||
tmp = gmtime(×tamp);
|
||||
|
|
@ -296,7 +292,7 @@ int main(int argc,char* argv[]) // days, timestamp, latitude, longitude
|
|||
// start of Almanac
|
||||
queryday = time_to_epoch(year, month, day, 0, 0, 0);
|
||||
j = 0;
|
||||
printf("{ \"query\":[");
|
||||
length += snprintf(Buffer+length, buflen-length, "{ \"query\":[");
|
||||
|
||||
// calculate all hours for all days
|
||||
while ( j <= days ) {
|
||||
|
|
@ -316,18 +312,65 @@ int main(int argc,char* argv[]) // days, timestamp, latitude, longitude
|
|||
|
||||
planetary_moment(latitude, longitude, hm, lunar, planet);
|
||||
|
||||
printf(
|
||||
length += snprintf(Buffer+length, buflen-length,
|
||||
"{ \"ts\": %d, \"lunar\": { \"day\": %d, \"angle\": %f, \"phase\": %f }, \"planetary\": { \"day\": { \"no\": %d, \"start\": %d, \"end\": %d }, \"night\": { \"start\": %d, \"end\": %d }, \"hour\": { \"no\": %d, \"start\": %d, \"end\": %d, \"length\": { \"day\": %d, \"night\": %d } } }, \"ephemeris\": { \"sun\": { \"deg\": %f, \"speed\": %f }, \"moon\": { \"deg\": %f, \"speed\": %f }, \"mercury\": { \"deg\": %f, \"speed\": %f }, \"venus\": { \"deg\": %f, \"speed\": %f }, \"mars\": { \"deg\": %f, \"speed\": %f }, \"jupiter\": { \"deg\": %f, \"speed\": %f }, \"saturn\": { \"deg\": %f, \"speed\": %f }, \"asc\": { \"deg\": %f }, \"mc\": { \"deg\": %f } } }",
|
||||
hm, (int) lunar[0], lunar[1], lunar[2], solar[7], solar[1], solar[2]-1, solar[2], solar[3]-1, h, hm, hm+interval-1, solar[5], solar[6], planet[0], planet[7], planet[1], planet[8], planet[2], planet[9], planet[3], planet[10], planet[4], planet[11], planet[5], planet[12], planet[6], planet[13], planet[14], planet[15]
|
||||
);
|
||||
|
||||
if(j == days && h == 23) printf("");
|
||||
else printf(", ");
|
||||
if(j == days && h == 23) length += snprintf(Buffer+length, buflen-length, "");
|
||||
else length += snprintf(Buffer+length, buflen-length, ", ");
|
||||
|
||||
h++;
|
||||
}
|
||||
queryday = solar[3];
|
||||
j++;
|
||||
};
|
||||
printf("]}");
|
||||
length += snprintf(Buffer+length, buflen-length, "]}");
|
||||
return Buffer;
|
||||
}
|
||||
|
||||
#if VARIANT == ONLINE
|
||||
int main(int argc,char* argv[]) // days, timestamp, latitude, longitude
|
||||
{
|
||||
double latitude = 0.0;
|
||||
double longitude = 0.0;
|
||||
unsigned long epoch = 0;
|
||||
time_t timestamp = 0;
|
||||
int32 days = 1, buflen;
|
||||
|
||||
// read and assign commandline arguments
|
||||
if ( argc > 1 ) {
|
||||
days = atof(argv[1]);
|
||||
}
|
||||
if ( argc > 3 ) {
|
||||
latitude = atof(argv[3]);
|
||||
longitude = atof(argv[4]);
|
||||
}
|
||||
if ( argc > 2 ) {
|
||||
sscanf(argv[2], "%lu", &epoch);
|
||||
timestamp = epoch;
|
||||
}
|
||||
else {
|
||||
time(×tamp);
|
||||
epoch = (int) timestamp;
|
||||
}
|
||||
|
||||
timestamp = epoch;
|
||||
buflen = days * 100000;
|
||||
printf(pmom( days, epoch, latitude, longitude, buflen));
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
#if VARIANT == OFFLINE
|
||||
EMSCRIPTEN_KEEPALIVE
|
||||
const char * get(int days, long epoch, double latitude, double longitude) // days, timestamp, latitude, longitude
|
||||
{
|
||||
time_t timestamp = 0;
|
||||
int32 buflen;
|
||||
|
||||
timestamp = epoch;
|
||||
buflen = days * 100000;
|
||||
return pmom( days, epoch, latitude, longitude, buflen);
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue