Run update-copyright.py.
[hooke.git] / hooke / driver / hdf5.py
1 # Copyright (C) 2009-2012 Massimo Sandal <devicerandom@gmail.com>
2 #                         W. Trevor King <wking@drexel.edu>
3 #
4 # This file is part of Hooke.
5 #
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
9 # later version.
10 #
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
14 # details.
15 #
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/>.
18
19 """Driver for text-exported HDF5 files from Igor pro
20 """
21
22 import os.path
23
24 from .. import curve as lhc
25 from .. import libhooke as lh
26
27 class hdf5Driver(lhc.Driver):
28     
29     def __init__(self, filename):
30         
31         self.filename=filename
32         self.filedata=open(filename,'rU')
33         self.lines=list(self.filedata.readlines())
34         self.filedata.close()
35         
36     def close_all(self):
37         self.filedata.close()
38         
39     def is_me(self):
40         if os.path.isdir(path):
41             return False
42         self.raw_header=self.lines[0]      
43                 
44         if 'IGP-HDF5-Hooke' in self.raw_header:
45             return True
46         else:
47             return False
48         
49     def _read_columns(self):
50         
51         self.raw_columns=self.lines[4:]
52         
53         kline=None
54         for line in self.lines:
55             if line[:7]=='SpringC':
56                 kline=line
57                 break
58         
59         kline=kline.split(':')
60         
61         self.k=float(kline[1])
62         
63         
64         xext=[]
65         xret=[]
66         yext=[]
67         yret=[]
68         for line in self.raw_columns:
69             spline=line.split()
70             xext.append(float(spline[0]))
71             yext.append(float(spline[1]))
72             xret.append(float(spline[2]))
73             yret.append(float(spline[3]))
74             
75         return [[xext,yext],[xret,yret]]
76         
77     def deflection(self):
78         self.data=self._read_columns()
79         return self.data[0][1],self.data[1][1]
80         
81         
82     def default_plots(self):   
83         main_plot=lhc.PlotObject()
84         defl_ext,defl_ret=self.deflection()
85         yextforce=[i*self.k for i in defl_ext]
86         yretforce=[i*self.k for i in defl_ret]
87         main_plot.add_set(self.data[0][0],yextforce)
88         main_plot.add_set(self.data[1][0],yretforce)
89         main_plot.normalize_vectors()
90         main_plot.units=['Z','force']  #FIXME: if there's an header saying something about the time count, should be used
91         main_plot.destination=0
92         main_plot.title=self.filename
93         #main_plot.colors=['red','blue']
94         return [main_plot]