如何在 Fortran 90 中复制文件?
如何以可移植、跨平台的方式复制 Fortran 90 中的文件?
How can I copy a file in fortran 90 in a portable, cross plaform way ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
如何以可移植、跨平台的方式复制 Fortran 90 中的文件?
How can I copy a file in fortran 90 in a portable, cross plaform way ?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(6)
使用系统 使用操作系统的复制命令。几乎所有编译器都支持此功能。
Use the SYSTEM with your OS's copy command. Practically all compilers support this feature.
您可以在 Fortran 2003 中通过流读取/写入文件,但在 Fortran 90/95 中我认为这可以复制任意文件(虽然效率极低!!)
当然,如果它是 Fortran 生成的文件,您可以使用该信息可以提高效率。
就个人而言:如果您需要从 Fortran 内部调用系统调用,您在做什么?使用更适合该任务的其他语言不是更好吗?
You can read/write the file through a stream in Fortran 2003, but in Fortran 90/95 I think this would work to copy an arbitrary file (extremely inefficient though!!)
Of course, if it was a fortran generated file, you could use that information to make it more efficient.
On a personal note: if you need invoke system calls from inside fortran, what are you doing? Isn't it better to use some other language that is better suited for the task?
是的,Fortran 的 I/O 很差,如果可能的话,不应该用于此类事情。多么遗憾我们中的一些人被迫这样做。
我只是读取源文件并同时逐行写入目标。到目前为止,这对我有用,但效率很低。
对于 Fortran 来说,处理文件和可移植性很烦人,而且 SYSTEM 调用通常也不是很好。 Windows 操作系统不能正确遵循 linux 链接文件,并且 Windows/Linux/MacOS 有不同的分隔符,我遇到了 SYSTEM 调用中固有的堆栈限制,等等。
祝你好运 !
Yes, Fortran has pathetic I/O and shouldn't be used for this sort of thing if at all possible. What a shame that some of us are forced to do it.
I just read the source file and simultaneously write to the destination, line-by-line. So far this works for me, but is very inefficient.
Dealing with files and portability is annoying with Fortran, and SYSTEM calls are often not very good either. The windows OS doesn't properly follow linux linked files, and Windows/Linux/MacOS have different separaters, I have been caught out with stack limits inherent in the SYSTEM call, and so on.
Good luck !
对于英特尔 Fortran
For Intel Fortran
之前的答案对我不起作用,所以我编写了以下子例程
The previous answer didn't work for me so I wrote the following subroutine
!对于康柏/英特尔 Visual Fortran
! For Compaq/Intel Visual Fortran