1. The programming steps to get a planet’s position
2 ` |! A, T( Y6 \. P2 HTo compute a celestial body r! G) Q& V1 \$ f
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.
1 m6 u4 P/ x+ [! i9 s 2 F1 I5 K3 h' Q0 M4 C6 `* \ `
1.
" ]( N' }* [6 c3 MSet the directory path of the ephemeris files, e.g.: 0 d1 \, c( M* o* k
' L# _4 A- W9 ~2 t P$ O
swe_set_ephe_path(”C:\\SWEPH\\EPHE”);% {! H( O3 u, b
: Z* n# ]4 |- p( O9 j' X0 ]
2..
" j' u, K6 D0 P- ~/ _; _) z, oFrom the birth date, compute the Julian day number:* W3 P: a4 @# \) F0 u
/ X( H: v. h( D
jul_day_UT = swe_julday(year, month, day, hour, gregflag);
& _- P3 U& l) v7 j+ M) I9 G 0 X7 m: A! L3 {% K8 b/ }
3..
) ^* b2 a- e6 ~7 T* U5 vCompute a planet or other bodies:3 D/ v9 v7 I7 p* q* V+ I# ]
6 x& Z7 `" r3 fret_flag = swe_calc_ut(jul_day_UT, planet_no, flag, lon_lat_rad, err_msg); # v5 F3 _1 E3 S% o8 O
6 i+ [) |' P: l0 Por a fixed star:
% I: E3 D k- g( F1 v
* B1 C' y% G, a A- L" hret_flag = swe_fixstar_ut(star_nam, jul_day_UT, flag, lon_lat_rad, err_msg);4 U, i' {1 i% { J O4 ^: t4 ]' k
$ I: u% f2 f3 b5 O) N4 G% ~5 \2 g4 l# X# V
Note:
m4 U. P% d& f! E I5 Z. L ~- _
/ Z( i/ z& a1 p" \2 i3 u# ^The functions swe_calc_ut() and swe_fixstar_ut() were introduced with Swisseph version 1.60.
' K5 U" x4 f0 F# i6 X" _1 ~1 H# S- ?
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:4 o: _% e1 }; m
# j0 ]8 R5 a5 Q ?. \' R% G `% j
First, if necessary, convert Universal Time (UT) to Ephemeris Time (ET):
; ~6 z0 \! a# e9 E* {1 x; f7 m
- [7 X; \! |: z2 [jul_day_ET = jul_day_UT + swe_deltat(jul_day_UT);* ?9 ~2 o1 Z9 n9 ]* P- _
& p5 ^5 G8 u) t( Z
0 u0 ^/ m' g: x" c8 f$ \8 x/ ^* G
Then Compute a planet or other bodies:
% s' w/ z L* a! y& i$ n+ {! S
t+ x* p) m7 c2 h/ m0 B$ Eret_flag = swe_calc(jul_day_ET, planet_no, flag, lon_lat_rad, err_msg); 0 I! B9 u7 V3 g0 |1 Y
& ?5 A0 V( e: j5 sor a fixed star:
- ~ D) @* a% [4 D( s6 w7 D" z4 }& T! S9 D
ret_flag = swe_fixstar(star_nam, jul_day_ET, flag, lon_lat_rad, err_msg);+ u8 \6 y6 e( [0 f
' L6 j' V9 ~3 y, Y' C3 {7 z2 ?
5..5 ]# L* Q* B* O" {
At the end of your computations close all files and free memory calling swe_close();
1 _+ O6 E" t3 n( }! |
1 |; K: }9 m, D" \Here is a miniature sample program, it is in the source distribution as swemini.c( D' N9 E% N6 v1 B( @
# p O7 O8 U4 n$ V#include "swephexp.h" " V) C# s" z5 \
/* this includes
* A/ s/ ~9 j8 i+ D, H"sweodef.h" */0 j( ^' c2 j. O# F! _' W, Z& T
int main()& \ l9 k( p `: l! ?
{
3 k3 c5 T* \# z! y2 |0 c
* t" d4 e7 j6 Q, Y9 ~8 \' ]1 fchar *sp, sdate[AS_MAXCH], snam[40], serr[AS_MAXCH];
. U4 d1 j. ]. J+ |1 @
: B& a1 a) ^+ D/ D2 J; V- f' ~: T4 E0 n9 P& X; P$ W% p
int jday = 1, jmon = 1, jyear = 2000;
# h) t1 o4 Z c" \- q
- J" \ P& d% y* A4 D/ Ydouble jut = 0.0;
9 M, l% P& q$ y3 K/ z3 U1 d" L# F# {" d0 Q1 O' H% ]9 [+ z
double tjd_ut, te, x2[6];4 a8 o) I+ c/ i1 m1 o
# T! }+ \, x* p) x, [long iflag, iflgret;
# t: H R0 y R
3 C' d) Y) V( {% |5 i( lint p;+ R0 a4 g, o+ R ^0 x7 {! r, L+ F
4 z! r* g* [6 e9 u% t/ r- w3 o3 eiflag = SEFLG_SPEED;7 ?# k* ]6 @& z% d5 q
1 Y0 B& a& z, g3 P" c* c, W5 swhile (TRUE) {; S% Q1 I3 G! f8 a
+ l* I* s+ D. z0 x3 P# K+ pprintf("\nDate (d.m.y) ?"); y- {* F/ K3 x+ G
5 j8 M) v! L7 ^3 |7 Tgets(sdate);9 ~& k% W1 Q( z/ f" n
+ ~, o; O# f% S6 h/* stop if a period . is entered */! A* |# M' t/ C6 U- \0 Q$ ~
+ Y& A5 A2 c, i' z& r Q- S& O7 tif (*sdate == '.') ! J( W( r8 A7 x7 \( q- ]2 F
2 w+ T% t; ^1 A/ x7 {/ t
return OK;4 t# V T& Y" h4 I9 c# S/ ^
g( z5 E6 ]; M% P7 t
if (sscanf (sdate, "%d%*c%d%*c%d", &jday,&jmon,&jyear) < 1) exit(1);+ s: ]) T2 N( u7 v, T9 I
/ G# a i" ^" g! [$ e- a: r- O0 D, P! k3 [7 b6 j
/*
: G7 w9 e, u; S1 g7 G
/ g$ D E! K- a2 F" c7 p( x
9 S2 U& [7 Y/ H/ j, x+ z: R2 J: T2 a* we have day, month and year and convert to Julian day number
4 }2 d/ _3 u( \1 z5 V
# |/ t% |1 B1 z. C( \# {( s9 I4 W
1 R: |. V( y1 S& O*/; @. H. u. d* t' E
, x7 r' g/ X2 k+ f& f
tjd_ut = swe_julday(jyear,jmon,jday,jut,SE_GREG_CAL);- }0 b3 Z# b$ v
4 A0 G. _- }$ U2 ^) S" K6 o8 \4 n
7 W) E; s7 S* p9 L2 N- R3 H
0 s4 x- g, f- V5 t1 p
/*
6 H" P2 J: k& S& L m) c0 R: P, n; u" }3 v& w9 ^2 x
6 v6 D9 Q( @# m/ f' d. [+ P* compute Ephemeris from Universal by adding delta_t% I- o4 }; j! Q$ W- C' f/ r( ]. a' a
6 U0 b1 ^. p, ~& H3 B# z' o
) i' T) w" X- Q3 W* not required for Swisseph versions smaller than 1.60* ^% v; n( d& Q3 M3 y! _
& T# `& o% l+ [6 b# |/ d5 r3 d% d3 t+ Y
! H- E4 D. a, O*/
B. c3 F( U5 B# Z1 E+ @9 f" u4 K5 Q) N3 m7 f1 s- T
/* te = tjd_ut + swe_deltat(tjd_ut); */: \- Z6 \" W# [/ U( I: ?
+ q0 X3 [7 C ]/ Sprintf("date: %02d.%02d.%d at 0:00 Universal time\n", jday, jmon, jyear);1 K1 Y ^- u& _$ ]. M" ^7 i: B$ n" l
' |8 Z! b6 x! w: A& K# C6 k- ]
printf("planet5 ~; l, t- w0 X7 O# O
\tlongitude\tlatitude\tdistance\tspeed long.\n");2 @1 d7 P5 A8 Q* [' J; w
4 c; E+ G1 g4 u9 |3 Z2 Y0 E! q3 t
& U' d3 Y Q9 J, s" `( s* ]. `: w
/*/ y" m+ B2 }* W& D% s) }2 P9 Z
2 i" ~* c8 d; h, x+ v8 M: e
; j& ?" p$ j4 q. A+ W7 W' F
* a loop over all planets2 r' v$ m5 B5 r+ h( F( j: U# G
# L" v Y3 r1 [& N
1 v; N4 f& H& c*/
: }5 b3 C& v1 b$ Q7 g8 Z) ^
C) g$ {2 \6 \/ B8 G; q$ }. hfor (p = SE_SUN; p <= SE_CHIRON; p++) {9 R/ i, D, ~: b3 L* X/ B
; M/ ?5 V! p( N8 `! Q8 t/ A# Y
if (p == SE_EARTH) continue;
! |8 X9 d" ]5 X6 c: v* |" W2 C# Z* k; S8 a( x8 h
/*3 V5 k/ Q2 K# n1 \, ]
4 n, {, k# h; g
; v3 d( N& V6 `0 P6 t
* do the coordinate calculation for this planet p3 k, h* O$ S. s/ B5 F, n
- L% q7 z' B O6 m
% e( _- Y V& I. i: ~*/
$ G6 E0 C, y# Y1 u1 P9 diflgret = swe_calc_ut(tjd_ut, p, iflag, x2, serr);' H/ T' L) \" b- Q. U
Y+ z* ?! I* H4 x8 |1 J7 R6 \! T
, y6 `3 F/ i1 }
/* Swisseph versions older than 1.60 require the following 5 W9 _3 ?! E. A$ G$ ~( Q: Q
4 ^ J7 j6 a4 W6 `
* statement instead */
) U) _' a: V7 h5 Y( o* Q4 j/* iflgret = swe_calc(te, p, iflag, x2, serr); */9 M) o, e7 z$ p, I4 n
# I- n K3 d8 [1 Y- J2 c# X
% l$ l; T5 q1 E! q% P9 U
/*
5 J" A- G9 M+ Q8 P( {3 O$ ?1 k, B" B# }' L v; M; x+ l4 Y E
* Z6 U7 K1 R0 c' I3 Z
* if there is a problem, a negative value is returned and an - ?) q$ [( J s$ s
; Z5 ~/ r! f1 e8 B+ t: @" u
4 F9 ]4 p- g2 e" t) V# U# p
* error message is in serr.
1 v8 Q3 o: ]% c1 T H
7 h4 v1 k1 D. Z4 u9 o
9 r' u& L1 a. f" ^- U*/
+ V8 X3 N$ s; w+ g, k! t
~& z3 E0 d! v2 a# c" z) lif (iflgret < 0) # z0 p1 T& @$ k+ C& ?8 q
s: o, W X( _/ Z3 }. Fprintf("error: %s\n", serr);$ ^' `" [5 x, R/ v2 G1 |/ A
' Y/ b+ Y2 H6 N y: Y
" x3 @$ g1 M4 k% D
/*
/ v/ q0 s2 y8 Z* l6 `1 b: C) ^- u! z" E( |$ ^4 j7 [
" n4 W A+ `8 h9 c3 X, M) B) t* get the name of the planet p8 w5 R- x: \, @* x. V
0 @5 q+ `) ~: u9 z9 ?/ o0 `
: b3 W/ M! q% S, {0 l: Q*/ p8 X4 W1 I1 F' `+ H& |0 g
0 M( g8 v* x# Y2 L
swe_get_planet_name(p, snam);
E7 w8 p2 w. m
+ T; m. W+ M/ G) h# t# E" e' i- ]/ M. V# c
/*
8 N+ B g3 R, V+ }
* z ]! O* X/ s( S
( p1 p; a; l/ A" o% q1 s* print the coordinates
4 W3 k2 M4 Y% c- z9 z) ^
. @9 E" K/ _8 h5 q1 d
5 c$ K* W; }% Z0 y3 S# m( o |*/3 ^+ S' N" f5 P( Y4 t" U
! g4 y! N; Y" P$ q* e! b
printf("%10s\t%11.7f\t%10.7f\t%10.7f\t%10.7f\n",3 r: c$ V7 J: S$ X1 D
6 U1 V9 c+ F$ T8 H z$ v% F& r( t6 D2 H1 J5 U( P4 z
snam, x2[0], x2[1], x2[2], x2[3]);
. m* n2 E. @7 H+ c6 o- P
7 q3 k+ L4 f; F/ V' ~* ]}, x; ]) R" c: Y: v6 p
+ u- j) _) w5 n R: x- c
}3 h9 j, V/ Y, w" Q; S. i
" _% z# }2 n. |return OK;' P1 ?# j8 l4 A# `
} |