Commit 7fda5b6b authored by Pierre-Antoine Rouby's avatar Pierre-Antoine Rouby
Browse files

Mage: Fix #17 ST file export format.

Showing with 22 additions and 8 deletions
+22 -8
...@@ -149,19 +149,25 @@ class Mage(AbstractSolver): ...@@ -149,19 +149,25 @@ class Mage(AbstractSolver):
c1 = f"{profile.code1:>6}" c1 = f"{profile.code1:>6}"
c2 = f"{profile.code2:>6}" c2 = f"{profile.code2:>6}"
t = f"{len(profile.points):>6}" t = f"{len(profile.points):>6}"
kp = f"{profile.kp:>13.4f}" kp = f"{profile.kp:>12f}"[0:12]
pname = profile.name pname = profile.name
if profile.name == "": if profile.name == "":
pname = f"p{profile.id:>3}".replace(" ", "p") # Generate name from profile id prefixed with
name = f"{pname}" # 'p' (and replace space char with '0' char)
pname = f"p{profile.id:>3}".replace(" ", "0")
name = f"{pname:<19}"
# Generate sediment additional data if available
sediment = "" sediment = ""
if profile.sl is not None: if profile.sl is not None:
if not any(filter(lambda f: ".GRA" in f, files)): if not any(filter(lambda f: ".GRA" in f, files)):
files.append(gra_file) files.append(gra_file)
# Number of layers
nl = len(profile.sl) nl = len(profile.sl)
sediment = f" {nl:>3}" sediment = f" {nl:>3}"
# Layers data
for layer in profile.sl.layers: for layer in profile.sl.layers:
sediment += ( sediment += (
f" {layer.height:>10} {layer.d50:>10} " + f" {layer.height:>10} {layer.d50:>10} " +
...@@ -169,20 +175,26 @@ class Mage(AbstractSolver): ...@@ -169,20 +175,26 @@ class Mage(AbstractSolver):
f"{layer.critical_constraint:>10}" f"{layer.critical_constraint:>10}"
) )
f.write(f"{num}{c1}{c2}{t}{kp} {name} {sediment}\n") # Profile header line
f.write(f"{num}{c1}{c2}{t} {kp} {name} {sediment}\n")
cnt_num += 1 cnt_num += 1
# Points
for point in profile.points: for point in profile.points:
x = f"{point.x:>13.4f}" x = f"{point.x:<12f}"[0:12]
y = f"{point.y:>13.4f}" y = f"{point.y:<12f}"[0:12]
z = f"{point.z:>13.4f}" z = f"{point.z:<12f}"[0:12]
n = f"{point.name:<3}" n = f"{point.name:<3}"
# Generate sediment additional data if available
sediment = "" sediment = ""
prev = point.z prev = point.z
if point.sl is not None: if point.sl is not None:
# Number of layers
nl = len(point.sl) nl = len(point.sl)
sediment = f"{nl:>3}" sediment = f"{nl:>3}"
# Layers data
for layer in point.sl.layers: for layer in point.sl.layers:
prev = round(prev - layer.height, 5) prev = round(prev - layer.height, 5)
sediment += ( sediment += (
...@@ -191,8 +203,10 @@ class Mage(AbstractSolver): ...@@ -191,8 +203,10 @@ class Mage(AbstractSolver):
f"{layer.critical_constraint:>10}" f"{layer.critical_constraint:>10}"
) )
f.write(f"{x}{y}{z} {n} {sediment}\n") # Point line
f.write(f"{x} {y} {z}{n} {sediment}\n")
# Profile last line
f.write(f" 999.9990 999.9990 999.9990\n") f.write(f" 999.9990 999.9990 999.9990\n")
return files return files
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment