6 Driver for text-exported MFP 1D files
8 Massimo Sandal (c) 2009
11 import libhookecurve as lhc
14 class mfp1dexportDriver(lhc.Driver):
16 def __init__(self, filename):
18 self.filename=filename
19 self.filedata=open(filename,'rU')
20 self.lines=list(self.filedata.readlines())
23 self.filetype='mfp1dexport'
24 self.experiment='smfs'
31 self.raw_header=self.lines[0:38]
33 #Not enough lines for a header; not a good file
36 #FIXME: We want a more reasonable header recognition
37 if self.raw_header[0][0:4]=='Wave':
42 def _read_columns(self):
44 self.raw_columns=self.lines[39:]
47 for line in self.lines:
48 if line[:7]=='SpringC':
52 kline=kline.split(':')
54 #self.k=float(self.raw_header[23][8:])
55 self.k=float(kline[1])
62 for line in self.raw_columns:
64 xext.append(float(spline[0]))
65 yext.append(float(spline[1]))
66 xret.append(float(spline[2]))
67 yret.append(float(spline[3]))
69 return [[xext,yext],[xret,yret]]
72 self.data=self._read_columns()
73 return self.data[0][1],self.data[1][1]
76 def default_plots(self):
77 main_plot=lhc.PlotObject()
78 defl_ext,defl_ret=self.deflection()
79 yextforce=[i*self.k for i in defl_ext]
80 yretforce=[i*self.k for i in defl_ret]
81 main_plot.add_set(self.data[0][0],yextforce)
82 main_plot.add_set(self.data[1][0],yretforce)
83 main_plot.normalize_vectors()
84 main_plot.units=['Z','force'] #FIXME: if there's an header saying something about the time count, should be used
85 main_plot.destination=0
86 main_plot.title=self.filename
87 #main_plot.colors=['red','blue']