【发布时间】:2020-06-24 08:52:44
【问题描述】:
我正在使用 Specfem3d 包。这个包将一些文件写入未格式化的 .bin 文件中。 还有另一个程序可以读取生成的文件。但是当我运行该代码来读取未格式化的二进制文件时,它会返回以下错误:
在文件 src/tomography/read_model.f90 的第 337 行(单位 = 40,文件 = 'topo/proc000012_external_mesh.bin') Fortran 运行时错误:I/O 超出未格式化文件的记录结尾
有一个 python 代码来检查文件。它会产生以下输出(可能是有用的信息):
scan type <q ( little endian 8 byte header) invalid header size 34359738368004 exceeds file size 82468068
scan type >q ( big endian 8 byte header) invalid header size 288230377227485184 exceeds file size 82468068
scan type <i ( little endian 4 byte header)
read record 1 size 4
read record 2 size 4
read record 3 size 4
read record 4 size 4000000
read record 5 size 2125764
read record 6 size 2125764
read record 7 size 2125764
read record 8 size 32000
read record 9 size 4
successfully read 69 records with unformatted fortran header type <i
scan type >i ( big endian 4 byte header) unmatched header
我该怎么办? :((
应该读取文件的部分代码是:
open(IIN,file='proc.bin',status='old',form='unformatted',iostat=ier)
nglob=531441
NGLLX=5
NGLLy=5
NGLLz=5
nspec=8000
read(IIN) ival
allocate(ibool(NGLLX,NGLLY,NGLLZ,NSPEC))
allocate(x(NGLOB),y(NGLOB),z(NGLOB))
read(IIN) ibool(:,:,:,1:nspec) !!!!error occurs in this line
print*,ibool
read(IIN) x(1:nglob)
read(IIN) y(1:nglob)
read(IIN) z(1:nglob)
close(IIN)
编辑: 原来的安全函数是here。
【问题讨论】:
-
从 python 输出看来,您应该首先读取 3 个整数(不仅仅是
ival?),然后是 1 个大数组(ibool?,正确的类型?),然后是 3 个大数组( x,y,x?)。