Routino SVN Repository Browser

Check out the latest version of Routino: svn co http://routino.org/svn/trunk routino

ViewVC logotype

Contents of /trunk/src/output.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 680 - (show annotations) (download) (as text)
Sun Apr 24 15:14:53 2011 UTC (13 years, 11 months ago) by amb
File MIME type: text/x-csrc
File size: 31486 byte(s)
Update comments throughout the source code.

1 /***************************************
2 Routing output generator.
3
4 Part of the Routino routing software.
5 ******************/ /******************
6 This file Copyright 2008-2011 Andrew M. Bishop
7
8 This program is free software: you can redistribute it and/or modify
9 it under the terms of the GNU Affero General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12
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 Affero General Public License for more details.
17
18 You should have received a copy of the GNU Affero General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 ***************************************/
21
22
23 #include <stdlib.h>
24 #include <string.h>
25 #include <ctype.h>
26 #include <stdio.h>
27 #include <math.h>
28 #include <errno.h>
29 #include <sys/types.h>
30 #include <sys/stat.h>
31 #include <unistd.h>
32
33 #include "types.h"
34 #include "nodes.h"
35 #include "segments.h"
36 #include "ways.h"
37
38 #include "files.h"
39 #include "functions.h"
40 #include "fakes.h"
41 #include "translations.h"
42 #include "results.h"
43 #include "xmlparse.h"
44
45
46 /* Global variables */
47
48 /*+ The option to calculate the quickest route insted of the shortest. +*/
49 extern int option_quickest;
50
51 /*+ The options to select the format of the output. +*/
52 extern int option_html,option_gpx_track,option_gpx_route,option_text,option_text_all;
53
54 /* Local variables */
55
56 /*+ Heuristics for determining if a junction is important. +*/
57 static char junction_other_way[Way_Count][Way_Count]=
58 { /* M, T, P, S, T, U, R, S, T, C, P, S, F = Way type of route not taken */
59 { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }, /* Motorway */
60 { 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }, /* Trunk */
61 { 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }, /* Primary */
62 { 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1 }, /* Secondary */
63 { 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1 }, /* Tertiary */
64 { 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1 }, /* Unclassified */
65 { 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1 }, /* Residential */
66 { 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1 }, /* Service */
67 { 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1 }, /* Track */
68 { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1 }, /* Cycleway */
69 { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, /* Path */
70 { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, /* Steps */
71 { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, /* Ferry */
72 };
73
74
75 /*++++++++++++++++++++++++++++++++++++++
76 Print the optimum route between two nodes.
77
78 Results **results The set of results to print (some may be NULL - ignore them).
79
80 int nresults The number of results in the list.
81
82 Nodes *nodes The set of nodes to use.
83
84 Segments *segments The set of segments to use.
85
86 Ways *ways The set of ways to use.
87
88 Profile *profile The profile containing the transport type, speeds and allowed highways.
89 ++++++++++++++++++++++++++++++++++++++*/
90
91 void PrintRoute(Results **results,int nresults,Nodes *nodes,Segments *segments,Ways *ways,Profile *profile)
92 {
93 FILE *htmlfile=NULL,*gpxtrackfile=NULL,*gpxroutefile=NULL,*textfile=NULL,*textallfile=NULL;
94
95 int point=1;
96 distance_t cum_distance=0;
97 duration_t cum_duration=0;
98 double finish_lat,finish_lon;
99 int segment_count=0;
100 int route_count=0;
101
102 /* Open the files */
103
104 if(option_quickest==0)
105 {
106 /* Print the result for the shortest route */
107
108 if(option_html)
109 htmlfile =fopen("shortest.html","w");
110 if(option_gpx_track)
111 gpxtrackfile=fopen("shortest-track.gpx","w");
112 if(option_gpx_route)
113 gpxroutefile=fopen("shortest-route.gpx","w");
114 if(option_text)
115 textfile =fopen("shortest.txt","w");
116 if(option_text_all)
117 textallfile =fopen("shortest-all.txt","w");
118
119 if(option_html && !htmlfile)
120 fprintf(stderr,"Warning: Cannot open file 'shortest.html' for writing [%s].\n",strerror(errno));
121 if(option_gpx_track && !gpxtrackfile)
122 fprintf(stderr,"Warning: Cannot open file 'shortest-track.gpx' for writing [%s].\n",strerror(errno));
123 if(option_gpx_route && !gpxroutefile)
124 fprintf(stderr,"Warning: Cannot open file 'shortest-route.gpx' for writing [%s].\n",strerror(errno));
125 if(option_text && !textfile)
126 fprintf(stderr,"Warning: Cannot open file 'shortest.txt' for writing [%s].\n",strerror(errno));
127 if(option_text_all && !textallfile)
128 fprintf(stderr,"Warning: Cannot open file 'shortest-all.txt' for writing [%s].\n",strerror(errno));
129 }
130 else
131 {
132 /* Print the result for the quickest route */
133
134 if(option_html)
135 htmlfile =fopen("quickest.html","w");
136 if(option_gpx_track)
137 gpxtrackfile=fopen("quickest-track.gpx","w");
138 if(option_gpx_route)
139 gpxroutefile=fopen("quickest-route.gpx","w");
140 if(option_text)
141 textfile =fopen("quickest.txt","w");
142 if(option_text_all)
143 textallfile =fopen("quickest-all.txt","w");
144
145 if(option_html && !htmlfile)
146 fprintf(stderr,"Warning: Cannot open file 'quickest.html' for writing [%s].\n",strerror(errno));
147 if(option_gpx_track && !gpxtrackfile)
148 fprintf(stderr,"Warning: Cannot open file 'quickest-track.gpx' for writing [%s].\n",strerror(errno));
149 if(option_gpx_route && !gpxroutefile)
150 fprintf(stderr,"Warning: Cannot open file 'quickest-route.gpx' for writing [%s].\n",strerror(errno));
151 if(option_text && !textfile)
152 fprintf(stderr,"Warning: Cannot open file 'quickest.txt' for writing [%s].\n",strerror(errno));
153 if(option_text_all && !textallfile)
154 fprintf(stderr,"Warning: Cannot open file 'quickest-all.txt' for writing [%s].\n",strerror(errno));
155 }
156
157 /* Print the head of the files */
158
159 if(htmlfile)
160 {
161 fprintf(htmlfile,"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n");
162 fprintf(htmlfile,"<HTML>\n");
163 if(translate_copyright_creator[0] && translate_copyright_creator[1])
164 fprintf(htmlfile,"<!-- %s : %s -->\n",translate_copyright_creator[0],translate_copyright_creator[1]);
165 if(translate_copyright_source[0] && translate_copyright_source[1])
166 fprintf(htmlfile,"<!-- %s : %s -->\n",translate_copyright_source[0],translate_copyright_source[1]);
167 if(translate_copyright_license[0] && translate_copyright_license[1])
168 fprintf(htmlfile,"<!-- %s : %s -->\n",translate_copyright_license[0],translate_copyright_license[1]);
169 fprintf(htmlfile,"<HEAD>\n");
170 fprintf(htmlfile,"<TITLE>");
171 fprintf(htmlfile,translate_html_title,option_quickest?translate_route_quickest:translate_route_shortest);
172 fprintf(htmlfile,"</TITLE>\n");
173 fprintf(htmlfile,"<META http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\n");
174 fprintf(htmlfile,"<STYLE type=\"text/css\">\n");
175 fprintf(htmlfile,"<!--\n");
176 fprintf(htmlfile," table {table-layout: fixed; border: none; border-collapse: collapse;}\n");
177 fprintf(htmlfile," table.c {color: grey; font-size: x-small;} /* copyright */\n");
178 fprintf(htmlfile," tr {border: 0px;}\n");
179 fprintf(htmlfile," tr.c {display: none;} /* coords */\n");
180 fprintf(htmlfile," tr.n {} /* node */\n");
181 fprintf(htmlfile," tr.s {} /* segment */\n");
182 fprintf(htmlfile," tr.t {font-weight: bold;} /* total */\n");
183 fprintf(htmlfile," td.l {font-weight: bold;}\n");
184 fprintf(htmlfile," td.r {}\n");
185 fprintf(htmlfile," span.w {font-weight: bold;} /* waypoint */\n");
186 fprintf(htmlfile," span.h {text-decoration: underline;} /* highway */\n");
187 fprintf(htmlfile," span.d {} /* segment distance */\n");
188 fprintf(htmlfile," span.j {font-style: italic;} /* total journey distance */\n");
189 fprintf(htmlfile," span.t {font-variant: small-caps;} /* turn */\n");
190 fprintf(htmlfile," span.b {font-variant: small-caps;} /* bearing */\n");
191 fprintf(htmlfile,"-->\n");
192 fprintf(htmlfile,"</STYLE>\n");
193 fprintf(htmlfile,"</HEAD>\n");
194 fprintf(htmlfile,"<BODY>\n");
195 fprintf(htmlfile,"<H1>");
196 fprintf(htmlfile,translate_html_title,option_quickest?translate_route_quickest:translate_route_shortest);
197 fprintf(htmlfile,"</H1>\n");
198 fprintf(htmlfile,"<table>\n");
199 }
200
201 if(gpxtrackfile)
202 {
203 fprintf(gpxtrackfile,"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
204 fprintf(gpxtrackfile,"<gpx version=\"1.1\" creator=\"Routino\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"http://www.topografix.com/GPX/1/1\" xsi:schemaLocation=\"http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd\">\n");
205
206 fprintf(gpxtrackfile,"<metadata>\n");
207 fprintf(gpxtrackfile,"<desc>%s : %s</desc>\n",translate_copyright_creator[0],translate_copyright_creator[1]);
208 if(translate_copyright_source[1])
209 {
210 fprintf(gpxtrackfile,"<copyright author=\"%s\">\n",translate_copyright_source[1]);
211
212 if(translate_copyright_license[1])
213 fprintf(gpxtrackfile,"<license>%s</license>\n",translate_copyright_license[1]);
214
215 fprintf(gpxtrackfile,"</copyright>\n");
216 }
217 fprintf(gpxtrackfile,"</metadata>\n");
218
219 fprintf(gpxtrackfile,"<trk>\n");
220 fprintf(gpxtrackfile,"<name>");
221 fprintf(gpxtrackfile,translate_gpx_name,option_quickest?translate_route_quickest:translate_route_shortest);
222 fprintf(gpxtrackfile,"</name>\n");
223 fprintf(gpxtrackfile,"<desc>");
224 fprintf(gpxtrackfile,translate_gpx_desc,option_quickest?translate_route_quickest:translate_route_shortest);
225 fprintf(gpxtrackfile,"</desc>\n");
226 }
227
228 if(gpxroutefile)
229 {
230 fprintf(gpxroutefile,"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
231 fprintf(gpxroutefile,"<gpx version=\"1.1\" creator=\"Routino\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"http://www.topografix.com/GPX/1/1\" xsi:schemaLocation=\"http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd\">\n");
232
233 fprintf(gpxroutefile,"<metadata>\n");
234 fprintf(gpxroutefile,"<desc>%s : %s</desc>\n",translate_copyright_creator[0],translate_copyright_creator[1]);
235 if(translate_copyright_source[1])
236 {
237 fprintf(gpxroutefile,"<copyright author=\"%s\">\n",translate_copyright_source[1]);
238
239 if(translate_copyright_license[1])
240 fprintf(gpxroutefile,"<license>%s</license>\n",translate_copyright_license[1]);
241
242 fprintf(gpxroutefile,"</copyright>\n");
243 }
244 fprintf(gpxroutefile,"</metadata>\n");
245
246 fprintf(gpxroutefile,"<rte>\n");
247 fprintf(gpxroutefile,"<name>");
248 fprintf(gpxroutefile,translate_gpx_name,option_quickest?translate_route_quickest:translate_route_shortest);
249 fprintf(gpxroutefile,"</name>\n");
250 fprintf(gpxroutefile,"<desc>");
251 fprintf(gpxroutefile,translate_gpx_desc,option_quickest?translate_route_quickest:translate_route_shortest);
252 fprintf(gpxroutefile,"</desc>\n");
253 }
254
255 if(textfile)
256 {
257 if(translate_copyright_creator[0] && translate_copyright_creator[1])
258 fprintf(textfile,"# %s : %s\n",translate_copyright_creator[0],translate_copyright_creator[1]);
259 if(translate_copyright_source[0] && translate_copyright_source[1])
260 fprintf(textfile,"# %s : %s\n",translate_copyright_source[0],translate_copyright_source[1]);
261 if(translate_copyright_license[0] && translate_copyright_license[1])
262 fprintf(textfile,"# %s : %s\n",translate_copyright_license[0],translate_copyright_license[1]);
263 if((translate_copyright_creator[0] && translate_copyright_creator[1]) ||
264 (translate_copyright_source[0] && translate_copyright_source[1]) ||
265 (translate_copyright_license[0] && translate_copyright_license[1]))
266 fprintf(textfile,"#\n");
267
268 fprintf(textfile,"#Latitude\tLongitude\tSection \tSection \tTotal \tTotal \tPoint\tTurn\tBearing\tHighway\n");
269 fprintf(textfile,"# \t \tDistance\tDuration\tDistance\tDuration\tType \t \t \t \n");
270 /* "%10.6f\t%11.6f\t%6.3f km\t%4.1f min\t%5.1f km\t%4.0f min\t%s\t %+d\t %+d\t%s\n" */
271 }
272
273 if(textallfile)
274 {
275 if(translate_copyright_creator[0] && translate_copyright_creator[1])
276 fprintf(textallfile,"# %s : %s\n",translate_copyright_creator[0],translate_copyright_creator[1]);
277 if(translate_copyright_source[0] && translate_copyright_source[1])
278 fprintf(textallfile,"# %s : %s\n",translate_copyright_source[0],translate_copyright_source[1]);
279 if(translate_copyright_license[0] && translate_copyright_license[1])
280 fprintf(textallfile,"# %s : %s\n",translate_copyright_license[0],translate_copyright_license[1]);
281 if((translate_copyright_creator[0] && translate_copyright_creator[1]) ||
282 (translate_copyright_source[0] && translate_copyright_source[1]) ||
283 (translate_copyright_license[0] && translate_copyright_license[1]))
284 fprintf(textallfile,"#\n");
285
286 fprintf(textallfile,"#Latitude\tLongitude\t Node\tType\tSegment\tSegment\tTotal\tTotal \tSpeed\tBearing\tHighway\n");
287 fprintf(textallfile,"# \t \t \t \tDist \tDurat'n\tDist \tDurat'n\t \t \t \n");
288 /* "%10.6f\t%11.6f\t%8d%c\t%s\t%5.3f\t%5.2f\t%5.2f\t%5.1f\t%3d\t%4d\t%s\n" */
289 }
290
291 /* Loop through the segments of the route and print it */
292
293 while(!results[point])
294 point++;
295
296 while(point<=nresults)
297 {
298 int nextpoint=point;
299 double start_lat,start_lon;
300 distance_t junc_distance=0;
301 duration_t junc_duration=0;
302 Result *result;
303
304 if(gpxtrackfile)
305 fprintf(gpxtrackfile,"<trkseg>\n");
306
307 if(IsFakeNode(results[point]->start_node))
308 GetFakeLatLong(results[point]->start_node,&start_lat,&start_lon);
309 else
310 GetLatLong(nodes,results[point]->start_node,&start_lat,&start_lon);
311
312 if(IsFakeNode(results[point]->finish_node))
313 GetFakeLatLong(results[point]->finish_node,&finish_lat,&finish_lon);
314 else
315 GetLatLong(nodes,results[point]->finish_node,&finish_lat,&finish_lon);
316
317 result=FindResult(results[point],results[point]->start_node,results[point]->prev_segment);
318
319 do
320 {
321 double latitude,longitude;
322 Result *nextresult;
323 Segment *nextresultsegment;
324
325 if(result->node==results[point]->start_node)
326 {latitude=start_lat; longitude=start_lon;}
327 else if(result->node==results[point]->finish_node)
328 {latitude=finish_lat; longitude=finish_lon;}
329 else
330 GetLatLong(nodes,result->node,&latitude,&longitude);
331
332 if(gpxtrackfile)
333 fprintf(gpxtrackfile,"<trkpt lat=\"%.6f\" lon=\"%.6f\"/>\n",
334 radians_to_degrees(latitude),radians_to_degrees(longitude));
335
336 nextresult=result->next;
337
338 if(!nextresult)
339 for(nextpoint=point+1;nextpoint<=nresults;nextpoint++)
340 if(results[nextpoint])
341 {
342 nextresult=FindResult(results[nextpoint],results[nextpoint]->start_node,results[nextpoint]->prev_segment);
343 nextresult=nextresult->next;
344 break;
345 }
346
347 if(nextresult)
348 {
349 if(IsFakeSegment(nextresult->segment))
350 nextresultsegment=LookupFakeSegment(nextresult->segment);
351 else
352 nextresultsegment=LookupSegment(segments,nextresult->segment,2);
353 }
354 else
355 nextresultsegment=NULL;
356
357 if(result->node!=results[point]->start_node)
358 {
359 distance_t seg_distance=0;
360 duration_t seg_duration=0;
361 Segment *resultsegment,*comparesegment;
362 Way *resultway;
363 int important=0;
364
365 /* Cache the values to be printed rather than calculating them repeatedly for each output format */
366
367 char *waynameraw=NULL,*waynamexml=NULL;
368 const char *wayname=NULL;
369 int bearing_int=0,bearing_next_int=0,turn_int=0;
370 char *bearing_str=NULL,*bearing_next_str=NULL,*turn_str=NULL;
371
372 /* Get the properties of this segment */
373
374 if(IsFakeSegment(result->segment))
375 {
376 resultsegment=LookupFakeSegment(result->segment);
377 comparesegment=LookupSegment(segments,IndexRealSegment(result->segment),1);
378 }
379 else
380 {
381 resultsegment=LookupSegment(segments,result->segment,3);
382 comparesegment=resultsegment;
383 }
384 resultway=LookupWay(ways,resultsegment->way,1);
385
386 seg_distance+=DISTANCE(resultsegment->distance);
387 seg_duration+=Duration(resultsegment,resultway,profile);
388 junc_distance+=seg_distance;
389 junc_duration+=seg_duration;
390 cum_distance+=seg_distance;
391 cum_duration+=seg_duration;
392
393 /* Decide if this is an important junction */
394
395 if(result->node==results[point]->finish_node) /* Waypoint */
396 important=10;
397 else if(result->segment==result->next->segment) /* U-turn */
398 important=5;
399 else
400 {
401 Segment *segment=FirstSegment(segments,nodes,result->node);
402
403 do
404 {
405 index_t othernode=OtherNode(segment,result->node);
406
407 if(othernode!=result->prev->node && segment!=comparesegment)
408 if(IsNormalSegment(segment) && (!profile->oneway || !IsOnewayTo(segment,result->node)))
409 {
410 Way *way=LookupWay(ways,segment->way,2);
411
412 if(othernode==result->next->node) /* the next segment that we follow */
413 {
414 if(HIGHWAY(way->type)!=HIGHWAY(resultway->type))
415 if(important<2)
416 important=2;
417 }
418 else if(IsFakeNode(result->next->node))
419 ;
420 else /* a segment that we don't follow */
421 {
422 if(junction_other_way[HIGHWAY(resultway->type)-1][HIGHWAY(way->type)-1])
423 if(important<3)
424 important=3;
425
426 if(important<1)
427 important=1;
428 }
429 }
430
431 segment=NextSegment(segments,segment,result->node);
432 }
433 while(segment);
434 }
435
436 /* Print out the important points (junctions / waypoints) */
437
438 if(important>1)
439 {
440 /* Print the intermediate finish points (because they have correct junction distances) */
441
442 if(htmlfile)
443 {
444 char *type;
445
446 if(important==10)
447 type=translate_html_waypoint;
448 else
449 type=translate_html_junction;
450
451 if(!waynameraw)
452 {
453 waynameraw=WayName(ways,resultway);
454 if(!*waynameraw)
455 waynameraw=translate_highway[HIGHWAY(resultway->type)];
456 }
457
458 if(!waynamexml)
459 waynamexml=ParseXML_Encode_Safe_XML(waynameraw);
460
461 fprintf(htmlfile,"<tr class='s'><td class='l'>%s:<td class='r'>",translate_html_segment[0]);
462 fprintf(htmlfile,translate_html_segment[1],
463 waynamexml,
464 distance_to_km(junc_distance),duration_to_minutes(junc_duration));
465 fprintf(htmlfile," [<span class='j'>");
466 fprintf(htmlfile,translate_html_total[1],
467 distance_to_km(cum_distance),duration_to_minutes(cum_duration));
468 fprintf(htmlfile,"</span>]\n");
469
470 fprintf(htmlfile,"<tr class='c'><td class='l'><td class='r'>%.6f %.6f\n",
471 radians_to_degrees(latitude),radians_to_degrees(longitude));
472
473 if(nextresult)
474 {
475 if(!turn_str)
476 {
477 turn_int=(int)TurnAngle(nodes,resultsegment,nextresultsegment,result->node);
478 turn_str=translate_turn[(4+(22+turn_int)/45)%8];
479 }
480
481 if(!bearing_next_str)
482 {
483 bearing_next_int=(int)BearingAngle(nodes,nextresultsegment,nextresult->node);
484 bearing_next_str=translate_heading[(4+(22+bearing_next_int)/45)%8];
485 }
486
487 fprintf(htmlfile,"<tr class='n'><td class='l'>%s:<td class='r'>",translate_html_node[0]);
488 fprintf(htmlfile,translate_html_node[1],
489 type,
490 turn_str,
491 bearing_next_str);
492 fprintf(htmlfile,"\n");
493 }
494 else
495 {
496 fprintf(htmlfile,"<tr class='n'><td class='l'>%s:<td class='r'>",translate_html_stop[0]);
497 fprintf(htmlfile,translate_html_stop[1],
498 translate_html_waypoint);
499 fprintf(htmlfile,"\n");
500 fprintf(htmlfile,"<tr class='t'><td class='l'>%s:<td class='r'><span class='j'>",translate_html_total[0]);
501 fprintf(htmlfile,translate_html_total[1],
502 distance_to_km(cum_distance),duration_to_minutes(cum_duration));
503 fprintf(htmlfile,"</span>\n");
504 }
505 }
506
507 if(gpxroutefile)
508 {
509 if(!waynameraw)
510 {
511 waynameraw=WayName(ways,resultway);
512 if(!*waynameraw)
513 waynameraw=translate_highway[HIGHWAY(resultway->type)];
514 }
515
516 if(!waynamexml)
517 waynamexml=ParseXML_Encode_Safe_XML(waynameraw);
518
519 if(!bearing_str)
520 {
521 bearing_int=(int)BearingAngle(nodes,resultsegment,result->node);
522 bearing_str=translate_heading[(4+(22+bearing_int)/45)%8];
523 }
524
525 fprintf(gpxroutefile,"<desc>");
526 fprintf(gpxroutefile,translate_gpx_step,
527 bearing_str,
528 waynamexml,
529 distance_to_km(junc_distance),duration_to_minutes(junc_duration));
530 fprintf(gpxroutefile,"</desc></rtept>\n");
531
532 if(!nextresult)
533 {
534 fprintf(gpxroutefile,"<rtept lat=\"%.6f\" lon=\"%.6f\"><name>%s</name>\n",
535 radians_to_degrees(finish_lat),radians_to_degrees(finish_lon),
536 translate_gpx_finish);
537 fprintf(gpxroutefile,"<desc>");
538 fprintf(gpxroutefile,translate_gpx_final,
539 distance_to_km(cum_distance),duration_to_minutes(cum_duration));
540 fprintf(gpxroutefile,"</desc></rtept>\n");
541 }
542 else if(important==10)
543 fprintf(gpxroutefile,"<rtept lat=\"%.6f\" lon=\"%.6f\"><name>%s%d</name>\n",
544 radians_to_degrees(latitude),radians_to_degrees(longitude),
545 translate_gpx_inter,++segment_count);
546 else
547 fprintf(gpxroutefile,"<rtept lat=\"%.6f\" lon=\"%.6f\"><name>%s%03d</name>\n",
548 radians_to_degrees(latitude),radians_to_degrees(longitude),
549 translate_gpx_trip,++route_count);
550 }
551
552 if(textfile)
553 {
554 char *type;
555
556 if(important==10)
557 type="Waypt";
558 else
559 type="Junct";
560
561 if(!wayname)
562 {
563 wayname=WayName(ways,resultway);
564 if(!*wayname)
565 wayname=HighwayName(HIGHWAY(resultway->type));
566 }
567
568 if(nextresult)
569 {
570 if(!turn_str)
571 {
572 turn_int=(int)TurnAngle(nodes,resultsegment,nextresultsegment,result->node);
573 turn_str=translate_turn[(4+(22+turn_int)/45)%8];
574 }
575
576 if(!bearing_next_str)
577 {
578 bearing_next_int=(int)BearingAngle(nodes,nextresultsegment,nextresult->node);
579 bearing_next_str=translate_heading[(4+(22+bearing_next_int)/45)%8];
580 }
581
582 fprintf(textfile,"%10.6f\t%11.6f\t%6.3f km\t%4.1f min\t%5.1f km\t%4.0f min\t%s\t %+d\t %+d\t%s\n",
583 radians_to_degrees(latitude),radians_to_degrees(longitude),
584 distance_to_km(junc_distance),duration_to_minutes(junc_duration),
585 distance_to_km(cum_distance),duration_to_minutes(cum_duration),
586 type,
587 (22+turn_int)/45,
588 ((22+bearing_next_int)/45+4)%8-4,
589 wayname);
590 }
591 else
592 fprintf(textfile,"%10.6f\t%11.6f\t%6.3f km\t%4.1f min\t%5.1f km\t%4.0f min\t%s\t\t\t%s\n",
593 radians_to_degrees(latitude),radians_to_degrees(longitude),
594 distance_to_km(junc_distance),duration_to_minutes(junc_duration),
595 distance_to_km(cum_distance),duration_to_minutes(cum_duration),
596 type,
597 wayname);
598 }
599
600 junc_distance=0;
601 junc_duration=0;
602 }
603
604 /* Print out all of the results */
605
606 if(textallfile)
607 {
608 char *type;
609
610 if(important==10)
611 type="Waypt";
612 else if(important==2)
613 type="Change";
614 else if(important>=1)
615 type="Junct";
616 else
617 type="Inter";
618
619 if(!wayname)
620 {
621 wayname=WayName(ways,resultway);
622 if(!*wayname)
623 wayname=HighwayName(HIGHWAY(resultway->type));
624 }
625
626 if(!bearing_str)
627 {
628 bearing_int=(int)BearingAngle(nodes,resultsegment,result->node);
629 bearing_str=translate_heading[(4+(22+bearing_int)/45)%8];
630 }
631
632 fprintf(textallfile,"%10.6f\t%11.6f\t%8d%c\t%s\t%5.3f\t%5.2f\t%5.2f\t%5.1f\t%3d\t%4d\t%s\n",
633 radians_to_degrees(latitude),radians_to_degrees(longitude),
634 IsFakeNode(result->node)?(NODE_FAKE-result->node):result->node,
635 (!IsFakeNode(result->node) && IsSuperNode(LookupNode(nodes,result->node,1)))?'*':' ',type,
636 distance_to_km(seg_distance),duration_to_minutes(seg_duration),
637 distance_to_km(cum_distance),duration_to_minutes(cum_duration),
638 profile->speed[HIGHWAY(resultway->type)],
639 bearing_int,
640 wayname);
641 }
642
643 if(waynamexml && waynamexml!=waynameraw)
644 free(waynamexml);
645 }
646 else if(!cum_distance)
647 {
648 int bearing_next_int=(int)BearingAngle(nodes,nextresultsegment,nextresult->node);
649 char *bearing_next_str=translate_heading[(4+(22+bearing_next_int)/45)%8];
650
651 /* Print out the very first start point */
652
653 if(htmlfile)
654 {
655 fprintf(htmlfile,"<tr class='c'><td class='l'><td class='r'>%.6f %.6f\n",
656 radians_to_degrees(latitude),radians_to_degrees(longitude));
657 fprintf(htmlfile,"<tr class='n'><td class='l'>%s:<td class='r'>",translate_html_start[0]);
658 fprintf(htmlfile,translate_html_start[1],
659 translate_html_waypoint,
660 bearing_next_str);
661 fprintf(htmlfile,"\n");
662 }
663
664 if(gpxroutefile)
665 fprintf(gpxroutefile,"<rtept lat=\"%.6f\" lon=\"%.6f\"><name>%s</name>\n",
666 radians_to_degrees(latitude),radians_to_degrees(longitude),
667 translate_gpx_start);
668
669 if(textfile)
670 fprintf(textfile,"%10.6f\t%11.6f\t%6.3f km\t%4.1f min\t%5.1f km\t%4.0f min\t%s\t\t +%d\t\n",
671 radians_to_degrees(latitude),radians_to_degrees(longitude),
672 0.0,0.0,0.0,0.0,
673 "Waypt",
674 (22+bearing_next_int)/45);
675
676 if(textallfile)
677 fprintf(textallfile,"%10.6f\t%11.6f\t%8d%c\t%s\t%5.3f\t%5.2f\t%5.2f\t%5.1f\t\t\t\n",
678 radians_to_degrees(latitude),radians_to_degrees(longitude),
679 IsFakeNode(result->node)?(NODE_FAKE-result->node):result->node,
680 (!IsFakeNode(result->node) && IsSuperNode(LookupNode(nodes,result->node,1)))?'*':' ',"Waypt",
681 0.0,0.0,0.0,0.0);
682 }
683
684 result=nextresult;
685 }
686 while(point==nextpoint);
687
688 if(gpxtrackfile)
689 fprintf(gpxtrackfile,"</trkseg>\n");
690
691 point=nextpoint;
692 }
693
694 /* Print the tail of the files */
695
696 if(htmlfile)
697 {
698 fprintf(htmlfile,"</table>\n");
699
700 if((translate_copyright_creator[0] && translate_copyright_creator[1]) ||
701 (translate_copyright_source[0] && translate_copyright_source[1]) ||
702 (translate_copyright_license[0] && translate_copyright_license[1]))
703 {
704 fprintf(htmlfile,"<p>\n");
705 fprintf(htmlfile,"<table class='c'>\n");
706 if(translate_copyright_creator[0] && translate_copyright_creator[1])
707 fprintf(htmlfile,"<tr><td class='l'>%s:<td class='r'>%s\n",translate_copyright_creator[0],translate_copyright_creator[1]);
708 if(translate_copyright_source[0] && translate_copyright_source[1])
709 fprintf(htmlfile,"<tr><td class='l'>%s:<td class='r'>%s\n",translate_copyright_source[0],translate_copyright_source[1]);
710 if(translate_copyright_license[0] && translate_copyright_license[1])
711 fprintf(htmlfile,"<tr><td class='l'>%s:<td class='r'>%s\n",translate_copyright_license[0],translate_copyright_license[1]);
712 fprintf(htmlfile,"</table>\n");
713 }
714
715 fprintf(htmlfile,"</BODY>\n");
716 fprintf(htmlfile,"</HTML>\n");
717 }
718
719 if(gpxtrackfile)
720 {
721 fprintf(gpxtrackfile,"</trk>\n");
722 fprintf(gpxtrackfile,"</gpx>\n");
723 }
724
725 if(gpxroutefile)
726 {
727 fprintf(gpxroutefile,"</rte>\n");
728 fprintf(gpxroutefile,"</gpx>\n");
729 }
730
731 /* Close the files */
732
733 if(htmlfile)
734 fclose(htmlfile);
735 if(gpxtrackfile)
736 fclose(gpxtrackfile);
737 if(gpxroutefile)
738 fclose(gpxroutefile);
739 if(textfile)
740 fclose(textfile);
741 if(textallfile)
742 fclose(textallfile);
743 }

Properties

Name Value
cvs:description New file to contain the function to print the output.