foo126 发表于 2018-6-4 16:15:30

Error: DATA statement at (1) has more values than variables

我刚学fortran,下面这段代码总编译不成功,总提示 Error: DATA statement at (1) has more values than variables
program ex0707
implicit none
integer, parameter :: row = 3
integer, parameter :: col = 2
integer :: m(row, col)
integer r
integer c

data((m(r, c),r=1,2,3),c=1,2)/10,20,30,40,50,60/
write(*, "(i3, i3, /,i3, i3, /, i3, i3)")((m(r, c), c=1,2),r=1,2,3)

stop
end

编译信息如下(警告我都删掉了):
ex0707.f95:9:5:
data((m(r, c),r=1,2,3),c=1,2)/10,20,30,40,50,60/
   1
Error: DATA statement at (1) has more values than variables
编译失败。

我没有多赋值啊?请各位指教。

li913 发表于 2018-6-4 17:39:40

data((m(r, c),r=1,3),c=1,2)/10,20,30,40,50,60/

li913 发表于 2018-6-4 17:44:28

既然是刚学,就要学新的,你这个代码风格有点老了。推荐彭国伦的书。另外,使用二维数组,可以看看这个http://fcode.cn/guide-45-1.html
program ex0707
implicit none
integer, parameter :: row = 3, col = 2
integer :: m(row, col)
integer r, c
m = reshape(,)
write(*, "(2i3)") ((m(r, c), c=1,2),r=1,3)
read(*,*)
end

foo126 发表于 2018-6-4 20:11:18

谢谢 我刚发现是这里的错,谢谢,以后多指教。我项用fortran作概率统计分析用

foo126 发表于 2018-6-4 20:46:34

我正在读他的fortran95程序设计,        m = reshape(,)这种格式的输入还没看到:-)

fcode 发表于 2018-6-6 08:31:38

恭喜你,学到新东西了

foo126 发表于 2018-6-6 20:34:21

fcode 发表于 2018-6-6 08:31
恭喜你,学到新东西了

谢谢,多指教
页: [1]
查看完整版本: Error: DATA statement at (1) has more values than variables