2018-11-17 12:42:12 +05:30
|
|
|
#!/usr/bin/env python3
|
2014-05-27 13:38:10 +05:30
|
|
|
|
2019-06-14 16:33:30 +05:30
|
|
|
import os
|
|
|
|
import sys
|
2019-11-27 16:49:37 +05:30
|
|
|
from io import StringIO
|
2014-08-07 22:21:26 +05:30
|
|
|
from optparse import OptionParser
|
2019-06-14 16:33:30 +05:30
|
|
|
|
2014-08-07 22:21:26 +05:30
|
|
|
import damask
|
2014-05-27 13:38:10 +05:30
|
|
|
|
2019-06-14 16:33:30 +05:30
|
|
|
|
2016-01-27 22:36:00 +05:30
|
|
|
scriptName = os.path.splitext(os.path.basename(__file__))[0]
|
|
|
|
scriptID = ' '.join([scriptName,damask.version])
|
2014-05-27 13:38:10 +05:30
|
|
|
|
2019-06-14 16:33:30 +05:30
|
|
|
|
2014-05-27 13:38:10 +05:30
|
|
|
# --------------------------------------------------------------------
|
|
|
|
# MAIN
|
|
|
|
# --------------------------------------------------------------------
|
|
|
|
|
2019-02-17 12:30:26 +05:30
|
|
|
parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [ASCIItable(s)]', description = """
|
2015-08-08 00:33:26 +05:30
|
|
|
Uniformly scale column values by given factor.
|
2014-05-27 13:38:10 +05:30
|
|
|
|
2014-08-07 22:21:26 +05:30
|
|
|
""", version = scriptID)
|
|
|
|
|
2015-08-08 00:33:26 +05:30
|
|
|
parser.add_option('-l','--label',
|
|
|
|
dest = 'label',
|
|
|
|
action = 'extend', metavar = '<string LIST>',
|
|
|
|
help ='column(s) to scale')
|
|
|
|
parser.add_option('-f','--factor',
|
|
|
|
dest = 'factor',
|
|
|
|
action = 'extend', metavar='<float LIST>',
|
|
|
|
help = 'factor(s) per column')
|
|
|
|
|
|
|
|
parser.set_defaults(label = [],
|
|
|
|
)
|
2014-05-27 13:38:10 +05:30
|
|
|
|
|
|
|
(options,filenames) = parser.parse_args()
|
2019-11-27 16:38:23 +05:30
|
|
|
if filenames == []: filenames = [None]
|
2014-05-27 13:38:10 +05:30
|
|
|
|
2015-08-08 00:33:26 +05:30
|
|
|
if len(options.label) != len(options.factor):
|
2019-11-27 16:38:23 +05:30
|
|
|
parser.error('number of column labels and factors do not match.')
|
2014-05-27 13:38:10 +05:30
|
|
|
|
2019-11-27 16:38:23 +05:30
|
|
|
for name in filenames:
|
|
|
|
damask.util.report(scriptName,name)
|
2014-05-27 13:38:10 +05:30
|
|
|
|
2019-11-27 16:38:23 +05:30
|
|
|
table = damask.Table.from_ASCII(StringIO(''.join(sys.stdin.read())) if name is None else name)
|
|
|
|
for i,label in enumerate(options.label):
|
2019-12-05 10:40:27 +05:30
|
|
|
table.set(label,
|
|
|
|
table.get(label)*float(options.factor[i]),
|
|
|
|
scriptID+' '+' '.join(sys.argv[1:]))
|
2014-05-27 13:38:10 +05:30
|
|
|
|
2019-11-27 16:38:23 +05:30
|
|
|
table.to_ASCII(sys.stdout if name is None else name)
|