38 lines
1003 B
Python
38 lines
1003 B
Python
"""
|
|
This works like the convert.py script but accepts a range of polygons to extract.
|
|
This is useful for debugging the meshing code.
|
|
|
|
Example usage:
|
|
$ python extract-range.py Norgeskyst.txt 2 4 > coast.txt
|
|
|
|
This will extract polygons 2, 3, and 4 from the file Norgeskyst.txt and write
|
|
them to coast.txt. First polygon is 1, not 0.
|
|
"""
|
|
|
|
import sys
|
|
|
|
|
|
file_name = sys.argv[-3]
|
|
start_polygon = int(sys.argv[-2])
|
|
end_polygon = int(sys.argv[-1])
|
|
|
|
current_polygon = 0
|
|
with open(file_name, "r") as f:
|
|
_ = next(f)
|
|
_ = next(f)
|
|
while True:
|
|
try:
|
|
line = next(f)
|
|
except StopIteration:
|
|
break
|
|
n = int(line.split()[0])
|
|
current_polygon += 1
|
|
if current_polygon > end_polygon:
|
|
break
|
|
if start_polygon <= current_polygon <= end_polygon:
|
|
print(f"polygon {n}")
|
|
for _ in range(n):
|
|
line = next(f)
|
|
if start_polygon <= current_polygon <= end_polygon:
|
|
print(line.strip())
|