summaryrefslogtreecommitdiffstats
path: root/org/madore/ephem/VSOP87.java
blob: e8a5fb192a43ca6baf9de4c42f4f432adc9e5225 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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; }
    }

    private static EnumMap<Planet, EnumMap<Variable, Comput.SumPoissonTerms>> data = new EnumMap<Planet, EnumMap<Variable, Comput.SumPoissonTerms>>(Planet.class);

    public static Comput.SumPoissonTerms getFunc(Planet pl, Variable v) {
	if ( ! data.containsKey(pl) ) {
	    data.put(pl, new EnumMap<Variable, Comput.SumPoissonTerms>(Variable.class));
	}
	if ( ! data.get(pl).containsKey(v) ) {
	    List<Comput.PoissonTerm> series = new ArrayList<Comput.PoissonTerm>();
	    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]);
		    double c = Double.parseDouble(fields[3]);
		    double phi = Double.parseDouble(fields[4]);
		    double om = Double.parseDouble(fields[5]);
		    series.add(Comput.PoissonTerm.cphi(deg, c, phi, om));
		}
	    } catch ( Exception e ) {
		throw new RuntimeException(e);
	    }
	    data.get(pl).put(v, new Comput.SumPoissonTerms(series));
	}
	return data.get(pl).get(v);
    }

}