The programming steps to get a planet’s position
! Z/ E: W# n5 DTo compute a celestial body
$ Z/ T# r' K# o& t6 k4 [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.
( M+ e! p8 v7 d
: @- ]* @) ^2 Q/ Z# [1.
7 J) j0 m/ H2 p5 P8 O+ D) qSet the directory path of the ephemeris files, e.g.: " A. @1 `# R2 E; R; E% a' Q; ^/ J
( q9 V9 ]- F0 w* p2 T$ m- M: T
swe_set_ephe_path(”C:\\SWEPH\\EPHE”);
, t% k& D' M4 @8 Z / o) @& X! s/ |; @& x* V4 B
2..( F, Q) E9 T- I2 n" `
From the birth date, compute the Julian day number:/ I$ Y, m1 r3 i+ M! U
0 G& w. y0 n3 K# J8 {jul_day_UT = swe_julday(year, month, day, hour, gregflag);- H5 E4 c9 I1 X* o7 H" ^/ ]0 ~ s/ {
# s8 p( W; K y
3.. Q r1 p* a# d# V
Compute a planet or other bodies:3 Z* t) s2 Z# a2 Q% N# x
" G5 a, z$ m1 ?: `, `+ v# k) R$ z
ret_flag = swe_calc_ut(jul_day_UT, planet_no, flag, lon_lat_rad, err_msg);
2 i% G9 q4 V6 C) @
p x* J, }! D2 ~4 `( por a fixed star:
' G! i& W& X- Y s6 I; b/ s8 y
( B) D- a3 Z* xret_flag = swe_fixstar_ut(star_nam, jul_day_UT, flag, lon_lat_rad, err_msg);$ |% U6 m% M/ ]9 i) _9 Y. M
$ F( d" O0 A6 u8 Z1 r# _5 \
: P! f- O' G+ ^5 f9 ? }! Z, V! B, w
Note:+ S3 [% Q2 A, }! H
; o. ?, [* h4 ]8 R) `9 }! f, Z9 ~
The functions swe_calc_ut() and swe_fixstar_ut() were introduced with Swisseph version 1.60.: E7 s! c% T2 U0 n! S E. H3 |% P
% h& F' Z$ T- y# n5 r' v) dIf 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:
7 S6 ^3 j9 @8 f6 y; J4 | 6 U: y4 ~/ t# \( c) O1 o, c! p- E
7 b2 W# K4 ^' P. ?+ A/ b' bFirst, if necessary, convert Universal Time (UT) to Ephemeris Time (ET):
4 P+ `8 E, d5 p0 ~- t4 N; S) {" Y: D
jul_day_ET = jul_day_UT + swe_deltat(jul_day_UT);: d, N" b, v, c- L' {8 U) ^
2 F( R- L# K; C! b" v
6 e" W2 @$ j5 A o
Then Compute a planet or other bodies:
4 Y: a5 H) Z( b) J4 Y& H6 C
/ e, n# C7 M' e: C" }ret_flag = swe_calc(jul_day_ET, planet_no, flag, lon_lat_rad, err_msg); $ ]; B7 }) s7 s7 M) ?. i8 l, v
5 p S& \8 N/ x9 S8 h4 N4 C; q
or a fixed star:
" a7 _& [" j' S' x0 S& Y& h( O( j2 h, d
ret_flag = swe_fixstar(star_nam, jul_day_ET, flag, lon_lat_rad, err_msg);
- }9 l% w% m5 s2 k7 I* C+ l , e- {( t# d; P3 D
5..
! P+ S: M; O1 h8 v) vAt the end of your computations close all files and free memory calling swe_close();" Y7 ^" C8 u0 R4 g2 K( o$ _
* k" N& t( B/ T% w }( HHere is a miniature sample program, it is in the source distribution as swemini.c
* }9 {8 l; z0 V# S% E 4 q8 Z% ]. K) r& V; h
#include "swephexp.h" : U- d! D& x# k1 d/ D
/* this includes
* U4 q+ E& _3 z7 t. ]"sweodef.h" */
8 |9 {4 M0 D0 o# ^1 D) L9 ]+ `$ J: Hint main()
; F9 i* c; E# Q- A- S{
5 t' M* {3 d; Q1 D% G: o5 F6 _$ J7 Z% r: x
char *sp, sdate[AS_MAXCH], snam[40], serr[AS_MAXCH];
; K) \" J; j l) a; V J/ z" \& y% _& H6 B/ ]' A7 u5 q; V
7 R2 ^) D/ d2 S
int jday = 1, jmon = 1, jyear = 2000;
5 Z2 X6 b0 g+ [; s# _
6 N3 O5 j0 {5 o6 t- edouble jut = 0.0;
. p; `2 L6 m. u' {1 N4 e3 G8 g3 {* r! ^9 t& u' d* r- }" N7 Q1 c
double tjd_ut, te, x2[6];
2 [. k9 ^( \- d% e3 x) e0 w% C' ^6 v& G2 B1 b9 l
long iflag, iflgret;
; h4 ]" M0 m8 i3 P8 s* D! R7 n% b; }( ?* v$ Q
int p;0 q8 s3 A7 D2 R2 r; E
% x& H) l" _6 e3 L2 I2 g
iflag = SEFLG_SPEED;
9 o, w+ ]3 P% D7 u6 i o5 y) z, U+ k. ]# _9 v- v; V
while (TRUE) {
4 t' ~5 h( _+ Q; P# w! s" s$ u( m. R/ D5 s3 m* G5 w% p" i* x+ l
printf("\nDate (d.m.y) ?");
, s1 q4 X! ^; q4 A% ~3 O
; g3 L" g. E) ~/ R7 H- Egets(sdate);
+ ^: w% I+ J% z$ [7 N1 R+ U
9 p/ Z* |6 f2 v$ k' F/* stop if a period . is entered */
, r" @; M; t( S: \- G6 C! K. m+ o: X8 X v4 N( v7 Q0 s
if (*sdate == '.') / {7 `+ |* Q& n
+ d) {$ _9 z3 creturn OK;
# Z- {9 M g4 I' J2 F
" _# C7 H9 X3 d! m) x3 wif (sscanf (sdate, "%d%*c%d%*c%d", &jday,&jmon,&jyear) < 1) exit(1);3 n- w$ S& }! s
8 }1 i# _/ g% D5 F! I# ?9 L. A( x/ N8 y
/*
6 l: E% {0 `) c+ y
/ B5 I" g3 L7 n# |8 e" b8 h6 z$ @2 ^9 g4 I
* we have day, month and year and convert to Julian day number% r8 H8 p9 G& X
( J! X0 q4 d. X9 Y+ B" I- R
1 S. ~) y# @0 O5 d8 d" K# X# g/ @
*/
7 |' f3 m0 ]) _3 L6 ]( Z' N& T& @! B; \9 Z- l0 h
tjd_ut = swe_julday(jyear,jmon,jday,jut,SE_GREG_CAL);& D) h; V9 Q# q; x1 F$ C# ~
* ?8 y5 L* o+ b1 b
6 f& d: H( x/ u. B
5 {4 K% W2 m. T& l, o, S/*+ B% `8 R: m; E# `3 F" [2 U
/ \" F9 f" j5 I. o" D+ y3 Q
( d4 ]6 a& ^$ N
* compute Ephemeris from Universal by adding delta_t
% q: {3 k( c0 C. f
, t: s1 n: A a8 r
3 h0 g* a% E3 w: `3 z; |4 k* not required for Swisseph versions smaller than 1.60+ U+ Q2 `2 ^8 q) ?
# W( Z( J; }! B9 ]$ x/ V1 F4 M
) ~7 x2 c/ T2 _+ l+ ]*/
# u* x7 p9 B6 p8 i( C6 F2 g0 H( q0 Z# _7 I
/* te = tjd_ut + swe_deltat(tjd_ut); */
# z7 m3 c0 k3 j: a+ W. f
+ E/ h/ _6 f- u. dprintf("date: %02d.%02d.%d at 0:00 Universal time\n", jday, jmon, jyear);0 X. w$ @8 P6 w7 K
: F/ l6 t# v( _3 C$ R! I9 Z
printf("planet& L5 z. h J+ N& V$ {
\tlongitude\tlatitude\tdistance\tspeed long.\n");
6 q' d- F9 Z+ \- U/ u% x0 T$ `
" I( S0 h% Y% ^6 K7 l1 r5 F- K
, f" T* |! r6 d# a* R/*7 s' l+ J$ f6 L# V: H
" ?7 X& Z5 ]& S
9 Q) _9 o1 U- \1 ^9 P: F6 c9 q* a loop over all planets. y6 Y) i- \1 u# X" H! E& a) \0 G
, j! m) M- o/ ^% v7 ~1 s
6 U3 ?7 ^1 t! V) H
*/9 L# G5 h( s. W, C
, w$ q* p% x. ?( a3 p2 {% Qfor (p = SE_SUN; p <= SE_CHIRON; p++) {
$ Q& ~( x1 H. h9 {4 _1 g& l0 [# l1 H5 ~
if (p == SE_EARTH) continue;
a2 B/ c5 A2 Z3 f5 d' p' h
- \7 B8 f2 O- E7 u8 K' m/*( i2 ?5 [$ @/ u7 Q$ t+ U
v# s& M( u3 {/ ^1 a
9 ~, e% m* x5 j* do the coordinate calculation for this planet p# ] a3 x3 q* @6 S5 w
7 p) v U* o0 f6 r% v
- p4 _! S0 J2 w$ `/ ^*/- {! o0 ~ t- O/ Y" l* B& b, B
iflgret = swe_calc_ut(tjd_ut, p, iflag, x2, serr);; i0 b; w$ w) R. r7 |
- Q% b! `; \2 C, J3 V8 p# N
T" Z- A- L0 Z$ c/* Swisseph versions older than 1.60 require the following
* F1 G6 S( J, V3 a4 X2 u; m- W! M# x1 z3 F9 w4 [. X
* statement instead */
# K; s' g, x7 B/* iflgret = swe_calc(te, p, iflag, x2, serr); */+ S a6 u( R ^0 M; D5 c; I
* |- ?% t2 q5 }8 @8 x- j8 C' W) c: w
8 o& q- n. p( l0 Q5 z- z/*
! w, v5 e) `5 C. ]
5 ]5 e0 ]6 _$ R$ d4 d
6 v6 h5 h p6 ` O& }2 r8 Q/ A* if there is a problem, a negative value is returned and an 9 q2 S4 s: ?4 p$ J( [- T; l
6 V, n" I+ K) u& `# ]% ]
, L% j$ Y) Y: T# K
* error message is in serr.2 |8 j! h& w" L3 r
4 i8 H$ F! i" `4 b4 T# o
3 i. _$ Y' B0 U6 p* R* z2 X) o$ {. c: e) W/ q*/
* U2 j0 i6 i( R6 U, q$ q2 O. ~# S% [7 P
if (iflgret < 0) 7 m- u) g! N) u8 M
8 H# P$ B7 E w8 E
printf("error: %s\n", serr);
7 ~, r' d7 e! A6 o4 L( Z4 x% K6 j- c$ ?8 H8 O5 V! x* i: I! {
$ [" v% F/ J9 y) U8 T1 X/*" m5 w7 a, V: z9 z F
* V( i- E& _2 m: \( t2 \ _
9 G |4 Z* E) B- a4 T8 |! l* S
* get the name of the planet p
/ W2 J: v1 J% ?- l0 J& c% g1 y8 u: u
) V+ f+ d. Z6 \/ ]1 ^) J9 G3 o6 G& \; n' t2 I/ I0 b
*/- O ?7 c! d T& P* a
0 D1 ~$ k, H6 ~% M: pswe_get_planet_name(p, snam);
2 d: p) j+ u; C! ?( I- D& \' I' k8 ]2 T! i: O# F, g _0 e; s5 {' c% |
; w% Z. A9 y$ `" P/*) H% e/ B5 ~5 Z* E$ l. d3 J% J3 ~
0 L6 s' F' a. M! t9 l. J/ \' B: c* i3 E5 L7 y0 M
* print the coordinates
3 [# |7 a3 s9 I) E3 b4 ?. ^
, `; x) e3 r) K( T/ d4 @ ?5 r4 S( B' [9 V8 o2 z
*/
: I* x! P& C' _2 h
$ c/ E) R1 I. }; \9 g+ Vprintf("%10s\t%11.7f\t%10.7f\t%10.7f\t%10.7f\n",8 S6 o) ?1 ~# }$ S4 o7 `# O3 t
! |3 L( T* l0 z( q
, g& ~; B8 `2 v r$ w
snam, x2[0], x2[1], x2[2], x2[3]);
# M9 D' @1 [' ]) m: B" p2 c/ b/ U# D
}
$ F8 T% R9 a% s/ C7 n
+ \, A4 O; A# Y: g ^} b+ `3 G8 J& |5 g& z D2 Q1 T
1 K' g2 ?/ q0 U5 K2 o/ R1 {% L
return OK;: w0 ]$ }6 L( v# s+ i* M
} |