| 1 | #ifndef XASTROPACK_H | 
|---|
| 2 | #define XASTROPACK_H | 
|---|
| 3 |  | 
|---|
| 4 | #include "machdefs.h" | 
|---|
| 5 | #include <string.h> | 
|---|
| 6 | #include <string> | 
|---|
| 7 |  | 
|---|
| 8 | #ifdef __cplusplus | 
|---|
| 9 | extern "C" {  /* extern "C" */ | 
|---|
| 10 | #endif | 
|---|
| 11 | /* #include "XAstro/P_.h" */ | 
|---|
| 12 | #include "XAstro/astro.h" | 
|---|
| 13 | #undef mjd | 
|---|
| 14 | #undef lat | 
|---|
| 15 | #undef lng | 
|---|
| 16 | #undef tz | 
|---|
| 17 | #undef temp | 
|---|
| 18 | #undef pressure | 
|---|
| 19 | #undef elev | 
|---|
| 20 | #undef dip | 
|---|
| 21 | #undef epoch | 
|---|
| 22 | #undef tznm | 
|---|
| 23 | #undef mjed | 
|---|
| 24 | #ifdef __cplusplus | 
|---|
| 25 | }             /* extern "C" */ | 
|---|
| 26 | #endif | 
|---|
| 27 |  | 
|---|
| 28 | enum TypAstroCoord { | 
|---|
| 29 | //------ Coordonnees de type (A,B) avec: | 
|---|
| 30 | //      A,B <==> alpha,delta | 
|---|
| 31 | //      A,B <==> longitude,latitude | 
|---|
| 32 | //      A,B <==> azimuth,altitude ou elevation | 
|---|
| 33 |  | 
|---|
| 34 | //------ Les unites des coordonnees | 
|---|
| 35 | TypUniteH       =  (unsigned long)  (1 << 0), // coord en heure | 
|---|
| 36 | TypUniteD       =  (unsigned long)  (1 << 1), // coord en degre | 
|---|
| 37 | TypUniteR       =  (unsigned long)  (1 << 2), // coord en radian | 
|---|
| 38 |  | 
|---|
| 39 | //------ Les unites des coordonnees A et B | 
|---|
| 40 | TypCoord1H      =  (unsigned long)  (1 << 3), // coord A en heure | 
|---|
| 41 | TypCoord1D      =  (unsigned long)  (1 << 4), // coord A en degre | 
|---|
| 42 | TypCoord1R      =  (unsigned long)  (1 << 5), // coord A en radian | 
|---|
| 43 | TypCoord2H      =  (unsigned long)  (1 << 6), // coord B en heure | 
|---|
| 44 | TypCoord2D      =  (unsigned long)  (1 << 7), // coord B en degre | 
|---|
| 45 | TypCoord2R      =  (unsigned long)  (1 << 8), // coord B en radian | 
|---|
| 46 |  | 
|---|
| 47 | //------ Le type d'intervalle des coordonnees A et B | 
|---|
| 48 | // Coord A intervalle... ex: [0,24[ ou [0,360[ ou [0,2Pi[ | 
|---|
| 49 | TypCoord1C      =  (unsigned long)  (1 << 10), | 
|---|
| 50 | // Coord A intervalle centre... ex: ]-12,12] ou ]-180,180] ou ]-Pi,Pi] | 
|---|
| 51 | TypCoord1L      =  (unsigned long)  (1 << 11), | 
|---|
| 52 | // Coord B intervalle... ex:  [0,12] ou [0,180] ou [0,Pi] (colatitude) | 
|---|
| 53 | TypCoord2C      =  (unsigned long)  (1 << 12), | 
|---|
| 54 | // Coord B intervalle centre... ex: [-6,6] ou [-90,90] ou [-Pi/2,Pi/2] (latitude) | 
|---|
| 55 | TypCoord2L      =  (unsigned long)  (1 << 13), | 
|---|
| 56 |  | 
|---|
| 57 | //------ Les systemes de coordonnees astronomiques | 
|---|
| 58 | // Coordonnees Equatoriales alpha,delta | 
|---|
| 59 | TypCoordEq     =  (unsigned long)  (1 << 15), | 
|---|
| 60 | // Coordonnees Galactiques gLong, gLat | 
|---|
| 61 | TypCoordGal    =  (unsigned long)  (1 << 16), | 
|---|
| 62 | // Coordonnees Horizontales azimuth,altitude | 
|---|
| 63 | TypCoordHor    =  (unsigned long)  (1 << 17), | 
|---|
| 64 | // Coordonnees Ecliptiques EclLong,EclLat | 
|---|
| 65 | TypCoordEcl    =  (unsigned long)  (1 << 18), | 
|---|
| 66 |  | 
|---|
| 67 | //------ Les systemes de coordonnees astronomiques "standard" | 
|---|
| 68 | // Coordonnees Equatoriales alpha,delta | 
|---|
| 69 | TypCoordEqStd     =  (unsigned long)  (TypCoordEq |TypCoord1C|TypCoord1H|TypCoord2L|TypCoord2D), | 
|---|
| 70 | // Coordonnees Galactiques gLong, gLat | 
|---|
| 71 | TypCoordGalStd    =  (unsigned long)  (TypCoordGal|TypCoord1C|TypCoord1D|TypCoord2L|TypCoord2D), | 
|---|
| 72 | // Coordonnees Horizontales azimuth,altitude | 
|---|
| 73 | TypCoordHorStd    =  (unsigned long)  (TypCoordHor|TypCoord1C|TypCoord1D|TypCoord2L|TypCoord2D), | 
|---|
| 74 | // Coordonnees Ecliptiques EclLong,EclLat | 
|---|
| 75 | TypCoordEclStd    =  (unsigned long)  (TypCoordEcl|TypCoord1C|TypCoord1D|TypCoord2L|TypCoord2D), | 
|---|
| 76 |  | 
|---|
| 77 | //------ undef pour la forme | 
|---|
| 78 | TypCoordUndef  =  (unsigned long)  (0) | 
|---|
| 79 | }; | 
|---|
| 80 |  | 
|---|
| 81 | // ------------------- Utilitaires ------------------- | 
|---|
| 82 | unsigned long CoordConvertToStd(unsigned long typ,double* coord1,double* coord2); | 
|---|
| 83 | inline unsigned long CoordConvertToStd(unsigned long typ,double &coord1,double &coord2) | 
|---|
| 84 | {return CoordConvertToStd(typ,&coord1,&coord2);} | 
|---|
| 85 |  | 
|---|
| 86 | unsigned long GetCoordUnit(int coordnum,unsigned long typ); | 
|---|
| 87 |  | 
|---|
| 88 | unsigned long DecodeTypAstro(const char *ctype); | 
|---|
| 89 | inline unsigned long DecodeTypAstro(const string stype) | 
|---|
| 90 | {return DecodeTypAstro(stype.c_str());} | 
|---|
| 91 | string        DecodeTypAstro(unsigned long typ); | 
|---|
| 92 |  | 
|---|
| 93 | void ToCoLat(double* val,unsigned long typ); | 
|---|
| 94 | inline void ToCoLat(double &val,unsigned long typ) | 
|---|
| 95 | {ToCoLat(&val,typ);} | 
|---|
| 96 |  | 
|---|
| 97 | void InRangeLat(double* val,unsigned long typ); | 
|---|
| 98 | inline void InRangeLat(double &val,unsigned long typ) | 
|---|
| 99 | {InRangeLat(&val,typ);} | 
|---|
| 100 |  | 
|---|
| 101 | void InRangeCoLat(double* val,unsigned long typ); | 
|---|
| 102 | inline void InRangeCoLat(double &val,unsigned long typ) | 
|---|
| 103 | {InRangeCoLat(&val,typ);} | 
|---|
| 104 |  | 
|---|
| 105 | /*! | 
|---|
| 106 | \brief Pour remettre la valeur "val" dans la dynamique [0.,range[. | 
|---|
| 107 | Si "vmax" different de "range", c'est la borne superieure | 
|---|
| 108 | qui peut etre atteinte | 
|---|
| 109 | (si elle est depassee, on soustrait "range"). | 
|---|
| 110 | \verbatim | 
|---|
| 111 | r>0 vmax>0 | 
|---|
| 112 | r=24. vmax=24.   -> mets "val" dans [  0,+24[ borne sup exclue | 
|---|
| 113 | r=24. vmax=12.   -> mets "val" dans ]-12,+12] borne inf exclue | 
|---|
| 114 | (ATTENTION: ca ne marche pas pour la latitude [-90,90] | 
|---|
| 115 | car -90 ne peut etre inclus dans l'intervalle) | 
|---|
| 116 | \endverbatim | 
|---|
| 117 | */ | 
|---|
| 118 | inline void InRange(double *val,double range) | 
|---|
| 119 | {*val-=range*floor(*val/range);} | 
|---|
| 120 | inline void InRange(double &val,double range) | 
|---|
| 121 | {val-=range*floor(val/range);} | 
|---|
| 122 |  | 
|---|
| 123 | inline void InRange(double *val,double range,double vmax) | 
|---|
| 124 | {InRange(val,range); if(*val>vmax) *val-=range;} | 
|---|
| 125 | inline void InRange(double &val,double range,double vmax) | 
|---|
| 126 | {InRange(val,range); if(val>vmax) val-=range;} | 
|---|
| 127 |  | 
|---|
| 128 | // ------------------- Gestions des temps ------------------- | 
|---|
| 129 | /*! \ingroup XAstroPack | 
|---|
| 130 | \brief Compute true Julian day from MJD | 
|---|
| 131 | */ | 
|---|
| 132 | inline double TrueJDfrMJD(double mjd) {return mjd + MJD0;} | 
|---|
| 133 |  | 
|---|
| 134 | /*! \ingroup XAstroPack | 
|---|
| 135 | \brief Compute MJD from true Julian day | 
|---|
| 136 | */ | 
|---|
| 137 | inline double MJDfrTrueJD(double jd) {return jd - MJD0;} | 
|---|
| 138 |  | 
|---|
| 139 | double MJDfrDate(double dy,int mn,int yr); | 
|---|
| 140 |  | 
|---|
| 141 | void DatefrMJD(double mjd,double *dy,int *mn,int *yr); | 
|---|
| 142 | inline void DatefrMJD(double mjd,double &dy,int &mn,int &yr) | 
|---|
| 143 | {DatefrMJD(mjd,&dy,&mn,&yr);} | 
|---|
| 144 |  | 
|---|
| 145 | double YearfrMJD(double mjd); | 
|---|
| 146 |  | 
|---|
| 147 | double MJDfrYear(double yr); | 
|---|
| 148 |  | 
|---|
| 149 | void YDfrMJD(double mjd,double *dy,int *yr); | 
|---|
| 150 | inline void YDfrMJD(double mjd,double &dy,int &yr) | 
|---|
| 151 | {YDfrMJD(mjd,&dy,&yr);} | 
|---|
| 152 |  | 
|---|
| 153 | int IsLeapYear(int y); | 
|---|
| 154 |  | 
|---|
| 155 | int DayOrder(double mjd,int *dow); | 
|---|
| 156 | inline int DayOrder(double mjd,int &dow) | 
|---|
| 157 | {return DayOrder(mjd,&dow);} | 
|---|
| 158 |  | 
|---|
| 159 | int DaysInMonth(double mjd); | 
|---|
| 160 | double MJDat0hFrMJD(double mjd); | 
|---|
| 161 | double HfrMJD(double mjd); | 
|---|
| 162 | double GSTfrUTC(double mjd0,double utc); | 
|---|
| 163 | double UTCfrGST(double mjd0,double gst); | 
|---|
| 164 |  | 
|---|
| 165 | /*! \ingroup XAstroPack | 
|---|
| 166 | \brief return local sidereal time from greenwich mean siderial time and longitude | 
|---|
| 167 | \param precis : if not zero, then correct for obliquity and nutation | 
|---|
| 168 | \warning no nutation or obliquity correction are done. | 
|---|
| 169 | */ | 
|---|
| 170 | inline double LSTfrGST(double gst,double geolng) | 
|---|
| 171 | {double lst = gst + deghr(geolng); InRange(&lst,24.); return lst;} | 
|---|
| 172 |  | 
|---|
| 173 | double GST0(double mjd0); | 
|---|
| 174 | double LSTfrMJD(double mjd,double geolng); | 
|---|
| 175 |  | 
|---|
| 176 | void HMSfrHdec(double hd,int *h,int *mn,double *s); | 
|---|
| 177 | inline void HMSfrHdec(double hd,int &h,int &mn,double &s) | 
|---|
| 178 | {HMSfrHdec(hd,&h,&mn,&s);} | 
|---|
| 179 |  | 
|---|
| 180 | double HdecfrHMS(int h,int mn,double s); | 
|---|
| 181 | string ToStringHMS(int h,int mn,double s); | 
|---|
| 182 | string ToStringHdec(double hd); | 
|---|
| 183 |  | 
|---|
| 184 | // ------------------- Calculs Divers ------------------- | 
|---|
| 185 | void Precess(double mjd1,double mjd2,double ra1,double dec1,double *ra2,double *dec2); | 
|---|
| 186 | inline void Precess(double mjd1,double mjd2,double ra1,double dec1,double &ra2,double &dec2) | 
|---|
| 187 | {Precess(mjd1,mjd2,ra1,dec1,&ra2,&dec2);} | 
|---|
| 188 |  | 
|---|
| 189 | inline void PrecessInPlace(double mjd1,double mjd2,double* ra,double* dec) { | 
|---|
| 190 | double ra1=*ra, dec1=*dec; | 
|---|
| 191 | Precess(mjd1,mjd2,ra1,dec1,ra,dec); | 
|---|
| 192 | } | 
|---|
| 193 | inline void PrecessInPlace(double mjd1,double mjd2,double &ra,double &dec) { | 
|---|
| 194 | double ra1=ra, dec1=dec; | 
|---|
| 195 | Precess(mjd1,mjd2,ra1,dec1,ra,dec); | 
|---|
| 196 | } | 
|---|
| 197 |  | 
|---|
| 198 | double AirmassfrAlt(double alt); | 
|---|
| 199 | double HelioCorr(double jd,double ra,double dec); | 
|---|
| 200 |  | 
|---|
| 201 | // ------------------- Transformation de coordonnees ------------------- | 
|---|
| 202 | /*! \ingroup XAstroPack | 
|---|
| 203 | \brief Give the hour angle from local sideral time and right ascension | 
|---|
| 204 | \warning right ascencion should be first precessed to date of interest | 
|---|
| 205 | \warning no nutation or obliquity correction are done. | 
|---|
| 206 | */ | 
|---|
| 207 | // Attention au probleme de la discontinuite 0h <==> 24h | 
|---|
| 208 | // ts=1  ra=23 ; (ts-ra)=-22 <-12 --> ha = +2 = +24 + (ts-ra) | 
|---|
| 209 | // ts=23 ra=1  ; (ts-ra)=+22 >+12 --> ha = -2 = -24 + (ts-ra) | 
|---|
| 210 | inline double HafrRaTS(double lst,double ra) | 
|---|
| 211 | {double ha = lst - ra; InRange(&ha,24.,12.); return ha;} | 
|---|
| 212 |  | 
|---|
| 213 | /*! \ingroup XAstroPack | 
|---|
| 214 | \brief Give the local sideral time and the hour angle return the right ascencion | 
|---|
| 215 | \warning right ascencion is the value precessed to date of interest | 
|---|
| 216 | \warning no nutation or obliquity correction are done. | 
|---|
| 217 | */ | 
|---|
| 218 | inline double RafrHaTS(double lst,double ha) | 
|---|
| 219 | {double ra = lst - ha; InRange(&ra,24.); return ra;} | 
|---|
| 220 |  | 
|---|
| 221 | void EqtoGal(double mjd,double ra,double dec,double *glng,double *glat); | 
|---|
| 222 | inline void EqtoGal(double mjd,double ra,double dec,double &glng,double &glat) | 
|---|
| 223 | {EqtoGal(mjd,ra,dec,&glng,&glat);} | 
|---|
| 224 |  | 
|---|
| 225 |  | 
|---|
| 226 | void GaltoEq(double mjd,double glng,double glat,double *ra,double *dec); | 
|---|
| 227 | inline void GaltoEq(double mjd,double glng,double glat,double &ra,double &dec) | 
|---|
| 228 | {GaltoEq( mjd, glng, glat, &ra, &dec);} | 
|---|
| 229 |  | 
|---|
| 230 | void EqHtoHor(double geolat,double ha,double dec,double *az,double *alt); | 
|---|
| 231 | inline void EqHtoHor(double geolat,double ha,double dec,double &az,double &alt) | 
|---|
| 232 | {EqHtoHor( geolat, ha, dec, &az, &alt);} | 
|---|
| 233 |  | 
|---|
| 234 | void HortoEqH(double geolat,double az,double alt,double *ha,double *dec); | 
|---|
| 235 | inline void HortoEqH(double geolat,double az,double alt,double &ha,double &dec) | 
|---|
| 236 | {HortoEqH( geolat, az, alt, &ha, &dec);} | 
|---|
| 237 |  | 
|---|
| 238 | void EqtoHor(double geolat,double lst,double ra,double dec,double *az,double *alt); | 
|---|
| 239 | inline void EqtoHor(double geolat,double lst,double ra,double dec,double &az,double &alt) | 
|---|
| 240 | {EqtoHor( geolat, lst, ra, dec, &az, &alt);} | 
|---|
| 241 |  | 
|---|
| 242 | void HortoEq(double geolat,double lst,double az,double alt,double *ra,double *dec); | 
|---|
| 243 | inline void HortoEq(double geolat,double lst,double az,double alt,double &ra,double &dec) | 
|---|
| 244 | {HortoEq( geolat, lst, az, alt, &ra, &dec);} | 
|---|
| 245 |  | 
|---|
| 246 | void EqtoEcl(double mjd,double ra,double dec,double *eclng,double *eclat); | 
|---|
| 247 | inline void EqtoEcl(double mjd,double ra,double dec,double &eclng,double &eclat) | 
|---|
| 248 | {EqtoEcl( mjd, ra, dec, &eclng, &eclat);} | 
|---|
| 249 |  | 
|---|
| 250 | void EcltoEq(double mjd,double eclng,double eclat,double *ra,double *dec); | 
|---|
| 251 | inline void EcltoEq(double mjd,double eclng,double eclat,double &ra,double &dec) | 
|---|
| 252 | {EcltoEq( mjd, eclng, eclat, &ra, &dec);} | 
|---|
| 253 |  | 
|---|
| 254 | // ------------------- Positions des astres ------------------- | 
|---|
| 255 | void SunPos(double mjd,double *eclsn,double *ecbsn,double *rsn); | 
|---|
| 256 | inline void SunPos(double mjd,double &eclsn,double &ecbsn,double &rsn) | 
|---|
| 257 | {SunPos( mjd, &eclsn, &ecbsn, &rsn);} | 
|---|
| 258 |  | 
|---|
| 259 | void MoonPos(double mjd,double *lmn,double *bmn,double *rho); | 
|---|
| 260 | inline void MoonPos(double mjd,double &lmn,double &bmn,double &rho) | 
|---|
| 261 | {MoonPos( mjd, &lmn, &bmn, &rho);} | 
|---|
| 262 |  | 
|---|
| 263 | void PlanetPos(double mjd,PLCode numplan,double *sunecl,double *sunecb,double *sundist | 
|---|
| 264 | ,double *geodist,double *geoecl,double *geoecb | 
|---|
| 265 | ,double *diamang,double *mag); | 
|---|
| 266 | inline void PlanetPos(double mjd,PLCode numplan,double &sunecl,double &sunecb,double &sundist | 
|---|
| 267 | ,double &geodist,double &geoecl,double &geoecb | 
|---|
| 268 | ,double &diamang,double &mag) | 
|---|
| 269 | {PlanetPos(mjd,numplan,&sunecl,&sunecb,&sundist,&geodist,&geoecl,&geoecb,&diamang,&mag);} | 
|---|
| 270 |  | 
|---|
| 271 | /*! \ingroup XAstroPack | 
|---|
| 272 | \brief Same as PlanetPos above with less arguments | 
|---|
| 273 | */ | 
|---|
| 274 | inline void PlanetPos(double mjd,PLCode numplan,double *geoecl,double *geoecb | 
|---|
| 275 | ,double *geodist,double *diamang) | 
|---|
| 276 | { | 
|---|
| 277 | double sunecl,sunecb,sundist,mag; | 
|---|
| 278 | PlanetPos(mjd,numplan,&sunecl,&sunecb,&sundist,geodist,geoecl,geoecb,diamang,&mag); | 
|---|
| 279 | } | 
|---|
| 280 | inline void PlanetPos(double mjd,PLCode numplan,double &geoecl,double &geoecb | 
|---|
| 281 | ,double &geodist,double &diamang) | 
|---|
| 282 | { | 
|---|
| 283 | double sunecl,sunecb,sundist,mag; | 
|---|
| 284 | PlanetPos(mjd,numplan,sunecl,sunecb,sundist,geodist,geoecl,geoecb,diamang,mag); | 
|---|
| 285 | } | 
|---|
| 286 |  | 
|---|
| 287 | /*! \ingroup XAstroPack | 
|---|
| 288 | \brief Give Jupiter position | 
|---|
| 289 | */ | 
|---|
| 290 | inline void JupiterPos(double mjd,double *ecl,double *ecb,double *geodist,double *diamang) | 
|---|
| 291 | { | 
|---|
| 292 | PlanetPos(mjd,JUPITER,ecl,ecb,geodist,diamang); | 
|---|
| 293 | } | 
|---|
| 294 | inline void JupiterPos(double mjd,double &ecl,double &ecb,double &geodist,double &diamang) | 
|---|
| 295 | { | 
|---|
| 296 | PlanetPos(mjd,JUPITER,ecl,ecb,geodist,diamang); | 
|---|
| 297 | } | 
|---|
| 298 |  | 
|---|
| 299 | /*! \ingroup XAstroPack | 
|---|
| 300 | \brief Give Saturn position | 
|---|
| 301 | */ | 
|---|
| 302 | inline void SaturnPos(double mjd,double *ecl,double *ecb,double *geodist,double *diamang) | 
|---|
| 303 | { | 
|---|
| 304 | PlanetPos(mjd,SATURN,ecl,ecb,geodist,diamang); | 
|---|
| 305 | } | 
|---|
| 306 | inline void SaturnPos(double mjd,double &ecl,double &ecb,double &geodist,double &diamang) | 
|---|
| 307 | { | 
|---|
| 308 | PlanetPos(mjd,SATURN,ecl,ecb,geodist,diamang); | 
|---|
| 309 | } | 
|---|
| 310 |  | 
|---|
| 311 | #endif | 
|---|