6 Simple driver to read general comma-separated values in Hooke
8 Columns are read this way:
10 X1 , Y1 , X2 , Y2 , X3 , Y3 ...
12 If the number of columns is odd, the last column is ignored.
14 Copyright 2008 by Massimo Sandal
15 with modifications by Dr. Rolf Schmidt (Concordia University, Canada)
17 This program is released under the GNU General Public License version 2.
28 class csvdriverDriver(lib.driver.Driver):
30 def __init__(self, filename):
32 self.filedata = open(filename,'r')
33 self.data = list(self.filedata)
36 self.filetype = 'generic'
39 self.filename=filename
44 def default_plots(self):
45 rrows=csv.reader(self.data)
46 rows=list(rrows) #transform the csv.reader iterator into a normal list
47 columns=lib.libhooke.transposed2(rows[1:])
49 for index in range(0, len(columns), 2):
51 temp_y=columns[index+1]
52 #convert to float (the csv gives strings)
53 temp_x=[float(item) for item in temp_x]
54 temp_y=[float(item) for item in temp_y]
56 curve = lib.curve.Curve()
58 curve.destination.row = index + 1
59 curve.label = 'curve ' + str(index)
66 plot = lib.plot.Plot()
67 plot.title = os.path.basename(self.filename)
68 plot.curves.append(curve)
70 #TODO: is normalization helpful or detrimental here?
75 myfile=file(self.filename)
76 headerline=myfile.readlines()[0]
79 #using a custom header makes things much easier...
80 #(looking for raw CSV data is at strong risk of confusion)
81 if headerline[:-1]=='Hooke data':