-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathread_xsams.py
executable file
·51 lines (46 loc) · 1.54 KB
/
read_xsams.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import sys
from units_parser import *
from units import *
from xsams_units_dims import *
from xml.dom.minidom import parse
try:
xsams_file = sys.argv[1]
except IndexError:
print 'usage is:'
print '%s <xsams-file>' % sys.argv[0]
sys.exit(0)
#xsams_name = '/Users/christian/Downloads/HIT-2011-10-03T20_35_44.539109.xsams'
#xsams_name = '/Users/christian/Downloads/HIT-2011-08-27T00_50_08.820263.xsams'
#xsams_file = os.path.join('/Users/christian/Downloads', xsams_name)
dom = parse(xsams_file)
d_wavenumber = units.Dimensions
for elm in dom.getElementsByTagName("Value"):
tagName = elm.parentNode.tagName
if tagName == 'FitParameter':
# don't check FitParameters... yet
continue
if tagName == 'LineshapeParameter':
# don't check LineshapeParameters... yet
continue
attr = elm.getAttribute('units')
if attr == 'unitless' or attr == '':
unit = None
dims = d_dimensionless
else:
unit = parse_compound_units(attr)
dims = unit.get_dims()
ok = False
for dim in xsams_units[tagName]:
#print 'Comparing',dims,'with',dim,':',dims == dim
if dims == dim:
ok = True
#print 'OK:',unit,dims
break
if not ok:
print 'Error for element %s:\nunits="%s" has dimensions of %s but'\
' should resolve to units with dimensions in (%s)' % (tagName,
attr, dims,
', '.join([str(x) for x in xsams_units[tagName]]))