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.
12 from .. import curve as lhc
13 from .. import libhooke as lh
16 class csvdriverDriver(lhc.Driver):
18 def __init__(self, filename):
20 self.filedata = open(filename,'r')
21 self.data = list(self.filedata)
24 self.filetype = 'generic'
27 self.filename=filename
30 myfile=file(self.filename)
31 headerline=myfile.readlines()[0]
34 #using a custom header makes things much easier...
35 #(looking for raw CSV data is at strong risk of confusion)
36 if headerline[:-1]=='Hooke data':
44 def default_plots(self):
45 rrows=csv.reader(self.data)
46 rows=list(rrows) #transform the csv.reader iterator in a normal list
47 columns=lh.transposed2(rows[1:])
49 main_plot=lhc.PlotObject()
52 for index in range(0,len(columns),2):
53 main_plot.vectors.append([])
55 temp_y=columns[index+1]
57 #convert to float (the csv gives strings)
58 temp_x=[float(item) for item in temp_x]
59 temp_y=[float(item) for item in temp_y]
61 main_plot.vectors[-1].append(temp_x)
62 main_plot.vectors[-1].append(temp_y)
64 main_plot.units=['x','y']
65 main_plot.title=self.filename
66 main_plot.destination=0