1
2 """Analyze a file with GNUPLOT-Data"""
3
4 from string import strip,split
5 import re
6
9 """
10 @param fname: The filename
11 """
12 self.fname=fname
13
14 self.titles=[]
15 self.analyze()
16
18 """
19 Find out how many columns there are and what their names are
20
21 There are two cases:
22
23 1. the first line is not a comment. In this case the column
24 names are 'time' and 'value0x'
25 depending on how many values are in the first line
26
27 2. the first line is a comment line (it starts with a #).
28 In this case the rest of the line
29 is analyzed and used as names
30 """
31 fh=open(self.fname)
32 line=fh.readline()
33 fh.close()
34 line=strip(line)
35
36 if line[0]=='#':
37 line=line[1:]
38 exp=re.compile("^\s*((\"[^\"]+\")|(\S+))(.*)$")
39 while exp.match(line)!=None:
40 m=exp.match(line)
41 fnd=m.group(1)
42 line=strip(m.group(4))
43 if fnd[0]=='\"':
44 fnd=fnd[1:-1]
45 self.titles.append(fnd)
46 else:
47 self.titles=["time"]
48 els=split(line)
49 for i in range(1,len(els)):
50 self.titles.append("value%02d" % i )
51
53 """
54 Writes a file that can be used by Gnuplot
55
56 @param name: name of the file
57 """
58 fh=open(name,'w')
59
60 fh.write("plot ")
61 first=True
62
63 for i in range(1,len(self.titles)):
64 if first:
65 first=False
66 else:
67 fh.write(" , ")
68
69 fh.write(" \"%s\" using 1:%d title \"%s\" with lines " % (self.fname,i+1,self.titles[i]))
70
71 fh.write("\n")
72 fh.close()
73