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