Package PyFoam :: Package Basics :: Module OutputFile
[hide private]
[frames] | no frames]

Source Code for Module PyFoam.Basics.OutputFile

 1  #  ICE Revision: $Id: /local/openfoam/Python/PyFoam/PyFoam/Basics/OutputFile.py 5789 2009-11-06T12:32:54.086322Z bgschaid  $  
 2  """Output of time-dependent data""" 
 3   
 4  from BasicFile import BasicFile 
 5  from os import path 
 6   
7 -class OutputFile(BasicFile):
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 # def __del__(self): 23 # print "Deleting File",self.name 24
25 - def setTitles(self,titles):
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
33 - def outputAtStart(self):
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
51 - def callAtOpen(self):
52 """A hook that gets called when the file is opened""" 53 if self.parent: 54 self.parent.addToOpenList(path.basename(self.name))
55
56 - def callAtClose(self):
57 """A hook that gets called when the file is closed""" 58 if self.parent: 59 self.parent.removeFromOpenList(path.basename(self.name))
60
61 - def __repr__(self):
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