The programming steps to get a planet’s position
9 y6 q$ X) e# BTo compute a celestial body; v1 A4 o/ s M: X
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.4 c. f8 ~2 {' y/ G
- w& {8 Z( t9 h$ Z$ G7 ?' c% H
1.
* t: X4 D* c! J; PSet the directory path of the ephemeris files, e.g.:
/ D% d+ f8 G5 J3 A r6 d# d) g0 F3 d9 N2 k7 g
swe_set_ephe_path(”C:\\SWEPH\\EPHE”);
" q0 g6 v( U3 W 2 [% }+ j, `3 L$ w. z
2..! H0 P6 Q" L! s! B$ C
From the birth date, compute the Julian day number:! }1 a+ b9 N6 e+ X& c$ a
3 D6 R9 P- ^% J( I
jul_day_UT = swe_julday(year, month, day, hour, gregflag);# l3 c q+ V. _& V; }2 x( g
# A# a7 s* \5 ~! w3..( Q' p: g9 G) T4 T% [
Compute a planet or other bodies:
9 e9 i0 o! f; I7 @. t; F% `! p6 [) C0 i0 j& H- }2 a; H2 ?1 L
ret_flag = swe_calc_ut(jul_day_UT, planet_no, flag, lon_lat_rad, err_msg);
; A2 c$ T# B+ O" v- F, ]7 M% W' m5 {& e9 T' j
or a fixed star:
9 `1 y7 E7 o$ h6 [ A8 v O0 K, u, d* ~" k
ret_flag = swe_fixstar_ut(star_nam, jul_day_UT, flag, lon_lat_rad, err_msg);
9 k9 w1 G n* S1 }) e: q$ k
5 N3 ^' Z' {0 M G" d# I+ h
6 b3 P3 W$ k j, }8 fNote:0 h% o o5 Q9 F6 L+ O8 Q
# g2 ]. o: q6 P; V. r8 b$ `The functions swe_calc_ut() and swe_fixstar_ut() were introduced with Swisseph version 1.60., N& u8 r( A) x G
+ x, q% D! u4 l
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:
7 v w# ?: D) K: D: C4 F # I5 h k- C& z; E8 X) e0 p
, A( s* r0 t2 `( l2 ^1 E
First, if necessary, convert Universal Time (UT) to Ephemeris Time (ET):
9 \ S* p/ B# H
; }- S [/ f x4 \jul_day_ET = jul_day_UT + swe_deltat(jul_day_UT);0 r! h3 c9 z. f, M6 s
& R6 W: f' V% }
0 R. K1 ]) u8 U) O" i: H* o4 Z
Then Compute a planet or other bodies:3 A, [1 o; X4 i5 Y$ g
9 X G( ]1 C. p" Z. [* r
ret_flag = swe_calc(jul_day_ET, planet_no, flag, lon_lat_rad, err_msg); $ C6 e: E8 ~8 [& n" g
0 a0 L: r5 e, _+ O! v9 f5 for a fixed star:% l5 E. C8 }+ S' X1 M) F* {
/ ]7 E1 s. V5 _% U+ \% B
ret_flag = swe_fixstar(star_nam, jul_day_ET, flag, lon_lat_rad, err_msg);3 Y7 K6 }( |/ e" w/ I( j- ~; U
0 O' P9 z! }" u( ]! @( q5..
. q R) ?. p: C3 L, w% yAt the end of your computations close all files and free memory calling swe_close();$ V) J) s3 P4 E* I8 N4 A- q
$ H# j9 S7 c) t9 O( r4 D: I
Here is a miniature sample program, it is in the source distribution as swemini.c1 ^7 L" a8 O H: _: J8 {
! q) k7 p4 _9 r* G9 h; T
#include "swephexp.h" % Q3 I* i& t# r2 D
/* this includes
0 J9 V( u8 a! P0 v$ g& t"sweodef.h" */$ G. E* C, d/ R
int main()
, Q$ n+ x" [6 @; D7 @5 N( Z! Z5 T{
0 c j5 m( h/ b* y4 v1 p( W$ T0 Q! x
char *sp, sdate[AS_MAXCH], snam[40], serr[AS_MAXCH];9 f7 e7 X# p3 H* }, A9 J- Y4 q1 u; b
4 g' A3 V# {0 a; l
7 _) K/ z Y7 a9 \int jday = 1, jmon = 1, jyear = 2000;/ }. h7 ?' r- f0 O7 f
. U! @2 m' l: p: D8 ?. l2 f5 X. j: U
double jut = 0.0;
3 G, @# f/ b, h# I( ^$ U. S# Z2 O9 ~" S" e
double tjd_ut, te, x2[6];
" c, @2 @' S' l! Z b# D
' s, Y- z) z9 z- @- qlong iflag, iflgret;" C& ~. Q* G" c1 T4 g9 d
# x4 Z/ U' a, b1 t3 c ?5 _
int p;6 M4 g" L( b9 P. Y* {
6 R$ L+ S) `, a, @0 S# ?iflag = SEFLG_SPEED;
0 z' _$ K' w7 l1 E
! p4 b [; w U0 j3 q7 z( r twhile (TRUE) { P* P8 o& a5 i8 ]1 Z# y Y' t
& q E3 }6 m6 v3 I+ L8 Rprintf("\nDate (d.m.y) ?");) [' h9 ]( q( c- ?9 `
5 B5 X2 X: V( L/ I3 j
gets(sdate);
) ?6 p7 R1 C+ d; f) A' j. g q
/* stop if a period . is entered */
/ Z; P8 Y5 L2 J5 g1 k
: b5 H! p) u* s d- {, h1 gif (*sdate == '.')
8 S6 m. Y6 ]. I# ^8 ~/ U5 g& v5 V6 T; ~7 J4 o0 Q" z6 S( b
return OK;
5 ~& \7 o6 l& Q: |9 F Y3 A6 {2 A" l: ? x# Q, O! E: |- v& g9 C0 I8 a
if (sscanf (sdate, "%d%*c%d%*c%d", &jday,&jmon,&jyear) < 1) exit(1);
$ ~+ ~/ m- s! S4 O9 \: d4 E t+ x/ w" W- ~ B# S4 u! x b
5 m! M* [' [+ [- q! c4 P( B" I" {6 z
/*! |3 T- [( i9 f. r, M" ~; R( ^- H
" B* r0 ], Q1 c; O, J
! W; I3 t+ u. O+ K/ x. `7 L& `* we have day, month and year and convert to Julian day number
2 u, S/ V: f# h2 g/ z H
! H) N3 c: o- O3 l3 t
3 H2 m: ^4 {# w1 g*/2 D O7 i0 a3 F! S& K# i8 \
$ _( s& k1 ?3 i1 qtjd_ut = swe_julday(jyear,jmon,jday,jut,SE_GREG_CAL);% J0 N1 d/ y* L5 Z
% a1 h+ ^( X: c" U
* W! m; G9 ]) v. a; u2 G6 o e0 _1 [
/*/ r8 K- Q! T) ^
4 A7 F& b$ Y ^! X6 \& Y" v2 J/ ], x Q ~. N7 \9 I. t
* compute Ephemeris from Universal by adding delta_t" j' K$ ]! C; U: ~
+ k0 _: t" { w' ^$ K( S
9 `0 f+ j! F8 Y: u+ y: L
* not required for Swisseph versions smaller than 1.60
" e+ @" A4 f: \% }2 e+ P
7 Z o9 F, K2 u2 A7 L1 D! p4 a; n7 Y( Z$ W3 H8 D4 `, p
*/- I8 j* [& x5 B2 P
; I# j7 V0 q9 L/ E3 S/* te = tjd_ut + swe_deltat(tjd_ut); */
+ W/ ? g" f" v. X) S# Z# S/ ~2 D8 l8 O! d% x
printf("date: %02d.%02d.%d at 0:00 Universal time\n", jday, jmon, jyear);0 n6 W" f* r5 g6 G- K
; M. y, O, F% z; p# |( Z f
printf("planet7 B- M* S/ l$ M2 \' z3 ~' R# k
\tlongitude\tlatitude\tdistance\tspeed long.\n");5 X4 I, _" h6 G% j' _
6 c8 }/ F* d, Y% [0 A' n* s! a; c# `9 S& m, R8 a& w) o1 \6 e$ `8 y
/*' X$ l6 e% k" N
; p T; A6 j+ J3 e4 |
# t- S! @$ g8 O& z- t# l" K7 c A
* a loop over all planets4 k ^* A& n& c0 {% O# a9 E
0 P% ]; m- h- W6 N1 W- T( ?* d5 d ^# I
*/1 w0 E/ K# {5 W- f. b
$ \) d: m8 u# X! Ofor (p = SE_SUN; p <= SE_CHIRON; p++) {
! t! S- i1 x0 x1 M1 C! t; ?0 z0 ~* O( O4 Q1 L$ \* \. E# n7 [1 n
if (p == SE_EARTH) continue;# `! x7 w+ z' t1 \* @' t9 b6 L( U
1 }9 o5 r% V' M/*
a' g' l; y* V$ Q: x* t* @7 r1 x n0 x9 N& T, u, o# ^
, \- d' Y; K) j9 e% D4 o
* do the coordinate calculation for this planet p8 b0 g- q& u' w( v3 a" Z
: j+ Z' q/ M- F% h* \) A. `4 M; [
7 Z2 A0 A. h* s) r9 z W*/
4 ~/ ?; d! b) U$ Jiflgret = swe_calc_ut(tjd_ut, p, iflag, x2, serr);) k( \! r. ] t0 }9 g$ Q# N
. u i v& P4 o+ q" D3 s1 J1 }/ J" e3 a- F
$ t" `4 k$ P1 L5 H. a* ^' U/* Swisseph versions older than 1.60 require the following 2 ^( \: A- o# X' u( W5 w& ]
8 a% Q. d' R$ D! G) P* statement instead */
& z5 P0 j" t* w# N8 r8 C/* iflgret = swe_calc(te, p, iflag, x2, serr); */; M. Z/ G' S/ I; z- G
8 W. E2 B* a( N4 V: ]
: u, u. T- r" H' B1 w8 N/*6 N9 b9 d3 f- S: i! d! \
( I/ a( }1 V; C) u( a
% }2 d c+ i4 ]
* if there is a problem, a negative value is returned and an
; x- t0 n$ _2 S1 a3 q, L! R
; i s* _. |/ \) M u
2 F! F/ I: S0 t1 I& ^6 E6 W* E* error message is in serr.9 V1 p7 R' y: h6 C# y
6 U' W2 Y4 u; b; \9 Q# T6 L0 O( C) W
, _$ L9 C. D5 U& |
*/: }% X4 ?+ O" a* [3 A
! F- \$ U4 ?" b( cif (iflgret < 0) , i v, l9 I- d
4 r3 M* ^9 G; Z+ }+ o0 z
printf("error: %s\n", serr);" U* L, V* a% p' z* p/ @
O% T- G. V1 c7 W( K
! W& e2 x# U6 v
/* r7 w' @ |2 R" P9 h- S% s* S6 W
/ y4 `* ]& U3 |8 _
0 C" g! \6 V0 r% j* y* get the name of the planet p
" I2 z$ U9 T# [; N
. |% e6 r3 t0 R& x0 `/ B- s/ Q3 b! W. o
*/% ~" I; W ?, g' T7 ^% y
- `" z+ b$ f! P6 g* H! ?swe_get_planet_name(p, snam);
7 ~# q8 m/ K% e
4 l: W! `4 B# {; z$ d5 k9 D4 r
% u, l( `( M0 _( [8 d- [/*8 q+ X `9 M, r2 D, o1 Y& G3 |
' \# ~+ w' M1 S, d; y& E! L% L2 \6 q# T8 @' K; R
* print the coordinates" j& b2 N% n" x) {
, z' P5 b, f! }' B
: x* {# ~# c: `: {*/2 J; p1 H& m% o( _8 F$ G5 S' k. i
" S" N1 e: F* j& [0 s( h
printf("%10s\t%11.7f\t%10.7f\t%10.7f\t%10.7f\n",. f. O) \) A) w4 ?( C% L9 O4 [
3 l, a E" [7 v7 }: T3 q* e) \# {9 o1 q. a
snam, x2[0], x2[1], x2[2], x2[3]);1 B ~' {% Z+ c+ g, u, M. c2 q
9 V& z( E5 P6 l4 r# Q2 v# D- I9 C}
0 w( n3 O1 ?( p+ Y& m! _: S' G# H3 u, t& Q/ a
}
$ V, A9 N8 a8 M; I9 Y- d6 f3 H7 S T& v9 ^4 X" `
return OK;
, q! w" b; Z) @9 X3 u8 G} |