2017-03-03 98 views
0

我试图编写一个程序,其中包含很多其他if语句。但是,我不明白这个错误来自哪里。任何帮助,将不胜感激。其他语句后出现意外的垃圾:(i == 1 .AND。1 <j <L)

下面是if块我目前有:

if (i == 1 .AND. j==1) then 
     E = E + A(i+1,j) + A(i,j+1) + A(L,j) + A(i,L) 

    else if (i == 1 .AND. j==L) then 
     E = E + A(i,j-1) + A(i+1,j) + A(i,1) + A(L,j) 

    else if (i == L .AND. j == 1) then 
     E = E + A(i,j+1) + A(i-1,j) + A(1,j) + A(i,L) 

    else if (i == L .AND. j == L) then 
     E = E + A(i,j-1) + A(i-1,j) + A(1,j) + A(i,1) 

    else if (i == 1 .AND. 1 < j < L) then 
     E = E + A(i+1,j) + A(i,j+1) + A(i,j-1) + A(L,j) 

    else if (i == L .AND. 1 < j < L) then 
     E = E + A(i-1,j) + A(i,j+1) + A(i,j-1) + A(1,j) 

    else if (1 < i < L .AND. j == 1) then 
     E = E + A(i-1,j) + A(i+1,j) + A(i,j+1) + A(i,L) 

    else if (1 < i < L .AND. j == L) then 
     E = E + A(i-1,j) + A(i+1,j) + A(i,j-1) + A(i,1) 
    else 
     E = E + A(i-1,j) + A(i+1,j) + A(i,j-1) + A(i,j+1) 
    end if 

的错误不断上来就是:

Ising.f90:56:15: 

    else if (i == 1 .AND. 1 < j < L) then 
      1 
Error: Unexpected junk after ELSE statement at (1) 
Ising.f90:59:15: 

    else if (i == L .AND. 1 < j < L) then 
      1 
Error: Unexpected junk after ELSE statement at (1) 
Ising.f90:62:15: 

    else if (1 < i < L .AND. j == 1) then 
      1 
Error: Unexpected junk after ELSE statement at (1) 
Ising.f90:65:15: 

    else if (1 < i < L .AND. j == L) then 
      1 
Error: Unexpected junk after ELSE statement at (1) 
+0

即使使用它接受之间的比较逻辑的延伸和整数它不”不要做你的想法。如果你的意思是1 tim18

回答

1

不能使用这样的表达式1 < i < L,以确定是否i处于的范围1到L. 您需要使用两个不等式测试的交集。使用类似

else if (1 < i .AND. i < L .AND. j == L) then

+0

这对SELECTED CASE,WHERE和ELSEWHERE来说会更容易一些。或者让我如果结构化,然后在其中进行j测试。 – Holmz

+1

或者,鉴于它看起来像周期性的边界条件,使得几乎可以肯定存在的i和j循环从2到j,并设置循环外部的例外情况,只是避免if/case /不管所有在一起 –

-1

这将是对与选定的情况或者和其他地方的眼睛更容易一些。或者让我如果结构化,然后在其中进行j测试。

没有看到的代码,我只能猜测,这可能是一些类似插值休息...

一些地方,如果将阵列从(0 indiexed人能做到这一点对一个数学语句行: N + 1)。

+0

这是怎么回事回答有关错误的问题?这是否意味着评论?你会如何使用WHERE重写?我花了很长时间看这个,但我仍然不知道。你怎么能知道结果被分配给某个数组? –

0

@VladimirF以及我提到它看起来像一些插值...

@Ianbush也提到了一些很好的意见。

也许......这是一些更平滑/内插?

平滑例如:

L = UBOUND(OldThing, 1) !assumes it is square! 
ALLOCATE(newthing(0:L+1, 0:L+1)) 
DO I = 1, L 
    DO J = 1, L 
    NewThing(I,j) = OldThing(I,j) 
    ENDDO 
ENDDO 

! Probably a derivative to extrapolate the outliers is better... 
! Kindergarten example below is for simplicity. 
DO I= 1, L 
    NewThing(0,(I))= OldThing(1,I) 
    NewThing(0,(I))= OldThing(1,I) 
    NewThing(0,(I))= OldThing(1,I) 
    NewThing(0,(I))= OldThing(1,I) 
ENDDO 

NewThing(0 , 0) = OldThing(1,1) 
NewThing(0, L+1) = OldThing(1,L) 
NewThing(L+1, 0) = OldThing(L,1) 
NewThing(L+1,L+1) = OldThing(L,L) 

!then one is always within the bounds... And the normal case is executed. 
E = E + NewThing(I-1,j) + NewThing(i+1,j) + NewThing(i,j-1) + NewThing(i,j+1) 

大概NewThing的返回(1:L,1:L)需要发生

+0

请不要发布新的答案作为反应,如果关于同一主题,您可以编辑当前的答案。你对'WHERE'的使用很奇怪。 WHERE是**数组**表达式。 –

相关问题