The programming steps to get a planet’s position
- G) S7 M/ n* uTo compute a celestial body
, A0 C4 U% W: Bor point with SWISSEPH, you have to do the following steps (use swetest.c as an example). The details of the functions will be explained in the following chapters.
3 q5 [- A6 `9 m( j( B5 { 6 \7 p+ k7 J3 `& I, V' F$ D
1. 9 S; K! Q* |; X, b$ N/ L7 V# [
Set the directory path of the ephemeris files, e.g.: & b8 H3 B/ H- ]5 b0 @
0 r" J0 ` B4 U' R5 z: |; qswe_set_ephe_path(”C:\\SWEPH\\EPHE”);
' o: \. E4 d, Z5 W. |9 N
% a/ A; e+ H6 {6 D! u4 \" O2..9 i- q! _5 V' l, v2 _8 J# a+ s
From the birth date, compute the Julian day number:
& g& m9 j6 [' y+ g7 A6 M) }/ a- h9 ^+ n9 K# l% m! ]& n: y6 y
jul_day_UT = swe_julday(year, month, day, hour, gregflag);
' e3 j0 ~, E3 J% M % U" ]* X+ W+ o
3..
7 o& D# K4 ?6 _Compute a planet or other bodies:/ e5 k% q9 ?& N( h( E* y- r5 B0 h0 F
, Y% q8 x l. f- qret_flag = swe_calc_ut(jul_day_UT, planet_no, flag, lon_lat_rad, err_msg);
+ _3 y/ p% V6 S$ i, W! C3 K8 w6 u4 k& n$ L
or a fixed star:' C, x5 S1 b' d9 c6 M j
" A1 }, y$ `! S- v1 ?4 iret_flag = swe_fixstar_ut(star_nam, jul_day_UT, flag, lon_lat_rad, err_msg);$ M/ k, B7 L9 ~- C2 A. u) e
0 R' t' i: C# ^* e) o* ^! \
# J8 n7 e; e& c5 |
Note:
2 v ~0 M+ @3 W# f; y. f& O+ s+ {+ f5 n5 Q7 U+ |' ^9 g
The functions swe_calc_ut() and swe_fixstar_ut() were introduced with Swisseph version 1.60.
1 G2 x `) a' z O
8 Q# r0 Z" Q, e5 s _2 P7 ^2 qIf you use a Swisseph version older than 1.60 or if you want to work with Ephemeris Time, you have to proceed as follows instead:
& A' P# m$ Y. V/ q5 S6 Z& M
8 u! ]( L4 c2 T# X
|# n* M2 ^6 M$ D% IFirst, if necessary, convert Universal Time (UT) to Ephemeris Time (ET):2 w( j2 R* `1 b: P- B
$ q. `' z( B& r7 `
jul_day_ET = jul_day_UT + swe_deltat(jul_day_UT);9 O( j, y0 }3 f: l2 B( p
$ O( l: q1 n L- c3 t9 y. C3 v2 ~6 s y$ Q d7 B7 w- T* r
Then Compute a planet or other bodies:8 f- {: h% d! P' j. Q2 O
6 x. U- l- t, B* j" Kret_flag = swe_calc(jul_day_ET, planet_no, flag, lon_lat_rad, err_msg);
, S! m" }' A. I7 }: p
" u' p$ x' x. Qor a fixed star:
3 H( v; G+ d! C( J. b. l# v) P1 \1 R& [8 J& ^
ret_flag = swe_fixstar(star_nam, jul_day_ET, flag, lon_lat_rad, err_msg);
/ [0 f- c" s. ~# i% P
9 L' \1 `& \/ K6 u" ?* g5..
, V. v. _4 R3 H: X9 Q; u. T! P" V/ zAt the end of your computations close all files and free memory calling swe_close();
& V% Y. ^6 ]* Z& |6 Z. i $ |' b9 Y W8 T
Here is a miniature sample program, it is in the source distribution as swemini.c& N; S* ^# o- o- `% p
* O* b5 t2 w% t7 ?# H6 A: f% J#include "swephexp.h" z4 a( h3 Z5 w/ t0 c4 c! |$ {
/* this includes
: P4 s- N8 n0 G2 J% U"sweodef.h" */: }$ ]6 A; h- F- f# i
int main()" n" V$ }, ^5 l" T, I, \/ z. I
{
2 E- z* d: M+ |9 b, r
N+ |+ c/ W$ h4 C' m \+ Gchar *sp, sdate[AS_MAXCH], snam[40], serr[AS_MAXCH];
5 U1 {$ v" n t8 n2 C5 k# Y
# y; _! k" @/ |& X
# j8 p/ t6 R) _4 l9 ^int jday = 1, jmon = 1, jyear = 2000;
( w t* @" p* L: Y* D. g) { B' _6 q4 y2 |" Q y4 {
double jut = 0.0;: B6 ^. k2 P3 j% q/ D! k
`! n% W+ x9 } {4 k: ^double tjd_ut, te, x2[6];+ |% v s9 w2 H6 m3 b
: k4 A, E: N5 Y# G+ f) W' b1 `' f
long iflag, iflgret;3 f: v; x2 q6 a' i6 C9 R3 B/ h a( \
z3 l0 E6 W1 m- _& g! k2 Wint p;
' a' S) D/ u* e& p7 a! c6 |4 R& D
4 `: O2 d% G q ` U4 Niflag = SEFLG_SPEED;
/ e" y) R) ?+ t4 M: }
$ ?& Z6 w5 \( d0 ]" u4 Zwhile (TRUE) {
, b( _. X. f8 J4 W! O ?0 f/ y+ c. s- w
printf("\nDate (d.m.y) ?");* r( I, U$ p. B6 @* C
/ S. J# V- H7 V- m% g
gets(sdate);3 M- \3 n% O0 Q- }
, Q/ r9 F: e, I# I. w/* stop if a period . is entered */; Y. b8 u* E/ g4 p( L2 u( @3 U
/ \ P; u: D/ x6 b5 ]
if (*sdate == '.')
! Q$ }, v3 @6 n' `
* y; R) ~) h5 Y4 k+ J8 Mreturn OK;
5 V' B5 @9 y. H# G- P& r( O8 C
% j6 R7 |; G W9 I) O! Mif (sscanf (sdate, "%d%*c%d%*c%d", &jday,&jmon,&jyear) < 1) exit(1);
, F; o& L4 C2 U& E6 e. T- l* _ U% P5 Z. F8 q! e9 o! w8 V
& \# k' |" U3 {# T3 [/*
/ a1 b* ~. V& F* V: l' t( ?" q3 K+ t4 G" B
7 v. d7 S0 {7 }" e' k* we have day, month and year and convert to Julian day number9 A3 \ K/ @+ U, y7 H0 ]8 E8 F
1 O3 C" R$ q* l" j. F( Q
0 D4 t' W/ x7 f1 G. q2 C- D*/9 f0 H, }0 ^& H$ d, d9 y3 R
6 r8 z! S$ `% ]1 H! m4 Ntjd_ut = swe_julday(jyear,jmon,jday,jut,SE_GREG_CAL);
8 t1 `9 h9 w; c2 h: f. T( w t* \. \( }, {3 e$ ?& ?
; i' B/ Y9 N% _2 ~% U: E& l* B1 \1 Q' M/ M1 c
/*% c0 y; V/ {0 u% D
! S* M% n/ C: @8 o$ A/ D% u- @
. w1 q# |6 J0 K9 N" W8 Q* compute Ephemeris from Universal by adding delta_t
) P% z, F$ ?7 a& Y2 D- g3 E1 ]. u* T, ^8 G I- ^
$ h. q% I' G9 [+ S6 A
* not required for Swisseph versions smaller than 1.602 Z' v. b& _4 L8 o0 Y9 V
6 I9 ]. h0 ]# R5 @. ?1 O* M; A! O& F
*/; m, \+ ?# {0 n& H" N
2 K: O% ^9 n9 B" Q. d* v
/* te = tjd_ut + swe_deltat(tjd_ut); */# Q% `3 f' g: q* `2 b/ t: D' F
: G1 \: U3 a& ?* f1 Yprintf("date: %02d.%02d.%d at 0:00 Universal time\n", jday, jmon, jyear);+ G* P& r( |* k7 n& i
9 r- s4 f! T5 e" Iprintf("planet
# \4 A5 \" z! F* K, Y$ I\tlongitude\tlatitude\tdistance\tspeed long.\n");3 e1 E( Z3 E ]" u; u4 V. G
$ J8 A. \+ l( f- y6 j5 n" Z! H, x# a$ c3 S" T
/*
# J3 J6 B, k' j
0 d0 x3 ?% e3 X
/ n0 j+ Y: E' B1 L* a loop over all planets
, M X" D5 p3 \' x" n5 @ T2 b o0 S% Y! T7 ]% O0 Y. k- R' |! ]0 o$ L
) q- g% u( s. U1 g* p1 V, ^
*/
3 |. o; ^. }7 i V' b' N! c) H L! s9 u5 ]2 H% {8 w9 {
for (p = SE_SUN; p <= SE_CHIRON; p++) {
7 a& k1 [+ A/ e9 G3 T6 H: y
3 s; p1 ]* W% Z. qif (p == SE_EARTH) continue;2 Q. S" y' h" V+ U5 h" y: S
! N( ]5 Q" }1 M/*2 N8 u$ [/ s4 ?( h1 O: Y0 k
9 q* e0 h; j. Z1 y
# L/ u e# u3 Q) C9 r' q
* do the coordinate calculation for this planet p
" l1 C( r. V2 M' N
4 f+ `5 ]2 W* g; N4 {" {5 ^) a5 B& a' Q- d& }3 _* a
*/- J7 k3 ]' c i/ E5 p; h& B9 D
iflgret = swe_calc_ut(tjd_ut, p, iflag, x2, serr);
3 N6 p0 ?0 x+ ^; K8 i7 W5 r5 ~4 g
2 G' d3 W$ z) P: k% D* j; _/* Swisseph versions older than 1.60 require the following
" V, P) e0 Z: J; _$ `8 {1 Q
6 r2 U k F. N) u* statement instead */% N2 y' H! N. C, j5 h
/* iflgret = swe_calc(te, p, iflag, x2, serr); */2 L5 d) r) ?" Q6 ~" c8 O' {+ Q
, p4 j) P5 N# u/ x" l, X
/ s, d0 B2 U* n; S& Y9 n8 O
/*7 I& l9 h h7 w' V" x
8 E4 A9 s9 ~) O) T, B4 q. q. Y3 j3 A
* if there is a problem, a negative value is returned and an
5 V8 Y [+ Q7 Q' m- S. O3 R! M: b* O$ u6 U& L& [" a! R
0 U( R% I( q1 H* R( M0 X; k* error message is in serr.' x- m. _: i$ d% A- u- S+ t
; T$ _! l2 G9 Q* q4 W
. s( }9 t; w; Q8 l: ^# Z7 }*/
' V- t, Y/ E' |+ f, {. U$ z: x7 R% O1 N8 F$ Y4 g
if (iflgret < 0)
5 _+ t- ]9 l! u& R: E& v
5 @! D% Z- T# bprintf("error: %s\n", serr);/ O+ ^' i K, |0 r
4 f) s' ?- {8 ~+ b+ E9 q& [, w) F) u. N/ h
/*
! [0 H9 T' a. c e' T3 W1 M. R @, X9 N: L9 B0 k
' k8 _" I% q! c& y. |# K* get the name of the planet p
) u. c2 \+ S8 s2 d* U! ^. h
: t c; E2 X) f+ L
& a2 F, P2 x. y" u/ j*/
1 }4 ?+ H2 F& J7 H4 s; O3 u+ T: e' |7 N% L0 V/ j7 B; i8 F1 i$ T6 p
swe_get_planet_name(p, snam);
- y# |6 \ o# r) M' M
8 s i2 }3 x1 S7 S& }0 n8 g
/ a" d: i! \7 s1 W. i6 b/ a9 R/*
& z/ g4 I; Q( \4 A4 G% L6 m6 V. X' V6 `4 s% K
! L0 ]+ ?% \; Q* [+ `/ E. s+ {4 }
* print the coordinates# Q: R5 z7 H3 Y* V( M
0 u. L4 e$ f: o2 P2 C! W* }2 |) H7 G
*/
! q# Y, b. h3 L4 Y/ D# I& P5 J3 X
# { G0 o& l1 P5 y: O( Fprintf("%10s\t%11.7f\t%10.7f\t%10.7f\t%10.7f\n",6 U! y1 y& t; w. m. l9 [
, b" ?6 t- t$ t6 |$ n) F8 C+ X4 ^8 m6 m2 B
snam, x2[0], x2[1], x2[2], x2[3]);
# Z. S3 x) t. i0 ~+ }
7 d' n6 S% ~7 N7 A0 o}) {" [( j! M6 }! p" J
! g: o) \! y* w9 e}
4 i, Y# [5 I% r; G2 q9 z- O* J) Z S& w4 x( l+ j5 y7 A3 y
return OK;7 y2 d4 z4 v# m3 g5 F6 r6 H
} |