1. The programming steps to get a planet’s position
& b9 f! q& [; z9 U2 n* C' y8 f% R$ ~To compute a celestial body, N- [) F0 R" Z
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.
3 x: T3 L0 m+ V9 M' w3 m! ~
% h) u' B( Y i5 R* g0 C: a4 L1.
$ {0 M' t6 J- ^. V; ~8 j7 ]& A$ z8 \Set the directory path of the ephemeris files, e.g.: ! t7 q$ S+ |3 w- ?
. j( t5 y- o' `& n0 y7 bswe_set_ephe_path(”C:\\SWEPH\\EPHE”);
4 y) M2 l! I$ R* X
1 Q N* y: t& A% c8 n2.. x* B6 ~3 A9 M* P w
From the birth date, compute the Julian day number:. s+ ]0 A' S& l0 d, @, y/ e
: u. v: a* v0 ]- K% U& K0 `5 N$ Xjul_day_UT = swe_julday(year, month, day, hour, gregflag);
1 {, c- O, s' h: { ; e0 H/ b& _/ {" J# G
3..* v2 o. F1 W: W, t. A. ~; v4 e3 N Q
Compute a planet or other bodies:
/ G- ?; x) E3 z `1 O3 Z1 ?2 n+ `. a5 k8 J: a# n
ret_flag = swe_calc_ut(jul_day_UT, planet_no, flag, lon_lat_rad, err_msg);
( S6 T- v# Y f M- {7 i) v. r
. S' |% [/ y. Y1 S' Sor a fixed star:! q+ r/ z7 y: Y: j$ s
8 R; J$ R* V; I3 q8 u6 c* t
ret_flag = swe_fixstar_ut(star_nam, jul_day_UT, flag, lon_lat_rad, err_msg);+ P# X1 p( y8 j0 |( X$ L2 O
: ^9 K( v+ H( ?/ t0 z) k
s3 O- v' E( \4 B5 Q% @' `* h2 hNote:
" Z' P u1 S3 L3 b$ Q& E) x- C4 n4 H, y. o7 [; M) J# o7 [
The functions swe_calc_ut() and swe_fixstar_ut() were introduced with Swisseph version 1.60.
5 L& _6 i, z! Y3 X1 @3 M5 a
8 u- S! f/ {1 x( k: ~( j0 y3 sIf 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:
& S3 y; V* ~1 [$ A9 Y* J0 `$ d) X
; r- A2 Q) c, H1 i; F% d1 b- L: C6 Z( Z, h# V6 I
First, if necessary, convert Universal Time (UT) to Ephemeris Time (ET):
" }) G- p" Y$ k4 w# K
9 S; [6 r4 C$ W2 Ajul_day_ET = jul_day_UT + swe_deltat(jul_day_UT);
. H* W- N0 D# F+ k2 `
0 }9 f- C& @' N! S' E9 K
% L2 U4 R% m$ g; X4 z* z: kThen Compute a planet or other bodies:2 i) x# |/ m& ? V
! y2 u5 j6 {. g- M) b, F4 gret_flag = swe_calc(jul_day_ET, planet_no, flag, lon_lat_rad, err_msg);
' u; s6 m: X* d) ^, v( t; d5 E; y" s# v ]7 ]1 n, ?% ]8 r
or a fixed star:) w9 O7 e4 {: k, L0 l
2 n; X3 s3 O8 x2 H6 S' |: M% R
ret_flag = swe_fixstar(star_nam, jul_day_ET, flag, lon_lat_rad, err_msg);
2 I+ f5 C# \6 _! U3 ^ * h; |5 x% ]* S' r- `) j4 t
5..* O0 V4 N% e3 ?: u3 W3 D2 c/ T
At the end of your computations close all files and free memory calling swe_close();7 ] e, M% P- z6 ?* W9 @
# [2 W# A* @0 R& I h- _: G/ k2 ^9 |Here is a miniature sample program, it is in the source distribution as swemini.c
- |2 Q1 C2 W( m+ @3 v
9 J4 |! J; g: O/ ?( a! b" n7 v$ H#include "swephexp.h"
9 G/ F% ?" E) `. y/ }) H- q e/* this includes
. y7 w/ U1 t' c, g l, a"sweodef.h" */
/ f. F, G. _) G; e; J9 Sint main()
, { s1 y# ^; R3 q! {6 x{
?. R( O5 _: |: w3 ?! B! Z
* q/ P! N$ p; g V) D! B t9 fchar *sp, sdate[AS_MAXCH], snam[40], serr[AS_MAXCH];' [" x0 f7 p! x# R6 I
2 f3 F6 ^5 b% ?, \% I! `) V
3 w6 a. @" O) S, X% {. |int jday = 1, jmon = 1, jyear = 2000;
/ Y+ Y3 p* Z- C! Q
. U3 ]: l+ Z. w) t: S+ Fdouble jut = 0.0;
1 H+ v3 \8 W/ |2 C. a8 J/ e' k5 j/ W) Y5 t, A) N- [5 p
double tjd_ut, te, x2[6];6 M3 l4 K" T" ]3 X
( I. K6 Z7 V, I$ X% c5 h5 h
long iflag, iflgret;
1 |; D$ O4 w+ }+ D n9 |% F. z1 y \
int p;7 v' [& @) S5 T1 Y7 F
- q3 O3 N5 f4 E0 t" ~' r7 R
iflag = SEFLG_SPEED;
& w3 b3 s: f* k% o# l! p" E3 c3 H* q, b
while (TRUE) {
, V( d( ]# ^, V: f* I3 U$ y1 k4 q6 c, [) J9 }
printf("\nDate (d.m.y) ?");
5 I4 [2 `2 B2 N) ~9 E& Z
: l0 m+ \6 l6 @* Igets(sdate); |3 W# r& }' D! k
7 O/ @* b7 b- f* }& h/* stop if a period . is entered */
' n _$ H. q# n) @0 @8 U- ^
& G! I( }3 F& u7 ?if (*sdate == '.')
. x2 |3 B" B3 n; j
/ n8 `( F9 ^; ]return OK;0 J- X" N+ `7 |) m; p
; j, y# Z2 |' {* J/ Zif (sscanf (sdate, "%d%*c%d%*c%d", &jday,&jmon,&jyear) < 1) exit(1);6 V$ B& A- A: l& K
: g( V: E# @: r) p. |$ M
, K" O; r' v* Q2 O" K/*% W f6 l9 l! `2 p7 U' X/ \2 g
j5 q0 h4 G3 v0 l& w# G2 d' S5 Z; `
+ k( w2 H: J4 N5 w# `, i+ H
* we have day, month and year and convert to Julian day number
; ^; k6 Y7 V' V. Y) y) n0 a1 s. p; p( n( \+ |2 `' r
5 S; }; g- m$ r! k% M7 ?3 t*/: Z8 _) f0 k" K5 @+ Q2 y2 A# y1 {
( R+ z1 ?( N! o* Gtjd_ut = swe_julday(jyear,jmon,jday,jut,SE_GREG_CAL);; D3 [$ Q3 A0 t
9 _ b# H" G" \ S; v
( k, x8 z- a6 S! p3 ~7 k
0 W! G. w" s9 D! [1 K
/*
6 c8 l' Q" n- @: n ]2 X+ L9 d I' x# D! g3 x
. o4 s! b& Q+ A7 Y, ^2 F
* compute Ephemeris from Universal by adding delta_t" H+ ~# ?' b% z+ U+ t# a* }
! k/ ~- F, D$ D. W$ f& O+ K* y4 ] C+ O1 q( u/ e/ ^( S
* not required for Swisseph versions smaller than 1.60
1 a) N: V$ q$ u2 K8 i" K; I" C( m6 I; S1 O
8 {' @, |' d/ A% q, s& `* |8 d7 W
*/% X, i8 D6 @ K# b
2 R. a) V) J2 _' b, ?4 m
/* te = tjd_ut + swe_deltat(tjd_ut); */2 z1 w& ] U) A3 q! G! P
8 m5 w! X0 \2 i4 `% {0 ?/ zprintf("date: %02d.%02d.%d at 0:00 Universal time\n", jday, jmon, jyear);
# j1 A" J- ]( B1 z& y8 ]$ Q% w5 q- Z
printf("planet6 q" W) ]1 f) t; W5 G
\tlongitude\tlatitude\tdistance\tspeed long.\n");
, e. c0 `: v. R6 ^. p) c- h3 Q/ c6 {' Q( ]9 J5 _+ g4 z
' H7 f' ^7 r/ K# \: M: C/*- W( b/ M+ l: A* k; I, o
# Z- ~/ f( t7 ^( Z
% N: r/ x: r, U1 i( T' X" ?+ y- ~% Y4 ^* a loop over all planets) W% N' r; V, X
3 ]6 Z+ M& a0 g( l. G5 D. D/ C( Y, ?, k/ N: g; Z
*/
- @* U7 X7 M8 d/ n! j t* F4 T
( \* A6 K, i" v- a+ Dfor (p = SE_SUN; p <= SE_CHIRON; p++) {7 l. x% Q; K) [+ w1 ^9 V1 l
0 h$ o- L0 X& ^$ r" Kif (p == SE_EARTH) continue;0 v. ^6 d/ ~* u0 C( m' \/ e, g
) |% F! L% v) G/*3 V( t2 j* X+ f4 `( T4 |0 C
) Z) q4 t/ b7 E* E5 e0 U+ d" L2 d9 L% l5 J/ [: i
* do the coordinate calculation for this planet p
- Q$ }3 w8 H: S* D7 s: F9 Q: w; G5 Y# a3 s! ]
$ g2 C) D9 f2 `( W
*/
: I+ _. h* C0 yiflgret = swe_calc_ut(tjd_ut, p, iflag, x2, serr);
6 Q x: f% k/ n+ G- ~8 Z q& S; W: ^6 Z1 ]9 V
6 ]; A+ t k: E: q- a2 w/* Swisseph versions older than 1.60 require the following " c" `3 _. x5 }
" G' C' d( s$ b! n& l* R; X
* statement instead */
& J) p, l3 @3 z$ u2 c5 i. M/* iflgret = swe_calc(te, p, iflag, x2, serr); */
. ?5 _9 h; x* D9 ^- X" G, M3 Q) t0 h6 s/ P) h. V3 J( H
% f5 m8 Y2 Q' N ~) y. b6 ~/* o3 ` M+ w; o6 P+ F
: T7 t% b" K; q
1 D# \ k/ U$ b
* if there is a problem, a negative value is returned and an
1 ~, K, q& A, ~7 a
6 t# q) b% b' H. w; B
K1 }8 \0 M& l% j! D( ]* error message is in serr.
. m! ?% H5 `6 ]* h5 C3 w8 m+ }- G2 [* K7 w. ~
( d6 ^7 J4 a) Z2 m* q$ x; y( {6 P
*/
4 ]' O$ i/ k% N" @. l1 f* `6 M6 q0 f* p4 E0 s) P; z6 u
if (iflgret < 0) & l% Y3 m4 g' S! i" w; P `
/ L4 D+ {# J, x7 a! [4 _% N) Q- Oprintf("error: %s\n", serr);4 U' [/ Q" ]1 v, f( \/ O% u' A
! a; I1 c) g4 z: w
& Y4 ]4 j" }' c. ?/*
2 E1 H# b4 l0 h5 z8 O- f8 D" R- F+ a- X p
7 F' q* I! f, d4 X0 z6 O9 k4 g* get the name of the planet p5 l0 n6 N2 D7 I
* U b3 @) ]2 D9 e) ^! E, u$ m! C3 L9 K9 P
*/, M, G! d4 {: l5 A# W3 m% }
0 D5 z5 F& p# F8 C& ~2 n
swe_get_planet_name(p, snam);
: g0 ?, q5 L2 V v3 P) U- o/ H( m4 R
2 \$ w- c2 w. @
/*8 h$ z: G d/ f/ j
! P8 h% P) [9 R: U4 {4 Q
* v& r% D' n. z* b- M: h, {! A5 U" Q
* print the coordinates
' U* \! ^( x/ V! [% ~; [* Q- V( _' G5 y4 i
5 c7 Z7 r: E* ?
*/
+ R0 p0 r' Q! \) t& H' E+ S T7 U, H% j( n3 k' v1 ]
printf("%10s\t%11.7f\t%10.7f\t%10.7f\t%10.7f\n",
. R6 P: N$ [8 G" u3 r }
5 S# l) l) y$ Q# x) ?6 F; J: e. U; K5 K6 i3 J6 X4 a
snam, x2[0], x2[1], x2[2], x2[3]);
6 X, J+ U8 s* X) O: O3 r" Z6 X* j X' h, i4 m
}
2 f( P- ^' m. N8 ~3 m# T: Z5 f- J7 }- d! ~/ I- b/ U4 w
}
! p$ R! P; w0 ?$ D! `
% r7 z0 V! x2 Qreturn OK;. f, s9 }" o$ s5 j, r
} |