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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 329 - (show annotations) (download) (as text)
Sat Mar 20 12:23:39 2010 UTC (15 years ago) by amb
File MIME type: text/x-csrc
File size: 14137 byte(s)
Don't check the return value of the functions to load the nodes, segments and
ways because those functions will exit in case of an error.

1 /***************************************
2 $Header: /home/amb/CVS/routino/src/filedumper.c,v 1.38 2010-03-20 12:23:39 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 - Note: No error checking because Load*List() will call exit() in case of an error. */
125
126 OSMNodes=LoadNodeList(nodes_filename=FileName(dirname,prefix,"nodes.mem"));
127
128 OSMSegments=LoadSegmentList(segments_filename=FileName(dirname,prefix,"segments.mem"));
129
130 OSMWays=LoadWayList(ways_filename=FileName(dirname,prefix,"ways.mem"));
131
132 /* Write out the visualiser data */
133
134 if(option_visualiser)
135 {
136 if(coordcount!=4)
137 {
138 fprintf(stderr,"The --visualiser option must have --latmin, --latmax, --lonmin, --lonmax.\n");
139 exit(1);
140 }
141
142 if(!option_data)
143 {
144 fprintf(stderr,"The --visualiser option must have --data.\n");
145 exit(1);
146 }
147
148 if(!strcmp(option_data,"junctions"))
149 OutputJunctions(OSMNodes,OSMSegments,OSMWays,latmin,latmax,lonmin,lonmax);
150 else if(!strcmp(option_data,"super"))
151 OutputSuper(OSMNodes,OSMSegments,OSMWays,latmin,latmax,lonmin,lonmax);
152 else if(!strcmp(option_data,"oneway"))
153 OutputOneway(OSMNodes,OSMSegments,OSMWays,latmin,latmax,lonmin,lonmax);
154 else if(!strcmp(option_data,"speed"))
155 OutputSpeedLimits(OSMNodes,OSMSegments,OSMWays,latmin,latmax,lonmin,lonmax);
156 else if(!strcmp(option_data,"weight"))
157 OutputWeightLimits(OSMNodes,OSMSegments,OSMWays,latmin,latmax,lonmin,lonmax);
158 else if(!strcmp(option_data,"height"))
159 OutputHeightLimits(OSMNodes,OSMSegments,OSMWays,latmin,latmax,lonmin,lonmax);
160 else if(!strcmp(option_data,"width"))
161 OutputWidthLimits(OSMNodes,OSMSegments,OSMWays,latmin,latmax,lonmin,lonmax);
162 else if(!strcmp(option_data,"length"))
163 OutputLengthLimits(OSMNodes,OSMSegments,OSMWays,latmin,latmax,lonmin,lonmax);
164 else
165 {
166 fprintf(stderr,"Unrecognised data option '%s' with --visualiser.\n",option_data);
167 exit(1);
168 }
169 }
170
171 /* Print out statistics */
172
173 if(option_statistics)
174 {
175 struct stat buf;
176
177 /* Examine the files */
178
179 printf("Files\n");
180 printf("-----\n");
181 printf("\n");
182
183 stat(nodes_filename,&buf);
184
185 printf("'%s%snodes.mem' - %9ld Bytes\n",prefix?prefix:"",prefix?"-":"",buf.st_size);
186 printf("%s\n",RFC822Date(buf.st_mtime));
187 printf("\n");
188
189 stat(segments_filename,&buf);
190
191 printf("'%s%ssegments.mem' - %9ld Bytes\n",prefix?prefix:"",prefix?"-":"",buf.st_size);
192 printf("%s\n",RFC822Date(buf.st_mtime));
193 printf("\n");
194
195 stat(ways_filename,&buf);
196
197 printf("'%s%sways.mem' - %9ld Bytes\n",prefix?prefix:"",prefix?"-":"",buf.st_size);
198 printf("%s\n",RFC822Date(buf.st_mtime));
199 printf("\n");
200
201 /* Examine the nodes */
202
203 printf("Nodes\n");
204 printf("-----\n");
205 printf("\n");
206
207 printf("sizeof(Node) =%9d Bytes\n",sizeof(Node));
208 printf("Number =%9d\n",OSMNodes->number);
209 printf("Number(super)=%9d\n",OSMNodes->snumber);
210 printf("\n");
211
212 printf("Lat bins= %4d\n",OSMNodes->latbins);
213 printf("Lon bins= %4d\n",OSMNodes->lonbins);
214 printf("\n");
215
216 printf("Lat zero=%5d (%8.4f deg)\n",OSMNodes->latzero,radians_to_degrees(latlong_to_radians(bin_to_latlong(OSMNodes->latzero))));
217 printf("Lon zero=%5d (%8.4f deg)\n",OSMNodes->lonzero,radians_to_degrees(latlong_to_radians(bin_to_latlong(OSMNodes->lonzero))));
218
219 /* Examine the segments */
220
221 printf("\n");
222 printf("Segments\n");
223 printf("--------\n");
224 printf("\n");
225
226 printf("sizeof(Segment)=%9d Bytes\n",sizeof(Segment));
227 printf("Number(total) =%9d\n",OSMSegments->number);
228 printf("Number(super) =%9d\n",OSMSegments->snumber);
229 printf("Number(normal) =%9d\n",OSMSegments->nnumber);
230
231 /* Examine the ways */
232
233 printf("\n");
234 printf("Ways\n");
235 printf("----\n");
236 printf("\n");
237
238 printf("sizeof(Way) =%9d Bytes\n",sizeof(Way));
239 printf("Number(compacted)=%9d\n",OSMWays->number);
240 printf("Number(original) =%9d\n",OSMWays->onumber);
241 printf("\n");
242
243 printf("Total names =%9ld Bytes\n",buf.st_size-sizeof(Ways)-OSMWays->number*sizeof(Way));
244 printf("\n");
245
246 printf("Included transports: %s\n",AllowedNameList(OSMWays->allow));
247 printf("Included properties: %s\n",PropertiesNameList(OSMWays->props));
248 }
249
250 /* Print out internal data */
251
252 if(option_dump)
253 {
254 index_t item;
255
256 for(arg=1;arg<argc;arg++)
257 if(!strcmp(argv[arg],"--node=all"))
258 {
259 for(item=0;item<OSMNodes->number;item++)
260 print_node(OSMNodes,item);
261 }
262 else if(!strncmp(argv[arg],"--node=",7))
263 {
264 item=atoi(&argv[arg][7]);
265
266 if(item>=0 && item<OSMNodes->number)
267 print_node(OSMNodes,item);
268 else
269 printf("Invalid node number; minimum=0, maximum=%d.\n",OSMNodes->number-1);
270 }
271 else if(!strcmp(argv[arg],"--segment=all"))
272 {
273 for(item=0;item<OSMSegments->number;item++)
274 print_segment(OSMSegments,item);
275 }
276 else if(!strncmp(argv[arg],"--segment=",10))
277 {
278 item=atoi(&argv[arg][10]);
279
280 if(item>=0 && item<OSMSegments->number)
281 print_segment(OSMSegments,item);
282 else
283 printf("Invalid segment number; minimum=0, maximum=%d.\n",OSMSegments->number-1);
284 }
285 else if(!strcmp(argv[arg],"--way=all"))
286 {
287 for(item=0;item<OSMWays->number;item++)
288 print_way(OSMWays,item);
289 }
290 else if(!strncmp(argv[arg],"--way=",6))
291 {
292 item=atoi(&argv[arg][6]);
293
294 if(item>=0 && item<OSMWays->number)
295 print_way(OSMWays,item);
296 else
297 printf("Invalid way number; minimum=0, maximum=%d.\n",OSMWays->number-1);
298 }
299 }
300
301 return(0);
302 }
303
304
305 /*++++++++++++++++++++++++++++++++++++++
306 Print out the contents of a node from the routing database.
307
308 Nodes *nodes The set of nodes to use.
309
310 index_t item The node index to print.
311 ++++++++++++++++++++++++++++++++++++++*/
312
313 static void print_node(Nodes* nodes,index_t item)
314 {
315 Node *node=LookupNode(nodes,item);
316 double latitude,longitude;
317
318 GetLatLong(nodes,item,&latitude,&longitude);
319
320 printf("Node %d\n",item);
321 printf(" firstseg=%d\n",SEGMENT(node->firstseg));
322 printf(" latoffset=%d lonoffset=%d (latitude=%.6f longitude=%.6f)\n",node->latoffset,node->lonoffset,radians_to_degrees(latitude),radians_to_degrees(longitude));
323 if(IsSuperNode(nodes,item))
324 printf(" Super-Node\n");
325 }
326
327
328 /*++++++++++++++++++++++++++++++++++++++
329 Print out the contents of a segment from the routing database.
330
331 Segments *segments The set of segments to use.
332
333 index_t item The segment index to print.
334 ++++++++++++++++++++++++++++++++++++++*/
335
336 static void print_segment(Segments *segments,index_t item)
337 {
338 Segment *segment=LookupSegment(segments,item);
339
340 printf("Segment %d\n",item);
341 printf(" node1=%d node2=%d\n",segment->node1,segment->node2);
342 printf(" next2=%d\n",segment->next2);
343 printf(" way=%d\n",segment->way);
344 printf(" distance=%d (%.3f km)\n",DISTANCE(segment->distance),distance_to_km(DISTANCE(segment->distance)));
345 if(IsSuperSegment(segment) && IsNormalSegment(segment))
346 printf(" Super-Segment AND normal Segment\n");
347 else if(IsSuperSegment(segment) && !IsNormalSegment(segment))
348 printf(" Super-Segment\n");
349 if(IsOnewayTo(segment,segment->node1))
350 printf(" One-Way from node2 to node1\n");
351 if(IsOnewayTo(segment,segment->node2))
352 printf(" One-Way from node1 to node2\n");
353 }
354
355
356 /*++++++++++++++++++++++++++++++++++++++
357 Print out the contents of a way from the routing database.
358
359 Ways *ways The set of ways to use.
360
361 index_t item The way index to print.
362 ++++++++++++++++++++++++++++++++++++++*/
363
364 static void print_way(Ways *ways,index_t item)
365 {
366 Way *way=LookupWay(ways,item);
367
368 printf("Way %d\n",item);
369 printf(" name=%s\n",WayName(ways,way));
370 printf(" type=%02x (%s%s%s)\n",way->type,HighwayName(HIGHWAY(way->type)),way->type&Way_OneWay?",One-Way":"",way->type&Way_Roundabout?",Roundabout":"");
371 printf(" allow=%02x (%s)\n",way->allow,AllowedNameList(way->allow));
372 if(way->props)
373 printf(" props=%02x (%s)\n",way->props,PropertiesNameList(way->props));
374 if(way->speed)
375 printf(" speed=%d (%d km/hr)\n",way->speed,speed_to_kph(way->speed));
376 if(way->weight)
377 printf(" weight=%d (%.1f tonnes)\n",way->weight,weight_to_tonnes(way->weight));
378 if(way->height)
379 printf(" height=%d (%.1f m)\n",way->height,height_to_metres(way->height));
380 if(way->width)
381 printf(" width=%d (%.1f m)\n",way->width,width_to_metres(way->width));
382 if(way->length)
383 printf(" length=%d (%.1f m)\n",way->length,length_to_metres(way->length));
384 }
385
386
387 /*+ Conversion from time_t to date string and back (day of week). +*/
388 static const char* const weekdays[7]={"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};
389
390 /*+ Conversion from time_t to date string and back (month of year). +*/
391 static const char* const months[12]={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
392
393
394 /*++++++++++++++++++++++++++++++++++++++
395 Convert the time into an RFC 822 compliant date.
396
397 char *RFC822Date Returns a pointer to a fixed string containing the date.
398
399 time_t t The time.
400 ++++++++++++++++++++++++++++++++++++++*/
401
402 static char *RFC822Date(time_t t)
403 {
404 static char value[32];
405 char weekday[4];
406 char month[4];
407 struct tm *tim;
408
409 tim=gmtime(&t);
410
411 strcpy(weekday,weekdays[tim->tm_wday]);
412 strcpy(month,months[tim->tm_mon]);
413
414 /* Sun, 06 Nov 1994 08:49:37 GMT ; RFC 822, updated by RFC 1123 */
415
416 sprintf(value,"%3s, %02d %3s %4d %02d:%02d:%02d %s",
417 weekday,
418 tim->tm_mday,
419 month,
420 tim->tm_year+1900,
421 tim->tm_hour,
422 tim->tm_min,
423 tim->tm_sec,
424 "GMT"
425 );
426
427 return(value);
428 }

Properties

Name Value
cvs:description Test program for mmap files.