int main(int argc, char **argv) { Args args(argc, argv, "FILE.igc"); const auto path = args.ExpectNextPath(); args.ExpectEnd(); GRecord g; g.Initialize(); Error error; if (!g.LoadFileToBuffer(path, error)) { fprintf(stderr, "%s\n", error.GetMessage()); return 2; } g.FinalizeBuffer(); if (!g.AppendGRecordToFile(path)) { fprintf(stderr, "Failed to write file\n"); return 2; } return 0; }
int main(int argc, char **argv) { Args args(argc, argv, "PATH"); const auto path = args.ExpectNextPath(); args.ExpectEnd(); Error error; FileLineReaderA reader(path, error); if (reader.error()) { fprintf(stderr, "%s\n", error.GetMessage()); return EXIT_FAILURE; } FileRepository repository; if (!ParseFileRepository(repository, reader)) { fprintf(stderr, "Failed to parse file\n"); return EXIT_FAILURE; } for (auto i = repository.begin(), end = repository.end(); i != end; ++i) { const auto &file = *i; printf("file '%s' '%s' area='%s' type=%u\n", file.GetName(), file.GetURI(), file.GetArea(), (unsigned)file.type); } return EXIT_SUCCESS; }
int main(int argc, char **argv) { Args args(argc, argv, "PATH"); const char *path = args.ExpectNext(); args.ExpectEnd(); ZZIP_DIR *dir = zzip_dir_open(path, NULL); if (dir == NULL) { fprintf(stderr, "Failed to open %s\n", (const char *)path); return EXIT_FAILURE; } Error error; ZipLineReaderA reader(dir, "topology.tpl", error); if (reader.error()) { fprintf(stderr, "%s\n", error.GetMessage()); return EXIT_FAILURE; } TopographyStore topography; NullOperationEnvironment operation; topography.Load(operation, reader, NULL, dir); zzip_dir_close(dir); topography.LoadAll(); #ifdef ENABLE_OPENGL TriangulateAll(topography); #endif return EXIT_SUCCESS; }
void IGCFileVisitor::Visit(Path path, Path filename) { Error error; FileLineReaderA reader(path, error); if (reader.error()) { fprintf(stderr, "%s\n", error.GetMessage()); return; } IGCExtensions extensions; extensions.clear(); FlightCheck flight(filename.c_str()); char *line; while ((line = reader.ReadLine()) != NULL) { unsigned day, month, year; IGCFix fix; if (IGCParseFix(line, extensions, fix)) flight.fix(fix); else if (sscanf(line, "HFDTE%02u%02u%02u", &day, &month, &year)) { /* damn you, Y2K bug! */ if (year > 80) year += 1900; else year += 2000; flight.date(year, month, day); } } flight.finish(); }
static void TestWriter() { Profile::Clear(); Profile::Set("key1", 4); Profile::Set("key2", "value2"); Profile::SaveFile(Path(_T("output/TestProfileWriter.prf"))); Error error; FileLineReader reader(Path(_T("output/TestProfileWriter.prf")), error); if (reader.error()) { skip(3, 0, error.GetMessage()); return; } unsigned count = 0; bool found1 = false, found2 = false; TCHAR *line; while ((line = reader.ReadLine()) != NULL) { if (StringIsEqual(line, _T("key1=\"4\""))) found1 = true; if (StringIsEqual(line, _T("key2=\"value2\""))) found2 = true; count++; } ok1(count == 2); ok1(found1); ok1(found2); }
int main(int argc, char **argv) { Args args(argc, argv, "FILE.igc"); const auto path = args.ExpectNextPath(); args.ExpectEnd(); { GRecord grecord; grecord.Initialize(); Error error; if (!grecord.VerifyGRecordInFile(path, error)) { fprintf(stderr, "%s\n", error.GetMessage()); return EXIT_FAILURE; } } printf("Valid G record found\n"); FileTransaction transaction(path); { Error error; FileLineReaderA reader(path, error); if (reader.error()) { fprintf(stderr, "%s\n", error.GetMessage()); return EXIT_FAILURE; } if (!FixGRecord(reader, transaction.GetTemporaryPath())) { fprintf(stderr, "Failed to write output file\n"); return EXIT_FAILURE; } } if (!transaction.Commit()) { fprintf(stderr, "Failed to commit output file\n"); return EXIT_FAILURE; } printf("New G record written\n"); return EXIT_SUCCESS; }
int main(int argc, char **argv) { Args args(argc, argv, "FILE"); const auto path = args.ExpectNextPath(); args.ExpectEnd(); Error error; FileLineReaderA reader(path, error); if (reader.error()) { fprintf(stderr, "%s\n", error.GetMessage()); return EXIT_FAILURE; } KalmanFilter1d kalman_filter(0.0075); unsigned last_t = 0; double last_value; const char *line; while ((line = reader.ReadLine()) != nullptr) { const char *p = line; char *endptr; unsigned t = strtoul(p, &endptr, 10); if (endptr == line) { fprintf(stderr, "Malformed line: %s\n", line); return EXIT_FAILURE; } p = endptr; double value = strtod(p, &endptr); if (endptr == line) { fprintf(stderr, "Malformed line: %s\n", line); return EXIT_FAILURE; } if (last_t > 0 && t > last_t) { auto dt = (t - last_t) / 1000.; kalman_filter.Update(value, 0.05, dt); printf("%u %f %f %f %f\n", t, value, (value - last_value) / dt, kalman_filter.GetXAbs(), kalman_filter.GetXVel()); } last_t = t; last_value = value; } return EXIT_SUCCESS; }
DebugReplay* DebugReplayNMEA::Create(Path input_file, const tstring &driver_name) { const struct DeviceRegister *driver = FindDriverByName(driver_name.c_str()); if (driver == NULL) { _ftprintf(stderr, _T("No such driver: %s\n"), driver_name.c_str()); return nullptr; } Error error; FileLineReaderA *reader = new FileLineReaderA(input_file, error); if (reader->error()) { delete reader; fprintf(stderr, "%s\n", error.GetMessage()); return nullptr; } return new DebugReplayNMEA(reader, driver); }
static bool ParseFile(Path path, Airspaces &airspaces) { Error error; FileLineReader reader(path, error, Charset::AUTO); if (!ok1(!reader.error())) { skip(1, 0, error.GetMessage()); return false; } AirspaceParser parser(airspaces); NullOperationEnvironment operation; if (!ok1(parser.Parse(reader, operation))) return false; airspaces.Optimise(); return true; }
int main(int argc, char **argv) { Args args(argc, argv, "FILE.lua"); const auto path = args.ExpectNextPath(); args.ExpectEnd(); int result = EXIT_SUCCESS; lua_State *L = Lua::NewBasicState(); Lua::InitLog(L); lua_register(L, "alert", l_alert); Error error; if (!Lua::RunFile(L, path, error)) { fprintf(stderr, "%s\n", error.GetMessage()); result = EXIT_FAILURE; } lua_close(L); return result; }
static bool TestTrace(const char *filename, unsigned ntrace, bool output=false) { Error error; FileLineReaderA reader(filename, error); if (reader.error()) { fprintf(stderr, "%s\n", error.GetMessage()); return false; } printf("# %d", ntrace); Trace trace(1000, ntrace); IGCExtensions extensions; extensions.clear(); char *line; int i = 0; for (; (line = reader.ReadLine()) != NULL; i++) { if (output && (i % 500 == 0)) { putchar('.'); fflush(stdout); } IGCFix fix; if (!IGCParseFix(line, extensions, fix) || !fix.gps_valid) continue; OnAdvance(trace, fix.location, fixed(fix.gps_altitude), fixed(fix.time.GetSecondOfDay())); } putchar('\n'); printf("# samples %d\n", i); return true; }
static bool test_replay() { Directory::Create(Path(_T("output/results"))); std::ofstream f("output/results/res-sample.txt"); GlidePolar glide_polar(4.0); Waypoints waypoints; AircraftState state_last; TaskBehaviour task_behaviour; task_behaviour.SetDefaults(); task_behaviour.auto_mc = true; TaskManager task_manager(task_behaviour, waypoints); TaskEventsPrint default_events(verbose); task_manager.SetTaskEvents(default_events); glide_polar.SetBallast(1.0); task_manager.SetGlidePolar(glide_polar); OrderedTask* t = task_load(task_behaviour); if (t) { task_manager.Commit(*t); delete t; task_manager.Resume(); } else { return false; } // task_manager.get_task_advance().get_advance_state() = TaskAdvance::AUTO; Error error; FileLineReaderA *reader = new FileLineReaderA(replay_file, error); if (reader->error()) { delete reader; fprintf(stderr, "%s\n", error.GetMessage()); return false; } ReplayLoggerSim sim(reader); sim.state.netto_vario = 0; bool do_print = verbose; unsigned print_counter=0; NMEAInfo basic; basic.Reset(); while (sim.Update(basic) && !sim.started) { } state_last = sim.state; sim.state.wind.norm = 7; sim.state.wind.bearing = Angle::Degrees(330); auto time_last = sim.state.time; // uncomment this to manually go to first tp // task_manager.incrementActiveTaskPoint(1); FlyingComputer flying_computer; flying_computer.Reset(); FlyingState flying_state; flying_state.Reset(); while (sim.Update(basic)) { if (sim.state.time>time_last) { n_samples++; flying_computer.Compute(glide_polar.GetVTakeoff(), sim.state, sim.state.time - time_last, flying_state); sim.state.flying = flying_state.flying; task_manager.Update(sim.state, state_last); task_manager.UpdateIdle(sim.state); task_manager.UpdateAutoMC(sim.state, 0); task_manager.SetTaskAdvance().SetArmed(true); state_last = sim.state; if (verbose>1) { sim.print(f); f.flush(); } if (do_print) { PrintHelper::taskmanager_print(task_manager, sim.state); } do_print = (++print_counter % output_skip ==0) && verbose; } time_last = sim.state.time; }; if (verbose) { PrintDistanceCounts(); printf("# task elapsed %d (s)\n", (int)task_manager.GetStats().total.time_elapsed); printf("# task speed %3.1f (kph)\n", (int)task_manager.GetStats().total.travelled.GetSpeed()*3.6); printf("# travelled distance %4.1f (km)\n", (double)task_manager.GetStats().total.travelled.GetDistance()/1000.0); printf("# scored distance %4.1f (km)\n", (double)task_manager.GetStats().distance_scored/1000.0); if (task_manager.GetStats().total.time_elapsed > 0) { printf("# scored speed %3.1f (kph)\n", (double)task_manager.GetStats().distance_scored/(double)task_manager.GetStats().total.time_elapsed*3.6); } } return true; }
void LogError(const Error &error) { LogString(error.GetMessage()); }
void ShowError(const Error &error, const TCHAR *caption) { ShowMessageBox(UTF8ToWideConverter(error.GetMessage()), caption, MB_OK|MB_ICONEXCLAMATION); }
void LogError(const char *msg, const Error &error) { LogFormat("%s: %s", msg, error.GetMessage()); }
void LogError(const Error &error) { LogFormat("%s\n", error.GetMessage()); }
static bool test_replay(const Contest olc_type, const ContestResult &official_score) { Directory::Create(_T("output/results")); std::ofstream f("output/results/res-sample.txt"); GlidePolar glide_polar(fixed(2)); Error error; FileLineReaderA *reader = new FileLineReaderA(replay_file.c_str(), error); if (reader->error()) { delete reader; fprintf(stderr, "%s\n", error.GetMessage()); return false; } ReplayLoggerSim sim(reader); ComputerSettings settings_computer; settings_computer.SetDefaults(); settings_computer.contest.enable = true; load_scores(settings_computer.contest.handicap); if (verbose) { switch (olc_type) { case Contest::OLC_LEAGUE: std::cout << "# OLC-League\n"; break; case Contest::OLC_SPRINT: std::cout << "# OLC-Sprint\n"; break; case Contest::OLC_FAI: std::cout << "# OLC-FAI\n"; break; case Contest::OLC_CLASSIC: std::cout << "# OLC-Classic\n"; break; case Contest::OLC_PLUS: std::cout << "# OLC-Plus\n"; break; default: std::cout << "# Unknown!\n"; break; } } bool do_print = verbose; unsigned print_counter=0; MoreData basic; basic.Reset(); FlyingComputer flying_computer; flying_computer.Reset(); FlyingState flying_state; flying_state.Reset(); TraceComputer trace_computer; ContestManager contest_manager(olc_type, trace_computer.GetFull(), trace_computer.GetFull(), trace_computer.GetSprint()); contest_manager.SetHandicap(settings_computer.contest.handicap); DerivedInfo calculated; while (sim.Update(basic)) { n_samples++; flying_computer.Compute(glide_polar.GetVTakeoff(), basic, calculated, flying_state); calculated.flight.flying = true; trace_computer.Update(settings_computer, basic, calculated); contest_manager.UpdateIdle(); if (verbose>1) { sim.print(f, basic); f.flush(); } if (do_print) { PrintHelper::trace_print(trace_computer.GetFull(), basic.location); } do_print = (++print_counter % output_skip ==0) && verbose; }; contest_manager.SolveExhaustive(); if (verbose) { PrintDistanceCounts(); } return compare_scores(official_score, contest_manager.GetStats().GetResult(0)); }