Skip to content

Commit

Permalink
fixes #30, try a couple things before failing on #L and #X lines
Browse files Browse the repository at this point in the history
  • Loading branch information
prjemian committed Jan 25, 2015
1 parent 954ec8f commit 23bed05
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/spec2nexus/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
# The full license is in the file LICENSE.txt, distributed with this software.
#-----------------------------------------------------------------------------

__version__ = '2015.0113.0'
__version__ = '2015.0125.0'
__release__ = __version__
__author__ = 'Pete R. Jemian'
__email__ = 'prjemian@gmail.com'
__copyright__ = '2014, Pete R. Jemian'
__copyright__ = '2015, Pete R. Jemian'

__package_name__ = 'spec2nexus'
__license_url__ = 'http://creativecommons.org/licenses/by/4.0/deed.en_US'
Expand Down
34 changes: 22 additions & 12 deletions src/spec2nexus/plugins/spec_common_spec2nexus.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,8 @@ def process(self, part, spec_obj, *args, **kws):
scan = SpecDataFileScan(spec_obj.headers[-1], part, parent=spec_obj)
text = part.splitlines()[0].strip()
scan.S = strip_first_word(text)
pos = scan.S.find(' ')
scan.scanNum = int(scan.S[0:pos])
scan.scanCmd = strip_first_word(scan.S[pos+1:])
scan.scanNum = int(scan.S.split()[0])
scan.scanCmd = strip_first_word(scan.S)
if scan.scanNum in spec_obj.scans:
msg = str(scan.scanNum) + ' in ' + spec_obj.fileName
raise DuplicateSpecScanNumber(msg)
Expand Down Expand Up @@ -359,6 +358,15 @@ class SPEC_Labels(ControlLineHandler):
def process(self, text, scan, *args, **kws):
# Some folks use more than two spaces! Use regular expression(re) module
scan.L = re.split(" +", strip_first_word(text))

if len(scan.L) == 1 and hasattr(scan, 'N') and scan.N[0] > 1:
# BUT: some folks only use a single-space as a separator!
# perhaps #L was written with single-space separators.?
# Unusual for scan to have only 1 column, but possible
labels = strip_first_word(text).split()
if len(labels) == scan.N[0]:
scan.L = labels

scan.column_first = scan.L[0]
scan.column_last = scan.L[-1]

Expand Down Expand Up @@ -599,7 +607,7 @@ def writer(self, h5parent, writer, scan, *args, **kws):

class SPEC_TemperatureSetPoint(ControlLineHandler):
'''
**#X** -- Temperature
**#X** -- Temperature Set Point (desired temperature)
The default declaration of the #X control line is written::
Expand All @@ -626,16 +634,18 @@ def Fheader '_cols++;printf("#X %gKohm (%gC)\\n",TEMP_SP,DEGC_SP)'
'''

key = '#X'
# TODO: Needs an example data file to test

def process(self, text, scan, *args, **kws):
fmt = "#X %fKohm (%fC)"
try:
# This looks fragile!
scan.TEMP_SP, scan.DEGC_SP = scanf(fmt, text)
scan.addH5writer(self.key, self.writer)
except:
pass
# Try a list of formats until one succeeds
format_list = ["#X %fKohm (%fC)",
# "#X %g %g", # note: %g specifier is not available
"#X %f %f",
]
for fmt in format_list:
result = scanf(fmt, text)
if result is not None:
scan.TEMP_SP, scan.DEGC_SP = result
scan.addH5writer(self.key, self.writer)

def writer(self, h5parent, writer, scan, nxclass=None, *args, **kws):
'''Describe how to store this data in an HDF5 NeXus file'''
Expand Down

0 comments on commit 23bed05

Please sign in to comment.