Fortran 77代码有效但不显示所有值

时间:2015-01-12 10:41:51

标签: fortran fortran77

我的程序有效,但没有显示所有P(I)值。

当它的工作时它只显示P(1)值。并阻止它。但我想知道所有的价值观。 P(1)至P(121)。

问题出在哪里?循环有什么问题吗?

       PROGRAM odev
        dimension P(121)
c       div(ro.v.fi)=div(r.gradfi)+a-bfi
c       P(1)=P(2)=P(3)=P(4)=P(5)=P(6)=P(7)=P(8)=P(9)=P(10)=P(11)=100
c       P(12)=P(23)=P(34)=P(45)=P(56)=P(67)=P(78)=P(89)=P(100)=P(111)=100
c       P(22)=P(33)=P(44)=P(55)=P(66)=P(77)=P(88)=P(99)=P(110)=P(121)=0
c       P(112)=P(113)=P(114)=P(115)=P(116)=P(117)=P(118)=P(119)=P(120)=0
   50  PRINT *, "Hangi yontemle cozum yapmak istiyorsunuz?"
        PRINT *, "Merkezi farklar icin 1"
        PRINT *, "Upwind icin 2"
        PRINT *, "Hybrid icin 3"
        PRINT *, "Powerlaw icin 4 giriniz"
        READ *, DE
        PRINT *, "iterasyon saysn giriniz"
        read*, iter
        IF (DE.eq.1)  THEN
        GO TO 10
        ELSE IF (DE.eq.2)  THEN
        GO TO 20
        ELSE IF (DE.eq.3)  THEN
        GO TO 30
        ELSE IF (DE.eq.4)  THEN
        GO TO 40
        ELSE
        PRINT *, "Lutfen 1-4 aral§nda giriŸ yapnz"
        GO TO 50
        END IF
    5  do I=1,11
       P(I)=100
       end do
    6  do I=12,111,11
       P(I)= 100
       end do
    7  do I=22,121,11
       P(I)=0
       end do
    8  do I=112,120
       P(I)=0
       end do
   10 PRINT *, "Merkezi farklar metodu"
c      tanimlanan formule gore 10*10 hucreli grid
c      sistem icin hesap yapar
       do 3 n=1, iter
        DO 4 I=13, 109
       P(I)=(0.5*P(I+1)+1.5*P(I-1)-P(I-11)+3*P(I+11)+10)/6
    4 continue
    3 continue
        GO TO 60
   20  PRINT *, "Upwind metodu "
       do n=1, iter
        DO I=13, 109
        P(I)=(P(I+1)+2*P(I-1)+P(I-11)+5*P(I+11)+10)/11
        END DO
       end do
        GO TO 60
   30  PRINT *, "Hybrid metodu "
        do n=1, iter
        DO I=13, 109
        P(I)=(0.5*P(I+1)+1.5*P(I-1)+4*P(I+11)+10)/8
        END DO
       end do
        GO TO 60
   40  PRINT *, "Powerlaw metodu "
        do n=1, iter
        DO I=13, 109
       P(I)=(0.591*P(I+1)+1.591*P(I-1)+0.078*P(I-11)+4.078*P(I+11)+10)/8.338
        END DO
       end do
        GO TO 60
   60  PRINT *, "Tesekkurler"
       do 11 I=1,121
       print *, I, P(I)
       pause
   11  continue
       END

编辑;

来自 @High Performance Mark 建议

  60  PRINT *, "Tesekkurler"
       do 11 I=1,121
       print *, I, P(I)
c       pause
   11  continue

现在正在工作。但是P(13)至P(109)值显示为> Nan

P(1)至P(12)接近1e-40(必须为100) P(110)至P(121)接近1e-38

我认为还有另一个问题......

编辑2;

来自 @francescalus 建议

c       P(112)=P(113)=P(114)=P(115)=P(116)=P(117)=P(118)=P(119)=P(120)=0
    5  do I=1,11
       P(I)=100
       end do
    6  do I=12,111,11
       P(I)= 100
       end do
    7  do I=22,121,11
       P(I)=0
       end do
    8  do I=112,120
       P(I)=0
       end do
   50  PRINT *, "Hangi yontemle cozum yapmak istiyorsunuz?"

来自 @agentp 建议

SELECT CASE (N)
CASE (1)
PRINT *, "Merkezi farklar metodu"
    do 3 n=1, iter
    DO 4 I=13, 109
    P(I)=(0.5*P(I+1)+1.5*P(I-1)-P(I-11)+3*P(I+11)+10)/6
4 continue
3 continue
    GO TO 60
CASE (2)
PRINT *, "Upwind metodu "
    do n=1, iter
    DO I=13, 109
    P(I)=(P(I+1)+2*P(I-1)+P(I-11)+5*P(I+11)+10)/11
    END DO
    end do
    GO TO 60
CASE (3)
PRINT *, "Hybrid metodu "
    do n=1, iter
    DO I=13, 109
    P(I)=(0.5*P(I+1)+1.5*P(I-1)+4*P(I+11)+10)/8
    END DO
    end do
    GO TO 60
CASE (4)
PRINT *, "Powerlaw metodu "
    do n=1, iter
    DO I=13, 109
    Z=8.338
   P(I)=(0.591*P(I+1)+1.591*P(I-1)+0.078*P(I-11)+4.078*P(I+11)+10)/Z
    END DO
    end do
    GO TO 60
END SELECT

现在终于有效了......

1 个答案:

答案 0 :(得分:2)

这些行

   print *, I, P(I)
   pause

告诉程序打印P的第一个元素,然后打印到pause。在许多计算机上,当时任何用户输入(例如按键)将导致程序继续。在您的代码中,将导致P的下一个元素写入终端,并且程序再次暂停。

尝试取出pause行,看看会发生什么。或者像猴子一样坐在那里,按一下键120次。

然后抛弃程序并在现代Fortran中重写它;看FORTRAN77会让我痛苦。