Skip to content Skip to sidebar Skip to footer

What Is The Intent Of This Fortran 77 Code?

I'm trying to Pythonize a FORTRAN77 code. 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 bet

Solution 1:

I had already been programming for about eight years when 1977 rolled in. Fortunately this code is bedrock with nothing abstruse or complicated. 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.

  • Fortran arrays were 1-relative; ie, the first element of a 1-D array was number one.
  • As you already know, Python floats are doubles.
  • Fortran DO-loop variables assume each and every value from the first to the last, unlike Python for-loop variables.
  • The GOTO 18 targets the end of the DO-loop. The loop will continue with the next value of the DO-loop variable, J.
  • In contrast, GOTO 20 targets a line outside of the loop and is, hence, like a Python break.
defsample(ZM):
    Z = [_/10for _ inrange(0,11)]

    NJ = len(Z)
    for J inrange(1, NJ):
        if ZM > Z[J]:
            continue
        J1 = J
        J1M = J - 1break

    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)

Post a Comment for "What Is The Intent Of This Fortran 77 Code?"