Routino SVN Repository Browser

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

ViewVC logotype

Annotation of /trunk/src/output.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 695 - (hide annotations) (download) (as text)
Sat May 7 10:13:40 2011 UTC (13 years, 11 months ago) by amb
File MIME type: text/x-csrc
File size: 31854 byte(s)
Use real segments when making comparisons (not pointers or non-real segments).

1 amb 160 /***************************************
2     Routing output generator.
3    
4     Part of the Routino routing software.
5     ******************/ /******************
6 amb 598 This file Copyright 2008-2011 Andrew M. Bishop
7 amb 160
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 amb 165 #include <stdlib.h>
24 amb 160 #include <string.h>
25 amb 164 #include <ctype.h>
26 amb 160 #include <stdio.h>
27 amb 316 #include <math.h>
28 amb 330 #include <errno.h>
29 amb 164 #include <sys/types.h>
30     #include <sys/stat.h>
31     #include <unistd.h>
32 amb 160
33     #include "types.h"
34     #include "nodes.h"
35     #include "segments.h"
36     #include "ways.h"
37 amb 449
38     #include "files.h"
39     #include "functions.h"
40 amb 532 #include "fakes.h"
41 amb 449 #include "translations.h"
42 amb 160 #include "results.h"
43 amb 378 #include "xmlparse.h"
44 amb 160
45    
46 amb 360 /* Global variables */
47    
48 amb 160 /*+ The option to calculate the quickest route insted of the shortest. +*/
49     extern int option_quickest;
50    
51 amb 324 /*+ 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 amb 360 /* Local variables */
55    
56 amb 171 /*+ Heuristics for determining if a junction is important. +*/
57 amb 300 static char junction_other_way[Way_Count][Way_Count]=
58 amb 492 { /* 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 amb 171 };
73 amb 165
74 amb 360
75 amb 160 /*++++++++++++++++++++++++++++++++++++++
76 amb 379 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 amb 680 Nodes *nodes The set of nodes to use.
83 amb 379
84     Segments *segments The set of segments to use.
85    
86 amb 680 Ways *ways The set of ways to use.
87 amb 379
88     Profile *profile The profile containing the transport type, speeds and allowed highways.
89 amb 164 ++++++++++++++++++++++++++++++++++++++*/
90 amb 160
91 amb 379 void PrintRoute(Results **results,int nresults,Nodes *nodes,Segments *segments,Ways *ways,Profile *profile)
92 amb 164 {
93 amb 379 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 amb 683 int segment_count=0,route_count=0;
100     int point_count=0;
101 amb 379
102 amb 164 /* Open the files */
103 amb 160
104     if(option_quickest==0)
105     {
106     /* Print the result for the shortest route */
107    
108 amb 324 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 amb 177
119 amb 324 if(option_html && !htmlfile)
120 amb 330 fprintf(stderr,"Warning: Cannot open file 'shortest.html' for writing [%s].\n",strerror(errno));
121 amb 324 if(option_gpx_track && !gpxtrackfile)
122 amb 330 fprintf(stderr,"Warning: Cannot open file 'shortest-track.gpx' for writing [%s].\n",strerror(errno));
123 amb 324 if(option_gpx_route && !gpxroutefile)
124 amb 330 fprintf(stderr,"Warning: Cannot open file 'shortest-route.gpx' for writing [%s].\n",strerror(errno));
125 amb 324 if(option_text && !textfile)
126 amb 330 fprintf(stderr,"Warning: Cannot open file 'shortest.txt' for writing [%s].\n",strerror(errno));
127 amb 324 if(option_text_all && !textallfile)
128 amb 330 fprintf(stderr,"Warning: Cannot open file 'shortest-all.txt' for writing [%s].\n",strerror(errno));
129 amb 160 }
130     else
131     {
132     /* Print the result for the quickest route */
133    
134 amb 324 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 amb 177
145 amb 324 if(option_html && !htmlfile)
146 amb 330 fprintf(stderr,"Warning: Cannot open file 'quickest.html' for writing [%s].\n",strerror(errno));
147 amb 324 if(option_gpx_track && !gpxtrackfile)
148 amb 330 fprintf(stderr,"Warning: Cannot open file 'quickest-track.gpx' for writing [%s].\n",strerror(errno));
149 amb 324 if(option_gpx_route && !gpxroutefile)
150 amb 330 fprintf(stderr,"Warning: Cannot open file 'quickest-route.gpx' for writing [%s].\n",strerror(errno));
151 amb 324 if(option_text && !textfile)
152 amb 330 fprintf(stderr,"Warning: Cannot open file 'quickest.txt' for writing [%s].\n",strerror(errno));
153 amb 324 if(option_text_all && !textallfile)
154 amb 330 fprintf(stderr,"Warning: Cannot open file 'quickest-all.txt' for writing [%s].\n",strerror(errno));
155 amb 160 }
156    
157 amb 164 /* Print the head of the files */
158 amb 160
159 amb 323 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 amb 376 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 amb 323 fprintf(htmlfile,"<HEAD>\n");
170 amb 378 fprintf(htmlfile,"<TITLE>");
171     fprintf(htmlfile,translate_html_title,option_quickest?translate_route_quickest:translate_route_shortest);
172     fprintf(htmlfile,"</TITLE>\n");
173 amb 485 fprintf(htmlfile,"<META http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\n");
174     fprintf(htmlfile,"<STYLE type=\"text/css\">\n");
175 amb 323 fprintf(htmlfile,"<!--\n");
176 amb 376 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 amb 323 fprintf(htmlfile,"-->\n");
192     fprintf(htmlfile,"</STYLE>\n");
193     fprintf(htmlfile,"</HEAD>\n");
194     fprintf(htmlfile,"<BODY>\n");
195 amb 378 fprintf(htmlfile,"<H1>");
196     fprintf(htmlfile,translate_html_title,option_quickest?translate_route_quickest:translate_route_shortest);
197     fprintf(htmlfile,"</H1>\n");
198 amb 323 fprintf(htmlfile,"<table>\n");
199     }
200    
201 amb 177 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 amb 160
206 amb 177 fprintf(gpxtrackfile,"<metadata>\n");
207 amb 383 fprintf(gpxtrackfile,"<desc>%s : %s</desc>\n",translate_copyright_creator[0],translate_copyright_creator[1]);
208 amb 376 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 amb 177 fprintf(gpxtrackfile,"</copyright>\n");
216 amb 376 }
217 amb 177 fprintf(gpxtrackfile,"</metadata>\n");
218 amb 160
219 amb 177 fprintf(gpxtrackfile,"<trk>\n");
220 amb 376 fprintf(gpxtrackfile,"<name>");
221 amb 378 fprintf(gpxtrackfile,translate_gpx_name,option_quickest?translate_route_quickest:translate_route_shortest);
222 amb 376 fprintf(gpxtrackfile,"</name>\n");
223     fprintf(gpxtrackfile,"<desc>");
224 amb 378 fprintf(gpxtrackfile,translate_gpx_desc,option_quickest?translate_route_quickest:translate_route_shortest);
225 amb 376 fprintf(gpxtrackfile,"</desc>\n");
226 amb 177 }
227 amb 160
228 amb 177 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 amb 160
233 amb 177 fprintf(gpxroutefile,"<metadata>\n");
234 amb 383 fprintf(gpxroutefile,"<desc>%s : %s</desc>\n",translate_copyright_creator[0],translate_copyright_creator[1]);
235 amb 376 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 amb 177 fprintf(gpxroutefile,"</copyright>\n");
243 amb 376 }
244 amb 177 fprintf(gpxroutefile,"</metadata>\n");
245 amb 160
246 amb 177 fprintf(gpxroutefile,"<rte>\n");
247 amb 360 fprintf(gpxroutefile,"<name>");
248 amb 378 fprintf(gpxroutefile,translate_gpx_name,option_quickest?translate_route_quickest:translate_route_shortest);
249 amb 360 fprintf(gpxroutefile,"</name>\n");
250 amb 376 fprintf(gpxroutefile,"<desc>");
251 amb 378 fprintf(gpxroutefile,translate_gpx_desc,option_quickest?translate_route_quickest:translate_route_shortest);
252 amb 376 fprintf(gpxroutefile,"</desc>\n");
253 amb 177 }
254 amb 160
255 amb 177 if(textfile)
256     {
257 amb 376 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 amb 177 fprintf(textfile,"#\n");
267 amb 376
268 amb 316 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 amb 177 }
272 amb 160
273 amb 177 if(textallfile)
274     {
275 amb 376 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 amb 177 fprintf(textallfile,"#\n");
285 amb 376
286 amb 316 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 amb 177 }
290 amb 160
291 amb 379 /* Loop through the segments of the route and print it */
292 amb 164
293 amb 316 while(!results[point])
294     point++;
295 amb 164
296 amb 316 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 amb 160
304 amb 324 if(gpxtrackfile)
305     fprintf(gpxtrackfile,"<trkseg>\n");
306 amb 303
307 amb 605 if(IsFakeNode(results[point]->start_node))
308     GetFakeLatLong(results[point]->start_node,&start_lat,&start_lon);
309 amb 316 else
310 amb 605 GetLatLong(nodes,results[point]->start_node,&start_lat,&start_lon);
311 amb 165
312 amb 605 if(IsFakeNode(results[point]->finish_node))
313     GetFakeLatLong(results[point]->finish_node,&finish_lat,&finish_lon);
314 amb 303 else
315 amb 605 GetLatLong(nodes,results[point]->finish_node,&finish_lat,&finish_lon);
316 amb 160
317 amb 605 result=FindResult(results[point],results[point]->start_node,results[point]->prev_segment);
318 amb 160
319 amb 316 do
320 amb 160 {
321 amb 316 double latitude,longitude;
322     Result *nextresult;
323 amb 695 index_t nextrealsegment;
324 amb 459 Segment *nextresultsegment;
325 amb 160
326 amb 605 if(result->node==results[point]->start_node)
327 amb 316 {latitude=start_lat; longitude=start_lon;}
328 amb 605 else if(result->node==results[point]->finish_node)
329 amb 316 {latitude=finish_lat; longitude=finish_lon;}
330     else
331     GetLatLong(nodes,result->node,&latitude,&longitude);
332 amb 171
333 amb 316 if(gpxtrackfile)
334     fprintf(gpxtrackfile,"<trkpt lat=\"%.6f\" lon=\"%.6f\"/>\n",
335     radians_to_degrees(latitude),radians_to_degrees(longitude));
336 amb 171
337 amb 605 nextresult=result->next;
338 amb 171
339 amb 316 if(!nextresult)
340     for(nextpoint=point+1;nextpoint<=nresults;nextpoint++)
341     if(results[nextpoint])
342     {
343 amb 605 nextresult=FindResult(results[nextpoint],results[nextpoint]->start_node,results[nextpoint]->prev_segment);
344     nextresult=nextresult->next;
345 amb 316 break;
346     }
347 amb 171
348 amb 459 if(nextresult)
349     {
350 amb 605 if(IsFakeSegment(nextresult->segment))
351 amb 695 {
352 amb 605 nextresultsegment=LookupFakeSegment(nextresult->segment);
353 amb 695 nextrealsegment=IndexRealSegment(nextresult->segment);
354     }
355 amb 459 else
356 amb 695 {
357 amb 605 nextresultsegment=LookupSegment(segments,nextresult->segment,2);
358 amb 695 nextrealsegment=nextresult->segment;
359     }
360 amb 459 }
361     else
362 amb 695 {
363 amb 459 nextresultsegment=NULL;
364 amb 695 nextrealsegment=NO_SEGMENT;
365     }
366 amb 459
367 amb 605 if(result->node!=results[point]->start_node)
368 amb 169 {
369 amb 316 distance_t seg_distance=0;
370     duration_t seg_duration=0;
371 amb 695 index_t realsegment;
372     Segment *resultsegment;
373 amb 316 Way *resultway;
374     int important=0;
375 amb 171
376 amb 378 /* Cache the values to be printed rather than calculating them repeatedly for each output format */
377    
378 amb 474 char *waynameraw=NULL,*waynamexml=NULL;
379     const char *wayname=NULL;
380 amb 440 int bearing_int=0,bearing_next_int=0,turn_int=0;
381 amb 378 char *bearing_str=NULL,*bearing_next_str=NULL,*turn_str=NULL;
382    
383 amb 316 /* Get the properties of this segment */
384    
385 amb 605 if(IsFakeSegment(result->segment))
386 amb 633 {
387 amb 605 resultsegment=LookupFakeSegment(result->segment);
388 amb 695 realsegment=IndexRealSegment(result->segment);
389 amb 633 }
390 amb 459 else
391 amb 633 {
392 amb 605 resultsegment=LookupSegment(segments,result->segment,3);
393 amb 695 realsegment=result->segment;
394 amb 633 }
395 amb 460 resultway=LookupWay(ways,resultsegment->way,1);
396 amb 316
397 amb 459 seg_distance+=DISTANCE(resultsegment->distance);
398     seg_duration+=Duration(resultsegment,resultway,profile);
399 amb 316 junc_distance+=seg_distance;
400     junc_duration+=seg_duration;
401     cum_distance+=seg_distance;
402     cum_duration+=seg_duration;
403    
404     /* Decide if this is an important junction */
405    
406 amb 680 if(result->node==results[point]->finish_node) /* Waypoint */
407 amb 316 important=10;
408 amb 695 else if(realsegment==nextrealsegment) /* U-turn */
409 amb 678 important=5;
410 amb 316 else
411 amb 303 {
412 amb 316 Segment *segment=FirstSegment(segments,nodes,result->node);
413 amb 160
414 amb 316 do
415     {
416     index_t othernode=OtherNode(segment,result->node);
417 amb 303
418 amb 695 if(othernode!=result->prev->node && IndexSegment(segments,segment)!=realsegment)
419 amb 316 if(IsNormalSegment(segment) && (!profile->oneway || !IsOnewayTo(segment,result->node)))
420 amb 303 {
421 amb 460 Way *way=LookupWay(ways,segment->way,2);
422 amb 316
423 amb 695 if(othernode==nextresult->node) /* the next segment that we follow */
424 amb 316 {
425     if(HIGHWAY(way->type)!=HIGHWAY(resultway->type))
426     if(important<2)
427     important=2;
428     }
429 amb 695 else if(IsFakeNode(nextresult->node))
430 amb 633 ;
431 amb 316 else /* a segment that we don't follow */
432     {
433     if(junction_other_way[HIGHWAY(resultway->type)-1][HIGHWAY(way->type)-1])
434     if(important<3)
435     important=3;
436    
437     if(important<1)
438     important=1;
439     }
440 amb 303 }
441 amb 160
442 amb 316 segment=NextSegment(segments,segment,result->node);
443     }
444     while(segment);
445 amb 303 }
446 amb 169
447 amb 316 /* Print out the important points (junctions / waypoints) */
448 amb 169
449 amb 332 if(important>1)
450 amb 177 {
451 amb 332 /* Print the intermediate finish points (because they have correct junction distances) */
452 amb 303
453 amb 378 if(htmlfile)
454     {
455     char *type;
456    
457     if(important==10)
458     type=translate_html_waypoint;
459     else
460     type=translate_html_junction;
461    
462 amb 411 if(!waynameraw)
463     {
464 amb 474 waynameraw=WayName(ways,resultway);
465 amb 411 if(!*waynameraw)
466     waynameraw=translate_highway[HIGHWAY(resultway->type)];
467     }
468    
469 amb 378 if(!waynamexml)
470 amb 411 waynamexml=ParseXML_Encode_Safe_XML(waynameraw);
471 amb 378
472     fprintf(htmlfile,"<tr class='s'><td class='l'>%s:<td class='r'>",translate_html_segment[0]);
473     fprintf(htmlfile,translate_html_segment[1],
474     waynamexml,
475     distance_to_km(junc_distance),duration_to_minutes(junc_duration));
476 amb 379 fprintf(htmlfile," [<span class='j'>");
477 amb 378 fprintf(htmlfile,translate_html_total[1],
478     distance_to_km(cum_distance),duration_to_minutes(cum_duration));
479     fprintf(htmlfile,"</span>]\n");
480    
481 amb 683 fprintf(htmlfile,"<tr class='c'><td class='l'>%d:<td class='r'>%.6f %.6f\n",
482     ++point_count,
483 amb 378 radians_to_degrees(latitude),radians_to_degrees(longitude));
484    
485     if(nextresult)
486     {
487     if(!turn_str)
488     {
489 amb 672 turn_int=(int)TurnAngle(nodes,resultsegment,nextresultsegment,result->node);
490 amb 684 turn_str=translate_turn[((202+turn_int)/45)%8];
491 amb 378 }
492    
493     if(!bearing_next_str)
494     {
495 amb 672 bearing_next_int=(int)BearingAngle(nodes,nextresultsegment,nextresult->node);
496 amb 378 bearing_next_str=translate_heading[(4+(22+bearing_next_int)/45)%8];
497     }
498    
499     fprintf(htmlfile,"<tr class='n'><td class='l'>%s:<td class='r'>",translate_html_node[0]);
500     fprintf(htmlfile,translate_html_node[1],
501     type,
502     turn_str,
503     bearing_next_str);
504     fprintf(htmlfile,"\n");
505     }
506     else
507     {
508     fprintf(htmlfile,"<tr class='n'><td class='l'>%s:<td class='r'>",translate_html_stop[0]);
509     fprintf(htmlfile,translate_html_stop[1],
510     translate_html_waypoint);
511     fprintf(htmlfile,"\n");
512     fprintf(htmlfile,"<tr class='t'><td class='l'>%s:<td class='r'><span class='j'>",translate_html_total[0]);
513     fprintf(htmlfile,translate_html_total[1],
514     distance_to_km(cum_distance),duration_to_minutes(cum_duration));
515     fprintf(htmlfile,"</span>\n");
516     }
517     }
518    
519 amb 177 if(gpxroutefile)
520 amb 332 {
521 amb 411 if(!waynameraw)
522     {
523 amb 474 waynameraw=WayName(ways,resultway);
524 amb 411 if(!*waynameraw)
525     waynameraw=translate_highway[HIGHWAY(resultway->type)];
526     }
527    
528 amb 378 if(!waynamexml)
529 amb 411 waynamexml=ParseXML_Encode_Safe_XML(waynameraw);
530 amb 378
531     if(!bearing_str)
532     {
533 amb 672 bearing_int=(int)BearingAngle(nodes,resultsegment,result->node);
534 amb 378 bearing_str=translate_heading[(4+(22+bearing_int)/45)%8];
535     }
536    
537     fprintf(gpxroutefile,"<desc>");
538 amb 360 fprintf(gpxroutefile,translate_gpx_step,
539 amb 378 bearing_str,
540     waynamexml,
541     distance_to_km(junc_distance),duration_to_minutes(junc_duration));
542     fprintf(gpxroutefile,"</desc></rtept>\n");
543 amb 316
544 amb 332 if(!nextresult)
545     {
546 amb 360 fprintf(gpxroutefile,"<rtept lat=\"%.6f\" lon=\"%.6f\"><name>%s</name>\n",
547 amb 378 radians_to_degrees(finish_lat),radians_to_degrees(finish_lon),
548     translate_gpx_finish);
549     fprintf(gpxroutefile,"<desc>");
550 amb 360 fprintf(gpxroutefile,translate_gpx_final,
551 amb 378 distance_to_km(cum_distance),duration_to_minutes(cum_duration));
552     fprintf(gpxroutefile,"</desc></rtept>\n");
553 amb 332 }
554     else if(important==10)
555 amb 360 fprintf(gpxroutefile,"<rtept lat=\"%.6f\" lon=\"%.6f\"><name>%s%d</name>\n",
556 amb 378 radians_to_degrees(latitude),radians_to_degrees(longitude),
557     translate_gpx_inter,++segment_count);
558 amb 332 else
559 amb 360 fprintf(gpxroutefile,"<rtept lat=\"%.6f\" lon=\"%.6f\"><name>%s%03d</name>\n",
560 amb 378 radians_to_degrees(latitude),radians_to_degrees(longitude),
561     translate_gpx_trip,++route_count);
562 amb 332 }
563 amb 316
564 amb 378 if(textfile)
565 amb 322 {
566     char *type;
567 amb 316
568 amb 322 if(important==10)
569 amb 378 type="Waypt";
570 amb 322 else
571 amb 378 type="Junct";
572 amb 316
573 amb 378 if(!wayname)
574 amb 474 {
575     wayname=WayName(ways,resultway);
576     if(!*wayname)
577     wayname=HighwayName(HIGHWAY(resultway->type));
578     }
579 amb 322
580     if(nextresult)
581 amb 369 {
582 amb 378 if(!turn_str)
583     {
584 amb 672 turn_int=(int)TurnAngle(nodes,resultsegment,nextresultsegment,result->node);
585 amb 684 turn_str=translate_turn[((202+turn_int)/45)%8];
586 amb 378 }
587 amb 322
588 amb 378 if(!bearing_next_str)
589     {
590 amb 672 bearing_next_int=(int)BearingAngle(nodes,nextresultsegment,nextresult->node);
591 amb 378 bearing_next_str=translate_heading[(4+(22+bearing_next_int)/45)%8];
592     }
593 amb 322
594 amb 316 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",
595 amb 378 radians_to_degrees(latitude),radians_to_degrees(longitude),
596     distance_to_km(junc_distance),duration_to_minutes(junc_duration),
597     distance_to_km(cum_distance),duration_to_minutes(cum_duration),
598     type,
599     (22+turn_int)/45,
600     ((22+bearing_next_int)/45+4)%8-4,
601     wayname);
602     }
603 amb 316 else
604     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",
605 amb 378 radians_to_degrees(latitude),radians_to_degrees(longitude),
606     distance_to_km(junc_distance),duration_to_minutes(junc_duration),
607     distance_to_km(cum_distance),duration_to_minutes(cum_duration),
608     type,
609     wayname);
610 amb 316 }
611    
612     junc_distance=0;
613     junc_duration=0;
614 amb 165 }
615 amb 160
616 amb 316 /* Print out all of the results */
617 amb 303
618 amb 316 if(textallfile)
619     {
620     char *type;
621    
622     if(important==10)
623     type="Waypt";
624     else if(important==2)
625     type="Change";
626     else if(important>=1)
627     type="Junct";
628     else
629     type="Inter";
630    
631 amb 378 if(!wayname)
632 amb 474 {
633     wayname=WayName(ways,resultway);
634     if(!*wayname)
635     wayname=HighwayName(HIGHWAY(resultway->type));
636     }
637 amb 378
638     if(!bearing_str)
639     {
640 amb 672 bearing_int=(int)BearingAngle(nodes,resultsegment,result->node);
641 amb 378 bearing_str=translate_heading[(4+(22+bearing_int)/45)%8];
642     }
643    
644 amb 316 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",
645 amb 378 radians_to_degrees(latitude),radians_to_degrees(longitude),
646 amb 471 IsFakeNode(result->node)?(NODE_FAKE-result->node):result->node,
647 amb 598 (!IsFakeNode(result->node) && IsSuperNode(LookupNode(nodes,result->node,1)))?'*':' ',type,
648 amb 378 distance_to_km(seg_distance),duration_to_minutes(seg_duration),
649     distance_to_km(cum_distance),duration_to_minutes(cum_duration),
650     profile->speed[HIGHWAY(resultway->type)],
651     bearing_int,
652     wayname);
653 amb 316 }
654 amb 378
655 amb 411 if(waynamexml && waynamexml!=waynameraw)
656 amb 378 free(waynamexml);
657 amb 160 }
658 amb 316 else if(!cum_distance)
659     {
660 amb 672 int bearing_next_int=(int)BearingAngle(nodes,nextresultsegment,nextresult->node);
661 amb 378 char *bearing_next_str=translate_heading[(4+(22+bearing_next_int)/45)%8];
662    
663 amb 316 /* Print out the very first start point */
664 amb 160
665 amb 323 if(htmlfile)
666 amb 369 {
667 amb 683 fprintf(htmlfile,"<tr class='c'><td class='l'>%d:<td class='r'>%.6f %.6f\n",
668     ++point_count,
669 amb 378 radians_to_degrees(latitude),radians_to_degrees(longitude));
670     fprintf(htmlfile,"<tr class='n'><td class='l'>%s:<td class='r'>",translate_html_start[0]);
671     fprintf(htmlfile,translate_html_start[1],
672     translate_html_waypoint,
673     bearing_next_str);
674     fprintf(htmlfile,"\n");
675 amb 369 }
676 amb 323
677 amb 316 if(gpxroutefile)
678 amb 360 fprintf(gpxroutefile,"<rtept lat=\"%.6f\" lon=\"%.6f\"><name>%s</name>\n",
679 amb 378 radians_to_degrees(latitude),radians_to_degrees(longitude),
680     translate_gpx_start);
681 amb 171
682 amb 316 if(textfile)
683     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",
684 amb 378 radians_to_degrees(latitude),radians_to_degrees(longitude),
685     0.0,0.0,0.0,0.0,
686     "Waypt",
687     (22+bearing_next_int)/45);
688 amb 171
689 amb 316 if(textallfile)
690     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",
691 amb 378 radians_to_degrees(latitude),radians_to_degrees(longitude),
692 amb 471 IsFakeNode(result->node)?(NODE_FAKE-result->node):result->node,
693 amb 598 (!IsFakeNode(result->node) && IsSuperNode(LookupNode(nodes,result->node,1)))?'*':' ',"Waypt",
694 amb 378 0.0,0.0,0.0,0.0);
695 amb 316 }
696 amb 160
697 amb 316 result=nextresult;
698 amb 160 }
699 amb 316 while(point==nextpoint);
700 amb 171
701 amb 316 if(gpxtrackfile)
702     fprintf(gpxtrackfile,"</trkseg>\n");
703 amb 160
704 amb 316 point=nextpoint;
705 amb 160 }
706    
707 amb 164 /* Print the tail of the files */
708    
709 amb 323 if(htmlfile)
710     {
711     fprintf(htmlfile,"</table>\n");
712 amb 376
713     if((translate_copyright_creator[0] && translate_copyright_creator[1]) ||
714     (translate_copyright_source[0] && translate_copyright_source[1]) ||
715     (translate_copyright_license[0] && translate_copyright_license[1]))
716     {
717     fprintf(htmlfile,"<p>\n");
718     fprintf(htmlfile,"<table class='c'>\n");
719     if(translate_copyright_creator[0] && translate_copyright_creator[1])
720 amb 378 fprintf(htmlfile,"<tr><td class='l'>%s:<td class='r'>%s\n",translate_copyright_creator[0],translate_copyright_creator[1]);
721 amb 376 if(translate_copyright_source[0] && translate_copyright_source[1])
722 amb 378 fprintf(htmlfile,"<tr><td class='l'>%s:<td class='r'>%s\n",translate_copyright_source[0],translate_copyright_source[1]);
723 amb 376 if(translate_copyright_license[0] && translate_copyright_license[1])
724 amb 378 fprintf(htmlfile,"<tr><td class='l'>%s:<td class='r'>%s\n",translate_copyright_license[0],translate_copyright_license[1]);
725 amb 376 fprintf(htmlfile,"</table>\n");
726     }
727    
728 amb 323 fprintf(htmlfile,"</BODY>\n");
729     fprintf(htmlfile,"</HTML>\n");
730     }
731    
732 amb 177 if(gpxtrackfile)
733     {
734     fprintf(gpxtrackfile,"</trk>\n");
735     fprintf(gpxtrackfile,"</gpx>\n");
736     }
737 amb 160
738 amb 177 if(gpxroutefile)
739     {
740     fprintf(gpxroutefile,"</rte>\n");
741     fprintf(gpxroutefile,"</gpx>\n");
742     }
743 amb 160
744 amb 164 /* Close the files */
745    
746 amb 323 if(htmlfile)
747     fclose(htmlfile);
748 amb 177 if(gpxtrackfile)
749     fclose(gpxtrackfile);
750     if(gpxroutefile)
751     fclose(gpxroutefile);
752     if(textfile)
753     fclose(textfile);
754     if(textallfile)
755     fclose(textallfile);
756 amb 160 }

Properties

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