1. The programming steps to get a planet’s position 8 `! v2 f8 w. M' |5 e. A7 G
To compute a celestial body
7 @( {4 E7 i9 ~: _4 c9 p0 D4 G! k) gor 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.6 ^8 H/ b- U9 g( x' ~
8 z+ C, B9 }) v2 [& B7 Z8 Y1.
5 `! b! P- |' xSet the directory path of the ephemeris files, e.g.:
% J# `; s( B* k8 Y# ~; v S# L+ F& n; Z5 }) V. o0 k* O P( \
swe_set_ephe_path(”C:\\SWEPH\\EPHE”);! X5 H1 B) o) R0 Q+ r
1 y7 K" Z2 y& p* ^5 [, Y
2..% S9 F1 w, K" i" T( E2 e
From the birth date, compute the Julian day number:
( Y% w' I6 d$ A v1 ^
6 g) R8 ~8 x4 R! b/ i, i1 ?jul_day_UT = swe_julday(year, month, day, hour, gregflag);
4 k, K' \, } R* c; s( q# D * d8 N/ q8 [3 d) r) h& C7 F
3..6 J: s$ W$ z( q4 s' D9 y- Z% }
Compute a planet or other bodies:5 K* Y7 E7 B, A) u/ |2 x& x" s$ m
% z7 U9 z; a! _( E5 T: u7 j, Qret_flag = swe_calc_ut(jul_day_UT, planet_no, flag, lon_lat_rad, err_msg); ; I3 d) P' A. V) F8 h
# U4 G4 Z5 g4 ]% q" a6 y. J
or a fixed star:8 y( S- {/ \: [: t( P$ I
. Q# m+ x" }/ f7 K
ret_flag = swe_fixstar_ut(star_nam, jul_day_UT, flag, lon_lat_rad, err_msg);
, b# n$ P% Z; m9 u& Q/ z% d 6 d- c( g2 U8 Q! t6 C
5 U5 W$ h& T8 N/ o1 T5 l# {/ pNote:
; P4 d( n% W- I8 L7 |+ g
/ X& @ y1 q& t4 ^" cThe functions swe_calc_ut() and swe_fixstar_ut() were introduced with Swisseph version 1.60.' I( G ^% w: Y
6 U, n, U8 f9 S5 O8 i: s% E1 o* w+ N
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:
* |2 f; h; Y3 K2 {8 A$ b: t
]8 T4 `/ s, d+ K6 g: `( B5 J8 A2 }1 }& B# N
First, if necessary, convert Universal Time (UT) to Ephemeris Time (ET):
. P0 ?' ^9 p( _, ]* \8 Z% f- i- o2 b9 P( p0 S1 t, H+ i* X8 b5 w
jul_day_ET = jul_day_UT + swe_deltat(jul_day_UT);5 P+ y( M. [6 n
6 Q0 p3 y) d# @2 j( w9 k) U3 c2 Z- F" f; A1 w6 s' L) r
Then Compute a planet or other bodies:$ `/ v( N! h* F" N
8 t' B1 f; d" H; gret_flag = swe_calc(jul_day_ET, planet_no, flag, lon_lat_rad, err_msg);
) L# L9 A3 c U# T" K9 A8 }/ b O4 j% O; m, O( ?
or a fixed star:5 R& g! p5 _' x7 }7 X
" V* Z; c1 Q3 `# P# x: |+ r: hret_flag = swe_fixstar(star_nam, jul_day_ET, flag, lon_lat_rad, err_msg);
; {8 C! \* b; @: R: O
* C/ ~/ P- @: N- w5..! c6 C% F! b# v5 ^+ i# B4 x
At the end of your computations close all files and free memory calling swe_close();# P3 i* B8 ], c( C0 M
& @/ _/ S8 ]8 J1 P \* a1 xHere is a miniature sample program, it is in the source distribution as swemini.c
2 E( w* v2 ]8 `( ~% E8 d* L * N/ B) [# H% i& F4 A9 M. m
#include "swephexp.h" $ y& z7 O: t! t7 T" [5 n2 B! M
/* this includes+ y/ b! V: K6 m& I0 \7 d
"sweodef.h" */
$ [' K* {! j) N% n2 y8 }! Lint main()
, Z' R' b* d, @9 u+ H( b+ N Y5 z$ O{
; Y) m( @- ?) d2 k
1 r. S. [9 ]( f( ~char *sp, sdate[AS_MAXCH], snam[40], serr[AS_MAXCH];
7 t* M8 [/ b9 a7 S
& w6 ^- G3 r [ I4 P0 C9 w. ~0 M- \; C8 u% l
int jday = 1, jmon = 1, jyear = 2000;
8 G4 ~2 ~0 n/ @0 W. c6 u( w2 n& Y# V8 j* Q
double jut = 0.0;2 @( I |1 U! Y( g9 ~
, m) f7 Q0 ?# V
double tjd_ut, te, x2[6];
. `9 U! Z, V3 v+ A5 I
4 {" N+ Y3 o: G4 B' q. |& Wlong iflag, iflgret;
% \" L4 U: d" ?$ v9 d
1 \2 K! Q) J4 S, C; c- t/ m) Cint p;6 z Z" L4 w1 f& y# M: L) j2 z; G
/ _. [# i9 r* V& qiflag = SEFLG_SPEED;* M9 U' n" G0 B7 F j
. \3 q" B( _+ y; I& V! iwhile (TRUE) {
2 [* V& W4 L5 ~ h$ p; O: }8 D4 G* [/ @0 w* _; y# U! [
printf("\nDate (d.m.y) ?");, I3 Z& q0 A7 d8 x t8 b
7 T( H5 w1 }, ]$ J2 U$ Jgets(sdate);
& D7 P: P6 F6 u3 s6 \) p# {) d0 Q" i8 m+ Y* z7 [
/* stop if a period . is entered */
& M/ K( V: ~5 q) k
0 H( m% ^4 Z1 I4 P( ~if (*sdate == '.') . R( E1 a+ K" n" e' H
" T: P- j) [4 T6 {4 k o. c2 sreturn OK;
0 M4 C, Z o7 D2 j) Y" \
$ c: S i3 W. I# f+ X0 u% wif (sscanf (sdate, "%d%*c%d%*c%d", &jday,&jmon,&jyear) < 1) exit(1);
0 ~9 N: i- ~7 W0 @2 S# v6 f: N
1 r% S# T! u- n& j+ t- s( _- l- C) e- j l8 S; V
/*
5 B8 ] ?. g/ x) {5 J- B2 D/ W$ U- {6 Y z
& g* O! g. ?$ I1 A# f2 e: l% ~2 @
* we have day, month and year and convert to Julian day number. t% _0 W |3 P+ ^& W& ^& R
5 |8 _( ?! D) e% y: w
* H( e$ a( S3 v9 v' C- p1 Z# ?
*/, l* s2 C; |0 i" }* L$ X- ~6 V
7 x- X d' i' R6 [, N) A- J
tjd_ut = swe_julday(jyear,jmon,jday,jut,SE_GREG_CAL);
( u3 n5 Q- V! G y5 r( ^6 w5 s5 ]* ]' I N+ @$ c( u+ K$ Y
! r* O* Y+ i* W7 D" g
+ q2 H. G8 o6 R& ]2 k( t/*- F0 ~3 {% T1 G# _, a; W3 Q
* G6 V& D f6 Q# b, s1 k: L
; b5 V# p* x6 I1 }) \4 ~* compute Ephemeris from Universal by adding delta_t
, x" |2 U) c) \ ]' w$ ~5 u; P8 B' F5 d9 k) t, g% f
6 x# V' q9 u+ m' U+ |, O" R* not required for Swisseph versions smaller than 1.604 E7 V& O$ O# j6 i. z. j* r$ Y
( J0 d$ _9 ]. R8 _9 Y$ Q, {1 e+ G+ X) X; Y. o+ ?6 q9 @
*/8 t7 Z0 e$ W9 e$ i
7 K/ a; L6 N$ Z, o0 A/* te = tjd_ut + swe_deltat(tjd_ut); */
4 N( p7 K" M' ]0 m
6 v/ c8 |5 R( @9 ?6 `# e3 |. Hprintf("date: %02d.%02d.%d at 0:00 Universal time\n", jday, jmon, jyear);
, Z& p. S+ F6 ^$ D# a% D9 Q1 Q6 p/ z. n N4 \! w& G" R
printf("planet; x! Q2 {$ _7 {
\tlongitude\tlatitude\tdistance\tspeed long.\n");
- v7 X5 W; J' u7 j% `! z. V$ c& A* m( `: F
) T1 f( Y# n a: S/*
( V2 i3 S! ?. x. _& _- d2 L- R9 G2 q% v
7 u0 L8 u4 \; a C* a loop over all planets& \4 z' `+ @# f) R( P9 v; m
) V7 G G# A. C& j3 m2 R6 {9 i- c/ A, m" Z
*/2 z# n; D' c, S {
7 d( s( _0 s- W0 \ ^1 Z
for (p = SE_SUN; p <= SE_CHIRON; p++) {
0 i( z0 E9 X! M' @) ~" ]1 R
3 c9 v/ I3 ~6 l" [& iif (p == SE_EARTH) continue;8 g/ z4 u5 K8 W6 S) u
( \7 x- X+ u0 R d
/*
; x4 u0 {+ T% @4 |
0 h8 B( D, Z6 s
0 O8 l! D( Q% [; h1 g' v* do the coordinate calculation for this planet p
5 D) [( e# G, u) g0 C9 f0 D% c* p0 q r0 i: G' \* z
2 V- {" J4 y. }- }% Y
*/
; R! D% V; r! |5 c6 miflgret = swe_calc_ut(tjd_ut, p, iflag, x2, serr);2 ]2 x# t5 V; O6 e: t9 v% U, Z, D
G, X1 e F4 ]- G3 n2 e% Y: {9 G2 @+ O5 V8 f2 E% P2 S
/* Swisseph versions older than 1.60 require the following
/ K5 s. L5 v. b- [2 w( p, H9 T9 \" q+ S2 `' e- y& K* T7 X' L H
* statement instead */: [, q [# R# A/ X( v$ y
/* iflgret = swe_calc(te, p, iflag, x2, serr); */+ i' \. _# w& D8 P% F7 s0 I) D( s
$ }; W1 ? ^, V3 {0 d5 t
( v& v5 S, `# h: I" u' O/*
* O& K* ^+ s4 m2 v! x
( q& m& F$ A, r
; f- P) n2 Y9 e( M) F5 h: R* if there is a problem, a negative value is returned and an
$ y; G, ]% V9 W9 I6 R
. c) u0 B4 l3 S% V% N8 Y* a& v- k8 }) X! g! f, C1 P$ G+ ~- X' D
* error message is in serr." T7 R, ]9 ^2 K) k& Y+ ^
/ w2 N+ M4 e3 E
7 k# \& W, z+ [& N N3 @*/9 O7 _ f# |- g! {$ \1 G I
9 @; _: e" x3 b" g7 Iif (iflgret < 0)
3 M) d" j. ^. O$ ~ Y& q' x- W
7 [, n( |! G l1 ?8 l, I1 @4 i. [" J( \printf("error: %s\n", serr);& K( {' \4 i |3 i& a
' r0 @6 w$ Z V- [/ Q2 G2 v3 d6 C2 S" `2 F! \" |& ~
/*
! l! l2 z5 h9 W: _' y0 g/ w" f" K% {
* G" ?* U4 B8 u
* get the name of the planet p* c" [& ^' r/ _2 g- Y
0 C5 N& i: G, W( G7 j1 c% {! P6 `
# e8 W$ R0 E# v*/: t# C! D# I0 E- B' K& V
7 `$ k. A/ w% ?8 W7 E; x
swe_get_planet_name(p, snam);
! M/ L" {! h F u% a/ R% ]* b
$ U5 V$ R6 o' {- F6 l6 ^2 _& {+ W/ x J. N6 `3 S
/*. h7 |) {1 N- e e
: Z7 X3 }) S9 w! y9 F4 X U6 s% u. N
* x* P, E' Y0 [* C* print the coordinates/ y. I* E$ f$ ?% U" @2 m/ k8 k
& E% h/ [+ w Q0 b' Y# q
1 m6 P6 B/ N9 D1 t*/3 e6 b: X6 |( q- Y$ q
! s# m9 T/ w' n) K8 o2 [0 \: C `' eprintf("%10s\t%11.7f\t%10.7f\t%10.7f\t%10.7f\n",
; X$ S, U# W9 C' T+ U; J8 S' Z3 V7 ^0 {
0 s& F- M7 r" i; U
snam, x2[0], x2[1], x2[2], x2[3]);
/ D# k- S) }/ b# ]2 s4 u, h% F/ q6 b' W' v$ C
}$ I# Q5 @% R k+ m9 j& W$ S
# M. i) k/ v3 V! M! a}
( c2 b6 T$ f+ c9 P5 Z) c2 x: ? N, ^1 I% i# i1 j
return OK;
$ f4 A' S+ n1 F4 z" D! }, u3 V, N} |