Skip to content

Commit

Permalink
internally, convert EOL to UNIX before processing
Browse files Browse the repository at this point in the history
  • Loading branch information
prjemian committed Jun 1, 2016
1 parent 893924f commit 50274fc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/spec2nexus/dev_extractSpecScan.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#args = 'data/CdOsO -s 1 1.1 48 -c HerixE H K L T_control_LS340 T_sample_LS340 ICO-C PIN-D PIN-C Seconds'
args = 'data/02_03_setup.dat -s 46 -c ar ay dy Epoch seconds I0 USAXS_PD'
# args = 'data/02_03_setup.dat -s 47 -c mr seconds I0 USAXS_PD'
args = 'data/xpcs_plugin_sample.spec -s 7 -c img_n Epoch ccdc'

for _ in args.split():
sys.argv.append(_)

Expand Down
10 changes: 7 additions & 3 deletions src/spec2nexus/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,9 @@ def read(self):

#------------------------------------------------------
# identify all header blocks: split buf on #E control lines
headers = []
headers = [] # caution: some files may have EOL = \r\n
for part in buf.split('\n#E '): # Identify the spec file header sections (usually just 1)
if len(part) == 0: continue # just in case
if len(part.strip()) == 0: continue # just in case DOS EOL
key = self.plugin_manager.getKey(part.splitlines()[0].strip())
if key != '#E':
headers.append('#E ' + part) # new header is starting
Expand Down Expand Up @@ -268,7 +268,11 @@ def _read_file_(self, spec_file_name):
if not is_spec_file(spec_file_name):
msg = 'Not a spec data file: ' + str(spec_file_name)
raise NotASpecDataFile(msg)
return buf

# caution: some files may have EOL = \r\n
# convert all '\r\n' to '\n', then all '\r' to '\n'

return buf.replace('\r\n', '\n').replace('\r', '\n')

def getScan(self, scan_number=0):
'''return the scan number indicated, None if not found'''
Expand Down

0 comments on commit 50274fc

Please sign in to comment.