Skip to content

Commit 86aaf21

Browse files
committed
Fix mccode.dat output for case of "scanning filenames" with -L
1 parent bd9c628 commit 86aaf21

1 file changed

Lines changed: 21 additions & 3 deletions

File tree

tools/Python/mcrun/optimisation.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ def build_header(options, params, intervals, detectors):
2929
# ylabel: 'Intensity'
3030
# xvars: %(xvars)s
3131
# yvars: %(yvars)s
32+
# list: %(xvals)s
3233
# xlimits: %(xmin)s %(xmax)s
3334
# filename: %(filename)s
3435
# variables: %(variables)s
@@ -41,8 +42,12 @@ def build_header(options, params, intervals, detectors):
4142
hdrparams = {key.lstrip('-') for key in params}
4243
xvars = ', '.join(hdrparams)
4344
lst = intervals[list(params)[0]]
44-
xmin = min(lst)
45-
xmax = max(lst)
45+
if options.list:
46+
xmin=1
47+
xmax=len(lst)
48+
else:
49+
xmin = min(lst)
50+
xmax = max(lst)
4651
# Get Numpoints from length of -L list
4752
N = len(lst)
4853
# ... or using options.numponts if in fact a normal scan
@@ -77,6 +82,8 @@ def build_header(options, params, intervals, detectors):
7782
'xvars': xvars,
7883
'yvars': ' '.join('(%s_I,%s_ERR)' % (d, d) for d in detectors),
7984

85+
'xvals': str(lst),
86+
8087
'xmin': xmin,
8188
'xmax': xmax,
8289

@@ -308,7 +315,18 @@ def run(self):
308315
LOG.info("Wrote headers")
309316
LOG.info(f"Write step detectors line into {self.outfile}")
310317
values = ['%s %s' % (d.intensity, d.error) for d in detectors]
311-
line = '%s %s\n' % (' '.join(map(str, par_values)), ' '.join(values))
318+
319+
# Normal equidistant scan
320+
if not self.mcstas.options.list:
321+
line = '%s %s\n' % (' '.join(map(str, par_values)), ' '.join(values))
322+
else:
323+
try:
324+
# Check if parameters are numeric/float
325+
par_floats = [float(x) for x in par_values]
326+
line = '%s %s\n' % (' '.join(map(str, par_floats)), ' '.join(values))
327+
except:
328+
# otherwise use simple 'index' (may be scanning e.g. a filename)
329+
line = '%s %s\n' % (str(i), ' '.join(values))
312330
outfile.write(line)
313331
outfile.flush()
314332

0 commit comments

Comments
 (0)