4 XCSoar Glide Computer - http://www.xcsoar.org/
5 Copyright (C) 2000-2013 The XCSoar Project
6 A detailed list of copyright holders can be found in the file "AUTHORS".
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 #include "OS/Args.hpp"
25 #include "DebugReplay.hpp"
26 #include "Engine/Trace/Trace.hpp"
28 int main(int argc
, char **argv
)
30 int start
= -1, end
= -1;
31 unsigned max_points
= 1000;
34 "[options] DRIVER FILE\n"
36 " --start=5000 Begin flight path at 5000 sec after UTC midnight,\n"
37 " if not defined takeoff time is used\n"
38 " --end=15000 End flight path at 15000 sec after UTC midnight,\n"
39 " if not defined the last timestamp in the file is used\n"
40 " --max-points=1000 Maximum number of trace points in output (default = 1000)");
43 while ((arg
= args
.PeekNext()) != nullptr && *arg
== '-') {
47 if ((value
= StringAfterPrefix(arg
, "--max-points=")) != nullptr) {
48 unsigned _max_points
= strtol(value
, NULL
, 10);
50 max_points
= _max_points
;
51 } else if ((value
= StringAfterPrefix(arg
, "--start=")) != nullptr) {
53 start
= strtol(value
, &endptr
, 10);
54 if (endptr
== value
|| *endptr
!= '\0' || start
< 0) {
55 fputs("The start parameter could not be parsed correctly.\n", stderr
);
58 } else if ((value
= StringAfterPrefix(arg
, "--end=")) != nullptr) {
60 end
= strtol(value
, &endptr
, 10);
61 if (endptr
== value
|| *endptr
!= '\0' || end
< 0) {
62 fputs("The end parameter could not be parsed correctly.\n", stderr
);
70 if (start
>= 0 && end
>= 0 && start
>= end
) {
71 fputs("The start parameter has to be smaller than the end parameter.\n", stderr
);
75 DebugReplay
*replay
= CreateDebugReplay(args
);
76 if (replay
== nullptr)
81 Trace
trace(0, Trace::null_time
, max_points
);
85 while (replay
->Next()) {
86 const MoreData
&basic
= replay
->Basic();
87 const DerivedInfo
&calculated
= replay
->Calculated();
89 if (!basic
.time_available
|| !basic
.location_available
||
90 !basic
.NavAltitudeAvailable())
93 if (start
>= 0 && (int)basic
.time
< start
)
96 if (end
>= 0 && (int)basic
.time
> end
)
99 trace
.push_back(TracePoint(basic
));
101 if (start
< 0 && calculated
.flight
.flying
&& !takeoff
) {
103 trace
.EraseEarlierThan(calculated
.flight
.takeoff_time
);
109 for (auto i
= trace
.begin(), end
= trace
.end(); i
!= end
; ++i
) {
110 const TracePoint
&point
= *i
;
111 printf("%u %f %f %d %u\n",
113 (double)point
.GetLocation().latitude
.Degrees(),
114 (double)point
.GetLocation().longitude
.Degrees(),
115 point
.GetIntegerAltitude(),
116 point
.GetEngineNoiseLevel());