Newer
Older
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
#include <math.h>
#include <stdio.h>
#include "xastropack.h"
// TEMPS: modified Julian date (mjd) (number of days elapsed since 1900 jan 0.5)
// jour [1,31] (dy)
// mois [1,12] (mn)
// annee (yr)
// universal time [0,23[ (utc)
// Greenwich mean siderial [0,23[ (gst)
// Greenwich mean siderial at 0h UT [0,23[ (gst0)
// EQUATORIALE: ascension droite en heures [0,24[ (ra)
// declinaison en degres [-90,90] (dec)
// angle horaire en heures [-12,12] (-12=12) (ha) tsid=ha+ra
// GALACTIQUE: longitude en degres [0,360[ (glng)
// latitude en degres [-90,90] (glat)
// HORIZONTAL: altitude en degres [-90,90] (alt)
// azimuth en degres [0,360[ (az)
// (angle round to the east from north+)
// ECLIPTIQUE: latitude ecliptique en degres [-90,90] (eclat)
// lontitude ecliptique en degres [0,360[ (eclng)
// (angle round counter clockwise from the vernal equinoxe)
// GEOGRAPHIE: latitude en degres [-90,90] (north>0) (geolat)
// longitude en degres ]-180,180] (geolng)
// (angle + vers l'ouest, - vers l'est)
double TrueMJDfrMJD(double mjd)
{
return mjd + MJD0;
}
double MJDfrDate(double dy,int mn,int yr)
{
double mjd;
cal_mjd(mn,dy,yr,&mjd);
return mjd;
}
void DatefrMJD(double mjd,double *dy,int *mn,int *yr)
{
mjd_cal(mjd,mn,dy,yr);
}
/* given a mjd, return the year as a double. */
double YearfrMJD(double mjd)
{
double yr;
mjd_year(mjd,&yr);
return yr;
}
/* given a decimal year, return mjd */
double MJDfrYear(double yr)
{
double mjd;
year_mjd(yr,&mjd);
return mjd;
}
/* given a mjd, return the year and number of days since 00:00 Jan 1 */
/* Attention: si mjd = 2 Janvier -> number of days = 1 */
void YDfrMJD(double mjd,double *dy,int *yr)
{
mjd_dayno(mjd,yr,dy);
}
/* given a modified julian date, mjd, and a universally coordinated time, utc,
* return greenwich mean siderial time, *gst.
* N.B. mjd must be at the beginning of the day.
*/
double GSTfrUTC(double mjd0,double utc)
{
double gst;
utc_gst(mjd0,utc,&gst) ;
return gst;
}
/* given a modified julian date, mjd, and a greenwich mean siderial time, gst,
* return universally coordinated time, *utc.
* N.B. mjd must be at the beginning of the day.
*/
double UTCfrGST(double mjd0,double gst)
{
double utc;
gst_utc(mjd0,gst,&utc);
return utc;
}
/* gmst0() - return Greenwich Mean Sidereal Time at 0h UT */
/* mjd = date at 0h UT in julian days since MJD0 */
double GST0(double mjd0)
/* Copie depuis le code de Xephem car pas prototype */
{
double T, x;
T = ((int)(mjd0 - 0.5) + 0.5 - J2000)/36525.0;
x = 24110.54841 +
(8640184.812866 + (0.093104 - 6.2e-6 * T) * T) * T;
x /= 3600.0;
range(&x, 24.0);
return (x);
}
void Precess(double mjd1,double mjd2,double ra1,double dec1,double *ra2,double *dec2)
{
ra1 *= PI/12.; // radians
dec1 *= PI/180.; // radians
precess(mjd1,mjd2,&ra1,&dec1);
*ra2 = ra1*12./PI; if(*ra2>24.) *ra2 -= 24.; if(*ra2==24.) *ra2 = 0.;
*dec2 = dec1*180./PI;
}
/* given apparent altitude find airmass. */
double AirmassfrAlt(double alt)
{
double x;
alt *= PI/180.; // radians
airmass(alt,&x);
return x;
}
/* donne l'angle horaire a partir du temps sideral et de l'ascension droite */
double HafrRaTS(double gst,double ra)
{
double ha = gst - ra;
// Attention au probleme de la discontinuite 0h <==> 24h
// ts=1 ra=23 ; (ts-ra)=-22 <-12 --> ha = +2 = +24 + (ts-ra)
// ts=23 ra=1 ; (ts-ra)=+22 >+12 --> ha = -2 = -24 + (ts-ra)
if(ha==-12.) ha = 12.; if(ha<-12.) ha += 24.; if(ha>12.) ha -= 24.;
return ha;
}
void HdectoHMS(double hd,int *h,int *mn,double *s)
// INPUT: hd
// OUTPUT: h:mn:s
// REMARQUE: si hd<0 alors h<0 mais toujours mn,s>=0
{
int sgn=1;
if(hd<0.) {sgn=-1; hd*=-1.;}
*h = int(hd);
*mn = int((hd-(double)(*h))*60.);
*s = (hd - (double)(*h) - (double)(*mn)/60.)*3600.;
// pb precision
if(*s<0.) *s = 0.;
if(*s>60. || *s==60.) {*s-=60.; *mn+=1;} // s=double attention comparaison
if(*mn<0) *mn = 0;
if(*mn>=60) {*mn-=60; *h+=1;}
*h *= sgn;
}
double HMStoHdec(int h,int mn,double s)
// INPUT: h , mn , s
// RETURN: h:|mn|:|s| en heures decimales
// REMARQUE: si h<0 return -h:mn:s
// ERROR: mn<0 ou s<0 n'est pas correct, le programme les remet>0
{
if(mn<0) {
cout<<"HMStoHdec: mn out of range <0 : "<<mn<<" changed to abs()"<<endl;
mn *= -1;
}
if(s<0.) {
cout<<"HMStoHdec: s out of range <0 : "<<s<<" changed to abs()"<<endl;
s *= -1.;
}
int sgn=1; if(h<0) {sgn=-1; h*=-1;}
return ((double)h + (double)mn/60. + s/3600.)*(double)sgn;
}
string ToStringHMS(int h,int mn,double s)
// INPUT: h , mn>=0 , s >=0
// RETURN: string h:mn:s
// REMARQUE: si h<0 return -h:mn:s
// ERROR: mn<0 ou s<0 est une erreur !
// on prend la valeur absolue mn->|mn| , s->|s|
{
double hd = HMStoHdec(h,mn,s); // put in range
HdectoHMS(hd,&h,&mn,&s);
char str[128];
sprintf(str,"%d:%d:%.3f",h,mn,s);
string dum = str;
return dum;
}
string ToStringHdec(double hd)
{
int h,mn; double s;
HdectoHMS(hd,&h,&mn,&s);
return ToStringHMS(h,mn,s);
}
void EqtoGal(double mjd,double ra,double dec, double *glng,double *glat)
// Coordonnees equatoriales -> Coordonnees galactiques
{
ra *= PI/12.; // radians
dec *= PI/180.; // radians
eq_gal(mjd,ra,dec,glat,glng);
// Vraiment bizarre, sur Linux-g++ glng>=360 ne comprend pas glng==360 ! (CMV)
*glng *= 180./PI; if(*glng>360.) *glng -= 360.; if(*glng==360.) *glng = 0.;
*glat *= 180./PI;
}
void GaltoEq(double mjd,double glng,double glat,double *ra,double *dec)
// Coordonnees galactiques -> Coordonnees equatoriales
{
glng *= PI/180.; // radians
glat *= PI/180.; // radians
gal_eq (mjd,glat,glng,ra,dec);
*ra *= 12./PI; if(*ra>24.) *ra -= 24.; if(*ra==24.) *ra = 0.;
*dec *= 180./PI;
}
void EqtoHor(double geolat,double ha,double dec,double *az,double *alt)
// Coordonnees equatoriales -> Coordonnees horizontales
{
geolat *= PI/180.;
ha *= PI/12.; // radians
dec *= PI/180.; // radians
hadec_aa (geolat,ha,dec,alt,az);
*alt *= 180./PI;
*az *= 180./PI; if(*az>360.) *az -= 360.; if(*az==360.) *az = 0.;
}
void HortoEq(double geolat,double az,double alt,double *ha,double *dec)
// Coordonnees horizontales -> Coordonnees equatoriales
{
geolat *= PI/180.;
alt *= PI/180.; // radians
az *= PI/180.; // radians
aa_hadec (geolat,alt,az,ha,dec);
*ha *= 12./PI;
if(*ha==-12.) *ha = 12.; if(*ha<-12.) *ha += 24.; if(*ha>12.) *ha -= 24.;
*dec *= 180./PI;
}
// Attention, j'ai modifie eq_ecl.c pour proteger NaN
// dans ecleq_aux :
// *q = (sy*ceps)-(cy*seps*sx*sw);
// if(*q<-1.) *q = -PI/2.; else if(*q>1.) *q = PI/2.; else *q = asin(*q);
void EqtoEcl(double mjd,double ra,double dec,double *eclng,double *eclat)
// Coordonnees equatoriales -> Coordonnees ecliptiques
{
ra *= PI/12.; // radians
dec *= PI/180.; // radians
eq_ecl(mjd,ra,dec,eclat,eclng);
*eclng *= 180./PI; if(*eclng>360.) *eclng -= 360.; if(*eclng==360.) *eclng = 0.;
*eclat *= 180./PI;
}
void EcltoEq(double mjd,double eclng,double eclat,double *ra,double *dec)
// Coordonnees ecliptiques -> Coordonnees equatoriales
{
eclat *= PI/180.; // radians
eclng *= PI/180.; // radians
ecl_eq(mjd,eclat,eclng,ra,dec);
*ra *= 12./PI; if(*ra>24.) *ra -= 24.; if(*ra==24.) *ra = 0.;
*dec *= 180./PI;
}
/* given the modified JD, mjd, return the true geocentric ecliptic longitude
* of the sun for the mean equinox of the date, *lsn, in radians, the
* sun-earth distance, *rsn, in AU, and the latitude *bsn, in radians
* (since this is always <= 1.2 arcseconds, in can be neglected by
* calling with bsn = NULL). */
void SunPos(double mjd,double *eclsn,double *ecbsn)
{
double rsn;
sunpos(mjd,eclsn,&rsn,ecbsn);
*eclsn *= 180./PI; if(*eclsn>360.) *eclsn -= 360.; if(*eclsn==360.) *eclsn = 0.;
*ecbsn *= 180./PI;
}
/* given the mjd, find the geocentric ecliptic longitude, lam, and latitude,
* bet, and geocentric distance, rho in a.u. for the moon. also return
* the sun's mean anomaly, *msp, and the moon's mean anomaly, *mdp.
* (for the mean equinox) */
void MoonPos(double mjd,double *eclmn,double *ecbmn)
{
double rho,msp,mdp;
moon(mjd,eclmn,ecbmn,&rho,&msp,&mdp);
*eclmn *= 180./PI; if(*eclmn>360.) *eclmn -= 360.; if(*eclmn==360.) *eclmn = 0.;
*ecbmn *= 180./PI;
}
void PlanetPos(double mjd,int numplan,double *ecl,double *ecb,double *diamang)
/* given a modified Julian date, mjd, and a planet, p, find:
* lpd0: heliocentric longitude,
* psi0: heliocentric latitude,
* rp0: distance from the sun to the planet,
* rho0: distance from the Earth to the planet,
* none corrected for light time, ie, they are the true values for the
* given instant.
* lam: geocentric ecliptic longitude,
* bet: geocentric ecliptic latitude,
* each corrected for light time, ie, they are the apparent values as
* seen from the center of the Earth for the given instant.
* dia: angular diameter in arcsec at 1 AU,
* mag: visual magnitude when 1 AU from sun and earth at 0 phase angle.
* (for the mean equinox) */
{
double lpd0,psi0,rp0,rho0,mag;
plans(mjd,numplan,&lpd0,&psi0,&rp0,&rho0,ecl,ecb,diamang,&mag);
*ecl *= 180./PI; if(*ecl>360.) *ecl -= 360.; if(*ecl==360.) *ecl = 0.;
*ecb *= 180./PI;
}
void JupiterPos(double mjd,double *ecl,double *ecb,double *diamang)
{
PlanetPos(mjd,JUPITER,ecl,ecb,diamang);
}
void SaturnPos(double mjd,double *ecl,double *ecb,double *diamang)
{
PlanetPos(mjd,SATURN,ecl,ecb,diamang);
}