1. The programming steps to get a planet’s position
, u* x5 O0 T3 w5 N" @& VTo compute a celestial body
. q S& |' L, C9 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.
$ m: S. C) Z. i8 x/ R$ l |) v : ~# V; \3 Z( q9 i( b3 ^
1.
4 y' y: M' E; }# q( USet the directory path of the ephemeris files, e.g.: , F5 W, v) N4 x/ F/ a% p s4 ^8 p
7 r0 Q# u" N( R. |4 W8 y
swe_set_ephe_path(”C:\\SWEPH\\EPHE”);
2 h. k ?9 j4 V6 J 9 u! \0 ~1 S, N& L% t
2..0 S4 |- x, I! G S( r
From the birth date, compute the Julian day number:% K6 p7 R$ D* u8 t q( G* g
1 O; Q* @/ L3 u( w0 n" S0 y Y9 c
jul_day_UT = swe_julday(year, month, day, hour, gregflag);2 O6 {; E# `9 j6 f$ X+ |
( x4 m6 j( C, p0 E7 S* p; }; n
3..
; s$ @0 ^ m9 c. H2 ^Compute a planet or other bodies:3 V' B. H$ z5 `- T I; S. D
& Z- D% P! J- \ret_flag = swe_calc_ut(jul_day_UT, planet_no, flag, lon_lat_rad, err_msg);
6 ]- t( n A2 c4 A. P# q5 j4 h
" a7 t7 a& L/ |; h, @1 o) {$ D, O$ Vor a fixed star:
$ T5 D: c# M, _0 q! O9 H+ i( w8 h
ret_flag = swe_fixstar_ut(star_nam, jul_day_UT, flag, lon_lat_rad, err_msg);
3 l+ H$ ?( P% }# b& I# v4 [& d
8 {7 W1 e8 P+ t4 h
4 s) Y0 Y x2 w6 t7 cNote:
# E& l `2 L/ D$ p& V
2 \0 B+ R, I& yThe functions swe_calc_ut() and swe_fixstar_ut() were introduced with Swisseph version 1.60.
2 M% ^" a ^, u
0 }! u: E) R. N0 J0 \+ d' wIf 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:( W! j# X9 u: V; C8 r: F
# g+ [1 X4 w& r2 r% M2 X* c9 v
) G' U c/ {% k4 i
First, if necessary, convert Universal Time (UT) to Ephemeris Time (ET):
5 o# s5 B1 }! O. t& r+ e
# r0 f) |% Y: g$ V# L, cjul_day_ET = jul_day_UT + swe_deltat(jul_day_UT);
& w, {6 q3 w5 V! Q , a1 X6 m+ ]+ \5 Z% K
9 v5 V" a. j9 ]( NThen Compute a planet or other bodies:
% t; u1 o0 _, U: U9 X' P% B7 g: |. G N C: h% h7 S
ret_flag = swe_calc(jul_day_ET, planet_no, flag, lon_lat_rad, err_msg);
. p3 ]2 Q! D8 Q9 ?* U Y8 x: y {! f5 {! o s, W
or a fixed star:
; f; U7 Y0 t! b% q$ ?( b, |' T. {$ ~/ X0 j# w5 {+ p
ret_flag = swe_fixstar(star_nam, jul_day_ET, flag, lon_lat_rad, err_msg);
: [0 t- Q4 e# R" K' c 8 i& g: s" w2 m* c3 d0 W; c& h8 K" l
5..
8 `5 m/ h0 I$ T) B' J* vAt the end of your computations close all files and free memory calling swe_close();3 u3 V; R N' r
% w+ v1 v2 Z0 A$ e
Here is a miniature sample program, it is in the source distribution as swemini.c
6 y# |1 \- j' n- y, L0 q/ N" z ! z! M9 s2 l# I9 D. \9 ~8 V
#include "swephexp.h" 3 T s6 Y' O7 Q
/* this includes% i" `8 Q" ]% ]" V7 V
"sweodef.h" */8 e* M5 o- B4 k$ s- ]5 l3 o* x
int main()
* N* I' A1 ^$ c/ q: x5 }0 J o{7 g" N0 x0 ~) }5 ^" o
' F! k5 O8 c) } z0 ~& b
char *sp, sdate[AS_MAXCH], snam[40], serr[AS_MAXCH];, t. v; k" L8 K J; M) E3 F- l
+ W* i6 G1 [$ j+ y# q, p( \# T5 }
8 X' i; l' b8 s* Tint jday = 1, jmon = 1, jyear = 2000;
) d9 Q* y7 ?1 | J U* M3 c* H) f# J, Y2 ?. T
double jut = 0.0;
# `, K7 t6 u# v% o* J3 z8 B, D$ f5 E
double tjd_ut, te, x2[6];
1 ~7 T' C0 v$ t8 x$ y; o# @* k" T
: m# U- ^' X- jlong iflag, iflgret;
+ D* w$ r7 B) w9 @' i. h1 n/ _5 V/ L
int p;
, v$ O' |" @$ a/ L$ a% B8 F: p
7 C6 P8 ?* p) A! a* k! k" piflag = SEFLG_SPEED;7 X& ]; {& r4 A6 Y; B
4 A# v& w/ `: t3 {; X7 o
while (TRUE) {
9 z' m2 D- p/ x6 V8 k8 R' v8 i5 E! Y! m, T. b$ k1 S+ E1 C% I+ s
printf("\nDate (d.m.y) ?");
" W5 \ D, H( b+ \( W H3 T* |) d! ~3 z) Q; `- Q
gets(sdate);9 _' u2 R/ s2 L* |$ Q
" `2 U! D% c2 q( O
/* stop if a period . is entered */
# b v& E8 o9 p6 E2 |+ _& l! y9 m0 g. K0 D1 d( F' l4 ^) L
if (*sdate == '.')
# k. B) u5 m+ o& J9 V: M
: [/ v. U) M8 Z: Greturn OK;
2 C( y4 y% y- t2 r8 m
, R3 D) P! C! tif (sscanf (sdate, "%d%*c%d%*c%d", &jday,&jmon,&jyear) < 1) exit(1);
; ?% s% T1 e2 O" p2 b& [# U$ i' q* L2 c7 f9 U
1 `3 s6 v. m. `9 y- c; [
/*# ~9 g/ o0 P% X. Q3 x. Q
+ y" ~0 h0 j' W. t) a2 X3 [
3 h8 H c4 ? Q# H% z; X. C9 ]4 G/ s
* we have day, month and year and convert to Julian day number# D( @& S9 x/ s* [& _8 N2 i- ]
3 T: t% t" c7 k- e; u1 ]
# | S! B* `0 d* B. Z% c*/
$ z2 ], O) ~' S( S2 ]9 `& q$ Q/ i3 e ]' K( m, @
tjd_ut = swe_julday(jyear,jmon,jday,jut,SE_GREG_CAL);
. z. k2 M5 ?# K0 K) G8 p
. ]4 ~% t& z$ j' M
( \/ R; N$ c# f/ ]. r
& A% r- s: j" ?9 M5 v3 }8 @8 _/*& Y# o' ]1 M! |* A m
5 v1 {& K0 h/ L
- F# J/ b4 B% F- N0 M0 O
* compute Ephemeris from Universal by adding delta_t; O# M6 s# U% F/ ?# ~ K
6 } {5 g2 v$ V0 ^( F' |! O
5 d- x8 ]" I9 d+ `9 R) k( A4 o* I* not required for Swisseph versions smaller than 1.60
7 I& q6 o3 q7 X( H9 A4 Y- {8 [) c9 j: g
' A3 {- u7 U. G* j, Y2 {, a*/
1 B" |8 O) |9 ]4 o- Q) d( H% @' f6 V$ E; G/ V( ^5 p
/* te = tjd_ut + swe_deltat(tjd_ut); */
! q/ f6 Q& u0 ]: A+ _/ i4 _" c5 B+ F3 w* I3 o1 M$ K2 S
printf("date: %02d.%02d.%d at 0:00 Universal time\n", jday, jmon, jyear);4 _* `4 `' L1 {/ m
. W% R# }6 f- P
printf("planet
1 \, e! l9 P# U& k\tlongitude\tlatitude\tdistance\tspeed long.\n");
. [/ N$ L4 `* y" l: k0 f9 K- E7 M, {% X. E. S9 X' [
3 [6 u5 L/ a" D. Z$ e Y {9 Z
/*
& y+ e3 m& v: O! L
x# H/ |; t' |6 l" g& P( a5 m% M/ W$ x2 U6 n& Y
* a loop over all planets
7 b8 U+ s: H9 ~$ U* F; T3 i9 L6 U M" g
. Z- w% \! h" H2 l5 t
*/
; Y$ L L. K+ A& Z; j# X+ Y3 X' J
0 m0 \0 e4 X: V1 afor (p = SE_SUN; p <= SE_CHIRON; p++) {
. n" ~6 d9 g/ f* \4 z$ k. X1 Q$ ^7 r p: G! ^
if (p == SE_EARTH) continue;
' k& U5 k# n( }# P8 Q
6 M+ f- [8 B) s1 X) N: {" L/*# k/ D" _* t2 u: H3 x& G: D$ A; I
3 s* }. f/ `* C& F' L
! @, }( [3 K K2 j" g* P6 |
* do the coordinate calculation for this planet p+ j9 ~ R, c. T* v: Q, U6 y
# _" S8 z1 m( K$ D3 [1 g( r; z' \2 U9 |+ @
*/
+ y7 S+ p$ C( X4 a& c& biflgret = swe_calc_ut(tjd_ut, p, iflag, x2, serr);
! E2 Y; ]! V! H( R! V+ f" Y+ p) j8 P2 t6 J# `
3 H% ~- \+ r- U4 f8 `5 c
/* Swisseph versions older than 1.60 require the following
$ U6 Z' B& X3 d( g
! Z# j% }/ }# M8 B' U# G2 h2 q# Y' h* statement instead */
0 Q% m5 I# G' d/* iflgret = swe_calc(te, p, iflag, x2, serr); */
8 z: ]; |8 n' H, P' a# w* M
( a0 M, {3 U3 a9 J# m
) n8 M8 c8 Y, u7 Q7 m/** o2 a7 s) d* } o1 N
. m1 E3 b! B/ `; _/ q& i7 Q/ @
5 D' P4 B ?! P* if there is a problem, a negative value is returned and an & o( C. ~! _( Z9 {& \. f& H
2 I, m+ y* Z8 H0 M
$ I' H: i3 b- y9 v3 J, g
* error message is in serr.( v7 B3 l) v- Y+ b z! S0 j: ]
S5 q* M& O: d' I1 V( ^6 L& t0 N0 b9 \. {/ C
*/
9 S+ Z* Q% }# R
+ F8 j! Q8 {. | M# E* uif (iflgret < 0)
5 h9 v0 o7 q, ~6 b {/ V" v. a$ h4 \2 K8 A1 |$ Y# v
printf("error: %s\n", serr);& }7 o* v# Y! y: |: O+ `
" x; w2 o8 X+ f/ F0 J% e
, Z, \9 o* P, v( Q5 b
/*
/ j+ P1 J: c$ e
3 i2 p7 j4 S% v4 Q7 K9 @3 r0 A7 C0 {2 k
* get the name of the planet p
1 x, h! i2 i2 T! y( J2 I0 S9 ~$ L8 f# G; @& ], ^4 c$ S# f8 a
( _! }8 |) `- S6 v& {( a* V
*/! O9 D! W3 u$ N( N1 t
/ |- [, u, C6 a- ]" z9 w% @
swe_get_planet_name(p, snam);
0 B( a" k1 F6 S* G/ D. o; ~+ V4 g
0 Y- L/ Y* e6 S
/*+ {' w& [, k8 l1 C$ |. Q; F4 S, K
- a. x* L/ G' V6 [- \! |5 G6 R: x( `: h2 K
* print the coordinates. B B6 i4 u# U/ K |
: [) z! c- ~8 e+ v
6 l3 W1 Y) g. o6 |! D% `* I6 h; W*/0 ^/ _6 j! S3 V2 Y& T; ]
8 _# H G* L" J$ qprintf("%10s\t%11.7f\t%10.7f\t%10.7f\t%10.7f\n",
: V1 T" d6 e3 i) h4 w% y- e! `
# t% d. O! ]4 Y" r! E; {% }8 osnam, x2[0], x2[1], x2[2], x2[3]);9 \" w2 T9 h7 N' x% {( G- Y
a L1 T# \; q# b7 u1 G8 s}0 }. @7 ^( L9 l7 w
) t! ]5 g. Z+ L) B4 |; o f}
. A8 n0 z. G* K, U: C% D7 `: C4 v4 |) t/ H4 P$ }9 n8 X: j; d0 O/ l0 z( w
return OK;0 s- B3 S' J6 j; c0 j7 X
} |