1 # Copyright (C) 2008-2011 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 """Simple driver to read general comma-separated values in Hooke
22 Columns are read this way:
24 X1 , Y1 , X2 , Y2 , X3 , Y3 ...
26 If the number of columns is odd, the last column is ignored.
37 class csvdriverDriver(lib.driver.Driver):
39 def __init__(self, filename):
41 self.filedata = open(filename,'r')
42 self.data = list(self.filedata)
44 self.filename=filename
49 def default_plots(self):
50 rrows=csv.reader(self.data)
51 rows=list(rrows) #transform the csv.reader iterator into a normal list
52 columns=lib.libhooke.transposed2(rows[1:])
54 for index in range(0, len(columns), 2):
56 temp_y=columns[index+1]
57 #convert to float (the csv gives strings)
58 temp_x=[float(item) for item in temp_x]
59 temp_y=[float(item) for item in temp_y]
61 curve = lib.curve.Curve()
63 curve.destination.row = index + 1
64 curve.label = 'curve ' + str(index)
71 plot = lib.plot.Plot()
72 plot.title = os.path.basename(self.filename)
73 plot.curves.append(curve)
75 #TODO: is normalization helpful or detrimental here?
80 myfile=file(self.filename)
81 headerline=myfile.readlines()[0]
84 #using a custom header makes things much easier...
85 #(looking for raw CSV data is at strong risk of confusion)
86 if headerline[:-1]=='Hooke data':