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/filedumper.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 298 - (hide annotations) (download) (as text)
Mon Nov 2 19:32:06 2009 UTC (15 years, 4 months ago) by amb
File MIME type: text/x-csrc
File size: 13797 byte(s)
Added the ability to set routing preferences using highway properties.
Initially the only choice is either paved or unpaved but the code has been
updated to allow any number of properties to be added.

1 amb 2 /***************************************
2 amb 298 $Header: /home/amb/CVS/routino/src/filedumper.c,v 1.34 2009-11-02 19:32:06 amb Exp $
3 amb 2
4     Memory file dumper.
5 amb 151
6     Part of the Routino routing software.
7 amb 2 ******************/ /******************
8 amb 151 This file Copyright 2008,2009 Andrew M. Bishop
9 amb 2
10 amb 151 This program is free software: you can redistribute it and/or modify
11     it under the terms of the GNU Affero General Public License as published by
12     the Free Software Foundation, either version 3 of the License, or
13     (at your option) any later version.
14    
15     This program is distributed in the hope that it will be useful,
16     but WITHOUT ANY WARRANTY; without even the implied warranty of
17     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18     GNU Affero General Public License for more details.
19    
20     You should have received a copy of the GNU Affero General Public License
21     along with this program. If not, see <http://www.gnu.org/licenses/>.
22 amb 2 ***************************************/
23    
24    
25     #include <stdio.h>
26     #include <stdlib.h>
27 amb 107 #include <string.h>
28 amb 185 #include <sys/stat.h>
29     #include <sys/time.h>
30     #include <time.h>
31 amb 2
32 amb 97 #include "types.h"
33 amb 162 #include "functions.h"
34 amb 185 #include "visualiser.h"
35 amb 97 #include "nodes.h"
36     #include "segments.h"
37     #include "ways.h"
38 amb 2
39 amb 185 /* Local functions */
40 amb 2
41 amb 185 static char *RFC822Date(time_t t);
42    
43 amb 202 static void print_node(Nodes* nodes,index_t item);
44     static void print_segment(Segments *segments,index_t item);
45     static void print_way(Ways *ways,index_t item);
46 amb 185
47 amb 2 int main(int argc,char** argv)
48     {
49 amb 26 Nodes *OSMNodes;
50 amb 66 Segments *OSMSegments;
51 amb 26 Ways *OSMWays;
52 amb 219 int arg;
53     char *dirname=NULL,*prefix=NULL;
54     char *nodes_filename,*segments_filename,*ways_filename;
55     int option_statistics=0;
56     int option_visualiser=0,coordcount=0;
57     double latmin=0,latmax=0,lonmin=0,lonmax=0;
58     char *option_data=NULL;
59     int option_dump=0;
60 amb 13
61 amb 107 /* Parse the command line arguments */
62    
63 amb 202 for(arg=1;arg<argc;arg++)
64 amb 107 {
65 amb 202 if(!strcmp(argv[arg],"--help"))
66 amb 107 goto usage;
67 amb 202 else if(!strncmp(argv[arg],"--dir=",6))
68     dirname=&argv[arg][6];
69     else if(!strncmp(argv[arg],"--prefix=",9))
70     prefix=&argv[arg][9];
71     else if(!strncmp(argv[arg],"--statistics",12))
72 amb 185 option_statistics=1;
73 amb 202 else if(!strncmp(argv[arg],"--visualiser",12))
74 amb 185 option_visualiser=1;
75 amb 202 else if(!strncmp(argv[arg],"--dump",6))
76     option_dump=1;
77     else if(!strncmp(argv[arg],"--latmin",8) && argv[arg][8]=='=')
78     {latmin=degrees_to_radians(atof(&argv[arg][9]));coordcount++;}
79     else if(!strncmp(argv[arg],"--latmax",8) && argv[arg][8]=='=')
80     {latmax=degrees_to_radians(atof(&argv[arg][9]));coordcount++;}
81     else if(!strncmp(argv[arg],"--lonmin",8) && argv[arg][8]=='=')
82     {lonmin=degrees_to_radians(atof(&argv[arg][9]));coordcount++;}
83     else if(!strncmp(argv[arg],"--lonmax",8) && argv[arg][8]=='=')
84     {lonmax=degrees_to_radians(atof(&argv[arg][9]));coordcount++;}
85     else if(!strncmp(argv[arg],"--data",6) && argv[arg][6]=='=')
86     option_data=&argv[arg][7];
87     else if(!strncmp(argv[arg],"--node=",7))
88     ;
89     else if(!strncmp(argv[arg],"--segment=",10))
90     ;
91     else if(!strncmp(argv[arg],"--way=",6))
92     ;
93 amb 107 else
94     {
95     usage:
96    
97     fprintf(stderr,"Usage: filedumper\n"
98     " [--help]\n"
99 amb 185 " [--dir=<name>] [--prefix=<name>]\n"
100     " [--statistics]\n"
101 amb 189 " [--visualiser --latmin=<latmin> --latmax=<latmax>\n"
102 amb 185 " --lonmin=<lonmin> --lonmax=<lonmax>\n"
103 amb 189 " --data=<data-type>]\n"
104 amb 202 " [--dump --node=<node> ...\n"
105     " --segment=<segment> ...\n"
106     " --way=<way> ...]\n"
107 amb 185 "\n"
108     "<data-type> can be selected from:\n"
109 amb 189 "junctions = segment count at each junction.\n"
110     "super = super-node and super-segments.\n"
111     "oneway = oneway segments.\n"
112     "speed = speed limits.\n"
113     "weight = weight limits.\n"
114     "height = height limits.\n"
115     "width = width limits.\n"
116     "length = length limits.\n");
117 amb 107
118     return(1);
119     }
120     }
121    
122 amb 202 if(!option_statistics && !option_visualiser && !option_dump)
123 amb 185 goto usage;
124 amb 2
125 amb 185 /* Load in the data */
126 amb 2
127 amb 185 OSMNodes=LoadNodeList(nodes_filename=FileName(dirname,prefix,"nodes.mem"));
128 amb 6
129 amb 185 if(!OSMNodes)
130     {
131     fprintf(stderr,"Cannot open nodes file '%s'.\n",nodes_filename);
132     return(1);
133     }
134 amb 2
135 amb 185 OSMSegments=LoadSegmentList(segments_filename=FileName(dirname,prefix,"segments.mem"));
136 amb 99
137 amb 185 if(!OSMSegments)
138     {
139     fprintf(stderr,"Cannot open segments file '%s'.\n",segments_filename);
140     return(1);
141     }
142 amb 99
143 amb 185 OSMWays=LoadWayList(ways_filename=FileName(dirname,prefix,"ways.mem"));
144 amb 66
145 amb 185 if(!OSMWays)
146     {
147     fprintf(stderr,"Cannot open ways file '%s'.\n",ways_filename);
148     return(1);
149     }
150 amb 66
151 amb 185 /* Write out the visualiser data */
152 amb 66
153 amb 185 if(option_visualiser)
154     {
155     if(coordcount!=4)
156     {
157     fprintf(stderr,"The --visualiser option must have --latmin, --latmax, --lonmin, --lonmax.\n");
158     exit(1);
159     }
160 amb 66
161 amb 185 if(!option_data)
162     {
163     fprintf(stderr,"The --visualiser option must have --data.\n");
164     exit(1);
165     }
166 amb 2
167 amb 185 if(!strcmp(option_data,"junctions"))
168     OutputJunctions(OSMNodes,OSMSegments,OSMWays,latmin,latmax,lonmin,lonmax);
169     else if(!strcmp(option_data,"super"))
170     OutputSuper(OSMNodes,OSMSegments,OSMWays,latmin,latmax,lonmin,lonmax);
171     else if(!strcmp(option_data,"oneway"))
172     OutputOneway(OSMNodes,OSMSegments,OSMWays,latmin,latmax,lonmin,lonmax);
173     else if(!strcmp(option_data,"speed"))
174     OutputSpeedLimits(OSMNodes,OSMSegments,OSMWays,latmin,latmax,lonmin,lonmax);
175     else if(!strcmp(option_data,"weight"))
176     OutputWeightLimits(OSMNodes,OSMSegments,OSMWays,latmin,latmax,lonmin,lonmax);
177     else if(!strcmp(option_data,"height"))
178     OutputHeightLimits(OSMNodes,OSMSegments,OSMWays,latmin,latmax,lonmin,lonmax);
179     else if(!strcmp(option_data,"width"))
180     OutputWidthLimits(OSMNodes,OSMSegments,OSMWays,latmin,latmax,lonmin,lonmax);
181     else if(!strcmp(option_data,"length"))
182     OutputLengthLimits(OSMNodes,OSMSegments,OSMWays,latmin,latmax,lonmin,lonmax);
183     else
184     {
185     fprintf(stderr,"Unrecognised data option '%s' with --visualiser.\n",option_data);
186     exit(1);
187     }
188     }
189 amb 6
190 amb 185 /* Print out statistics */
191 amb 6
192 amb 185 if(option_statistics)
193     {
194     struct stat buf;
195 amb 6
196 amb 185 /* Examine the files */
197    
198     printf("Files\n");
199     printf("-----\n");
200     printf("\n");
201    
202     stat(nodes_filename,&buf);
203    
204 amb 202 printf("'%s%snodes.mem' - %9ld Bytes\n",prefix?prefix:"",prefix?"-":"",buf.st_size);
205 amb 185 printf("%s\n",RFC822Date(buf.st_mtime));
206     printf("\n");
207    
208     stat(segments_filename,&buf);
209    
210 amb 202 printf("'%s%ssegments.mem' - %9ld Bytes\n",prefix?prefix:"",prefix?"-":"",buf.st_size);
211 amb 185 printf("%s\n",RFC822Date(buf.st_mtime));
212     printf("\n");
213    
214     stat(ways_filename,&buf);
215    
216 amb 202 printf("'%s%sways.mem' - %9ld Bytes\n",prefix?prefix:"",prefix?"-":"",buf.st_size);
217 amb 185 printf("%s\n",RFC822Date(buf.st_mtime));
218     printf("\n");
219    
220     /* Examine the nodes */
221    
222     printf("Nodes\n");
223     printf("-----\n");
224     printf("\n");
225    
226 amb 232 printf("sizeof(Node) =%9d Bytes\n",sizeof(Node));
227     printf("Number =%9d\n",OSMNodes->number);
228     printf("Number(super)=%9d\n",OSMNodes->snumber);
229 amb 185 printf("\n");
230    
231     printf("Lat bins= %4d\n",OSMNodes->latbins);
232     printf("Lon bins= %4d\n",OSMNodes->lonbins);
233     printf("\n");
234    
235 amb 223 printf("Lat zero=%5d (%8.4f deg)\n",OSMNodes->latzero,radians_to_degrees(latlong_to_radians(bin_to_latlong(OSMNodes->latzero))));
236     printf("Lon zero=%5d (%8.4f deg)\n",OSMNodes->lonzero,radians_to_degrees(latlong_to_radians(bin_to_latlong(OSMNodes->lonzero))));
237 amb 185
238     /* Examine the segments */
239    
240     printf("\n");
241     printf("Segments\n");
242     printf("--------\n");
243     printf("\n");
244    
245     printf("sizeof(Segment)=%9d Bytes\n",sizeof(Segment));
246 amb 232 printf("Number(total) =%9d\n",OSMSegments->number);
247     printf("Number(super) =%9d\n",OSMSegments->snumber);
248     printf("Number(normal) =%9d\n",OSMSegments->nnumber);
249 amb 185
250     /* Examine the ways */
251    
252     printf("\n");
253     printf("Ways\n");
254     printf("----\n");
255     printf("\n");
256    
257 amb 232 printf("sizeof(Way) =%9d Bytes\n",sizeof(Way));
258     printf("Number(compacted)=%9d\n",OSMWays->number);
259     printf("Number(original) =%9d\n",OSMWays->onumber);
260 amb 202 printf("\n");
261    
262     printf("Total names =%9ld Bytes\n",buf.st_size-sizeof(Ways)-OSMWays->number*sizeof(Way));
263 amb 185 }
264    
265 amb 202 /* Print out internal data */
266    
267     if(option_dump)
268     {
269     index_t item;
270    
271     for(arg=1;arg<argc;arg++)
272 amb 254 if(!strcmp(argv[arg],"--node=all"))
273 amb 202 {
274 amb 254 for(item=0;item<OSMNodes->number;item++)
275     print_node(OSMNodes,item);
276     }
277     else if(!strncmp(argv[arg],"--node=",7))
278     {
279 amb 202 item=atoi(&argv[arg][7]);
280    
281     print_node(OSMNodes,item);
282     }
283 amb 254 else if(!strcmp(argv[arg],"--segment=all"))
284     {
285     for(item=0;item<OSMSegments->number;item++)
286     print_segment(OSMSegments,item);
287     }
288 amb 202 else if(!strncmp(argv[arg],"--segment=",10))
289     {
290     item=atoi(&argv[arg][10]);
291    
292     print_segment(OSMSegments,item);
293     }
294 amb 254 else if(!strcmp(argv[arg],"--way=all"))
295     {
296     for(item=0;item<OSMWays->number;item++)
297     print_way(OSMWays,item);
298     }
299 amb 202 else if(!strncmp(argv[arg],"--way=",6))
300     {
301     item=atoi(&argv[arg][6]);
302    
303     print_way(OSMWays,item);
304     }
305     }
306    
307 amb 2 return(0);
308     }
309 amb 185
310    
311 amb 202 /*++++++++++++++++++++++++++++++++++++++
312     Print out the contents of a node from the routing database.
313    
314     Nodes *nodes The set of nodes to use.
315    
316     index_t item The node index to print.
317     ++++++++++++++++++++++++++++++++++++++*/
318    
319     static void print_node(Nodes* nodes,index_t item)
320     {
321     Node *node=LookupNode(nodes,item);
322 amb 219 double latitude,longitude;
323 amb 202
324     GetLatLong(nodes,item,&latitude,&longitude);
325    
326     printf("Node %d\n",item);
327 amb 235 printf(" firstseg=%d\n",SEGMENT(node->firstseg));
328 amb 227 printf(" latoffset=%d lonoffset=%d (latitude=%.6f longitude=%.6f)\n",node->latoffset,node->lonoffset,radians_to_degrees(latitude),radians_to_degrees(longitude));
329 amb 202 if(IsSuperNode(nodes,item))
330     printf(" Super-Node\n");
331     }
332    
333    
334     /*++++++++++++++++++++++++++++++++++++++
335     Print out the contents of a segment from the routing database.
336    
337     Segments *segments The set of segments to use.
338    
339     index_t item The segment index to print.
340     ++++++++++++++++++++++++++++++++++++++*/
341    
342     static void print_segment(Segments *segments,index_t item)
343     {
344     Segment *segment=LookupSegment(segments,item);
345    
346     printf("Segment %d\n",item);
347 amb 208 printf(" node1=%d node2=%d\n",segment->node1,segment->node2);
348 amb 202 printf(" next2=%d\n",segment->next2);
349     printf(" way=%d\n",segment->way);
350     printf(" distance=%d (%.3f km)\n",DISTANCE(segment->distance),distance_to_km(DISTANCE(segment->distance)));
351     if(IsSuperSegment(segment) && IsNormalSegment(segment))
352     printf(" Super-Segment AND normal Segment\n");
353     else if(IsSuperSegment(segment) && !IsNormalSegment(segment))
354     printf(" Super-Segment\n");
355     if(IsOnewayTo(segment,segment->node1))
356     printf(" One-Way from node2 to node1\n");
357     if(IsOnewayTo(segment,segment->node2))
358     printf(" One-Way from node1 to node2\n");
359     }
360    
361    
362     /*++++++++++++++++++++++++++++++++++++++
363     Print out the contents of a way from the routing database.
364    
365     Ways *ways The set of ways to use.
366    
367     index_t item The way index to print.
368     ++++++++++++++++++++++++++++++++++++++*/
369    
370     static void print_way(Ways *ways,index_t item)
371     {
372     Way *way=LookupWay(ways,item);
373    
374     printf("Way %d\n",item);
375     printf(" name=%s\n",WayName(ways,way));
376     printf(" type=%02x (%s%s%s)\n",way->type,HighwayName(HIGHWAY(way->type)),way->type&Way_OneWay?",One-Way":"",way->type&Way_Roundabout?",Roundabout":"");
377 amb 298 printf(" allow=%02x (%s)\n",way->allow,AllowedNameList(way->allow));
378     if(way->props)
379     printf(" props=%02x (%s)\n",way->props,PropertiesNameList(way->props));
380 amb 202 if(way->speed)
381     printf(" speed=%d (%d km/hr)\n",way->speed,speed_to_kph(way->speed));
382     if(way->weight)
383 amb 227 printf(" weight=%d (%.1f tonnes)\n",way->weight,weight_to_tonnes(way->weight));
384 amb 202 if(way->height)
385 amb 227 printf(" height=%d (%.1f m)\n",way->height,height_to_metres(way->height));
386 amb 202 if(way->width)
387 amb 227 printf(" width=%d (%.1f m)\n",way->width,width_to_metres(way->width));
388 amb 202 if(way->length)
389 amb 227 printf(" length=%d (%.1f m)\n",way->length,length_to_metres(way->length));
390 amb 202 }
391    
392    
393 amb 185 /*+ Conversion from time_t to date string and back (day of week). +*/
394     static const char* const weekdays[7]={"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};
395    
396     /*+ Conversion from time_t to date string and back (month of year). +*/
397     static const char* const months[12]={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
398    
399    
400     /*++++++++++++++++++++++++++++++++++++++
401     Convert the time into an RFC 822 compliant date.
402    
403     char *RFC822Date Returns a pointer to a fixed string containing the date.
404    
405     time_t t The time.
406     ++++++++++++++++++++++++++++++++++++++*/
407    
408     static char *RFC822Date(time_t t)
409     {
410     static char value[32];
411     char weekday[4];
412     char month[4];
413     struct tm *tim;
414    
415     tim=gmtime(&t);
416    
417     strcpy(weekday,weekdays[tim->tm_wday]);
418     strcpy(month,months[tim->tm_mon]);
419    
420     /* Sun, 06 Nov 1994 08:49:37 GMT ; RFC 822, updated by RFC 1123 */
421    
422     sprintf(value,"%3s, %02d %3s %4d %02d:%02d:%02d %s",
423     weekday,
424     tim->tm_mday,
425     month,
426     tim->tm_year+1900,
427     tim->tm_hour,
428     tim->tm_min,
429     tim->tm_sec,
430     "GMT"
431     );
432    
433     return(value);
434     }

Properties

Name Value
cvs:description Test program for mmap files.