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 208 - (show annotations) (download) (as text)
Mon Jun 29 17:39:20 2009 UTC (15 years, 9 months ago) by amb
File MIME type: text/x-csrc
File size: 12847 byte(s)
Move the super-segment and normal-segment flags from the nodes to the distance.
Remove the NODE() macro and rename SUPER_FLAG to NODE_SUPER.

1 /***************************************
2 $Header: /home/amb/CVS/routino/src/filedumper.c,v 1.26 2009-06-29 17:39:20 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 float 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("\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(bin_to_lat_long(OSMNodes->latzero)));
235 printf("Lon zero=%5d (%8.4f deg)\n",OSMNodes->lonzero,radians_to_degrees(bin_to_lat_long(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 =%9d\n",OSMSegments->number);
246
247 /* Examine the ways */
248
249 printf("\n");
250 printf("Ways\n");
251 printf("----\n");
252 printf("\n");
253
254 printf("sizeof(Way) =%9d Bytes\n",sizeof(Way));
255 printf("Number =%9d\n",OSMWays->number);
256 printf("\n");
257
258 printf("Total names =%9ld Bytes\n",buf.st_size-sizeof(Ways)-OSMWays->number*sizeof(Way));
259 }
260
261 /* Print out internal data */
262
263 if(option_dump)
264 {
265 index_t item;
266
267 for(arg=1;arg<argc;arg++)
268 if(!strncmp(argv[arg],"--node=",7))
269 {
270 item=atoi(&argv[arg][7]);
271
272 print_node(OSMNodes,item);
273 }
274 else if(!strncmp(argv[arg],"--segment=",10))
275 {
276 item=atoi(&argv[arg][10]);
277
278 print_segment(OSMSegments,item);
279 }
280 else if(!strncmp(argv[arg],"--way=",6))
281 {
282 item=atoi(&argv[arg][6]);
283
284 print_way(OSMWays,item);
285 }
286 }
287
288 return(0);
289 }
290
291
292 /*++++++++++++++++++++++++++++++++++++++
293 Print out the contents of a node from the routing database.
294
295 Nodes *nodes The set of nodes to use.
296
297 index_t item The node index to print.
298 ++++++++++++++++++++++++++++++++++++++*/
299
300 static void print_node(Nodes* nodes,index_t item)
301 {
302 Node *node=LookupNode(nodes,item);
303 float latitude,longitude;
304
305 GetLatLong(nodes,item,&latitude,&longitude);
306
307 printf("Node %d\n",item);
308 printf(" firstseg=%d\n",node->firstseg);
309 printf(" latoffset=%d lonoffset=%d (latitude=%.5f longitude=%.5f)\n",node->latoffset,node->lonoffset,latitude,longitude);
310 if(IsSuperNode(nodes,item))
311 printf(" Super-Node\n");
312 }
313
314
315 /*++++++++++++++++++++++++++++++++++++++
316 Print out the contents of a segment from the routing database.
317
318 Segments *segments The set of segments to use.
319
320 index_t item The segment index to print.
321 ++++++++++++++++++++++++++++++++++++++*/
322
323 static void print_segment(Segments *segments,index_t item)
324 {
325 Segment *segment=LookupSegment(segments,item);
326
327 printf("Segment %d\n",item);
328 printf(" node1=%d node2=%d\n",segment->node1,segment->node2);
329 printf(" next2=%d\n",segment->next2);
330 printf(" way=%d\n",segment->way);
331 printf(" distance=%d (%.3f km)\n",DISTANCE(segment->distance),distance_to_km(DISTANCE(segment->distance)));
332 if(IsSuperSegment(segment) && IsNormalSegment(segment))
333 printf(" Super-Segment AND normal Segment\n");
334 else if(IsSuperSegment(segment) && !IsNormalSegment(segment))
335 printf(" Super-Segment\n");
336 if(IsOnewayTo(segment,segment->node1))
337 printf(" One-Way from node2 to node1\n");
338 if(IsOnewayTo(segment,segment->node2))
339 printf(" One-Way from node1 to node2\n");
340 }
341
342
343 /*++++++++++++++++++++++++++++++++++++++
344 Print out the contents of a way from the routing database.
345
346 Ways *ways The set of ways to use.
347
348 index_t item The way index to print.
349 ++++++++++++++++++++++++++++++++++++++*/
350
351 static void print_way(Ways *ways,index_t item)
352 {
353 Way *way=LookupWay(ways,item);
354
355 printf("Way %d\n",item);
356 printf(" name=%s\n",WayName(ways,way));
357 printf(" type=%02x (%s%s%s)\n",way->type,HighwayName(HIGHWAY(way->type)),way->type&Way_OneWay?",One-Way":"",way->type&Way_Roundabout?",Roundabout":"");
358 printf(" allow=%02x\n",way->allow);
359 if(way->speed)
360 printf(" speed=%d (%d km/hr)\n",way->speed,speed_to_kph(way->speed));
361 if(way->weight)
362 printf(" weight=%d (%.0f tonnes)\n",way->weight,weight_to_tonnes(way->weight));
363 if(way->height)
364 printf(" height=%d (%.0f m)\n",way->height,height_to_metres(way->height));
365 if(way->width)
366 printf(" width=%d (%.0f m)\n",way->width,width_to_metres(way->width));
367 if(way->length)
368 printf(" length=%d (%.0f m)\n",way->length,length_to_metres(way->length));
369 }
370
371
372 /*+ Conversion from time_t to date string and back (day of week). +*/
373 static const char* const weekdays[7]={"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};
374
375 /*+ Conversion from time_t to date string and back (month of year). +*/
376 static const char* const months[12]={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
377
378
379 /*++++++++++++++++++++++++++++++++++++++
380 Convert the time into an RFC 822 compliant date.
381
382 char *RFC822Date Returns a pointer to a fixed string containing the date.
383
384 time_t t The time.
385 ++++++++++++++++++++++++++++++++++++++*/
386
387 static char *RFC822Date(time_t t)
388 {
389 static char value[32];
390 char weekday[4];
391 char month[4];
392 struct tm *tim;
393
394 tim=gmtime(&t);
395
396 strcpy(weekday,weekdays[tim->tm_wday]);
397 strcpy(month,months[tim->tm_mon]);
398
399 /* Sun, 06 Nov 1994 08:49:37 GMT ; RFC 822, updated by RFC 1123 */
400
401 sprintf(value,"%3s, %02d %3s %4d %02d:%02d:%02d %s",
402 weekday,
403 tim->tm_mday,
404 month,
405 tim->tm_year+1900,
406 tim->tm_hour,
407 tim->tm_min,
408 tim->tm_sec,
409 "GMT"
410 );
411
412 return(value);
413 }

Properties

Name Value
cvs:description Test program for mmap files.