Skip to content

Commit be46b90

Browse files
authored
Merge pull request #2377 from mccode-dev/fix-broken-listmode-mcrun
mcrun -L list was broken, fixed here by (re-)calculating number of elements …
2 parents 451df4f + 86aaf21 commit be46b90

2 files changed

Lines changed: 24 additions & 3 deletions

File tree

tools/Python/mcrun/mcrun.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,9 @@ def main():
600600

601601
# Parameters for linear scanning present
602602
if interval_points and (options.scan_split is None):
603+
# In case of list, update with number of list points
604+
if options.list:
605+
options.numpoints=len(pointlist[0])
603606
scanner = Scanner(mcstas, intervals)
604607
scanner.set_points(interval_points)
605608
if (not options.dir == ''):

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)