Changeset 15190 for trunk/FACT++


Ignore:
Timestamp:
03/30/13 13:35:20 (12 years ago)
Author:
tbretz
Message:
Implemented function to get the time of the previous and next sun-rise. Updated NightAsInt to use that as reference instead of noon, to get consistent with the changes in the datalogger.
Location:
trunk/FACT++/src
Files:
2 edited

Legend:

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

    r15006 r15190  
    2626// **************************************************************************
    2727#include "Time.h"
     28
     29#ifdef HAVE_LIBNOVA
     30#include <libnova/solar.h>
     31#include <libnova/rise_set.h>
     32#endif
    2833
    2934using namespace std;
     
    291296//
    292297//! @returns
    293 //!     an int corresponding to the stored time minus 12 hours of the form
     298//!     The time of the previous sun-rise, relative to given horizon in degree,
     299//!     for the coordinates of the ORM, La Palma.
     300//!     if libnova was not compiled in, it will return the next noon.
     301//!
     302//!  @throws
     303//!     a runtime_error exception is thrown if the calculation of the sun-rise
     304//!     by libnova fails (this would happen if libnova thinks the sun is
     305//!     circumpolar which should never happen at La Palma)
     306//
     307Time Time::GetPrevSunRise(double horizon) const
     308{
     309#ifdef HAVE_LIBNOVA
     310    const double lon = -(17.+53./60+26.525/3600);
     311    const double lat =   28.+45./60+42.462/3600;
     312
     313    ln_lnlat_posn observer;
     314    observer.lng = lon;
     315    observer.lat = lat;
     316
     317    ln_rst_time sun_day;
     318    if (ln_get_solar_rst_horizon(JD()-0.5, &observer, horizon, &sun_day)==1)
     319        throw runtime_error("ln_get_solar_rst_horizon reported the sun to be circumpolar at the coordinates of La Palma!");
     320
     321    if (Time(sun_day.rise)<*this)
     322        return Time(sun_day.rise);
     323
     324    if (ln_get_solar_rst_horizon(JD()-1.5, &observer, horizon, &sun_day)==1)
     325        throw runtime_error("ln_get_solar_rst_horizon reported the sun to be circumpolar at the coordinates of La Palma!");
     326
     327    return Time(sun_day.rise);
     328#else
     329    return Time(floor(GetMjd()-0.5)+0.5);
     330#endif
     331}
     332
     333// --------------------------------------------------------------------------
     334//
     335//! @returns
     336//!     The time of the next sun-rise, relative to given horizon in degree,
     337//!     for the coordinates of the ORM, La Palma.
     338//!     if libnova was not compiled in, it will return the next noon.
     339//!
     340//!  @throws
     341//!     a runtime_error exception is thrown if the calculation of the sun-rise
     342//!     by libnova fails (this would happen if libnova thinks the sun is
     343//!     circumpolar which should never happen at La Palma)
     344//
     345Time Time::GetNextSunRise(double horizon) const
     346{
     347#ifdef HAVE_LIBNOVA
     348    const double lon = -(17.+53./60+26.525/3600);
     349    const double lat =   28.+45./60+42.462/3600;
     350
     351    ln_lnlat_posn observer;
     352    observer.lng = lon;
     353    observer.lat = lat;
     354
     355    ln_rst_time sun_day;
     356    if (ln_get_solar_rst_horizon(JD()-0.5, &observer, horizon, &sun_day)==1)
     357        throw runtime_error("ln_get_solar_rst_horizon reported the sun to be circumpolar at the coordinates of La Palma!");
     358
     359    if (Time(sun_day.rise)>=*this)
     360        return Time(sun_day.rise);
     361
     362    if (ln_get_solar_rst_horizon(JD()+0.5, &observer, horizon, &sun_day)==1)
     363        throw runtime_error("ln_get_solar_rst_horizon reported the sun to be circumpolar at the coordinates of La Palma!");
     364
     365    return Time(sun_day.rise);
     366#else
     367    return Time(floor(GetMjd()+0.5))+0.5;
     368#endif
     369}
     370
     371// --------------------------------------------------------------------------
     372//
     373//! Calls GetPrevSunRise(LN_SOLAR_STANDART_HORIZON)
     374//
     375Time Time::GetPrevSunRise() const
     376{
     377    return GetPrevSunRise(LN_SOLAR_STANDART_HORIZON);
     378}
     379
     380// --------------------------------------------------------------------------
     381//
     382//! Calls GetNextSunRise(LN_SOLAR_STANDART_HORIZON)
     383//
     384Time Time::GetNextSunRise() const
     385{
     386    return GetNextSunRise(LN_SOLAR_STANDART_HORIZON);
     387}
     388
     389// --------------------------------------------------------------------------
     390//
     391//! @returns
     392//!     Returns an int corresponding to the current sun-cycle, that means
     393//!     the day of the last sun-rise w.r.t. this Time.
    294394//!     YYYYMMDD, e.g. 20111224 for Christmas eve 2011
     395//!
     396//! @remark
     397//!     Before March 30th 2013, 12:00 noon was the reference and the
     398//!     returned value belonged to the day of sun-set within the
     399//!     24h period between two noon's.
    295400//
    296401int Time::NightAsInt() const
    297402{
    298     const Time tm = *this - boost::posix_time::hours(12);
     403    const Time tm = GetPrevSunRise();
    299404    return tm.Y()*10000 + tm.M()*100 + tm.D();
    300405}
     
    379484    return in;
    380485}
    381 
  • trunk/FACT++/src/Time.h

    r15006 r15190  
    113113    std::string SecondsTo(const Time & = Time()) const;
    114114
     115    Time GetPrevSunRise(double horizon) const;
     116    Time GetNextSunRise(double horizon) const;
     117
     118    Time GetPrevSunRise() const;
     119    Time GetNextSunRise() const;
     120
    115121    int NightAsInt() const;
    116122};
Note: See TracChangeset for help on using the changeset viewer.