superfluous since same can be (even more flexibly) accomplished with:

reLabel -l old -s old+tag
This commit is contained in:
Philip Eisenlohr 2015-07-26 00:41:42 +00:00
parent 0db33f21b5
commit 020a3e2634
1 changed files with 0 additions and 79 deletions

View File

@ -1,79 +0,0 @@
#!/usr/bin/env python
# -*- coding: UTF-8 no BOM -*-
import os,re,sys,math,string
import damask
from optparse import OptionParser
scriptID = string.replace('$Id$','\n','\\n')
scriptName = os.path.splitext(scriptID.split()[1])[0]
# --------------------------------------------------------------------
# MAIN
# --------------------------------------------------------------------
parser = OptionParser(option_class=damask.extendableOption, usage='%prog [options] dfile[s]', description = """
Tag scalar, vectorial, and/or tensorial data header labels by specified suffix.
""", version = scriptID)
parser.add_option('-t','--tag', dest='tag', metavar='string',
help='tag to use as suffix for labels')
parser.add_option('-l','--label', dest='label', action='extend', metavar='<string LIST>',
help='columns to tag')
parser.set_defaults(tag = '')
parser.set_defaults(label = [])
(options,filenames) = parser.parse_args()
# --- loop over input files -------------------------------------------------------------------------
if filenames == []:
filenames = ['STDIN']
for name in filenames:
if name == 'STDIN':
file = {'name':'STDIN', 'input':sys.stdin, 'output':sys.stdout, 'croak':sys.stderr}
file['croak'].write('\033[1m'+scriptName+'\033[0m\n')
else:
if not os.path.exists(name): continue
file = {'name':name, 'input':open(name), 'output':open(name+'_tmp','w'), 'croak':sys.stderr}
file['croak'].write('\033[1m'+scriptName+'\033[0m: '+file['name']+'\n')
table = damask.ASCIItable(file['input'],file['output'],buffered=False) # make unbuffered ASCII_table
table.head_read()
table.info_append(scriptID + '\t' + ' '.join(sys.argv[1:])) # read ASCII header info
# ------------------------------------------ process labels ---------------------------------------
if options.label == []: # default to tagging all labels
for i,label in enumerate(table.labels):
table.labels[i] += options.tag
else: # tag individual candidates
indices = table.label_index (options.label)
dimensions = table.label_dimension(options.label)
for i,index in enumerate(indices):
if index == -1:
file['croak'].write('label %s not present...\n'%options.label[i])
else:
for j in xrange(dimensions[i]):
table.labels[index+j] += options.tag
# ------------------------------------------ assemble header ---------------------------------------
table.head_write()
# ------------------------------------------ process data ---------------------------------------
outputAlive = True
while outputAlive and table.data_read(): # read next data line of ASCII table
outputAlive = table.data_write() # output processed line
# ------------------------------------------ output result ---------------------------------------
outputAlive and table.output_flush() # just in case of buffered ASCII table
table.close() # close ASCII tables
if file['name'] != 'STDIN':
os.rename(file['name']+'_tmp',file['name']) # overwrite old one with tmp new