Changeset 18366 for trunk/FACT++/src


Ignore:
Timestamp:
11/07/15 18:46:37 (9 years ago)
Author:
tbretz
Message:
Fixed the rise and set times... under some circumstances, they were not correct.
File:
1 edited

Legend:

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

    r18364 r18366  
    8686    Time time;
    8787
    88     Time fRiseDayTime;
    89     Time fRiseCivil;
    90     Time fRiseAstronomical;
    91     Time fRiseDarkTime;
    92 
    93     Time fSetDayTime;
    94     Time fSetCivil;
    95     Time fSetAstronomical;
    96     Time fSetDarkTime;
     88    // This is always the time of the next...
     89    Time fSunRise00;
     90    Time fSunRise06;
     91    Time fSunRise12;
     92    Time fSunRise18;
     93
     94    Time fSunSet00;
     95    Time fSunSet06;
     96    Time fSunSet12;
     97    Time fSunSet18;
    9798
    9899    int state;
     
    103104    bool visible;
    104105
     106    Nova::RstTime Rst(double jd, double hrz=LN_SOLAR_STANDART_HORIZON)
     107    {
     108        Nova::RstTime rs = Nova::GetSolarRst(jd-0.5, hrz);
     109        if (jd>rs.rise || jd>rs.set)
     110        {
     111            const Nova::RstTime rs2 = Nova::GetSolarRst(jd+0.5, hrz);
     112            if (jd>rs.rise)
     113                rs.rise = rs2.rise;
     114            if (jd>rs.set)
     115                rs.set = rs2.set;
     116        }
     117        return rs;
     118    }
     119
    105120public:
    106121    Sun() : time(Time::none)
     
    116131        const double JD = time.JD();
    117132
    118         // Warning: return code of 1 means circumpolar and is not checked!
     133        // >0deg           : day
     134        //  -6deg -   0deg : civil        twilight
     135        // -12deg -  -6deg : nautical     twilight
     136        // -18deg - -12deg : astronomical twilight
     137        // <-18deg         : night
     138
     139        const Nova::RstTime sun00 = Rst(JD);
     140        const Nova::RstTime sun06 = Rst(JD,  -6);
     141        const Nova::RstTime sun12 = Rst(JD, -12);
     142        const Nova::RstTime sun18 = Rst(JD, -18);
     143
     144        fSunRise00 = sun00.rise;
     145        fSunRise06 = sun06.rise;
     146        fSunRise12 = sun12.rise;
     147        fSunRise18 = sun18.rise;
     148
     149        fSunSet00  = sun00.set;
     150        fSunSet06  = sun06.set;
     151        fSunSet12  = sun12.set;
     152        fSunSet18  = sun18.set;
     153
     154        array<double,8> arr =
     155        {{
     156            sun00.set,
     157            sun06.set,
     158            sun12.set,
     159            sun18.set,
     160            sun18.rise,
     161            sun12.rise,
     162            sun06.rise,
     163            sun00.rise,
     164        }};
     165
     166
     167        state = std::min_element(arr.begin(), arr.end())-arr.begin();
     168
     169        string name[] =
     170        {
     171            "day time",
     172            "civil twilight",
     173            "nautical twilight",
     174            "astron. twilight",
     175            "dark time",
     176            "astron. twilight",
     177            "nautical twilight",
     178            "civil twilight"
     179        };
     180
     181        description = name[state];
     182
     183        const string txt = fSunRise18<fSunSet18 ?
     184            time.MinutesTo(fSunRise18)+"&uarr;" :
     185            time.MinutesTo(fSunSet18)+"&darr;";
     186
     187        description += " ["+txt+"]";
     188
     189        isday = state==0;
     190
     191        switch (state)
     192        {
     193        case 0:                  color = HTML::kRed;     break;
     194        case 1: case 2:          color = HTML::kYellow;  break;
     195        case 3: case 4:  case 5: color = HTML::kGreen;   break;
     196        case 6: case 7:          color = HTML::kYellow;  break;
     197        }
     198
     199        visible = state==0;
     200
     201        /*
     202         // Warning: return code of 1 means circumpolar and is not checked!
    119203        Nova::RstTime sun_day          = Nova::GetSolarRst(JD-0.5);
    120204        Nova::RstTime sun_civil        = Nova::GetSolarRst(JD-0.5,  -6);
     
    156240        }
    157241
    158         // case 0: midnight to sun-rise | !is_day && !is_night | rise/set
    159         // case 1: sun-rise to sun-set  |  is_day && !is_night | set /rise
    160         // case 2: sun-set  to midnight |  is_day &&  is_night | rise/set
     242        // case 0: midnight to sun-rise | !is_day && !is_night | rise/set  | -> isday=0
     243        // case 1: sun-rise to sun-set  |  is_day && !is_night | set /rise | -> isday=1
     244        // case 2: sun-set  to midnight |  is_day &&  is_night | rise/set  | -> isday=0
    161245
    162246        isday = is_day^is_night;
    163247
    164         state = isday ? 4 : 0;
    165         if (time>fSetDayTime)       state++;
    166         if (time>fSetCivil)         state++;
    167         if (time>fSetAstronomical)  state++;
    168         if (time>fSetDarkTime)      state++;
    169 
    170         if (time>fRiseDarkTime)     state++;
    171         if (time>fRiseAstronomical) state++;
    172         if (time>fRiseCivil)        state++;
    173         if (time>fRiseDayTime)      state++;
     248        Time fRiseDayTime;      //   0: Start of day time (=end of civil twilight)
     249        Time fRiseCivil;        //  -6: End of nautical twilight
     250        Time fRiseAstronomical; // -12: End of astron. twilight
     251        Time fRiseDarkTime;     // -18: End of dark time
     252
     253        Time fSetDayTime;       //   0: End of day time (=start of civil twilight)
     254        Time fSetCivil;         //  -6: Start of nautical twilight
     255        Time fSetAstronomical;  // -12: Start of astron. twilight
     256        Time fSetDarkTime;      // -18: Start of dark time
     257
     258        state = isday ? 4 : 0;               // 0 [-> Day time       ]
     259        if (time>fSetDayTime)       state++; // 1 [-> Civil  twilight]
     260        if (time>fSetCivil)         state++; // 2 [-> Naut.  twilight]
     261        if (time>fSetAstronomical)  state++; // 3 [-> Astro. twilight]
     262        if (time>fSetDarkTime)      state++; // 4 [-> Dark time      ]
     263
     264        if (time>fRiseDarkTime)     state++; // 5 [-> Astro. twilight]
     265        if (time>fRiseAstronomical) state++; // 6 [-> Naut.  twilight]
     266        if (time>fRiseCivil)        state++; // 7 [-> Civil  twilight]
     267        if (time>fRiseDayTime)      state++; // 8 [-> Day time       ]
    174268
    175269        string name[] =
    176270        {
    177             "dark time",
    178             "astron. twilight",
    179             "civil twilight",
    180             "sunrise",
    181             "day time",
    182             "sunset",
    183             "civil twilight",
    184             "astron. twilight",
    185             "dark time"
     271            "dark time",          // 0
     272            "astron. twilight",   // 1
     273            "civil twilight",     // 2
     274            "sunrise",            // 3
     275            "day time",           // 4
     276            "sunset",             // 5
     277            "civil twilight",     // 6
     278            "astron. twilight",   // 7
     279            "dark time"           // 8
    186280        };
    187281
     
    204298
    205299        visible = state>=3 && state<=5;
     300        */
    206301#endif
    207302    }
     
    12001295        vector<float> Uov(ptr+416+6, ptr+416+6+320);
    12011296
    1202         WriteCam(d, "cam-feedback-overvoltage", Uov, 0.2, 1.0);
     1297        WriteCam(d, "cam-feedback-overvoltage", Uov, 0.2, -0.1);
    12031298
    12041299        const Statistics stat2(Uov);
     
    21422237    pair<vector<float>, pair<Time, float>> GetVisibility(Nova::EquPosn *src=0)
    21432238    {
    2144         const double sunset  = fSun.fSetAstronomical.JD();
    2145         const double sunrise = fSun.fRiseAstronomical.JD();
     2239        const double sunset  = fSun.fSunSet12.JD()-1;
     2240        const double sunrise = fSun.fSunRise12.JD();
    21462241
    21472242        Nova::EquPosn  moon;
     
    21822277    pair<vector<float>, pair<Time, float>> GetLightCondition(const Nova::EquPosn &src_pos)
    21832278    {
    2184         const double sunset  = fSun.fSetAstronomical.JD();
    2185         const double sunrise = fSun.fRiseAstronomical.JD();
     2279        const double sunset  = fSun.fSunSet12.JD()-1;
     2280        const double sunrise = fSun.fSunRise12.JD();
    21862281
    21872282        double max   = -1;
     
    22282323
    22292324        vector<string> color(8, HTML::kWhite);
    2230         color[fSun.state%8] = HTML::kBlue;
     2325        color[fSun.state] = HTML::kBlue;
    22312326
    22322327        ostringstream out;
    22332328        out << setprecision(3);
    22342329        out << now.JavaDate() << '\n';
    2235         out << color[0] << '\t' << fSun.fRiseDarkTime.GetAsStr("%H:%M") << '\n';
    2236         out << color[1] << '\t' << fSun.fRiseAstronomical.GetAsStr("%H:%M") << '\n';
    2237         out << color[2] << '\t' << fSun.fRiseCivil.GetAsStr("%H:%M") << '\n';
    2238         out << color[3] << '\t' << fSun.fRiseDayTime.GetAsStr("%H:%M") << '\n';
    2239 
    2240         out << color[4] << '\t' << fSun.fSetDayTime.GetAsStr("%H:%M") << '\n';
    2241         out << color[5] << '\t' << fSun.fSetCivil.GetAsStr("%H:%M") << '\n';
    2242         out << color[6] << '\t' << fSun.fSetAstronomical.GetAsStr("%H:%M") << '\n';
    2243         out << color[7] << '\t' << fSun.fSetDarkTime.GetAsStr("%H:%M") << '\n';
     2330        out << color[4] << '\t' << fSun.fSunRise18.GetAsStr("%H:%M") << '\n';
     2331        out << color[5] << '\t' << fSun.fSunRise12.GetAsStr("%H:%M") << '\n';
     2332        out << color[6] << '\t' << fSun.fSunRise06.GetAsStr("%H:%M") << '\n';
     2333        out << color[7] << '\t' << fSun.fSunRise00.GetAsStr("%H:%M") << '\n';
     2334
     2335        out << color[0] << '\t' << fSun.fSunSet00.GetAsStr("%H:%M") << '\n';
     2336        out << color[1] << '\t' << fSun.fSunSet06.GetAsStr("%H:%M") << '\n';
     2337        out << color[2] << '\t' << fSun.fSunSet12.GetAsStr("%H:%M") << '\n';
     2338        out << color[3] << '\t' << fSun.fSunSet18.GetAsStr("%H:%M") << '\n';
    22442339
    22452340        ofstream(fPath+"/sun.data") << out.str();
     
    24242519            }
    24252520
    2426             if (fSun.fSetAstronomical>fSun.fRiseAstronomical)
    2427                 fSun.fSetAstronomical += boost::posix_time::hours(24);
     2521            const Time st = fSun.fSunSet12;;
     2522            const Time rs = fSun.fSunRise12;
    24282523
    24292524            ostringstream title;
    2430             title << fSun.fSetAstronomical.GetAsStr("%H:%M");
     2525            title << st.GetAsStr("%H:%M");
    24312526            title << " / ";
    2432             title << ((fSun.fRiseAstronomical-fSun.fSetAstronomical)/20).minutes();
     2527            title << ((rs>st?rs-st:st-rs)/20).minutes();
    24332528            title << "' / ";
    2434             title << fSun.fRiseAstronomical.GetAsStr("%H:%M");
     2529            title << rs.GetAsStr("%H:%M");
    24352530
    24362531            out  << '\n';
     
    27872882                out << " &#9788;";
    27882883                if (fDimDriveControl.state()<Drive::State::kInitialized)
    2789                     out << " [" << fSun.fSetCivil.MinutesTo() << "&darr;]";
     2884                    out << " [" << fSun.fSunSet12.MinutesTo() << "&darr;]";
    27902885            }
    27912886            else
Note: See TracChangeset for help on using the changeset viewer.