/[escript]/trunk/pyvisi/py_src/datacollector.py
ViewVC logotype

Diff of /trunk/pyvisi/py_src/datacollector.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1809 by ksteube, Thu Sep 25 06:43:44 2008 UTC revision 2365 by gross, Mon Apr 6 01:25:25 2009 UTC
# Line 17  http://www.uq.edu.au/esscc Line 17  http://www.uq.edu.au/esscc
17  Primary Business: Queensland, Australia"""  Primary Business: Queensland, Australia"""
18  __license__="""Licensed under the Open Software License version 3.0  __license__="""Licensed under the Open Software License version 3.0
19  http://www.opensource.org/licenses/osl-3.0.php"""  http://www.opensource.org/licenses/osl-3.0.php"""
20  __url__="http://www.uq.edu.au/esscc/escript-finley"  __url__="https://launchpad.net/escript-finley"
21    
22  """  """
23  @var __author__: name of author  @var __author__: name of author
# Line 31  __url__="http://www.uq.edu.au/esscc/escr Line 31  __url__="http://www.uq.edu.au/esscc/escr
31  __author__="John Ngui, john.ngui@uq.edu.au"  __author__="John Ngui, john.ngui@uq.edu.au"
32    
33    
 import vtk  
34  import tempfile, os, sys  import tempfile, os, sys
35  from constant import Source, ColorMode  from constant import Source, ColorMode
36  try:  from esys.escript import getMPISizeWorld
37      import esys.escript  import esys.escript
38  except ImportError:  if getMPISizeWorld()==1: import vtk
     print "Warning: importing esys.escript failed."  
39    
40  class DataCollector:  class DataCollector:
41      """      """
# Line 59  class DataCollector: Line 57  class DataCollector:
57          @type source: L{Source <constant.Source>} constant          @type source: L{Source <constant.Source>} constant
58          @param source: Source type          @param source: Source type
59          """          """
60                    if getMPISizeWorld()>1:
61                        raise ValueError,"pyvisi.DataCollector is not running on more than one processor"
62          self.__source = source          self.__source = source
63          # Keeps track on whether DataCollector have been modified.          # Keeps track on whether DataCollector have been modified.
64          self.__modified = True          self.__modified = True
# Line 71  class DataCollector: Line 70  class DataCollector:
70          self.__set_scalar = False          self.__set_scalar = False
71          self.__set_vector= False          self.__set_vector= False
72          self.__set_tensor= False          self.__set_tensor= False
73            self.__tmp_fd = None
74            self.__tmp_file = None
75          if(source == Source.XML): # Source is an XML file.          if(source == Source.XML): # Source is an XML file.
76              self.__vtk_xml_reader = vtk.vtkXMLUnstructuredGridReader()              self.__vtk_xml_reader = vtk.vtkXMLUnstructuredGridReader()
77          # Source is a escript data object using a temp file in the background.          # Source is a escript data object using a temp file in the background.
78          elif (self.__source == Source.ESCRIPT):          elif (self.__source == Source.ESCRIPT):
79              self.__vtk_xml_reader = vtk.vtkXMLUnstructuredGridReader()              self.__vtk_xml_reader = vtk.vtkXMLUnstructuredGridReader()
80              # Create a temporary .xml file and retrieve its path.              # Create a temporary .xml file and retrieve its path.
81              self.__tmp_file = tempfile.mkstemp(suffix=".xml")[1]              # Should raise IOError on failure, in wich case
82                # __tmp_fd will remain None.
83                fd_and_name = tempfile.mkstemp(suffix=".xml")
84                self.__tmp_fd = fd_and_name[0]
85                self.__tmp_file = fd_and_name[1]
86    
87      def __del__(self):      def __del__(self):
88          """          """
89          Perform some clean up of the temporary file.          Perform some clean up of ths assumese temporary file.
90          """          """
91            # remove this test and rely upon the existance of an open
92          if (self.__source == Source.ESCRIPT):          # __tmp_file to decide upon closing and unlinking.
93              if os.access(self.__tmp_file,os.F_OK): os.unlink(self.__tmp_file)          # if (self.__source == Source.ESCRIPT):
94            if self.__tmp_fd != None :
95                os.close(self.__tmp_fd)
96                os.unlink(self.__tmp_file)
97    
98      def setFileName(self, file_name):      def setFileName(self, file_name):
99          """          """

Legend:
Removed from v.1809  
changed lines
  Added in v.2365

  ViewVC Help
Powered by ViewVC 1.1.26