1
2 """Output of time-dependent data"""
3
4 from BasicFile import BasicFile
5 from os import path
6
8 """output of time dependent data"""
9
10 - def __init__(self,name,titles=[],parent=None):
11 """
12 @param name: name of the file
13 @param titles: Titles of the columns
14 @param parent: A parent collection that knows about opened and
15 closed files
16 """
17 BasicFile.__init__(self,name)
18
19 self.parent=parent
20 self.setTitles(titles)
21
22
23
24
26 """
27 Sets the titles anew. Only has an effect if the file hasn't been opened yet
28
29 @param titles: The new titles
30 """
31 self.titles=titles
32
34 """
35 Write column titles if present
36 """
37 if len(self.titles)>0:
38 fh=self.getHandle()
39 fh.write("# time")
40 for c in self.titles:
41 fh.write(" \t"+c)
42 fh.write("\n")
43
44 - def write(self,time,data):
45 """write data set
46
47 @param time: the current time
48 @param data: tuple with data"""
49 self.writeLine( (time,)+data)
50
52 """A hook that gets called when the file is opened"""
53 if self.parent:
54 self.parent.addToOpenList(path.basename(self.name))
55
57 """A hook that gets called when the file is closed"""
58 if self.parent:
59 self.parent.removeFromOpenList(path.basename(self.name))
60
62 """Output for debugging"""
63
64 result="Outfile:"+self.name
65 if self.isOpen:
66 result+=" OPEN"
67 if self.append:
68 result+=" APPEND"
69 if self.handle:
70 result+=" HANDLE"
71 return result
72