stream
是的,您可以按照 IanH 的建议使用两种访问方式编写二进制文件,或者direct
访问:
integer :: reclen
real(kind=kind(0.0d0)),dimension(256,256,256) :: dense
inquire(iolength=reclen)dense ! Inquire record length of the array dense
open(unit=8,file='test.dat',& ! Binary file, direct access
form='unformatted',access='direct',recl=reclen)
write(unit=8,rec=1)dense ! Write array into first record
close(unit=8)
end
Unless you specify access
attribute in the open
statement, the file will be opened in sequential
mode, which may be inconvenient for reading because it adds a padding to each record which contains information about record length. By using direct
access, you are able to specify the record length explicitly, and in this case, the size of the file written will be exactly 8*256^3
, so assuming you know the array ordering and endianness, you are able to read it from your MATLAB script.