DAMASK_EICMD/processing/post/viewTable.py

90 lines
3.3 KiB
Python
Raw Normal View History

#!/usr/bin/env python3
import os
from optparse import OptionParser
import damask
scriptName = os.path.splitext(os.path.basename(__file__))[0]
scriptID = ' '.join([scriptName,damask.version])
# --------------------------------------------------------------------
# MAIN
# --------------------------------------------------------------------
2019-02-16 22:11:56 +05:30
parser = OptionParser(usage='%prog options [ASCIItable(s)]', description = """
Show components of given ASCIItable(s).
""", version = scriptID)
parser.add_option('-a','--head',
dest = 'head',
action = 'store_true',
help = 'output complete header (info + labels)')
parser.add_option('-i','--info',
dest = 'info',
action = 'store_true',
help = 'output info lines')
parser.add_option('-l','--labels',
dest = 'labels',
action = 'store_true',
help = 'output labels')
parser.add_option('-d','--data',
dest = 'data',
action = 'store_true',
help = 'output data')
parser.add_option('-t','--table',
dest = 'table',
action = 'store_true',
help = 'output heading line for proper ASCIItable format')
parser.add_option('--nolabels',
dest = 'labeled',
action = 'store_false',
help = 'table has no labels')
parser.set_defaults(table = False,
head = False,
info = False,
labels = False,
data = False,
labeled = True,
)
2015-05-10 16:28:32 +05:30
(options,filenames) = parser.parse_args()
# --- loop over input files -------------------------------------------------------------------------
2015-08-18 20:07:32 +05:30
if filenames == []: filenames = [None]
for name in filenames:
2015-08-18 20:07:32 +05:30
try:
table = damask.ASCIItable(name = name,
buffered = False, labeled = options.labeled, readonly = True)
except: continue
details = ', '.join(
(['header'] if options.table else []) +
(['info'] if options.head or options.info else []) +
(['labels'] if options.head or options.labels else []) +
(['data'] if options.data else []) +
[]
)
2019-01-24 07:26:01 +05:30
damask.util.report(scriptName,(name if name is not None else '') + ('' if details == '' else ' -- '+details))
# ------------------------------------------ output head ---------------------------------------
table.head_read()
if not (options.head or options.info): table.info_clear()
if not (options.head or (options.labels and options.labeled)): table.labels_clear()
table.head_write(header = options.table)
# ------------------------------------------ output data ---------------------------------------
outputAlive = options.data
2015-05-10 16:28:32 +05:30
while outputAlive and table.data_read(): # read next data line of ASCII table
outputAlive = table.data_write() # output line
table.close()