Commit Graph

45 Commits

Author SHA1 Message Date
Don Cross
7e196a3c17 Fixed Windows batch files ignoring negative integer failure codes.
In many of my Windows batch files, I used the following
construct to detect failures:

    do_something
    if errorlevel 1 (
        echo.An error occurred in do_something
        exit /b 1
    )

I discovered that it is possible for a Windows program
to exit with a negative integer error code.
This causes the above construct to miss the failure
and the batch file blithely continues.

So I have replaced that construct with

    do_something || (
        echo.An error occurred in do_something
        exit /b 1
    )

This way, if the command exits with any nonzero error,
we correctly detect it as a failure.
2023-02-26 10:26:42 -05:00
Don Cross
42650bd341 Java: added true solar time demo 2023-02-12 20:01:05 -05:00
Don Cross
1a4f842764 Updated Ecliptic to return ECL in all languages. 2022-12-10 19:35:42 -05:00
Don Cross
8a153315cf Simplified and optimized nutation formula.
While trying to convert ecliptic coordinates from mean
equinox of date to true equinox of date, I ran into excessive
overhead from the IAU2000B nutation model. The fact that it
uses 77 trigonometric terms made the calculations a lot slower.

https://apps.dtic.mil/sti/pdfs/AD1112517.pdf
Page 4 in the above document mentions a shorter series
“NOD version 2” that has 13 terms instead of 77 as used in IAU2000B.
I had not noticed NOD2 before, because it appears only in
the FORTRAN version of NOVAS 3.x, not the C version.

After reading the FORTRAN code, I realized NOD2 is the same
as IAU2000B, only it keeps the first 13 of 77 terms.
The terms are already arranged in descending order of
significance, so it is easy to truncate the series.

Based on this discovery, I realized I could achieve all of
the required accuracy needed for Astronomy Engine by
keeping only the first 5 terms of the nutation series.
This tremendously speeds up nutation calculations while
sacrificing only a couple of arcseconds of accuracy.

It also makes the minified JavaScript code smaller:
Before: 119500 bytes.
After:  116653 bytes.

So that's what I did here. Most of the work was updating
unit tests for accepting slightly different calculation
results.

The nutation formula change did trigger detection of a
lurking bug in the inverse_terra functions, which convert
a geocentric vector into latitude, longitude, and elevation
(i.e. an Observer object). The Newton's Method loop in
this function was not always converging, resulting in
an infinite loop. I fixed that by increasing the
convergence threshold and throwing an exception
if the loop iterates more than 10 times.

I also fixed a couple of bugs in the `demotest` scripts.
2022-12-04 10:31:15 -05:00
Don Cross
61445889ad Forgot to update Java demo riseset.txt.
Changes to the altitude search caused a tiny
change in rise/set times in all the demo programs.
I remembered to update the expected output for
Kotlin, but forgot to do it for Java.
2022-11-14 07:52:46 -05:00
Don Cross
06b62887d2 Kotlin: obscuration for solar, lunar eclipses. 2022-10-20 17:31:21 -04:00
Don Cross
c1759b081a Kotlin: Reverse chrono search for rise/set, hour angles.
The following Kotlin functions now support searching
in forward or reverse chronological order:

    searchRiseSet
    searchAltitude
    searchHourAngle
2022-10-01 11:26:03 -04:00
Don Cross
5676049596 Kotlin: added iterator helper functions
Added the following iterator functions that wrap
search/next pairs of functions:

    globalSolarEclipsesAfter
    localSolarEclipsesAfter
    lunarApsidesAfter
    lunarEclipsesAfter
    moonNodesAfter
    moonQuartersAfter
    planetApsidesAfter
    transitsAfter

I updated the following Kotlin demos:

    MoonPhase.kt    ==> moonQuartersAfter
    LunarEclipse.kt ==> lunarEclipsesAfter

However, I have not yet figured out how to use these
functions in the corresponding Java demos.
2022-05-06 21:52:27 -04:00
Don Cross
87665fe5d5 Added missing Windows batch files: rundemo.bat
The help pages for the Java and Kotlin demos mention
a Windows batch file `rundemo.bat`, but they did not exist.
I created them, so now the documentation is correct.
2022-05-04 21:44:04 -04:00
Ebrahim Byagowi
37ca6c4fe3 jvm demos: Use stream/sequence
Uses of newer language structures to recreate the needed logic.
2022-05-05 01:38:14 +04:30
Don Cross
cc4bc88fbe Improved efficiency of 3 lunar eclipse demos.
Three of the lunar eclipse demos (Python, Java, Kotlin)
provided a less than ideal example of efficient computation.
They were wasting a lunar eclipse search by calculating it
but not printing it. Now after printing exactly 10 lunar
eclipses, stop running immediately.
2022-05-04 14:00:35 -04:00
Don Cross
29e2bd31b8 Java demo: lunar eclipse prediction 2022-05-04 13:04:39 -04:00
Don Cross
7a916d4f8c Java demo: rise/set/culmination
Added Java demo to search for rise/set/culmination
of the Sun and Moon.

Also added the missing entry for the Kotlin
rise/set/culmination demo that I had forgotten.
2022-05-04 11:12:49 -04:00
Don Cross
f32a922ddb Demo for Kotlin, Java: constellation 2022-05-03 16:50:11 -04:00
Ebrahim Byagowi
c24d49f742 jvm: Upgrade Java language version to 11 2022-05-03 21:57:57 +04:30
Don Cross
c9f2228827 Cannot use Optional<T>.isEmpty() in Java 1.8.
Our GitHub Actions tests were using a Java 11
function `Optional<T>.isEmpty()`, but it runs using
Java 1.8. Replaced `isEmpty` with `!isPresent`.
2022-05-02 20:34:29 -04:00
Ebrahim Byagowi
6c55d15778 jvm demos: Simplify main function
Also makes the two more similar.
2022-05-03 01:41:06 +04:30
Ebrahim Byagowi
612f2ef3f4 jvm demos: Apply IDE provided suggestions 2022-05-03 01:27:05 +04:30
Don Cross
1e84f4940f Demo jupiter_moons for Kotlin, Java.
Added Kotlin and Java demos for calculating Jupiter's moons.
Illustrates correcting for light travel time.
I added named getters for the 4 moons in `JupiterMoonsInfo`,
because in Java it was really ugly to write
`jm.getMoon()[0]`, etc.
2022-05-02 15:45:10 -04:00
Don Cross
5df9b03e7c Added comments to Java demos. 2022-05-02 13:38:31 -04:00
Don Cross
e11cb1721b Simplified demotest scripts for C, C#, JS, PY.
I made the scripts for testing the demos for
C, C#, JavaScript, and Python follow the improved
pattern used for Java and Kotlin: much smaller
and easier to maintain thanks to bash functions.
2022-05-02 12:27:19 -04:00
Don Cross
237bc42084 Added Kotlin demo: positions.
I also reworked how the Java and Kotlin demos
process errors in the command line arguments.
Using exceptions that are caught by main() rather
than directly exiting the process where the errors
are detected.
2022-05-02 11:28:16 -04:00
Don Cross
551ce7a249 Simplified Java/Kotlin demo tests.
I found that it is possible to use the "||" operator
in Windows batch files, and it works the same as the
"||" operator in bash scripts.

This inspired me to rework the bash scripts and
Windows batch files for running the Java/Kotlin demo
tests to be much more compact using functions/subroutines.

The best part is, the new approach will make it much
easier to add more demo tests in the future.

Removed the "now" test from Java demos, because it
does not follow the same pattern as the other demos,
plus it is not really demonstrating astronomy calculations.

Starting working on the Positions.kt demo; but not finished yet.
2022-05-02 10:21:23 -04:00
Don Cross
190cc5b534 Java: added positions demo. 2022-05-01 21:12:57 -04:00
Don Cross
eac8582418 Test Kotlin demos in Windows. 2022-05-01 19:48:18 -04:00
Don Cross
6064bf1d94 Updated README.md for the Java demo suite.
Added link and description of Seasons.java.
Mention `rundemo` script.
2022-05-01 09:40:50 -04:00
Don Cross
99d1aecba7 Minor cleanup to Java demos. 2022-04-30 21:38:32 -04:00
Don Cross
303bebdff5 Added Java demo for calculating seasons. 2022-04-30 21:20:33 -04:00
Don Cross
7c74730d8e Java demos: print error message for unknown verb. 2022-04-30 17:46:15 -04:00
Don Cross
b3d42fc6d5 Java demos: reworked as table-driven.
As I add more Java demos, it will make the code more
compact to factor out argument count checking, etc.
Reworked as a table-driven model instead of using `switch`,
so that I will be able to add new demos more concisely.
2022-04-30 12:20:28 -04:00
Don Cross
8f5f8940bc Java demo: eliminate use of Date. 2022-04-30 11:31:32 -04:00
Don Cross
e81a566d1e Kotlin: was not running Java demo tests.
Run the Java demo unit test as part of the automated test suite.
If the test fails, print the xml test results to the screen,
so if it happens in GitHub Actions, we can see what went wrong
and diagnose the problem.
2022-04-30 11:14:01 -04:00
Ebrahim Byagowi
13f6e98866 Kotlin: Use Instant.parse instead a custom date parser
Also fixes the demo which had the same code.
2022-04-30 12:14:46 +04:30
Don Cross
3ca64f1ab2 Kotlin: fixed Java demo test for Windows.
I forgot to update the Windows batch file
for testing Java demo programs. Now it works
and correctly verifies the output of the
Java demo `MoonPhase`.
2022-04-28 21:52:33 -04:00
Don Cross
05684bafdb Kotlin: added Java demo: moonphase.
This is the first substantial demo of using
the Kotlin version of Astronomy Engine from
a Java program.

Structured the README.md so I can keep adding more and
more demos as separate Java class files.
The `demotest` script builds the code and will run
each demo one at a time, verifying each one's output.
2022-04-28 21:04:54 -04:00
Don Cross
61e398b592 Kotlin: removed all dependencies on JVM.
The Kotlin version of Astronomy Engine was using Java
classes like `Date` and `GregorianCalendar`.

Reworked the code to use a completely self-contained
representation of calendar date/time, just like the C version does.
Now Astronomy Engine does not depend on anything outside of
the Kotlin standard library. This should allow us to use
Astronomy Engine for Kotlin Native apps, Web Assembly, etc.

Updated Java demo to use the new method Time.fromMillisecondsSince1970.
2022-04-14 10:55:22 -04:00
Ebrahim Byagowi
7ad9487c3e kotlin: Upgrade Android example to use the new namings 2022-04-12 23:29:09 +04:30
Don Cross
79ff7b2805 Kotlin: Create fatJar during initial build.
Moved the step that creates the fatJar into
the main build process for Kotlin. This is
needed to run the Java demos, and it is good
to fail early if it cannot be built.
2022-04-12 10:37:02 -04:00
Ebrahim Byagowi
6ac0dcbff4 kotlin: Directly provide the library to demo
No longer having jitpack as the middle man and just directly building
demo from the project itself.
2022-04-12 12:06:58 +04:30
Don Cross
57a736067a Kotlin: renamed AstroTime, AstroVector.
Renamed AstroTime to Time.
Renamed AstroVector to Vector.
For some reason this breaks the Java demo build.
I'm pushing the broken build anyway to see if
ebraminio can help me fix it.
2022-04-11 20:17:59 -04:00
Don Cross
57ab910abb Automate validation of Java demos in Windows. 2022-03-22 16:04:36 -04:00
Don Cross
ae5e744e1b Verify that Java demos work. Prep more demos.
Restructured the Java code so we pass in command
line arguments to select which demo we want to run.
We will also pass in date/time, latitude/longitude,
or whatever numeric data we need for future demos.

Automated test run of the Java demos from the
unit test suite.
2022-03-22 12:55:49 -04:00
Ebrahim Byagowi
c588da34c9 jvm: Make the demo project able to produce fat jars
Adopted from https://stackoverflow.com/a/63332420

So one can run the demo with `./gradlew jar && java -jar build/libs/astronomy-demo-0.0.1.jar`
instead `./gradlew run`
2022-03-22 19:25:41 +04:30
Don Cross
f031d6fc64 Added placeholder links to Android, Java demos. 2022-03-21 20:52:46 -04:00
Ebrahim Byagowi
c318b586eb kotlin: Add a Java demo project 2022-03-22 04:33:10 +04:30