added option to multiply values instead of summing them
This commit is contained in:
parent
e074bf7842
commit
03a3edc128
|
@ -26,6 +26,10 @@ parser.add_option('-l','--label',
|
||||||
action = 'extend', metavar = '<string LIST>',
|
action = 'extend', metavar = '<string LIST>',
|
||||||
help = 'columns to cumulate')
|
help = 'columns to cumulate')
|
||||||
|
|
||||||
|
parser.add_option('-p','--product',
|
||||||
|
dest='product', action = 'store_true',
|
||||||
|
help = 'product of values instead of sum')
|
||||||
|
|
||||||
(options,filenames) = parser.parse_args()
|
(options,filenames) = parser.parse_args()
|
||||||
|
|
||||||
if options.label is None:
|
if options.label is None:
|
||||||
|
@ -38,8 +42,8 @@ if filenames == []: filenames = [None]
|
||||||
for name in filenames:
|
for name in filenames:
|
||||||
try:
|
try:
|
||||||
table = damask.ASCIItable(name = name,
|
table = damask.ASCIItable(name = name,
|
||||||
buffered = False)
|
buffered = False)
|
||||||
except: continue
|
except IOError: continue
|
||||||
damask.util.report(scriptName,name)
|
damask.util.report(scriptName,name)
|
||||||
|
|
||||||
# ------------------------------------------ read header ------------------------------------------
|
# ------------------------------------------ read header ------------------------------------------
|
||||||
|
@ -76,12 +80,16 @@ for name in filenames:
|
||||||
# ------------------------------------------ process data ------------------------------------------
|
# ------------------------------------------ process data ------------------------------------------
|
||||||
mask = []
|
mask = []
|
||||||
for col,dim in zip(columns,dims): mask += range(col,col+dim) # isolate data columns to cumulate
|
for col,dim in zip(columns,dims): mask += range(col,col+dim) # isolate data columns to cumulate
|
||||||
cumulated = np.zeros(len(mask),dtype=float) # prepare output field
|
cumulated = np.ones(len(mask),dtype=float) * (1 if options.product else 0) # prepare output field
|
||||||
|
|
||||||
outputAlive = True
|
outputAlive = True
|
||||||
while outputAlive and table.data_read(): # read next data line of ASCII table
|
while outputAlive and table.data_read(): # read next data line of ASCII table
|
||||||
for i,col in enumerate(mask):
|
if options.product:
|
||||||
cumulated[i] += float(table.data[col]) # cumulate values
|
for i,col in enumerate(mask):
|
||||||
|
cumulated[i] *= float(table.data[col]) # cumulate values (multiplication)
|
||||||
|
else:
|
||||||
|
for i,col in enumerate(mask):
|
||||||
|
cumulated[i] += float(table.data[col]) # cumulate values (addition)
|
||||||
table.data_append(cumulated)
|
table.data_append(cumulated)
|
||||||
|
|
||||||
outputAlive = table.data_write() # output processed line
|
outputAlive = table.data_write() # output processed line
|
||||||
|
|
Loading…
Reference in New Issue