From 5ea2bf65a10552d349ff7e128dfde4871d2057cc Mon Sep 17 00:00:00 2001 From: Don Cross Date: Tue, 6 Jul 2021 20:58:31 -0400 Subject: [PATCH] equator_of_date.js defaults to current date/time. Allow this demo to use the current date and time by default if the user does not specify one on the command line. This required changing the order of the command line parameters. --- demo/nodejs/equator_of_date.js | 15 +++++++++------ demo/nodejs/test/equator_of_date_correct.txt | 1 + demo/nodejs/test/test | 2 +- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/demo/nodejs/equator_of_date.js b/demo/nodejs/equator_of_date.js index b65fa2e2..69333733 100644 --- a/demo/nodejs/equator_of_date.js +++ b/demo/nodejs/equator_of_date.js @@ -6,14 +6,15 @@ */ const UsageText = ` -USAGE: node equator_of_date.js yyyy-mm-ddThh:mm:ssZ ra dec +USAGE: node equator_of_date.js ra dec [yyyy-mm-ddThh:mm:ssZ] Converts J2000 equatorial coordinates to equator-of-date coordinates. -yyyy-mm-ddThh:mm:ssZ = The date and time in UTC. ra = J2000 Right ascension in sidereal hours (0 .. 24). dec = J2000 Declination in degrees (-90 .. +90). +yyyy-mm-ddThh:mm:ssZ = Optional date and time in UTC. +(If omitted, the current date and time are used.) This program prints out the right ascension and declination of the same point in the sky, but expressed in the Earth's @@ -41,14 +42,16 @@ function ParseDate(text) { } function Demo() { - if (process.argv.length !== 5) { + if (process.argv.length < 4 || process.argv.length > 5) { console.log(UsageText); process.exit(1); } else { // Parse the command line arguments. - const time = Astronomy.MakeTime(ParseDate(process.argv[2])); - const ra = ParseNumber("RA", process.argv[3], 0, 24); - const dec = ParseNumber("DEC", process.argv[4], -90, +90); + const ra = ParseNumber("RA", process.argv[2], 0, 24); + const dec = ParseNumber("DEC", process.argv[3], -90, +90); + const date = (process.argv.length > 4) ? ParseDate(process.argv[4]) : new Date(); + const time = Astronomy.MakeTime(date); + console.log(`time = ${time}`); // Create a rotation matrix that converts J2000 equatorial (EQJ) // orientation to equator-of-date (EQD) orientation. diff --git a/demo/nodejs/test/equator_of_date_correct.txt b/demo/nodejs/test/equator_of_date_correct.txt index 75225b89..1aeffa88 100644 --- a/demo/nodejs/test/equator_of_date_correct.txt +++ b/demo/nodejs/test/equator_of_date_correct.txt @@ -1 +1,2 @@ +time = 2021-07-06T00:00:00.000Z Equator-of-date coordinates: RA=12.0181, DEC=44.8820 diff --git a/demo/nodejs/test/test b/demo/nodejs/test/test index abc04e29..f4adb176 100755 --- a/demo/nodejs/test/test +++ b/demo/nodejs/test/test @@ -12,7 +12,7 @@ node equatorial.js 38.1256 -89.5544 215.7 23.5 2021-03-27T18:45:00Z > test/equat diff test/equatorial.txt test/equatorial_correct.txt || Fail "Error comparing equatorial.js output." echo "Testing example: equator_of_date.js" -node equator_of_date.js 2021-07-06T00:00:00Z 12 45 > test/equator_of_date.txt || Fail "Error testing equator_of_date.js" +node equator_of_date.js 12 45 2021-07-06T00:00:00Z > test/equator_of_date.txt || Fail "Error testing equator_of_date.js" diff test/equator_of_date.txt test/equator_of_date_correct.txt || Fail "Error comparing equator_of_date.js output." echo "Testing example: camera.js"