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 (c)Massimo Sandal, 2008
17 import libhookecurve as lhc
21 class csvdriverDriver(lhc.Driver):
23 def __init__(self, filename):
25 self.filedata = open(filename,'r')
26 self.data = list(self.filedata)
29 self.filetype = 'generic'
32 self.filename=filename
35 myfile=file(self.filename)
36 headerline=myfile.readlines()[0]
39 #using a custom header makes things much easier...
40 #(looking for raw CSV data is at strong risk of confusion)
41 if headerline[:-1]=='Hooke data':
49 def default_plots(self):
50 rrows=csv.reader(self.data)
51 rows=list(rrows) #transform the csv.reader iterator in a normal list
52 columns=lh.transposed2(rows[1:])
54 main_plot=lhc.PlotObject()
57 for index in range(0,len(columns),2):
58 main_plot.vectors.append([])
60 temp_y=columns[index+1]
62 #convert to float (the csv gives strings)
63 temp_x=[float(item) for item in temp_x]
64 temp_y=[float(item) for item in temp_y]
66 main_plot.vectors[-1].append(temp_x)
67 main_plot.vectors[-1].append(temp_y)
69 main_plot.units=['x','y']
70 main_plot.title=self.filename
71 main_plot.destination=0