using central functionality

This commit is contained in:
Martin Diehl 2019-12-22 22:23:48 +01:00
parent 644967329f
commit db14baec41
2 changed files with 19 additions and 91 deletions

View File

@ -25,56 +25,19 @@ parser.add_option('-a', '--add','--table',
help = 'tables to add') help = 'tables to add')
(options,filenames) = parser.parse_args() (options,filenames) = parser.parse_args()
if filenames == []: filenames = [None]
if options.table is None: if options.table is None:
parser.error('no table specified.') parser.error('no table specified.')
# --- loop over input files -------------------------------------------------------------------------
if filenames == []: filenames = [None]
for name in filenames: for name in filenames:
try: table = damask.ASCIItable(name = name,
buffered = False)
except: continue
damask.util.report(scriptName,name) damask.util.report(scriptName,name)
tables = [] table = damask.Table.from_ASCII(StringIO(''.join(sys.stdin.read())) if name is None else name)
for addTable in options.table: for addTable in options.table:
try: tables.append(damask.ASCIItable(name = addTable, table2 = damask.Table.from_ASCII(addTable)
buffered = False, table2.data = table2.data[:table.data.shape[0]]
readonly = True) table.join(table2)
)
except: continue
# ------------------------------------------ read headers ------------------------------------------ table.to_ASCII(sys.stdout if name is None else name)
table.head_read()
for addTable in tables: addTable.head_read()
# ------------------------------------------ assemble header --------------------------------------
table.info_append(scriptID + '\t' + ' '.join(sys.argv[1:]))
for addTable in tables: table.labels_append(addTable.labels(raw = True)) # extend ASCII header with new labels
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:
addTable.close()

View File

@ -27,53 +27,18 @@ parser.add_option('-a', '--add','--table',
help = 'tables to add') help = 'tables to add')
(options,filenames) = parser.parse_args() (options,filenames) = parser.parse_args()
if filenames == []: filenames = [None]
if options.table is None: if options.table is None:
parser.error('no table specified.') parser.error('no table specified.')
# --- loop over input files -------------------------------------------------------------------------
if filenames == []: filenames = [None]
for name in filenames: for name in filenames:
try: table = damask.ASCIItable(name = name,
buffered = False)
except: continue
damask.util.report(scriptName,name) damask.util.report(scriptName,name)
tables = [] table = damask.Table.from_ASCII(StringIO(''.join(sys.stdin.read())) if name is None else name)
for addTable in options.table:
try: tables.append(damask.ASCIItable(name = addTable,
buffered = False,
readonly = True)
)
except: continue
# ------------------------------------------ read headers ------------------------------------------ for growTable in options.table:
table2 = damask.Table.from_ASCII(growTable)
table.append(table2)
table.head_read() table.to_ASCII(sys.stdout if name is None else name)
for addTable in tables: addTable.head_read()
# ------------------------------------------ assemble header --------------------------------------
table.info_append(scriptID + '\t' + ' '.join(sys.argv[1:]))
table.head_write()
# ------------------------------------------ process data ------------------------------------------
table.data_readArray()
data = table.data
for addTable in tables:
addTable.data_readArray(table.labels(raw = True))
data = np.vstack((data,addTable.data))
table.data = data
table.data_writeArray()
# ------------------------------------------ output finalization -----------------------------------
table.close() # close ASCII tables
for addTable in tables:
addTable.close()