3 """Simple driver to read general comma-separated values in Hooke
5 Columns are read this way:
7 X1 , Y1 , X2 , Y2 , X3 , Y3 ...
9 If the number of columns is odd, the last column is ignored.
20 class csvdriverDriver(lib.driver.Driver):
22 def __init__(self, filename):
24 self.filedata = open(filename,'r')
25 self.data = list(self.filedata)
28 self.filetype = 'generic'
31 self.filename=filename
36 def default_plots(self):
37 rrows=csv.reader(self.data)
38 rows=list(rrows) #transform the csv.reader iterator into a normal list
39 columns=lib.libhooke.transposed2(rows[1:])
41 for index in range(0, len(columns), 2):
43 temp_y=columns[index+1]
44 #convert to float (the csv gives strings)
45 temp_x=[float(item) for item in temp_x]
46 temp_y=[float(item) for item in temp_y]
48 curve = lib.curve.Curve()
50 curve.destination.row = index + 1
51 curve.label = 'curve ' + str(index)
58 plot = lib.plot.Plot()
59 plot.title = os.path.basename(self.filename)
60 plot.curves.append(curve)
62 #TODO: is normalization helpful or detrimental here?
67 myfile=file(self.filename)
68 headerline=myfile.readlines()[0]
71 #using a custom header makes things much easier...
72 #(looking for raw CSV data is at strong risk of confusion)
73 if headerline[:-1]=='Hooke data':