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