在gnuplot上查看Fortran的二进制输出 [英] Looking at binary output from fortran on gnuplot

查看:318
本文介绍了在gnuplot上查看Fortran的二进制输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我用fortran创建了一个二进制文件,使用类似这样的内容:

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

按照我的理解,fortran在文件两端填充4个字节的文件,剩下的就是我想要的数据(在这种情况下,列表中有1000个双打)。 p>

我想用gnuplot读这个,但是,我不知道如何让gnuplot跳过第一个和最后4个字节,然后读取其余的双精度数据。文档在这方面并不是很有帮助。



谢谢 解决方案

p>使用gnuplot 5.0进行测试,以下fortran未格式化的数据写入大小 N 的双数组 x p>

  open(FID,file ='binaryfile')
do k = 1,N
write(FID) x(k)
end do
close(FID)

可以理解通过gnuplot与以下内容:

  plot'binaryfile'binary format =%* 1int%double%* 1int

%* 1int 表示,跳过四个字节整数,有效地跳过页眉和页脚数据fortran环绕输出。

有关更复杂数据的更多信息和外推,请参阅关于二进制文件的gnuplot 5.0文档,并查看格式大小, show datafile binary datasizes 。但是请注意,多列数据(即每写N次)可以使用与上面相同的格式进行访问,但是可以使用%Ndoubles 来访问,其中N是整数。然后以使用1:3 为例,可以将第一列与第三列作图。


So, I created a binary file with fortran, using something similar to this:

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

The way I understand it, fortran pads the file with 4 bytes on either end of the file, and the rest is just the data that I want (in this case, a list of 1000 doubles).

I want to read this in with gnuplot, however, I don't know how to get gnuplot to skip the first and last 4 bytes, and read the rest in as doubles. The documentation isn't very helpful in this regard.

Thanks

解决方案

Testing with gnuplot 5.0, the following fortran unformatted data write of a double array x of size N,

open(FID,file='binaryfile')
do k = 1, N
  write(FID) x(k)
end do 
close(FID)

can be understood by gnuplot with the following:

plot 'binaryfile' binary format="%*1int%double%*1int"

The %*1int means, skip once a four byte integer, effectively skipping the header and footer data fortran wraps around output.

For more information and extrapolation for more complicated data, see the gnuplot 5.0 docs on binary and see the size of the formats with, show datafile binary datasizes. Note however that multi-column data (i.e. N doubles per write) can be accessed with the same format as above but as %Ndoubles where N is an integer. Then with using 1:3 for example, one would plot the first column against the 3rd.

这篇关于在gnuplot上查看Fortran的二进制输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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