问题描述
我想读这是从Fortran程序生成的二进制文件。我越来越奇怪的字符在我的输出,会不会是既Fortran和C有不同的字节序?
I'm trying to read a binary file which was generated from a fortran program. I'm getting strange characters in my output, could it be that both fortran and C have different endianess?
推荐答案
您应该使用
acces="stream"
和未格式化。这是后C I / O直接仿照所以不应该有了解它的任何问题。它为二○○三年的Fortran的一部分,所有的现代编译AFAIK实现它。
and not unformatted. It is directly modelled after C I/O so there should not be any problems understanding it. It is part of Fortran 2003 and all modern compilers implement it AFAIK (even the less advanced like Open64 or NEC).
Fortran和C两者都使用同一台机器上相同的字节顺序,除非你使用特殊的编译器功能。平台之间传送文件时,它可以是有问题的。
Both Fortran and C use the same endianness on the same machine, unless you use special compiler features. It can be problematic when transfering files between platforms.
如果使用Fortran程序
If the Fortran program used
access="sequential", form="unformatted"
您将有创纪录的分隔符的问题。
you will have problems with record delimiters.
文件写成
access="direct", form="unformatted"
可能是确定。
这篇关于从FORTRAN写出一个二进制文件,并用C阅读的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!