4 Driver for text-exported MFP 1D files
6 Massimo Sandal (c) 2009
11 from .. import libhooke as lh
12 from .. import libhookecurve as lhc
15 __version__='0.0.0.20090923'
18 class mfp1dexportDriver(lhc.Driver):
20 def __init__(self, filename):
22 This is a driver to import Asylum Research MFP 1D data.
25 self.filename = filename
26 self.filedata = open(filename,'rU')
27 self.lines = list(self.filedata.readlines())
30 self.filetype='mfp1dexport'
31 self.experiment='smfs'
38 self.raw_header = self.lines[0:38]
40 #Not enough lines for a header; not a good file
43 #FIXME: We want a more reasonable header recognition
44 if self.raw_header[0].startswith('Wave'):
49 def _read_columns(self):
51 self.raw_columns=self.lines[39:]
54 for line in self.lines:
55 if line[:7]=='SpringC':
59 kline=kline.split(':')
61 #self.k=float(self.raw_header[23][8:])
62 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]
81 def default_plots(self):
82 main_plot = lhc.PlotObject()
83 defl_ext,defl_ret = self.deflection()
84 yextforce = [i*self.k for i in defl_ext]
85 yretforce = [i*self.k for i in defl_ret]
86 main_plot.add_set(self.data[0][0], yextforce)
87 main_plot.add_set(self.data[1][0], yretforce)
88 main_plot.normalize_vectors()
89 #main_plot.units = ['Z','force'] #FIXME: if there's an header saying something about the time count, should be used
90 main_plot.units = ['m','N']
91 main_plot.destination = 0
92 main_plot.filename = self.filename
93 main_plot.title = os.path.basename(self.filename)
94 main_plot.colors = ['red','blue']
95 main_plot.style = ['plot','plot']