1. The programming steps to get a planet’s position
+ e' S) L) M; U+ ~2 eTo compute a celestial body
" U- h5 H, C/ |3 l0 hor 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 Y' J A* a. U9 ?
; k' T4 D1 `0 Q' ^3 w
1.
$ A% |# j) O6 Y8 J \5 LSet the directory path of the ephemeris files, e.g.:
, e# i4 u. d; I4 G( ^0 `) S2 n& l" i7 ^ [( v9 J) ?
swe_set_ephe_path(”C:\\SWEPH\\EPHE”);
+ ]3 z+ I; W, D) ^; T" x/ F
* }3 Y& k- N' r O7 d2..& o# R5 y, D2 V; z% O
From the birth date, compute the Julian day number:
( A" Z1 T% I2 d2 x ~
& @0 e/ S) V; u% C2 ?* ^jul_day_UT = swe_julday(year, month, day, hour, gregflag);
# M9 z T- [! l 8 H; J$ Z& v+ }; v
3..+ F$ H7 m. M3 k7 _
Compute a planet or other bodies:- M4 {4 Z) j/ B" i3 W. ~& v
; H' s- ~$ r5 r9 @3 Uret_flag = swe_calc_ut(jul_day_UT, planet_no, flag, lon_lat_rad, err_msg); 1 [& U& q: L F6 |2 }+ _
% o( \ c/ `4 X. z
or a fixed star:
( b1 C7 u1 |$ T. X5 U: X; c! Q0 _( o. O& I: ^6 z* C
ret_flag = swe_fixstar_ut(star_nam, jul_day_UT, flag, lon_lat_rad, err_msg);
* o- C! i( U4 `7 ]2 C
. x. G4 l) m% u# y; R* d3 f8 P! \- _3 n2 F; Y0 s. p/ B( |
Note:
$ T. Y+ G5 t$ q8 O$ R( v
9 ]& e) U7 u1 c7 c2 zThe functions swe_calc_ut() and swe_fixstar_ut() were introduced with Swisseph version 1.60.
& C" H5 z- A/ [4 `" `, l) }
: l& y8 |, H+ R/ d3 VIf 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:( R9 H) `* F: D! ]% e1 a6 r9 q9 j/ N
9 }$ a, O9 v. m/ l% }9 r Z
3 r0 J$ Q* i. Q9 AFirst, if necessary, convert Universal Time (UT) to Ephemeris Time (ET):
( d, ]- M$ b8 K/ H- X4 J9 Y4 M$ O8 I3 [" y; E
jul_day_ET = jul_day_UT + swe_deltat(jul_day_UT);
4 ?, ]/ V: Y9 z* H* P- O5 Y
; p* l; M5 h( u2 e& h: h6 _8 O. y- P
9 j. U& O; \; R% fThen Compute a planet or other bodies:8 E" j' E0 r/ s5 r/ D) |" u2 I
3 G" G& D# p0 e( q& D* xret_flag = swe_calc(jul_day_ET, planet_no, flag, lon_lat_rad, err_msg); U( X% o; Y* s. G. b8 G
6 b3 E3 k; `) t0 [: @2 Vor a fixed star:" k% i6 W% @* C0 |' a
& O" D& U; l2 w+ U+ ?ret_flag = swe_fixstar(star_nam, jul_day_ET, flag, lon_lat_rad, err_msg);
. h5 J) O- V0 T- r $ r# a4 p( j7 _" c: P% _. k
5..3 C' x( V6 |' N9 ]# c) \0 k8 Y
At the end of your computations close all files and free memory calling swe_close();7 `7 \' C. c* @
( c" F: G) X$ f) ]7 ?* `
Here is a miniature sample program, it is in the source distribution as swemini.c
9 T7 `) A) u2 l' A
4 L1 ^( B- c7 ?5 l% p3 R Y#include "swephexp.h"
+ X" v- c# P0 P3 q' i: D7 y/* this includes1 `0 z4 o* s: A* \; ?
"sweodef.h" */* i5 c8 a& O W. ]
int main() B) b' b! U6 u3 b1 ]! i
{) |0 ^7 M- X6 a- x2 F
d* p1 e/ I) l, l+ T
char *sp, sdate[AS_MAXCH], snam[40], serr[AS_MAXCH];- D2 m/ g0 w. X+ H
) w- [- B* A4 `* l/ x& L
; J2 ^$ H: M$ j+ q* i$ i8 e
int jday = 1, jmon = 1, jyear = 2000;
/ g2 f4 w5 e* B
6 Q' C" R' L: J1 t' I# |double jut = 0.0;$ c$ C$ {' J7 J! d# W, ^- _
6 u+ B5 o2 V( ?- ?9 |9 v9 c' ]$ Udouble tjd_ut, te, x2[6];
* y, w" j' O+ I/ }+ ~5 I2 a; i& e$ k7 P1 L' H& A
long iflag, iflgret;
7 @( V; _, l4 Q7 }- Z! }) j
1 m" g( D* g, nint p;. x' H7 ~$ r) {! a; B2 _/ _: l
; ^2 K2 G. x$ U' y8 h6 k6 X
iflag = SEFLG_SPEED;
' m+ ~/ ^, s& J, W9 E4 J: f7 W: K$ i0 J
while (TRUE) {) W& L$ O: u e" R; t+ s0 N
3 ?+ u. d/ z& v7 ?9 o Z
printf("\nDate (d.m.y) ?");
( _6 l8 M8 R0 D5 h* t: L L" a
( d: \' `2 d# O0 x( C9 |gets(sdate);
* o' U! K9 B a6 F& v* G
3 Y' R5 ]3 B2 H0 A7 h2 S2 F/* stop if a period . is entered */
7 Y: {# F J5 W5 ?+ [
5 k; w3 l7 P" N! l: mif (*sdate == '.') 4 e; y' D* M, k: O2 c" {
2 ?6 ]. Q. u8 p. _* l& r
return OK;5 H& P. ?( M t2 z- U. F
0 W; @7 P: A& l* f! r$ nif (sscanf (sdate, "%d%*c%d%*c%d", &jday,&jmon,&jyear) < 1) exit(1);' c3 v9 }$ Q$ z" ]8 {- N7 T
. [: K& @" h! \7 [ _+ }
* i% D% l/ c7 }: o h% `+ O
/* y# X/ r" R# u/ W4 i+ x2 y
- v. P) J/ U- ^, g" C/ U2 i
+ _4 T' V: |, u, V0 |* we have day, month and year and convert to Julian day number6 A* g* G" N+ K
8 z1 ]- t( A8 [1 P+ S+ l# V# k. \6 i: e0 U3 \+ d, F9 Q, I* A5 l& t
*/7 K( Q& |9 t2 S7 d; ^, l
7 H* J1 ]" n, |/ U7 s0 P$ i2 J# T
tjd_ut = swe_julday(jyear,jmon,jday,jut,SE_GREG_CAL);
4 Y# I" \8 a: Y3 e
! G1 j5 r* @+ q% h5 |& \9 F# R& s5 b6 V; ]
7 i6 z& t& u. X/ l* @
/*- G& x- U& a/ W7 C
9 L$ z1 N0 W2 {$ _
B$ K( q4 x0 H" J2 T* compute Ephemeris from Universal by adding delta_t3 |4 O R1 P; N4 d
7 _% J: y( s! V6 a z$ P. Y5 e9 V
# D8 s0 O, H- r+ }2 E! }, l* not required for Swisseph versions smaller than 1.60# `+ a) }6 Y& U) X% ]8 O; T
3 Y4 j3 G6 \4 ~2 G; f- L/ v
, v) }! o2 n. b# D*/8 D3 E3 H/ ^5 C2 O" g2 O
3 f7 Z4 e1 d: q9 d! i7 {
/* te = tjd_ut + swe_deltat(tjd_ut); *// z3 m/ m4 V6 f3 O0 }5 i
$ q! [5 i) u' l& `) ]/ k
printf("date: %02d.%02d.%d at 0:00 Universal time\n", jday, jmon, jyear);
4 {! k4 o9 i+ `" W# Y) i' s+ U
5 K2 h- k5 x& \+ K6 ~printf("planet* c1 H; x5 R6 m/ ]
\tlongitude\tlatitude\tdistance\tspeed long.\n");5 n. p p n' E. X' U
`. n4 p: G2 ^
' j# i. P! x/ O: v/*; K5 }9 ? v- h3 G$ c N: r
( Z/ a1 _+ }: o5 ~* m
3 N/ f% R0 Z$ i* a loop over all planets, [1 w5 Q2 d" d% o2 ~4 T
0 S( T9 A& H, X" G, D7 o+ E$ @6 X/ Z8 M5 A" T6 H6 W
*/, p/ B$ N5 U2 ^& [ y# Z
4 n: w7 i& j7 S2 a: |# r% s0 ofor (p = SE_SUN; p <= SE_CHIRON; p++) {% h* e% D4 y/ r3 Z1 Z! G) p
7 O2 T6 D% W# J; f6 q' f
if (p == SE_EARTH) continue;
( D. U8 M f9 a3 L( ^/ f3 s. E4 a" j
/* K5 K2 X4 g4 Z7 T
! t, \) e. u+ ?1 _: Q" i6 F, [4 S) X6 ]! h3 x
* do the coordinate calculation for this planet p$ G; k2 l' p7 d2 Z
, M [/ h) V- z! n8 j" `( J; j/ D6 C2 o- c
*/- p& g% b5 r$ x' \! B* C
iflgret = swe_calc_ut(tjd_ut, p, iflag, x2, serr);! F! ?8 [8 F+ f. W T
/ v7 j+ D1 V7 \9 V6 K7 _/ l: ~7 N, _' I' t! r; }1 H: v
/* Swisseph versions older than 1.60 require the following & E5 l8 c5 @6 M9 S7 W! Y0 [3 Y
9 F6 S l8 k1 v2 A* ?) d Z/ Z4 s/ g* statement instead */: e i* B7 x8 v6 P5 r
/* iflgret = swe_calc(te, p, iflag, x2, serr); */
q( k; u% |3 m) I$ J0 J- X) s
3 J/ m+ B! [; h; e7 ?7 E& } G) ?: {9 Z3 N( x% V
/*+ w7 b# F+ r5 Z
( `/ e- g6 v' V) `0 R5 C) n2 V
# |, o! z# { e5 u, z) e* if there is a problem, a negative value is returned and an 0 b9 @. W! Q: G) B
7 C8 E" I( W; P9 C# w' D+ s5 J3 J: B; Y
* error message is in serr.
Y1 g) H& @" k4 ~1 R2 `; ~1 s7 |1 d
9 V# |! |. d) N( ^8 z. n
*/0 |3 u( X; U3 C+ u& D/ G* J' z
5 ]9 R$ d* N4 P$ p* q
if (iflgret < 0)
* n5 n8 m* Z1 E2 ` W
! {2 L* ?& y9 k( N1 h, G& X- _printf("error: %s\n", serr);
! N$ t. @; Y4 d' h' `. [ p2 \; ?
* E3 h5 U$ ^/ M4 N0 ^( P
4 j/ j* S0 _* h" F, d/ G, w/*
6 U; q" Q. u6 g$ }( M* X6 m$ N% Y o) P( H
- O1 L( \7 i" p' U4 ^1 R* get the name of the planet p9 A: C9 \: s. @
5 w) C: u& A& I. Q% v4 D ?/ m
! O: F2 Z6 U1 J7 R$ ~* \2 r
*/
: w1 a/ H$ a% F# V7 y: ?+ E% l6 p- Q- }! u. Y4 H( x2 m
swe_get_planet_name(p, snam);
- N! W5 V! t8 q) j% H* ^" P, n1 m! m& S
8 ]1 |; O1 Z5 C- L6 n) t5 V0 ~' C
/*
, X: b2 I+ S0 b& g8 P
3 a% F$ b+ o8 [# X5 j' t; \, X0 _! s
* print the coordinates
6 P2 z9 m' o/ M1 ~- z2 e4 w/ Z* [% l/ f" U
2 ~% z T& @, d9 T0 r+ t
*/
$ X+ {6 n; w* T [7 p; S' t8 Q. }6 {; L S" k2 ]& D' ?) D6 x
printf("%10s\t%11.7f\t%10.7f\t%10.7f\t%10.7f\n",
$ o5 f/ L* J: u+ x4 i+ t* l! z8 V. h- x O6 L
& P( d1 p: n2 i, h1 g& u. N+ U
snam, x2[0], x2[1], x2[2], x2[3]);/ F" `/ s- {8 U% N8 M* K3 D+ U
( ]6 q$ W2 E g3 k8 `3 {$ ~% R) C( J
}8 ]- `/ R' o; J, p; W
2 d/ a/ V% u, H/ a; a& k; w}
5 A. z7 o: }, r9 n" C
, E, @2 Z0 F% \return OK;% \7 l! _! V) u* ?- m" i1 J$ H9 J
} |