The programming steps to get a planet’s position 1 ?5 J5 g3 r& W# t% g k
To compute a celestial body
) \1 r6 f5 B: g' ~6 g. por 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.2 l2 o& h& b1 H3 p7 d/ @7 A
; f) W" K' P" ]8 K; e1.
% {. B3 }5 R4 g7 d! v1 h* M3 vSet the directory path of the ephemeris files, e.g.: . S+ o4 O$ \2 Y& _# l* q0 d2 ~% D
1 ? E& E9 N( C0 l4 V' l. Jswe_set_ephe_path(”C:\\SWEPH\\EPHE”);
[ m' `7 J% E- i
* \4 I6 S: ~$ _) {0 X1 W3 l4 f2..
+ v2 x" Z: X& f& U/ @" CFrom the birth date, compute the Julian day number:# t: K$ w6 {# G6 e5 Z6 }
7 v8 Y' a* j2 f: d( h1 r
jul_day_UT = swe_julday(year, month, day, hour, gregflag);
5 V1 B' V4 _3 x 5 h6 H* V' X& Y( D
3..* p0 e* ]. }5 K3 D
Compute a planet or other bodies:
8 y) T1 N$ {' @6 G; h
. C5 k! g. y9 ~# i6 eret_flag = swe_calc_ut(jul_day_UT, planet_no, flag, lon_lat_rad, err_msg); : K/ C# @0 _6 K
4 o4 V! F7 D# F
or a fixed star:
& b# K- l% l* y: n$ X1 X8 O4 L6 h- F! n4 p9 j3 J% p, {7 v
ret_flag = swe_fixstar_ut(star_nam, jul_day_UT, flag, lon_lat_rad, err_msg);
. m' v$ G* e$ F0 H' q3 w # D p* h* [' x2 _" b% r8 ^
; g( D; d' g, H6 j" V2 Z- KNote:
5 A: K/ Z" ^% e8 _9 C) T* U2 h% a/ h4 |3 V; l9 D: K1 z
The functions swe_calc_ut() and swe_fixstar_ut() were introduced with Swisseph version 1.60.
( |7 S4 i8 i9 a# l( r- I3 Y& P* M3 x5 M4 E7 n, P# i6 k1 V* ]
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:( K; N8 {* C, r8 }* M4 V# s7 D. q
2 A# `, S: @$ Z% \5 X
' H4 r1 p: O2 V2 b8 r4 c" iFirst, if necessary, convert Universal Time (UT) to Ephemeris Time (ET):
% M1 a n* }' A4 n' ?0 a) y1 H# s9 O) R! l
jul_day_ET = jul_day_UT + swe_deltat(jul_day_UT);
+ u: W+ ?9 e9 w( j/ y$ M
# A) A/ @" j. m, M3 G b- @5 g; @$ |1 ] c: Q; G1 k7 y
Then Compute a planet or other bodies:# m" i0 t2 u, R3 o4 G% w4 C3 L/ W
3 Z1 g- I7 P8 {* n* mret_flag = swe_calc(jul_day_ET, planet_no, flag, lon_lat_rad, err_msg); / P) q7 @( V/ k {/ ^ d& Z
6 V; r) }9 V, k* c: y4 K8 v- g" e! ~
or a fixed star:
' q7 k& T6 a; J' R2 l8 T5 `* N1 Y V1 `3 M/ }$ |2 v
ret_flag = swe_fixstar(star_nam, jul_day_ET, flag, lon_lat_rad, err_msg);
3 U" v M B* Y. n/ _ , a8 h! |5 F) ? s, j0 D M1 {! Y/ `
5..
& ` p( c" t# N/ i, CAt the end of your computations close all files and free memory calling swe_close();. J n8 n2 C) i/ A, i
8 H% F0 C5 Q0 y7 h, Q% w2 o w
Here is a miniature sample program, it is in the source distribution as swemini.c
J% D3 _! H: S( D# o $ M0 L/ R7 }# C8 |- o
#include "swephexp.h"
% q/ B; c2 h( z) }+ h" Y/* this includes* ?6 h: |' P+ q: D- V: S
"sweodef.h" */2 w6 m4 y3 N; i6 R4 n- o/ e: ^* J
int main()4 s) L( ~8 d$ B2 {) I0 _
{. y) x9 d; `" g2 Z. i$ H: T; t' K
9 @- h$ z/ h* ^! ]6 F+ q
char *sp, sdate[AS_MAXCH], snam[40], serr[AS_MAXCH];
: b2 k2 E/ f2 e6 K/ A m+ T; W8 {2 G, c1 c2 P
) H+ L: t- c$ R1 Nint jday = 1, jmon = 1, jyear = 2000;
0 g: z3 ]6 B3 P7 r0 l
2 F3 {; J. _0 x5 P3 ydouble jut = 0.0;" d# H& @+ h2 a5 ?! y/ o
4 n+ J( u1 [( R: rdouble tjd_ut, te, x2[6];& H" ^1 c* Z8 f$ i" G& V
% Q) f6 a& C4 Y* T- Y1 r4 ]
long iflag, iflgret;& I5 B: ], {2 I. A3 D& T# @+ }
7 H' V" d2 |$ s7 f: N- t
int p; {9 p; O, Z. J: }8 I( c
. l8 E; U: @' S! D3 Viflag = SEFLG_SPEED;( m9 \- H* n' {& P5 x p, J
0 I: C' u! W' b! K7 G# bwhile (TRUE) {
- Q6 x9 o. Y" K) ?8 _2 F; i+ n& t& M" u( O9 M' U" B- e; ?
printf("\nDate (d.m.y) ?");
: z& |& ~0 E5 t, U
: L1 M) {9 ^' Z1 x2 P9 [4 X) Sgets(sdate);
, n1 _7 X, I! k
: E+ [8 @) R) A2 l+ Y/* stop if a period . is entered */
9 {. Y: v6 I( O' N* u& p- j" u% T8 [4 r" y9 h. z8 [
if (*sdate == '.')
* \! D. F) K/ T/ w6 c, |" A. l# G6 h; O" x: i9 ?( {
return OK;% }& E# Q) `: M* e8 Q4 \
( a( i6 C- W4 y3 _ L
if (sscanf (sdate, "%d%*c%d%*c%d", &jday,&jmon,&jyear) < 1) exit(1);
6 K' M' `" S3 t7 K, E( m4 @! [0 n
8 ]$ p7 m8 s* J4 w4 s0 |$ B( r# V
/*
" M1 ?4 T0 }/ p- i' u9 b% r3 ]+ E. i% e4 t( }$ d
" w2 B9 Q0 h8 x7 P& g6 H* we have day, month and year and convert to Julian day number5 T9 f: C7 t' q9 J* d" `
, l4 Q3 |- r1 {' h
1 c9 Y8 p" w9 e% X; ]*/
1 s0 t. }4 X& g8 M$ M1 Q' a* ]! z/ k7 I3 `$ C; D q; H
tjd_ut = swe_julday(jyear,jmon,jday,jut,SE_GREG_CAL);
( ?- {. F- T/ X6 D7 ~7 Z) p2 V& ~ v: b L# K1 e! C& b: f/ c
7 h3 j; M- G# V& M C9 f) U
2 x% Y6 [* v f. N- }' n/*0 c2 j* @# X* ~ b8 _2 s
+ w+ }; l9 {( T- a$ V: ` H' [0 E
: U \- {+ K1 S- x* compute Ephemeris from Universal by adding delta_t. h6 O6 a5 X" [+ R2 e% Q
* m4 G6 r: \8 U0 v, h: e" k5 z" [9 ~7 F
* not required for Swisseph versions smaller than 1.60/ K# O* }0 R6 i9 X4 e2 A9 J7 L
) c0 q1 ~8 v Q! H) M7 S! f+ J8 q, A9 e$ w
*/8 L% V( e% Z2 u& A5 h# y0 ~; G
: h- W5 y% C" p- ~, w/ [
/* te = tjd_ut + swe_deltat(tjd_ut); */
0 [0 ?0 X9 o7 _/ S
5 c, Q6 i/ @$ A) ~# E9 f5 Z8 z" Vprintf("date: %02d.%02d.%d at 0:00 Universal time\n", jday, jmon, jyear);) U/ h" E$ I9 X: J. B
9 f" W& A6 L1 Vprintf("planet
2 r: Q8 V7 z0 B& e) \\tlongitude\tlatitude\tdistance\tspeed long.\n");
, b0 Z3 z. C: U" I3 h! O
% u. t( y5 C2 F: S7 ^' W0 d( C- n' q% z- i4 e7 e
/*8 n2 _# p* r+ ?' e
+ e2 [' W" F6 Q% M! N6 G: e2 U
; p' M5 X- W0 G& P3 n" r6 W/ R, w
* a loop over all planets
( Q" E. r2 }: R5 r! d! [/ O* N, n2 h0 w* W' d
* |4 ~2 b) Y* x1 S9 i
*/
& m. G0 X0 j( z8 T
( Z; H1 p. w; |* ]; ?3 ?for (p = SE_SUN; p <= SE_CHIRON; p++) {% }9 I4 D! E" p9 R
; L# E4 ` o* R
if (p == SE_EARTH) continue;
* j' J8 p' y" o; @# L' Q
5 R- s% K7 x" }$ }; B/*5 g1 `, z" } r5 q! `$ h
6 v9 t2 ^0 p' _) J' c6 x1 a' e
' {9 K! L+ Y- x2 `( ^* H
* do the coordinate calculation for this planet p6 Y' c& y _: V+ i h8 Y
; o8 \1 |( Q8 E: p# m0 {# ^. g8 v. l% E2 d7 [: T# l) I& P
*/
2 t3 Q" C0 i% O6 K4 o- xiflgret = swe_calc_ut(tjd_ut, p, iflag, x2, serr);
. Y" m# [/ K2 B9 q; p+ q4 L4 C
, [+ ~7 T' v' v+ F
# G/ ]/ N* X5 p4 o/ \/* Swisseph versions older than 1.60 require the following 0 R* s+ o/ X. m- a, ~' V1 k
$ n) x' [* {+ H6 W1 ^' h* statement instead */
' O7 }; z5 Y& s0 T3 g" v/* iflgret = swe_calc(te, p, iflag, x2, serr); */+ r! _8 \2 ^5 Y3 d- r7 o7 W
4 x w+ m! r C6 ]5 Q! g$ l0 C* V- i4 W3 v( |( \1 ]
/*; O! m/ }7 G, y
# @8 A1 ?2 A' M! M2 X3 Q. p5 r# I4 e# e% d( \9 ?2 Y/ i! }
* if there is a problem, a negative value is returned and an : O6 q- B& a' b" o: k
& _* c+ W5 W% O1 ]$ ^- F9 Q
8 J0 f3 Z/ w! y" v. U& [* error message is in serr.) v0 ]% H; k# a" H* c# G3 ?' k
* ^$ c7 U; ^) r
! M0 y$ n* u: u, s6 B+ l*/# P) ^/ Z/ q( y, g
5 F! J# U8 Q) w+ @& {) G) z
if (iflgret < 0)
5 I8 R6 x% j7 Y4 Q% V" S6 c; k4 p0 l# K+ e" L
printf("error: %s\n", serr);
6 p4 Y9 L3 L5 @& W! R# t: x) K/ P2 h; q0 u
4 z' K" z2 r: w2 \0 {9 k
/*" [& d: k5 V* v( `' P( R8 c) ^
+ C8 T b+ U& X: J
7 T- Q. |8 A$ m; t% N* get the name of the planet p$ j' I3 t3 z1 ^, }
/ C) }9 r* Y4 h) y6 F
+ g+ C% g6 v! q5 G# e7 j5 U3 j*/, L( M! R! A A9 t1 B3 R/ j
2 l/ j! E. V/ w7 w: b! A4 z0 g; n
swe_get_planet_name(p, snam);# d3 q4 r" a! s( Z; J+ Q
# W( T8 d$ l9 J: |; g# V% H% |8 f% a/ J6 u7 h
/*6 c$ e/ a0 n# ^
, f9 S) T; b7 V/ t9 d# u3 u3 `6 {& Z- P
* print the coordinates
7 Q# [* j4 Q/ }- t* f- g" r v i0 r4 }$ V$ I3 l
( } }, g. o" S, M- _! C y0 P' Q*/9 S/ B$ ]/ S4 r k
; h. R# \3 b* t
printf("%10s\t%11.7f\t%10.7f\t%10.7f\t%10.7f\n",4 V5 C& a( g0 e# J
1 b8 a/ t" j. g/ |: x+ b
6 d0 ]! _8 T" hsnam, x2[0], x2[1], x2[2], x2[3]); B# P$ o* T9 p3 M
9 N0 D: `3 `# P t! g" ~}
) O( ~. h1 n) p' W$ O: Q
: }; ?. }' s6 B: v* e( h}
; R0 ^6 E# o2 W' ?% v r& m' W5 F( B' Y, _
return OK;1 i4 f5 ?1 Y. b! e* W8 Q: k0 n3 o
} |