DAMASK_EICMD/processing/pre/geom_unpack.py

41 lines
1.1 KiB
Python
Raw Normal View History

#!/usr/bin/env python3
import os
import sys
from optparse import OptionParser
2019-05-25 13:44:53 +05:30
from io import StringIO
2019-05-26 15:36:51 +05:30
import damask
2019-05-26 15:36:51 +05:30
scriptName = os.path.splitext(os.path.basename(__file__))[0]
scriptID = ' '.join([scriptName,damask.version])
2019-05-26 15:36:51 +05:30
#--------------------------------------------------------------------------------------------------
# MAIN
#--------------------------------------------------------------------------------------------------
2019-05-26 15:36:51 +05:30
parser = OptionParser(option_class=damask.extendableOption, usage='%prog [geomfile(s)]', description = """
Unpack ranges "a to b" and/or "n of x" multiples (exclusively in one line).
""", version = scriptID)
(options, filenames) = parser.parse_args()
if filenames == []: filenames = [None]
for name in filenames:
2019-05-25 13:44:53 +05:30
damask.util.report(scriptName,name)
geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name)
damask.util.croak(geom)
geom.add_comments(scriptID + ' ' + ' '.join(sys.argv[1:]))
if name is None:
2019-05-25 13:44:53 +05:30
sys.stdout.write(str(geom.show()))
else:
geom.to_file(name)