2018-11-17 12:42:12 +05:30
|
|
|
#!/usr/bin/env python3
|
2014-04-02 00:11:14 +05:30
|
|
|
# -*- coding: UTF-8 no BOM -*-
|
2012-11-30 13:56:13 +05:30
|
|
|
|
2015-09-24 14:54:42 +05:30
|
|
|
import os
|
2012-11-30 13:56:13 +05:30
|
|
|
from optparse import OptionParser
|
2014-10-16 20:26:44 +05:30
|
|
|
import damask
|
2012-11-30 13:56:13 +05:30
|
|
|
|
2016-01-27 22:36:00 +05:30
|
|
|
scriptName = os.path.splitext(os.path.basename(__file__))[0]
|
|
|
|
scriptID = ' '.join([scriptName,damask.version])
|
2012-11-30 13:56:13 +05:30
|
|
|
|
|
|
|
# --------------------------------------------------------------------
|
|
|
|
# MAIN
|
|
|
|
# --------------------------------------------------------------------
|
|
|
|
|
2019-02-16 22:11:56 +05:30
|
|
|
parser = OptionParser(usage='%prog options [ASCIItable(s)]', description = """
|
2012-11-30 13:56:13 +05:30
|
|
|
Show components of given ASCIItable(s).
|
2014-10-16 20:26:44 +05:30
|
|
|
|
|
|
|
""", version = scriptID)
|
2012-11-30 13:56:13 +05:30
|
|
|
|
|
|
|
|
2015-08-08 00:33:26 +05:30
|
|
|
parser.add_option('-a','--head',
|
|
|
|
dest = 'head',
|
|
|
|
action = 'store_true',
|
2015-12-04 10:01:53 +05:30
|
|
|
help = 'output complete header (info + labels)')
|
2015-08-08 00:33:26 +05:30
|
|
|
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')
|
2015-12-04 10:01:53 +05:30
|
|
|
parser.add_option('-d','--data',
|
|
|
|
dest = 'data',
|
2015-08-08 00:33:26 +05:30
|
|
|
action = 'store_true',
|
2015-12-04 10:01:53 +05:30
|
|
|
help = 'output data')
|
2015-08-08 00:33:26 +05:30
|
|
|
parser.add_option('-t','--table',
|
|
|
|
dest = 'table',
|
|
|
|
action = 'store_true',
|
|
|
|
help = 'output heading line for proper ASCIItable format')
|
2015-12-04 10:01:53 +05:30
|
|
|
parser.add_option('--nolabels',
|
|
|
|
dest = 'labeled',
|
|
|
|
action = 'store_false',
|
|
|
|
help = 'table has no labels')
|
|
|
|
parser.set_defaults(table = False,
|
|
|
|
head = False,
|
2015-08-08 00:33:26 +05:30
|
|
|
info = False,
|
|
|
|
labels = False,
|
|
|
|
data = False,
|
|
|
|
labeled = True,
|
|
|
|
)
|
2012-11-30 13:56:13 +05:30
|
|
|
|
2015-05-10 16:28:32 +05:30
|
|
|
(options,filenames) = parser.parse_args()
|
2012-11-30 13:56:13 +05:30
|
|
|
|
2015-08-08 00:33:26 +05:30
|
|
|
# --- loop over input files -------------------------------------------------------------------------
|
2012-11-30 13:56:13 +05:30
|
|
|
|
2015-08-18 20:07:32 +05:30
|
|
|
if filenames == []: filenames = [None]
|
2012-11-30 13:56:13 +05:30
|
|
|
|
2015-08-08 00:33:26 +05:30
|
|
|
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
|
2019-01-05 03:04:04 +05:30
|
|
|
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))
|
2012-11-30 13:56:13 +05:30
|
|
|
|
2015-08-08 00:33:26 +05:30
|
|
|
# ------------------------------------------ output head ---------------------------------------
|
2013-09-09 19:42:00 +05:30
|
|
|
|
2015-08-08 00:33:26 +05:30
|
|
|
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)
|
2014-01-30 02:43:36 +05:30
|
|
|
|
|
|
|
# ------------------------------------------ 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
|
2012-11-30 13:56:13 +05:30
|
|
|
|
2015-08-08 00:33:26 +05:30
|
|
|
table.close()
|