意外的“填充"在 Fortran 无格式文件中 [英] Unexpected "padding" in a Fortran unformatted file

查看:24
本文介绍了意外的“填充"在 Fortran 无格式文件中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不明白 Fortran 中无格式文件的格式.

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

例如:

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

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

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?

推荐答案

对于未格式化的 IO,Fortran 编译器通常会在记录的开头和结尾写入记录的长度.大多数但不是所有编译器都使用四个字节.这有助于阅读记录,例如末尾的长度有助于退格操作.您可以使用 Fortran 2003 的新 Stream IO 模式来抑制这种情况,该模式是为了与其他语言兼容而添加的.在您的公开声明中使用 access='stream'.

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天全站免登陆