首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用fortran将数据块插入到一个大文件中

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

Stack Overflow用户
提问于 2010-10-06 22:16:34
回答 2查看 162关注 0票数 0

我有一些大量(460万行)的数据文件,我正试图用fortran编辑这些文件。基本上,整个文件都是一系列的标题,后面跟着一个数字表格。如下所示:

P he4 blah 99 ggg

1.0e+01 2.0e+01 2.0e+01

2.0e+01 5.0e+01 2.0e+01

3.2e+-1 2.0e+01 1.0e+00

P he3 blafoo 99 ggg

1.1e+00 2.3e+01 2.0e+01

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

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

为你的帮助干杯,瑞奇

EN

回答 2

Stack Overflow用户

发布于 2010-10-06 22:25:29

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

票数 0
EN

Stack Overflow用户

发布于 2010-10-07 00:22:39

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

代码语言:javascript
复制
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

这应该能起到作用。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3873430

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档