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 235 -
(show annotations)
(download)
(as text)
Sat Aug 15 14:18:05 2009 UTC (15 years, 7 months ago) by amb
File MIME type: text/x-csrc
File size: 13180 byte(s)
Sat Aug 15 14:18:05 2009 UTC (15 years, 7 months ago) by amb
File MIME type: text/x-csrc
File size: 13180 byte(s)
Fix dumping nodes when they are super-nodes.
1 | /*************************************** |
2 | $Header: /home/amb/CVS/routino/src/filedumper.c,v 1.32 2009-08-15 14:18:05 amb Exp $ |
3 | |
4 | Memory file dumper. |
5 | |
6 | Part of the Routino routing software. |
7 | ******************/ /****************** |
8 | This file Copyright 2008,2009 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\n" |
98 | " [--help]\n" |
99 | " [--dir=<name>] [--prefix=<name>]\n" |
100 | " [--statistics]\n" |
101 | " [--visualiser --latmin=<latmin> --latmax=<latmax>\n" |
102 | " --lonmin=<lonmin> --lonmax=<lonmax>\n" |
103 | " --data=<data-type>]\n" |
104 | " [--dump --node=<node> ...\n" |
105 | " --segment=<segment> ...\n" |
106 | " --way=<way> ...]\n" |
107 | "\n" |
108 | "<data-type> can be selected from:\n" |
109 | "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 | |
118 | return(1); |
119 | } |
120 | } |
121 | |
122 | if(!option_statistics && !option_visualiser && !option_dump) |
123 | goto usage; |
124 | |
125 | /* Load in the data */ |
126 | |
127 | OSMNodes=LoadNodeList(nodes_filename=FileName(dirname,prefix,"nodes.mem")); |
128 | |
129 | if(!OSMNodes) |
130 | { |
131 | fprintf(stderr,"Cannot open nodes file '%s'.\n",nodes_filename); |
132 | return(1); |
133 | } |
134 | |
135 | OSMSegments=LoadSegmentList(segments_filename=FileName(dirname,prefix,"segments.mem")); |
136 | |
137 | if(!OSMSegments) |
138 | { |
139 | fprintf(stderr,"Cannot open segments file '%s'.\n",segments_filename); |
140 | return(1); |
141 | } |
142 | |
143 | OSMWays=LoadWayList(ways_filename=FileName(dirname,prefix,"ways.mem")); |
144 | |
145 | if(!OSMWays) |
146 | { |
147 | fprintf(stderr,"Cannot open ways file '%s'.\n",ways_filename); |
148 | return(1); |
149 | } |
150 | |
151 | /* Write out the visualiser data */ |
152 | |
153 | 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 | |
161 | if(!option_data) |
162 | { |
163 | fprintf(stderr,"The --visualiser option must have --data.\n"); |
164 | exit(1); |
165 | } |
166 | |
167 | 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 | |
190 | /* Print out statistics */ |
191 | |
192 | if(option_statistics) |
193 | { |
194 | struct stat buf; |
195 | |
196 | /* Examine the files */ |
197 | |
198 | printf("Files\n"); |
199 | printf("-----\n"); |
200 | printf("\n"); |
201 | |
202 | stat(nodes_filename,&buf); |
203 | |
204 | printf("'%s%snodes.mem' - %9ld Bytes\n",prefix?prefix:"",prefix?"-":"",buf.st_size); |
205 | printf("%s\n",RFC822Date(buf.st_mtime)); |
206 | printf("\n"); |
207 | |
208 | stat(segments_filename,&buf); |
209 | |
210 | printf("'%s%ssegments.mem' - %9ld Bytes\n",prefix?prefix:"",prefix?"-":"",buf.st_size); |
211 | printf("%s\n",RFC822Date(buf.st_mtime)); |
212 | printf("\n"); |
213 | |
214 | stat(ways_filename,&buf); |
215 | |
216 | printf("'%s%sways.mem' - %9ld Bytes\n",prefix?prefix:"",prefix?"-":"",buf.st_size); |
217 | 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 | printf("sizeof(Node) =%9d Bytes\n",sizeof(Node)); |
227 | printf("Number =%9d\n",OSMNodes->number); |
228 | printf("Number(super)=%9d\n",OSMNodes->snumber); |
229 | printf("\n"); |
230 | |
231 | printf("Lat bins= %4d\n",OSMNodes->latbins); |
232 | printf("Lon bins= %4d\n",OSMNodes->lonbins); |
233 | printf("\n"); |
234 | |
235 | 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 | |
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 | printf("Number(total) =%9d\n",OSMSegments->number); |
247 | printf("Number(super) =%9d\n",OSMSegments->snumber); |
248 | printf("Number(normal) =%9d\n",OSMSegments->nnumber); |
249 | |
250 | /* Examine the ways */ |
251 | |
252 | printf("\n"); |
253 | printf("Ways\n"); |
254 | printf("----\n"); |
255 | printf("\n"); |
256 | |
257 | 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 | printf("\n"); |
261 | |
262 | printf("Total names =%9ld Bytes\n",buf.st_size-sizeof(Ways)-OSMWays->number*sizeof(Way)); |
263 | } |
264 | |
265 | /* Print out internal data */ |
266 | |
267 | if(option_dump) |
268 | { |
269 | index_t item; |
270 | |
271 | for(arg=1;arg<argc;arg++) |
272 | if(!strncmp(argv[arg],"--node=",7)) |
273 | { |
274 | item=atoi(&argv[arg][7]); |
275 | |
276 | print_node(OSMNodes,item); |
277 | } |
278 | else if(!strncmp(argv[arg],"--segment=",10)) |
279 | { |
280 | item=atoi(&argv[arg][10]); |
281 | |
282 | print_segment(OSMSegments,item); |
283 | } |
284 | else if(!strncmp(argv[arg],"--way=",6)) |
285 | { |
286 | item=atoi(&argv[arg][6]); |
287 | |
288 | print_way(OSMWays,item); |
289 | } |
290 | } |
291 | |
292 | return(0); |
293 | } |
294 | |
295 | |
296 | /*++++++++++++++++++++++++++++++++++++++ |
297 | Print out the contents of a node from the routing database. |
298 | |
299 | Nodes *nodes The set of nodes to use. |
300 | |
301 | index_t item The node index to print. |
302 | ++++++++++++++++++++++++++++++++++++++*/ |
303 | |
304 | static void print_node(Nodes* nodes,index_t item) |
305 | { |
306 | Node *node=LookupNode(nodes,item); |
307 | double latitude,longitude; |
308 | |
309 | GetLatLong(nodes,item,&latitude,&longitude); |
310 | |
311 | printf("Node %d\n",item); |
312 | printf(" firstseg=%d\n",SEGMENT(node->firstseg)); |
313 | printf(" latoffset=%d lonoffset=%d (latitude=%.6f longitude=%.6f)\n",node->latoffset,node->lonoffset,radians_to_degrees(latitude),radians_to_degrees(longitude)); |
314 | if(IsSuperNode(nodes,item)) |
315 | printf(" Super-Node\n"); |
316 | } |
317 | |
318 | |
319 | /*++++++++++++++++++++++++++++++++++++++ |
320 | Print out the contents of a segment from the routing database. |
321 | |
322 | Segments *segments The set of segments to use. |
323 | |
324 | index_t item The segment index to print. |
325 | ++++++++++++++++++++++++++++++++++++++*/ |
326 | |
327 | static void print_segment(Segments *segments,index_t item) |
328 | { |
329 | Segment *segment=LookupSegment(segments,item); |
330 | |
331 | printf("Segment %d\n",item); |
332 | printf(" node1=%d node2=%d\n",segment->node1,segment->node2); |
333 | printf(" next2=%d\n",segment->next2); |
334 | printf(" way=%d\n",segment->way); |
335 | printf(" distance=%d (%.3f km)\n",DISTANCE(segment->distance),distance_to_km(DISTANCE(segment->distance))); |
336 | if(IsSuperSegment(segment) && IsNormalSegment(segment)) |
337 | printf(" Super-Segment AND normal Segment\n"); |
338 | else if(IsSuperSegment(segment) && !IsNormalSegment(segment)) |
339 | printf(" Super-Segment\n"); |
340 | if(IsOnewayTo(segment,segment->node1)) |
341 | printf(" One-Way from node2 to node1\n"); |
342 | if(IsOnewayTo(segment,segment->node2)) |
343 | printf(" One-Way from node1 to node2\n"); |
344 | } |
345 | |
346 | |
347 | /*++++++++++++++++++++++++++++++++++++++ |
348 | Print out the contents of a way from the routing database. |
349 | |
350 | Ways *ways The set of ways to use. |
351 | |
352 | index_t item The way index to print. |
353 | ++++++++++++++++++++++++++++++++++++++*/ |
354 | |
355 | static void print_way(Ways *ways,index_t item) |
356 | { |
357 | Way *way=LookupWay(ways,item); |
358 | |
359 | printf("Way %d\n",item); |
360 | printf(" name=%s\n",WayName(ways,way)); |
361 | printf(" type=%02x (%s%s%s)\n",way->type,HighwayName(HIGHWAY(way->type)),way->type&Way_OneWay?",One-Way":"",way->type&Way_Roundabout?",Roundabout":""); |
362 | printf(" allow=%02x\n",way->allow); |
363 | if(way->speed) |
364 | printf(" speed=%d (%d km/hr)\n",way->speed,speed_to_kph(way->speed)); |
365 | if(way->weight) |
366 | printf(" weight=%d (%.1f tonnes)\n",way->weight,weight_to_tonnes(way->weight)); |
367 | if(way->height) |
368 | printf(" height=%d (%.1f m)\n",way->height,height_to_metres(way->height)); |
369 | if(way->width) |
370 | printf(" width=%d (%.1f m)\n",way->width,width_to_metres(way->width)); |
371 | if(way->length) |
372 | printf(" length=%d (%.1f m)\n",way->length,length_to_metres(way->length)); |
373 | } |
374 | |
375 | |
376 | /*+ Conversion from time_t to date string and back (day of week). +*/ |
377 | static const char* const weekdays[7]={"Sun","Mon","Tue","Wed","Thu","Fri","Sat"}; |
378 | |
379 | /*+ Conversion from time_t to date string and back (month of year). +*/ |
380 | static const char* const months[12]={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"}; |
381 | |
382 | |
383 | /*++++++++++++++++++++++++++++++++++++++ |
384 | Convert the time into an RFC 822 compliant date. |
385 | |
386 | char *RFC822Date Returns a pointer to a fixed string containing the date. |
387 | |
388 | time_t t The time. |
389 | ++++++++++++++++++++++++++++++++++++++*/ |
390 | |
391 | static char *RFC822Date(time_t t) |
392 | { |
393 | static char value[32]; |
394 | char weekday[4]; |
395 | char month[4]; |
396 | struct tm *tim; |
397 | |
398 | tim=gmtime(&t); |
399 | |
400 | strcpy(weekday,weekdays[tim->tm_wday]); |
401 | strcpy(month,months[tim->tm_mon]); |
402 | |
403 | /* Sun, 06 Nov 1994 08:49:37 GMT ; RFC 822, updated by RFC 1123 */ |
404 | |
405 | sprintf(value,"%3s, %02d %3s %4d %02d:%02d:%02d %s", |
406 | weekday, |
407 | tim->tm_mday, |
408 | month, |
409 | tim->tm_year+1900, |
410 | tim->tm_hour, |
411 | tim->tm_min, |
412 | tim->tm_sec, |
413 | "GMT" |
414 | ); |
415 | |
416 | return(value); |
417 | } |
Properties
Name | Value |
---|---|
cvs:description | Test program for mmap files. |