如何将数据写入TXT文件中的特定位置?
我想更改文本文件的一部分。文件内容如下:
PLANE
CV = 1.4, PRINT = 1
Ks = 3.17, G = 120.67, DIST = 0.34, POR = 0.456, ROCK = 0.3
PLANE
我想用随机数替换 ks=3.17
部分。更具体地说,文本文件是另一个可执行文件的输入,我想修改Ks值,运行可执行文件,再次修改Ks值,等等。
I want to change part of a text file. The file's contents follow:
PLANE
CV = 1.4, PRINT = 1
Ks = 3.17, G = 120.67, DIST = 0.34, POR = 0.456, ROCK = 0.3
PLANE
I want to replace the ks=3.17
part with a random number. More specifically, the text file is the input to another executable, and I want to modify the Ks value, run the executable, modify the Ks value again, and so on.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
可能有更好的方法可以做到这一点,但这是有效的。它写入一个新的输出文件,将 Ks 值更改为 9.99。
There are probably better ways of doing it, but this works. It writes a new output file changing the Ks value to 9.99.
您有充分的理由使用 Fortran 来完成这项任务吗?您在上一段中描述的任务可以使用其他语言轻松完成。例如,如果您编写如下所示的 python 脚本,
给定这样的示例 fortran 程序,
您将得到
Do you have strong reason to use fortran for this task? The task you described in the last paragraph may be accomplished with other languages with less hustle. For example if you write a python script like below,
Given sample fortran program like this,
You will get