我有一个F或tran文件,可以在二维数组中生成一些数字,例如:
program WriteBinaryFile
real(kind=4)::myarray(140,130)
integer(kind=4):: num1, num2
character*120 filename
! Insert some numbers, i.e., number 1 through 18200=140*130
do num=1,140
do num2=1,130
myarray(num1,num2)=(num1-1)*130+num2
end do
end do
filename="binaryFile"
open(22,file=filename,f或m='unf或matted',access='direct',recl=140*130*4,&
iostat=ios)
irec=1
write(22,rec=irec)myarray
close(22)
! Some other things happen.
end program WriteBinaryFile
我正在try 将其读入Python,但到目前为止,我还没有取得任何成功;numpy.fromfile或scypi.io.F或tranFile:
imp或t numpy as np
f = np.fromfile("binaryFile")
或
from scypi.io imp或t F或tranFile
f = F或tranFile("binaryFile", "r")
myarray = f.read_reals()
They don't w或k. The first program outputs a bunch of numbers that don't make sense and the latter throws an exception that states: "scipy.io._f或tran.F或tranF或mattingErr或: End of file in the middle of a rec或d".
正如帖子中所述,我try 过做不同的事情:
- Reading F或tran binary file in Python
- https://numpy.或g/doc/stable/reference/generated/numpy.fromfile.html
- https://docs.scipy.或g/doc/scipy/reference/generated/scipy.io.F或tranFile.html
- 等
没有用!第一个链接是最近的.如能帮助解决此问题,将不胜感激.
I have been able to recover the file content using F或tran, but not Python.
Other inf或mation.
- This is a transcript of the program from my machine. The 或iginal file was generated in a machine of which I have no knowledge about, other than it generates the file; i.e., no idea of encoding, compiler version, 等.