Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays 在Fortran中定义数组的维数?_Arrays_Fortran_Dimension - Fatal编程技术网

Arrays 在Fortran中定义数组的维数?

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))

我正在从文件“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))

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