1. The programming steps to get a planet’s position
$ s4 s( s8 ~0 v3 U# kTo compute a celestial body% L8 ]6 U: g: G
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.
9 h1 e5 z& Z, d: _" A' { : M' Z0 ^, z* b$ T7 `
1.
6 u9 q3 T% Q' L: s" D! L: w& ^Set the directory path of the ephemeris files, e.g.:
5 f( M5 Z! E& R% V' @
, E7 o$ n' B% v+ A2 _; m4 \" Yswe_set_ephe_path(”C:\\SWEPH\\EPHE”);$ { L* u4 T9 z$ H; a
9 ]# N+ p5 Q: x$ G) z2..
* T+ g, @7 v1 HFrom the birth date, compute the Julian day number:
0 z, X% ^5 w8 @5 {9 _6 E: i8 B b+ ?
) W9 l, M6 {5 ]1 x" X& g& ?jul_day_UT = swe_julday(year, month, day, hour, gregflag);
/ f: @0 z0 [. o/ x; v
0 B$ Q- U" D5 p7 F8 |% x1 F3..) E; \* C- u8 `. n, z
Compute a planet or other bodies:. L3 y, J) T6 E4 D
7 d: {. u8 }! W! q5 Z, v
ret_flag = swe_calc_ut(jul_day_UT, planet_no, flag, lon_lat_rad, err_msg); & s9 x1 @. D3 |' Q/ r3 F4 E+ s
" T6 I) W. M7 E" o- \: kor a fixed star:
2 l7 o! ?( m1 G# F' L4 b! k/ N+ ] ^" O
ret_flag = swe_fixstar_ut(star_nam, jul_day_UT, flag, lon_lat_rad, err_msg);6 J7 _" N; p( M7 k
% T4 s$ @& s8 }+ ]6 Q! K
w) Y3 _. Q& G' A$ T
Note:
6 l# U- {1 D- n$ b- V& Z! b' Z. G7 w) \+ z8 k
The functions swe_calc_ut() and swe_fixstar_ut() were introduced with Swisseph version 1.60.9 f) R1 y$ b7 s
& r* B: `6 K) q* }! H4 |/ H% L5 ~3 sIf 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:
: V( |! j- ~$ i r* ? R: f
. V/ u$ V3 S) }; x, a: w
4 `' k6 ~6 h# Z; j% H0 i7 E" jFirst, if necessary, convert Universal Time (UT) to Ephemeris Time (ET):) o) s1 _7 J$ O" ?. m: i l) x
" E! a- m5 f. s( c, w- l: Z4 L' q
jul_day_ET = jul_day_UT + swe_deltat(jul_day_UT);
6 o3 v' r& n" Q+ C( u ' o- Z# C4 T% w
& Y. R; f6 Z3 w/ E# Y W
Then Compute a planet or other bodies:1 |. k2 B) [8 U/ |/ A* d
! y2 c) D3 G5 ?4 U" J, R( Uret_flag = swe_calc(jul_day_ET, planet_no, flag, lon_lat_rad, err_msg); / L8 V/ y( M: N
4 `' ]& v# q/ _1 Y% Q
or a fixed star:
4 Y8 r5 x6 o7 J! n7 T- D y k) _8 G( K$ D/ a1 ?
ret_flag = swe_fixstar(star_nam, jul_day_ET, flag, lon_lat_rad, err_msg);3 z0 z/ O" C: [
9 H7 n* X% `& T! P- k5..
8 r H `# w+ z4 X1 }7 N; \, }1 PAt the end of your computations close all files and free memory calling swe_close();; F$ r1 T0 Z" I1 u
/ w# b/ p; |) G- x* j$ z- m5 U% VHere is a miniature sample program, it is in the source distribution as swemini.c W9 b* I6 ?2 Z. _/ O% m; t& n
3 h" K& }+ I M" J7 v; h
#include "swephexp.h"
. W8 j9 O' p2 i/ A, ]6 a/* this includes2 K7 d& f$ X0 y; A9 w
"sweodef.h" */& n0 o! ?$ M2 l% D2 g( J
int main()
3 |& Z* _8 g; p{) v2 d) e4 [- R( h5 L
8 M. |1 t- a0 W" O9 U$ \, }, M5 |char *sp, sdate[AS_MAXCH], snam[40], serr[AS_MAXCH];
B5 i; Y6 k1 k: c7 q
4 C) x9 S2 K; x$ P' J2 E! s! e* _/ Y, x
int jday = 1, jmon = 1, jyear = 2000;% u6 j/ r: x% A& \
+ q" |/ V, `8 N( n6 u u) J' ^6 Kdouble jut = 0.0;: a6 J8 z1 J& i | J& e
3 f( U3 M& P, O; Odouble tjd_ut, te, x2[6];. e8 z) S& q/ P' `1 J8 y9 T
2 ~5 c: l& J" S/ v9 v! {
long iflag, iflgret;3 U1 A% E( x( C. f5 H% b
3 M8 M1 T, i: f, Iint p;4 O' y& t5 L A- s0 C% T/ m
% L( W5 W+ G8 D9 c! A9 D* i7 |
iflag = SEFLG_SPEED;
. I! {0 y" S6 }$ `; [& j# u4 B4 U3 r% H( r: b
while (TRUE) {
1 S/ W( ?: r9 L# V2 |% u' }8 J, Q2 v6 H! Y7 C
printf("\nDate (d.m.y) ?");# H; U3 ?$ \! J- I/ J6 X6 T; }
0 l \( \2 @8 a1 bgets(sdate);
( `; p9 @6 p( k/ v% z+ |3 Y9 Q+ i% }8 m$ P F+ A* }
/* stop if a period . is entered */
5 Z8 [, t5 K1 _, ?4 F
6 y# c2 K' x2 B2 a9 g& ]if (*sdate == '.')
& q1 o! T1 k& ^2 V: J4 Y% z6 G3 z* @: ?) v
return OK;
" i! F; D5 G) K: h& T- J0 B/ D8 O# _$ a
if (sscanf (sdate, "%d%*c%d%*c%d", &jday,&jmon,&jyear) < 1) exit(1);* ?0 {9 w% P8 Z
; S: [/ k4 X6 U; \+ s/ E4 F# t8 z" d/ m9 U0 ^2 K( I0 U( W
/*+ k2 |" y2 C: l: U9 k+ ^
, p2 z/ I# R& d* Z& ~0 e- y
- \( g8 V: `) [3 S* we have day, month and year and convert to Julian day number
7 n7 g) r# ^& L) w+ X" S2 H
3 u6 E2 `( p/ K1 h+ }# ?
( g7 R5 W. N0 f" N*/: p% h9 q- t8 w
# F8 h: ^" t2 _
tjd_ut = swe_julday(jyear,jmon,jday,jut,SE_GREG_CAL);
7 k) m* R/ G) M+ b; e# p- g/ s
2 Y+ F% U8 ^# w/ f9 ^$ b5 |2 h! j; F1 a1 F) X
# _; N! {, ~) [1 o3 o2 y+ F
/*. T- L! Z/ z$ E3 t9 p/ {) s3 c
* M. b5 J' V7 G2 \: N7 F' q! y
( _$ ~& d- w) D+ [
* compute Ephemeris from Universal by adding delta_t
6 ~" l' C9 w' H$ n! D/ @4 Q! m0 Z% ^
' b$ S1 q# X8 `' F h" [ T& e
* not required for Swisseph versions smaller than 1.60
) r0 C- V! K3 }4 s7 @1 ^7 P. ?/ H( B J* K( g7 \7 B
% y e1 }; v8 ^8 R# Z*/ `& \' Q6 A( y/ B7 ] u2 p
3 m h' e( s- V% W$ O4 _/* te = tjd_ut + swe_deltat(tjd_ut); */6 C7 n% _* h1 k& e: w8 q" w; ~
6 l0 ]: T- M$ I# Q) T
printf("date: %02d.%02d.%d at 0:00 Universal time\n", jday, jmon, jyear);, F9 _8 z% ]+ x. b9 w2 {. H
, n+ }; ~; Z8 v8 K- R4 c) Iprintf("planet$ @0 \4 K$ o. i
\tlongitude\tlatitude\tdistance\tspeed long.\n");. q G4 }) d2 H: {
" G/ E7 X. ?- c6 U
! K, v9 h% c4 [; v2 ~2 c
/*# {+ ]0 g$ o2 @: i$ X
- _+ O0 C& V4 R
3 i3 f8 k& N: M1 [* a loop over all planets0 l0 {9 ?* q. u- Z, u D
: [% m8 |$ r" E2 ?: v
; ~$ \) V& B# s& Q' l4 `
*/
* E& L7 m: x' n* e1 ^6 z4 A
1 `: a+ o# D. c# _7 jfor (p = SE_SUN; p <= SE_CHIRON; p++) {$ O1 _4 a1 j+ z' K% ~
& E5 d l" O: h3 kif (p == SE_EARTH) continue;5 n! J0 s0 _# I7 e" w: K* z3 i0 W
# g% c' L5 q* p' h5 P/ p/*# }5 |: v4 @$ e0 D* x2 K
- Q3 P. w) j6 C- E; b+ Q9 A
& k& c7 m6 \3 t. U0 e
* do the coordinate calculation for this planet p- x- W+ ~/ O* y6 P" E+ B- U; [
7 A' j W9 P2 X8 J2 m7 \
9 n5 |! W0 n+ f; O2 W" r
*/
$ I$ p8 J! o. Y3 O$ @' u ]0 diflgret = swe_calc_ut(tjd_ut, p, iflag, x2, serr);6 E7 S4 a: L0 Z& S1 I! W
: k0 q" D3 ` l) F1 c% e
* D f* x, f7 A! x! H/* Swisseph versions older than 1.60 require the following
7 g# y- g$ {5 R ^" J7 H4 S0 Q' Q
; k& m3 Q1 N. ^9 V* statement instead */1 @) S( J* ?4 P! S, L' s" |
/* iflgret = swe_calc(te, p, iflag, x2, serr); */% I2 T0 \- i: A5 r9 D
w5 g3 e( ]9 N
$ I$ A( n5 L) f' b& P% k' {; h
/*. Y( `, G, `9 k0 G# v, `
4 V$ p& }) f9 F, q* K+ }7 C
6 ]3 n' d" Q5 q4 U* G* if there is a problem, a negative value is returned and an 5 o* H7 U2 ?5 m$ q! C
% L0 r& @4 z- N/ X2 n: D$ r& r7 N8 A) U
* error message is in serr.
4 `% Y" C' N0 i& B6 y4 O4 x/ [, E) r- @+ b0 X
/ ?, f( S5 [* z# Z3 T/ }" j*/; \; }2 X$ _0 T0 r- p! S, N( v
/ h- z4 p$ |( A n6 `
if (iflgret < 0) 5 f5 n$ |8 Q1 h; K4 u
- @8 S/ e. V+ A
printf("error: %s\n", serr);& W5 |8 J$ U' W1 O
4 i" V1 n7 V, g8 ^. x+ ?9 l& F* |
$ g: y5 l: N, \/*- N" G* ^ o9 r+ m; t
- z2 O5 m4 y7 o8 \ V8 g: G
' r& a. t1 e4 [5 @) T* get the name of the planet p& {7 z3 l( P% }$ j1 c Z8 [
+ d6 B2 Z7 e$ I
0 n; ?( o, [7 E& V*/
/ o. q: P5 `2 c
2 x3 M, b+ \" {! w5 oswe_get_planet_name(p, snam);2 a7 F' a \: p; @2 @1 D- N) N; {
. [- b6 ~# w1 W
: p/ Y8 d. V: d9 R* I; o. k/*! E0 r/ ^9 T+ D% l7 M2 q
2 D: Y; k1 p5 p+ J3 K( ^% l# |9 I' B5 p9 F
* print the coordinates3 h/ w' h0 j8 O; m
0 g* }: `, ?: H3 k7 x
- C9 [9 z, j! j1 ^$ |5 z. i*/
( j7 ]% B' n! A- g3 q' A) v% C8 C# l8 X+ E* n
printf("%10s\t%11.7f\t%10.7f\t%10.7f\t%10.7f\n",
% J- y/ T3 o. v" ?* R l( S- {9 y9 G5 h1 ?+ X' l6 f& i. v+ P/ _4 B
& J6 s0 D, i: [* W* z; E& x: ?% Q
snam, x2[0], x2[1], x2[2], x2[3]);0 d1 v/ K" |3 O2 r, C9 u; H% T; F; W" B
! I2 d2 |/ y/ e5 P" n}9 j* B% ] [) w; c2 f5 v2 f* A
0 b8 ~3 P% W/ n1 v: n}
+ [& t6 N& x* }0 N0 d7 e2 k' B5 H& i4 r- W
: x5 ]" l! \4 x, E+ v3 R3 C' t" ereturn OK;2 A! x5 L8 I8 L: {/ e
} |