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
19 """
20 @param basename: name of the base directory
21 @param titles: names of the data columns
22 """
23 self.files={}
24 self.lastTime=""
25 self.called={}
26 self.basename=basename
27 self.setTitles(titles)
28
29
30
31
33 """
34 Sets the titles anew
35
36 @param titles: the new titles
37 """
38 self.titles=titles
39 for f in self.files.items():
40 f.setTitles(titles)
41
47
49 """get a OutputFile-object"""
50 if not self.files.has_key(name):
51 fullname=path.join(self.basename,name)
52 self.files[name]=OutputFile(fullname,titles=self.titles)
53
54 return self.files[name]
55
57 """checks whether the name was used previously at that time-step"""
58 if self.called.has_key(name):
59 return self.called[name]
60 else:
61 return 0
62
64 """increments the access counter for name"""
65 self.called[name]=1+self.prevCalls(name)
66
67 - def write(self,name,time,data):
84
86 """Force all files to be closed"""
87
88 for f in self.files:
89 self.files[f].close()
90