英雄我使用的新代码。我已经尝试过这个,如果我先声明 n ,它就会起作用,这不是我想要的。我需要知道行总数 (n) 并在以后的模拟中使用该数字。但是,在变量声明中,我需要在读取数据之前缩小 xy(n) ,如果这样做,代码将不会运行。
数据文件是两列随机模拟的正常数据
让我们说这样的话
1 3
2 4
3 6
4 8
5 9
6 8
7 1
8 9
99 88
Run Code Online (Sandbox Code Playgroud)
我尝试了以下代码来确定 n 但它不起作用!
program reading
implicit none
integer,allocatable :: a(:,:)
integer :: pair(2)
integer :: unit, n, io,k
!!!variable declaration
real, dimension(1:n)::x,y
integer:: T, I1, I2, I3, i, j, dist
open(2, file = 'xyBVNData_R.txt', status = 'old', action = 'read')
n = 0
DO
READ(2,*,iostat=io)
IF (io/=0) EXIT
n = n + 1 …
Run Code Online (Sandbox Code Playgroud)