-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathswhmisc.c
125 lines (105 loc) · 3.27 KB
/
swhmisc.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
/*
Swephelp
Copyright 2007-2020 Stanislas Marquis <[email protected]>
Swephelp is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of
the License, or (at your option) any later version.
Swephelp is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Swephelp. If not, see <http://www.gnu.org/licenses/>.
*/
#include <assert.h>
#include <swephexp.h>
#include "swhmisc.h"
int swh_calc_ut(
double tjdut,
int planet,
char* star,
int flags,
double* res,
char* stnamret,
char* err)
{
assert(res);
assert(err);
if (star) {
assert(stnamret);
if (!*stnamret) {
memset(stnamret, 0, (SE_MAX_STNAME*2)+1);
strncpy(stnamret, star, SE_MAX_STNAME*2);
}
return swe_fixstar2_ut(stnamret, tjdut, flags, res, err);
}
return swe_calc_ut(tjdut, planet, flags, res, err);
}
int swh_saturn_4_stars( const double jd, const int flag, double* ret, char* err )
{
char starbuf[50];
double xx[6];
double* stars[2] = {0,0}; /* dummy assign */
double midp, dist0, dist1, dist2;
int i;
/* Get bodies positions */
i = swe_calc_ut( jd, SE_SATURN, flag, xx, err );
if ( i < 0 )
return -1;
ret[0] = xx[0];
strcpy( starbuf, "Aldebaran" );
i = swe_fixstar_ut( starbuf, jd, flag, xx, err );
if ( i < 0 )
return -1;
ret[1] = xx[0];
strcpy( starbuf, "Regulus" );
i = swe_fixstar_ut( starbuf, jd, flag, xx, err );
if ( i < 0 )
return -1;
ret[2] = xx[0];
strcpy( starbuf, "Antares" );
i = swe_fixstar_ut( starbuf, jd, flag, xx, err );
if ( i < 0 )
return -1;
ret[3] = xx[0];
strcpy( starbuf, "Fomalhaut" );
i = swe_fixstar_ut( starbuf, jd, flag, xx, err );
if ( i < 0 )
return -1;
ret[4] = xx[0];
/* Find nearest stars from Saturn */
if ( ret[0] <= ret[1] || ret[0] > ret[4] )
{
stars[0] = &ret[4];
stars[1] = &ret[1];
}
else if ( ret[0] <= ret[2] )
{
stars[0] = &ret[1];
stars[1] = &ret[2];
}
else if ( ret[0] <= ret[3] )
{
stars[0] = &ret[2];
stars[1] = &ret[3];
}
else if ( ret[0] <= ret[4] )
{
stars[0] = &ret[3];
stars[1] = &ret[4];
}
/* Find midpoint between stars */
midp = swe_deg_midp( *stars[0], *stars[1] );
/* Find distance Saturn/midpoint */
dist0 = fabs( swe_difdeg2n( ret[0], midp ) );
/* Find which star is closer from saturn and calculate the index */
dist1 = fabs( swe_difdeg2n( ret[0], *stars[0] ) );
dist2 = fabs( swe_difdeg2n( ret[0], *stars[1] ) );
if ( dist1 <= dist2 ) /* first is closer */
ret[5] = dist0 / ( fabs( swe_difdeg2n( midp, *stars[0] ) ) / 100.0 );
else /* second is closer */
ret[5] = dist0 / ( fabs( swe_difdeg2n( midp, *stars[1] ) ) / 100.0 );
return 0;
}
/* vi: set fenc=utf-8 ff=unix et sw=4 ts=4 : */