The programming steps to get a planet’s position
' q+ A6 Z9 l# ]; t6 ~! @To compute a celestial body
' `3 |) T/ W; k# t' Zor 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.
; M( C. R- g8 S* l! S
# h" Y2 h0 P! W& C( x# w5 }1.
& y( }. ~7 _8 h; R; T: XSet the directory path of the ephemeris files, e.g.:
- V1 a6 U" X: K3 Z1 f1 m$ `& l( j1 F* S2 Y1 x
swe_set_ephe_path(”C:\\SWEPH\\EPHE”);/ u( X6 p+ V S4 H# Z3 o6 Q9 h! d
. S6 L/ V3 \$ m! t' j; E+ M, u; U& F) {
2..* |, ^) {$ d2 W2 G9 k2 _' a, S
From the birth date, compute the Julian day number:$ T" X% i# q! w& F0 b# E- y: U1 x
' B8 k5 s1 @7 `
jul_day_UT = swe_julday(year, month, day, hour, gregflag);
& K- g. M+ b' D6 M ! s5 `' R2 H" ]0 [7 |. m! b
3..7 j$ Q1 d9 h4 o a9 `
Compute a planet or other bodies:! `9 H, f* {3 j" N- x% F
! _' M( F: @( S, sret_flag = swe_calc_ut(jul_day_UT, planet_no, flag, lon_lat_rad, err_msg); ! e# p0 ~* `" h+ @ b q$ [; g/ W
$ \1 k0 w3 M1 F* O; s; Qor a fixed star:
8 _/ d/ C& @8 J, Z7 x5 F
& J! D9 \# z& ?& V1 aret_flag = swe_fixstar_ut(star_nam, jul_day_UT, flag, lon_lat_rad, err_msg);
1 d/ U( R6 f3 Z4 \) T8 B" }
f$ D) P& M( B4 e1 c0 q* ~# J8 o& N' K1 N
Note:6 G1 i- W. Z4 c, S' r* X
3 v( d: ]: k4 b, |
The functions swe_calc_ut() and swe_fixstar_ut() were introduced with Swisseph version 1.60.
; a' l) A$ [, ^6 h3 r9 n( K2 _ C. E. w
If 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:0 P+ o6 o4 A4 o7 a/ P D5 B
" T P0 h) G4 L) a* Q1 t$ I- Y8 g. ^
First, if necessary, convert Universal Time (UT) to Ephemeris Time (ET):
: F O( _& |1 b+ g
( v" o$ y4 [: B+ vjul_day_ET = jul_day_UT + swe_deltat(jul_day_UT); ^* o, @) }, t8 D7 W
4 ~6 i7 }3 Y! b/ b' n1 ^) M2 }/ Z7 d
5 |+ x% i4 w, S/ [2 JThen Compute a planet or other bodies:
8 {; b* `" u8 Y5 a
q D1 B7 A6 G( W3 V1 ^0 b9 k. kret_flag = swe_calc(jul_day_ET, planet_no, flag, lon_lat_rad, err_msg); 9 _2 X2 @$ R& a" L x7 R
: Q2 v" l2 `0 ^+ Y3 o' _0 k
or a fixed star:
5 f* Y( \" j" h2 M! y, q, b6 e1 D. R7 b* R6 n/ ^9 D X8 h
ret_flag = swe_fixstar(star_nam, jul_day_ET, flag, lon_lat_rad, err_msg);
5 k. Z) D! \2 a# R# O- l8 H+ c
8 k8 t; t3 b' G5 p7 S5../ n- b( Q: c L( h1 u
At the end of your computations close all files and free memory calling swe_close();( C& E' V0 b0 [+ E3 @7 J4 y) |. }) Z0 g
6 g* j9 a" z8 H) \Here is a miniature sample program, it is in the source distribution as swemini.c2 ~5 e; |8 } g, n
4 K! P5 r$ s8 G) B9 d#include "swephexp.h" , A0 t8 h- ^" {: g$ N; U' ^
/* this includes
/ G1 `: O' Z3 [( J3 I* X"sweodef.h" */
! s& U' t- y: n' O2 V3 iint main()
' n: e+ M c0 d) B, d! n1 g{, g4 [) F$ j$ y7 ]' w$ l$ r
U4 ~; S# ]( t8 S" _3 A
char *sp, sdate[AS_MAXCH], snam[40], serr[AS_MAXCH];7 C1 D# p: f7 e' R& m$ i
. j0 y; O1 k# z. j5 q. j% r
$ |( C% b: G, b# ]( A% |int jday = 1, jmon = 1, jyear = 2000;% X" i5 r' s, K7 `
4 _0 A7 B. M( q8 H, x. u
double jut = 0.0;$ j, |! ]4 k* `5 J% z% P5 n
0 F' m! C0 R$ l$ w9 I2 `double tjd_ut, te, x2[6];! }0 _9 C% }" v" L' H5 b% ~+ n
! g' h- x/ m3 Y3 D* L! f, Clong iflag, iflgret;
0 ~$ b) r. K/ w0 v/ G- ]$ [# o0 {( u9 o, ^
int p;
8 r$ I# X% ~; l; j) z0 `
2 _9 M4 P+ b( _) Piflag = SEFLG_SPEED;6 a0 ]1 P! `$ S A4 I2 h5 F6 B
) G3 x. A+ e) i4 a
while (TRUE) {
* w* u8 e) |7 Z( L( A0 Q4 F
! E" L, B: H8 @7 S. o1 b9 fprintf("\nDate (d.m.y) ?");
: r. R+ [3 K3 O8 ?8 g6 B: E) D7 B' D9 r2 a2 b7 \" a' y
gets(sdate); z" `# z+ {1 P1 K% z* E6 r
5 {2 h1 l+ g) Z
/* stop if a period . is entered */
/ f2 w, b2 O& J9 M( D% b2 U6 D) ~9 c* T3 d* [
if (*sdate == '.')
$ S4 q- D# V6 f' u# }! Z% }6 N, G* P1 Q6 \
return OK;
3 D* \5 L5 F% T, `2 ^7 t. F0 r$ k: {# @7 m5 j3 Y* a
if (sscanf (sdate, "%d%*c%d%*c%d", &jday,&jmon,&jyear) < 1) exit(1);
0 j" \# X+ S5 H$ q
0 j6 E6 l8 |. M% a, |% j8 } x" A0 M
/*8 R# ]7 B' N9 J% Y
5 m2 V- N# T0 Z c6 w( k
8 W7 o3 P2 \7 h Q* we have day, month and year and convert to Julian day number" |2 F/ g% j( S1 m% z6 E
" J m' L- T& @$ p8 Z9 _0 h0 M5 j4 b: [
*/* h, O1 z; U# Q- V8 V0 C
- {8 I1 R @' ]$ O% ~+ A3 D$ U! h+ e
tjd_ut = swe_julday(jyear,jmon,jday,jut,SE_GREG_CAL);( d1 n; z6 Q) e* Q: z2 `2 m
: y3 c9 ^: m" P6 t% j/ h2 u
7 H9 G' P8 q: x# K7 c
) |- e2 O r$ `# o6 P! J/*: H0 T: f5 U$ q2 C
" W' b# a8 Z- I% g/ D, W
5 Y% i, O* k0 [! W! [3 e* compute Ephemeris from Universal by adding delta_t
3 }: E {' I% F
9 x( }% Q: r- I; V/ @3 ^
& a+ A* }" O: z. ^ G* not required for Swisseph versions smaller than 1.601 a3 r3 x5 f' X: Z/ d/ { f5 ^3 z
" [+ O% Z% f( N1 q( m h6 {3 Z' O$ U% y! @
*/
/ Q% A, H+ i/ K+ l$ U' B: _6 {& N
/* te = tjd_ut + swe_deltat(tjd_ut); */
1 ?5 b# l$ A+ D! X
3 T! V. N0 ~$ i: u' w: |! fprintf("date: %02d.%02d.%d at 0:00 Universal time\n", jday, jmon, jyear);
7 ^+ |% z: a0 \) ~
; P# |% M# @! x& l* i' Vprintf("planet+ C8 s6 g! Y0 N* W% i9 f
\tlongitude\tlatitude\tdistance\tspeed long.\n");
^; q8 v" Y0 [* ~' b5 i. U6 a+ D6 p
% S k q& Y* c1 g( |
7 k' ]; C4 ]( _+ B/*
6 N: u5 b% ^0 K9 _- B! ]' [: B) f; o
8 R) [) R. u- l+ X# c6 w! q* a loop over all planets: A B* S4 o8 {: s" `
, ^- b8 b+ J5 X
9 |) c2 s" A7 U" R' k" Z
*/- x9 ?% a: w- p* m- p! F5 f; J
7 m3 [0 i; j0 n2 h# g4 j
for (p = SE_SUN; p <= SE_CHIRON; p++) {: a% j7 ^3 ~3 G3 @# A$ E
+ g2 y8 L8 @4 M5 Kif (p == SE_EARTH) continue;% S, r' Y! E" B0 A2 M
9 F- R( x* C2 U9 h
/*
: p/ K% R' q- ^( m9 [! Y" L
! |0 x' u/ t/ s& G" R" r- U2 N& j" T0 ?; I. `/ X# Z1 W1 h/ A3 ^
* do the coordinate calculation for this planet p, `. }( l9 O& G3 T0 H* S
$ Y2 G8 Q2 a- V1 f+ G9 j
9 l, U8 ~" `5 F/ L7 f: e" q*/; _4 Y, ^0 L% v4 v* |; R) ?
iflgret = swe_calc_ut(tjd_ut, p, iflag, x2, serr);
3 f- [2 ^4 g/ v# Y& V* f( X" t. T- w) W8 D1 f9 r
( y* k' ?6 T: q; ^" W' H4 }% Q; h/* Swisseph versions older than 1.60 require the following
5 T! W) K0 m4 p# U0 P c, h! P
0 Q$ ?2 J6 L" g: Z5 C* statement instead */
, \7 t; T+ G6 [# Q3 u9 w j" K/* iflgret = swe_calc(te, p, iflag, x2, serr); */
5 i/ ? T8 C7 u( F J* d3 m @/ m: g b& J6 I. k2 o1 {
( T! A1 D( v$ x, H# T" i( K/*9 K2 ]' K$ I( c& ^0 W- f
2 J/ W1 j8 i, @, t! F5 r
5 ?( ?! C* t2 u) P* if there is a problem, a negative value is returned and an * w4 V0 Q! {' @6 H3 }
; z$ e8 T8 B3 v2 Q3 N4 j$ k: z
% b c! V$ p0 h$ S7 a* error message is in serr.
, v9 k. j+ V9 ?7 W: N _
, J0 Z. i9 Z- v9 T0 k
& ?+ r0 f' L! i5 u" M6 m*/
+ }9 I7 D# z* U! a6 P2 C" {, x3 } I: ]+ @" A
if (iflgret < 0)
) b2 m1 l& J& ` m
! A& D/ w5 H2 r1 C4 |1 r: i( w2 ]printf("error: %s\n", serr);( v$ ?$ x! K5 |, J$ ~
' u9 e5 D: K3 P; ?& b& F3 M. d6 [: r- n+ r8 r0 t7 l9 Q5 s0 m
/*
4 @% @) q* \$ P* G) _- k
u! p- a3 }1 }0 K. n- _0 Z7 ^4 F
. T0 T9 A b$ m# L$ c$ q8 n- M* get the name of the planet p
( ^7 x- _$ J; u/ A% v9 h9 D/ t' n) n; Q0 H, P
2 S+ ]. h7 L, s$ R% l
*/0 ]; J6 c1 `- @) v# g. |6 k
6 K: {7 M8 \6 i: ]8 g1 wswe_get_planet_name(p, snam);
& u; ^3 k/ x3 V7 u" g# \
8 H; ?! Z+ K5 X0 {/ z3 ], z6 O' y( j7 K S1 `; A3 v! H
/*3 ]( V& F: M) l9 @" w2 o# i
/ H, m, G! S+ D8 l/ Q6 F3 P
& q6 T' q5 [6 |- F2 V* D1 N! M* print the coordinates
) q/ l, U( p5 r% ^% A7 W+ y* z) i6 k- H' b S9 k$ g: V1 ]( I' S
4 E3 b: i9 o$ X8 \. s; }*/+ W. ~5 R; W- u0 P
U+ w! n' H0 T* g" {& S2 J5 `
printf("%10s\t%11.7f\t%10.7f\t%10.7f\t%10.7f\n",& k5 t0 y% X8 n- @7 v% E' C
- a Z) D" k; }( s& o
1 d9 `: i! L# O8 t2 c: O1 i) tsnam, x2[0], x2[1], x2[2], x2[3]);
) B" C9 ~2 T2 e; F1 s. Q/ Z9 z, n
}6 s3 |0 V% W- ~, \
+ ^# E1 t( n$ ]+ M2 z: q}
: J. Y+ [6 b3 V& {" z! r0 `5 V' x# U$ D) h7 d2 d% Z6 U
return OK;- R3 k% u0 Z6 \' k8 V9 i
} |