Fortran未格式化的文件格式 [英] Fortran unformatted file format

查看:538
本文介绍了Fortran未格式化的文件格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



例如:

<$ p $
写入(3)矩阵(i,:)
打开(3,file = filename,form =unformatted,access =sequential $ c>

将矩阵的一列输出到文件中。我发现它在两端填充了4个字节的文件,但我不明白为什么,或者如何控制这种行为。有没有办法删除填充?



谢谢

解决方案

对于未格式化的IO,Fortran编译器通常在记录的开始和结尾处写入记录的长度。大多数但不是全部编译器使用四个字节。这有助于读取记录,例如最后的长度有助于退格操作。您可以使用Fortran 2003的新Stream IO模式来抑制这种情况,Fortran 2003是为了与其他语言兼容而添加的。在您的open语句中使用 access ='stream'


I don't understand the format of unformatted files in fortran.

For example:

open (3,file=filename,form="unformatted",access="sequential")
write(3) matrix(i,:)

outputs a column of a matrix into a file. I've discovered that it pads the file with 4 bytes on either end, however I don't really understand why, or how to control this behavior. Is there a way to remove the padding?

Thanks

解决方案

For unformated IO, Fortran compilers typically write the length of the record at the beginning and end of the record. Most but not all compilers use four bytes. This aids in reading records, e.g., length at the end assists with a backspace operation. You can suppress this with the new Stream IO mode of Fortran 2003, which was added for compatibility with other languages. Use access='stream' in your open statement.

这篇关于Fortran未格式化的文件格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆