Arrays 在Fortran中定义数组的维数?
我正在从文件“var_and_runs.txt”读取矩阵“a”的行数和列数 但它显示编译错误-“意外数据声明语句”Arrays 在Fortran中定义数组的维数?,arrays,fortran,dimension,Arrays,Fortran,Dimension,我正在从文件“var_and_runs.txt”读取矩阵“a”的行数和列数 但它显示编译错误-“意外数据声明语句” 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))
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
与
希望一切正常。Thanx,这解决了我的问题。@curiousprogrammer很高兴我能提供帮助,因为这已经回答了你的问题。如果你能接受最好的答案,让其他人看到这个问题已经解决,那将非常有用(请参阅)。
INTEGER, DIMENSION(:, :), ALLOCATABLE :: A
open(unit = 30, file = 'var_and_runs.txt')
read(30,*) cols,rows