1. The programming steps to get a planet’s position . X% A, D! a0 e
To compute a celestial body
& w& p: A. q- d% ]% n" f% C# oor 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.
- A; p3 B2 R6 H' ^( j 9 E* G) S+ M! v; x1 a
1. $ @# {" k$ G1 `, b. U; V7 @. x# ]& N0 U
Set the directory path of the ephemeris files, e.g.: - V8 U% E; }" x% B r
7 a: m) U3 l% e% H6 m$ Jswe_set_ephe_path(”C:\\SWEPH\\EPHE”);
5 T& a! |1 g4 C; z( `. @ 7 P& C8 j' b: b5 R% I& u- c
2..
1 q% l( K6 d* z$ K$ F% NFrom the birth date, compute the Julian day number:. M: x4 L d: a2 K9 l# e, G T h8 @
3 p: r/ F7 h0 v% x2 ujul_day_UT = swe_julday(year, month, day, hour, gregflag);
2 `# o3 L( q' M* b! S+ U
% r4 ~5 _. y! q8 s9 n4 a3../ D8 @' i$ T3 y8 T" L
Compute a planet or other bodies:
7 h5 _" @) P& d+ v. T4 l6 [9 P
+ o' v) _. }- o3 }! |: U; x9 kret_flag = swe_calc_ut(jul_day_UT, planet_no, flag, lon_lat_rad, err_msg);
+ W! L+ ]3 Q. ^
$ k6 r3 @- U7 g, r2 C8 Sor a fixed star:
( q" @/ I4 O" c4 Y/ y* @6 [% }/ k) o9 [, ?) K. n
ret_flag = swe_fixstar_ut(star_nam, jul_day_UT, flag, lon_lat_rad, err_msg);
# j( i) {# ~! z9 Y; t7 i 2 Q& y; U/ n5 J. L$ T+ x
) A* |2 i4 ?: T, r
Note:" l" b Y0 Z, W
# k, w$ y* h2 h/ uThe functions swe_calc_ut() and swe_fixstar_ut() were introduced with Swisseph version 1.60.
$ y/ V, j* ]6 V0 J/ }2 h3 x8 n4 F' E4 W9 ^2 E
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:
% o, B- i# x+ c/ X8 S
; b0 R$ }. L( p- x" ?+ [: N; L# Y. S$ C8 m/ n2 U9 O& A. C
First, if necessary, convert Universal Time (UT) to Ephemeris Time (ET):' ?! w+ o/ j$ U( T8 [
4 o( q+ k2 K" k' h* `* k1 Rjul_day_ET = jul_day_UT + swe_deltat(jul_day_UT);
" I3 i9 _# ], u: Z+ I. p; x
- P+ C# S" ]+ [2 Z& ]% D& d5 {. X" f( y1 i1 q
Then Compute a planet or other bodies:
* o' c- S N1 V7 G5 ]5 `. d9 S5 E; {7 S1 [0 X/ ^1 A
ret_flag = swe_calc(jul_day_ET, planet_no, flag, lon_lat_rad, err_msg); 3 n, O) A5 u! F# A
- Y) y6 }1 q* x
or a fixed star:
$ a, B# n r7 p' \! i0 d4 x
9 P$ g9 m# V" o, S" `) jret_flag = swe_fixstar(star_nam, jul_day_ET, flag, lon_lat_rad, err_msg);( t5 [- }$ ?2 t# ?( w# d3 E! L2 O/ w
0 v/ o5 b- ]0 A0 `* K+ |5..
2 H6 W5 ]- I }( aAt the end of your computations close all files and free memory calling swe_close();
{5 b1 y$ |# l& V' P" h6 x4 G 0 Z/ s$ R0 Y: q0 `- _+ ?$ k& w
Here is a miniature sample program, it is in the source distribution as swemini.c
: c0 _5 T+ `; F2 M; n# T
1 P! i, V0 f9 \! f9 K#include "swephexp.h"
: ^ m1 R2 l( ?# |. h3 M/* this includes6 H) |' i* \8 C' D* P
"sweodef.h" *// N1 j E7 ~: ]# Z% k( e
int main()- k( Q) n' h4 a2 O8 c+ y
{
% l: T; [* s. _- B0 h, f1 _' W* S2 G& @0 ^; g1 k$ @
char *sp, sdate[AS_MAXCH], snam[40], serr[AS_MAXCH];
. R( C, C. ^. l5 o2 e2 p- w! O' {) ?. U2 a
5 C: m- I' K8 m/ W7 N! [+ ?' a5 k! L8 y
int jday = 1, jmon = 1, jyear = 2000;$ {# r% E2 u& X! N4 D
3 g1 n6 |2 y# B" Y& l" pdouble jut = 0.0;
7 x' N$ Q) _& O3 j0 R% v( Y
4 |6 C3 h# o5 A5 l9 ydouble tjd_ut, te, x2[6];
7 f; Z+ [/ B/ p* `/ |& d$ }/ n" S3 A9 y: r( R
long iflag, iflgret;
z3 | c5 c4 m2 I. C) k$ E7 r7 J: C+ l' F" D) e0 B8 {# M6 M& K1 V
int p;
% W0 G7 @$ ~, r8 P! [* o& | k, m& w# @7 ^" Q, c
iflag = SEFLG_SPEED;
, \- S& I& t4 A" I
0 c m/ U, O) \) Kwhile (TRUE) {4 [" X S( v8 H. I( P
6 }. ]: M0 ~& R' Z! n
printf("\nDate (d.m.y) ?");7 s' o2 |% m$ @* T3 U7 H
6 d5 g( x% i: v, @9 Y
gets(sdate);. d5 l7 f1 o2 a5 \
/ f$ |* z0 T% ]4 }/ B0 a) ~; O/* stop if a period . is entered */
( b3 @/ H4 W) E$ M- u
+ ]: A, y. U# P0 Y, Q% e( bif (*sdate == '.')
2 n3 S5 @) V' t7 [- U
0 N' O Q3 d: I- |return OK;
' x: `. K; N3 ~' |' H& E4 i* _$ J5 T/ ]& B$ V/ F
if (sscanf (sdate, "%d%*c%d%*c%d", &jday,&jmon,&jyear) < 1) exit(1);
- d9 ?9 Z/ |: y0 a
( `( ^0 e5 O" @% u6 Y1 F9 U* C# {8 x- x
7 n* [, J$ L9 k* T5 z9 N/*
1 ?( [ E6 \ `$ x$ S8 k: i9 {3 L$ b9 @
- Q" \+ w, B, I8 N0 H0 w4 u# H+ q& \
* we have day, month and year and convert to Julian day number
7 X1 E7 [7 [& }& ]5 {
) T1 B1 t* W1 k8 T8 L( T$ x$ u% m6 m& I a. t& n
*/
6 V, i' b- b1 @8 x
) O; ~% s8 m/ [tjd_ut = swe_julday(jyear,jmon,jday,jut,SE_GREG_CAL);
. V& ?' U. }" t- q
1 }% l! [/ s; |. I4 A( I) n+ D9 j% u8 d$ O6 z
+ ?) G+ @$ ]3 A" j# S
/*- b& h6 X i0 G. @1 ^. Q
( j3 }7 R. t) y4 P5 {' h+ v) n
: N. N0 X, w6 `# Z! i& U* compute Ephemeris from Universal by adding delta_t
G: z1 ^" U+ j$ q, k1 j1 i5 O$ k5 B& l
9 f# v" B6 M- Z
* not required for Swisseph versions smaller than 1.60
$ t' X4 v4 l: c+ d( d' v8 g- N. _( V, ]$ I+ X
+ X7 ~! ^+ {& F. v: @! v
*/
* O q% g5 z6 X' f; |7 s2 V4 \: n4 J: J6 i6 V3 M6 C! B4 f3 C
/* te = tjd_ut + swe_deltat(tjd_ut); */9 @$ i @- L! F6 ]# g
! C9 ^3 Q) r% Y, q3 u! N
printf("date: %02d.%02d.%d at 0:00 Universal time\n", jday, jmon, jyear);) ^1 i" Z2 f4 J0 ^! ?
2 R' `. ^7 U2 `- N! f; x: I3 J( ^! f
printf("planet" e* R9 g0 Y) U8 |+ @+ H
\tlongitude\tlatitude\tdistance\tspeed long.\n");
" p! t# W* ^9 a" D: A- E { |1 M5 @4 j7 c
3 X3 ?. G& |! f$ l& @/ j
/*
9 y3 ]" @' r9 H& S" ]% q! d- L3 p. M
, X- b+ {- b7 J/ p! h$ y, v& W* a loop over all planets. S0 D9 N2 c0 c/ x. l8 Q7 z
8 W, a2 A0 t9 \: @
! e" g* V( ~8 k; {# Y*/* p( d/ `+ B9 I. K( c! m
8 w8 J/ J+ k1 @: ^for (p = SE_SUN; p <= SE_CHIRON; p++) {
' u$ C3 {1 N0 B. o L
" y) K7 ], w6 \3 p. Qif (p == SE_EARTH) continue;
3 }: P7 f7 w& O0 H8 o! k5 D
* A( T2 v! B! v; ?( t/*
+ n3 ~( m+ U/ g; F- N/ Y
( h8 e$ u+ ?5 U% L# a* K$ O* \. R4 j
" J9 o9 n3 w; Q7 m+ { J s* do the coordinate calculation for this planet p
0 u' z$ W$ X- i6 y; b3 N4 {1 h# l) U: q9 e
+ |( j; Y9 _1 V; ~$ D" _" s6 S*/
2 r# d+ d8 \% jiflgret = swe_calc_ut(tjd_ut, p, iflag, x2, serr);
% T. A G* q; _ `, A# I: T1 Y8 E$ x, u0 `6 i+ c( j+ Z! D
, q; b3 z; R. B7 h6 n+ W% t. O/* Swisseph versions older than 1.60 require the following
! R! O3 k5 J% v! \2 I, m3 x8 T2 [: F$ ^* t: D
* statement instead */' m% V/ \, T7 o. G- w! ?
/* iflgret = swe_calc(te, p, iflag, x2, serr); */
% h5 ]6 P; X, N- ^/ q( q5 j* @- T U" m8 U6 `! x& Y% _" P9 _0 Z
) r) }9 q- N( U% S' c! ^ F/** |8 ^4 [# z- R2 e6 k# z
( K) q# c: B% @! y, `/ P' T. Z& M# H* V1 b- o
* if there is a problem, a negative value is returned and an
- d3 p& B: m) s5 M- D: \1 D1 n1 }2 V+ ?2 a P
- e/ L0 A! q# ^* e7 Q6 a* error message is in serr.7 Q3 c Q9 [. X% s/ x
- D, y. B& V3 g7 h
1 J2 b1 R4 f8 [' W3 v- a1 _*/
# K, j+ j2 M5 t/ h" w, x8 \: Z" h, V3 C+ S9 K
if (iflgret < 0)
6 h7 v# A3 s9 x6 ~" m4 Q" `* j: o5 b% _9 {- Z( p
printf("error: %s\n", serr);% `& j) Y$ k1 b, x( R
; K: r7 k4 X0 }9 A% t, c. y4 U. _$ Z% Z$ K' m
/*: u- F$ `: G3 e8 n& Z+ u
$ a- f7 e* l$ f% `; y: E3 i( f" A
; V- P5 d/ @' k5 A
* get the name of the planet p
) U( u% K" m9 n. c2 K+ B
2 l( Y( [7 X5 v& {( \0 e' A3 e A% Q# V# L g' G
*/( v9 ^: E: `. n5 o; _3 z
0 {% }) ?4 g. {& H1 G, q' g/ ]1 e
swe_get_planet_name(p, snam);
" a4 A5 l8 ^1 N7 U
. A9 J5 w" N2 Q; W$ J
; @- ^1 Q/ ]' H% x& Y2 Q& b+ I/*9 c+ Q% l0 T$ C7 V% L i0 Q% u
: }% Y1 k+ t8 S0 H- Z3 Q- Q
9 B$ ^" i) l: I9 _* print the coordinates8 o8 w2 `. L, Z
) w; z" ^ U9 N3 O9 |
P' h+ @# H9 p5 `1 Z6 ^# b, [, B
*/
) [/ u; ~. Q8 n. Q8 I
! Q0 ^6 M' W6 o" ^# Rprintf("%10s\t%11.7f\t%10.7f\t%10.7f\t%10.7f\n",+ h$ v3 _9 B! b1 k& U/ V1 X m
3 u9 [7 r/ _0 S% q9 C1 T. h! }' [0 z8 {! G' p7 ?5 {) ?2 I( v& R: G
snam, x2[0], x2[1], x2[2], x2[3]);
' @& ^( S! X, b4 Y8 t! r
1 o) @, C' W1 j m- t+ i# c}
5 a+ x+ ~& Q! m0 K; a2 \$ P/ C9 F$ A0 z' q7 d& c: ^' A2 u
}
! b7 U$ E9 F+ [1 u% D- l* E z/ j1 j6 `
return OK; l8 `. E+ g* s+ ^7 N
} |