-
Notifications
You must be signed in to change notification settings - Fork 4
/
body.go
119 lines (95 loc) · 2.71 KB
/
body.go
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package novas
/*
#include "NOVAS_novas.h"
*/
import "C"
import (
"log"
"math"
)
type bodyClass int
const (
clSTAR = bodyClass(iota)
clPLANET
)
type Body struct {
class bodyClass
object C.object
cat_entry C.cat_entry
name string
}
// Information returned by function (*Body) App(Time)
type BodyData struct {
RA float64 // Right ascension
Dec float64 // Declination
Dis float64 // Distance in AU
ELon float64 // Ecliptic longitude
ELat float64 // Ecliptic latitude
}
// Information returned by function (*Body) Topo(Time, *Place, RefractType)
type BodyTopoData struct {
Dis float64 // Distance in AU
Az float64 // Azimuth
Alt float64 // Altitude
}
type RefractType int
const (
// Types of refraction correction
REFR_NONE = RefractType(0)
REFR_STANDARD = RefractType(1)
REFR_PLACE = RefractType(2)
)
// Get the name of a body.
func (b *Body) Name() string {
return b.name
}
// Compute the apparent place of an object.
func (p *Body) App(t Time) BodyData {
t.update()
data := BodyData{}
var ra, dec, dis C.double
switch p.class {
case clPLANET:
if err := C.app_planet(C.double(t.jd_tt), &p.object, C.short(Accuracy), &ra, &dec, &dis); err != 0 {
log.Fatalf("Error %d from app_planet (%s)\n", int(err), p.name)
}
data.Dis = float64(dis)
case clSTAR:
if err := C.app_star(C.double(t.jd_tt), &p.cat_entry, C.short(Accuracy), &ra, &dec); err != 0 {
log.Fatalf("Error %d from app_star (%s)\n", int(err), p.name)
}
data.Dis = math.NaN()
}
data.RA = float64(ra)
data.Dec = float64(dec)
var elon, elat C.double
C.equ2ecl(C.double(t.jd_tt), 0, C.short(Accuracy), ra, dec, &elon, &elat)
data.ELon = float64(elon)
data.ELat = float64(elat)
return data
}
// Compute the topocentric place of a solar system body.
func (p *Body) Topo(t Time, geo *Place, refr RefractType) BodyTopoData {
t.update()
data := BodyTopoData{}
var ra, dec, dis C.double
switch p.class {
case clPLANET:
if err := C.topo_planet(C.double(t.jd_tt), &p.object, C.double(t.delta_t), &geo.place, C.short(Accuracy), &ra, &dec, &dis); err != 0 {
log.Fatalf("Error %d from app_planet (%s)\n", int(err), p.name)
}
data.Dis = float64(dis)
case clSTAR:
if err := C.topo_star(C.double(t.jd_tt), C.double(t.delta_t), &p.cat_entry, &geo.place, C.short(Accuracy), &ra, &dec); err != 0 {
log.Fatalf("Error %d from app_planet (%s)\n", int(err), p.name)
}
data.Dis = math.NaN()
}
var elon, elat C.double
C.equ2ecl(C.double(t.jd_tt), 0, C.short(Accuracy), ra, dec, &elon, &elat)
var zd, az, rar, decr C.double
C.equ2hor(C.double(t.jd_ut1), C.double(t.delta_t), C.short(Accuracy), 0, 0, &geo.place, ra, dec, C.short(refr), &zd, &az, &rar, &decr)
data.Alt = 90 - float64(zd)
data.Az = float64(az)
return data
}