|
17 | 17 |
|
18 | 18 | verbose = False |
19 | 19 |
|
| 20 | +temp_var_count = 0 |
| 21 | + |
| 22 | +def get_new_temp_var(): |
| 23 | + global temp_var_count |
| 24 | + tv = 'TMP__%i'%temp_var_count |
| 25 | + temp_var_count+=1 |
| 26 | + return tv |
| 27 | + |
20 | 28 | def _closing_bracket_index(expr, open_bracket_index): |
21 | 29 | depth = 0 |
22 | 30 | logger.debug('Looking for closing bracket of %s from %i, i.e. %s'%(expr, open_bracket_index, expr[open_bracket_index:])) |
@@ -123,8 +131,35 @@ def parse_script(file_path): |
123 | 131 | else: |
124 | 132 | # "Normal" variable... |
125 | 133 | expr = value.strip() |
| 134 | + |
| 135 | + #### This should be refactored to make it 'infinitely' recursive... |
126 | 136 | if 'if' in expr and 'else' in expr: |
127 | | - data["conditional_derived_variables"][key.strip()] = _split_if_then_else(expr) |
| 137 | + var_0 = key.strip() |
| 138 | + ite_0 = _split_if_then_else(expr) |
| 139 | + |
| 140 | + if 'if' in ite_0['value_true']: |
| 141 | + ite_1 = _split_if_then_else(ite_0['value_true']) |
| 142 | + new_var_name1 = get_new_temp_var() |
| 143 | + |
| 144 | + if 'if' in ite_1['value_false']: |
| 145 | + ite_2 = _split_if_then_else(ite_1['value_false']) |
| 146 | + new_var_name2 = get_new_temp_var() |
| 147 | + |
| 148 | + if 'if' in ite_2['value_true']: |
| 149 | + ite_3 = _split_if_then_else(ite_2['value_true']) |
| 150 | + new_var_name3 = get_new_temp_var() |
| 151 | + |
| 152 | + data["conditional_derived_variables"][new_var_name3] = ite_3 |
| 153 | + ite_2['value_true'] = new_var_name3 |
| 154 | + |
| 155 | + data["conditional_derived_variables"][new_var_name2] = ite_2 |
| 156 | + ite_1['value_false'] = new_var_name2 |
| 157 | + |
| 158 | + data["conditional_derived_variables"][var_0] = ite_0 |
| 159 | + data["conditional_derived_variables"][new_var_name1] = ite_1 |
| 160 | + ite_0['value_true'] = new_var_name1 |
| 161 | + |
| 162 | + data["conditional_derived_variables"][var_0] = ite_0 |
128 | 163 | else: |
129 | 164 | k = key.strip() |
130 | 165 | if ' ' in k: |
@@ -601,7 +636,12 @@ def run_xpp_file(filename, plot, show_plot_already=True, plot_separately={}): |
601 | 636 | try: |
602 | 637 | ret_string = sp.check_output( |
603 | 638 | cmds, cwd=cwd, shell=False, stderr=sp.STDOUT |
604 | | - ) |
| 639 | + ).decode("utf-8") |
| 640 | + |
| 641 | + xpp_error_phrases = ['Error allocating', 'illegal expression'] |
| 642 | + for err in xpp_error_phrases: |
| 643 | + if err in ret_string: |
| 644 | + raise Exception("Command: %s failed! Full output from XPP: \n==========================\n%s\n==========================" % (cmds, ret_string)) |
605 | 645 | logger.info( |
606 | 646 | "Commands: %s completed successfully" % (cmds) |
607 | 647 | ) |
|
0 commit comments