gpsfold: Remove $Id$ at EOF.
[gpstools.git] / branches / gpst.near / incomplete-latlon.patch
blob542e9d8bacd9175f8b93e74c996a8673053f9d9a
1 Index: tests/run-tests.pl
2 ===================================================================
3 --- tests/run-tests.pl (revision 1843)
4 +++ tests/run-tests.pl (working copy)
5 @@ -828,15 +828,17 @@
6 <track>
7 <title>Missing various elements</title>
8 <tp> <time>2006-04-30T17:16:59Z</time> </tp>
9 -<tp> <time>2006-04-30T17:17:00Z</time> </tp>
10 +<tp> <time>2006-04-30T17:17:00Z</time> <lat>60.42352</lat> </tp>
11 <tp> <time>2006-04-30T17:17:09Z</time> <lat>60.42353</lat> <lon>5.34185</lon> </tp>
12 -<tp> <time>2006-04-30T17:17:11Z</time> <ele>483</ele> </tp>
13 +<tp> <time>2006-04-30T17:17:11Z</time> <lon>5.34187</lon> <ele>483</ele> </tp>
14 <tp> <time>2006-04-30T17:17:22Z</time> <ele>485</ele> </tp>
15 <tp> <lat>60.42347</lat> <lon>5.34212</lon> <ele>486</ele> </tp>
16 -<tp> <ele>484</ele> </tp>
17 +<tp> <lon>5.34224</lon> <ele>484</ele> </tp>
18 <tp> <ele>486</ele> </tp>
19 <tp> <desc>Missing everything</desc> </tp>
20 -<tp> <time>2006-04-30T17:18:03Z</time> <ele>490</ele> </tp>
21 +<tp> <lat>60.42339</lat> </tp>
22 +<tp> <lon>5.34262</lon> </tp>
23 +<tp> <time>2006-04-30T17:18:03Z</time> <lat>60.42339</lat> <ele>490</ele> </tp>
24 <tp> <time>2006-04-30T17:18:05Z</time> <lat>60.42338</lat> <lon>5.34269</lon> <ele>487</ele> </tp>
25 </track>
26 </gpsml>
27 @@ -872,18 +874,19 @@
29 TODO: {
30 local $TODO = "Shall lat/lon be cleared if one is missing?";
31 + diag("Testing --require...");
32 testcmd("../gpst -re missing.gpsml", # {{{
33 <<END,
34 <?xml version="1.0" encoding="UTF-8"?>
35 <gpsml>
36 <track>
37 <title>Missing various elements</title>
38 -<tp> <time>2006-04-30T17:17:11Z</time> <ele>483</ele> </tp>
39 +<tp> <time>2006-04-30T17:17:11Z</time> <lon>5.34187</lon> <ele>483</ele> </tp>
40 <tp> <time>2006-04-30T17:17:22Z</time> <ele>485</ele> </tp>
41 <tp> <lat>60.42347</lat> <lon>5.34212</lon> <ele>486</ele> </tp>
42 -<tp> <ele>484</ele> </tp>
43 +<tp> <lon>5.34224</lon> <ele>484</ele> </tp>
44 <tp> <ele>486</ele> </tp>
45 -<tp> <time>2006-04-30T17:18:03Z</time> <ele>490</ele> </tp>
46 +<tp> <time>2006-04-30T17:18:03Z</time> <lat>60.42339</lat> <ele>490</ele> </tp>
47 <tp> <time>2006-04-30T17:18:05Z</time> <lat>60.42338</lat> <lon>5.34269</lon> <ele>487</ele> </tp>
48 </track>
49 </gpsml>
50 @@ -899,11 +902,11 @@
51 <track>
52 <title>Missing various elements</title>
53 <tp> <time>2006-04-30T17:16:59Z</time> </tp>
54 -<tp> <time>2006-04-30T17:17:00Z</time> </tp>
55 +<tp> <time>2006-04-30T17:17:00Z</time> <lat>60.42352</lat> </tp>
56 <tp> <time>2006-04-30T17:17:09Z</time> <lat>60.42353</lat> <lon>5.34185</lon> </tp>
57 -<tp> <time>2006-04-30T17:17:11Z</time> <ele>483</ele> </tp>
58 +<tp> <time>2006-04-30T17:17:11Z</time> <lon>5.34187</lon> <ele>483</ele> </tp>
59 <tp> <time>2006-04-30T17:17:22Z</time> <ele>485</ele> </tp>
60 -<tp> <time>2006-04-30T17:18:03Z</time> <ele>490</ele> </tp>
61 +<tp> <time>2006-04-30T17:18:03Z</time> <lat>60.42339</lat> <ele>490</ele> </tp>
62 <tp> <time>2006-04-30T17:18:05Z</time> <lat>60.42338</lat> <lon>5.34269</lon> <ele>487</ele> </tp>
63 </track>
64 </gpsml>
65 @@ -918,8 +921,14 @@
66 <gpsml>
67 <track>
68 <title>Missing various elements</title>
69 +<tp> <time>2006-04-30T17:17:00Z</time> <lat>60.42352</lat> </tp>
70 <tp> <time>2006-04-30T17:17:09Z</time> <lat>60.42353</lat> <lon>5.34185</lon> </tp>
71 +<tp> <time>2006-04-30T17:17:11Z</time> <lon>5.34187</lon> <ele>483</ele> </tp>
72 <tp> <lat>60.42347</lat> <lon>5.34212</lon> <ele>486</ele> </tp>
73 +<tp> <lon>5.34224</lon> <ele>484</ele> </tp>
74 +<tp> <lat>60.42339</lat> </tp>
75 +<tp> <lon>5.34262</lon> </tp>
76 +<tp> <time>2006-04-30T17:18:03Z</time> <lat>60.42339</lat> <ele>490</ele> </tp>
77 <tp> <time>2006-04-30T17:18:05Z</time> <lat>60.42338</lat> <lon>5.34269</lon> <ele>487</ele> </tp>
78 </track>
79 </gpsml>
80 @@ -934,9 +943,9 @@
81 <gpsml>
82 <track>
83 <title>Missing various elements</title>
84 -<tp> <time>2006-04-30T17:17:11Z</time> <ele>483</ele> </tp>
85 +<tp> <time>2006-04-30T17:17:11Z</time> <lon>5.34187</lon> <ele>483</ele> </tp>
86 <tp> <time>2006-04-30T17:17:22Z</time> <ele>485</ele> </tp>
87 -<tp> <time>2006-04-30T17:18:03Z</time> <ele>490</ele> </tp>
88 +<tp> <time>2006-04-30T17:18:03Z</time> <lat>60.42339</lat> <ele>490</ele> </tp>
89 <tp> <time>2006-04-30T17:18:05Z</time> <lat>60.42338</lat> <lon>5.34269</lon> <ele>487</ele> </tp>
90 </track>
91 </gpsml>
92 @@ -951,6 +960,15 @@
93 <gpsml>
94 <track>
95 <title>Missing various elements</title>
96 +<tp> <time>2006-04-30T17:16:59Z</time> </tp>
97 +<tp> <time>2006-04-30T17:17:00Z</time> <lat>60.42352</lat> </tp>
98 +<tp> <time>2006-04-30T17:17:09Z</time> <lat>60.42353</lat> <lon>5.34185</lon> </tp>
99 +<tp> <time>2006-04-30T17:17:11Z</time> <lon>5.34187</lon> <ele>483</ele> </tp>
100 +<tp> <time>2006-04-30T17:17:22Z</time> <ele>485</ele> </tp>
101 +<tp> <lat>60.42347</lat> <lon>5.34212</lon> <ele>486</ele> </tp>
102 +<tp> <lon>5.34224</lon> <ele>484</ele> </tp>
103 +<tp> <ele>486</ele> </tp>
104 +<tp> <time>2006-04-30T17:18:03Z</time> <lat>60.42339</lat> <ele>490</ele> </tp>
105 <tp> <time>2006-04-30T17:18:05Z</time> <lat>60.42338</lat> <lon>5.34269</lon> <ele>487</ele> </tp>
106 </track>
107 </gpsml>
108 @@ -965,7 +983,14 @@
109 <gpsml>
110 <track>
111 <title>Missing various elements</title>
112 +<tp> <time>2006-04-30T17:17:00Z</time> <lat>60.42352</lat> </tp>
113 +<tp> <time>2006-04-30T17:17:09Z</time> <lat>60.42353</lat> <lon>5.34185</lon> </tp>
114 +<tp> <time>2006-04-30T17:17:11Z</time> <lon>5.34187</lon> <ele>483</ele> </tp>
115 +<tp> <time>2006-04-30T17:17:22Z</time> <ele>485</ele> </tp>
116 <tp> <lat>60.42347</lat> <lon>5.34212</lon> <ele>486</ele> </tp>
117 +<tp> <lon>5.34224</lon> <ele>484</ele> </tp>
118 +<tp> <ele>486</ele> </tp>
119 +<tp> <time>2006-04-30T17:18:03Z</time> <lat>60.42339</lat> <ele>490</ele> </tp>
120 <tp> <time>2006-04-30T17:18:05Z</time> <lat>60.42338</lat> <lon>5.34269</lon> <ele>487</ele> </tp>
121 </track>
122 </gpsml>
123 @@ -975,37 +1000,85 @@
125 # }}}
127 + testcmd("../gpst -o gpx missing.gpsml | ../gpst", # {{{
128 + <<END,
129 +<?xml version="1.0" encoding="UTF-8"?>
130 +<gpsml>
131 +<track>
132 +<title>Missing various elements</title>
133 +<tp> <time>2006-04-30T17:17:09Z</time> <lat>60.42353</lat> <lon>5.34185</lon> </tp>
134 +<tp> <lat>60.42347</lat> <lon>5.34212</lon> <ele>486</ele> </tp>
135 +<tp> <time>2006-04-30T17:18:05Z</time> <lat>60.42338</lat> <lon>5.34269</lon> <ele>487</ele> </tp>
136 +</track>
137 +</gpsml>
138 +END
139 + "Via GPX from gpsml with missing data",
140 + );
142 -testcmd("../gpst -o gpx missing.gpsml", # {{{
143 +# }}}
144 +testcmd("echo '<tp> </tp>' | ../gpst", # {{{
145 <<END,
146 +<?xml version="1.0" encoding="UTF-8"?>
147 +<gpsml>
148 +<track>
149 +</track>
150 +</gpsml>
151 +END
152 + "Don’t print empty trackpoints"
155 +# }}}
156 +testcmd("echo '<tp> <lat>5</lat> </tp>' | ../gpst", # {{{
157 + <<END,
158 +<?xml version="1.0" encoding="UTF-8"?>
159 +<gpsml>
160 +<track>
161 +<etp err="incomplete"> <lat>5</lat> </etp>
162 +</track>
163 +</gpsml>
164 +END
165 + "Only latitude, no longitude (gpsml)"
168 +# }}}
169 +testcmd("echo '<tp> <lon>5</lon> </tp>' | ../gpst", # {{{
170 + <<END,
171 +<?xml version="1.0" encoding="UTF-8"?>
172 +<gpsml>
173 +<track>
174 +<etp err="incomplete"> <lon>5</lon> </etp>
175 +</track>
176 +</gpsml>
177 +END
178 + "Only longitude, no latitude (gpsml)"
181 +# }}}
182 +testcmd("echo '<tp> <lat>5</lat> </tp>' | ../gpst -o gpx", # {{{
183 + <<END,
184 $gpx_header
185 <trk>
186 <trkseg>
187 - <trkpt lat="60.42353" lon="5.34185"> <time>2006-04-30T17:17:09Z</time> </trkpt>
188 - <trkpt> <time>2006-04-30T17:17:11Z</time> <ele>483</ele> </trkpt>
189 - <trkpt> <time>2006-04-30T17:17:22Z</time> <ele>485</ele> </trkpt>
190 - <trkpt lat="60.42347" lon="5.34212"> <ele>486</ele> </trkpt>
191 - <trkpt> <ele>484</ele> </trkpt>
192 - <trkpt> <ele>486</ele> </trkpt>
193 - <trkpt> <time>2006-04-30T17:18:03Z</time> <ele>490</ele> </trkpt>
194 - <trkpt lat="60.42338" lon="5.34269"> <time>2006-04-30T17:18:05Z</time> <ele>487</ele> </trkpt>
195 </trkseg>
196 </trk>
197 </gpx>
199 - "Output GPX from gpsml with missing data",
200 - );
201 + "Only latitude, no longitude (gpx)"
204 # }}}
205 -testcmd("echo '<tp> </tp>' | ../gpst", # {{{
206 +testcmd("echo '<tp> <lon>5</lon> </tp>' | ../gpst -o gpx", # {{{
207 <<END,
208 -<?xml version="1.0" encoding="UTF-8"?>
209 -<gpsml>
210 -<track>
211 -</track>
212 -</gpsml>
213 +<?xml version="1.0" standalone="no"?>
214 +<gpx>
215 + <trk>
216 + <trkseg>
217 + </trkseg>
218 + </trk>
219 +</gpx>
221 - "Don’t print empty trackpoints");
222 + "Only longitude, no latitude (gpx)"
225 # }}}
226 testcmd("../gpst --epoch pause.gpx", # {{{
227 Index: GPST.pm
228 ===================================================================
229 --- GPST.pm (revision 1843)
230 +++ GPST.pm (working copy)
231 @@ -104,26 +104,23 @@
232 # }}}
233 } elsif($Dat{'format'} eq "gpx") {
234 # {{{
235 - my $lat_str = length($Dat{'lat'}) ? " lat=\"$Dat{'lat'}\"" : "";
236 - my $lon_str = length($Dat{'lon'}) ? " lon=\"$Dat{'lon'}\"" : "";
237 - if (length("$lat_str$lon_str$Dat{'ele'}")) {
238 - $Retval .=
239 - join("",
240 - "$Spc$Spc$Spc$Spc$Spc$Spc",
241 - "<trkpt$lat_str$lon_str>",
242 - "$Spc",
243 - $print_time
244 - ? "<time>" .
245 - "$Dat{'year'}-$Dat{'month'}-$Dat{'day'}T" .
246 - "$Dat{'hour'}:$Dat{'min'}:$Dat{'sec'}Z" .
247 - "</time>$Spc"
248 - : "",
249 - length($Dat{'ele'})
250 - ? "<ele>$Dat{'ele'}</ele>$Spc"
251 - : "",
252 - "</trkpt>\n"
253 - );
255 + (length($Dat{'lat'}) && length($Dat{'lon'})) || return("");
256 + $Retval .=
257 + join("",
258 + "$Spc$Spc$Spc$Spc$Spc$Spc",
259 + "<trkpt lat=\"$Dat{'lat'}\" lon=\"$Dat{'lon'}\">",
260 + "$Spc",
261 + $print_time
262 + ? "<time>" .
263 + "$Dat{'year'}-$Dat{'month'}-$Dat{'day'}T" .
264 + "$Dat{'hour'}:$Dat{'min'}:$Dat{'sec'}Z" .
265 + "</time>$Spc"
266 + : "",
267 + length($Dat{'ele'})
268 + ? "<ele>$Dat{'ele'}</ele>$Spc"
269 + : "",
270 + "</trkpt>\n"
271 + );
272 # }}}
273 } else {
274 $Retval = undef;
275 Index: gpst
276 ===================================================================
277 --- gpst (revision 1843)
278 +++ gpst (working copy)
279 @@ -710,9 +710,14 @@
280 defined($Dat{'lon'}) || ($Dat{'lon'} = "");
281 defined($Dat{'year'}) || ($Dat{'year'} = "");
282 my $print_time = length($Dat{'year'}) ? 1 : 0;
283 - my $print_pos = (length($Dat{'lat'}) && length($Dat{'lon'})) ? 1 : 0;
284 - if (!$print_pos) {
285 - $Dat{'lat'} = $Dat{'lon'} = "";
286 + my $print_pos = 1;
287 + if (length($Dat{'lat'}) && length($Dat{'lon'})) {
288 + $print_pos = 1;
289 + } else {
290 + if (length($Dat{'lat'}) || length($Dat{'lon'})) {
291 + $Dat{'error'} = "incomplete";
292 + $print_pos = ($Opt{'output-format'} eq "gpsml") ? 1 : 0;
295 my $print_ele = length($Dat{'ele'}) ? 1 : 0;
296 my $print_desc = length($Dat{'desc'}) ? 1 : 0;
297 @@ -829,11 +834,9 @@
299 if ($Dat{'type'} eq "tp") {
300 # {{{
301 - if ($Opt{'require'}) {
302 - $Req{'time'} && !$print_time && return;
303 - $Req{'position'} && !$print_pos && return;
304 - $Req{'ele'} && !$print_ele && return;
306 + ($Req{'time'} && !$print_time) && return("");
307 + ($Req{'position'} && length("$Dat{'lat'}$Dat{'lon'}")) && return("");
308 + ($Req{'ele'} && !$print_ele) && return("");
310 if ($Opt{'inside'} || $Opt{'outside'}) {
311 if (