Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Performance 用fortran将数据块插入到一个大文件中_Performance_Fortran - Fatal编程技术网

Performance 用fortran将数据块插入到一个大文件中

Performance 用fortran将数据块插入到一个大文件中,performance,fortran,Performance,Fortran,我有一些海量(460万行)数据文件,我正试图用fortran编辑它们。基本上,贯穿整个文件的是一系列标题,后面是一个数字表。类似这样的内容: p he4 blah 99 ggg 1.0e+01 2.0e+01 2.0e+01 2.0e+015.0e+012.0e+01 . . 3.2e+-12.0e+01 1.0e+00 p he3 blafoo 99 ggg 1.1e+00 2.3e+01 2.0e+01 我的任务是将一个文件中的某些条目替换为另一个文件中的条目。该清单单独提供 我已经写了一个

我有一些海量(460万行)数据文件,我正试图用fortran编辑它们。基本上,贯穿整个文件的是一系列标题,后面是一个数字表。类似这样的内容:
p he4 blah 99 ggg
1.0e+01 2.0e+01 2.0e+01
2.0e+015.0e+012.0e+01
.
.
3.2e+-12.0e+01 1.0e+00
p he3 blafoo 99 ggg
1.1e+00 2.3e+01 2.0e+01

我的任务是将一个文件中的某些条目替换为另一个文件中的条目。该清单单独提供

我已经写了一个代码,已经可以工作了。我的策略是只读取并回显第一个文件,直到找到与替换列表匹配的头。然后在第二个文件中找到相同的头,回显条目。最后,切换回回回第一个文件。这种方法唯一的问题是速度太慢了!我查看了文件的直接访问,但它们没有固定的记录长度。有人有更好的主意吗

为帮助干杯,
Rich

文件中的标题是否以任何方式排序?如果没有,那么在第二个文件中创建头的索引文件应该会加快第一次查找。我的fortran非常生疏,但是如果您可以将第二个文件中的标题按照完整条目的位置排序到索引文件中,您应该能够显著加快速度?

我假设您正在读取文件1,并将结果写入文件3。 文件2包含替换项

Preprocess file 2, by loading each header, and using a hash algorithm to create 
an array with and integer hash representation of each header value in it, and a
pointer/subscript to the values to replace it by.

while there are lines left in file 1

    read an original line from file 1
    hash the original line to get the hash value.

    if the hash value is in the hash array
         write the replacement to file 3
    else
         write the original line to file 3

这应该能奏效

嗯,很有趣。不能期望对标题进行排序。但是建立一个索引是可行的。但是,有没有办法跳到文件中的某一行?我仍然需要逐行阅读和倒带,除非有某种“seekg”,对吗?对不起,我已经25年没用fortran了。不过,我原以为Fortran会在某个地方具有随机文件访问功能。无论如何,我原以为在第二个文件中有一个简单的标题排序列表将有助于加快速度,因为您可以扫描文件,直到找到(或不找到)第一个文件中的标题,然后从下一个标题开始。这意味着您不需要每次扫描整个第二个文件。我发现这可能对您有所帮助。这是针对Fortran 2003的。我无法使用链接中建议的方法,因为我已格式化了文件。但是,您是对的,我可以通过不不断地重新读取第二个文件来加快速度。我没有标题列表,但我能够将整个内容缩减为一个循环,而不是一个双读循环。你说的echo是什么意思?