package org.madore.ephem; import java.util.List; import java.util.ArrayList; import java.util.EnumMap; import java.io.InputStream; import java.io.InputStreamReader; import java.io.BufferedReader; public final class VSOP87 { public static enum Planet { MERCURY("mercury"), VENUS("venus"), EARTH("earth"), JUPITER("jupiter"), SATURN("saturn"), URANUS("uranus"), NEPTUNE("neptune"); final String name; Planet(String name) { this.name = name; } } public static enum Variable { LAT("lat"), LONG("long"), DIST("dist"); final String name; Variable(String name) { this.name = name; } } // The argument is in Julian millennia (value is in radians). public static Comput.Polynomial[] lambdas = new Comput.Polynomial[] { new Comput.Polynomial(4.40260884240, 26087.9031415742), // Mercury new Comput.Polynomial(3.17614669689, 10213.2855462110), // Venus new Comput.Polynomial(1.75347045953, 6283.0758499914), // Earth new Comput.Polynomial(6.20347611291, 3340.6124266998), // Mars new Comput.Polynomial(0.59954649739, 529.6909650946), // Jupiter new Comput.Polynomial(0.87401675650, 213.2990954380), // Saturn new Comput.Polynomial(5.48129387159, 74.7815985673), // Uranus new Comput.Polynomial(5.31188628676, 38.1330356378), // Neptune new Comput.Polynomial(5.19846674103, 77713.7714681205), // Moon D new Comput.Polynomial(1.62790523337, 84334.6615813083), // Moon F new Comput.Polynomial(2.35555589827, 83286.9142695536), // Moon l new Comput.Polynomial(3.81034454697, 83997.0911355954) // Moon Lm }; private static EnumMap> data = new EnumMap>(Planet.class); public static Comput.SumPoisson2Terms getFunc(Planet pl, Variable v) { if ( ! data.containsKey(pl) ) { data.put(pl, new EnumMap(Variable.class)); } if ( ! data.get(pl).containsKey(v) ) { List series = new ArrayList(); try { InputStream str = VSOP87.class.getResourceAsStream("vsop87-simp.dat"); BufferedReader in = new BufferedReader(new InputStreamReader(str, "utf-8")); String s; while ( ( s = in.readLine() ) != null ) { String[] fields = s.split("\t"); if ( ! fields[0].equals(pl.name) || ! fields[1].equals(v.name) ) continue; int deg = Integer.parseInt(fields[2]); String[] subfields = fields[3].split(","); double[] om = new double[12]; for ( int j=0 ; j<12 ; j++ ) om[j] = Double.parseDouble(subfields[j]); double b = Double.parseDouble(fields[4]); double a = Double.parseDouble(fields[5]); series.add(Comput.Poisson2Term.ab(deg, a, b, om, lambdas)); } } catch ( Exception e ) { throw new RuntimeException(e); } data.get(pl).put(v, new Comput.SumPoisson2Terms(series)); } return data.get(pl).get(v); } public static double getVal(Planet pl, Variable v, double tdbJd) { return getFunc(pl, v).v(Ephem.fromJd(tdbJd)/10); } }