Added ad-hoc tests to find discrepancy between JS and C code.

The JS and C SkyPos functions are calculating slightly
different values. It looks like the C code is actually
a little more accurate. I want to understand why.
This commit is contained in:
Don Cross
2019-05-18 22:23:08 -04:00
parent 82ba5efecc
commit f0f7db74dd
3 changed files with 45 additions and 8 deletions

10
generate/adhoc.js Normal file
View File

@@ -0,0 +1,10 @@
var Astronomy = require('../source/js/astronomy.js');
const observer = Astronomy.MakeObserver(29, -81, 10);
var body = 'Sun';
var time = Astronomy.MakeTime(-109572.5);
var pos = Astronomy.GeoVector(body, time);
var sky = Astronomy.SkyPos(pos, observer);
console.log(`J2000 RA = ${sky.j2000.ra.toFixed(16)}`);
console.log(`J2000 DEC = ${sky.j2000.dec.toFixed(16)}`);
console.log(`ofdate RA = ${sky.ofdate.ra.toFixed(16)}`);
console.log(`ofdate DEC = ${sky.ofdate.dec.toFixed(16)}`);

20
generate/adhoc_c Executable file
View File

@@ -0,0 +1,20 @@
#!/bin/bash
Fail()
{
echo "ERROR($0): $1"
exit 1
}
[[ -z "${CC}" ]] && CC=gcc
echo "$0: C compiler = ${CC}"
BUILDOPT='-g -O0'
${CC} ${BUILDOPT} -Wall -Werror -o ctest -I ../source/c/ ../source/c/astronomy.c ctest.c -lm || Fail "Error building ctest"
echo "$0: Built 'ctest' program."
./ctest adhoc || Fail "Failure reported by ctest."
echo "adhoc_c: success"
exit 0

View File

@@ -26,7 +26,7 @@ static int CheckVector(int lnum, astro_vector_t v)
#define CHECK_VECTOR(v,x) CHECK(CheckVector(__LINE__, ((v) = (x))))
static int Test_Geo(void);
static int AdHoc(void);
static int Test_AstroTime(void);
static int AstroCheck(void);
@@ -34,9 +34,9 @@ int main(int argc, const char *argv[])
{
int error = 0;
if (argc == 2 && !strcmp(argv[1], "geo"))
if (argc == 2 && !strcmp(argv[1], "adhoc"))
{
CHECK(Test_Geo()); /* ad hoc test for debugging */
CHECK(AdHoc()); /* ad hoc test for debugging */
}
else
{
@@ -145,17 +145,24 @@ fail:
return error;
}
static int Test_Geo(void)
static int AdHoc(void)
{
int error = 0;
astro_observer_t observer = Astronomy_MakeObserver(28.0, -81.0, 10.0);
astro_time_t time;
astro_vector_t pos;
astro_sky_t sky;
time.ut = -109492.2564886306936387;
time.tt = -109492.2562455624283757;
time.tt = -109572.4997569444385590;
time.ut = -109572.5;
CHECK_VECTOR(pos, Astronomy_GeoVector(BODY_SUN, time));
sky = Astronomy_SkyPos(pos, observer);
printf("J2000 RA = %0.16lf\n", sky.j2000.ra);
printf("J2000 DEC = %0.16lf\n", sky.j2000.dec);
printf("ofdate RA = %0.16lf\n", sky.ofdate.ra);
printf("ofdate DEC = %0.16lf\n", sky.ofdate.dec);
CHECK_VECTOR(pos, Astronomy_GeoVector(BODY_MERCURY, time));
printf("#(C ) GeoVector tt=%0.16lf ut=%0.16lf x=%0.16lf y=%0.16lf z=%0.16lf\n", time.tt, time.ut, pos.x, pos.y, pos.z);
fail:
return error;
}