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 modify it
7 # under the terms of the GNU Lesser General Public License as
8 # published by the Free Software Foundation, either version 3 of the
9 # License, or (at your option) any later version.
11 # Hooke is distributed in the hope that it will be useful, but WITHOUT
12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
14 # 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
26 from .. import libhooke as lh
27 from .. import curve as lhc
30 __version__='0.0.0.20090923'
33 class mfp1dexportDriver(lhc.Driver):
35 def __init__(self, filename):
37 This is a driver to import Asylum Research MFP 1D data.
40 self.filename = filename
41 self.filedata = open(filename,'rU')
42 self.lines = list(self.filedata.readlines())
45 self.filetype='mfp1dexport'
46 self.experiment='smfs'
52 if os.path.isdir(path):
55 self.raw_header = self.lines[0:38]
57 #Not enough lines for a header; not a good file
60 #FIXME: We want a more reasonable header recognition
61 if self.raw_header[0].startswith('Wave'):
66 def _read_columns(self):
68 self.raw_columns=self.lines[39:]
71 for line in self.lines:
72 if line[:7]=='SpringC':
76 kline=kline.split(':')
78 #self.k=float(self.raw_header[23][8:])
79 self.k=float(kline[1])
85 for line in self.raw_columns:
87 xext.append(float(spline[0]))
88 yext.append(float(spline[1]))
89 xret.append(float(spline[2]))
90 yret.append(float(spline[3]))
92 return [[xext,yext],[xret,yret]]
95 self.data = self._read_columns()
96 return self.data[0][1], self.data[1][1]
98 def default_plots(self):
99 main_plot = lhc.PlotObject()
100 defl_ext,defl_ret = self.deflection()
101 yextforce = [i*self.k for i in defl_ext]
102 yretforce = [i*self.k for i in defl_ret]
103 main_plot.add_set(self.data[0][0], yextforce)
104 main_plot.add_set(self.data[1][0], yretforce)
105 main_plot.normalize_vectors()
106 #main_plot.units = ['Z','force'] #FIXME: if there's an header saying something about the time count, should be used
107 main_plot.units = ['m','N']
108 main_plot.destination = 0
109 main_plot.filename = self.filename
110 main_plot.title = os.path.basename(self.filename)
111 main_plot.colors = ['red','blue']
112 main_plot.style = ['plot','plot']