DAMASK_EICMD/processing/post/addTable.py

45 lines
1.3 KiB
Python
Raw Normal View History

#!/usr/bin/env python3
2019-06-14 02:44:40 +05:30
import os
import sys
2020-01-12 04:44:35 +05:30
from io import StringIO
from optparse import OptionParser
2019-06-14 02:44:40 +05:30
import damask
scriptName = os.path.splitext(os.path.basename(__file__))[0]
scriptID = ' '.join([scriptName,damask.version])
2019-06-14 02:44:40 +05:30
# --------------------------------------------------------------------
# MAIN
# --------------------------------------------------------------------
2019-02-16 22:55:41 +05:30
parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [ASCIItable(s)]', description = """
2019-06-14 02:44:40 +05:30
Append data of ASCIItable(s) column-wise.
""", version = scriptID)
parser.add_option('-a', '--add','--table',
dest = 'table',
action = 'extend', metavar = '<string LIST>',
help = 'tables to add')
(options,filenames) = parser.parse_args()
2019-12-23 02:53:48 +05:30
if filenames == []: filenames = [None]
2019-02-16 19:23:56 +05:30
if options.table is None:
2019-12-23 02:53:48 +05:30
parser.error('no table specified.')
for name in filenames:
2019-12-23 02:53:48 +05:30
damask.util.report(scriptName,name)
2019-12-23 02:53:48 +05:30
table = damask.Table.from_ASCII(StringIO(''.join(sys.stdin.read())) if name is None else name)
2019-12-23 02:53:48 +05:30
for addTable in options.table:
table2 = damask.Table.from_ASCII(addTable)
table2.data = table2.data[:table.data.shape[0]]
table.join(table2)
2019-12-23 02:53:48 +05:30
table.to_ASCII(sys.stdout if name is None else name)