Routino SVN Repository Browser

Check out the latest version of Routino: svn co http://routino.org/svn/trunk routino

ViewVC logotype

Contents of /trunk/extras/find-fixme/fixme-finder.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1598 - (show annotations) (download) (as text)
Sat Sep 27 16:35:09 2014 UTC (10 years, 5 months ago) by amb
File MIME type: text/x-csrc
File size: 10298 byte(s)
Add a '--logmemory' option to planetsplitter which will report the maximum
memory in use (allocated and mapped files) during each step of the processing.

1 /***************************************
2 OSM planet file fixme finder.
3
4 Part of the Routino routing software.
5 ******************/ /******************
6 This file Copyright 2008-2014 Andrew M. Bishop
7
8 This program is free software: you can redistribute it and/or modify
9 it under the terms of the GNU Affero General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU Affero General Public License for more details.
17
18 You should have received a copy of the GNU Affero General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 ***************************************/
21
22
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <unistd.h>
26 #include <string.h>
27 #include <errno.h>
28
29 #include "types.h"
30 #include "ways.h"
31
32 #include "typesx.h"
33 #include "nodesx.h"
34 #include "waysx.h"
35 #include "relationsx.h"
36
37 #include "files.h"
38 #include "logging.h"
39 #include "errorlogx.h"
40 #include "functions.h"
41 #include "osmparser.h"
42 #include "tagging.h"
43 #include "uncompress.h"
44
45
46 /* Global variables */
47
48 /*+ The name of the temporary directory. +*/
49 char *option_tmpdirname=NULL;
50
51 /*+ The amount of RAM to use for filesorting. +*/
52 size_t option_filesort_ramsize=0;
53
54 /*+ The number of threads to use for filesorting. +*/
55 int option_filesort_threads=1;
56
57
58 /* Local functions */
59
60 static void print_usage(int detail,const char *argerr,const char *err);
61
62
63 /*++++++++++++++++++++++++++++++++++++++
64 The main program for the find-fixme.
65 ++++++++++++++++++++++++++++++++++++++*/
66
67 int main(int argc,char** argv)
68 {
69 NodesX *OSMNodes;
70 WaysX *OSMWays;
71 RelationsX *OSMRelations;
72 ErrorLogsX *OSMErrorLogs;
73 char *dirname=NULL,*prefix=NULL,*tagging="fixme.xml",*errorlog="fixme.log";
74 int option_keep=1;
75 int option_filenames=0;
76 int arg;
77
78 printf_program_start();
79
80 /* Parse the command line arguments */
81
82 for(arg=1;arg<argc;arg++)
83 {
84 if(!strcmp(argv[arg],"--help"))
85 print_usage(1,NULL,NULL);
86 else if(!strncmp(argv[arg],"--dir=",6))
87 dirname=&argv[arg][6];
88 else if(!strncmp(argv[arg],"--sort-ram-size=",16))
89 option_filesort_ramsize=atoi(&argv[arg][16]);
90 #if defined(USE_PTHREADS) && USE_PTHREADS
91 else if(!strncmp(argv[arg],"--sort-threads=",15))
92 option_filesort_threads=atoi(&argv[arg][15]);
93 #endif
94 else if(!strncmp(argv[arg],"--tmpdir=",9))
95 option_tmpdirname=&argv[arg][9];
96 else if(!strncmp(argv[arg],"--tagging=",10))
97 tagging=&argv[arg][10];
98 else if(!strcmp(argv[arg],"--loggable"))
99 option_loggable=1;
100 else if(!strcmp(argv[arg],"--logtime"))
101 option_logtime=1;
102 else if(!strcmp(argv[arg],"--logmemory"))
103 option_logmemory=1;
104 else if(argv[arg][0]=='-' && argv[arg][1]=='-')
105 print_usage(0,argv[arg],NULL);
106 else
107 option_filenames++;
108 }
109
110 /* Check the specified command line options */
111
112 if(!option_filesort_ramsize)
113 {
114 #if SLIM
115 option_filesort_ramsize=64*1024*1024;
116 #else
117 option_filesort_ramsize=256*1024*1024;
118 #endif
119 }
120 else
121 option_filesort_ramsize*=1024*1024;
122
123 if(!option_tmpdirname)
124 {
125 if(!dirname)
126 option_tmpdirname=".";
127 else
128 option_tmpdirname=dirname;
129 }
130
131 if(tagging)
132 {
133 if(!ExistsFile(tagging))
134 {
135 fprintf(stderr,"Error: The '--tagging' option specifies a file that does not exist.\n");
136 exit(EXIT_FAILURE);
137 }
138 }
139 else
140 {
141 if(ExistsFile(FileName(dirname,prefix,"tagging.xml")))
142 tagging=FileName(dirname,prefix,"tagging.xml");
143 else
144 {
145 fprintf(stderr,"Error: The '--tagging' option was not used and the default 'tagging.xml' does not exist.\n");
146 exit(EXIT_FAILURE);
147 }
148 }
149
150 if(ParseXMLTaggingRules(tagging))
151 {
152 fprintf(stderr,"Error: Cannot read the tagging rules in the file '%s'.\n",tagging);
153 exit(EXIT_FAILURE);
154 }
155
156 /* Create new node, segment, way and relation variables */
157
158 OSMNodes=NewNodeList(0,0);
159
160 OSMWays=NewWayList(0,0);
161
162 OSMRelations=NewRelationList(0,0);
163
164 /* Create the error log file */
165
166 if(errorlog)
167 open_errorlog(FileName(dirname,prefix,errorlog),0,option_keep);
168
169 /* Parse the file */
170
171 for(arg=1;arg<argc;arg++)
172 {
173 int fd;
174 char *filename,*p;
175
176 if(argv[arg][0]=='-' && argv[arg][1]=='-')
177 continue;
178
179 filename=strcpy(malloc(strlen(argv[arg])+1),argv[arg]);
180
181 fd=OpenFile(filename);
182
183 if((p=strstr(filename,".bz2")) && !strcmp(p,".bz2"))
184 {
185 fd=Uncompress_Bzip2(fd);
186 *p=0;
187 }
188
189 if((p=strstr(filename,".gz")) && !strcmp(p,".gz"))
190 {
191 fd=Uncompress_Gzip(fd);
192 *p=0;
193 }
194
195 if((p=strstr(filename,".xz")) && !strcmp(p,".xz"))
196 {
197 fd=Uncompress_Xz(fd);
198 *p=0;
199 }
200
201 printf("\nParse OSM Data [%s]\n==============\n\n",filename);
202 fflush(stdout);
203
204 if((p=strstr(filename,".pbf")) && !strcmp(p,".pbf"))
205 {
206 if(ParsePBFFile(fd,OSMNodes,OSMWays,OSMRelations))
207 exit(EXIT_FAILURE);
208 }
209 else if((p=strstr(filename,".o5m")) && !strcmp(p,".o5m"))
210 {
211 if(ParseO5MFile(fd,OSMNodes,OSMWays,OSMRelations))
212 exit(EXIT_FAILURE);
213 }
214 else
215 {
216 if(ParseOSMFile(fd,OSMNodes,OSMWays,OSMRelations))
217 exit(EXIT_FAILURE);
218 }
219
220 CloseFile(fd);
221
222 free(filename);
223 }
224
225 DeleteXMLTaggingRules();
226
227 FinishNodeList(OSMNodes);
228 FinishWayList(OSMWays);
229 FinishRelationList(OSMRelations);
230
231 /* Sort the data */
232
233 printf("\nSort OSM Data\n=============\n\n");
234 fflush(stdout);
235
236 /* Sort the nodes, ways and relations */
237
238 SortNodeList(OSMNodes);
239
240 SortWayList(OSMWays);
241
242 SortRelationList(OSMRelations);
243
244 /* Process the data */
245
246 RenameFile(OSMNodes->filename_tmp,OSMNodes->filename);
247 RenameFile(OSMWays->filename_tmp,OSMWays->filename);
248 RenameFile(OSMRelations->rrfilename_tmp,OSMRelations->rrfilename);
249 RenameFile(OSMRelations->trfilename_tmp,OSMRelations->trfilename);
250
251 close_errorlog();
252
253 printf("\nCreate Error Log\n================\n\n");
254 fflush(stdout);
255
256 OSMErrorLogs=NewErrorLogList();
257
258 ProcessErrorLogs(OSMErrorLogs,OSMNodes,OSMWays,OSMRelations);
259
260 SortErrorLogsGeographically(OSMErrorLogs);
261
262 SaveErrorLogs(OSMErrorLogs,FileName(dirname,prefix,"fixme.mem"));
263
264 FreeErrorLogList(OSMErrorLogs);
265
266 /* Free the memory (delete the temporary files) */
267
268 FreeNodeList(OSMNodes,0);
269 FreeWayList(OSMWays,0);
270 FreeRelationList(OSMRelations,0);
271
272 printf_program_end();
273
274 return(0);
275 }
276
277
278 /*++++++++++++++++++++++++++++++++++++++
279 Print out the usage information.
280
281 int detail The level of detail to use - 0 = low, 1 = high.
282
283 const char *argerr The argument that gave the error (if there is one).
284
285 const char *err Other error message (if there is one).
286 ++++++++++++++++++++++++++++++++++++++*/
287
288 static void print_usage(int detail,const char *argerr,const char *err)
289 {
290 fprintf(stderr,
291 "Usage: fixme-finder [--help]\n"
292 " [--dir=<dirname>]\n"
293 #if defined(USE_PTHREADS) && USE_PTHREADS
294 " [--sort-ram-size=<size>] [--sort-threads=<number>]\n"
295 #else
296 " [--sort-ram-size=<size>]\n"
297 #endif
298 " [--tmpdir=<dirname>]\n"
299 " [--tagging=<filename>]\n"
300 " [--loggable] [--logtime] [--logmemory]\n"
301 " [<filename.osm> ...\n"
302 " | <filename.pbf> ...\n"
303 " | <filename.o5m> ..."
304 #if defined(USE_BZIP2) && USE_BZIP2
305 "\n | <filename.(osm|o5m).bz2> ..."
306 #endif
307 #if defined(USE_GZIP) && USE_GZIP
308 "\n | <filename.(osm|o5m).gz> ..."
309 #endif
310 #if defined(USE_XZ) && USE_XZ
311 "\n | <filename.(osm|o5m).xz> ..."
312 #endif
313 "]\n");
314
315 if(argerr)
316 fprintf(stderr,
317 "\n"
318 "Error with command line parameter: %s\n",argerr);
319
320 if(err)
321 fprintf(stderr,
322 "\n"
323 "Error: %s\n",err);
324
325 if(detail)
326 fprintf(stderr,
327 "\n"
328 "--help Prints this information.\n"
329 "\n"
330 "--dir=<dirname> The directory containing the fixme database.\n"
331 "\n"
332 "--sort-ram-size=<size> The amount of RAM (in MB) to use for data sorting\n"
333 #if SLIM
334 " (defaults to 64MB otherwise.)\n"
335 #else
336 " (defaults to 256MB otherwise.)\n"
337 #endif
338 #if defined(USE_PTHREADS) && USE_PTHREADS
339 "--sort-threads=<number> The number of threads to use for data sorting.\n"
340 #endif
341 "\n"
342 "--tmpdir=<dirname> The directory name for temporary files.\n"
343 " (defaults to the '--dir' option directory.)\n"
344 "\n"
345 "--tagging=<filename> The name of the XML file containing the tagging rules\n"
346 " (defaults to 'fixme.xml' with '--dir' option)\n"
347 "\n"
348 "--loggable Print progress messages suitable for logging to file.\n"
349 "--logtime Print the elapsed time for each processing step.\n"
350 "--logmemory Print the max allocated/mapped memory for each step.\n"
351 "\n"
352 "<filename.osm>, <filename.pbf>, <filename.o5m>\n"
353 " The name(s) of the file(s) to read and parse.\n"
354 " Filenames ending '.pbf' read as PBF, filenames ending\n"
355 " '.o5m' read as O5M, others as XML.\n"
356 #if defined(USE_BZIP2) && USE_BZIP2
357 " Filenames ending '.bz2' will be bzip2 uncompressed.\n"
358 #endif
359 #if defined(USE_GZIP) && USE_GZIP
360 " Filenames ending '.gz' will be gzip uncompressed.\n"
361 #endif
362 #if defined(USE_XZ) && USE_XZ
363 " Filenames ending '.xz' will be xz uncompressed.\n"
364 #endif
365 );
366
367 exit(!detail);
368 }