2018-12-09 12:37:40 +05:30
|
|
|
#!/usr/bin/env python3
|
2016-04-24 23:36:37 +05:30
|
|
|
# -*- coding: UTF-8 no BOM -*-
|
|
|
|
|
|
|
|
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(option_class=damask.extendableOption, usage='%prog options [ASCIItable(s)]', description = """
|
2016-04-24 23:36:37 +05:30
|
|
|
Add info lines to ASCIItable header.
|
|
|
|
|
|
|
|
""", version = scriptID)
|
|
|
|
|
|
|
|
parser.add_option('-i',
|
|
|
|
'--info',
|
|
|
|
dest = 'info', action = 'extend', metavar = '<string LIST>',
|
|
|
|
help = 'items to add')
|
|
|
|
|
|
|
|
|
|
|
|
(options,filenames) = parser.parse_args()
|
|
|
|
|
2019-02-16 19:23:56 +05:30
|
|
|
if options.info is None:
|
|
|
|
parser.error('no info specified.')
|
|
|
|
|
2016-04-24 23:36:37 +05:30
|
|
|
# --- loop over input files ------------------------------------------------------------------------
|
|
|
|
|
|
|
|
if filenames == []: filenames = [None]
|
|
|
|
|
|
|
|
for name in filenames:
|
|
|
|
try: table = damask.ASCIItable(name = name,
|
|
|
|
buffered = False)
|
|
|
|
except: continue
|
|
|
|
damask.util.report(scriptName,name)
|
|
|
|
|
|
|
|
# ------------------------------------------ assemble header ---------------------------------------
|
|
|
|
|
|
|
|
table.head_read()
|
|
|
|
table.info_append(options.info)
|
|
|
|
table.head_write()
|
|
|
|
|
|
|
|
# ------------------------------------------ pass through data -------------------------------------
|
|
|
|
|
|
|
|
outputAlive = True
|
|
|
|
|
|
|
|
while outputAlive and table.data_read(): # read next data line of ASCII table
|
|
|
|
outputAlive = table.data_write() # output processed line
|
|
|
|
|
|
|
|
# ------------------------------------------ output finalization -----------------------------------
|
|
|
|
|
|
|
|
table.close() # close ASCII tables
|