1 # Copyright (C) 2009-2010 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
7 # modify it under the terms of the GNU Lesser General Public
8 # License as published by the Free Software Foundation, either
9 # version 3 of the License, or (at your option) any later version.
11 # Hooke is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU Lesser General Public License for more details.
16 # You should have received a copy of the GNU Lesser General Public
17 # License along with Hooke. If not, see
18 # <http://www.gnu.org/licenses/>.
20 """Driver for text-exported MFP 1D files
25 from .. import libhooke as lh
26 from .. import curve as lhc
29 __version__='0.0.0.20090923'
32 class mfp1dexportDriver(lhc.Driver):
34 def __init__(self, filename):
36 This is a driver to import Asylum Research MFP 1D data.
39 self.filename = filename
40 self.filedata = open(filename,'rU')
41 self.lines = list(self.filedata.readlines())
44 self.filetype='mfp1dexport'
45 self.experiment='smfs'
52 self.raw_header = self.lines[0:38]
54 #Not enough lines for a header; not a good file
57 #FIXME: We want a more reasonable header recognition
58 if self.raw_header[0].startswith('Wave'):
63 def _read_columns(self):
65 self.raw_columns=self.lines[39:]
68 for line in self.lines:
69 if line[:7]=='SpringC':
73 kline=kline.split(':')
75 #self.k=float(self.raw_header[23][8:])
76 self.k=float(kline[1])
82 for line in self.raw_columns:
84 xext.append(float(spline[0]))
85 yext.append(float(spline[1]))
86 xret.append(float(spline[2]))
87 yret.append(float(spline[3]))
89 return [[xext,yext],[xret,yret]]
92 self.data = self._read_columns()
93 return self.data[0][1], self.data[1][1]
95 def default_plots(self):
96 main_plot = lhc.PlotObject()
97 defl_ext,defl_ret = self.deflection()
98 yextforce = [i*self.k for i in defl_ext]
99 yretforce = [i*self.k for i in defl_ret]
100 main_plot.add_set(self.data[0][0], yextforce)
101 main_plot.add_set(self.data[1][0], yretforce)
102 main_plot.normalize_vectors()
103 #main_plot.units = ['Z','force'] #FIXME: if there's an header saying something about the time count, should be used
104 main_plot.units = ['m','N']
105 main_plot.destination = 0
106 main_plot.filename = self.filename
107 main_plot.title = os.path.basename(self.filename)
108 main_plot.colors = ['red','blue']
109 main_plot.style = ['plot','plot']