[MixMaster] Fix variable ambiguity in DataFrame.py.

Fix file not closed bug in importCSV. Import from XML is broken due
to missing XML module.
This commit is contained in:
Bryan W. Weber 2014-02-19 22:45:00 +00:00
parent 771ff96e86
commit 3de3842e3c

View file

@ -125,11 +125,8 @@ class DataFrame(Frame):
if self.plt:
self.plt.destroy()
f = open(self.datafile.get(),'r')
lines = f.readlines()
vars = string.split(lines[0],',')
nlines = len(lines)
self.np = nlines - 1
with open(self.datafile.get(),'r') as f:
vars = f.readline().split(',')
nv = len(vars)
vv = []
for n in range(nv):
@ -140,18 +137,11 @@ class DataFrame(Frame):
break
nv = len(vv)
vars = vv
fdata = np.zeros((nv, self.np),'d')
for n in range(self.np):
v = string.split(lines[n+1],',')
for j in range(nv):
try:
fdata[j,n] = float(v[j])
except:
fdata[j,n] = 0.0
fdata = np.genfromtxt(self.datafile.get(), dtype=float, delimiter=',',
skip_header=1).transpose()
self.nsp = self.g.n_species
self.y = np.zeros(self.nsp,'d')
self.data = np.zeros((self.nsp+6,self.np),'d')
self.data = np.zeros((self.nsp+6,fdata.shape[1]),'d')
self.data[0,:] = fdata[0,:]
self.label = ['-']*(self.nsp+6)
self.label[0] = vars[0]
@ -184,10 +174,10 @@ class DataFrame(Frame):
w.append((vars[n], self.newplot, 'check', self.loc, k + Y_LOC))
if self.data[P_LOC,0] == 0.0:
self.data[P_LOC,:] = np.ones(self.np,'d')*one_atm
self.data[P_LOC,:] = np.ones(fdata.shape[1],'d')*one_atm
print('Warning: no pressure data. P set to 1 atm.')
self.sc.config(cnf={'from':0,'to':self.np-1})
self.sc.config(cnf={'from':0,'to':fdata.shape[1]-1})
if self.loc.get() <= 0:
self.loc.set(self.lastloc)
self.updateplot()
@ -225,9 +215,9 @@ class DataFrame(Frame):
if x['title'] == 'pressure':
p = float(x.value())
fa = gdata.children('floatArray')
self.np = int(fa[0]['size'])
data_size = int(fa[0]['size'])
self.data = np.zeros((self.nsp+6,self.np),'d')
self.data = np.zeros((self.nsp+6,data_size),'d')
w = []
for f in fa:
t = f['title']
@ -256,9 +246,9 @@ class DataFrame(Frame):
self.label[V_LOC] = t
w.append((t, self.newplot, 'check', self.loc, V_LOC))
self.data[P_LOC,:] = np.ones(self.np,'d')*p
self.data[P_LOC,:] = np.ones(data_size,'d')*p
self.label[P_LOC] = 'P (Pa)'
self.sc.config(cnf={'from':0,'to':self.np-1})
self.sc.config(cnf={'from':0,'to':data_size-1})
if self.loc.get() <= 0:
self.loc.set(self.lastloc)
self.updateplot()