fixed bug when column was referenced multiple time in a formula.
changed column tagging character to '#' ('$' gave some trouble on the shell...)
This commit is contained in:
parent
f8013ce4bf
commit
3228cf563c
|
@ -30,6 +30,7 @@ class extendableOption(Option):
|
||||||
parser = OptionParser(option_class=extendableOption, usage='%prog options [file[s]]', description = """
|
parser = OptionParser(option_class=extendableOption, usage='%prog options [file[s]]', description = """
|
||||||
Add column(s) with derived values according to user defined arithmetic operation between column(s).
|
Add column(s) with derived values according to user defined arithmetic operation between column(s).
|
||||||
|
|
||||||
|
Example: distance to IP coordinates -- "math.sqrt( #ip.x#**2 + #ip.y#**2 + #ip.z#**2 )"
|
||||||
""" + string.replace('$Id$','\n','\\n')
|
""" + string.replace('$Id$','\n','\\n')
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -72,17 +73,17 @@ for file in files:
|
||||||
for label,formula in zip(options.labels,options.formulas):
|
for label,formula in zip(options.labels,options.formulas):
|
||||||
table.labels_append(label)
|
table.labels_append(label)
|
||||||
interpolator = []
|
interpolator = []
|
||||||
operands = re.findall(r'\$(.+?)\$',formula)
|
operands = re.findall(r'#(.+?)#',formula)
|
||||||
for operand in operands:
|
for operand in operands:
|
||||||
if not operand in column:
|
if not operand in column:
|
||||||
try:
|
try:
|
||||||
column[operand] = table.labels.index(operand)
|
column[operand] = table.labels.index(operand)
|
||||||
except:
|
except:
|
||||||
parser.error('column %s not found...\n'%operand)
|
parser.error('column %s not found...\n'%operand)
|
||||||
interpolator += ['float(table.data[%i])'%column[operand]]
|
interpolator += ['float(table.data[%i])'%column[operand]]
|
||||||
for operand in operands:
|
for operand in operands:
|
||||||
formula = formula.replace('$'+operand+'$','%e')
|
formula = formula.replace('#'+operand+'#','%e')
|
||||||
evaluator[label] = "'" + formula + "'%(" + ','.join(interpolator) + ")"
|
evaluator[label] = "'" + formula + "'%(" + ','.join(interpolator) + ")"
|
||||||
|
|
||||||
# ------------------------------------------ assemble header ---------------------------------------
|
# ------------------------------------------ assemble header ---------------------------------------
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue