1. The programming steps to get a planet’s position
/ v x/ |8 ~( [& _To compute a celestial body
2 o3 W& N [; r- S* Ior 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.& R# E- t, Y/ u' T! k
$ q% O* l/ |" V0 q1.
( V+ k; o# E. C b' a- \2 H& ?7 @" S8 WSet the directory path of the ephemeris files, e.g.: 1 c+ H3 g5 w! F# ^) P+ T" L
) m' F$ {/ h# a/ T+ X1 O0 R Pswe_set_ephe_path(”C:\\SWEPH\\EPHE”);
0 b; z% a9 w/ A( k, b" c* W
% j1 P1 x" f; z. U$ J) U2..
. Z7 z3 C4 }; F0 }From the birth date, compute the Julian day number:* f! e% D# ^' I3 O9 \8 i
' i* o% }2 V. p0 Q! f( @
jul_day_UT = swe_julday(year, month, day, hour, gregflag);3 }# ]' C6 J+ t. d4 b# n- _/ B
" y6 j0 V6 a/ P4 j0 X3..
& D2 b: B U" GCompute a planet or other bodies:
2 I* V& v& I- n9 N
2 H& z3 h7 q& L/ M: Aret_flag = swe_calc_ut(jul_day_UT, planet_no, flag, lon_lat_rad, err_msg);
( j+ x$ J% b/ d- M. V9 H" i9 N+ C0 [1 e
or a fixed star:
' E# L+ r# X, A$ c/ h: `% `
, o8 P& n$ Z3 c8 n( a$ w4 Dret_flag = swe_fixstar_ut(star_nam, jul_day_UT, flag, lon_lat_rad, err_msg);
2 C: `0 I5 Y8 F* g6 M$ h; V 1 C, O1 R+ n# V7 M0 X+ f. f% x
: c4 R8 C' \0 m2 f$ z2 yNote:
7 K0 t* V8 H/ \3 C! @* g: {' s0 F# e7 @( c. s* M
The functions swe_calc_ut() and swe_fixstar_ut() were introduced with Swisseph version 1.60.
4 z Q0 O4 T# ], b+ w! O3 g5 C( C0 b W3 N
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:
. J$ g: b* k7 m
- t: |% R+ G8 u4 q4 e: I$ h V! n) \/ D% G
First, if necessary, convert Universal Time (UT) to Ephemeris Time (ET):! |) B( v: c5 g9 ]$ b% n8 y6 M% _
1 y; L0 u( J& u2 g- @% Z, D
jul_day_ET = jul_day_UT + swe_deltat(jul_day_UT);
" p5 q& P: P+ s3 D
" O% ~, r6 ?: t7 Y3 O+ H3 o
2 j" _; w1 ?- B7 ?5 v* GThen Compute a planet or other bodies:
# N& d8 c" W/ E7 ?6 C8 W& A5 ]6 X! r v% x; c6 I1 ~9 p
ret_flag = swe_calc(jul_day_ET, planet_no, flag, lon_lat_rad, err_msg);
- W" a9 h4 J4 L% B# P1 Z" z
) N3 q+ @( y( @9 v# Yor a fixed star:
- q; n9 \2 \9 i2 F9 \ L# f6 U e5 s4 h
ret_flag = swe_fixstar(star_nam, jul_day_ET, flag, lon_lat_rad, err_msg);
1 ]5 u! s I3 X N8 V$ e 4 U' M2 g4 j+ w) I
5..: h: Y% h% Y4 r9 j" S
At the end of your computations close all files and free memory calling swe_close();
$ e0 M! i6 g* C ]% H# l 9 G! ?$ I- s8 Y Y* g4 R
Here is a miniature sample program, it is in the source distribution as swemini.c
: K4 Z% r7 P8 ]" m ' X( g% h: [: Q& t
#include "swephexp.h" ' l; p3 m6 y# Q3 L' Q
/* this includes5 G* s/ X4 y: \# v- W# ~
"sweodef.h" */9 p7 L" a/ H" F0 T% X. J
int main()
) @2 r! A9 | s- F" q' H! i& ~{
, i( }- L2 {, x1 n2 T8 U6 L, ?/ X: Z8 Q: |- A" ^2 }- o" P
char *sp, sdate[AS_MAXCH], snam[40], serr[AS_MAXCH];+ P# A6 @" e4 w
P4 ?/ _8 {$ ]5 T6 I7 _
0 K- N8 a3 s/ E) |3 p, U+ [int jday = 1, jmon = 1, jyear = 2000;: y! V$ z1 |8 B1 J+ X
: O0 q! _# P1 l1 d9 ~! }7 j8 Bdouble jut = 0.0; Y8 X& a) `2 {. C
3 @0 ^. ^! i6 p+ j
double tjd_ut, te, x2[6];
7 A0 ?2 P! |7 w0 T! |: }) c" M# @
8 E* e8 S' m7 p2 f, ?, P7 ?1 slong iflag, iflgret;" N1 Z$ F" W3 G) p
" p& R9 B- _0 ` N7 dint p;
7 j* |+ x9 Y7 p. t* V7 {
8 P" n/ T/ ]6 f" n9 X- Hiflag = SEFLG_SPEED;
7 z7 Z1 n7 i- u& } U) N; |$ j- e x% E+ ?% G9 h
while (TRUE) {/ I) T4 _7 F1 N, A, A0 d
& R- E' O% Y/ j" F0 l: q" F
printf("\nDate (d.m.y) ?");9 j3 d ] P0 x
4 N* p1 I+ s& l/ Q
gets(sdate);3 w/ I# L y# \! c4 \
( R% C- `; U4 y# b+ h+ \$ z/* stop if a period . is entered */ x5 t9 F: { g& g4 R( S: m
$ O0 d G/ l! T8 M" J; [; }( W' f
if (*sdate == '.') + a% T' f1 [: b2 r" ]# u, z( F
+ P7 l: {, c0 s: X8 {return OK;% e! g2 h p) E3 X
2 A' R: v" {& q$ f
if (sscanf (sdate, "%d%*c%d%*c%d", &jday,&jmon,&jyear) < 1) exit(1);
7 Z; ]6 [7 d; V m* z( c8 K& D$ s: x0 Y" A
0 c* l- z: X/ n3 }
/*9 h1 l7 l6 G0 u; }6 ?# M8 ?! | h# F1 a
8 [ [4 N# U' q: B1 k P1 n
- [) ?/ w' R0 y5 @+ b! A, c: Y* we have day, month and year and convert to Julian day number
" X% A, ?6 S) {# P
4 f0 ]; m9 h; Q- k7 u
6 _9 m5 P& E* f/ F1 w/ S*/
7 E& S( @8 O5 ]
% w5 [% }7 }; b7 ^" Y2 F& u* Vtjd_ut = swe_julday(jyear,jmon,jday,jut,SE_GREG_CAL);
^( ~( }, D5 P2 E$ F
, H1 P3 j# Z1 \9 D) T) I! r% [- D& z+ s* G- Y% L3 O& t
. Z2 g$ o( P5 k1 D/*2 i9 \" X# s! D) k
/ c5 Y/ @ B) N" u/ \; v9 p, u: o6 n3 m# h% r9 ?5 [
* compute Ephemeris from Universal by adding delta_t; }/ R8 k( F4 T7 s9 _* z
1 v% z' }" w' u4 b; `1 T6 V/ S, I0 m
* not required for Swisseph versions smaller than 1.60
9 l4 t" p4 e# ]
4 u$ g1 o1 \5 x) [7 Z7 X) X$ V) E3 u/ I9 d
*/* R5 _7 L9 T4 s) J1 B9 L" A- ~
( y9 L& K1 p" K; _$ W7 U1 \
/* te = tjd_ut + swe_deltat(tjd_ut); */% O* b9 u6 W. E) L. l4 z
' L! O5 T; t, |0 a6 j
printf("date: %02d.%02d.%d at 0:00 Universal time\n", jday, jmon, jyear);
- z& a( c# b( S3 r' F) F3 ^4 W; J. y% q7 Q8 r' w) g# z1 k$ n
printf("planet0 V/ R; A& F: Y+ J$ r
\tlongitude\tlatitude\tdistance\tspeed long.\n");
7 V: |& d) g2 q" L! p0 o4 E) ^( [4 m) Z V) ^7 z
0 \5 o, `8 c0 F0 ^! Y1 ^0 Z/*
) O \; H3 i& t: {9 X2 S; b5 E0 o
& u1 U& Z1 T7 N& r
# H& z: j% p: w1 ]5 N9 U* a loop over all planets
9 A" e1 M% I, H9 x! U0 F% w$ Q
3 \4 \7 S/ b+ f, d. z9 B n. i5 ~9 X$ P. n" l/ {0 [, j
*/9 r8 a" g1 n8 P
# ?5 e9 ?- d0 K. F6 f: ?2 Y: Jfor (p = SE_SUN; p <= SE_CHIRON; p++) {
8 M* D' m# D% C& t" \
. i0 c' ^. k* u7 X* H# _* ?if (p == SE_EARTH) continue;: }- _- v) e* v- b" S
; D) W5 Y# y% j: ~( T
/*( B# O, M/ D1 f( B% m" B- _" A
; a a: \% k* l- N5 \
& S4 k! o6 s; y- l: A
* do the coordinate calculation for this planet p/ b Z; E3 x6 `, f
( g0 |' K4 F7 q; Y# d
1 D) n- e& p, U7 S; O
*/
1 V7 j7 m1 B% j% A& Uiflgret = swe_calc_ut(tjd_ut, p, iflag, x2, serr);% V' v( y% {1 |' i. t) [
# X, }% F% s. I8 R; ` d6 \% U; D A6 f, g
/* Swisseph versions older than 1.60 require the following
$ g+ P' i$ B( R0 `, y- u
/ g5 O( ^/ g* H/ I5 _6 n( n9 D* statement instead */
, M! O, S+ c* r/* iflgret = swe_calc(te, p, iflag, x2, serr); */' s4 {$ b* f0 P; }9 c) F
' R2 s* m2 q7 u- f" ^! H6 M2 x6 T0 N4 |
/*; p1 O4 g/ k2 ] [3 A
: e9 N3 ~6 l- r9 B9 j" Z1 u
5 h6 q$ @( S$ E; X% D5 g* if there is a problem, a negative value is returned and an , X% [3 q* E7 [ d n! b5 O3 c
/ V; [) ?$ T9 f1 B1 k# I% P
& x9 x& x. \6 O L( p" B! J* error message is in serr., i" d% K6 A: L% {# \1 {$ N
* s `( w: q* y% a5 _0 z- O) T8 z* f) Z5 |1 D, L. X
*/; V1 u5 o0 l' L. M3 R, y% N
/ T1 G- l, p: v/ r" ]
if (iflgret < 0)
4 u* f- `9 `1 z9 v) r2 v
) z( V8 U. {7 [printf("error: %s\n", serr);
, ]0 l7 T* j+ @
/ d& r* R7 ~3 E8 R- D7 G
% ^, i; E4 O+ [. j0 o/*3 e3 b s# ?/ \7 d
9 j2 ?$ p4 C4 Q- X$ I: |
) ~0 X% \1 q/ |1 N
* get the name of the planet p
2 a& d2 ~: X; J6 K- @1 ~9 K
9 ^- W, {* r5 K. w0 V" g! f3 i) s
! m4 t0 b* H+ q: r. h*/
+ h( C8 S+ E- N$ G
6 V4 b. c6 m3 Q! K% B' ~+ E) vswe_get_planet_name(p, snam);
6 C G" v& n, a1 L8 X% l6 S; x, A T- l5 S* x4 [0 `4 N6 ~9 Z
* r, S% U9 w# R) c N/*' c6 c) C- _5 _0 J, r) y; o
w3 [' r3 N2 ~# u- L: W9 ^
& z# M& H) G- v3 Q, a* print the coordinates
" \3 l# B# c, P0 G0 D9 q
. t' ?* O1 }2 c5 c! u1 r, ^6 ^; t e! i! Y
*/$ g |2 ?, G: \2 o) D" I
$ R0 N. ?1 |1 r, L3 l' N
printf("%10s\t%11.7f\t%10.7f\t%10.7f\t%10.7f\n",
% F0 _$ J1 p1 y: N
+ Z0 ~0 G+ H2 w3 x2 p# y
+ L$ ?$ q+ r. z4 lsnam, x2[0], x2[1], x2[2], x2[3]);
( J3 C+ E {6 I3 y9 a6 t, j6 a6 }: g0 p% ^8 b9 A. x
}8 Y, E$ v0 u! m" f0 N( C
/ u* R# [* ]% n5 Z) {; j" I% U}
3 X8 m. J, c- u! [4 a" t- _; W1 N' c7 U* f; Q" f5 g
return OK;
7 A, P- O# @& L4 t} |