2019-02-15 04:54:09 +05:30
|
|
|
#!/usr/bin/env python3
|
2015-09-10 03:52:29 +05:30
|
|
|
# -*- coding: UTF-8 no BOM -*-
|
|
|
|
|
2016-03-01 22:55:14 +05:30
|
|
|
import os,sys
|
2015-09-10 03:52:29 +05:30
|
|
|
from optparse import OptionParser
|
|
|
|
import damask
|
|
|
|
|
2016-01-27 22:36:00 +05:30
|
|
|
scriptName = os.path.splitext(os.path.basename(__file__))[0]
|
|
|
|
scriptID = ' '.join([scriptName,damask.version])
|
2015-09-10 03:52:29 +05:30
|
|
|
|
|
|
|
# --------------------------------------------------------------------
|
|
|
|
# MAIN
|
|
|
|
# --------------------------------------------------------------------
|
|
|
|
|
|
|
|
parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [file[s]]', description = """
|
|
|
|
Append data of ASCIItable(s).
|
|
|
|
|
|
|
|
""", version = scriptID)
|
|
|
|
|
|
|
|
parser.add_option('-a', '--add','--table',
|
|
|
|
dest = 'table',
|
|
|
|
action = 'extend', metavar = '<string LIST>',
|
|
|
|
help = 'tables to add')
|
|
|
|
|
|
|
|
(options,filenames) = parser.parse_args()
|
|
|
|
|
|
|
|
# --- loop over input files -------------------------------------------------------------------------
|
|
|
|
|
|
|
|
if filenames == []: filenames = [None]
|
|
|
|
|
|
|
|
for name in filenames:
|
2016-05-17 20:42:26 +05:30
|
|
|
try: table = damask.ASCIItable(name = name,
|
|
|
|
buffered = False)
|
2015-09-10 03:52:29 +05:30
|
|
|
except: continue
|
|
|
|
|
2015-09-24 14:54:42 +05:30
|
|
|
damask.util.report(scriptName,name)
|
2016-05-17 20:42:26 +05:30
|
|
|
|
2015-09-10 03:52:29 +05:30
|
|
|
tables = []
|
|
|
|
for addTable in options.table:
|
2016-05-17 20:42:26 +05:30
|
|
|
try: tables.append(damask.ASCIItable(name = addTable,
|
|
|
|
buffered = False,
|
|
|
|
readonly = True)
|
|
|
|
)
|
2015-09-10 03:52:29 +05:30
|
|
|
except: continue
|
|
|
|
|
|
|
|
# ------------------------------------------ read headers ------------------------------------------
|
|
|
|
|
|
|
|
table.head_read()
|
2016-05-17 20:42:26 +05:30
|
|
|
for addTable in tables: addTable.head_read()
|
2015-09-10 03:52:29 +05:30
|
|
|
|
|
|
|
# ------------------------------------------ assemble header --------------------------------------
|
|
|
|
|
|
|
|
table.info_append(scriptID + '\t' + ' '.join(sys.argv[1:]))
|
|
|
|
|
2016-05-17 20:42:26 +05:30
|
|
|
for addTable in tables: table.labels_append(addTable.labels(raw = True)) # extend ASCII header with new labels
|
2015-09-10 03:52:29 +05:30
|
|
|
|
|
|
|
table.head_write()
|
|
|
|
|
|
|
|
# ------------------------------------------ process data ------------------------------------------
|
|
|
|
|
|
|
|
outputAlive = True
|
|
|
|
while outputAlive and table.data_read():
|
|
|
|
for addTable in tables:
|
|
|
|
outputAlive = addTable.data_read() # read next table's data
|
|
|
|
if not outputAlive: break
|
|
|
|
table.data_append(addTable.data) # append to master table
|
|
|
|
if outputAlive:
|
|
|
|
outputAlive = table.data_write() # output processed line
|
|
|
|
|
|
|
|
# ------------------------------------------ output finalization -----------------------------------
|
|
|
|
|
|
|
|
table.close() # close ASCII tables
|
|
|
|
for addTable in tables:
|
2015-09-11 18:25:43 +05:30
|
|
|
addTable.close()
|