arrays - 将未格式化的数据附加到 Fortran 中的文件,然后读取它
问题描述
我希望能够将大型数组连续写入 Fortran 中的单个二进制文件。一个简单的例子如下:
program TEST_IO
implicit none
!Define float precision
integer, parameter :: dp = selected_real_kind(33,4931)
!Define array dimensions
integer(kind=dp) :: nrows = 1d4, ncols = 12
!Define write/read arrays
real(kind=dp), dimension(:,:), allocatable :: ArrayWrite, ArrayRead
!Allocate
allocate(ArrayWrite(nrows,ncols))
allocate(ArrayRead(2*nrows,ncols))
!Populate the array
ArrayWrite=1.0_dp
!Write to file
open(unit=10, file='example.dat' , form='unformatted')
write(10) ArrayWrite
close(10)
!Re-populate array
ArrayWrite=2.0_dp
!And append to existing file
open(unit=10, file='example.dat', form='unformatted',position='append')
write(10) ArrayWrite
close(10)
!Now read in all the data
open(unit=10, file='example.dat' , form='unformatted')
read(10) ArrayRead
close(10)
end program TEST_IO
由于我已经将一个大小数组写入(nrows,ncols)
文件两次,我想总写入文件的大小为(2*nrows,ncols)
. 事实上,从检查输出文件大小来看,这似乎是真的。
ArrayRead
但是,当我尝试将这些数据读回至
谁能提供一些关于我哪里出错的指导?谢谢。
解决方案
推荐阅读
- java - 是否有 Java 的调试/发布?
- javascript - 无法生成 NULL Javascript
- asp.net - ASP.NET 未捕获的 Sys.WebForms.PageRequestManagerParserErrorException
- database-design - 三个相关表的数据库表设计重构
- c++ - 拆分包含表情符号和拉丁字母的字符串
- sql - POSTGRESQL-将多行不同值的列转换为一行不同的列
- django - 使用正确的 URL 和数据测试 API 时 Pytest 失败
- c++ - 使用 std::filesystem 将文件夹从 USB 驱动器复制到 C: 驱动器
- javascript - 如何处理将数据持久化到数据库中的表单提交中断?
- flutter - Flutter apk 无法在物理设备上创建本地文本文件