-
Notifications
You must be signed in to change notification settings - Fork 6
/
swe_call.c
196 lines (185 loc) · 6.28 KB
/
swe_call.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
/*
** Astrolog (Version 5.41G) File: swe_call.c
**
** Code changed by Valentin Abramov ([email protected])
**
** IMPORTANT NOTICE: The graphics database and chart display routines
** used in this program are Copyright (C) 1991-1996 by Walter D. Pullen
** ([email protected], http://www.magitech.com/~cruiser1/astrolog.htm).
** Permission is granted to freely use and distribute these routines
** provided one doesn't sell, restrict, or profit from them in any way.
** Modification is allowed provided these notices remain with any
** altered or edited versions of the program.
**
** The main planetary calculation routines used in this program have
** been Copyrighted and the core of this program is basically a
** conversion to C of the routines created by James Neely as listed in
** Michael Erlewine's 'Manual of Computer Programming for Astrologers',
** available from Matrix Software. The copyright gives us permission to
** use the routines for personal use but not to sell them or profit from
** them in any way.
**
** The PostScript code within the core graphics routines are programmed
** and Copyright (C) 1992-1993 by Brian D. Willoughby
** ([email protected]). Conditions are identical to those above.
**
** The extended accurate ephemeris databases and formulas are from the
** calculation routines in the program "Swiss Ephemeris" and are
** Copyright (C) 1998 by Astrodienst AG.
** The use of that source code is subject to
** the Swiss Ephemeris Public License, available at
** http://www.astro.ch/swisseph.
** This copyright notice must not be changed or removed
** by any user of this program.
** by any user of this program.
**
** Initial programming 8/28,30, 9/10,13,16,20,23, 10/3,6,7, 11/7,10,21/1991.
** X Window graphics initially programmed 10/23-29/1991.
** PostScript graphics initially programmed 11/29-30/1992.
** Last code change made 9/22/1996.
*/
#include "astrolog.h"
#include "swephexp.h"
#include "extern.h"
# define d2l(x) swe_d2l(x)
/* Given an object index and a Julian Day time, get */
/* ecliptic longitude and latitude of the object */
/* and its velocity and distance from the Earth or Sun. This basically */
/* just calls the Placalc calculation function to actually do it, but as */
/* this is the one routine called from Astrolog, this is the one routine */
/* which has knowledge of and uses both Astrolog and Placalc definitions, */
/* and does things such as translation to Placalc indices and formats. */
bool FPlacalcPlanet(ind, jd, helio, obj, objalt, dir, space, altdir)
int ind, helio;
double jd;
real *obj, *objalt, *dir, *space, *altdir;
{
static AS_BOOL path_built = FALSE;
int iobj;
long flag;
double jde, xx[6];
char serr[AS_MAXCH];
/*
* if the function is called the first time, we build an ephemeris path
* in the same way as FileOpen() in io.c searchs for a file.
* we use serr to build the list of directories in it.
* If environment variable SE_EPHE_PATH exists, it will override all this.
*/
if (! path_built) {
#ifdef ENVIRON
char *env;
#endif
char name[80];
/* First look in the current directory. */
strcpy(serr, ".");
#ifdef ENVIRON
/* Next add the directory indicated by the version */
/* specific system environment variable. */
sprintf(name, "%s%s", ENVIRONVER, szVersionCore);
env = getenv(name);
if (env && *env)
sprintf(serr + strlen(serr), "%s%s", PATH_SEPARATOR, env);
/* Next look in the directory in the general environment variable. */
env = getenv(ENVIRONALL);
if (env && *env)
sprintf(serr + strlen(serr), "%s%s", PATH_SEPARATOR, env);
/* Next add the directory in the version prefix environment variable. */
env = getenv(ENVIRONVER);
if (env && *env)
sprintf(serr + strlen(serr), "%s%s", PATH_SEPARATOR, env);
#endif
/* Finally add several directories specified at compile time. */
sprintf(serr + strlen(serr), "%s%s", PATH_SEPARATOR, DEFAULT_DIR);
sprintf(serr + strlen(serr), "%s%s", PATH_SEPARATOR, EPHE_DIR);
sprintf(serr + strlen(serr), "%s%s", PATH_SEPARATOR, CHART_DIR);
swe_set_ephe_path(serr);
path_built = TRUE;
}
if (FBetween(ind, uranLo, uranHi -1))
iobj = ind - uranLo + SE_CUPIDO;
else if (ind <= oPlu)
iobj = ind-1;
else if (ind == oChi)
iobj = SE_CHIRON;
else if (FBetween(ind, oCer, oVes))
iobj = ind - oCer + SE_CERES;
else if (ind == oNod)
iobj = us.fTrueNode ? SE_TRUE_NODE : SE_MEAN_NODE;
else if (ind == oLil) {
if (oscLilith)
iobj = SE_OSCU_APOG;
else
iobj = SE_MEAN_APOG;
}
else
return fFalse;
if (ind == oSun && helio)
iobj = SE_EARTH;
flag = helio ? SEFLG_SPEED | SEFLG_HELCTR : SEFLG_SPEED;
deltaT = swe_deltat(jd);
jde = jd + deltaT;
if (swe_calc(jde, iobj, flag, xx, serr) >= 0) {
*obj = xx[0];
*objalt = xx[1];
*space = xx[2];
*dir = xx[3];
*altdir = xx[4];
return fTrue;
}
return fFalse;
}
double julday(int month, int day, int year, double hour, int gregflag)
{
double jd;
jd = swe_julday(year, month, day, hour, gregflag);
return jd;
}
void revjul (double jd, int gregflag,
int *jmon, int *jday, int *jyear, double *jut)
{
swe_revjul(jd, gregflag, jyear, jmon, jday, jut);
}
/* Added by V. Abramov, calls calculation of fixed stars. */
bool FPlacalcStar(ind, jd, obj, objalt)
int ind;
double jd;
real *obj, *objalt;
{
long flag;
char serr[AS_MAXCH];
char iobj[SE_MAX_STNAME * 2];
byte namebuf[SE_MAX_STNAME *2];
double jde, xx[6];
int pos;
byte *nomname;
sprintf (iobj, "%i", ind);
flag = SEFLG_SWIEPH;
jde = jd + swe_deltat(jd);
if (swe_fixstar(iobj, jde, flag, xx, serr) >= 0) {
*obj = xx[0];
*objalt = xx[1];
rStarBright[ind] = xx[2];
nomname = memccpy(namebuf, iobj, ',', SE_MAX_STNAME+1);
pos = nomname - namebuf;
if (pos > starMaxName)
namebuf[starMaxName] = chNull;
else
namebuf[pos-1] = chNull;
#if defined PC && !defined WIN
strcpy(szObjName[ind+starLo-1], namebuf);
#else
szObjName[ind+starLo-1] = strdup(namebuf);
#endif
strcpy(namebuf, iobj);
namebuf[pos+starMaxNName] = chNull;
#if defined PC && !defined WIN
strcpy(szStarConName[ind], nomname);
#else
szStarConName[ind] = strdup(nomname);
#endif
return fTrue;
}
if (us.fSeconds)
ErrorEphem(SE_STARFILE, ind);
return fFalse;
}