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 185 - (hide annotations) (download) (as text)
Sun Jun 7 15:33:15 2009 UTC (15 years, 9 months ago) by amb
File MIME type: text/x-csrc
File size: 8915 byte(s)
Now used for data visualisation and statistics.

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

Properties

Name Value
cvs:description Test program for mmap files.