From 722788ef784a89c6fa33cd05706d58ccc99dcd43 Mon Sep 17 00:00:00 2001 From: Craig Warren Date: Mon, 25 Apr 2016 17:55:13 +0100 Subject: [PATCH] Improved parsing of float and int time values. --- gprMax/input_cmds_multiuse.py | 13 +++++++------ gprMax/input_cmds_singleuse.py | 19 +++++++++++-------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/gprMax/input_cmds_multiuse.py b/gprMax/input_cmds_multiuse.py index 21a40fe0..1f91a550 100644 --- a/gprMax/input_cmds_multiuse.py +++ b/gprMax/input_cmds_multiuse.py @@ -429,15 +429,16 @@ def process_multicmds(multicmds, G): dy = round_value(float(tmp[7])/G.dy) dz = round_value(float(tmp[8])/G.dz) + # If number of iterations given + try: + time = int(tmp[9]) # If real floating point value given - if '.' in tmp[9] or 'e' in tmp[9]: - if float(tmp[9]) > 0: - time = round_value((float(tmp[9]) / G.dt)) + 1 + except: + time = float(tmp[9]) + if time > 0: + time = round_value((tmp[9] / G.dt)) + 1 else: raise CmdInputError("'" + cmdname + ': ' + ' '.join(tmp) + "'" + ' time value must be greater than zero') - # If number of iterations given - else: - time = int(tmp[9]) if xs < 0 or xs > G.nx: raise CmdInputError("'" + cmdname + ': ' + ' '.join(tmp) + "'" + ' the lower x-coordinate {:g}m is not within the model domain'.format(xs * G.dx)) diff --git a/gprMax/input_cmds_singleuse.py b/gprMax/input_cmds_singleuse.py index 5d63b103..8fad0cb5 100644 --- a/gprMax/input_cmds_singleuse.py +++ b/gprMax/input_cmds_singleuse.py @@ -164,17 +164,20 @@ def process_singlecmds(singlecmds, G): if len(tmp) != 1: raise CmdInputError(cmd + ' requires exactly one parameter to specify the time window. Either in seconds or number of iterations.') tmp = tmp[0].lower() + + # If number of iterations given + try: + tmp = int(tmp) + G.timewindow = (tmp - 1) * G.dt + G.iterations = tmp # If real floating point value given - if '.' in tmp or 'e' in tmp: - if float(tmp) > 0: - G.timewindow = float(tmp) - G.iterations = round_value((float(tmp) / G.dt)) + 1 + except: + tmp = float(tmp) + if tmp > 0: + G.timewindow = tmp + G.iterations = round_value((tmp / G.dt)) + 1 else: raise CmdInputError(cmd + ' must have a value greater than zero') - # If number of iterations given - else: - G.timewindow = (int(tmp) - 1) * G.dt - G.iterations = int(tmp) if G.messages: print('Time window: {:g} secs ({} iterations)'.format(G.timewindow, G.iterations))