1 """Collections of output files"""
2
3 from os import path
4
5 from OutputFile import OutputFile
6
8 """Collection of output files
9
10 The files are stored in a common directory and are created on
11 first access
12
13 Each file can be identified by a unique name. If a file is
14 accessed a second time at the same simulation-time a file with the
15 ending _2 is created (incrementing with each access)"""
16
18 """
19 @param basename: name of the base directory
20 @param titles: names of the data columns
21 """
22 self.files={}
23 self.lastTime=""
24 self.called={}
25 self.basename=basename
26 self.setTitles(titles)
27
28
29
30
32 """
33 Sets the titles anew
34
35 @param titles: the new titles
36 """
37 self.titles=titles
38 for f in self.files.items():
39 f.setTitles(titles)
40
42 """check whether the time has changed"""
43 if time!=self.lastTime:
44 self.lastTime=time
45 self.called={}
46
48 """get a OutputFile-object"""
49 if not self.files.has_key(name):
50 fullname=path.join(self.basename,name)
51 self.files[name]=OutputFile(fullname,titles=self.titles)
52
53 return self.files[name]
54
56 """checks whether the name was used previously at that time-step"""
57 if self.called.has_key(name):
58 return self.called[name]
59 else:
60 return 0
61
63 """increments the access counter for name"""
64 self.called[name]=1+self.prevCalls(name)
65
66 - def write(self,name,time,data):
67 """writes data to file
68
69 name - name of the file
70 time - simulation time
71 data - tuple with the data"""
72 self.checkTime(time)
73
74 fname=name
75 self.incrementCalls(name)
76
77 if self.prevCalls(name)>1:
78 fname+="_"+str(self.prevCalls(name))
79
80 f=self.getFile(fname)
81
82 f.write(time,data)
83