FACT++  1.0
makedata.cc
Go to the documentation of this file.
1 #include "externals/Prediction.h"
2 
3 #include "Database.h"
4 
5 #include "Time.h"
6 #include "Configuration.h"
7 
8 using namespace std;
9 using namespace Nova;
10 
11 // ========================================================================
12 // ========================================================================
13 // ========================================================================
14 
16 {
17  po::options_description control("Smart FACT");
18  control.add_options()
19  ("source-name", var<string>(), "Source name")
20  ("date-time", var<string>(), "SQL time (UTC)")
21  ("source-database", var<string>(""), "Database link as in\n\tuser:password@server[:port]/database.")
22  ("max-current", var<double>(75), "Maximum current to display in other plots.")
23  ("max-zd", var<double>(75), "Maximum zenith distance to display in other plots")
24  ("no-limits", po_switch(), "Switch off limits in plots")
25  ;
26 
27  po::positional_options_description p;
28  p.add("source-name", 1); // The 1st positional options
29  p.add("date-time", 2); // The 2nd positional options
30 
31  conf.AddOptions(control);
32  conf.SetArgumentPositions(p);
33 }
34 
35 void PrintUsage()
36 {
37  cout <<
38  "makedata - The astronomy data listing\n"
39  "\n"
40 // "Calculates several plots for the sources in the database\n"
41 // "helpful or needed for scheduling. The Plot is always calculated\n"
42 // "for the night which starts at the same so. So no matter if\n"
43 // "you specify '1974-09-09 00:00:00' or '1974-09-09 21:56:00'\n"
44 // "the plots will refer to the night 1974-09-09/1974-09-10.\n"
45 // "The advantage is that specification of the date as in\n"
46 // "1974-09-09 is enough. Time axis starts and ends at nautical\n"
47 // "twilight which is 12deg below horizon.\n"
48 // "\n"
49  "Usage: makedata sql-datetime [--ra={ra} --dec={dec}]\n";
50  cout << endl;
51 }
52 
53 int main(int argc, const char* argv[])
54 {
55  Configuration conf(argv[0]);
57  SetupConfiguration(conf);
58 
59  if (!conf.DoParse(argc, argv))
60  return 127;
61 /*
62  if (!conf.Has("source-name"))
63  {
64  cout << "ERROR - --source-name missing." << endl;
65  return 1;
66  }
67 */
68  // ------------------ Eval config ---------------------
69 
70  Time time;
71  if (conf.Has("date-time"))
72  time.SetFromStr(conf.Get<string>("date-time"));
73 
74  const double max_current = conf.Get<double>("max-current");
75  const double max_zd = conf.Get<double>("max-zd");
76  const double no_limits = conf.Get<bool>("no-limits");
77 
78  // -12: nautical
79  const RstTime sun_set = GetSolarRst(time.JD()-0.5, -12); // Sun set with the same date than th provided date
80  const RstTime sun_rise = GetSolarRst(time.JD()+0.5, -12); // Sun rise on the following day
81 
82  const double jd = floor(time.Mjd())+2400001;
83  const double mjd = floor(time.Mjd())+49718+0.5;
84 
85 
86  const double jd0 = fmod(sun_set.set, 1); // ~0.3
87  const double jd1 = fmod(sun_rise.rise, 1); // ~0.8
88 
89  cout << Time::iso << time << ", " << mjd-49718 << ", ";
90  cout << jd0 << ", ";
91  cout << jd1 << "\n";
92 
93  if (!conf.Has("source-name"))
94  return 1;
95 
96  const string source_name = conf.Get<string>("source-name");
97  const string fDatabase = conf.Get<string>("source-database");
98 
99  // ------------- Get Sources from databasse ---------------------
100 
101  const mysqlpp::StoreQueryResult res =
102  Database(fDatabase).query("SELECT fRightAscension, fDeclination FROM Source WHERE fSourceName='"+source_name+"'").store();
103 
104  // ------------- Create canvases and frames ---------------------
105 
106  vector<mysqlpp::Row>::const_iterator row=res.begin();
107  if (row==res.end())
108  return 1;
109 
110  EquPosn pos;
111  pos.ra = double((*row)[0])*15;
112  pos.dec = double((*row)[1]);
113 
114  // Loop over 24 hours
115  for (int i=0; i<24*12; i++)
116  {
117  const double h = double(i)/(24*12);
118 
119  // check if it is betwene sun-rise and sun-set
120  if (h<jd0 || h>jd1)
121  continue;
122 
123  const SolarObjects so(jd+h);
124 
125  // get local position of source
126  const HrzPosn hrz = GetHrzFromEqu(pos, jd+h);
127 
128  // get current prediction
129  const double cur = FACT::PredictI(so, pos);
130 
131  // Relative energy threshold prediction
132  const double ratio = pow(cos((90-hrz.alt)*M_PI/180), -2.664);
133 
134  // Add points to curve
135  // const double axis = (mjd+h)*24*3600;
136 
137  Time t(mjd-49718);
138  t += boost::posix_time::minutes(i*5);
139 
140  cout << t << ", " << h << ", ";
141 
142  if (no_limits || cur<max_current)
143  cout << hrz.alt;
144  cout << ", ";
145 
146  if (no_limits || 90-hrz.alt<max_zd)
147  cout << cur;
148  cout << ", ";
149 
150  if (no_limits || (cur<max_current && 90-hrz.alt<max_zd))
151  cout << ratio*cur/6.2;
152  cout << ", ";
153 
154  if (no_limits || (cur<max_current && 90-hrz.alt<max_zd))
155  cout << GetAngularSeparation(so.fMoonEqu, pos);
156  cout << "\n";
157  }
158 
159  cout << flush;
160 
161  return 0;
162 }
int i
Definition: db_dim_client.c:21
Adds some functionality to boost::posix_time::ptime for our needs.
Definition: Time.h:30
void SetPrintUsage(const std::function< void(void)> &func)
T Get(const std::string &var)
void SetupConfiguration(Configuration &conf)
Definition: makedata.cc:15
static const _time_format iso
set to format to the sql format (without the fraction of seconds)
Definition: Time.h:44
po::typed_value< bool > * po_switch()
STL namespace.
void SetArgumentPositions(const po::positional_options_description &desc)
double JD() const
Definition: Time.h:87
bool Has(const std::string &var)
int main(int argc, const char *argv[])
Definition: makedata.cc:53
void AddOptions(const po::options_description &opt, bool visible=true)
Definition: Configuration.h:92
void Mjd(double mjd)
Definition: Time.cc:145
Warning because the service this data corrsponds to might have been last updated longer ago than Local time
Definition: smartfact.txt:92
Commandline parsing, resource file parsing and database access.
Definition: Configuration.h:9
void SetFromStr(const std::string &str, const char *fmt="%Y-%m-%d %H:%M:%S")
Definition: Time.cc:273
void PrintUsage()
Definition: makedata.cc:35
RstTime GetSolarRst(double jd, const LnLatPosn &obs, double hrz=LN_SOLAR_STANDART_HORIZON)
Definition: nova.h:97
HrzPosn GetHrzFromEqu(const EquPosn &equ, const LnLatPosn &obs, double jd)
Definition: nova.h:75
EquPosn fMoonEqu
Definition: nova.h:167
Definition: nova.h:10
TT t
Definition: test_client.c:26
ln_rst_time RstTime
Definition: nova.h:13
double GetAngularSeparation(const EquPosn &p1, const EquPosn &p2)
Definition: nova.h:148
bool DoParse(int argc, const char **argv, const std::function< void()> &func=std::function< void()>())
double PredictI(const Nova::SolarObjects &so, const Nova::EquPosn &srcEqu)
Definition: Prediction.h:10