#include #include #include #include #include "Time.h" #include "Configuration.h" using namespace std; // ------------------------------------------------------------------------ class Moon { public: Time time; double ra; double dec; double zd; double az; double disk; bool visible; Time fRise; Time fTransit; Time fSet; int state; Moon() : time(Time::none) { } // Could be done more efficient: Only recalcuate if // the current time exceeds at least on of the stored times Moon(double lon, double lat, const Time &t=Time()) : time(t) { const double JD = time.JD(); ln_lnlat_posn observer; observer.lng = lon; observer.lat = lat; ln_rst_time moon; ln_get_lunar_rst(JD-0.5, &observer, &moon); fRise = Time(moon.rise); fTransit = Time(moon.transit); fSet = Time(moon.set); //visible = // ((JD>moon.rise && JDmoon.rise) && moon.rise>moon.set); const bool is_up = JD>moon.rise; const bool is_sinking = JD>moon.transit; const bool is_dn = JD>moon.set; ln_get_lunar_rst(JD+0.5, &observer, &moon); if (is_up) fRise = Time(moon.rise); if (is_sinking) fTransit = Time(moon.transit); if (is_dn) fSet = Time(moon.set); ln_equ_posn pos; ln_get_lunar_equ_coords(JD, &pos); ln_hrz_posn hrz; ln_get_hrz_from_equ (&pos, &observer, JD, &hrz); az = hrz.az; zd = 90-hrz.alt; ra = pos.ra/15; dec = pos.dec; disk = ln_get_lunar_disk(JD)*100; state = 0; if (fRise 1.0) arg = 1.0; if(arg < -1.0) arg = -1.0; return acos(arg) * 180/M_PI; } }; // ======================================================================== // ======================================================================== // ======================================================================== void SetupConfiguration(Configuration &conf) { po::options_description control("Smart FACT"); control.add_options() ("ra", var(), "Source right ascension") ("dec", var(), "Source declination") ("date-time", var() #if BOOST_VERSION >= 104200 ->required() #endif , "SQL time (UTC)") ; po::positional_options_description p; p.add("date-time", 1); // The first positional options conf.AddOptions(control); conf.SetArgumentPositions(p); } void PrintUsage() { cout << "moon - The moon calculator\n" "\n" "Usage: moon sql-datetime [--ra={ra} --dec={dec}]\n"; cout << endl; } int main(int argc, const char* argv[]) { Configuration conf(argv[0]); conf.SetPrintUsage(PrintUsage); SetupConfiguration(conf); if (!conf.DoParse(argc, argv)) return 127; if (conf.Has("ra")^conf.Has("dec")) { cout << "ERROR - Either --ra or --dec missing." << endl; return 1; } Time time; time.SetFromStr(conf.Get("date-time")); ln_lnlat_posn observer; observer.lng = -(17.+53./60+26.525/3600); observer.lat = 28.+45./60+42.462/3600; Moon moon(observer.lng, observer.lat, time); cout << setprecision(15); cout << time.GetAsStr() << '\n'; ln_equ_posn pos; ln_hrz_posn hrz; ln_get_solar_equ_coords(time.JD(), &pos); ln_get_hrz_from_equ(&pos, &observer, time.JD(), &hrz); cout << 90-hrz.alt << '\n'; cout << moon.visible << '\n'; cout << moon.disk << '\n'; cout << moon.zd << '\n'; if (conf.Has("ra") && conf.Has("dec")) { pos.ra = conf.Get("ra")*15; pos.dec = conf.Get("dec"); cout << moon.Angle(pos.ra/15, pos.dec) << '\n'; // Trick 17 moon.ra = pos.ra; moon.dec = pos.dec; // Sun distance cout << moon.Angle(pos.ra/15, pos.dec) << '\n'; } cout << endl; return 0; }