【发布时间】:2021-12-09 09:30:10
【问题描述】:
我尝试编译以下代码并得到以下错误,伙计们可以 你帮我解决这个错误
代码:
DIMENSION x(*),b(*),g(*),h(*),cg(*)
DIMENSION aa(*),ja(*),ia(*),al(*)
C
DO 1 K=1, kMax
C
IF (k.EQ.1) THEN
CALL IAmul(n,aa,ia,ja,x,h)
DO 2 i=1,n
cg(i)=b(i)-h(i)
g(i)=cg(i)
2 CONTINUE
CAll ISolvSys(n,g,al,ia,ja)
gcg=0.
DO 3 i=1,n
gcg=gcg+g(i)*cg(i)
h(i)=g(i)
3 CONTINUE
ENDIF
C
CALL IAmul (n,aa,ia,ja,h,b)
hAh=0.
DO 10 i=1,n
hAh=hAh+h(i)*b(i)
10 CONTINUE
ro=gcg/hAh
DO 11 i=1,n
cg(i)=cg(i)-r0*h(i)
11 CONTINUE
CALL ISolvSys(n,al,iaja)
DO 12 i=1,n
x(i)=x(i)+ro*h(i)
g(i)=g(i)-ro*b(i)
12 CONTINUE
gamma=gcg
gcg=0
DO 13 i=1,n
gcg=gcg+g(i)*cg(i)
13 CONTINUE
C
C
write(*,*)'iteration:',k, 'gcg=',gcg
IF(k.EQ.1) eps=eps*gcg
IF (gcg.LT.eps) RETURN
gamma=gcg/gamma
DO 14 i=1,n
h(i)=g(i)+gamma*h(i)
14 CONTINUE
C
C
1 CONTINUE
END
错误:
6 | DO i=1,n
| 2
......
12 | DO i=1,n
| 1
Error: Variable ‘i’ at (1) cannot be redefined inside loop beginning at (2)
<span class="error_line" onclick="ide.gotoLine('main.f95',16)">main.f95:16:7</span>:
16 | ENDIF
| 1
Error: Expecting END DO statement at (1)
<span class="error_line" onclick="ide.gotoLine('main.f95',20)">main.f95:20:13</span>:
12 | DO i=1,n
| 2
......
20 | DO i=1,n
| 1
Error: Variable ‘i’ at (1) cannot be redefined inside loop beginning at (2)
<span class="error_line" onclick="ide.gotoLine('main.f95',24)">main.f95:24:13</span>:
20 | DO i=1,n
| 2
......
24 | DO i=1,n
| 1
Error: Variable ‘i’ at (1) cannot be redefined inside loop beginning at (2)
<span class="error_line" onclick="ide.gotoLine('main.f95',28)">main.f95:28:13</span>:
24 | DO i=1,n
| 2
......
28 | DO i=1,n
| 1
Error: Variable ‘i’ at (1) cannot be redefined inside loop beginning at (2)
<span class="error_line" onclick="ide.gotoLine('main.f95',34)">main.f95:34:13</span>:
28 | DO i=1,n
| 2
......
34 | DO i=1,n
| 1
Error: Variable ‘i’ at (1) cannot be redefined inside loop beginning at (2)
<span class="error_line" onclick="ide.gotoLine('main.f95',41)">main.f95:41:13</span>:
34 | DO i=1,n
| 2
......
41 | DO i=1,n
| 1
Error: Variable ‘i’ at (1) cannot be redefined inside loop beginning at (2)
<span class="error_line" onclick="ide.gotoLine('main.f95',45)">main.f95:45:3</span>:
45 | END
| 1
Error: END DO statement expected at (1)
f951: Error: Unexpected end of file in ‘main.f95’
6 | DO i=1,n
| 2
......
12 | DO i=1,n
| 1
Error: Variable ‘i’ at (1) cannot be redefined inside loop beginning at (2)
<span class="error_line" onclick="ide.gotoLine('main.f95',16)">main.f95:16:7</span>:
16 | ENDIF
| 1
Error: Expecting END DO statement at (1)
<span class="error_line" onclick="ide.gotoLine('main.f95',20)">main.f95:20:13</span>:
12 | DO i=1,n
| 2
......
20 | DO i=1,n
| 1
Error: Variable ‘i’ at (1) cannot be redefined inside loop beginning at (2)
<span class="error_line" onclick="ide.gotoLine('main.f95',24)">main.f95:24:13</span>:
20 | DO i=1,n
| 2
......
24 | DO i=1,n
| 1
Error: Variable ‘i’ at (1) cannot be redefined inside loop beginning at (2)
<span class="error_line" onclick="ide.gotoLine('main.f95',28)">main.f95:28:13</span>:
24 | DO i=1,n
| 2
......
28 | DO i=1,n
| 1
Error: Variable ‘i’ at (1) cannot be redefined inside loop beginning at (2)
<span class="error_line" onclick="ide.gotoLine('main.f95',34)">main.f95:34:13</span>:
28 | DO i=1,n
| 2
......
34 | DO i=1,n
| 1
Error: Variable ‘i’ at (1) cannot be redefined inside loop beginning at (2)
<span class="error_line" onclick="ide.gotoLine('main.f95',41)">main.f95:41:13</span>:
34 | DO i=1,n
| 2
......
41 | DO i=1,n
| 1
Error: Variable ‘i’ at (1) cannot be redefined inside loop beginning at (2)
<span class="error_line" onclick="ide.gotoLine('main.f95',45)">main.f95:45:3</span>:
45 | END
| 1
Error: END DO statement expected at (1)
f951: Error: Unexpected end of file in ‘main.f95’
如果 Fortran 专家能澄清这个问题,我将不胜感激。
【问题讨论】:
-
很难看出您给出的错误消息与代码有何关联。无论哪种方式,我们都需要查看更多细节,而不仅仅是程序的一部分。见minimal reproducible example。
-
我必须同意@francescalus - 在您的代码示例中给出的我看不到一行代码
DO i=1,n我看不出您的错误消息与您所呈现的内容有何关系。
标签: loops compiler-errors fortran