1 # Copyright (C) 2009-2012 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 under the
7 # terms of the GNU Lesser General Public License as published by the Free
8 # Software Foundation, either version 3 of the License, or (at your option) any
11 # Hooke is distributed in the hope that it will be useful, but WITHOUT ANY
12 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
13 # A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
16 # You should have received a copy of the GNU Lesser General Public License
17 # along with Hooke. If not, see <http://www.gnu.org/licenses/>.
19 """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())
48 if os.path.isdir(path):
51 self.raw_header = self.lines[0:38]
53 #Not enough lines for a header; not a good file
56 #FIXME: We want a more reasonable header recognition
57 if self.raw_header[0].startswith('Wave'):
62 def _read_columns(self):
64 self.raw_columns=self.lines[39:]
67 for line in self.lines:
68 if line[:7]=='SpringC':
72 kline=kline.split(':')
74 #self.k=float(self.raw_header[23][8:])
75 self.k=float(kline[1])
81 for line in self.raw_columns:
83 xext.append(float(spline[0]))
84 yext.append(float(spline[1]))
85 xret.append(float(spline[2]))
86 yret.append(float(spline[3]))
88 return [[xext,yext],[xret,yret]]
91 self.data = self._read_columns()
92 return self.data[0][1], self.data[1][1]
94 def default_plots(self):
95 main_plot = lhc.PlotObject()
96 defl_ext,defl_ret = self.deflection()
97 yextforce = [i*self.k for i in defl_ext]
98 yretforce = [i*self.k for i in defl_ret]
99 main_plot.add_set(self.data[0][0], yextforce)
100 main_plot.add_set(self.data[1][0], yretforce)
101 main_plot.normalize_vectors()
102 #main_plot.units = ['Z','force'] #FIXME: if there's an header saying something about the time count, should be used
103 main_plot.units = ['m','N']
104 main_plot.destination = 0
105 main_plot.filename = self.filename
106 main_plot.title = os.path.basename(self.filename)
107 main_plot.colors = ['red','blue']
108 main_plot.style = ['plot','plot']