从FORTRAN写出一个二进制文件,并用C阅读 [英] Writing out a binary file from fortran and reading in C

查看:521
本文介绍了从FORTRAN写出一个二进制文件,并用C阅读的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想读这是从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阅读的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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