1 # Copyright (C) 2009-2012 Massimo Sandal <devicerandom@gmail.com>
2 # W. Trevor King <wking@drexel.edu>
4 # This file is part of Hooke.
6 # Hooke is free software: you can redistribute it and/or modify it under the
7 # terms of the GNU Lesser General Public License as published by the Free
8 # Software Foundation, either version 3 of the License, or (at your option) any
11 # Hooke is distributed in the hope that it will be useful, but WITHOUT ANY
12 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
13 # A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
16 # You should have received a copy of the GNU Lesser General Public License
17 # along with Hooke. If not, see <http://www.gnu.org/licenses/>.
19 """Driver for text-exported HDF5 files from Igor pro
24 from .. import curve as lhc
25 from .. import libhooke as lh
27 class hdf5Driver(lhc.Driver):
29 def __init__(self, filename):
31 self.filename=filename
32 self.filedata=open(filename,'rU')
33 self.lines=list(self.filedata.readlines())
40 if os.path.isdir(path):
42 self.raw_header=self.lines[0]
44 if 'IGP-HDF5-Hooke' in self.raw_header:
49 def _read_columns(self):
51 self.raw_columns=self.lines[4:]
54 for line in self.lines:
55 if line[:7]=='SpringC':
59 kline=kline.split(':')
61 self.k=float(kline[1])
68 for line in self.raw_columns:
70 xext.append(float(spline[0]))
71 yext.append(float(spline[1]))
72 xret.append(float(spline[2]))
73 yret.append(float(spline[3]))
75 return [[xext,yext],[xret,yret]]
78 self.data=self._read_columns()
79 return self.data[0][1],self.data[1][1]
82 def default_plots(self):
83 main_plot=lhc.PlotObject()
84 defl_ext,defl_ret=self.deflection()
85 yextforce=[i*self.k for i in defl_ext]
86 yretforce=[i*self.k for i in defl_ret]
87 main_plot.add_set(self.data[0][0],yextforce)
88 main_plot.add_set(self.data[1][0],yretforce)
89 main_plot.normalize_vectors()
90 main_plot.units=['Z','force'] #FIXME: if there's an header saying something about the time count, should be used
91 main_plot.destination=0
92 main_plot.title=self.filename
93 #main_plot.colors=['red','blue']