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 198 - (hide annotations) (download) (as text)
Mon Jun 15 18:52:54 2009 UTC (15 years, 10 months ago) by amb
File MIME type: text/x-csrc
File size: 8830 byte(s)
Add a macro for converting degrees to radians and radians to degrees.

1 amb 2 /***************************************
2 amb 198 $Header: /home/amb/CVS/routino/src/filedumper.c,v 1.24 2009-06-15 18:52:54 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    
44 amb 2 int main(int argc,char** argv)
45     {
46 amb 26 Nodes *OSMNodes;
47 amb 66 Segments *OSMSegments;
48 amb 26 Ways *OSMWays;
49 amb 162 char *dirname=NULL,*prefix=NULL;
50 amb 185 char *nodes_filename,*segments_filename,*ways_filename;
51     int option_statistics=0;
52     int option_visualiser=0,coordcount=0;
53     float latmin=0,latmax=0,lonmin=0,lonmax=0;
54     char *option_data=NULL;
55 amb 13
56 amb 107 /* Parse the command line arguments */
57    
58     while(--argc>=1)
59     {
60     if(!strcmp(argv[argc],"--help"))
61     goto usage;
62     else if(!strncmp(argv[argc],"--dir=",6))
63     dirname=&argv[argc][6];
64     else if(!strncmp(argv[argc],"--prefix=",9))
65     prefix=&argv[argc][9];
66 amb 185 else if(!strncmp(argv[argc],"--statistics",12))
67     option_statistics=1;
68     else if(!strncmp(argv[argc],"--visualiser",12))
69     option_visualiser=1;
70     else if(!strncmp(argv[argc],"--latmin",8) && argv[argc][8]=='=')
71 amb 198 {latmin=degrees_to_radians(atof(&argv[argc][9]));coordcount++;}
72 amb 185 else if(!strncmp(argv[argc],"--latmax",8) && argv[argc][8]=='=')
73 amb 198 {latmax=degrees_to_radians(atof(&argv[argc][9]));coordcount++;}
74 amb 185 else if(!strncmp(argv[argc],"--lonmin",8) && argv[argc][8]=='=')
75 amb 198 {lonmin=degrees_to_radians(atof(&argv[argc][9]));coordcount++;}
76 amb 185 else if(!strncmp(argv[argc],"--lonmax",8) && argv[argc][8]=='=')
77 amb 198 {lonmax=degrees_to_radians(atof(&argv[argc][9]));coordcount++;}
78 amb 185 else if(!strncmp(argv[argc],"--data",6) && argv[argc][6]=='=')
79     option_data=&argv[argc][7];
80 amb 107 else
81     {
82     usage:
83    
84     fprintf(stderr,"Usage: filedumper\n"
85     " [--help]\n"
86 amb 185 " [--dir=<name>] [--prefix=<name>]\n"
87     " [--statistics]\n"
88 amb 189 " [--visualiser --latmin=<latmin> --latmax=<latmax>\n"
89 amb 185 " --lonmin=<lonmin> --lonmax=<lonmax>\n"
90 amb 189 " --data=<data-type>]\n"
91 amb 185 "\n"
92     "<data-type> can be selected from:\n"
93 amb 189 "junctions = segment count at each junction.\n"
94     "super = super-node and super-segments.\n"
95     "oneway = oneway segments.\n"
96     "speed = speed limits.\n"
97     "weight = weight limits.\n"
98     "height = height limits.\n"
99     "width = width limits.\n"
100     "length = length limits.\n");
101 amb 107
102     return(1);
103     }
104     }
105    
106 amb 185 if(!option_statistics && !option_visualiser)
107     goto usage;
108 amb 2
109 amb 185 /* Load in the data */
110 amb 2
111 amb 185 OSMNodes=LoadNodeList(nodes_filename=FileName(dirname,prefix,"nodes.mem"));
112 amb 6
113 amb 185 if(!OSMNodes)
114     {
115     fprintf(stderr,"Cannot open nodes file '%s'.\n",nodes_filename);
116     return(1);
117     }
118 amb 2
119 amb 185 OSMSegments=LoadSegmentList(segments_filename=FileName(dirname,prefix,"segments.mem"));
120 amb 99
121 amb 185 if(!OSMSegments)
122     {
123     fprintf(stderr,"Cannot open segments file '%s'.\n",segments_filename);
124     return(1);
125     }
126 amb 99
127 amb 185 OSMWays=LoadWayList(ways_filename=FileName(dirname,prefix,"ways.mem"));
128 amb 66
129 amb 185 if(!OSMWays)
130     {
131     fprintf(stderr,"Cannot open ways file '%s'.\n",ways_filename);
132     return(1);
133     }
134 amb 66
135 amb 185 /* Write out the visualiser data */
136 amb 66
137 amb 185 if(option_visualiser)
138     {
139     if(coordcount!=4)
140     {
141     fprintf(stderr,"The --visualiser option must have --latmin, --latmax, --lonmin, --lonmax.\n");
142     exit(1);
143     }
144 amb 66
145 amb 185 if(!option_data)
146     {
147     fprintf(stderr,"The --visualiser option must have --data.\n");
148     exit(1);
149     }
150 amb 2
151 amb 185 if(!strcmp(option_data,"junctions"))
152     OutputJunctions(OSMNodes,OSMSegments,OSMWays,latmin,latmax,lonmin,lonmax);
153     else if(!strcmp(option_data,"super"))
154     OutputSuper(OSMNodes,OSMSegments,OSMWays,latmin,latmax,lonmin,lonmax);
155     else if(!strcmp(option_data,"oneway"))
156     OutputOneway(OSMNodes,OSMSegments,OSMWays,latmin,latmax,lonmin,lonmax);
157     else if(!strcmp(option_data,"speed"))
158     OutputSpeedLimits(OSMNodes,OSMSegments,OSMWays,latmin,latmax,lonmin,lonmax);
159     else if(!strcmp(option_data,"weight"))
160     OutputWeightLimits(OSMNodes,OSMSegments,OSMWays,latmin,latmax,lonmin,lonmax);
161     else if(!strcmp(option_data,"height"))
162     OutputHeightLimits(OSMNodes,OSMSegments,OSMWays,latmin,latmax,lonmin,lonmax);
163     else if(!strcmp(option_data,"width"))
164     OutputWidthLimits(OSMNodes,OSMSegments,OSMWays,latmin,latmax,lonmin,lonmax);
165     else if(!strcmp(option_data,"length"))
166     OutputLengthLimits(OSMNodes,OSMSegments,OSMWays,latmin,latmax,lonmin,lonmax);
167     else
168     {
169     fprintf(stderr,"Unrecognised data option '%s' with --visualiser.\n",option_data);
170     exit(1);
171     }
172     }
173 amb 6
174 amb 185 /* Print out statistics */
175 amb 6
176 amb 185 if(option_statistics)
177     {
178     struct stat buf;
179 amb 6
180 amb 185 /* Examine the files */
181    
182     printf("Files\n");
183     printf("-----\n");
184     printf("\n");
185    
186     stat(nodes_filename,&buf);
187    
188     printf("'%s%snodes.mem' - %ld Bytes\n",prefix?prefix:"",prefix?"-":"",buf.st_size);
189     printf("%s\n",RFC822Date(buf.st_mtime));
190     printf("\n");
191    
192     stat(segments_filename,&buf);
193    
194     printf("'%s%ssegments.mem' - %ld Bytes\n",prefix?prefix:"",prefix?"-":"",buf.st_size);
195     printf("%s\n",RFC822Date(buf.st_mtime));
196     printf("\n");
197    
198     stat(ways_filename,&buf);
199    
200     printf("'%s%sways.mem' - %ld Bytes\n",prefix?prefix:"",prefix?"-":"",buf.st_size);
201     printf("%s\n",RFC822Date(buf.st_mtime));
202     printf("\n");
203    
204     /* Examine the nodes */
205    
206     printf("Nodes\n");
207     printf("-----\n");
208     printf("\n");
209    
210     printf("sizeof(Node)=%9d Bytes\n",sizeof(Node));
211     printf("number =%9d\n",OSMNodes->number);
212     printf("\n");
213    
214     printf("Lat bins= %4d\n",OSMNodes->latbins);
215     printf("Lon bins= %4d\n",OSMNodes->lonbins);
216     printf("\n");
217    
218 amb 198 printf("Lat zero=%5d (%8.4f deg)\n",OSMNodes->latzero,radians_to_degrees(bin_to_lat_long(OSMNodes->latzero)));
219     printf("Lon zero=%5d (%8.4f deg)\n",OSMNodes->lonzero,radians_to_degrees(bin_to_lat_long(OSMNodes->lonzero)));
220 amb 185
221     /* Examine the segments */
222    
223     printf("\n");
224     printf("Segments\n");
225     printf("--------\n");
226     printf("\n");
227    
228     printf("sizeof(Segment)=%9d Bytes\n",sizeof(Segment));
229     printf("number =%9d\n",OSMSegments->number);
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 =%9d\n",OSMWays->number);
240     }
241    
242 amb 2 return(0);
243     }
244 amb 185
245    
246     /*+ Conversion from time_t to date string and back (day of week). +*/
247     static const char* const weekdays[7]={"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};
248    
249     /*+ Conversion from time_t to date string and back (month of year). +*/
250     static const char* const months[12]={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
251    
252    
253     /*++++++++++++++++++++++++++++++++++++++
254     Convert the time into an RFC 822 compliant date.
255    
256     char *RFC822Date Returns a pointer to a fixed string containing the date.
257    
258     time_t t The time.
259     ++++++++++++++++++++++++++++++++++++++*/
260    
261     static char *RFC822Date(time_t t)
262     {
263     static char value[32];
264     char weekday[4];
265     char month[4];
266     struct tm *tim;
267    
268     tim=gmtime(&t);
269    
270     strcpy(weekday,weekdays[tim->tm_wday]);
271     strcpy(month,months[tim->tm_mon]);
272    
273     /* Sun, 06 Nov 1994 08:49:37 GMT ; RFC 822, updated by RFC 1123 */
274    
275     sprintf(value,"%3s, %02d %3s %4d %02d:%02d:%02d %s",
276     weekday,
277     tim->tm_mday,
278     month,
279     tim->tm_year+1900,
280     tim->tm_hour,
281     tim->tm_min,
282     tim->tm_sec,
283     "GMT"
284     );
285    
286     return(value);
287     }

Properties

Name Value
cvs:description Test program for mmap files.