解密代码并转录为Python

时间:2019-07-18 09:53:23

标签: python

我在《地下水建模入门》一书中找到了下面描述的代码(按字面意思描述)。我无法识别代码中涉及的语言或逻辑(除了“ C”的意思是“注释”和一些迭代)。有人可以帮我破译它,并演示它在Python中的外观吗?原始代码和预期结果可在第this site页的82中找到。

  C RESERVOIR EXAMPLE
       DIMENSION HOLD(25),HNEW(25)
  C HOLD IS HEAD AT THE TIME STEP N
  C HNEW IS HEAD AT THE TIME STEP N+1
  C DEFINE PARAMETERS
       DT=5
       DX=10
       T=0.02
       S=0.002
       NX=11
       NLX=NX-1
  C DEFINE INITIAL AND BOUNDARY CONDITIONS
  C HO IS THE INITIAL HEAD
       HO=16
       DO 10 I=1,NX
       HOLD(I)=HO
       HNEW(I)=HO
   10 CONTINUE
  C CHANGE HEAD AT BOUNDARY FOR TIME GREATHER THAN ZERO
       HOLD(NX)=11
  C COMPUTE HEADS THROUGH TIME
       PRINT 120
   120 FORMAT(1H1,31X,'HEAD',36X,'TIME,//)
       KOUNT=1
       KPRINT=2
       TIME=DT
       NEND=100
       DO 50 N=1,NEND
       DO 20 I=2,NLX
       F1=DT*T/S
       D2H=(HOLD(I+1)-2.*HOLD(I)+HOLD(I-1))/(DX*DX)
       HNEW(I)=HOLD(I)+(F1*D2H)
    20 CONTINUE
       DO 30 I=1,NLX
       HOLD(I)=HNEW(I)
    30 CONTINUE
  C PRINT RESULTS FOR EVERY OTHER TIME STEP
       IF (KOUNT.NE.KPRINT) GO TO 49
       WRITE(6,40) (HOLD(I),I=1,NX),TIME
       KOUNT=0
    49 TIME=TIME+DT
       KOUNT=KOUNT+1
    50 CONTINUE
    40 FORMAT(1X,11F6.2,1F10.2)
       STOP
       END

0 个答案:

没有答案