Don't specify curve or data block types. See doc/standards.txt.
[hooke.git] / hooke / driver / hdf5.py
1 # Copyright (C) 2009-2010 Alberto Gomez-Casado
2 #                         Massimo Sandal <devicerandom@gmail.com>
3 #                         W. Trevor King <wking@drexel.edu>
4 #
5 # This file is part of Hooke.
6 #
7 # Hooke is free software: you can redistribute it and/or modify it
8 # under the terms of the GNU Lesser General Public License as
9 # published by the Free Software Foundation, either version 3 of the
10 # License, or (at your option) any later version.
11 #
12 # Hooke is distributed in the hope that it will be useful, but WITHOUT
13 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 # or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General
15 # Public License for more details.
16 #
17 # You should have received a copy of the GNU Lesser General Public
18 # License along with Hooke.  If not, see
19 # <http://www.gnu.org/licenses/>.
20
21 """Driver for text-exported HDF5 files from Igor pro
22 """
23
24 import os.path
25
26 from .. import curve as lhc
27 from .. import libhooke as lh
28
29 class hdf5Driver(lhc.Driver):
30     
31     def __init__(self, filename):
32         
33         self.filename=filename
34         self.filedata=open(filename,'rU')
35         self.lines=list(self.filedata.readlines())
36         self.filedata.close()
37         
38     def close_all(self):
39         self.filedata.close()
40         
41     def is_me(self):
42         if os.path.isdir(path):
43             return False
44         self.raw_header=self.lines[0]      
45                 
46         if 'IGP-HDF5-Hooke' in self.raw_header:
47             return True
48         else:
49             return False
50         
51     def _read_columns(self):
52         
53         self.raw_columns=self.lines[4:]
54         
55         kline=None
56         for line in self.lines:
57             if line[:7]=='SpringC':
58                 kline=line
59                 break
60         
61         kline=kline.split(':')
62         
63         self.k=float(kline[1])
64         
65         
66         xext=[]
67         xret=[]
68         yext=[]
69         yret=[]
70         for line in self.raw_columns:
71             spline=line.split()
72             xext.append(float(spline[0]))
73             yext.append(float(spline[1]))
74             xret.append(float(spline[2]))
75             yret.append(float(spline[3]))
76             
77         return [[xext,yext],[xret,yret]]
78         
79     def deflection(self):
80         self.data=self._read_columns()
81         return self.data[0][1],self.data[1][1]
82         
83         
84     def default_plots(self):   
85         main_plot=lhc.PlotObject()
86         defl_ext,defl_ret=self.deflection()
87         yextforce=[i*self.k for i in defl_ext]
88         yretforce=[i*self.k for i in defl_ret]
89         main_plot.add_set(self.data[0][0],yextforce)
90         main_plot.add_set(self.data[1][0],yretforce)
91         main_plot.normalize_vectors()
92         main_plot.units=['Z','force']  #FIXME: if there's an header saying something about the time count, should be used
93         main_plot.destination=0
94         main_plot.title=self.filename
95         #main_plot.colors=['red','blue']
96         return [main_plot]