4 Driver for text-exported MFP 1D files
6 Massimo Sandal (c) 2009
9 from .. import libhookecurve as lhc
10 from .. import libhooke as lh
12 class mfp1dexportDriver(lhc.Driver):
14 def __init__(self, filename):
16 self.filename=filename
17 self.filedata=open(filename,'rU')
18 self.lines=list(self.filedata.readlines())
21 self.filetype='mfp1dexport'
22 self.experiment='smfs'
29 self.raw_header=self.lines[0:38]
31 #Not enough lines for a header; not a good file
34 #FIXME: We want a more reasonable header recognition
35 if self.raw_header[0][0:4]=='Wave':
40 def _read_columns(self):
42 self.raw_columns=self.lines[39:]
45 for line in self.lines:
46 if line[:7]=='SpringC':
50 kline=kline.split(':')
52 #self.k=float(self.raw_header[23][8:])
53 self.k=float(kline[1])
60 for line in self.raw_columns:
62 xext.append(float(spline[0]))
63 yext.append(float(spline[1]))
64 xret.append(float(spline[2]))
65 yret.append(float(spline[3]))
67 return [[xext,yext],[xret,yret]]
70 self.data=self._read_columns()
71 return self.data[0][1],self.data[1][1]
74 def default_plots(self):
75 main_plot=lhc.PlotObject()
76 defl_ext,defl_ret=self.deflection()
77 yextforce=[i*self.k for i in defl_ext]
78 yretforce=[i*self.k for i in defl_ret]
79 main_plot.add_set(self.data[0][0],yextforce)
80 main_plot.add_set(self.data[1][0],yretforce)
81 main_plot.normalize_vectors()
82 main_plot.units=['Z','force'] #FIXME: if there's an header saying something about the time count, should be used
83 main_plot.destination=0
84 main_plot.title=self.filename
85 #main_plot.colors=['red','blue']