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

查看:83
本文介绍了意外的“填充"在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天全站免登陆