[英]What is the intent of this Fortran 77 code?
I'm trying to Pythonize a FORTRAN77 code. 我正在尝试对FORTRAN77代码进行Python化。 There's a block of code that I just can't seem to grasp the intent of.
我似乎无法理解其中的一段代码。
ZM is just a scalar between 0 and 1. Z is a 1D array of numbers between 0 and 1 with NJ elements. ZM只是介于0到1之间的标量。Z是带有NJ元素的介于0和1之间的一维数字数组。 J, J1, and J1M are type INTEGER.
J,J1和J1M是INTEGER类型。 PDFZ is another 1D array with NJ elements.
PDFZ是具有NJ元素的另一个一维阵列。 I'm having trouble mapping out the flow of execution.
我在规划执行流程时遇到了麻烦。
DO 18 J=2,NJ
IF(ZM.GT.Z(J)) GOTO 18
J1=J
J1M=J-1
GOTO 20
18 CONTINUE
20 CONTINUE
DO 22 J=1,NJ
PDFZ(J)=0.D0
22 CONTINUE
PDFZ(J1)=(ZM-Z(J1M))/(Z(J1)-Z(J1M))
PDFZ(J1M)=1.D0-PDFZ(J1)
I created what I thought was the equivalent in Python2.7. 我创建了我认为与Python2.7类似的东西。 But I'm not so sure anymore that my python code captures the behavior of the Fortran77 code.
但是我不太确定我的python代码是否捕获了Fortran77代码的行为。
loc = np.where(z < z_mean)[0][0]
pdf_z[loc] = (z_mean - z[loc-1])/(z[loc] - z[loc-1])
pdf_z[loc-1] = 1.0 - pdf_z[loc]
I had already been programming for about eight years when 1977 rolled in. Fortunately this code is bedrock with nothing abstruse or complicated. 1977年开始工作时,我已经进行了大约8年的编程。所幸的是,这段代码是基础,没有任何深奥或复杂的内容。 Not that I can discern what it does either.
并不是我能分辨出它是做什么的。
However, I can translate it. 但是,我可以翻译它。 Here it is in a form in which you can experiment with it.
在这里,您可以尝试使用它的形式。
GOTO 18
targets the end of the DO-loop. GOTO 18
以DO循环的结尾为目标。 The loop will continue with the next value of the DO-loop variable, J
. J
的下一个值。 GOTO 20
targets a line outside of the loop and is, hence, like a Python break
. GOTO 20
目标是循环外的一行,因此就像Python的break
。 def sample(ZM):
Z = [_/10 for _ in range(0,11)]
NJ = len(Z)
for J in range(1, NJ):
if ZM > Z[J]:
continue
J1 = J
J1M = J - 1
break
PDFZ = NJ * [0]
PDFZ[J1] = (ZM - Z[J1M])/(Z[J1] - Z[J1M])
PDFZ[J1M] = 1 - PDFZ[J1]
print (ZM, PDFZ)
for ZM in [0, .1, .2, .3, ]:
sample(ZM)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.