source: Sophya/trunk/SophyaExt/XAstroPack/xastropack.h@ 1679

Last change on this file since 1679 was 1679, checked in by cmv, 24 years ago

InRange,degrad()... et inline cmv 10/10/2001

File size: 9.1 KB
Line 
1#ifndef XASTROPACK_H
2#define XASTROPACK_H
3
4#include "machdefs.h"
5#include <string.h>
6#include <string>
7
8#ifdef __cplusplus
9extern "C" { /* extern "C" */
10#endif
11#include "XAstro/P_.h"
12#include "XAstro/astro.h"
13#ifdef __cplusplus
14} /* extern "C" */
15#endif
16
17enum TypAstroCoord {
18 TypCoordUndef = (unsigned long) (0),
19
20 // Pour indiquer que les coordonnees sont en (heure=[0,24[,degre=[-90,90])
21 TypCoordHD = (unsigned long) (1 << 20),
22 // Pour indiquer que les coordonnees sont en (degre=[0,360[,degre=[-90,90])
23 TypCoordDD = (unsigned long) (1 << 21),
24 // Pour indiquer que les coordonnees sont en (radian=[0,2Pi[,radian=[-Pi/2,Pi/2])
25 TypCoordRR = (unsigned long) (1 << 22),
26
27 // Coordonnees Equatoriales alpha,delta
28 TypCoordEq = (unsigned long) (1 << 0),
29 TypCoordEqStd = (unsigned long) ((1 << 0) | (1 << 20)),
30 // Coordonnees Galactiques gLong, gLat
31 TypCoordGal = (unsigned long) (1 << 1),
32 TypCoordGalStd = (unsigned long) ((1 << 1) | (1 << 21)),
33 // Coordonnees Horizontales azimuth,altitude
34 TypCoordHor = (unsigned long) (1 << 2),
35 TypCoordHorStd = (unsigned long) ((1 << 2) | (1 << 21)),
36 // Coordonnees Ecliptiques EclLong,EclLat
37 TypCoordEcl = (unsigned long) (1 << 3),
38 TypCoordEclStd = (unsigned long) ((1 << 3) | (1 << 21))
39};
40
41// ------------------- Utilitaires -------------------
42int CoordConvertToStd(TypAstroCoord typ,double& coord1,double& coord2);
43
44/*!
45\brief Pour remettre la valeur "val" dans la dynamique [0.,range[.
46 Si "vmax" different de "range", c'est la borne superieure
47 qui peut etre atteinte
48 (si elle est depassee, on soustrait "range").
49\verbatim
50 r>0 vmax>0
51 r=24. vmax=24. -> mets dans [ 0,+24[ borne sup exclue
52 r=24. vmax=12. -> mets dans ]-12,+12] borne inf exclue
53\endverbatim
54*/
55inline void InRange(double *val,double range)
56 {*val-=range*floor(*val/range);}
57inline void InRange(double *val,double range,double vmax)
58 {InRange(val,range); if(*val>vmax) *val-=range;}
59
60// ------------------- Gestions des temps -------------------
61/*! \ingroup XAstroPack
62\brief Compute true Julian day from MJD
63*/
64inline double TrueJDfrMJD(double mjd) {return mjd + MJD0;}
65
66/*! \ingroup XAstroPack
67\brief Compute MJD from true Julian day
68*/
69inline double MJDfrTrueJD(double jd) {return jd - MJD0;}
70
71/*! \ingroup XAstroPack
72\brief Compute MJD from date
73\verbatim
74 MJD = modified Julian date (number of days elapsed since 1900 jan 0.5),
75\endverbatim
76*/
77inline double MJDfrDate(double dy,int mn,int yr)
78 {double mjd; cal_mjd(mn,dy,yr,&mjd); return mjd;}
79
80/*! \ingroup XAstroPack
81\brief Compute date from MJD
82*/
83inline void DatefrMJD(double mjd,double *dy,int *mn,int *yr)
84 {mjd_cal(mjd,mn,dy,yr);}
85
86/*! \ingroup XAstroPack
87\brief Given a mjd, return the year as a double.
88*/
89inline double YearfrMJD(double mjd)
90 {double yr; mjd_year(mjd,&yr); return yr;}
91
92/*! \ingroup XAstroPack
93\brief Given a decimal year, return mjd
94*/
95inline double MJDfrYear(double yr)
96 {double mjd; year_mjd(yr,&mjd); return mjd;}
97
98/*! \ingroup XAstroPack
99\brief Given a mjd, return the year and number of days since 00:00 Jan 1
100\warning: if mjd = 2 January -> number of days = 1
101*/
102inline void YDfrMJD(double mjd,double *dy,int *yr)
103 {mjd_dayno(mjd,yr,dy);}
104
105/*! \ingroup XAstroPack
106\brief Given a year,
107*/
108inline int IsLeapYear(int y)
109 {return isleapyear(y);}
110
111/*! \ingroup XAstroPack
112\brief given an mjd, set *dow to 0..6 according to which day of the week it falls on (0=sunday).
113\return return 0 if ok else -1 if can't figure it out.
114*/
115inline int DayOrder(double mjd,int *dow)
116 {return mjd_dow(mjd,dow);}
117
118/*! \ingroup XAstroPack
119\brief given a mjd, return the the number of days in the month.
120*/
121inline int DaysInMonth(double mjd)
122 {int ndays; mjd_dpm(mjd,&ndays); return ndays;}
123
124/*! \ingroup XAstroPack
125\brief Given a mjd, truncate it to the beginning of the whole day
126*/
127inline double MJDat0hFrMJD(double mjd) {return mjd_day(mjd);}
128
129/*! \ingroup XAstroPack
130\brief Given a mjd, return the number of hours past midnight of the whole day
131*/
132inline double HfrMJD(double mjd) {return mjd_hr(mjd);}
133
134/*! \ingroup XAstroPack
135\brief Give GST from UTC
136\verbatim
137 Given a modified julian date, mjd, and a universally coordinated time, utc,
138 return greenwich mean siderial time, *gst.
139 N.B. mjd must be at the beginning of the day.
140\endverbatim
141*/
142inline double GSTfrUTC(double mjd0,double utc)
143 {double gst; utc_gst(mjd0,utc,&gst) ; return gst;}
144
145/*! \ingroup XAstroPack
146\brief Give UTC from GST
147\verbatim
148 Given a modified julian date, mjd, and a greenwich mean siderial time, gst,
149 return universally coordinated time, *utc.
150 N.B. mjd must be at the beginning of the day.
151\endverbatim
152*/
153inline double UTCfrGST(double mjd0,double gst)
154 {double utc; gst_utc(mjd0,gst,&utc); return utc;}
155
156/*! \ingroup XAstroPack
157\brief return local sidereal time from greenwich mean siderial time and longitude
158\param precis : if not zero, then correct for obliquity and nutation
159\warning no nutation or obliquity correction are done.
160*/
161inline double LSTfrGST(double gst,double geolng)
162 {double lst = gst + deghr(geolng); InRange(&lst,24.); return lst;}
163
164double GST0(double mjd0);
165double LSTfrMJD(double mjd,double geolng);
166void HMSfrHdec(double hd,int *h,int *mn,double *s);
167double HdecfrHMS(int h,int mn,double s);
168string ToStringHMS(int h,int mn,double s);
169string ToStringHdec(double hd);
170
171// ------------------- Calculs Divers -------------------
172void Precess(double mjd1,double mjd2,double ra1,double dec1,double *ra2,double *dec2);
173
174/*! \ingroup XAstroPack
175\brief Given apparent altitude find airmass.
176*/
177inline double AirmassfrAlt(double alt)
178 {double x; alt = degrad(alt); airmass(alt,&x); return x;}
179
180/*! \ingroup XAstroPack
181\brief given geocentric time "jd" and coords of a distant object at "ra/dec" (J2000),
182find the difference "hcp" in time between light arriving at earth vs the sun.
183\return "hcp" must be subtracted from "geocentric jd" to get "heliocentric jd".
184\warning "jd" is the TRUE Julian day (jd = mjd+MJD0).
185*/
186inline double HelioCorr(double jd,double ra,double dec)
187 {double hcp; ra=hrrad(ra); dec=degrad(dec); heliocorr(jd,ra,dec,&hcp); return hcp;}
188
189// ------------------- Transformation de coordonnees -------------------
190/*! \ingroup XAstroPack
191\brief Give the hour angle from local sideral time and right ascencion
192\warning right ascencion should be first precessed to date of interest
193\warning no nutation or obliquity correction are done.
194*/
195// Attention au probleme de la discontinuite 0h <==> 24h
196// ts=1 ra=23 ; (ts-ra)=-22 <-12 --> ha = +2 = +24 + (ts-ra)
197// ts=23 ra=1 ; (ts-ra)=+22 >+12 --> ha = -2 = -24 + (ts-ra)
198inline double HafrRaTS(double lst,double ra)
199 {double ha = lst - ra; InRange(&ha,24.,12.); return ha;}
200
201/*! \ingroup XAstroPack
202\brief Give the local sideral time and the hour angle return the right ascencion
203\warning right ascencion is the value precessed to date of interest
204\warning no nutation or obliquity correction are done.
205*/
206inline double RafrHaTS(double lst,double ha)
207 {double ra = lst - ha; InRange(&ra,24.); return ra;}
208
209void EqtoGal(double mjd,double ra,double dec,double *glng,double *glat);
210void GaltoEq(double mjd,double glng,double glat,double *ra,double *dec);
211void EqHtoHor(double geolat,double ha,double dec,double *az,double *alt);
212void HortoEqH(double geolat,double az,double alt,double *ha,double *dec);
213void EqtoHor(double geolat,double lst,double ra,double dec,double *az,double *alt);
214void HortoEq(double geolat,double lst,double az,double alt,double *ra,double *dec);
215void EqtoEcl(double mjd,double ra,double dec,double *eclng,double *eclat);
216void EcltoEq(double mjd,double eclng,double eclat,double *ra,double *dec);
217
218// ------------------- Positions des astres -------------------
219void SunPos(double mjd,double *eclsn,double *ecbsn,double *rsn);
220void MoonPos(double mjd,double *lmn,double *bmn,double *rho);
221void PlanetPos(double mjd,int numplan,double *sunecl,double *sunecb,double *sundist
222 ,double *geodist,double *geoecl,double *geoecb
223 ,double *diamang,double *mag);
224/*! \ingroup XAstroPack
225\brief Same as PlanetPos above with less arguments
226*/
227inline void PlanetPos(double mjd,int numplan,double *geoecl,double *geoecb
228 ,double *geodist,double *diamang)
229{
230 double sunecl,sunecb,sundist,mag;
231 PlanetPos(mjd,numplan,&sunecl,&sunecb,&sundist,geodist,geoecl,geoecb,diamang,&mag);
232}
233
234/*! \ingroup XAstroPack
235\brief Give Jupiter position
236*/
237inline void JupiterPos(double mjd,double *ecl,double *ecb,double *geodist,double *diamang)
238{
239 PlanetPos(mjd,JUPITER,ecl,ecb,geodist,diamang);
240}
241
242/*! \ingroup XAstroPack
243\brief Give Saturn position
244*/
245inline void SaturnPos(double mjd,double *ecl,double *ecb,double *geodist,double *diamang)
246{
247 PlanetPos(mjd,SATURN,ecl,ecb,geodist,diamang);
248}
249
250#endif
Note: See TracBrowser for help on using the repository browser.