FACT++  1.0
Sun::Sun ( const Time t)
inline

Definition at line 129 of file smartfact.cc.

References Time::JD(), HTML::kGreen, HTML::kRed, HTML::kYellow, Time::MinutesTo(), and time.

129  : time(t)
130  {
131 #ifdef HAVE_LIBNOVA
132  // get Julian day from local time
133  const double JD = time.JD();
134 
135  // >0deg : day
136  // -6deg - 0deg : civil twilight
137  // -12deg - -6deg : nautical twilight
138  // -18deg - -12deg : astronomical twilight
139  // <-18deg : night
140 
141  const Nova::RstTime sun00 = Rst(JD);
142  const Nova::RstTime sun06 = Rst(JD, -6);
143  const Nova::RstTime sun12 = Rst(JD, -12);
144  const Nova::RstTime sun18 = Rst(JD, -18);
145 
146  fSunRise00 = sun00.rise;
147  fSunRise06 = sun06.rise;
148  fSunRise12 = sun12.rise;
149  fSunRise18 = sun18.rise;
150 
151  fSunSet00 = sun00.set;
152  fSunSet06 = sun06.set;
153  fSunSet12 = sun12.set;
154  fSunSet18 = sun18.set;
155 
156  array<double,8> arr =
157  {{
158  sun00.set,
159  sun06.set,
160  sun12.set,
161  sun18.set,
162  sun18.rise,
163  sun12.rise,
164  sun06.rise,
165  sun00.rise,
166  }};
167 
168 
169  state = std::min_element(arr.begin(), arr.end())-arr.begin();
170 
171  string name[] =
172  {
173  "day time",
174  "civil twilight",
175  "nautical twilight",
176  "astron. twilight",
177  "dark time",
178  "astron. twilight",
179  "nautical twilight",
180  "civil twilight"
181  };
182 
183  description = name[state];
184 
185  const string txt = fSunRise18<fSunSet18 ?
186  time.MinutesTo(fSunRise18)+"&uarr;" :
187  time.MinutesTo(fSunSet18)+"&darr;";
188 
189  description += " ["+txt+"]";
190 
191  isday = state==0;
192 
193  switch (state)
194  {
195  case 0: color = HTML::kRed; break;
196  case 1: case 2: color = HTML::kYellow; break;
197  case 3: case 4: case 5: color = HTML::kGreen; break;
198  case 6: case 7: color = HTML::kYellow; break;
199  }
200 
201  visible = state==0;
202 
203  /*
204  // Warning: return code of 1 means circumpolar and is not checked!
205  Nova::RstTime sun_day = Nova::GetSolarRst(JD-0.5);
206  Nova::RstTime sun_civil = Nova::GetSolarRst(JD-0.5, -6);
207  Nova::RstTime sun_astronomical = Nova::GetSolarRst(JD-0.5, -12);
208  Nova::RstTime sun_dark = Nova::GetSolarRst(JD-0.5, -18);
209 
210  fSetDayTime = Time(sun_day.set);
211  fSetCivil = Time(sun_civil.set);
212  fSetAstronomical = Time(sun_astronomical.set);
213  fSetDarkTime = Time(sun_dark.set);
214 
215  fRiseDayTime = Time(sun_day.rise);
216  fRiseCivil = Time(sun_civil.rise);
217  fRiseAstronomical = Time(sun_astronomical.rise);
218  fRiseDarkTime = Time(sun_dark.rise);
219 
220  const bool is_day = JD>sun_day.rise;
221  const bool is_night = JD>sun_dark.set;
222 
223  sun_day = Nova::GetSolarRst(JD+0.5);
224  sun_civil = Nova::GetSolarRst(JD+0.5, -6);
225  sun_astronomical = Nova::GetSolarRst(JD+0.5, -12);
226  sun_dark = Nova::GetSolarRst(JD+0.5, -18);
227 
228  if (is_day)
229  {
230  fRiseDayTime = Time(sun_day.rise);
231  fRiseCivil = Time(sun_civil.rise);
232  fRiseAstronomical = Time(sun_astronomical.rise);
233  fRiseDarkTime = Time(sun_dark.rise);
234  }
235 
236  if (is_night)
237  {
238  fSetDayTime = Time(sun_day.set);
239  fSetCivil = Time(sun_civil.set);
240  fSetAstronomical = Time(sun_astronomical.set);
241  fSetDarkTime = Time(sun_dark.set);
242  }
243 
244  // case 0: midnight to sun-rise | !is_day && !is_night | rise/set | -> isday=0
245  // case 1: sun-rise to sun-set | is_day && !is_night | set /rise | -> isday=1
246  // case 2: sun-set to midnight | is_day && is_night | rise/set | -> isday=0
247 
248  isday = is_day^is_night;
249 
250  Time fRiseDayTime; // 0: Start of day time (=end of civil twilight)
251  Time fRiseCivil; // -6: End of nautical twilight
252  Time fRiseAstronomical; // -12: End of astron. twilight
253  Time fRiseDarkTime; // -18: End of dark time
254 
255  Time fSetDayTime; // 0: End of day time (=start of civil twilight)
256  Time fSetCivil; // -6: Start of nautical twilight
257  Time fSetAstronomical; // -12: Start of astron. twilight
258  Time fSetDarkTime; // -18: Start of dark time
259 
260  state = isday ? 4 : 0; // 0 [-> Day time ]
261  if (time>fSetDayTime) state++; // 1 [-> Civil twilight]
262  if (time>fSetCivil) state++; // 2 [-> Naut. twilight]
263  if (time>fSetAstronomical) state++; // 3 [-> Astro. twilight]
264  if (time>fSetDarkTime) state++; // 4 [-> Dark time ]
265 
266  if (time>fRiseDarkTime) state++; // 5 [-> Astro. twilight]
267  if (time>fRiseAstronomical) state++; // 6 [-> Naut. twilight]
268  if (time>fRiseCivil) state++; // 7 [-> Civil twilight]
269  if (time>fRiseDayTime) state++; // 8 [-> Day time ]
270 
271  string name[] =
272  {
273  "dark time", // 0
274  "astron. twilight", // 1
275  "civil twilight", // 2
276  "sunrise", // 3
277  "day time", // 4
278  "sunset", // 5
279  "civil twilight", // 6
280  "astron. twilight", // 7
281  "dark time" // 8
282  };
283 
284  description = name[state];
285 
286  const string arr = isday ?
287  fSetDarkTime.MinutesTo(time)+"&darr;" :
288  fRiseDarkTime.MinutesTo(time)+"&uarr;";
289 
290  description += " ["+arr+"]";
291 
292  switch (state)
293  {
294  case 0: case 1: color = HTML::kGreen; break;
295  case 2: case 3: color = HTML::kYellow; break;
296  case 4: color = HTML::kRed; break;
297  case 5: case 6: color = HTML::kYellow; break;
298  case 7: case 8: color = HTML::kGreen; break;
299  }
300 
301  visible = state>=3 && state<=5;
302  */
303 #endif
304  }
string description
Definition: smartfact.cc:102
Time fSunRise18
Definition: smartfact.cc:94
static const string kYellow
Definition: smartfact.cc:75
bool visible
Definition: smartfact.cc:106
Time fSunSet12
Definition: smartfact.cc:98
Time fSunRise12
Definition: smartfact.cc:93
double JD() const
Definition: Time.h:87
Nova::RstTime Rst(double jd, double hrz=LN_SOLAR_STANDART_HORIZON)
Definition: smartfact.cc:108
Time fSunSet06
Definition: smartfact.cc:97
bool isday
Definition: smartfact.cc:105
int state
Definition: smartfact.cc:101
Time fSunSet00
Definition: smartfact.cc:96
static const string kGreen
Definition: smartfact.cc:77
Time fSunRise00
Definition: smartfact.cc:91
ln_rst_time RstTime
Definition: nova.h:13
Time fSunRise06
Definition: smartfact.cc:92
std::string MinutesTo(const Time &=Time()) const
Definition: Time.cc:281
Time time
Definition: smartfact.cc:88
static const string kRed
Definition: smartfact.cc:76
string color
Definition: smartfact.cc:103
Time fSunSet18
Definition: smartfact.cc:99

+ Here is the call graph for this function: