1. The programming steps to get a planet’s position
1 E' h1 h5 O1 n! V/ ~6 s# L# ~To compute a celestial body! H8 {" |6 n8 r5 y
or 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.
" C/ |2 U" t. U- h X7 X
) ?1 Q" o/ [: Z( P; D1. 6 K2 ?. _$ q2 ^$ ?% _
Set the directory path of the ephemeris files, e.g.: # u/ | B, s% H" Q1 j6 e
, k2 I4 I6 I+ p3 O) L0 S$ f1 p
swe_set_ephe_path(”C:\\SWEPH\\EPHE”);1 B, z6 e1 Y- ^& E* e& P6 g% N
/ A7 V) E- I* D' C5 K$ V
2..
# r: R9 H) a/ i4 v1 mFrom the birth date, compute the Julian day number:
* M q+ t6 F2 v6 N5 W) u7 J, z% p h- z( f- x% U5 Y
jul_day_UT = swe_julday(year, month, day, hour, gregflag);
w' q) k2 R) @/ I; d ; y' m+ }* c- j3 S5 _/ q
3..6 P3 |7 s1 K; u8 f& j
Compute a planet or other bodies:
( l4 ]& N4 B- u' M6 ~3 J1 Q4 s: B: n7 d5 c
ret_flag = swe_calc_ut(jul_day_UT, planet_no, flag, lon_lat_rad, err_msg); & @" b3 N5 w( Y7 h! g
+ o' v% k; E! q" x$ h8 n6 T' w
or a fixed star:
9 A! ]2 E. n2 ^$ X# Y5 t5 s0 Y/ G
6 u5 ]2 ^* S" o- xret_flag = swe_fixstar_ut(star_nam, jul_day_UT, flag, lon_lat_rad, err_msg);
* z+ }8 Y/ w/ ]+ Z
, t1 \' N; Q/ ^( H. C6 ~# V& c5 y+ v# w
Note:/ M* T* G9 M7 l) ?# X1 _
5 D% w. V0 J- C* u' k" c* G( u
The functions swe_calc_ut() and swe_fixstar_ut() were introduced with Swisseph version 1.60.
! o$ z: V5 R# c0 ^
+ }% H+ ]5 k7 t5 aIf 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:
! q2 S7 W! w9 u! S: P# X9 { & g- G, W& n1 W! Z n7 G, C
?# }& ]4 h& v
First, if necessary, convert Universal Time (UT) to Ephemeris Time (ET):
1 V2 X, C+ w- J
) q7 Z/ U# Q6 L8 Xjul_day_ET = jul_day_UT + swe_deltat(jul_day_UT);: x. }- Q E7 Q: B, E
% c! l s9 k3 X8 K
. Z0 C3 @. g; P2 |0 [" LThen Compute a planet or other bodies:
& l S6 U5 y* H: L% o* k# l
( i' { }+ Y1 O1 `ret_flag = swe_calc(jul_day_ET, planet_no, flag, lon_lat_rad, err_msg); ; B; {0 y- _ V4 I) K7 r2 v
# d, o) [3 `, \* r+ ]/ |: Aor a fixed star:9 {# {1 v* s5 Y" o
6 a: b/ d7 Z( i, `4 e% _ret_flag = swe_fixstar(star_nam, jul_day_ET, flag, lon_lat_rad, err_msg);3 I& [6 ~7 F2 i( T
/ @1 q+ R' N9 H7 v- G
5../ M7 o! n+ o. }5 W2 Y
At the end of your computations close all files and free memory calling swe_close();
2 {6 N& a, P9 }" D3 ^: j ! C2 j5 x) y& ~$ w
Here is a miniature sample program, it is in the source distribution as swemini.c/ d1 y6 D# M/ j a
+ O9 z0 _$ _1 \7 ^
#include "swephexp.h" 9 T7 H: R/ A& H& r* z9 \
/* this includes8 F# R2 ^2 c2 o( z5 I
"sweodef.h" */# v: S6 W1 G, l! E: l G, z( R
int main()
6 i6 E, {# V2 X3 f{- f8 Z/ v1 Z! Z7 s! ]8 T
, u0 C3 i, E* j) [7 s& X$ Nchar *sp, sdate[AS_MAXCH], snam[40], serr[AS_MAXCH];! ? I1 Z" r, I
: H8 v$ W" b1 G3 B
& ^6 S( O! }; G' v1 ~- f Vint jday = 1, jmon = 1, jyear = 2000;) J/ [# g0 G; n
1 q( @. q) h, A X$ B0 }
double jut = 0.0;
# }+ S7 H% Y0 O; a3 x3 \
7 k6 w/ F1 o4 _' w8 b7 ? `double tjd_ut, te, x2[6];
+ B, Z/ X6 U' _$ L: W# `2 S# v# O7 p6 L) P
long iflag, iflgret;
0 d) E$ I6 q; `& f+ `: I0 b( B
( R$ m. ^% d* W, bint p;
% r* A, M$ J* V( s3 a5 N. l& x9 ^3 |" M e' D1 o; u% B
iflag = SEFLG_SPEED;
6 Y h9 y" b' F6 P B' \0 T; k/ q0 u
while (TRUE) {
4 m0 c. e7 U3 q$ _, c8 J" ]
6 ~* w$ O. S# d5 ~& p/ Hprintf("\nDate (d.m.y) ?");
. i7 T8 h8 o" L- k- O/ |# \" E2 [& s6 y, Z% P: _3 A" U
gets(sdate);5 {# c5 n, }1 `; z& _" u
/ r4 v$ S/ I& ^; S" w, {% ?1 B/* stop if a period . is entered */
! P V0 ]0 ^' |6 W" Y+ l* l8 W: Q; Q# E& H, L
if (*sdate == '.')
/ v1 I' Y4 e. T1 R3 {, P0 }" z% ?5 I2 ]0 }2 U# y7 u
return OK;% O, R" I/ ^5 y- U: P5 s8 X
9 N L, O l" z ^( p8 s! M
if (sscanf (sdate, "%d%*c%d%*c%d", &jday,&jmon,&jyear) < 1) exit(1);: y- h8 Q* @/ p4 L; p: e0 ?
& h" ^5 l- ]+ j, Q+ H% v
: p- `6 s) A' I T ]/*. J7 z1 m; E- `& y. N( |; `; Y
& m4 s e" S3 p2 a+ s
, l1 L5 N( t# m) r0 T0 W4 E3 a# m* we have day, month and year and convert to Julian day number8 u8 Q1 Z6 E# @4 B2 P
/ ~' v" s4 \/ j0 w1 j) Y2 x
! X$ _# Y+ ]' [*/
- l: E0 y- J# P- A! J s/ j; R$ z9 `, u1 ?3 V, N$ C9 M
tjd_ut = swe_julday(jyear,jmon,jday,jut,SE_GREG_CAL);. c% o" G: }( t& `
$ q4 C% d- M- V6 v5 ?: q G
7 B7 n/ U8 A! L: [7 E% ?7 o8 N5 u
0 T3 ~9 \- s" Y2 e' q
/*: ^. \0 X/ \% U. i, E0 d; `
2 }- {& k( l, c2 e& L- ?; A
" c4 G v1 }5 g0 F: c* compute Ephemeris from Universal by adding delta_t9 N; G+ |; T4 ^8 [
+ ?/ c% [; E; J( R6 `3 ?, }( v
' O- P7 {& `; s; g# I* not required for Swisseph versions smaller than 1.60) k; `" ^% c' W0 a. O
q O" X0 r9 E
2 @$ o: k4 Z; b% \# ?7 w
*/
* H: |: f* r- O* N
/ E* K. B: Q# Y$ s% j/* te = tjd_ut + swe_deltat(tjd_ut); */+ Y' U9 |6 B$ t2 Q0 p3 }, _, d
" X" E, A/ z% n
printf("date: %02d.%02d.%d at 0:00 Universal time\n", jday, jmon, jyear);& h# q8 u2 T' s
# ?- O' X: k" L# c7 i. c, k+ Aprintf("planet- i+ _- g7 ^, }+ v
\tlongitude\tlatitude\tdistance\tspeed long.\n");
! d% N. J9 C4 |1 i, N# A7 n9 T
; r3 `. C& B, t9 k% _
' V7 A. u5 E" P% {9 d: y7 ]! C) A/*
$ r& O: \* P$ h v$ l9 v# i/ j& O" t" k0 t" r: M5 o( k( B' c8 p" d
+ K m, g; {) S; K1 u7 h0 w
* a loop over all planets
" F) h' n3 w% C
. ~* Y' r/ H; [& |. N! }1 g. N, }. O( @+ ^; P# Y
*/+ p& B' Y' ?$ f1 \
% H, A* g2 c$ A7 [! s: j3 v/ tfor (p = SE_SUN; p <= SE_CHIRON; p++) { Z& P8 x& s5 a% O& i: ?
$ c" }, ^4 @& _0 m) @9 Mif (p == SE_EARTH) continue;
5 K+ y8 j- k* e9 |* {0 q
# k& L+ r6 c( \* b; v/*% g4 r& x3 _9 Q6 E
T5 G h0 l3 Z" _6 c( R7 r
( ?) G3 {( c4 e o* E, g% ^* do the coordinate calculation for this planet p
# `2 T0 k9 I0 y y% ]% y |" h# X9 u" M' G3 w: R. S; r
3 X8 Y3 Q a. F/ [
*/3 y, H, S K5 E1 E1 j& m7 R
iflgret = swe_calc_ut(tjd_ut, p, iflag, x2, serr);3 M9 g6 V- S: R* i$ N. }; {
+ W. N9 v/ L0 O/ A3 Q: D4 o+ I& j) W- P" Q5 G
/* Swisseph versions older than 1.60 require the following ! o' ]/ d' g9 [2 V
2 u, V; e; b3 o. c* V
* statement instead */
. ]) A v+ W; ^; h# s. ~) Q. M/* iflgret = swe_calc(te, p, iflag, x2, serr); */
( }. Y1 S' H p$ _. T- b1 h
& S4 X U" t5 E: R& d) a3 p% A/ U3 P1 t! t% i
/*' T. `, k, E( c. E& z
; Y& ^+ C* {6 q. ?8 M' U0 y1 h
: d6 N5 U' R$ F" Y, N* if there is a problem, a negative value is returned and an
2 P: d: W3 s I8 a( Y) O, U1 b5 q+ Z) ]9 b9 m9 @" U
, {+ U2 I" R5 i- @) m5 S7 T
* error message is in serr.5 d ^4 l* y S5 q& c4 M
3 Z1 n! p' M1 I' o- P1 t" @" I* i1 O9 n# [/ C1 `
*/
; ~% b4 k, ]7 u+ j/ h4 p
y. X5 ?0 i. [ N8 eif (iflgret < 0) , d; ]# r- n! a: Z
; h" G6 p5 d$ s# } W9 m* Nprintf("error: %s\n", serr);
7 s, R* B3 M! w& u5 {) l
9 \9 r$ a0 B& b$ H+ Y/ d7 w# c( ] ^3 c- R* b" M, q& a
/*: C* `7 G0 ?* }4 q/ E' f
2 X3 F; Y: }( d, T* W' q. ?
8 B9 J% A; F/ r, _7 S
* get the name of the planet p# ?' z$ \( J8 q$ G" B
) m% W6 K/ _4 Z6 h1 J( r1 E
5 j/ m+ h8 {% h) V3 M*/3 K& s( e5 N. U1 R! s W: c1 `
( v5 p E# j% V( Y/ Rswe_get_planet_name(p, snam);4 N9 M8 H7 t' t T
; k* w5 o! ` N2 ~4 N: u. C9 t" q. R6 R/ z& w' I
/* p5 W L% P& t/ T1 D) F' q3 Q& a
3 M. l# Z' f o
) f% D; J2 L" {$ q0 w% s
* print the coordinates J& s: @; c- w; I- `! @ c
9 e( b/ A' y; A
2 D* |4 x- A6 M) Y7 n' X*/
8 w4 i6 o; @% G9 @. Z
5 }6 \# J9 e1 Y; @, A9 kprintf("%10s\t%11.7f\t%10.7f\t%10.7f\t%10.7f\n",0 ]1 Y% \" j' ?% {$ h" C
: B$ y7 H% ?( m2 Z" N& t/ q5 X+ C& h: U! m
snam, x2[0], x2[1], x2[2], x2[3]);$ Q6 u& u/ e4 W% x0 {2 A9 k# a( Z
+ H( B9 f1 S j! @/ x* O. w- a; s}) ~2 n5 g8 {. S1 u I' X B
" J5 k9 S' C5 }$ I
}) g5 m! W8 r7 f+ P- Q# S7 h
& E9 `+ u. y- m2 M6 E6 B$ t; e
return OK;. Q! T5 C% G7 V2 x% z
} |