added option to multiply values instead of summing them

This commit is contained in:
Philip Eisenlohr 2019-10-17 13:19:51 -04:00
parent e074bf7842
commit 03a3edc128
1 changed files with 13 additions and 5 deletions

View File

@ -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:
@ -39,7 +43,7 @@ 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
if options.product:
for i,col in enumerate(mask): for i,col in enumerate(mask):
cumulated[i] += float(table.data[col]) # cumulate values 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