4 Simple driver to read general comma-separated values in Hooke
6 Columns are read this way:
8 X1 , Y1 , X2 , Y2 , X3 , Y3 ...
10 If the number of columns is odd, the last column is ignored.
12 (c)Massimo Sandal, 2008
15 from .. import libhookecurve as lhc
16 from .. import libhooke as lh
19 class csvdriverDriver(lhc.Driver):
21 def __init__(self, filename):
23 self.filedata = open(filename,'r')
24 self.data = list(self.filedata)
27 self.filetype = 'generic'
30 self.filename=filename
33 myfile=file(self.filename)
34 headerline=myfile.readlines()[0]
37 #using a custom header makes things much easier...
38 #(looking for raw CSV data is at strong risk of confusion)
39 if headerline[:-1]=='Hooke data':
47 def default_plots(self):
48 rrows=csv.reader(self.data)
49 rows=list(rrows) #transform the csv.reader iterator in a normal list
50 columns=lh.transposed2(rows[1:])
52 main_plot=lhc.PlotObject()
55 for index in range(0,len(columns),2):
56 main_plot.vectors.append([])
58 temp_y=columns[index+1]
60 #convert to float (the csv gives strings)
61 temp_x=[float(item) for item in temp_x]
62 temp_y=[float(item) for item in temp_y]
64 main_plot.vectors[-1].append(temp_x)
65 main_plot.vectors[-1].append(temp_y)
67 main_plot.units=['x','y']
68 main_plot.title=self.filename
69 main_plot.destination=0