From 10e31e489a402ef6084ed3c3439e57d40629ef39 Mon Sep 17 00:00:00 2001 From: Philip Eisenlohr Date: Sun, 24 Apr 2016 13:06:37 -0500 Subject: [PATCH] new script to add arbitrary lines to ASCIItable header --- processing/post/addInfo.py | 56 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100755 processing/post/addInfo.py diff --git a/processing/post/addInfo.py b/processing/post/addInfo.py new file mode 100755 index 000000000..5d48c25df --- /dev/null +++ b/processing/post/addInfo.py @@ -0,0 +1,56 @@ +#!/usr/bin/env python +# -*- 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 +# -------------------------------------------------------------------- + +parser = OptionParser(option_class=damask.extendableOption, usage='%prog options file[s]', description = """ +Add info lines to ASCIItable header. + +""", version = scriptID) + +parser.add_option('-i', + '--info', + dest = 'info', action = 'extend', metavar = '', + help = 'items to add') + +parser.set_defaults(info = [], + ) + +(options,filenames) = parser.parse_args() + +# --- 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