source: branches/Corsika7500Compatibility/fact/tools/GetObsTimes.C@ 20115

Last change on this file since 20115 was 18313, checked in by Daniela Dorner, 9 years ago
added (macro to calculate times of astronomical twilight, dark night and moon rise/set and to fill them in the DB)
File size: 4.7 KB
Line 
1// Be aware that this macro just inserts and not updates the rows
2
3void GetObsTimes(Bool_t dummy=kTRUE, Int_t start=55866 /*1.11.2011*/, Int_t stop=58848 /*31.12.2019*/)
4{
5 MSQLMagic serv("sql.rc");
6 Bool_t con = serv.IsConnected();
7 if (con)
8 {
9 cout << "Connected to " << serv.GetName() << endl;
10 cout << endl;
11 }
12 else
13 {
14 cout << "Could not connect to " << serv.GetName() << endl;
15 cout << endl;
16 return;
17 }
18
19
20 MTime time(-1);
21 MTime time2, time3, time4, time5;
22 MTime time6, time7, time8, time9;
23 Double_t darknight=0;
24 Int_t night=0;
25 TString query;
26 for (int i=start; i<=stop; i++)
27 {
28 //GetSolarRst returns the information for the next day
29 // as JD seems to be rounded to the next value in all
30 // cases in the libnova function ln_get_solar_rst
31 //to get the correct values the following would be needed
32 //Nova::RstTime t1= Nova::GetSolarRst(time.GetJD()-1, -12);
33 //Nova::RstTime t2= Nova::GetSolarRst(time.GetJD(), -12);
34 //time2.SetJD(t1.set);
35 //time3.SetJD(t2.rise);
36 //however, as time.GetNightAsInt() returns the date of the
37 // sunrise (MAGIC naming convention), we use:
38 time.SetMjd(i);
39 Nova::RstTime t1= Nova::GetSolarRst(time.GetJD(), -12);
40 Nova::RstTime t2= Nova::GetSolarRst(time.GetJD()+1, -12);
41 Nova::RstTime t3= Nova::GetSolarRst(time.GetJD(), -18);
42 Nova::RstTime t4= Nova::GetSolarRst(time.GetJD()+1, -18);
43 Nova::RstTime t5= Nova::GetLunarRst(time.GetJD());
44 Nova::RstTime t6= Nova::GetLunarRst(time.GetJD()+1);
45
46 /*
47 cout << time.GetNightAsInt()
48// << " " << MTime(t1.set).GetSqlDateTime()
49// << " " << MTime(t2.rise).GetSqlDateTime()
50// << " s" << MTime(t3.set).GetSqlDateTime()
51// << " r" << MTime(t4.rise).GetSqlDateTime()
52 << " s" << MTime(t5.set).GetSqlDateTime()
53 << " r" << MTime(t5.rise).GetSqlDateTime()
54 << " s" << MTime(t6.set).GetSqlDateTime()
55 << " r" << MTime(t6.rise).GetSqlDateTime()
56 << endl;
57 */
58
59 // astronomical twilight (-12 deg)
60 time2.SetJD(t1.set);
61 time3.SetJD(t2.rise);
62 // dark night (-18 deg)
63 time4.SetJD(t3.set);
64 time5.SetJD(t4.rise);
65 // setting rise (time6) and set (time7) of moon
66 if (t5.set<t5.rise)
67 {
68 time6.SetJD(t5.rise);
69 time7.SetJD(t6.set);
70 }
71 else//set>rise
72 {
73 if (t5.set>t3.set)
74 time7.SetJD(t5.set);
75 else
76 time7.SetJD(t6.set);
77
78 time6.SetJD(t6.rise);
79 }
80 // setting times for dark night
81 // sunset after moonrise
82 if (time4>time6)
83 time8=time7;
84 else
85 {
86 if (time4<time7 && time5>time7)
87 time8=time7;
88 else
89 time8=time4;
90 }
91 // moonset before sunrise
92 if (time7<time5)
93 time9=time5;
94 else
95 {
96 // sunrise before moonrise
97 if (time5<time6)
98 time9=time5;
99 else
100 time9=time6;
101 }
102 // number of dark hours
103 darknight=time9<time8 ? 0 : (time9.GetMjd()-time8.GetMjd())*24;
104
105 /*
106 cout << time.GetNightAsInt() << " "
107 << " ==> r" << time6.GetSqlDateTime()
108 << " s" << time7.GetSqlDateTime()
109 << " ==> start" << time8.GetSqlDateTime()
110 << " stop" << time9.GetSqlDateTime()
111 << " dark: " << darknight << "h "
112 << endl;
113 */
114
115 query=Form("INSERT ObservationTimes SET fNight=%d, "
116 "fStartObservation='%s', fStopObservation='%s', "
117 "fStartDarkTime='%s', fStopDarkTime='%s', "
118 "fStartDarkNight='%s', fStopDarkNight='%s', "
119 "fMoonRise='%s', fMoonSet='%s', "
120 "fNumDarkHours=%f, fMjd=%d",
121 time.GetNightAsInt(),
122 time2.GetSqlDateTime().Data(), time3.GetSqlDateTime().Data(),// astronomical twilight
123 time4.GetSqlDateTime().Data(), time5.GetSqlDateTime().Data(),// darktime
124 time8.GetSqlDateTime().Data(), time9.GetSqlDateTime().Data(),// darknight
125 time6.GetSqlDateTime().Data(), time7.GetSqlDateTime().Data(),// moon
126 darknight, i); //dark hours
127
128 cout << "QUERY: " << query << endl;
129
130 if (dummy)
131 continue;
132 TSQLResult *res = serv.Query(query);
133 if (!res)
134 {
135 cout << "problem to insert. " << endl;
136 return;
137 }
138 }
139 return;
140
141}
Note: See TracBrowser for help on using the repository browser.