DAMASK_EICMD/processing/pre/geom_unpack.py

52 lines
1.6 KiB
Python
Raw Normal View History

#!/usr/bin/env python3
# -*- coding: UTF-8 no BOM -*-
import os
import sys
from optparse import OptionParser
2019-05-25 13:44:53 +05:30
from io import StringIO
import damask
scriptName = os.path.splitext(os.path.basename(__file__))[0]
scriptID = ' '.join([scriptName,damask.version])
#--------------------------------------------------------------------------------------------------
# MAIN
#--------------------------------------------------------------------------------------------------
parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [file[s]]', description = """
Unpack geometry files containing ranges "a to b" and/or "n of x" multiples (exclusively in one line).
""", version = scriptID)
parser.add_option('-1', '--onedimensional',
dest = 'oneD',
action = 'store_true',
help = 'output geom file with one-dimensional data arrangement')
parser.set_defaults(oneD = False,
)
(options, filenames) = parser.parse_args()
# --- loop over input files -------------------------------------------------------------------------
if filenames == []: filenames = [None]
for name in filenames:
2019-05-25 13:44:53 +05:30
damask.util.report(scriptName,name)
if name is None:
virt_file = StringIO(''.join(sys.stdin.read()))
geom = damask.Geom.from_file(virt_file)
else:
geom = damask.Geom.from_file(name)
geom.add_comment(scriptID + ' ' + ' '.join(sys.argv[1:]))
2019-05-25 13:44:53 +05:30
damask.util.croak(geom)
if name is None:
2019-05-25 13:44:53 +05:30
sys.stdout.write(str(geom.show()))
else:
geom.to_file(name)