1. The programming steps to get a planet’s position - v. Q6 `3 f+ C* h, y& q3 B
To compute a celestial body* M! F6 i9 H. r/ H& ?/ K6 m3 \$ g
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.
! |; v3 P! c4 D1 M' [" x . z- L6 K9 C7 J7 \: u f
1. 1 d. k3 l4 a7 F
Set the directory path of the ephemeris files, e.g.:
+ r* n' w) S- Y6 B6 H8 r% D
7 [& b }- L0 |1 Iswe_set_ephe_path(”C:\\SWEPH\\EPHE”);6 r/ b5 L7 p4 w _" J+ M. ?
' ^; S" l) n. l* P/ T) _7 I$ W: V
2..
. n) V3 \9 G' t! X/ |5 ]From the birth date, compute the Julian day number:. S3 r/ K- S) w; Z3 U! I5 t
4 i8 X# s0 n5 D7 ?6 `& \jul_day_UT = swe_julday(year, month, day, hour, gregflag);5 l; k2 f7 d: A1 h3 W0 L2 @0 x: g
* J9 D# y+ V4 p* { X: T
3..6 M5 I# [( Y6 e; p! ]2 B; ^3 \ y( a6 a
Compute a planet or other bodies:5 ?# r x5 H: W# i( [
; [8 c5 o- r9 U! [' x$ iret_flag = swe_calc_ut(jul_day_UT, planet_no, flag, lon_lat_rad, err_msg); 9 g' H7 M! a7 ^; c
Z: G4 s3 d2 dor a fixed star:6 C% [+ G& s$ t4 U* O% I
) z2 q v7 l$ K1 `3 V6 V
ret_flag = swe_fixstar_ut(star_nam, jul_day_UT, flag, lon_lat_rad, err_msg);$ k; X" u9 y* v: [- `- J9 t
, r/ n7 Z/ ]& ?7 o, W5 _, ?6 K5 O! {6 p& b& M8 o4 f8 e8 w; |0 q
Note:4 C$ ~. I1 Z1 |$ u4 f. t' c' W
9 w i) r# k' kThe functions swe_calc_ut() and swe_fixstar_ut() were introduced with Swisseph version 1.60.
]6 A. a+ ?9 ^* N) H' T% Q0 n3 f/ W' w* H1 w
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:; F; k% V, T* m( S
% z9 t v1 J. F# c" E9 r
! N; h7 w) E+ W. h& |First, if necessary, convert Universal Time (UT) to Ephemeris Time (ET):0 a, j. j* J, V- _7 c
: J+ g# k5 ?1 G5 T6 \9 M
jul_day_ET = jul_day_UT + swe_deltat(jul_day_UT);
# ^! Y% P6 \" J$ ^9 [6 `' J2 H
9 U" [& y( `5 X/ w- F
. g; ]* T, W$ l9 tThen Compute a planet or other bodies:. u a/ O7 O- _5 |, s
9 ~5 y1 L2 r9 \* G5 N9 G8 v( x, f
ret_flag = swe_calc(jul_day_ET, planet_no, flag, lon_lat_rad, err_msg);
' ]! Z$ s5 L: [$ g
( H: y3 J! ^* N6 z( |or a fixed star:
/ a- D6 e$ w; @" D3 E. g+ j* |2 k) D, ~' V* i+ C# D# H
ret_flag = swe_fixstar(star_nam, jul_day_ET, flag, lon_lat_rad, err_msg);& h2 g$ R9 ^' U2 [& a" K
c) Q& D" ]. d! p, g2 U: A) a( C5..
) a+ ^6 h5 y( [' n; QAt the end of your computations close all files and free memory calling swe_close();& ~) P, f& g1 ?$ |1 n
2 }5 R9 |: P3 k# s/ y) u2 `
Here is a miniature sample program, it is in the source distribution as swemini.c9 ^' R4 u8 z# e# _$ _) H g
3 S; H5 u' v7 ]- _, i* q
#include "swephexp.h"
- D! q- j9 o) n7 W& H' t2 Q T/* this includes
8 |3 q( {# `4 ?: P9 \"sweodef.h" */
( S; ?/ p. s2 a2 ]+ Lint main()
3 X1 \& F P! V+ Q8 u* V% r0 @{# O" P* S% y* W5 ^: O
8 W" k+ \- G" p' c0 l' Kchar *sp, sdate[AS_MAXCH], snam[40], serr[AS_MAXCH];
. A- _+ w1 X+ I* k* p
( ~4 c+ [9 D* t, ]
9 T0 G9 @% \5 r4 ~int jday = 1, jmon = 1, jyear = 2000;
' y9 k0 R; C4 C% H5 w6 A/ v, t4 w
$ {; J' e3 @- udouble jut = 0.0;
! c" N! y# w0 q7 M4 ~0 h; x2 ~9 h, x7 I# H6 q( j1 L/ F. {
double tjd_ut, te, x2[6];+ Z% {! _& F) C9 ~3 i
( k5 h4 S1 Q& N5 G( d
long iflag, iflgret;5 [# g2 G8 M% F3 G" U. m
9 Q$ F- C9 Z8 F. Jint p;
V: t, B5 b9 d
* c# \6 p! M9 V9 Kiflag = SEFLG_SPEED;, M0 d+ @6 i6 ~0 J z3 X% w; l
/ G2 u+ O8 ?1 A3 e: f6 zwhile (TRUE) {
( l% a. T" @4 e5 S* V. y6 t6 ~ L2 T' I# h: k( S& O' K
printf("\nDate (d.m.y) ?");4 @4 m, O8 _" [. Z
+ A2 I& ]3 j6 Z. [3 A2 U* x+ f, l
gets(sdate);
( U1 n1 d: j( H, K" G, y4 Z/ w
0 i+ t4 u0 P9 Y& S7 F3 A/* stop if a period . is entered */
1 @$ k* u, S6 t7 W1 @3 M- T! h+ k) n. a$ U
if (*sdate == '.') 7 D' y9 a4 X- ? O
% `% u) h! f) H" Zreturn OK;, G* p6 _) u' I- x6 h Q j; _
/ K" p+ J% [; E% _, H/ Y
if (sscanf (sdate, "%d%*c%d%*c%d", &jday,&jmon,&jyear) < 1) exit(1);
, W5 B- Y6 y8 d. S' M. a
% {" ]7 M8 F ^: v. }4 A7 r6 P
1 B6 N* e$ U2 o6 C; ~: {& N9 ^6 ~# O/*
4 z4 D5 R: k. |( t0 e* A" M% ^
% V& ]: F5 H. L
9 ]( A3 h7 m4 X0 g7 x* we have day, month and year and convert to Julian day number
5 @! Z. o5 }5 O9 a, R Z6 ~# L8 _" y8 A+ _; g/ Y4 \7 R: m
8 l2 Q- G9 C# T*/
6 E' e0 q! n; a
' n3 ^6 A& t( ^$ Dtjd_ut = swe_julday(jyear,jmon,jday,jut,SE_GREG_CAL);
* O3 w3 V8 q3 E r$ s
0 n2 V* u9 h; e1 c# D" g3 C; d) F! J* l
$ P, k" ?* D2 Q ?9 }. N' l6 g2 r$ A5 g: X9 z
/*: w6 P% B6 d3 y/ q7 c' g3 Y! D1 f3 O
1 {3 w& w* f" w% y& r1 p" w+ C- {9 w: c9 x; Z1 x4 f9 p4 G6 q
* compute Ephemeris from Universal by adding delta_t
/ k" Y |! c2 w: [7 C; S: ?. g) ^% S3 O/ f; \1 \
2 `# z. w W) p* `% T* not required for Swisseph versions smaller than 1.60& t. _ B- T% K
3 U- L' ?) n, G4 k- W8 c; c0 m* L$ W! a; @5 F& T- w
*/
& ^( B, Z* u; }( @- J
2 t3 J8 F: M) |2 m1 I0 n/ }# e0 q/* te = tjd_ut + swe_deltat(tjd_ut); */+ Y$ J2 Q3 m3 f/ d
y% L& F9 {' e* T
printf("date: %02d.%02d.%d at 0:00 Universal time\n", jday, jmon, jyear);4 `* j' _7 R' s/ P% ^. e
9 y2 s! h T' {( f* i
printf("planet& g2 q# n, `( U y5 n# h
\tlongitude\tlatitude\tdistance\tspeed long.\n");, M- {& t2 g, j2 @5 T
; [2 J' _+ I, {# E
) P% j% v8 J# G4 u9 b) U a, M0 ]
/*
9 M) M4 ]% u( j- U9 r5 S( a2 u) i' p5 h) A: @
2 s- M! W0 m9 ]( @* a loop over all planets( ^( E. v8 Z7 n, S/ S2 A X+ Y
: d0 o1 G) s# I! h
' l( B9 y6 S& n1 e b*/1 J8 ]: s% ]9 V/ D% R8 l
( M7 }2 T8 \2 zfor (p = SE_SUN; p <= SE_CHIRON; p++) {
; r: K0 i: B/ t
h9 h% W; {3 {if (p == SE_EARTH) continue;4 h7 R# z6 B, s* d9 C
8 D7 Q' G! R2 N/*
3 e+ I$ s) f; L) B9 L5 r: S7 ~. m% H% _3 ?5 n! k
. l X0 v0 _8 |
* do the coordinate calculation for this planet p4 K( C2 c; b1 M5 Q) ^7 |) [/ M
$ r( J8 ?( n N7 t6 ?( m
* o! t9 e$ |; K, h*/
' _8 g- a0 K5 l( \iflgret = swe_calc_ut(tjd_ut, p, iflag, x2, serr);# G5 J- J0 L2 M& T
% q: E! ]6 L; p* [9 J* l2 w9 d+ ]
4 d# t+ ^7 v4 i/* Swisseph versions older than 1.60 require the following
2 Y+ O; j% R9 s- R, l2 b3 _8 L0 [" [2 {: G$ K5 q3 O! g" T& w
* statement instead */
# I3 g. L; E# [5 ~6 S/* iflgret = swe_calc(te, p, iflag, x2, serr); */
: A% e3 @" w0 f' p$ t2 l! `1 c7 n/ b0 w* I( o5 d
9 D u1 v5 X( _, ^% O+ j. w/*
/ G1 m& }. v/ _" p) k: h5 V5 e& R6 H9 o* n
3 B) S+ ^; b {- A' v, M* if there is a problem, a negative value is returned and an 9 F6 j# w0 D1 i+ U$ i$ D
* E- l4 i4 _$ h9 ]8 i P
! z1 m) _6 ]& t, D3 T* error message is in serr.
' q2 l" A/ `* c- d# i
6 t9 U. s8 p: @& G# g0 @0 Z3 `! e1 T4 w4 V# w
*/
+ |9 h5 F+ F, x6 ^1 r1 p4 \, S. `# b* o
if (iflgret < 0) 0 u$ D/ L( I% p& ~9 [
! l+ x) r1 v. gprintf("error: %s\n", serr);0 }% K; @8 a# d( \4 Z- q. ?# i
4 r3 L( v. w& o5 _. t4 l
( t! Y4 l& K* l) c: \" I4 I/*4 k1 _3 g* k" M+ s% C0 b8 w$ j
" V8 p, S( S0 l5 Y( w, v
0 s( o+ m5 k6 b* get the name of the planet p% I! U3 P6 g/ _3 x3 O/ C- m6 w
* J' r) i: b; T& r* `- _) \. [/ U3 s3 U
" S% |4 Q5 k" T+ s7 U*/
# I5 x: p' ^- A5 o" D' h4 @9 t9 v- l2 w7 N" z7 x/ f$ S }
swe_get_planet_name(p, snam); ~8 L }0 Z. M! [# W
5 d: X7 E% W2 Y' a4 [$ D( e/ m
+ M$ H: B/ ?& X( |* e
/*
2 V! G B0 e- {4 b1 V: ^
2 G4 z( F- }: s+ o, B1 r
9 u! h- F7 g9 Y0 P( y! s0 `2 L* print the coordinates4 e1 y7 n0 N! a. S) m- V+ h
* n) V4 n# ?* K. |. m5 b3 `6 L7 _, J( w3 L: ?4 d, q1 n7 v
*/6 l$ X% N% c" Q. @
) {/ c* L# f- y& F0 M4 F9 bprintf("%10s\t%11.7f\t%10.7f\t%10.7f\t%10.7f\n",
4 K' I3 h! H) u. j& x& t5 i, O% o; G1 e9 e0 w/ z9 r9 Z) J
a, J7 q: f! G6 ]% s0 p; r
snam, x2[0], x2[1], x2[2], x2[3]);
# ?: o/ ^" q) a) E" j* f, Y; L( W' W
}
6 X$ L% U& B* m8 H" D5 q: S& }9 m; Q1 B F' T1 c
}
) c2 R4 b! F* e# |/ b$ D n0 a2 k" U
return OK;( t, m, b, Q7 h5 X$ |: I& R
} |