0

我正在尝试制作一个转换程序,它将多个文本文件从 cad 设计文件转换为机器可以读取的文件。

每个文件都有多个值,布局如下:

X             -0.0001
Y              1.0500
Z              1.5700

LOCATION       0.0050

每个文件代表机器应该去并做某事的位置。输出需要看起来像这样:

X-0.0001Y1.0500Z1.5700L0.0050
Other information regarding position is here also.

所以这是一个相当简单的转换。但我想知道的是最好的方法是什么。我是否单独转换每个文件然后合并它们?其他信息必须放在文件的底部。所以哪里有更多的文件:

Location 1
Location 2
Location 1 parameters
location 2 parameters 

我尝试了几种不同的方法,但仍然无法找到最好的方法。

基本上我要问的是最好/最有效的方法是转换这些文件。对不起,如果这令人困惑。

注意我使用 vb.net 作为编程语言

4

1 回答 1

0

if this is a project of enormous scale (e.g. millions of files), you might want to look into something like map reduce.

if not (which I'm guessing), I would suggest as follows:

parse each file sequentially, adding (appending)the results to each of TWO files. Finally, combine the two files and you're done.

LOCATIONS_FILE (FILE 1)

Location 1
Location 2
(etc)

METADATA_FILE (FILE 2)

location 1 params
location 2 params
(etc)

when all files are parsed, append the contents of FILE 2 to those of FILE 1.

FINAL FILE

Location 1
Location 2
(etc)
location 1 params
location 2 params
(etc)

I don't use VB.NET. But, pseudocode would be something like:

fn parse_file(file,locations_filehandle, metadata_filehandle):
    file.extract_locations() -> append(locations_filehandle)
    file.extract_metadata() -> append(metadata_filehandle)

fn main():
   for file in files:
      parse_file(file,locations_filehandle,metadata_filehandle)

   finalfile=locations_filehandle.read() + metadata_filehandle.read()
   finalfile.writeToDisk()


main()
于 2013-04-23T20:05:58.043 回答