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