在 Fortran 中定义数组的维数?

Defining dimension of an array in Fortran?

我正在从文件-'var_and_runs.txt' 中读取矩阵 'A' 的行数和列数 但它显示编译错误 - 'unexpected data declaration statement'

implicit none
integer i, var, runs
integer  rows, cols
open(unit = 30, file = 'var_and_runs.txt')
    read(30,*) cols,rows

INTEGER, DIMENSION(:, :), ALLOCATABLE :: A

ALLOCATE (A(rows, cols))

open (unit = 40, file = 'read_this.txt')

read(40,*) A
A = transpose(A)
do 80 i = 1,3             
print*, A(i,:)
80    continue
print*, A
end

请帮忙!

可执行语句后不能有任何变量声明。在您的情况下,您应该更换

open(unit = 30, file = 'var_and_runs.txt')
  read(30,*) cols,rows

INTEGER, DIMENSION(:, :), ALLOCATABLE :: A

INTEGER, DIMENSION(:, :), ALLOCATABLE :: A
open(unit = 30, file = 'var_and_runs.txt')
  read(30,*) cols,rows

希望一切正常。