Improved parsing of float and int time values.

这个提交包含在:
Craig Warren
2016-04-25 17:55:13 +01:00
父节点 02547a8c38
当前提交 722788ef78
共有 2 个文件被更改,包括 18 次插入14 次删除

查看文件

@@ -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))

查看文件

@@ -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))