/[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 2313 by gross, Tue Mar 17 03:41:17 2009 UTC
# Line 34  __author__="John Ngui, john.ngui@uq.edu. Line 34  __author__="John Ngui, john.ngui@uq.edu.
34  import vtk  import vtk
35  import tempfile, os, sys  import tempfile, os, sys
36  from constant import Source, ColorMode  from constant import Source, ColorMode
37  try:  from esys.escript import getMPISizeWorld
38      import esys.escript  import esys.escript
 except ImportError:  
     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.2313

  ViewVC Help
Powered by ViewVC 1.1.26