我有一个 dat 格式的代码输出。该文件具有以下格式
Text
Text
Text
Text
3241234234
234234
23423423
34123424
1324234
iteration pressure temperature density
1 1234 312 2.12
2 1235 321 2.15
3 1234 312 2.12
4 1235 321 2.15
5 1234 312 2.12
6 1235 321 2.15
pressure temperature density
7 1234 312 2.12
8 1235 321 2.15
9 1234 312 2.12
10 1235 321 2.15
11 1234 312 2.12
warning pressure update is not linked
12 1235 321 2.15
pressure temperature density
13 1234 312 2.12
14 1235 321 2.15
15 1234 312 2.12
warning pressure update is not linked
16 1235 321 2.15
17 1234 312 2.12
18 1235 321 2.15
end of iterations
simulation time
end loop
end of code
我编写了一个代码,在其中打开 dat 文件。使用 iostat 将其作为文本阅读。然后我跳过标题文本行和随机数等直到迭代行。然后读取数字(迭代压力温度密度)。但是我被困在需要帮助的几个地方。
开头的文本行不是恒定的。有时这些是 4 行,有时是 5 或 6 行。每次我都必须调整行数并重新编译。有没有办法自动化这个。我的意思是代码本身会计算文本行并跳过它们。下一个随机数也是如此。
我想要做的是从开始到迭代跳过这些行。但这些也在发生变化。仅读取数字数据
1 1234 312 2.12 2 1235 321 2.15 3 1234 312 2.12 4 1235 321 2.15 5 1234 312 2.12 6 1235 321 2.15 7 1234 312 2.12 8 1235 321 2.15 9 1234 312 2.12 10 1235 321 2.15 11 1234 312 2.12 12 1235 321 2.15 13 1234 312 2.12 14 1235 321 2.15 15 1234 312 2.12 16 1235 321 2.15 17 1234 312 2.12 18 1235 321 2.15
然后将此数据写入输出文件。