1
2 """Collections of output files"""
3
4 from os import path
5
6 from OutputFile import OutputFile
7
9 """Collection of output files
10
11 The files are stored in a common directory and are created on
12 first access
13
14 Each file can be identified by a unique name. If a file is
15 accessed a second time at the same simulation-time a file with the
16 ending _2 is created (incrementing with each access)"""
17
18 - def __init__(self,
19 basename,
20 titles=[],
21 singleFile=False):
22 """
23 @param basename: name of the base directory
24 @param titles: names of the data columns
25 @param singleFile: don't split into multiple files if more than one
26 datum is insert per time-step
27 """
28 self.files={}
29 self.lastTime=""
30 self.called={}
31 self.basename=basename
32 self.setTitles(titles)
33 self.singleFile=singleFile
34
35
36
37
39 """
40 Sets the titles anew
41
42 @param titles: the new titles
43 """
44 self.titles=titles
45 for f in self.files.items():
46 f.setTitles(titles)
47
53
55 """get a OutputFile-object"""
56 if not self.files.has_key(name):
57 fullname=path.join(self.basename,name)
58 self.files[name]=OutputFile(fullname,titles=self.titles)
59
60 return self.files[name]
61
63 """checks whether the name was used previously at that time-step"""
64 if self.called.has_key(name):
65 return self.called[name]
66 else:
67 return 0
68
70 """increments the access counter for name"""
71 self.called[name]=1+self.prevCalls(name)
72
73 - def write(self,name,time,data):
90
92 """Force all files to be closed"""
93
94 for f in self.files:
95 self.files[f].close()
96