Changeset 18966 for trunk/FACT++


Ignore:
Timestamp:
04/04/18 17:53:02 (6 years ago)
Author:
tbretz
Message:
Moved the path to the Makefile, allow to define the location for SunRise/Set and NightAsInt. Default is ORM -> no change.
Location:
trunk/FACT++/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/FACT++/src/Time.cc

    r18820 r18966  
    2727#include "Time.h"
    2828
    29 #ifdef HAVE_LIBNOVA
    30 #include "../externals/nova.h"
    31 #endif
    32 
    3329using namespace std;
    3430using namespace boost::posix_time;
     31
     32#ifdef HAVE_LIBNOVA
     33#include "externals/nova.h"
     34#endif
    3535
    3636const boost::gregorian::date Time::fUnixOffset(1970, 1, 1);
     
    303303//! @returns
    304304//!     The time of the previous sun-rise, relative to given horizon in degree,
    305 //!     for the coordinates of the ORM, La Palma.
    306 //!     if libnova was not compiled in, it will return the next noon.
     305//!     for the observatory location given (see nova.h).
     306//!     If the sun is circumpolar, it simply return the intgeral fraction of
     307//!     the current MJD.
     308//!     If libnova was not compiled in, it will return the next noon.
    307309//!
    308310//!  @throws
    309 //!     a runtime_error exception is thrown if the calculation of the sun-rise
    310 //!     by libnova fails (this would happen if libnova thinks the sun is
    311 //!     circumpolar which should never happen at La Palma)
    312 //
    313 Time Time::GetPrevSunRise(double horizon) const
     311//!     A runtime_error exception is thrown if the observatory location
     312//!     is not defined (see nova.h)
     313//
     314Time Time::GetPrevSunRise(double horizon, const string &obs) const
    314315{
    315316#ifdef HAVE_LIBNOVA
    316     Nova::LnLatPosn obs = Nova::kORM;
     317    const Nova::LnLatPosn posn(obs);
     318    if (!posn.isValid())
     319        throw runtime_error("Observatory location '"+obs+"' unknown.");
    317320
    318321    ln_rst_time sun_day;
    319     if (ln_get_solar_rst_horizon(JD()-0.5, &obs, horizon, &sun_day)==1)
    320         throw runtime_error("ln_get_solar_rst_horizon reported the sun to be circumpolar at the coordinates of La Palma!");
     322    if (ln_get_solar_rst_horizon(JD()-0.5, const_cast<Nova::LnLatPosn*>(&posn), horizon, &sun_day)==1)
     323        return Time(floor(Mjd()));
    321324
    322325    if (Time(sun_day.rise)<*this)
    323326        return Time(sun_day.rise);
    324327
    325     if (ln_get_solar_rst_horizon(JD()-1.5, &obs, horizon, &sun_day)==1)
    326         throw runtime_error("ln_get_solar_rst_horizon reported the sun to be circumpolar at the coordinates of La Palma!");
     328    if (ln_get_solar_rst_horizon(JD()-1.5, const_cast<Nova::LnLatPosn*>(&posn), horizon, &sun_day)==1)
     329        return Time(floor(Mjd()));
    327330
    328331    return Time(sun_day.rise);
     
    336339//! @returns
    337340//!     The time of the next sun-rise, relative to given horizon in degree,
    338 //!     for the coordinates of the ORM, La Palma.
    339 //!     if libnova was not compiled in, it will return the next noon.
     341//!     for the observatory location given (see nova.h).
     342//!     If the sun is circumpolar, it simply return the intgeral fraction of
     343//!     the current MJD+1.
     344//!     If libnova was not compiled in, it will return the next noon.
    340345//!
    341346//!  @throws
    342 //!     a runtime_error exception is thrown if the calculation of the sun-rise
    343 //!     by libnova fails (this would happen if libnova thinks the sun is
    344 //!     circumpolar which should never happen at La Palma)
    345 //
    346 Time Time::GetNextSunRise(double horizon) const
     347//!     A runtime_error exception is thrown if the observatory location
     348//!     is not defined (see nova.h)
     349//
     350Time Time::GetNextSunRise(double horizon, const string &obs) const
    347351{
    348352#ifdef HAVE_LIBNOVA
    349     Nova::LnLatPosn obs = Nova::kORM;
     353    const Nova::LnLatPosn posn(obs);
     354    if (!posn.isValid())
     355        throw runtime_error("Observatory location '"+obs+"' unknown.");
    350356
    351357    ln_rst_time sun_day;
    352     if (ln_get_solar_rst_horizon(JD()-0.5, &obs, horizon, &sun_day)==1)
    353         throw runtime_error("ln_get_solar_rst_horizon reported the sun to be circumpolar at the coordinates of La Palma!");
     358    if (ln_get_solar_rst_horizon(JD()-0.5, const_cast<Nova::LnLatPosn*>(&posn), horizon, &sun_day)==1)
     359        return Time(floor(Mjd())+1);
    354360
    355361    if (Time(sun_day.rise)>=*this)
    356362        return Time(sun_day.rise);
    357363
    358     if (ln_get_solar_rst_horizon(JD()+0.5, &obs, horizon, &sun_day)==1)
    359         throw runtime_error("ln_get_solar_rst_horizon reported the sun to be circumpolar at the coordinates of La Palma!");
     364    if (ln_get_solar_rst_horizon(JD()+0.5, const_cast<Nova::LnLatPosn*>(&posn), horizon, &sun_day)==1)
     365        return Time(floor(Mjd())+1);
    360366
    361367    return Time(sun_day.rise);
    362368#else
    363     return Time(floor(Mjd()+0.5))+0.5;
     369    return Time(floor(Mjd()+0.5)+0.5);
    364370#endif
    365371}
     
    369375//! Calls GetPrevSunRise(LN_SOLAR_STANDART_HORIZON)
    370376//
    371 Time Time::GetPrevSunRise() const
    372 {
    373     return GetPrevSunRise(LN_SOLAR_STANDART_HORIZON);
     377Time Time::GetPrevSunRise(const string &obs) const
     378{
     379#ifdef HAVE_LIBNOVA
     380    return GetPrevSunRise(LN_SOLAR_STANDART_HORIZON, obs);
     381#else
     382    return GetPrevSunRise(-0.8333, obs);
     383#endif
    374384}
    375385
     
    378388//! Calls GetNextSunRise(LN_SOLAR_STANDART_HORIZON)
    379389//
    380 Time Time::GetNextSunRise() const
    381 {
    382     return GetNextSunRise(LN_SOLAR_STANDART_HORIZON);
     390Time Time::GetNextSunRise(const string &obs) const
     391{
     392#ifdef HAVE_LIBNOVA
     393    return GetNextSunRise(LN_SOLAR_STANDART_HORIZON, obs);
     394#else
     395    return GetNextSunRise(-0.8333, obs);
     396#endif
    383397}
    384398
     
    395409//!     24h period between two noon's.
    396410//
    397 uint32_t Time::NightAsInt() const
    398 {
    399     const Time tm = GetPrevSunRise();
     411uint32_t Time::NightAsInt(const string &obs) const
     412{
     413    const Time tm = GetPrevSunRise(obs);
    400414    return tm.Y()*10000 + tm.M()*100 + tm.D();
    401415}
  • trunk/FACT++/src/Time.h

    r16376 r18966  
    114114    std::string SecondsTo(const Time & = Time()) const;
    115115
    116     Time GetPrevSunRise(double horizon) const;
    117     Time GetNextSunRise(double horizon) const;
     116    Time GetPrevSunRise(double horizon, const std::string &obs="ORM") const;
     117    Time GetNextSunRise(double horizon, const std::string &obs="ORM") const;
    118118
    119     Time GetPrevSunRise() const;
    120     Time GetNextSunRise() const;
     119    Time GetPrevSunRise(const std::string &obs="ORM") const;
     120    Time GetNextSunRise(const std::string &obs="ORM") const;
    121121
    122     uint32_t NightAsInt() const;
     122    uint32_t NightAsInt(const std::string &obs="ORM") const;
    123123};
    124124
Note: See TracChangeset for help on using the changeset viewer.