1 | #include <math.h>
|
---|
2 | #include <stdio.h>
|
---|
3 | #include "xastropack.h"
|
---|
4 |
|
---|
5 | // TEMPS: modified Julian date (mjd) (number of days elapsed since 1900 jan 0.5)
|
---|
6 | // jour [1,31] (dy)
|
---|
7 | // mois [1,12] (mn)
|
---|
8 | // annee (yr)
|
---|
9 | // universal time [0,24[ (utc)
|
---|
10 | // Greenwich mean siderial [0,24[ (gst)
|
---|
11 | // Greenwich mean siderial at 0h UT [0,24[ (gst0)
|
---|
12 | // EQUATORIALE: ascension droite en heures [0,24[ (ra)
|
---|
13 | // declinaison en degres [-90,90] (dec)
|
---|
14 | // angle horaire en heures [-12,12] (-12=12) (ha) tsid=ha+ra
|
---|
15 | // GALACTIQUE: longitude en degres [0,360[ (glng)
|
---|
16 | // latitude en degres [-90,90] (glat)
|
---|
17 | // HORIZONTAL: azimuth en degres [0,360[ (az)
|
---|
18 | // (angle round to the east from north+)
|
---|
19 | // altitude en degres [-90,90] (alt)
|
---|
20 | // ECLIPTIQUE: lontitude ecliptique en degres [0,360[ (eclng)
|
---|
21 | // (angle round counter clockwise from the vernal equinoxe)
|
---|
22 | // latitude ecliptique en degres [-90,90] (eclat)
|
---|
23 | // GEOGRAPHIE: longitude en degres ]-180,180] (geolng)
|
---|
24 | // (angle + vers l'ouest, - vers l'est)
|
---|
25 | // latitude en degres [-90,90] (north>0) (geolat)
|
---|
26 |
|
---|
27 | double TrueJDfrMJD(double mjd)
|
---|
28 | {
|
---|
29 | return mjd + MJD0;
|
---|
30 | }
|
---|
31 |
|
---|
32 | double MJDfrTrueJD(double jd)
|
---|
33 | {
|
---|
34 | return jd - MJD0;
|
---|
35 | }
|
---|
36 |
|
---|
37 | double MJDfrDate(double dy,int mn,int yr)
|
---|
38 | {
|
---|
39 | double mjd;
|
---|
40 | cal_mjd(mn,dy,yr,&mjd);
|
---|
41 | return mjd;
|
---|
42 | }
|
---|
43 |
|
---|
44 | void DatefrMJD(double mjd,double *dy,int *mn,int *yr)
|
---|
45 | {
|
---|
46 | mjd_cal(mjd,mn,dy,yr);
|
---|
47 | }
|
---|
48 |
|
---|
49 | /* given a mjd, return the year as a double. */
|
---|
50 | double YearfrMJD(double mjd)
|
---|
51 | {
|
---|
52 | double yr;
|
---|
53 | mjd_year(mjd,&yr);
|
---|
54 | return yr;
|
---|
55 | }
|
---|
56 |
|
---|
57 | /* given a decimal year, return mjd */
|
---|
58 | double MJDfrYear(double yr)
|
---|
59 | {
|
---|
60 | double mjd;
|
---|
61 | year_mjd(yr,&mjd);
|
---|
62 | return mjd;
|
---|
63 | }
|
---|
64 |
|
---|
65 | /* given a mjd, return the year and number of days since 00:00 Jan 1 */
|
---|
66 | /* Attention: si mjd = 2 Janvier -> number of days = 1 */
|
---|
67 | void YDfrMJD(double mjd,double *dy,int *yr)
|
---|
68 | {
|
---|
69 | mjd_dayno(mjd,yr,dy);
|
---|
70 | }
|
---|
71 |
|
---|
72 | /* given a modified julian date, mjd, and a universally coordinated time, utc,
|
---|
73 | * return greenwich mean siderial time, *gst.
|
---|
74 | * N.B. mjd must be at the beginning of the day.
|
---|
75 | */
|
---|
76 | double GSTfrUTC(double mjd0,double utc)
|
---|
77 | {
|
---|
78 | double gst;
|
---|
79 | utc_gst(mjd0,utc,&gst) ;
|
---|
80 | return gst;
|
---|
81 | }
|
---|
82 |
|
---|
83 | /* given a modified julian date, mjd, and a greenwich mean siderial time, gst,
|
---|
84 | * return universally coordinated time, *utc.
|
---|
85 | * N.B. mjd must be at the beginning of the day.
|
---|
86 | */
|
---|
87 | double UTCfrGST(double mjd0,double gst)
|
---|
88 | {
|
---|
89 | double utc;
|
---|
90 | gst_utc(mjd0,gst,&utc);
|
---|
91 | return utc;
|
---|
92 | }
|
---|
93 |
|
---|
94 | /* gmst0() - return Greenwich Mean Sidereal Time at 0h UT */
|
---|
95 | /* mjd = date at 0h UT in julian days since MJD0 */
|
---|
96 | double GST0(double mjd0)
|
---|
97 | /* Copie depuis le code de Xephem car pas prototype */
|
---|
98 | {
|
---|
99 | double T, x;
|
---|
100 | T = ((int)(mjd0 - 0.5) + 0.5 - J2000)/36525.0;
|
---|
101 | x = 24110.54841 +
|
---|
102 | (8640184.812866 + (0.093104 - 6.2e-6 * T) * T) * T;
|
---|
103 | x /= 3600.0;
|
---|
104 | range(&x, 24.0);
|
---|
105 | return (x);
|
---|
106 | }
|
---|
107 |
|
---|
108 | void Precess(double mjd1,double mjd2,double ra1,double dec1,double *ra2,double *dec2)
|
---|
109 | {
|
---|
110 | ra1 *= PI/12.; // radians
|
---|
111 | dec1 *= PI/180.; // radians
|
---|
112 | precess(mjd1,mjd2,&ra1,&dec1);
|
---|
113 | *ra2 = ra1*12./PI; if(*ra2>24.) *ra2 -= 24.; if(*ra2==24.) *ra2 = 0.;
|
---|
114 | *dec2 = dec1*180./PI;
|
---|
115 | }
|
---|
116 |
|
---|
117 | /* given apparent altitude find airmass. */
|
---|
118 | double AirmassfrAlt(double alt)
|
---|
119 | {
|
---|
120 | double x;
|
---|
121 | alt *= PI/180.; // radians
|
---|
122 | airmass(alt,&x);
|
---|
123 | return x;
|
---|
124 | }
|
---|
125 |
|
---|
126 | /* donne l'angle horaire a partir du temps sideral et de l'ascension droite */
|
---|
127 | double HafrRaTS(double gst,double ra)
|
---|
128 | {
|
---|
129 | double ha = gst - ra;
|
---|
130 | // Attention au probleme de la discontinuite 0h <==> 24h
|
---|
131 | // ts=1 ra=23 ; (ts-ra)=-22 <-12 --> ha = +2 = +24 + (ts-ra)
|
---|
132 | // ts=23 ra=1 ; (ts-ra)=+22 >+12 --> ha = -2 = -24 + (ts-ra)
|
---|
133 | if(ha==-12.) ha = 12.; if(ha<-12.) ha += 24.; if(ha>12.) ha -= 24.;
|
---|
134 | return ha;
|
---|
135 | }
|
---|
136 |
|
---|
137 | void HMSfrHdec(double hd,int *h,int *mn,double *s)
|
---|
138 | // INPUT: hd
|
---|
139 | // OUTPUT: h mn s (h,mn,s >=< 0)
|
---|
140 | // REMARQUE: si hd<0 alors h<0 ET mn<0 ET s<0
|
---|
141 | // EX: 12.51 -> h=12 mn=30 s=10 ;
|
---|
142 | // -12.51 -> h=-12 mn=-30 s=-10 ;
|
---|
143 | {
|
---|
144 | int sgn=1;
|
---|
145 | if(hd<0.) {sgn=-1; hd*=-1.;}
|
---|
146 | *h = int(hd);
|
---|
147 | *mn = int((hd-(double)(*h))*60.);
|
---|
148 | *s = (hd - (double)(*h) - (double)(*mn)/60.)*3600.;
|
---|
149 | // pb precision
|
---|
150 | if(*s<0.) *s = 0.;
|
---|
151 | if(*s>60. || *s==60.) {*s-=60.; *mn+=1;} // s=double attention comparaison
|
---|
152 | if(*mn<0) *mn = 0;
|
---|
153 | if(*mn>=60) {*mn-=60; *h+=1;}
|
---|
154 | *h *= sgn; *mn *= sgn; *s *= (double)sgn;
|
---|
155 | }
|
---|
156 |
|
---|
157 | double HdecfrHMS(int h,int mn,double s)
|
---|
158 | // INPUT: h , mn , s (h,mn,s >=< 0)
|
---|
159 | // RETURN: en heures decimales
|
---|
160 | // REMARQUE: pour avoir hd=-12.51 <- h=-12 mn=-30 s=-10
|
---|
161 | {
|
---|
162 | return ((double)h + (double)mn/60. + s/3600.);
|
---|
163 | }
|
---|
164 |
|
---|
165 | string ToStringHMS(int h,int mn,double s)
|
---|
166 | // INPUT: h , mn , s (h,mn,s >=< 0)
|
---|
167 | // RETURN: string h:mn:s
|
---|
168 | {
|
---|
169 | double hd = HdecfrHMS(h,mn,s); // put in range
|
---|
170 | HMSfrHdec(hd,&h,&mn,&s);
|
---|
171 | char str[128];
|
---|
172 | if(hd<0.)
|
---|
173 | sprintf(str,"-%d:%d:%.3f",-h,-mn,-s);
|
---|
174 | else
|
---|
175 | sprintf(str,"%d:%d:%.3f",h,mn,s);
|
---|
176 | string dum = str;
|
---|
177 | return dum;
|
---|
178 | }
|
---|
179 |
|
---|
180 | string ToStringHdec(double hd)
|
---|
181 | {
|
---|
182 | int h,mn; double s;
|
---|
183 | HMSfrHdec(hd,&h,&mn,&s);
|
---|
184 | return ToStringHMS(h,mn,s);
|
---|
185 | }
|
---|
186 |
|
---|
187 | void EqtoGal(double mjd,double ra,double dec, double *glng,double *glat)
|
---|
188 | // Coordonnees equatoriales -> Coordonnees galactiques
|
---|
189 | {
|
---|
190 | ra *= PI/12.; // radians
|
---|
191 | dec *= PI/180.; // radians
|
---|
192 | eq_gal(mjd,ra,dec,glat,glng);
|
---|
193 | // Vraiment bizarre, sur Linux-g++ glng>=360 ne comprend pas glng==360 ! (CMV)
|
---|
194 | *glng *= 180./PI; if(*glng>360.) *glng -= 360.; if(*glng==360.) *glng = 0.;
|
---|
195 | *glat *= 180./PI;
|
---|
196 | }
|
---|
197 |
|
---|
198 | void GaltoEq(double mjd,double glng,double glat,double *ra,double *dec)
|
---|
199 | // Coordonnees galactiques -> Coordonnees equatoriales
|
---|
200 | {
|
---|
201 | glng *= PI/180.; // radians
|
---|
202 | glat *= PI/180.; // radians
|
---|
203 | gal_eq (mjd,glat,glng,ra,dec);
|
---|
204 | *ra *= 12./PI; if(*ra>24.) *ra -= 24.; if(*ra==24.) *ra = 0.;
|
---|
205 | *dec *= 180./PI;
|
---|
206 | }
|
---|
207 |
|
---|
208 | void EqtoHor(double geolat,double ha,double dec,double *az,double *alt)
|
---|
209 | // Coordonnees equatoriales -> Coordonnees horizontales
|
---|
210 | {
|
---|
211 | geolat *= PI/180.;
|
---|
212 | ha *= PI/12.; // radians
|
---|
213 | dec *= PI/180.; // radians
|
---|
214 | hadec_aa (geolat,ha,dec,alt,az);
|
---|
215 | *alt *= 180./PI;
|
---|
216 | *az *= 180./PI; if(*az>360.) *az -= 360.; if(*az==360.) *az = 0.;
|
---|
217 | }
|
---|
218 |
|
---|
219 | void HortoEq(double geolat,double az,double alt,double *ha,double *dec)
|
---|
220 | // Coordonnees horizontales -> Coordonnees equatoriales
|
---|
221 | {
|
---|
222 | geolat *= PI/180.;
|
---|
223 | alt *= PI/180.; // radians
|
---|
224 | az *= PI/180.; // radians
|
---|
225 | aa_hadec (geolat,alt,az,ha,dec);
|
---|
226 | *ha *= 12./PI;
|
---|
227 | if(*ha==-12.) *ha = 12.; if(*ha<-12.) *ha += 24.; if(*ha>12.) *ha -= 24.;
|
---|
228 | *dec *= 180./PI;
|
---|
229 | }
|
---|
230 |
|
---|
231 | // Attention, j'ai modifie eq_ecl.c pour proteger NaN
|
---|
232 | // dans ecleq_aux :
|
---|
233 | // *q = (sy*ceps)-(cy*seps*sx*sw);
|
---|
234 | // if(*q<-1.) *q = -PI/2.; else if(*q>1.) *q = PI/2.; else *q = asin(*q);
|
---|
235 | void EqtoEcl(double mjd,double ra,double dec,double *eclng,double *eclat)
|
---|
236 | // Coordonnees equatoriales -> Coordonnees ecliptiques
|
---|
237 | {
|
---|
238 | ra *= PI/12.; // radians
|
---|
239 | dec *= PI/180.; // radians
|
---|
240 | eq_ecl(mjd,ra,dec,eclat,eclng);
|
---|
241 | *eclng *= 180./PI; if(*eclng>360.) *eclng -= 360.; if(*eclng==360.) *eclng = 0.;
|
---|
242 | *eclat *= 180./PI;
|
---|
243 | }
|
---|
244 |
|
---|
245 | void EcltoEq(double mjd,double eclng,double eclat,double *ra,double *dec)
|
---|
246 | // Coordonnees ecliptiques -> Coordonnees equatoriales
|
---|
247 | {
|
---|
248 | eclat *= PI/180.; // radians
|
---|
249 | eclng *= PI/180.; // radians
|
---|
250 | ecl_eq(mjd,eclat,eclng,ra,dec);
|
---|
251 | *ra *= 12./PI; if(*ra>24.) *ra -= 24.; if(*ra==24.) *ra = 0.;
|
---|
252 | *dec *= 180./PI;
|
---|
253 | }
|
---|
254 |
|
---|
255 | /* given the modified JD, mjd, return the true geocentric ecliptic longitude
|
---|
256 | * of the sun for the mean equinox of the date, *lsn, in radians, the
|
---|
257 | * sun-earth distance, *rsn, in AU, and the latitude *bsn, in radians
|
---|
258 | * (since this is always <= 1.2 arcseconds, in can be neglected by
|
---|
259 | * calling with bsn = NULL). */
|
---|
260 | void SunPos(double mjd,double *eclsn,double *ecbsn)
|
---|
261 | {
|
---|
262 | double rsn;
|
---|
263 | sunpos(mjd,eclsn,&rsn,ecbsn);
|
---|
264 | *eclsn *= 180./PI; if(*eclsn>360.) *eclsn -= 360.; if(*eclsn==360.) *eclsn = 0.;
|
---|
265 | *ecbsn *= 180./PI;
|
---|
266 | }
|
---|
267 |
|
---|
268 | /* given the mjd, find the geocentric ecliptic longitude, lam, and latitude,
|
---|
269 | * bet, and geocentric distance, rho in a.u. for the moon. also return
|
---|
270 | * the sun's mean anomaly, *msp, and the moon's mean anomaly, *mdp.
|
---|
271 | * (for the mean equinox) */
|
---|
272 | void MoonPos(double mjd,double *eclmn,double *ecbmn)
|
---|
273 | {
|
---|
274 | double rho,msp,mdp;
|
---|
275 | moon(mjd,eclmn,ecbmn,&rho,&msp,&mdp);
|
---|
276 | *eclmn *= 180./PI; if(*eclmn>360.) *eclmn -= 360.; if(*eclmn==360.) *eclmn = 0.;
|
---|
277 | *ecbmn *= 180./PI;
|
---|
278 | }
|
---|
279 |
|
---|
280 | void PlanetPos(double mjd,int numplan,double *ecl,double *ecb,double *diamang)
|
---|
281 | /* given a modified Julian date, mjd, and a planet, p, find:
|
---|
282 | * lpd0: heliocentric longitude,
|
---|
283 | * psi0: heliocentric latitude,
|
---|
284 | * rp0: distance from the sun to the planet,
|
---|
285 | * rho0: distance from the Earth to the planet,
|
---|
286 | * none corrected for light time, ie, they are the true values for the
|
---|
287 | * given instant.
|
---|
288 | * lam: geocentric ecliptic longitude,
|
---|
289 | * bet: geocentric ecliptic latitude,
|
---|
290 | * each corrected for light time, ie, they are the apparent values as
|
---|
291 | * seen from the center of the Earth for the given instant.
|
---|
292 | * dia: angular diameter in arcsec at 1 AU,
|
---|
293 | * mag: visual magnitude when 1 AU from sun and earth at 0 phase angle.
|
---|
294 | * (for the mean equinox) */
|
---|
295 | {
|
---|
296 | double lpd0,psi0,rp0,rho0,mag;
|
---|
297 | plans(mjd,numplan,&lpd0,&psi0,&rp0,&rho0,ecl,ecb,diamang,&mag);
|
---|
298 | *ecl *= 180./PI; if(*ecl>360.) *ecl -= 360.; if(*ecl==360.) *ecl = 0.;
|
---|
299 | *ecb *= 180./PI;
|
---|
300 | }
|
---|
301 |
|
---|
302 | void JupiterPos(double mjd,double *ecl,double *ecb,double *diamang)
|
---|
303 | {
|
---|
304 | PlanetPos(mjd,JUPITER,ecl,ecb,diamang);
|
---|
305 | }
|
---|
306 |
|
---|
307 | void SaturnPos(double mjd,double *ecl,double *ecb,double *diamang)
|
---|
308 | {
|
---|
309 | PlanetPos(mjd,SATURN,ecl,ecb,diamang);
|
---|
310 | }
|
---|
311 |
|
---|
312 | /* Given a coordinate type "typ", convert to standard for astropack */
|
---|
313 | int CoordConvertToStd(TypAstroCoord typ,double& coord1,double& coord2)
|
---|
314 | // Return : 0 = OK
|
---|
315 | // 1 = Type de coordonnees non connu
|
---|
316 | // 2 = Mauvais range pour coord1
|
---|
317 | // 4 = Mauvais range pour coord2
|
---|
318 | // 6 = Mauvais range pour coord1 et coord2
|
---|
319 | {
|
---|
320 | int rc = 0;
|
---|
321 |
|
---|
322 | // ---- Equatoriales alpha,delta
|
---|
323 | // - standard = [0,24[ , [-90,90]
|
---|
324 | if(typ&TypCoordEq) {
|
---|
325 | if(typ&TypCoordDD) {
|
---|
326 | coord1 = coord1 / 180. * 12.;
|
---|
327 | } else if(typ&TypCoordRR) {
|
---|
328 | coord1 = coord1 / PI * 12.;
|
---|
329 | coord2 = coord2 / PI * 180.;
|
---|
330 | }
|
---|
331 | if(coord1==24.) coord1 = 0.;
|
---|
332 | if(coord1<0. || coord1>=24.) rc+= 2;
|
---|
333 | if(coord2<-90. || coord2>90. ) rc+= 4;
|
---|
334 |
|
---|
335 | // ---- Galactiques gLong, gLat
|
---|
336 | // ---- Horizontales azimuth,altitude
|
---|
337 | // ---- Ecliptiques EclLong,EclLat
|
---|
338 | // - standard = [0,360[ , [-90,90]
|
---|
339 | } else if( typ&TypCoordGal || typ&TypCoordHor || typ&TypCoordEcl) {
|
---|
340 | if(typ&TypCoordHD) {
|
---|
341 | coord1 = coord1 / 12. * 180.;
|
---|
342 | } else if(typ&TypCoordRR) {
|
---|
343 | coord1 = coord1 / PI * 180.;
|
---|
344 | coord2 = coord2 / PI * 180.;
|
---|
345 | }
|
---|
346 | if(coord1==360.) coord1 = 0.;
|
---|
347 | if(coord1<0. || coord1>=360.) rc+= 2;
|
---|
348 | if(coord2<-90. || coord2>90. ) rc+= 4;
|
---|
349 |
|
---|
350 | } else { // Coordonnees non-connues
|
---|
351 | rc= 1;
|
---|
352 | }
|
---|
353 |
|
---|
354 | return rc;
|
---|
355 | }
|
---|