Verify and publish documentation / test (macos-latest) (push) Canceled after 0s
Verify and publish documentation / test (ubuntu-latest) (push) Canceled after 0s
Verify and publish documentation / docs (push) Canceled after 0s
Verify and publish documentation / deploy (push) Canceled after 0s
Validate physical cards and CLI arguments, guard live DO cells, and share word encoding and checked numeric conversion. Preserve media on failed runs and bound notebook input, output, execution time and process cleanup. Clarify fixed-form editor support and compatibility evidence, add executable quick-start examples, and gate GitHub Pages on Linux/macOS and strict docs CI.
330 lines
9.8 KiB
Python
330 lines
9.8 KiB
Python
#!/usr/bin/env python3
|
|
"""FORTRAN I table limits, C28-6003 printed pages 49-50.
|
|
|
|
Writes just-over and just-under programs to the supplied output directory. The sources
|
|
are generated because several of them are longer than a card deck that
|
|
belongs in the tree. A passing run prints nothing: STOP is on stderr.
|
|
"""
|
|
|
|
import os
|
|
import sys
|
|
|
|
if len(sys.argv) != 2:
|
|
raise SystemExit("usage: %s OUTPUT_DIRECTORY" % sys.argv[0])
|
|
OUT = sys.argv[1]
|
|
|
|
|
|
def cards(label, text):
|
|
if len(text) > 660:
|
|
raise SystemExit("statement longer than 10 cards: %s" % text[:40])
|
|
lines = []
|
|
pos = 0
|
|
first = True
|
|
cont = 1
|
|
while first or pos < len(text):
|
|
chunk = text[pos : pos + 66]
|
|
pos += 66
|
|
if first:
|
|
pref = "%5d " % label if label else " "
|
|
lines.append(pref + chunk)
|
|
first = False
|
|
else:
|
|
if cont > 9:
|
|
raise SystemExit("too many continuations")
|
|
lines.append(" %d%s" % (cont, chunk))
|
|
cont += 1
|
|
if pos >= len(text):
|
|
break
|
|
for i, ln in enumerate(lines):
|
|
if len(ln) > 72:
|
|
raise SystemExit("card longer than 72: %s" % ln)
|
|
if i < len(lines) - 1 and len(ln) != 72:
|
|
raise SystemExit("short card would insert blanks: %s" % ln)
|
|
return lines
|
|
|
|
|
|
def write(name, stmts):
|
|
lines = []
|
|
for lab, text in stmts:
|
|
lines.extend(cards(lab, text))
|
|
path = os.path.join(OUT, name + ".f")
|
|
with open(path, "w") as f:
|
|
f.write("\n".join(lines) + "\n")
|
|
|
|
|
|
def stop(stmts):
|
|
stmts.append((0, "STOP"))
|
|
stmts.append((0, "END"))
|
|
return stmts
|
|
|
|
|
|
def seq(prefix, n):
|
|
return ["%s%05d" % (prefix, i) for i in range(1, n + 1)]
|
|
|
|
|
|
def reals(n):
|
|
names = []
|
|
i = 1
|
|
while len(names) < n:
|
|
names.append("A%02d" % i)
|
|
i += 1
|
|
if i == 100:
|
|
i = 1
|
|
break
|
|
j = 1
|
|
while len(names) < n:
|
|
names.append("B%02d" % j)
|
|
j += 1
|
|
return names
|
|
|
|
|
|
def defines(names, rhs="1.0"):
|
|
return [(0, "%s=%s" % (nm, rhs)) for nm in names]
|
|
|
|
|
|
def dim_stmts(prefix, n, rank):
|
|
bounds = ",".join(["1"] * rank)
|
|
stmts = []
|
|
chunk = []
|
|
|
|
def line_of(items):
|
|
return "DIMENSION " + ",".join(items)
|
|
|
|
for i in range(1, n + 1):
|
|
name = "%s%05d(%s)" % (prefix, i, bounds)
|
|
if chunk and len(line_of(chunk + [name])) > 66:
|
|
stmts.append((0, line_of(chunk)))
|
|
chunk = []
|
|
chunk.append(name)
|
|
if chunk:
|
|
stmts.append((0, line_of(chunk)))
|
|
return stmts
|
|
|
|
|
|
def dos(n, index="I"):
|
|
stmts = []
|
|
for lab in range(1, n + 1):
|
|
stmts.append((0, "DO %d %s=1,1" % (lab, index)))
|
|
stmts.append((lab, "CONTINUE"))
|
|
return stmts
|
|
|
|
|
|
def nest(n):
|
|
stmts = [(0, "DO 900 I%02d=1,1" % i) for i in range(1, n + 1)]
|
|
stmts.append((900, "CONTINUE"))
|
|
return stop(stmts)
|
|
|
|
|
|
def freq(n):
|
|
text = "FREQUENCY " + ",".join(["1"] * n)
|
|
if len(text) > 66:
|
|
raise SystemExit("FREQUENCY line does not fit: %d" % len(text))
|
|
return (0, text)
|
|
|
|
|
|
def wrapped(n):
|
|
return "Y=" + ("(" * n) + "A" + (")" * n)
|
|
|
|
|
|
def calls(k):
|
|
return "Y=" + "+".join(["SINF(Y)"] * k)
|
|
|
|
|
|
def jsum(k):
|
|
return "I=" + "+".join(["J"] * k)
|
|
|
|
|
|
def cgoto(n):
|
|
return "GOTO(" + ",".join(["1"] * n) + "),I"
|
|
|
|
|
|
def tau(rank, n):
|
|
if rank == 1:
|
|
dim = "DIMENSION A(1)"
|
|
use = "A(%s)"
|
|
elif rank == 2:
|
|
dim = "DIMENSION A(1,1)"
|
|
use = "A(%s,J)"
|
|
else:
|
|
dim = "DIMENSION A(1,1,1)"
|
|
use = "A(%s,J,K)"
|
|
names = seq("I", n)
|
|
stmts = [(0, dim)]
|
|
if rank >= 2:
|
|
stmts.append((0, "J=1"))
|
|
if rank == 3:
|
|
stmts.append((0, "K=1"))
|
|
for nm in names:
|
|
stmts.append((0, "%s=1" % nm))
|
|
stmts.append((0, "%s=1.0" % (use % names[0])))
|
|
for nm in names:
|
|
stmts.append((0, "Y=%s" % (use % nm)))
|
|
return stop(stmts)
|
|
|
|
|
|
def sigma(rank, n, zero):
|
|
"""n distinct nonzero additive parts, each on its own statement."""
|
|
if rank == 1:
|
|
dim = "DIMENSION A(%d)" % max(n, 1)
|
|
stmts = [(0, dim), (0, "I=1")]
|
|
if zero:
|
|
stmts.append((0, "A(I)=1.0"))
|
|
for k in range(1, n + 1):
|
|
stmts.append((0, "A(%d)=1.0" % k))
|
|
return stop(stmts)
|
|
last = n + 1
|
|
if rank == 2:
|
|
dim = "DIMENSION A(%d,1)" % last
|
|
body = "A(I+%d,J)=1.0"
|
|
zero_st = "A(I,J)=1.0"
|
|
else:
|
|
dim = "DIMENSION A(%d,1,1)" % last
|
|
body = "A(I+%d,J,K)=1.0"
|
|
zero_st = "A(I,J,K)=1.0"
|
|
stmts = [(0, dim), (0, "I=1"), (0, "J=1")]
|
|
if rank == 3:
|
|
stmts.append((0, "K=1"))
|
|
if zero:
|
|
stmts.append((0, zero_st))
|
|
for k in range(1, n + 1):
|
|
stmts.append((0, body % k))
|
|
return stop(stmts)
|
|
|
|
|
|
def main():
|
|
os.makedirs(OUT, exist_ok=True)
|
|
open(os.path.join(OUT, "empty.out"), "w").close()
|
|
|
|
write("teifno-ok", stop([(i, "CONTINUE") for i in range(1, 1501)]))
|
|
write("teifno-over", stop([(i, "CONTINUE") for i in range(1, 1502)]))
|
|
write("teifno-dim", stop([(i, "CONTINUE") for i in range(1, 1500)] +
|
|
[(1500, "DIMENSION A(1)")]))
|
|
write("teifno-dimover", stop([(i, "CONTINUE") for i in range(1, 1501)] +
|
|
[(1501, "DIMENSION A(1)")]))
|
|
impl = [(0, "DIMENSION A(1)")]
|
|
impl += [(i, "CONTINUE") for i in range(1, 1499)]
|
|
impl.append((1499, "FORMAT(I1)"))
|
|
impl.append((1500, "PRINT 1499, (A(I), I=1,1)"))
|
|
write("teifno-impl", stop(impl))
|
|
|
|
write("fixcon-ok", stop([(0, "I=%d" % k) for k in range(1, 101)]))
|
|
write("fixcon-over", stop([(0, "I=%d" % k) for k in range(1, 102)]))
|
|
|
|
fl = [(0, "Y=%d." % k) for k in range(1, 451)]
|
|
fl += [(0, "Y=4."), (0, "Y=4.0"), (0, "Y=40.E-1")]
|
|
write("flocon-ok", stop(fl))
|
|
write("flocon-over", stop([(0, "Y=%d." % k) for k in range(1, 452)]))
|
|
|
|
write("tdo-ok", stop(dos(150)))
|
|
write("tdo-over", stop(dos(151)))
|
|
impl_ok = [(0, "DIMENSION A(1)")] + dos(149)
|
|
# The implied DO must be compiled and must not run. IF (1) names
|
|
# it, and the positive result selects 9000.
|
|
impl_ok += [
|
|
(0, "IF (1) 9000, 9002, 9000"),
|
|
(9002, "PRINT 9001, (A(I), I=1,1)"),
|
|
(9001, "FORMAT(I1)"),
|
|
(9000, "STOP"),
|
|
(0, "END"),
|
|
]
|
|
write("tdo-impl-ok", impl_ok)
|
|
impl_over = [(0, "DIMENSION A(1)")] + dos(150)
|
|
impl_over.append((0, "PRINT 9001, (A(I), I=1,1)"))
|
|
impl_over.append((9001, "FORMAT(I1)"))
|
|
write("tdo-impl-over", stop(impl_over))
|
|
|
|
write("nest-rt", nest(50))
|
|
write("nest-over", nest(51))
|
|
|
|
write("tifgo-ok", stop([(0, "GOTO 1")] * 300 + [(1, "STOP")]))
|
|
write("tifgo-over", stop([(0, "GOTO 1")] * 301 + [(1, "STOP")]))
|
|
|
|
trad = [(0, "I=1"), (0, cgoto(64)), (0, cgoto(64)), (0, cgoto(64))]
|
|
write("trad-ok", stop(trad + [(0, cgoto(58)), (1, "STOP")]))
|
|
write("trad-over", stop(trad + [(0, cgoto(59)), (1, "STOP")]))
|
|
|
|
fret = [freq(28)] * 26
|
|
write("fret-ok", stop(fret + [freq(22)]))
|
|
write("fret-over", stop(fret + [freq(23)]))
|
|
write("fret-blank", stop([(0, "FREQUENCY 3 0(1,2,1)")] * 151))
|
|
|
|
dim = dim_stmts("A", 100, 1) + dim_stmts("B", 100, 2) + dim_stmts("C", 90, 3)
|
|
write("dim-ok", stop(dim))
|
|
write("dim1-over", stop(dim_stmts("A", 101, 1)))
|
|
write("dim2-over", stop(dim_stmts("B", 101, 2)))
|
|
write("dim3-over", stop(dim_stmts("C", 91, 3)))
|
|
|
|
write("fmt-ok", stop([(i, "FORMAT(I1)") for i in range(1, 358)]))
|
|
write("fmt-over", stop([(i, "FORMAT(I1)") for i in range(1, 359)]))
|
|
|
|
names = reals(133)
|
|
write("lam-ok", stop(defines(names) + [(0, "Y=" + "*".join(names))]))
|
|
over = reals(134)
|
|
write("lam-over", stop([(0, "Y=" + "*".join(over))]))
|
|
|
|
bnames = reals(99)
|
|
write("beta-ok", stop(defines(bnames) + [(0, "Y=" + "+".join(bnames))]))
|
|
bover = reals(100)
|
|
write("beta-over", stop([(0, "Y=" + "+".join(bover))]))
|
|
|
|
write("alpha-ok", stop([(0, "A=1.0"), (0, wrapped(34))]))
|
|
write("alpha-over", stop([(0, "A=1.0"), (0, wrapped(35))]))
|
|
|
|
clo = [(0, "Y=1.0")] + [(0, calls(40))] * 37
|
|
write("closub-ok", stop(clo + [(0, calls(20))]))
|
|
write("closub-over", stop(clo + [(0, calls(21))]))
|
|
|
|
write("forval-ok", stop([(0, "I=1")] * 500))
|
|
write("forval-over", stop([(0, "I=1")] * 501))
|
|
read = [(0, "I=1")] * 500 + [(0, "READ 1, I"), (1, "FORMAT(I5)")]
|
|
write("forval-read", stop(read))
|
|
|
|
fvar = [(0, "J=1")] + [(0, jsum(99))] * 7
|
|
write("forvar-ok", stop(fvar + [(0, jsum(57))]))
|
|
write("forvar-over", stop(fvar + [(0, jsum(58))]))
|
|
|
|
tag = [(0, "DIMENSION A(1)"), (0, "A(1)=1.0")] + [(0, "Y=A(1)")] * 1499
|
|
write("fortag-ok", stop(tag))
|
|
tag = [(0, "DIMENSION A(1)"), (0, "A(1)=1.0")] + [(0, "Y=A(1)")] * 1500
|
|
write("fortag-over", stop(tag))
|
|
|
|
write("tau1-ok", tau(1, 100))
|
|
write("tau1-over", tau(1, 101))
|
|
write("tau2-ok", tau(2, 90))
|
|
write("tau2-over", tau(2, 91))
|
|
write("tau3-ok", tau(3, 75))
|
|
write("tau3-over", tau(3, 76))
|
|
|
|
write("sig1-ok", sigma(1, 99, True))
|
|
write("sig1-over", sigma(1, 100, False))
|
|
write("sig2-ok", sigma(2, 99, True))
|
|
write("sig2-over", sigma(2, 100, False))
|
|
write("sig3-ok", sigma(3, 99, True))
|
|
write("sig3-over", sigma(3, 100, False))
|
|
|
|
sf = [(0, "F%02dF(X%02d)=X%02d" % (i, i, i)) for i in range(1, 33)]
|
|
write("forsub-ok", stop(sf))
|
|
|
|
def nlist_chain(n):
|
|
"""Each ASSIGN is the target of the previous GO TO, so the
|
|
flow reaches every one. The last GO TO selects statement 1.
|
|
"""
|
|
stmts = []
|
|
for i in range(1, n + 1):
|
|
nxt = i + 1 if i < n else 1
|
|
stmts.append((0 if i == 1 else i, "ASSIGN %d TO I%02d" % (nxt, i)))
|
|
stmts.append((0, "GOTO I%02d,(%d)" % (i, nxt)))
|
|
stmts.append((1, "STOP"))
|
|
return stmts
|
|
|
|
write("nlist-ok", stop(nlist_chain(25)))
|
|
write("nlist-over", stop(nlist_chain(26)))
|
|
same = [(0, "ASSIGN 1 TO I")] + [(0, "GOTO I,(1)")] * 26 + [(1, "STOP")]
|
|
write("nlist-same", stop(same))
|
|
|
|
print("wrote", OUT)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|