我想从文件中获取数据,该文件的数据内容可以具有可变大小。然而,结构非常简单。3 列和未定义的行数。我认为使用可分配的多维数组和显式 DO 循环可以解决我的问题。到目前为止,这是我的代码
program arraycall
implicit none
integer, dimension(:,:), allocatable :: array
integer :: max_rows, max_cols, row, col
allocate(array(row,col))
open(10, file='boundary.txt', access='sequential', status='old', FORM='FORMATTED')
DO row = 1, max_rows
DO col = 1, max_cols
READ (10,*) array (row, col)
END DO
END DO
print *, array (row,col)
deallocate(array)
end program arraycall
Run Code Online (Sandbox Code Playgroud)
现在我面临的问题是我不知道应该如何定义这些 max_rows 和 max_cols ,这与它的大小未知的事实产生共鸣。
示例文件可能看起来像
11 12 13
21 22 23
31 32 33
41 42 43
Run Code Online (Sandbox Code Playgroud)
所以我想出了一种动态(动态)估计文件记录长度的方法。更新一下,方便以后给其他人参考
!---------------------------------------------------------------------
! Estimate the number of records in the …Run Code Online (Sandbox Code Playgroud)